Fl_Group | +----Fl_Table | +----Fl_Table_Row
#include <FL/Fl_Table.H>
This widget does not handle the data in the table. The draw_cell() method must be overridden by a subclass to manage drawing the contents of the cells.
This widget can act as a container for FLTK widgets (see widgettable.cxx), or custom widgets (see testtablerow.cxx, with custom widgets being optimal for very large tables.
When acting as a container for custom widgets, events on the cells and/or headings generate callbacks when they are clicked by the user. You control when events are generated based on the values you supply for when().
When acting as a container for FLTK widgets, the fltk widgets maintain themselves, and although the draw_cell() method must be overridden, its contents can be very simple. (See the draw_cell() code in widgettable.cxx).
context will be one of the following:
row and col will be set to the row and column number the user clicked on. If someone clicked on a row header, col will be 0. If someone clicked on a column header, row will be 0.
Using these values is necessary to ensure the caller doesn't accidentally access the Fl_Table's internal widgets (such as the scroll bars).
Typically used in loops, eg:
for ( int x = child_start(); x < child_end(); x++ ) { Fl_Widget *w = children(x); [..] }
Only cells that are completely (or partially) visible will be told to draw.
context will be one of the following:
Fl_Table::CONTEXT_STARTPAGE | When table, or parts of the table, are about to be redrawn. Use to initialize static data, such as font selections. r/c will be zero, x/y/w/h will be the dimensions of the table's entire data area. (Useful for locking a database before accessing) |
Fl_Table::CONTEXT_ENDPAGE | When table has completed being redrawn. r/c will be zero, x/y/w/h dimensions of table's data area. (Useful for unlocking a database after accessing) |
Fl_Table::CONTEXT_ROW_HEADER | Whenever a row header cell needs to be drawn. |
Fl_Table::CONTEXT_COL_HEADER | Whenever a column header cell needs to be drawn. |
Fl_Table::CONTEXT_CELL | Whenever a data cell in the table needs to be drawn. |
Fl_Table::CONTEXT_RC_RESIZE | Whenever table or row/column is resized or scrolled. (Useful for fltk containers that need to resize or move the child fltk widgets.) |
row and col will be set to the row and column number the user clicked on. In the case of row headers, col will be 0. In the case of column headers, row will be 0.
x/y/w/h will be the position and dimensions of where the cell should be drawn.
In the case of custom widgets, a minimal draw_cell() override might look like the following. With custom widgets it is up to the caller to handle drawing everything within the dimensions of the cell, including handling the selection color. Note all clipping must be handled as well; this allows drawing outside the dimensions of the cell if so desired for 'custom effects'.
void MyTable::draw_cell(TableContext context, int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0) { static char s[40]; sprintf(s, "%d/%d", R, C); // text for each cell switch ( context ) { case CONTEXT_STARTPAGE: fl_font(FL_HELVETICA, 16); return; case CONTEXT_ROW_HEADER: case CONTEXT_COL_HEADER: fl_push_clip(X, Y, W, H); { fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, color()); fl_color(FL_BLACK); fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); } fl_pop_clip(); return; case CONTEXT_CELL: fl_push_clip(X, Y, W, H); { // BG COLOR fl_color( row_selected(R) ? selection_color() : FL_WHITE); fl_rectf(X, Y, W, H); // TEXT fl_color(FL_BLACK); fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); // BORDER fl_color(FL_LIGHT2); fl_rect(X, Y, W, H); } fl_pop_clip(); return; default: return; } //NOTREACHED }
The second form returns the number of columns in the table.
The second form returns if column headers are enabled or not; 1=enabled, 0=disabled.
The second form returns the current column header color.
The second form returns the current column header height (in pixels).
The second form returns the current column minimum resize value.
The second form returns the current column scroll position as a column number.
The second form returns the current value of this flag.
The second form returns the current width of the specified column in pixels and causes the screen to redraw.
The second form returns the number of rows in the table.
The second form returns the value of this flag.
The second form returns the current row header color.
The second form returns the current row header width (in pixels).
The second form returns the current row minimum resize value.
The second form returns the current row scroll position as a row number.
The second form returns the current value of this flag.
The second form returns the current height of the specified row as a value in pixels.
The second form returns the current box type used for the data table.
The second form returns the current top row shown in the table. This row may be partially obscured.
The second form returns the current value of when().