edelib 2.1.0
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):
// 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;
// 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;
// When row header cell needs to be redrawn
// 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;
// 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
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)
}
}
};
A base class for table widgets.
Definition TableBase.h:166
int callback_row()
Definition TableBase.h:692
TableContext
What happened in table callback.
Definition TableBase.h:172
@ CONTEXT_CELL
in one of the cells
Definition TableBase.h:178
@ CONTEXT_STARTPAGE
before a page is redrawn
Definition TableBase.h:174
@ CONTEXT_ENDPAGE
after a page is redrawn
Definition TableBase.h:175
@ CONTEXT_ROW_HEADER
in the row header
Definition TableBase.h:176
@ CONTEXT_RC_RESIZE
column or row being resized
Definition TableBase.h:180
@ CONTEXT_COL_HEADER
in the col header
Definition TableBase.h:177
int callback_col()
Definition TableBase.h:698
TableContext callback_context()
Definition TableBase.h:703

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

◆ 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()

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()

~TableBase ( )

Destroys the table and associated widgets

Member Function Documentation

◆ add() [1/2]

void add ( Fl_Widget & widget)
inline

Append widget to the table

◆ add() [2/2]

void add ( Fl_Widget * widget)
inline

Append widget to the table

◆ begin()

void begin ( )
inline

Same as Fl_Group::begin()

◆ callback_col()

int callback_col ( )
inline

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

◆ callback_context()

TableContext callback_context ( )
inline

Returns current TableContext

◆ callback_row()

int callback_row ( )
inline

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

◆ clear()

virtual void clear ( )
inlinevirtual

Clears the table

◆ col_header() [1/2]

int col_header ( )
inline

Returns 1 if column headers are shown or 0 if not

◆ col_header() [2/2]

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

◆ col_header_color() [1/2]

Fl_Color col_header_color ( )
inline

Returns the current column header color

◆ col_header_color() [2/2]

void col_header_color ( Fl_Color val)
inline

Sets the column header color. Table will be then redrawn

◆ col_header_height() [1/2]

int col_header_height ( )
inline

Returns the column header heights

◆ col_header_height() [2/2]

void col_header_height ( int height)
inline

Sets the column header heights. Table will be then redrawn

◆ col_position() [1/2]

int col_position ( )
inline

Returns the current columnscroll position

◆ col_position() [2/2]

void col_position ( int col)

Sets the table's current column scroll position

◆ col_resize() [1/2]

int col_resize ( )
inline

Returns 1 if column can be resized or 0 if not

◆ col_resize() [2/2]

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

◆ col_resize_min() [1/2]

int col_resize_min ( )
inline

Returns the current column minimum resize value

◆ col_resize_min() [2/2]

void col_resize_min ( int val)
inline

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

◆ col_width() [1/2]

int col_width ( int col)
inline

Returns the current height of specified column

◆ col_width() [2/2]

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

◆ col_width_all()

void col_width_all ( int width)
inline

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

◆ cols() [1/2]

int cols ( )
inline

Returns the number of columns in the table

◆ cols() [2/2]

virtual void cols ( int val)
virtual

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

◆ do_callback()

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

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

◆ draw()

void draw ( void )

Draw the table (called by FLTK)

◆ end()

void end ( )
inline

Same as Fl_Group::end()

◆ get_selection()

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

◆ init_sizes()

void init_sizes ( )
inline

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

◆ insert() [1/2]

void insert ( Fl_Widget & widget,
int n )
inline

Same as Fl_Group::insert()

◆ insert() [2/2]

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

Same as Fl_Group::insert()

◆ is_interactive_resize()

int is_interactive_resize ( )
inline

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

◆ is_selected()

int is_selected ( int r,
int c )

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

◆ move_cursor()

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

◆ remove()

void remove ( Fl_Widget & widget)
inline

Remove a widget from the table

◆ resize()

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

Resize table. Table is redrawn

◆ row_header() [1/2]

int row_header ( )
inline

Returns 1 if row headers are shown or 0 if not

◆ row_header() [2/2]

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

◆ row_header_color() [1/2]

Fl_Color row_header_color ( )
inline

Returns the current row header color

◆ row_header_color() [2/2]

void row_header_color ( Fl_Color val)
inline

Sets the row header color. Table will be then redrawn

◆ row_header_width() [1/2]

int row_header_width ( )
inline

Returns the row header heights

◆ row_header_width() [2/2]

void row_header_width ( int width)
inline

Sets the row header heights. Table will be then redrawn

◆ row_height() [1/2]

int row_height ( int row)
inline

Returns the current height of specified row

◆ row_height() [2/2]

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

◆ row_height_all()

void row_height_all ( int height)
inline

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

◆ row_position() [1/2]

int row_position ( )
inline

Returns the current row scroll position

◆ row_position() [2/2]

void row_position ( int row)

Sets the table's current row scroll position

◆ row_resize() [1/2]

int row_resize ( )
inline

Returns 1 if rows can be resized or 0 if not

◆ row_resize() [2/2]

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

◆ row_resize_min() [1/2]

int row_resize_min ( )
inline

Returns the current row minimum resize value

◆ row_resize_min() [2/2]

void row_resize_min ( int val)
inline

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

◆ rows() [1/2]

int rows ( )
inline

Returns the number of rows in the table

◆ rows() [2/2]

virtual void rows ( int val)
virtual

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

◆ set_selection()

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

◆ table_box() [1/2]

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

◆ table_box() [2/2]

Fl_Boxtype table_box ( void )
inline

Returns the current box type used for the data table

◆ top_row() [1/2]

int top_row ( )
inline

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

◆ top_row() [2/2]

void top_row ( int row)
inline

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

◆ visible_cells()

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: