/** * Copyright Mikael Högdahl - triyana@users.sourceforge.net * * This source is distributed under the terms of the Q Public License version 1.0, * created by Trolltech (www.trolltech.com). */ #ifndef Fl_Table_h #define Fl_Table_h #ifdef MSVC #define snprintf _snprintf #endif #include #include "Fl_Table_Data.h" class Fl_Input; class Fl_Scrollbar; class Fl_Find; enum { FL_DATA_CHANGE = 1000, FL_DATA_SAVE, FL_DATA_SAVE_ERROR, FL_DATA_ERROR, }; /** * A simple table object. * Create a object derived from the Fl_Table_Data interface to supply the table object with data. * Start editing with enter key or double click with the mouse. * Quit editing with enter or click outside cell. * To activate list boxes (after editins starts) press space. * There is also a color chooser dialog and a list choice dialog for editing data. */ class Fl_Table : public Fl_Group { public: Fl_Table (Fl_Window* dlgParent, Fl_Table_Data* data, int x, int y, int w, int h); ~Fl_Table (); static void cb_hor (Fl_Widget* w, void* o); void cb_hor (); static void cb_ver (Fl_Widget* w, void* o); void cb_ver (); void add (); Fl_Table_Data* data () const {return aData;} void data (Fl_Table_Data* data); void edit (bool force_custom); void erase (); void event_handler (Fl_Widget* widget) {aEventHandler = widget;} bool dirty () {if (aData) return aData->dirty(); else return false;} void draw (); void find (bool nextword); int handle (int event); void insert (); void move_cursor (int rows, int cols); void reload (const char* message) {if (aData) aData->reload (message); set_data_size();} void resize () {resize(x(), y(), w(), h()); redraw();} void resize (int x, int y, int w, int h); int row () {return aCurrRow;} bool quit_edit_mode (bool save); bool save (); void set_data_size(); private: enum { DRAG_NONE, DRAG_HOR, SCROLL_SIZE = 16, SCROLL_JUMP = 10, CLIP_NONE = 0, CLIP_COL = 1, CLIP_ROW = 2, CLIP_BOTH = 3, }; int aClipped; int aCurrCol; int aCurrRow; int aStartCol; int aStartRow; int aVisibleRows; int aMaxVisibleRows; int aVisibleCols; int* aWidth; int aDragState; int aDragCol; int aActiveX; int aActiveY; int aActiveW; int aActiveH; int aActiveR; int aActiveC; char aSearchWord[200]; bool aCase; Fl_Table_Data* aData; Fl_Scrollbar* aScrollbarHor; Fl_Scrollbar* aScrollbarVer; Fl_Widget* aEditWidget; Fl_Widget* aEventHandler; Fl_Input* aDummy; Fl_Window* aDlgParent; Fl_Find* aFind; int clip (int xpos, int ypos, int width, int height, int row = 0); void draw_cell (int row, int col, int xpos, int ypos, int width, int height); void draw_cell (int x, int y, int w, int h, Fl_Color bg, Fl_Color fg); void draw_label (int xpos, int ypos); void draw_header (int xpos, int ypos); int draw_row (int row, int xpos, int ypos); void ev_drag (); bool ev_keyboard_down (); void ev_move (); void ev_push (); void get_cell_pos (int& row, int& col, int& xpos, int& ypos, int& width, int& height); void start_edit_mode (bool force = false); void set_cursor(int row, int col) {move_cursor (row - aCurrRow, col - aCurrCol);} }; #endif