#ifndef _BOXES_
#define _BOXES_

#include <X11/Xlib.h>
#include "misc.hh"

struct Rect
{
	int x, y, wd, ht;

	Rect ();
	Rect (Rect *);
	int set (Rect *);
	int set (Rect &);
	int set (int, int, int, int);
	int cl ();
	int operator== (Rect &);
	int operator!= (Rect &);
	int overlap (Rect &); // ? operator /
	int overlap (int, int, int, int);
	int contains (int, int);
	int dsq (int, int);
#ifdef DEBUG
	int pr ();
#endif
	//union (Rect &); // ? operator *
};

struct Box: Rect
{
	Box *next;
	int xs, ys; // shrinkability, stretchability
	// ??? positive - stretchability
	// ??? negative - shrinkability

	Box ();
	Box (Box *);
	Box (int, int);
	virtual ~Box () {};

	int cl ();
	int align ();
	//  virtual int ia () {};
	virtual int ia ();
	virtual int fa () {};
	virtual int handle_event () {};
	virtual int draw () {};
};

#define HFil Box(10, 0)
#define VFil Box(0, 10)
#define Fil Box(10, 10)
#define Fill Box(100, 100)

struct HSkip: Box
{
	HSkip (int);
	int ia ();
};

struct VSkip: Box
{
	VSkip (int);
	int ia ();
};

struct GroupBox: Box
{
	Box *first;
	Box *last;

	GroupBox ();
	GroupBox (Box *, ...);
	~GroupBox ();
	int ia ();
	int fa ();
	int preaadd (Box *);
	int aadd (Box *);
	int add (Box *, ...);
	int rm_all ();
	int draw ();
	int handle_event ();
	virtual int add_border (int, GC) {};
};

struct VBox: GroupBox
{
	int baseht;
	int ia ();
	int fa ();
	int add_border (int, GC);
	int add_padding (int);
};

struct HBox: GroupBox
{
	int basewd;
	int ia ();
	int fa ();
	int add_border (int, GC);
	int add_padding (int);
};

struct HBoxTo: HBox
{
	HBoxTo (int);
	int ia ();
};

struct HCenter: HBox
{
	int fa ();
};

// has member functions similar to Box, but isn't inherited
struct Win
{
	HBox *hbox;
	Window w;
	Rect wr;

	Win ();
	~Win ();
	int align ();
	int ia ();
	int fa ();
	int handle_event ();
	int draw ();
	int update ();
};

struct FillBox: Box
{
	GC gc;
	int draw ();
	int handle_event ();
};

struct VRule: FillBox
{
	VRule (int, GC);
	int ia ();
};

struct HRule: FillBox
{
	HRule (int, GC);
	int ia ();
};

#define B_FREE    0
#define B_HOVER   1
#define B_DOWN    2

struct Button: Box
{
	MyPixmap *pm_free, *pm_hover, *pm_down;
	int state;

	Button ();

	int ia ();
	int draw ();
	int handle_event ();
	int handle_grab ();
	virtual int exec () {};
};

struct HText: Box
{
	char **text;

	HText (char *&);
	~HText ();
	int handle_event ();
	int ia ();
	int draw ();
};

//********************************************************************

extern Window boxw; // box output window

#endif
