Fl_Group | +----Fl_Table | +----Fl_Table_Row
#include <FL/Fl_Table_Row.H>
Most methods of importance will be found in the Fl_Table widget, such as rows() and cols().
To be useful it must be subclassed and at minimum the draw_cell() method must be overridden to provide the content of the cells. This widget does not manage the cell's data content; it is up to the parent class's draw_cell() method override to provide this.
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().
|
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; see also visible_cells()) |
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 dimension of the cell.
A minimal draw_cell() override might look like the following. 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_Table telling us its starting to draw page fl_font(FL_HELVETICA, 16); return; case CONTEXT_ROW_HEADER: // Fl_Table telling us it's draw row/col headers 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_Table telling us to draw cells 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 rows in the table.
You can check if a row is selected with row_selected(row).
Fl_Table_Row::SELECT_NONE | No selection allowed |
Fl_Table_Row::SELECT_SINGLE | Only single rows can be selected |
Fl_Table_Row::SELECT_MULTI | Multiple rows can be selected |