1 /**
2 *  Copyright Mikael H�gdahl - triyana@users.sourceforge.net
3 *
4 *  This source is distributed under the terms of the Q Public License version 1.0,
5 *  created by Trolltech (www.trolltech.com).
6 */
7 
8 #ifndef Fl_Table_h
9 #define Fl_Table_h
10 
11 #ifdef MSVC
12     #define snprintf _snprintf
13 #endif
14 
15 #include <FL/Fl_Group.H>
16 #include "Fl_Table_Data.h"
17 
18 class Fl_Input;
19 class Fl_Scrollbar;
20 class Fl_Find;
21 class Fl_File_Chooser;
22 
23 enum {
24     FL_DATA_CHANGE = 1000,
25     FL_DATA_SAVE,
26     FL_DATA_SAVE_ERROR,
27     FL_DATA_ERROR,
28 
29 };
30 
31 
32 
33 /**
34 *  A simple table object.
35 *  Create a object derived from the Fl_Table_Data interface to supply the table object with data.
36 *  Start editing with enter key or double click with the mouse.
37 *  Quit editing with enter or click outside cell.
38 *  To activate list boxes (after editins starts) press space.
39 *  There is also a color chooser dialog and a list choice dialog for editing data.
40 */
41 class Fl_Table : public Fl_Group {
42 public:
43                             Fl_Table (Fl_Window* dlgParent, Fl_Table_Data* data, int x, int y, int w, int h);
44                             ~Fl_Table ();
45 
46     static void             cb_hor (Fl_Widget* w, void* o);
47     void                    cb_hor ();
48     static void             cb_ver (Fl_Widget* w, void* o);
49     void                    cb_ver ();
50 
51     void                    add ();
data()52     Fl_Table_Data*          data () const {return aData;}
53     void                    data (Fl_Table_Data* data);
54     void                    edit (bool force_custom);
55     void                    erase ();
event_handler(Fl_Widget * widget)56     void                    event_handler (Fl_Widget* widget) {aEventHandler = widget;}
dirty()57     bool                    dirty () {if (aData) return aData->dirty(); else return false;}
58     void                    draw ();
59     void                    find (bool nextword);
60     int                     handle (int event);
61     void                    insert ();
62     void                    move_cursor (int rows, int cols);
reload(const char * message)63     void                    reload (const char* message) {if (aData) aData->reload (message); set_data_size();}
resize()64     void                    resize () {resize(x(), y(), w(), h()); redraw();}
65     void                    resize (int x, int y, int w, int h);
row()66     int                     row () {return aCurrRow;}
67     bool                    quit_edit_mode (bool save);
68     bool                    save ();
69     void                    set_data_size();
70 
71 private:
72     enum {
73                             DRAG_NONE,
74                             DRAG_HOR,
75                             SCROLL_SIZE = 16,
76                             SCROLL_JUMP = 10,
77                             CLIP_NONE   = 0,
78                             CLIP_COL    = 1,
79                             CLIP_ROW    = 2,
80                             CLIP_BOTH   = 3,
81     };
82 
83     int                     aClipped;
84     int                     aCurrCol;
85     int                     aCurrRow;
86     int                     aStartCol;
87     int                     aStartRow;
88     int                     aVisibleRows;
89     int                     aMaxVisibleRows;
90     int                     aVisibleCols;
91     int*                    aWidth;
92     int                     aDragState;
93     int                     aDragCol;
94     int                     aActiveX;
95     int                     aActiveY;
96     int                     aActiveW;
97     int                     aActiveH;
98     int                     aActiveR;
99     int                     aActiveC;
100     char                    aSearchWord[200];
101     bool                    aCase;
102 
103     Fl_Table_Data*          aData;
104     Fl_Scrollbar*           aScrollbarHor;
105     Fl_Scrollbar*           aScrollbarVer;
106     Fl_Widget*              aEditWidget;
107     Fl_Widget*              aEventHandler;
108     Fl_Input*               aDummy;
109     Fl_Window*              aDlgParent;
110     Fl_Find*                aFind;
111 
112     int                     clip (int xpos, int ypos, int width, int height, int row = 0);
113     void                    draw_cell (int row, int col, int xpos, int ypos, int width, int height);
114     void                    draw_cell (int x, int y, int w, int h, Fl_Color bg, Fl_Color fg);
115     void                    draw_label (int xpos, int ypos);
116     void                    draw_header (int xpos, int ypos);
117     int                     draw_row (int row, int xpos, int ypos);
118     void                    ev_drag ();
119     bool                    ev_keyboard_down ();
120     void                    ev_move ();
121     void                    ev_push ();
122     void                    get_cell_pos (int& row, int& col, int& xpos, int& ypos, int& width, int& height);
123     void                    start_edit_mode (bool force = false);
set_cursor(int row,int col)124     void                    set_cursor(int row, int col) {move_cursor (row - aCurrRow, col - aCurrCol);}
125 	 friend                  void tab_fc_callback(Fl_File_Chooser *fc, void *data);
126 
127 };
128 
129 #endif
130