On 07/25/13 02:04, domonic Thomson wrote:
> Below is the MyTable Class derived from FL_Table.
> At the bottom of this class is the *constructor for MyTable*.
Right, which is this:
MyTable(intX,intY,intW,intH,constchar*L=0):Fl_Table(X,Y,W,H,L){
// Fill data array
for(intr=0;r<MAX_ROWS;r++)
for(intc=0;c<MAX_COLS;c++)
data[r][c]=1000+(r*1000)+c;
// Rows
rows(MAX_ROWS); // how many rows
row_header(1); // enable row headers (along left)
row_height_all(20); // default height of rows
row_resize(0); // disable row resizing
// Cols
cols(MAX_COLS); // how many columns
col_header(1); // enable column headers (along top)
col_width_all(80); // default width of columns
col_resize(1); // enable column resizing
end();// end the Fl_Table group
}
> When the line in the constructor reaches *row_header(1) *and *col_header(1**)*
> and the fact that these functions return a 'context flag'
..hmm, no, those two methods don't return anything;
they just set a flag telling the table what you want headers displayed
for the rows and columns.
The argument to those methods is either 0 or 1;
0 disables headers from appearing in the table,
1 enables headers to appear in the table.
Docs for those methods are here:
void row_header(int):
http://www.fltk.org/doc-1.3/classFl__Table.html#ad51f00bbee634d5ba3c90c67a7c5650a
void col_header(int):
http://www.fltk.org/doc-1.3/classFl__Table.html#abcfb0374426baff30a91aca68dc0aea9
So these are just initialization methods; they tell the table what
features you want (on or off in this case).
What happens is, later, when the table is being drawn (see my previous post
describing how Fl_Table works), since you've enabled headers with those calls,
the table will call your draw_cell() method with 'context' set to CONTEXT_ROW_HEADER
when it wants you to draw the cells in the row header, and set to CONTEXT_COL_HEADER
when it wants you to draw the cells in the column header.
Keep in mind the draw_cell() method is code you supply to draw all
the cells in the table. The arguments passed to draw_cell() tell you
which cell to draw ('row'/'col' args), where the cell is to be drawn on the screen
(x/y/w/h args), and whether it's a row header cell, column header cell, or just a
regular data cell ('context' arg).
> CONTEXT_ROW_HEADER and CONTEXT_COL_HEADER respectively do these functions
> row_header() and col_header() call the draw_cell function and pass it the
> context flag which is then utilized in the switch statement (see below)?
No, row_header() and col_header() just set flags, they don't turn around
and invoke the draw_cell() method.
The draw_cell() method is automatically invoked by FLTK when the table
needs to be redrawn, such as if you unhide the window, or scroll the table,
revealing new cells of data.
> That is my interpretation of it. I'm not asking for a granular appraisal
> of my perspective
Sorry, I did ;)
> but I do want to know if I am on the right track.
Not quite on the right track, but hopefully the above will get you there.
Fl_Table is an unusual widget because the drawing code is actually
handled by you. Most widgets handle all drawing for you.
The reason for this is tables can be large, so the philosophy here
is it's better to let you, the app programmer, have control over
managing the memory of your (potentially huge) cell data, and how
to draw it (either with simple draw code, or more complex code that
handles user interaction like with an Fl_Input).