00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef _FL_LISTVIEW_BASE_H_
00024 #define _FL_LISTVIEW_BASE_H_
00025 
00026 #include <efltk/Fl.h>
00027 #include <efltk/Fl_Group.h>
00028 #include <efltk/Fl_Box.h>
00029 #include <efltk/Fl_Scrollbar.h>
00030 
00036 class FL_API Fl_Table_Base : public Fl_Group
00037 {
00038 public:
00039     
00040     enum RowColFlags {
00041         NONE = 0,
00042         INVISIBLE = 1,
00043         NON_RESIZABLE = 2
00044     };
00045 
00046     
00047     enum TableContext
00048     {
00049         CONTEXT_NONE = 0,
00050         CONTEXT_BEGIN,      
00051         CONTEXT_END,        
00052         CONTEXT_ROW_HEADER, 
00053         CONTEXT_COL_HEADER, 
00054         CONTEXT_CELL,       
00055         CONTEXT_TABLE,      
00056         CONTEXT_SCROLLED    
00057     };
00058 
00059     
00060     enum TypeValues {
00061         HORIZONTAL          = 1,
00062         VERTICAL            = 2,
00063         BOTH                = 3,
00064         ALWAYS_ON           = 4,
00065         HORIZONTAL_ALWAYS   = 5,
00066         VERTICAL_ALWAYS     = 6,
00067         BOTH_ALWAYS         = 7,
00068         TRANSPARENT_RESIZE  = 8
00069     };
00070 
00071     
00072     enum ResizeFlag {
00073         RESIZE_NONE      = 0,
00074         RESIZE_COL_LEFT  = 1,
00075         RESIZE_COL_RIGHT = 2,
00076         RESIZE_ROW_ABOVE = 3,
00077         RESIZE_ROW_BELOW = 4
00078     };
00079 
00080     Fl_Table_Base(int X, int Y, int W, int H, const char *l=0);
00081     Fl_Table_Base(const char *l = 0, int layout_size=30, Fl_Align layout_al=FL_ALIGN_TOP, int label_w=-1);
00082     virtual ~Fl_Table_Base();
00083 
00084     virtual int handle(int e);
00085     virtual void layout();
00086     virtual void draw();
00087 
00088     
00089     bool transparent_resize() const { return ((type() & TRANSPARENT_RESIZE)==TRANSPARENT_RESIZE); }
00090     void transparent_resize(bool v) { if(v) type(type()|TRANSPARENT_RESIZE); else type(type()&~TRANSPARENT_RESIZE); }
00091 
00092     
00093     void get_bounds(TableContext context, int &X, int &Y, int &W, int &H);
00094 
00095     
00096     TableContext cursor2rowcol(unsigned &R, unsigned &C, ResizeFlag &resizeflag);
00097 
00098     
00099     bool find_cell(TableContext context, unsigned R, unsigned C, int &X, int &Y, int &W, int &H);
00100 
00101     
00102     bool row_col_clamp(unsigned &R, unsigned &C);
00103     bool row_col_clamp(int &R, int &C);
00104 
00105     
00106     int row_scroll_position(unsigned row);
00107 
00108     
00109     int col_scroll_position(unsigned col);
00110 
00111     
00112     
00113     
00114     void position2rowcol(int x, int y, int &R, int &C) const;
00115 
00116     
00117     void row_resize(bool flag) { m_row_resize = flag; }
00118     bool row_resize() const { return m_row_resize; }
00119 
00120     
00121     void col_resize(bool flag) { m_col_resize = flag; }
00122     bool col_resize() const { return m_col_resize; }
00123 
00124     
00125     void col_resize_min(unsigned val) { m_col_resize_min = (int)val; }
00126     int col_resize_min() const { return m_col_resize_min; }
00127 
00128     
00129     void row_resize_min(unsigned val) { m_row_resize_min = (int)val; }
00130     int row_resize_min() const { return m_row_resize_min; }
00131 
00132     
00133     void row_header(bool flag) { m_row_header = flag; redraw(); relayout(); }
00134     bool row_header() const { return m_row_header; }
00135 
00136     
00137     void col_header(bool flag) { m_col_header = flag; redraw(); relayout(); }
00138     bool col_header() const { return m_col_header; }
00139 
00140     
00141     void col_header_height(int height) { m_col_header_h = height; redraw(); relayout(); }
00142     int col_header_height() const { return m_col_header_h; }
00143 
00144     
00145     void row_header_width(int width) { m_row_header_w = width; redraw(); relayout(); }
00146     int row_header_width() const { return m_row_header_w; }
00147 
00148     
00149     void row_height(unsigned row, int height);
00150     int row_height(unsigned row) const { return m_rowheights[row]; }
00151 
00152     
00153     void col_width(unsigned col, int width);
00154     int col_width(unsigned col) const { return m_colwidths[col]; }
00155 
00156     
00157     void row_height_all(int height);
00158     void col_width_all(int width);
00159 
00160     
00161     void top_row(unsigned row);
00162 
00163     
00164     void left_col(unsigned col);
00165 
00166     
00167     bool show_row(unsigned row);
00168 
00169     
00170     bool show_col(unsigned col);
00171 
00172     
00173     void yposition(int Y);
00174     int yposition() const { return (int)vscrollbar->value(); }
00175 
00176     
00177     void xposition(int X);
00178     int xposition() const { return (int)hscrollbar->value(); }
00179 
00180     
00181     int totalheight() const { return table_h; }
00182 
00183     
00184     int totalwidth()  const { return table_w; }
00185 
00187     
00188     void row_flags(int row, uchar flags) { m_rowflags[row] = flags; }
00189     uchar row_flags(int row) const { return m_rowflags[row]; }
00190 
00191     void col_flags(int row, uchar flags) { m_colflags[row] = flags; }
00192     uchar col_flags(int row) const { return m_colflags[row]; }
00193 
00194     
00195     bool visible_row(int row) const { return !(m_rowflags[row]&INVISIBLE); }
00196     void visible_row(int row, bool val);
00197 
00198     
00199     bool visible_col(int col) const { return !(m_colflags[col]&INVISIBLE); }
00200     void visible_col(int col, bool val);
00201 
00202     
00203     bool resizable_row(int row) const { return !(m_rowflags[row]&NON_RESIZABLE); }
00204     void resizable_row(int row, bool val);
00205 
00206     
00207     bool resizable_col(int col) const { return !(m_colflags[col]&NON_RESIZABLE); }
00208     void resizable_col(int col, bool val);
00209 
00210 protected:
00211 
00212     
00213     virtual void row_count(unsigned count);
00214     unsigned row_count() const { return m_rows; }
00215 
00216     
00217     virtual void col_count(unsigned count);
00218     unsigned col_count() const { return m_cols; }
00219 
00220     
00221     int default_col_width() const { return m_default_col_w; }
00222     void default_col_width(int w) { m_default_col_w = w; }
00223 
00224     
00225     int default_row_height() const { return m_default_row_h; }
00226     void default_row_height(int h) { m_default_row_h = h; }
00227 
00228     
00229     
00230     virtual void table_draw(TableContext context, unsigned R, unsigned C, int X, int Y, int W, int H) = 0;
00231 
00232     
00233     
00234     virtual void table_layout(TableContext context, unsigned row, unsigned col) { }
00235 
00236     
00237     virtual int table_handle(TableContext context, unsigned row, unsigned col, int event) { return 0; }
00238 
00239     
00240     int table_w, table_h;
00241 
00242     
00243     unsigned toprow, leftcol;     
00244     unsigned toprow_y, leftcol_x; 
00245 
00246     
00247     
00248     int tix, tiy, tiw, tih;
00249     
00250     int wix, wiy, wiw, wih;
00251 
00252     
00253     Fl_Scrollbar *vscrollbar;
00254     
00255     Fl_Scrollbar *hscrollbar;
00256 
00257     
00258     
00259     void recalc_row_lookup() { m_recalc_row_lookup=true; relayout(); }
00260 
00261     
00262     unsigned find_safe_top(int ypos, int &y) const;
00263 
00264     
00265     void recalc_dimensions();
00266 
00267     
00268     void change_cursor(Fl_Cursor newcursor);
00269 
00270     static void cb_vscrollbar(Fl_Scrollbar *s, Fl_Table_Base *d) { d->yposition((int)s->value()); }
00271     static void cb_hscrollbar(Fl_Scrollbar *s, Fl_Table_Base *d) { d->xposition((int)s->value()); }
00272 
00273 private:
00274     unsigned m_rows;    
00275     unsigned m_cols;    
00276 
00277     int m_default_row_h; 
00278     int m_default_col_w; 
00279 
00280     int m_row_header_w; 
00281     int m_col_header_h; 
00282 
00283     bool m_row_header;  
00284     bool m_row_resize;  
00285 
00286     bool m_col_header;  
00287     bool m_col_resize;  
00288 
00289     int m_row_resize_min; 
00290     int m_col_resize_min; 
00291 
00292     Fl_Int_List m_colwidths;  
00293     Fl_Int_List m_rowheights; 
00294 
00295     bool m_scrolled; 
00296     bool m_row_cols_changed;
00297 
00298     
00299     
00300     Fl_Int_List m_row_lookup;
00301     bool m_recalc_row_lookup;
00302     void calc_row_lookup();
00303 
00304     
00305     Fl_Cursor m_last_cursor;
00306 
00307     
00308     unsigned m_rowflags_size; 
00309     uchar *m_rowflags;        
00310 
00311     
00312     unsigned m_colflags_size; 
00313     uchar *m_colflags;        
00314 
00315     void ctor_init();
00316 };
00317 
00318 #endif