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_Data_h
9 #define Fl_Table_Data_h
10 
11 #include <stdio.h>
12 #include <string.h>
13 #include <FL/Fl.H>
14 
15 class Fl_Choice;
16 class Fl_Dialog;
17 class Fl_Widget;
18 
19 
20 
21 enum FL_TABLE_EDITOR {
22     FL_NO_EDITOR = 0,
23     FL_TEXT_EDITOR,
24     FL_INTEGER_EDITOR,
25     FL_FLOAT_EDITOR,
26     FL_BOOL_EDITOR,
27     FL_SECRET_EDITOR,
28     FL_LIST_EDITOR,
29     FL_DLG_LIST_EDITOR,
30     FL_DLG_COLOR_EDITOR,
31     FL_DLG_FILE_EDITOR,
32     FL_DLG_DIR_EDITOR,
33     FL_DLG_CUSTOM_EDITOR,
34 };
35 
36 enum FL_TABLE_ROWS {
37     FL_NO_ROW     = -4,
38     FL_ACTIVE_ROW = -3,
39     FL_LABEL_ROW  = -2,
40     FL_HEADER_ROW = -1,
41     FL_ROW        =  0,
42 };
43 
44 
45 
46 /**
47 *  Inherit form this interface to supply data to Fl_Table widget.
48 *  To be useful the value,cols,rows,editor,editor_type methods must be implemented.
49 */
50 class Fl_Table_Data {
51 public:
Fl_Table_Data()52                             Fl_Table_Data () {aHeader = true; aLabel = true; aDirty = false; aStripe = FL_WHITE; aBorder = true;}
~Fl_Table_Data()53     virtual                 ~Fl_Table_Data() {;}
54 
border(bool d)55     void                    border (bool d) {aBorder = d;}
border()56     bool                    border () {return aBorder;}
dirty(bool d)57     void                    dirty (bool d) {aDirty = d;}
dirty()58     bool                    dirty () {return aDirty;}
editor(int row,int col,bool force_editor)59     Fl_Widget*              editor (int row, int col, bool force_editor) {return get_editor (editor_type (row, col, force_editor), row, col);}
show_header()60     bool                    show_header () {return aHeader;}
show_header(bool header)61     void                    show_header (bool header) {aHeader = header;}
show_label()62     bool                    show_label () {return aLabel;}
show_label(bool label)63     void                    show_label (bool label) {aLabel = label;}
stripe()64     Fl_Color                stripe () {return aStripe;}
stripe(Fl_Color c)65     void                    stripe (Fl_Color c) {aStripe = c;}
66 
add()67     virtual void            add () {;}
align(int row,int col)68     virtual Fl_Align        align (int row, int col) {return FL_ALIGN_LEFT;}
69     virtual Fl_Color        border_color (int row, int col);
70     virtual Fl_Color        box_color (int row, int col);
choice(int row,int col,int & size,int & selected,char * label)71     virtual const char**    choice (int row, int col, int& size, int& selected, char* label) {size = 0; selected = 0; strncpy (label, "Select Item", 20); return 0;}
72     virtual int             cols ()  = 0;
custom_dialog(int row,int col)73     virtual Fl_Dialog*      custom_dialog (int row, int col) {return 0;}
editor_type(int row,int col,bool force_custom)74     virtual FL_TABLE_EDITOR editor_type (int row, int col, bool force_custom) {return FL_TEXT_EDITOR;}
erase(int row)75     virtual void            erase (int row) {;}
insert(int row)76     virtual void            insert (int row) {;}
data()77     virtual void*           data () {return 0;}
height(int row)78     virtual int             height (int row) {if (row == FL_LABEL_ROW) return 30; else if (row == FL_HEADER_ROW) return 24; else return 20;}
reload(const char * message)79     virtual void            reload (const char* message) {;}
80     virtual int             rows() = 0;
save()81     virtual int             save () {return -1;}
sort(int col,bool ascent)82     virtual void            sort (int col, bool ascent) {;}
textcolor(int row,int col)83     virtual Fl_Color        textcolor (int row, int col) {return FL_BLACK;}
textfont(int row,int col)84     virtual Fl_Font         textfont (int row, int col) {if (row == FL_LABEL_ROW || row == FL_HEADER_ROW) return FL_HELVETICA_BOLD ; else return FL_HELVETICA;}
textsize(int row,int col)85     virtual int             textsize (int row, int col) {if (row == FL_LABEL_ROW) return 20; else if (row == FL_HEADER_ROW) return 12; else return 10;}
value(const char * data,int row,int col)86     virtual bool            value (const char* data, int row, int col) {return true;}
value(int row,int col)87     virtual const char*     value (int row, int col) {if (row == FL_LABEL_ROW) return ""; else snprintf(aBuffer, 199, "%d - %d", row, col); return aBuffer;}
width(int col)88     virtual int             width (int col) {return 100;}
89 
90 protected:
91     Fl_Widget*              get_editor (FL_TABLE_EDITOR type, int row, int col);
92 
93 private:
94     char                    aBuffer[200];
95     char                    aDlgLabel[200];
96     char*                   aDefaultList[2];
97     Fl_Color                aStripe;
98     bool                    aDirty;
99     bool                    aHeader;
100     bool                    aBorder;
101     bool                    aLabel;
102 };
103 
104 #endif
105