/*	Table widget for FLTK-2
	Class Table
	Copyright(C) 2007 Alex Ivanov
	http://www.aleksoft.net
*/

#ifndef aleksoft_table_h
#define aleksoft_table_h

#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/ScrollGroup.h>
#include <stdio.h>
#include <fltk/draw.h>
#include <fltk/events.h>
#include "Collection.H"
#include <fltk/Cursor.h>
#include <fltk/Input.h>
#include <fltk/damage.h>

using namespace fltk;


enum FixedRows
{
	NONE      = 0,
	COLHEADER = 1,
	COLFOOTER = 2,
	ROWHEADER = 4,
	ROWFOOTER = 8,
	COLSONLY  = COLHEADER | COLFOOTER,
	ROWSONLY  = ROWHEADER | ROWFOOTER,
	ALL       = COLHEADER | COLFOOTER | ROWHEADER | ROWFOOTER
} ;

class Table : public Group{

public:
	Table(int X, int Y, int W, int H,
		uint rows=10, 
		uint cols=10, 
		uint rowHeight=16, 
		uint colWidth=120) ;
	int colOffset(uint C);
	int rowOffset(uint R);
	uint colAt(int X, int noHeaders_Footers=0);
	uint rowAt(int Y, int noHeaders_Footers=0);
	uint colWidth(int C);
	void colWidth(int C,int value);
	uint rowHeight(int R);
	void rowHeight(int R, int value);
	int handle(int event);
	void draw();
	void (*drawCell)(Table& t, int R, int C);
	void setFixedRows(int frows);
	void adjustSize();
	uint cols;
	uint rows;
	void (*showEditor)(Table& t, uint R, uint C,Widget** editor);
	void removeEditor();
	uint selectedRow;
	uint selectedCol;
private:
	Widget* editor;
	void drawHeaderFooter(int startpos);
	Collection colWidths;
	Collection rowHeights;
	uint firstrow;
	uint firstcol;
	int fixedRows;
	//char buf[30];
	ScrollGroup* scroll;
	Rectangle r;
};

#endif //aleksoft_table_h