#ifndef CODE_IMAGE_CXX
#define CODE_IMAGE_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: image.cxx,v 1.2 1998/07/31 06:35:15 beckerr Exp $)
 * 
 * Copyright (C) 1998 Jürgen Schmitz
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 *-----------------------------------------------------------------------
 */

#include "types.h"
#include <Xclasses/gadget.h>
#include <Xclasses/Xcolors.h>
#include <Xclasses/Ddraw.h>
#include <Xclasses/gfx_object.h>
#include <Xclasses/image.h>
#include "include/image_p.h"

image::image(): gadget(), Ddraw(this)
{
	while (!(p=new pimage))
	{
		outOfMemory("image");
	}
	p->o=this;
	Name("image");
}
pimage::pimage()
{
	obj=NULL;
	border=1;
}
pimage::~pimage()
{
}
image::~image()
{
	if (win) Free();
	if (p) delete p;
}
int image::Create(void)
{
	Background(col_background());
	BorderSize((p->border?1:0));
	
    if (gadget::Create())
    {
        Mode(GM_ONEEXPOSE);
        return 1;
    } 
    return 0;
}
void image::Free(void)
{
	gadget::Free();
}
void image::Border(void)
{
	p->border=1;
}
void image::NoBorder(void)
{
	p->border=0;
}
void image::Object(gfx_object *obj)
{
	p->obj=obj;
	if (win) GExpose(NULL);
}
void image::GExpose(XEvent *event)
{
	if (!event || (event->type!=NoExpose && event->type!=GraphicsExpose))
	{
		if (p->border)
		{
			borderDown(this,0,0,width,height);
			if (p->obj)
				p->obj->draw_normal(this,RealSize(),RealSize(),width-RealSize()*2,height-RealSize()*2);
		}
		else
		{
			if (p->obj)
				p->obj->draw_normal(this,0,0,width,height);
		}
	}
}
void image::GSetLimits(void)
{
	if (p->obj)
	{
		if (p->obj->width(this)!=NOLIMIT)
			minwidth=maxwidth=p->obj->width(this)+(p->border?RealSize()*2:0);
		if (p->obj->height(this)!=NOLIMIT)
			minheight=maxheight=p->obj->height(this)+(p->border?RealSize()*2:0);
	}
}

#endif
