#ifndef CODE_RULER_CXX
#define CODE_RULER_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: ruler.cxx,v 1.2 1998/08/05 14:57:09 schmitzj 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/group.h>
#include <Xclasses/Xcolors.h>
#include <Xclasses/ruler.h>
#include "include/ruler_p.h"


#define BORDERSIZE	2

ruler::ruler(void) : gadget()
{
	while (!(p=new pruler))
	{
		outOfMemory("ruler");
	}
	p->o=this;
	Name("ruler");
}
pruler::pruler()
{
	vert=0;
	hand=0;
	offset=0;
	space=4;
}
pruler::~pruler()
{
}
ruler::~ruler()
{
	if (win) Free();
	if (p) delete p;
}

int ruler::Create(void)
{
	Background(col_background());

	if (!setlimit) GSetLimits();

    if (gadget::Create())
    {
        Mode(GM_ONEEXPOSE);
        return 1;
    }
    return 0;
}

void ruler::Horiz(void)
{
	p->vert=0;
	p->hand=1;
}
void ruler::Vert(void)
{
	p->vert=1;
	p->hand=1;
}
void ruler::Offset(int x)
{
	p->offset=x;
}
void ruler::Space(int x)
{
	p->space=x;
}

//void pruler::Clear(void)
//{
//	XClearWindow(display(),o->win);
//}
void ruler::GExpose(XEvent *event)
{
	XSetForeground(display(),gc,col_shadow2());
	if (p->vert) XDrawLine(display(),win,gc,p->space,p->offset,p->space,height-p->offset-1); else XDrawLine(display(),win,gc,p->offset,p->space,width-p->offset-1,p->space);
	XSetForeground(display(),gc,col_shine2());
	if (p->vert) XDrawLine(display(),win,gc,width-1-p->space,p->offset,width-1-p->space,height-p->offset-1); else XDrawLine(display(),win,gc,p->offset,height-1-p->space,width-p->offset-1,height-1-p->space);
}
int ruler::GActivate(XEvent *event,int why)
{
	return 0;
}
void ruler::GSetLimits(void)
{
	setlimit=1;
	if (!p->hand)
	{
		Xclasses *par=ParentClass();
		if (par)
		{
			if (par->IsClassType("group"))
			{
				p->vert=((group*)par)->Direction()?1:0;
			}
		}
	}
	if (p->vert)
	{
		minwidth=p->space*2+2;
		maxwidth=p->space*2+2;
		minheight=2+p->offset*2;
	}
	else
	{
		minwidth=2+p->offset*2;
		minheight=p->space*2+2;
		maxheight=p->space*2+2;
	}
}

#endif
