edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | List of all members
TableBase Class Reference

A base class for table widgets. More...

`#include <edelib/TableBase.h>`

Inheritance diagram for TableBase:

## Public Types

enum | TableContext { CONTEXT_NONE = 0, CONTEXT_STARTPAGE = 0x01, CONTEXT_ENDPAGE = 0x02, CONTEXT_ROW_HEADER = 0x04, CONTEXT_COL_HEADER = 0x08, CONTEXT_CELL = 0x10, CONTEXT_TABLE = 0x20, CONTEXT_RC_RESIZE = 0x40 }
| What happened in table callback. More...

## Public Member Functions

| TableBase (int X, int Y, int W, int H, const char *l=0)
| ~TableBase ()
virtual void | clear ()
void | table_box (Fl_Boxtype val)
Fl_Boxtype | table_box (void)
virtual void | rows (int val)
int | rows ()
virtual void | cols (int val)
int | cols ()
void | visible_cells (int &r1, int &r2, int &c1, int &c2)
int | is_interactive_resize ()
void | row_resize (int flag)
int | row_resize ()
void | col_resize (int flag)
int | col_resize ()
void | col_resize_min (int val)
int | col_resize_min ()
void | row_resize_min (int val)
int | row_resize_min ()
void | row_header (int flag)
int | row_header ()
void | col_header (int flag)
int | col_header ()
void | col_header_height (int height)
int | col_header_height ()
void | row_header_width (int width)
int | row_header_width ()
void | row_header_color (Fl_Color val)
Fl_Color | row_header_color ()
void | col_header_color (Fl_Color val)
Fl_Color | col_header_color ()
void | row_height (int row, int height)
int | row_height (int row)
void | col_width (int col, int width)
int | col_width (int col)
void | row_height_all (int height)
void | col_width_all (int width)
void | row_position (int row)
int | row_position ()
void | col_position (int col)
int | col_position ()
void | top_row (int row)
int | top_row ()
int | is_selected (int r, int c)
void | get_selection (int &s_top, int &s_left, int &s_bottom, int &s_right)
void | set_selection (int s_top, int s_left, int s_bottom, int s_right)
int | move_cursor (int R, int C)
void | resize (int X, int Y, int W, int H)
void | draw (void)
void | init_sizes ()
void | add (Fl_Widget &widget)
void | add (Fl_Widget *widget)
void | insert (Fl_Widget &widget, int n)
void | insert (Fl_Widget &widget1, Fl_Widget *widget2)
void | remove (Fl_Widget &widget)
void | begin ()
void | end ()
int | callback_row ()
int | callback_col ()
TableContext | callback_context ()
void | do_callback (TableContext context, int row, int col)

## Detailed Description

A base class for table widgets.

TableBase is incarnation of excelent Fl_Table widget, written by Greg Ercolano. To be useful, it must be subclassed and several virtual functions defined.

This widget does not handle the data in the table. draw_cell() must be overridden by a subclass to manage drawing the content of the cells.

Drawing (and callbacks, later explained) are done via contexts. Contexts shows what parts should be redrawn or are changed by user when callbacks are used.

See Also
  TableContext

Here is the simple table implementation:

// table callback
void table_cb(Fl_Widget*, void* data) {
MyTable* t = (MyTable*)data;
t->table_callback();
}
class MyTable : public TableBase {
protected:
void draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H) {
switch(context):
case CONTEXT_STARTPAGE:
// When table or parts of the table are about to be redraw. Use it to initialize
// static data such a font selections or to lock a database before accessing.
// Here R and C will be zero and X, Y, W and H will have table dimensions.
break;
case CONTEXT_ENDPAGE:
// When table has completed being redrawn. Useful for unlocking a database after accessing.
// Here R and C will be zero and X, Y, W and H will have table dimensions.
break;
case CONTEXT_ROW_HEADER:
// When row header cell needs to be redrawn
case CONTEXT_COL_HEADER:
// When columnt header cell needs to be redrawn
// Our table has both row and column headers so draw it
fl_push_clip(X, Y, W, H);
fl_draw_box(FL_UP_BOX, X, Y, W, H, color());
fl_color(FL_BLACK);
// draw "demo" label in each header cell
fl_draw("demo", X, Y, W, H, FL_ALIGN_LEFT);
fl_pop_clip();
break;
case CONTEXT_CELL:
// When data in cells needs to be redrawn
// Here, each cells will have borders and contains "foo" label
fl_push_clip(X, Y, W, H);
// background color
fl_color(FL_WHITE);
fl_rectf(X, Y, W, H);
// text
fl_color(FL_BLACK);
fl_draw("foo", X, Y, W, H, FL_ALIGN_CENTER);
// border
fl_color(FL_GRAY);
fl_rect(X, Y, W, H);
fl_pop_clip();
break;
default:
break;
}
public:
MyTable() {
// table used frames, not boxes
box(FL_DOWN_FRAME);
// let we get all events
when(FL_WHEN_CHANGED | FL_WHEN_RELEASED);
// register our callback
callback(table_cb, this);
}
void table_callback() {
// changed row
int R = callback_row();
// changed column
int C = callback_col();
// context
TableContext context = callback_context();
if(context == CONTEXT_ROW_HEADER) {
// clicked on a row header
// excludes resizing
} else if(context == CONTEXT_COL_HEADER) {
// clicked on a column header
// excludes resizing
} else if(context == CONTEXT_CELL) {
// clicked on a cell
// to receive callback for FL_RELEASE events, you must set when(FL_WHEN_RELEASE)
} else if(context == CONTEXT_RC_RESIZE) {
// resized columns or rows interactively or via col_width() and row_height()
// is_interactive_resize() should be used to determine interactive resize
//
// if row is resized, R will have row number and C will be 0
// if column is resized, C will have column number and R will be 0
//
// to receive resize evenys, you must set when(FL_WHEN_CHANGED)
}
}
};

