#ifndef CODE_BORDERGROUP_CXX
#define CODE_BORDERGROUP_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: bordergroup.cxx,v 1.2 1998/07/31 06:35:14 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/bordergroup.h>
#include "include/bordergroup_p.h"

#define FENSTERRAHMEN	2

bordergroup::bordergroup(void) : group(), Ddraw(this)
{
	while (!(p=new pbordergroup))
	{
		outOfMemory("bordergroup");
	}
	p->o=this;
	Name("bordergroup");
}
pbordergroup::pbordergroup()
{
	title=NULL;
	width=0;
}
bordergroup::~bordergroup(void)
{
	if (p) delete p;
}
pbordergroup::~pbordergroup()
{
}

int bordergroup::Create(void)
{
	return group::Create();
}

void bordergroup::Title(char *t)
{
	p->title=t;
	if (win)
	{
		p->width=textlength(this,p->title)+4;
		GExpose(NULL);
	}
}

// überladen
void bordergroup::BorderLimits(void)
{
	borderleft=4;
	borderright=4;
	borderbottom=4;
	if (p->title)
	{
		bordertop=textheight(this,p->title)+2;
		if (bordertop<4) bordertop=4;
	}
	else
	{
		bordertop=4;
	}
	p->width=textlength(this,p->title)+4;
}
void bordergroup::GExpose(XEvent *event)
{
	int h;
	int w=p->width/2;
	if (!event)
	{
		XClearWindow(display(),win);
	}
	if (p->title) h=bordertop/2; else h=0;
	XSetForeground(display(),gc,col_shadow2());
	XDrawRectangle(display(),win,gc,1,1+h,width-4,height-4-h);
	XSetForeground(display(),gc,col_shine2());
	XDrawLine(display(),win,gc,2,2+h,width-4,2+h);
	XDrawLine(display(),win,gc,2,2+h,2,height-4);
	XDrawLine(display(),win,gc,width-2,1+h,width-2,height-2);
	XDrawLine(display(),win,gc,1,height-2,width-2,height-2);
	if (p->title)
	{
		XSetForeground(display(),gc,gadget::Background());
		XDrawLine(display(),win,gc,width/2-w,1+h,width/2+w,1+h);
		XDrawLine(display(),win,gc,width/2-w,2+h,width/2+w,2+h);
		if (locked)
		{
			borderlockedtext(this,width/2-w,1,p->width,bordertop,p->title,ADJUST_CENTER|ADJUST_MIDDLE);
		}
		else
		{
			bordertext(this,width/2-w,1,p->width,bordertop,p->title,ADJUST_CENTER|ADJUST_MIDDLE);
		}
	}
}

#endif
