@Greg Ercolano Thanks Greg, this answer was up and beyond my expectations! I got everything working thanks to your help. Appreciate all the awesome work you did on the Fl_Table class and your own website.
> Greg Ercolano wrote: > >> An example of the table with multiple colors: > >> http://db.tt/FFmO9hj > > Here's some code that shows how to define a second selection. > > I started with the table_simple.cxx in the examples directory, > modified it to use Fl_Table_Row, and added some code to do the > secondary selection stuff using the technique described in my last post. > > Might do what you want, or at least steer you in the right direction. > > Compile and run; highlight some lines to make a primary selection, > then click the button to define a secondary selection (fixed in code > to make row/cols 4 thru 8 selected in blue). You can change the primary > selection, and the secondary remains intact. > > #include <FL/Fl.H> > #include <FL/Fl_Double_Window.H> > #include <FL/Fl_Table_Row.H> > #include <FL/Fl_Check_Button.H> > #include <FL/fl_draw.H> > > // > // Demonstrate Fl_Table_Row with multiple selections -- erco 04/14/11 > // (Started with examples/table_simple.cxx) > // > > #define MAX_ROWS 100 > #define MAX_COLS 100 > > // Derive a class from Fl_Table_Row > class MyTable : public Fl_Table_Row { > int secondary_selection[4]; // handle secondary selection > > // Draw the row/col headings > // Make this a dark thin upbox with the text inside. > // > void DrawHeader(const char *s, int X, int Y, int W, int H) { > fl_push_clip(X,Y,W,H); > fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color()); > fl_color(FL_BLACK); > fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER); > fl_pop_clip(); > } > // Handle drawing table's cells > // Fl_Table calls this function to draw each visible cell in the table. > // It's up to us to use FLTK's drawing functions to draw the cells the > way we want. > // > void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int > Y=0, int W=0, int H=0) { > static char s[40]; > switch ( context ) { > case CONTEXT_STARTPAGE: // before page is drawn.. > fl_font(FL_HELVETICA, 16); // set the font for our > drawing operations > return; > case CONTEXT_COL_HEADER: // Draw column headers > sprintf(s,"%c",'A'+COL); // "A", "B", "C", etc. > DrawHeader(s,X,Y,W,H); > return; > case CONTEXT_ROW_HEADER: // Draw row headers > sprintf(s,"%03d:",ROW); // "001:", "002:", etc > DrawHeader(s,X,Y,W,H); > return; > case CONTEXT_CELL: { // Draw data in cells > sprintf(s,"%d",ROW*MAX_COLS+COL); // whatever.. > // HANDLE COLORING OF CELLS > int fgcol = FL_BLACK; > int bgcol = FL_WHITE; > if ( row_selected(ROW) ) { > fgcol = FL_WHITE; > bgcol = 0xaa4444; // lt blue > } > //// HANDLE SECONDARY SELECTION > if ( COL >= secondary_selection[0] && COL <= secondary_selection[1] && > ROW >= secondary_selection[2] && ROW <= secondary_selection[3] ) { > fgcol = FL_WHITE; > bgcol = 0x44aa44; // lt green > } > fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, bgcol); > fl_color(fgcol); > fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER); > return; > } > default: > return; > } > } > public: > // Constructor > // Make our data array, and initialize the table options. > // > MyTable(int X, int Y, int W, int H, const char *L=0) : > Fl_Table_Row(X,Y,W,H,L) { > // Init secondary selection off > SetSecondarySelection(-1,-1,-1,-1); > // 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 > } > ~MyTable() { } > // Let caller define a secondary selection rectangle > void SetSecondarySelection(int col_left, int col_right, int row_top, int > row_bot) { > secondary_selection[0] = col_left; > secondary_selection[1] = col_right; > secondary_selection[2] = row_top; > secondary_selection[3] = row_bot; > redraw(); > } > }; > > void Button_CB(Fl_Widget *w,void *data) { > Fl_Check_Button *but = (Fl_Check_Button*)w; > MyTable *table = (MyTable*)data; > if ( but->value() ) { > table->SetSecondarySelection(4,8,4,8); // on > } else { > table->SetSecondarySelection(-1,-1,-1,-1); // off > } > } > > int main(int argc, char **argv) { > Fl_Double_Window win(900, 400, "Multiselect Table"); > // Table > MyTable table(10,10,win.w()-20,win.h()-50); > // Toggle button for 'fixed' secondary selection > Fl_Check_Button but(10,win.h()-35,180,25,"Secondary Selection"); > but.callback(Button_CB, (void*)&table); > win.end(); > win.resizable(table); > win.show(argc,argv); > return(Fl::run()); > } _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