Since TableBase is inherited from Fl_Group, it can be container for FLTK widgets too. In that case there is no need to use CONTEXT_CELL in draw_cell() and draw widgets: they will be drawn by itself. The only thing you should use is to add() them, as any other widget is addet to Fl_Group.

## Member Enumeration Documentation

enum TableContext

What happened in table callback.

Enumerator:

  CONTEXT_STARTPAGE | before a page is redrawn
  CONTEXT_ENDPAGE | after a page is redrawn
  CONTEXT_ROW_HEADER | in the row header
  CONTEXT_COL_HEADER | in the col header
  CONTEXT_CELL | in one of the cells
  CONTEXT_TABLE | in the table
  CONTEXT_RC_RESIZE | column or row being resized

## Constructor & Destructor Documentation

TableBase | ( | int | X,
|  | int | Y,
|  | int | W,
|  | int | H,
|  | const char * | l = `0`
| ) |  |

The constructor that creates empty table with no rows or columns. Resizing of rows or columns is disabled. Header is not drawn too.

~TableBase | ( |  | ) |

Destroys the table and associated widgets

## Member Function Documentation

void add | ( | Fl_Widget & | widget | ) |

inline

Append widget to the table

void add | ( | Fl_Widget * | widget | ) |

inline

Append widget to the table

void begin | ( | void |  | ) |

inline

Same as Fl_Group::begin()

int callback_col | ( |  | ) |

inline

Returns the current column event occured on. This function should be used from user's callback set with callback()

TableContext callback_context | ( |  | ) |

inline

Returns current TableContext

int callback_row | ( |  | ) |

inline

Returns the current row event occured on. This function should be used from user's callback set with callback()

virtual void clear | ( | void |  | ) |

inline virtual

Clears the table

void col_header | ( | int | flag | ) |

inline

Enable or disable showing column headers. 1 will enable them and 0 will disable them. Table will be redrawn after this call

int col_header | ( |  | ) |

inline

Returns 1 if column headers are shown or 0 if not

void col_header_color | ( | Fl_Color | val | ) |

inline

Sets the column header color. Table will be then redrawn

Fl_Color col_header_color | ( |  | ) |

inline

Returns the current column header color

void col_header_height | ( | int | height | ) |

inline

Sets the column header heights. Table will be then redrawn

int col_header_height | ( |  | ) |

inline

Returns the column header heights

void col_position | ( | int | col | ) |

Sets the table's current column scroll position

int col_position | ( |  | ) |

inline

Returns the current columnscroll position

void col_resize | ( | int | flag | ) |

inline

Allow or disallow column resizing. If 1 is used, column will be resized; 0 is for opposite. Since interactive resizing is done via the column headers, col_header() must also be enabled to allow resizing

int col_resize | ( |  | ) |

inline

Returns 1 if column can be resized or 0 if not

void col_resize_min | ( | int | val | ) |

inline

Sets the current column minimum resize value. Must be a value >= 1

int col_resize_min | ( |  | ) |

inline

Returns the current column minimum resize value

void col_width | ( | int | col,
|  | int | width
| ) |  |

Sets the width of the specified column in pixels and table is redrawn. callback() will be invoked with CONTEXT_RC_RESIZE if the column's width was actually changed and when() is FL_WHEN_CHANGED

int col_width | ( | int | col | ) |

inline

Returns the current height of specified column

void col_width_all | ( | int | width | ) |

inline

Sets the width of all columns to the same value. Table is redrawn then

virtual void cols | ( | int | val | ) |

virtual

Sets the number of columns in the table. Table is redraw

