Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_Table_Base.h

00001 /*
00002  * $Id: Fl_Table_Base.h,v 1.3 2003/07/03 20:36:35 laza2000 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
00019  *
00020  * Fl_Table - LGPL (c)2003 Greg Ercolano 
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     // Bit mask for row/col flags. MAX 8 bytes!
00040     enum RowColFlags {
00041         NONE = 0,
00042         INVISIBLE = 1,
00043         NON_RESIZABLE = 2
00044     };
00045 
00046     // Context for table_layout and table_draw
00047     enum TableContext
00048     {
00049         CONTEXT_NONE = 0,
00050         CONTEXT_BEGIN,      // before a page is redrawn
00051         CONTEXT_END,        // after a page is redrawn
00052         CONTEXT_ROW_HEADER, // in the row header
00053         CONTEXT_COL_HEADER, // in the col header
00054         CONTEXT_CELL,       // in one of the cells
00055         CONTEXT_TABLE,      // in the table
00056         CONTEXT_SCROLLED    // Scrolled
00057     };
00058 
00059     // values for type()
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     // Resize flags for row/col resize
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     // Set transparent resize for columns and rows. Default is ON.
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     // Return x/y/w/h bounds for context.
00093     void get_bounds(TableContext context, int &X, int &Y, int &W, int &H);
00094 
00095     // Find row/col for current x/y event
00096     TableContext cursor2rowcol(unsigned &R, unsigned &C, ResizeFlag &resizeflag);
00097 
00098     // Find cell's on screen x/y/w/h for given row/col
00099     bool find_cell(TableContext context, unsigned R, unsigned C, int &X, int &Y, int &W, int &H);
00100 
00101     // Clamp r/c to known universe. Returns true, if clamped
00102     bool row_col_clamp(unsigned &R, unsigned &C);
00103     bool row_col_clamp(int &R, int &C);
00104 
00105     // Find scroll position of row (in pixels from top)
00106     int row_scroll_position(unsigned row);
00107 
00108     // Find scroll position of col (in pixels from left)
00109     int col_scroll_position(unsigned col);
00110 
00111     // Find row/col for x/y in somewhere table.
00112     // x/y must be in totalheight/totalwidth.
00113     // If row or col not found, variable is set to -1
00114     void position2rowcol(int x, int y, int &R, int &C) const;
00115 
00116     // Enable row resizing
00117     void row_resize(bool flag) { m_row_resize = flag; }
00118     bool row_resize() const { return m_row_resize; }
00119 
00120     // Enable col resizing
00121     void col_resize(bool flag) { m_col_resize = flag; }
00122     bool col_resize() const { return m_col_resize; }
00123 
00124     // Column minimum resizing width
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     // Column minimum resizing width
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     // set/get row header enable flag
00133     void row_header(bool flag) { m_row_header = flag; redraw(); relayout(); }
00134     bool row_header() const { return m_row_header; }
00135 
00136     // set/get col header enable flag
00137     void col_header(bool flag) { m_col_header = flag; redraw(); relayout(); }
00138     bool col_header() const { return m_col_header; }
00139 
00140     // set/get col header height
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     // set/get row header width
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     // set/get row height
00149     void row_height(unsigned row, int height);
00150     int row_height(unsigned row) const { return m_rowheights[row]; }
00151 
00152     // set/get a column's width
00153     void col_width(unsigned col, int width);
00154     int col_width(unsigned col) const { return m_colwidths[col]; }
00155 
00156     // set all row/col heights
00157     void row_height_all(int height);
00158     void col_width_all(int width);
00159 
00160     // Set new top row
00161     void top_row(unsigned row);
00162 
00163     // Set new left col
00164     void left_col(unsigned col);
00165 
00166     // Show row, returns true if scrolled
00167     bool show_row(unsigned row);
00168 
00169     // Show col, returns true if scrolled
00170     bool show_col(unsigned col);
00171 
00172     // Set/get Y scroll position
00173     void yposition(int Y);
00174     int yposition() const { return (int)vscrollbar->value(); }
00175 
00176     // Set/get X scroll position
00177     void xposition(int X);
00178     int xposition() const { return (int)hscrollbar->value(); }
00179 
00180     // Returns virtual height of table
00181     int totalheight() const { return table_h; }
00182 
00183     // Returns virtual width of table
00184     int totalwidth()  const { return table_w; }
00185 
00187     // Flags handling for row/col
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     // Set/get visibilty for row
00195     bool visible_row(int row) const { return !(m_rowflags[row]&INVISIBLE); }
00196     void visible_row(int row, bool val);
00197 
00198     // Set/get visibilty for col
00199     bool visible_col(int col) const { return !(m_colflags[col]&INVISIBLE); }
00200     void visible_col(int col, bool val);
00201 
00202     // Set/get resizable for individual row
00203     bool resizable_row(int row) const { return !(m_rowflags[row]&NON_RESIZABLE); }
00204     void resizable_row(int row, bool val);
00205 
00206     // Set/get resizable for individual col
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     // set/get number of rows
00213     virtual void row_count(unsigned count);
00214     unsigned row_count() const { return m_rows; }
00215 
00216     // set/get number of columns
00217     virtual void col_count(unsigned count);
00218     unsigned col_count() const { return m_cols; }
00219 
00220     // Default width for created columns
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     // Default height for created rows
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     // Called to draw cells
00229     // overridden by deriving class
00230     virtual void table_draw(TableContext context, unsigned R, unsigned C, int X, int Y, int W, int H) = 0;
00231 
00232     // Called when ever table gets resized or scrolled.
00233     // In CONTEXT_SCROLLED, row/col is set to top/left.
00234     virtual void table_layout(TableContext context, unsigned row, unsigned col) { }
00235 
00236     // You should use this to handle events.
00237     virtual int table_handle(TableContext context, unsigned row, unsigned col, int event) { return 0; }
00238 
00239     // table's virtual size (in pixels)
00240     int table_w, table_h;
00241 
00242     // top/left corners of viewable table
00243     unsigned toprow, leftcol;     //Row/col positions
00244     unsigned toprow_y, leftcol_x; //Scroll positions
00245 
00246     // Dimensions:
00247     // data table dimension xywh: E.G. tix = wix+(row_header()?row_header_width():0;
00248     int tix, tiy, tiw, tih;
00249     // widget inner dimension xywh: E.G. wih = h()-box()->dh()
00250     int wix, wiy, wiw, wih;
00251 
00252     // vertical scrollbar
00253     Fl_Scrollbar *vscrollbar;
00254     // horizontal scrollbar
00255     Fl_Scrollbar *hscrollbar;
00256 
00257     // Recalculate row lookup, this is needed when some row has changed
00258     // it's height. Or row count changed.
00259     void recalc_row_lookup() { m_recalc_row_lookup=true; relayout(); }
00260 
00261     // Returns cached row and set y to cached position.
00262     unsigned find_safe_top(int ypos, int &y) const;
00263 
00264     // Class maintenance. shows/hides scrollbar.
00265     void recalc_dimensions();
00266 
00267     // change mouse cursor to some other shape
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;    // Total rows
00275     unsigned m_cols;    // Total cols
00276 
00277     int m_default_row_h; // Default row height for new rows
00278     int m_default_col_w; // Default col width for new cols
00279 
00280     int m_row_header_w; // width of row header
00281     int m_col_header_h; // height of column header
00282 
00283     bool m_row_header;  // row header enabled?
00284     bool m_row_resize;  // row resizing enabled?
00285 
00286     bool m_col_header;  // col header enabled?
00287     bool m_col_resize;  // col resizing enabled?
00288 
00289     int m_row_resize_min; // row minimum resizing height (default=1)
00290     int m_col_resize_min; // col minimum resizing width (default=1)
00291 
00292     Fl_Int_List m_colwidths;  // column widths in pixels
00293     Fl_Int_List m_rowheights; // row heights in pixels
00294 
00295     bool m_scrolled; //True after scroll, turned off by layout()
00296     bool m_row_cols_changed;
00297 
00298     // Y position / row lookup, this makes HUGE tables usable also.
00299     // yposition stored for each 1000 rows.
00300     Fl_Int_List m_row_lookup;
00301     bool m_recalc_row_lookup;
00302     void calc_row_lookup();
00303 
00304     // last mouse cursor before changed to 'resize' cursor
00305     Fl_Cursor m_last_cursor;
00306 
00307     // Flags for rows
00308     unsigned m_rowflags_size; // Size of allocated space in m_rowflags
00309     uchar *m_rowflags;        // Pointer to hold flags
00310 
00311     // Flags for cols
00312     unsigned m_colflags_size; // Size of allocated space in m_rowflags
00313     uchar *m_colflags;        // Pointer to hold flags
00314 
00315     void ctor_init();
00316 };
00317 
00318 #endif

Generated on Thu Jul 31 15:33:45 2003 for eFLTK by doxygen1.2.15