/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: html_box.h,v 1.15 1998/09/09 21:10:34 schmitzj Exp $)
 * 
 * Copyright (C) 1998 Jürgen Schmitz
 *
 * HTML Parser system
 * (c) 1998 by Jürgen Schmitz - all rights reserved
 * THIS IS NOT GPL OR SOMETHING OTHER FREE LICENSE!!
 * it may only be used together with Xclasses!
 *-----------------------------------------------------------------------
 */

#ifndef HTML_BOX_H
#define HTML_BOX_H

enum ADJUST {LEFT,CENTER,RIGHT};

#include <stdlib.h>
#include "html_drawspec.h"
#include "html_item.h"
#include "../../include/strbuf.h"

class html_box
{
	int				x;
	int				y;
	int				width;
	int				height;
	FONTSTYLE		fontstyle;
	FONTSIZE		fontsize;
	enum ADJUST		adjust;

	int				mx1,mx2;
	int				my1,my2;

	int				xoffset;
	FONTSTYLE		cursor_fontstyle;
	FONTSIZE		cursor_fontsize;
	enum ADJUST		cursor_adjust;
	int 			cursor_x;
	int				cursor_y;
	Xcl_strbuf		cursor_color;
	int				nowrap:1,
					cursor_nowrap:1;

	Xcl_strbuf		marktext;

	class html_drawspec	*drawable;
	class html_item		*items;

	class html_box		*parentbox;
	class html_item		*last;
	class html_box		*workbox;

	class html_parser	*callback;
	Xcl_strbuf			stringdata;

	class html_item		*firsti;
	class html_item		*lasti;

	void SetItem(class html_item *);
	int LineOfY(int y);
public:
	html_box(FONTSTYLE fontstyle=FSY_NONE,FONTSIZE fontsize=NORMAL,enum ADJUST adjust=LEFT);
	~html_box();

	void AddItem(class html_item *);
	void SetData(char *);
	char *GetData(void);
	html_box *CreateBox(void);
	void ResetBox(void);
	void Position(int &x,int &y);		// set x/y to NULL before call
	html_box *GetMasterBox(void);

	int  GetWidth(void) { return width; };
	int  GetHeight(void) { return height; };
	FONTSTYLE GetFontstyle(void) { return cursor_fontstyle; };
	FONTSIZE  GetFontsize(void) { return cursor_fontsize; };
	void SetFont(FONTSTYLE f,FONTSIZE fs) { fontstyle=f; fontsize=fs; Font(fontstyle,fontsize); };

	void CalcSize(void);	// Breiten der Items ermitteln
	void CalcBox(int x,int y,int width,int &real_width,int &real_height);
	void CreateBox(html_drawspec *parent);
	void MoveBox(int x,int y);
	void MoveBox(void);
	void DrawBox(int nosub=0);
	void DrawBox(int y1,int y2,int nosub=0);
	void FreeBox(void);
	void SetNoWrap(int OnOff);

	char *Mark(int x1,int y1,int x2,int y1,int nosub=0);
	void Unmark(int nosub=0);

	void Callback(class html_parser *);					// (CalcSize) set callback
	void Callback(void);								// callback call
	void Text(char *,int xmove=0);						// (Draw)
	void MarkedText(char *,int x1,int x2,int xmove=0);	// (Draw)
	char *CutText(char *,int x1,int x2,int &size);		// (Draw)
	void Line(int x1,int y1,int x2,int y2);				// (Draw)
	int  TextLength(char *);							// (CalcSize, Draw)
	int  TextHeight(char *);							// (CalcSize, Draw)
	int  Newline(int size=0);							// (CalcSize)
	void XOffset(int offset);							// (CalcItem)
	void Font(FONTSTYLE fontsize=FSY_NONE,FONTSIZE=NORMAL);	// (CalcSize)
	void Adjust(enum ADJUST adjust=LEFT);				// (CalcSize)
	void Color(char *);									// (CalcSize)
	void BackgroundColor(char *);						// (Draw)
	void NoWrap(int OnOff);								// (CalcSize)
};

#endif
