#ifndef CODE_MULTILISTVIEWP_H
#define CODE_MULTILISTVIEWP_H

/*-----------------------------------------------------------------------
 * Xclasses header file
 * ($Id: multilistview_p.h,v 1.7 2002/07/31 09:34:00 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 <Xclasses/Ddraw.h>
#include <Xclasses/multilistview.h>
#include <Xclasses/scroller.h>
#include <Xclasses/text.h>
#include <Xclasses/dlist.h>
#include <Xclasses/gfx_locked.h>
#include <Xclasses/gfx_text.h>

struct lvnode
{
	struct node		base;
	int				marked:1,
					locked:1,
					free:1;
	void			*data;
	char			*text[1];
};

#define TA_SCROLL		0
#define TA_EXPOSE		1
#define TA_SELECT		2
#define TA_EVENT		3
#define TA_SELNEW		4
#define TA_EXPOSELINE	5
#define TA_EXPOSEBELOW	6

#define MD_EINFACH	0
#define MD_SELECTED	1
#define MD_READONLY	2

#define SCALEBASE	0x10000
#define SCALESIZE	6
#define SCALESUB(xx)	(multilistview::p->specs[xx].cs.flags & CSF_SCALEABLE?SCALESIZE:0)
#define SCALEADD(xx)	(xx>0?(multilistview::p->specs[xx-1].cs.flags & CSF_SCALEABLE?(-SCALESIZE+2):0):0)

class mlvtext : public gadget, private Ddraw
{
	gfx_text txt;
public:
	int bgcol;

	mlvtext(void);
	~mlvtext();

	void GExpose(XEvent *event);
	int GActivate(XEvent *event,int why);
	int GSelected(XEvent *event,int why,int wasabove);
	void GSetLimits(void);

	int Create(void);
	void Text(char *);
};

struct pspecs
{
	struct column_spec	cs;
	int					x;
	int					fixwidth;
	int					minwidth;
	gadget				innen;
	gadget				button;
	mlvtext				title;
};

class pmultilistview : public callable
{
	friend class multilistview;
public:
	multilistview *o;

	int selmode;
	int	multi:1,
		direct:1,
		key:1,
		shift:1,
		above:1,
		below:1,
		setmark:1,
		hascut:1,
		hastitle:1,
		dclick:1,
		free:1;

	int spacing;
	int scroller_width;
	int zeilen;
	int fontheight;
	int columns;
	int titlesize;

	callback	fcb;

	class dlist		items;
	GC				rubgc;
	int				rubpos;

	int 			top;		// 1...n 
	struct lvnode	*topp;
	int 			selected;	// 0 - keins, 1...n
	struct lvnode	*selectedp;
	int				normal_selected;
	int				selectedcolumn;


	scroller		scroll;
	struct pspecs	*specs;
	gfx_locked		glock;

	struct hook_data	hookdata;

    pmultilistview();
	~pmultilistview();

	int length(char **t);
	void copyColumns(struct lvnode *n1,char **t);
	int columnsize(int w,int col,int inRecursion=0);
	int bgcol(int col=-1);
	int columnpos(int col)
	{
		int x=0;
		for(int i=0;i<=col;i++)
		{
			x+=columnsize(o->width,i);
		}
		return x;
	};

	void textaus(int why,XEvent *event=NULL);
	void textaus(int why,struct lvnode *n) { textaus(why,(XEvent*)n); }
	void textaus(int why,int line) { textaus(why,(struct lvnode*)items.Find(line)); }
	void setvars(void);
	void checkvars(void);
	void zeileaus(struct lvnode *,int col=-1);
	void zeileclear(int,int col=-1);
	void Selected(int);

	void draw(void);
	void setWidthOf(int col,int dw);

	void title_callback(gadget *,int);
};

struct old_column_spec
{
	unsigned int	flags;

	unsigned int	weight;	// percent
	unsigned int	width;	// multiples of line height *10 - ie. number of chars*10 with a fixed width font
	int         	adjust; // ADJUST_LEFT, ...

	// column hook
	void *hookclass;
	int (*hook)(struct hook_data*);
	void *userdata;
 		// int Hook(struct hook_data*, void*)
 		// returns space of painted object
 		// if negativ old output colors are restored

	char *title;
};

#endif
