#ifndef CODE_TEXT_CXX
#define CODE_TEXT_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: text.cxx,v 1.4 1998/12/28 00:41:31 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 <string.h>
#include <math.h>
#include "types.h"
#include <Xclasses/gadget.h>
#include <Xclasses/Xcolors.h>
#include <Xclasses/Ddraw.h>
#include <Xclasses/text.h>
#include "include/text_p.h"

#define BORDERSIZE	2

text::text(void) : gadget(), Ddraw(this)
{
	while (!(p=new ptext))
	{
		outOfMemory("text");
	}
	p->o=this;
	Name("text");
	p->text.ParentClass(this);
	p->atext.ParentClass(this);
}
text::text(char *t) : gadget(), Ddraw()
{
	text();
	p->text.Text(t); p->atext.Text(t);
	Name("text");
	p->text.ParentClass(this);
	p->atext.ParentClass(this);
}
ptext::ptext() : text(), atext()
{
	text.Adjust(ADJUST_LEFT|ADJUST_MIDDLE);
	top=0;
	left=0;
	autof=0;
	fixedtext=0;
	nounderscore=0;
}
ptext::~ptext()
{
}
text::~text()
{
	if (win) Free();
	if (p) delete p;
}

int text::Create(void)
{
	Background(col_background());
//	BorderSize(BORDERSIZE);

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

void text::Text(char *t)
{
	if (p->nounderscore)
	{
		if (p->autof) p->atext.NoUnderlineText(t); else p->text.NoUnderlineText(t);
	}
	else
	{
		if (p->autof) p->atext.Text(t); else p->text.Text(t);
	}
	if (win) { p->Clear(); GExpose(NULL); };
}
void text::AutoFormat(void)
{
	p->autof=1;
}
void text::UserFormat(void)
{
	p->autof=0;
}
void text::NoUnderline(void)
{
	p->nounderscore=1;
}
void text::FixedText(void)
{
	p->fixedtext=1;
}
void text::Left(void)
{
	if (p->autof) p->atext.Adjust(ADJUST_LEFT|ADJUST_MIDDLE); else p->text.Adjust(ADJUST_LEFT|ADJUST_MIDDLE);
	if (win) { p->Clear(); GExpose(NULL); };
}
void text::Center(void)
{
	if (p->autof) p->atext.Adjust(ADJUST_CENTER|ADJUST_MIDDLE); else p->text.Adjust(ADJUST_CENTER|ADJUST_MIDDLE);
	if (win) { p->Clear(); GExpose(NULL); };
}
void text::Right(void)
{
	if (p->autof) p->atext.Adjust(ADJUST_RIGHT|ADJUST_MIDDLE); else p->text.Adjust(ADJUST_RIGHT|ADJUST_MIDDLE);
	if (win) { p->Clear(); GExpose(NULL); };
}
void text::OffsetLeft(int x)
{
	p->left=x;
	if (win) { p->Clear(); GExpose(NULL); };
}
void text::OffsetTop(int x)
{
	p->top=x;
	if (win) { p->Clear(); GExpose(NULL); };
}

void ptext::Clear(void)
{
	XClearWindow(o->display(),o->win);
}
void text::GExpose(XEvent *event)
{
	if (p->autof) p->atext.draw_normal(this,p->left,p->top,width-p->left,height-p->top); else p->text.draw_normal(this,p->left,p->top,width-p->left,height-p->top);
}
int text::GActivate(XEvent *event,int why)
{
	return 0;
}
void text::GSetLimits(void)
{
	int w=0,h=0;
	if (p->autof)
	{
		w=p->atext.width(this);
		h=p->atext.height(this);
		minwidth=w+p->left+2;
		minheight=h+p->top+2;
	}
	else
	{
		w=p->text.width(this);
		h=p->text.height(this);
		minwidth=w+p->left+2;
		if (p->fixedtext)
		{
			maxwidth=w+p->left+2;
		}
		minheight=h+p->top+2;
		maxheight=h+p->top+2;
	}
}

#endif