int cols | ( |  | ) |

inline

Returns the number of columns in the table

void do_callback | ( | TableContext | context,
|  | int | row,
|  | int | col
| ) |  |

inline

Execute user's callback with given TableContext, row and column

void draw | ( | void |  | ) |

Draw the table (called by FLTK)

void end | ( | void |  | ) |

inline

Same as Fl_Group::end()

void get_selection | ( | int & | s_top,
|  | int & | s_left,
|  | int & | s_bottom,
|  | int & | s_right
| ) |  |

Returns selected rows and columns. Values will be leftmost/rightmost column and topmost/bottommost rows

This function is used to return bounds of multiple selected cells

void init_sizes | ( |  | ) |

inline

Calls Fl_Group::init_sizes(). Table will be redrawn

void insert | ( | Fl_Widget & | widget,
|  | int | n
| ) |  |

inline

Same as Fl_Group::insert()

void insert | ( | Fl_Widget & | widget1,
|  | Fl_Widget * | widget2
| ) |  |

inline

Same as Fl_Group::insert()

int is_interactive_resize | ( |  | ) |

inline

Returns 1 if row or column is interactively resized or 0 if not

int is_selected | ( | int | r,
|  | int | c
| ) |  |

Returns 1 if the cell with the given row and column values is selected

int move_cursor | ( | int | R,
|  | int | C
| ) |  |

Selects cell at the given row/column position

Todo:
  This function should be called select_cell() or similar

void remove | ( | Fl_Widget & | widget | ) |

inline

Remove a widget from the table

void resize | ( | int | X,
|  | int | Y,
|  | int | W,
|  | int | H
| ) |  |

Resize table. Table is redrawn

void row_header | ( | int | flag | ) |

inline

Enable or disable showing row headers. 1 will enable them and 0 will disable them. Table will be redrawn after this call

int row_header | ( |  | ) |

inline

Returns 1 if row headers are shown or 0 if not

void row_header_color | ( | Fl_Color | val | ) |

inline

Sets the row header color. Table will be then redrawn

Fl_Color row_header_color | ( |  | ) |

inline

Returns the current row header color

void row_header_width | ( | int | width | ) |

inline

Sets the row header heights. Table will be then redrawn

int row_header_width | ( |  | ) |

inline

Returns the row header heights

void row_height | ( | int | row,
|  | int | height
| ) |  |

Sets the height of the specified row in pixels and table is redrawn. callback() will be invoked with CONTEXT_RC_RESIZE if the row's height was actually changed and when() is FL_WHEN_CHANGED

int row_height | ( | int | row | ) |

inline

Returns the current height of specified row

void row_height_all | ( | int | height | ) |

inline

Sets the height of all rows to the same value. Table is redrawn then

void row_position | ( | int | row | ) |

Sets the table's current row scroll position

int row_position | ( |  | ) |

inline

Returns the current row scroll position

void row_resize | ( | int | flag | ) |

inline

Allow or disallow row resizing. If 1 is used, row will be resized; 0 is for opposite. Since interactive resizing is done via the row headers, row_header() must also be enabled to allow resizing

int row_resize | ( |  | ) |

inline

Returns 1 if rows can be resized or 0 if not

void row_resize_min | ( | int | val | ) |

inline

Sets the current row minimum resize value. Must be a value >= 1

int row_resize_min | ( |  | ) |

inline

Returns the current row minimum resize value

virtual void rows | ( | int | val | ) |

virtual

Sets the number of rows in the table. Table is redrawn

int rows | ( |  | ) |

inline

Returns the number of rows in the table

void set_selection | ( | int | s_top,
|  | int | s_left,
|  | int | s_bottom,
|  | int | s_right
| ) |  |

Select's rows and columns. Values should be leftmost/rightmost column and topmost/bottommost rows

This function is used to select multiple cells

void table_box | ( | Fl_Boxtype | val | ) |

inline

Sets a kind of box around the table (default is FL_NO_BOX). Calling this function will redraw table

Fl_Boxtype table_box | ( | void |  | ) |

inline

Returns the current box type used for the data table

void top_row | ( | int | row | ) |

inline

Sets which row should be at the top of the table, scrolling as necessary. Table is redrawn

int top_row | ( |  | ) |

inline

Returns the current top row. This row may be partially obscured

void visible_cells | ( | int & | r1,
|  | int & | r2,
|  | int & | c1,
|  | int & | c2
| ) |  |

inline

Returns the range of row and column numbers for all the visible and partially visible cells in the table.

These values can be used e.g. by draw_cell() during CONTEXT_STARTPAGE to figure out what cells are about to be redrawn, for the purposes of locking the data from a database befire it's drawn

The documentation for this class was generated from the following file:

- edelib/TableBase.h