From bb6392f7ec94ba682ebade1d5b30eba9ff30ceb1 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 3 Jan 2011 08:28:38 +0000 Subject: Added Table and Tree support to Fluid. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8172 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- fluid/Fl_Group_Type.cxx | 122 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) (limited to 'fluid/Fl_Group_Type.cxx') diff --git a/fluid/Fl_Group_Type.cxx b/fluid/Fl_Group_Type.cxx index 8e433834e..ac4b81f88 100644 --- a/fluid/Fl_Group_Type.cxx +++ b/fluid/Fl_Group_Type.cxx @@ -32,6 +32,7 @@ #include #include +#include #include #include "Fl_Widget_Type.h" #include "../src/flstring.h" @@ -146,6 +147,91 @@ Fl_Pack_Type Fl_Pack_type; // the "factory" //////////////////////////////////////////////////////////////// +static const int MAX_ROWS = 14; +static const int MAX_COLS = 7; + +// this is a minimal table widget used as an example when adding tables in Fluid +class Fluid_Table : public Fl_Table { + int data[MAX_ROWS][MAX_COLS]; // data array for cells + + // 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(); + } + // Draw the cell data + // Dark gray text on white background with subtle border + // + void DrawData(const char *s, int X, int Y, int W, int H) { + fl_push_clip(X,Y,W,H); + // Draw cell bg + fl_color(FL_WHITE); fl_rectf(X,Y,W,H); + // Draw cell data + fl_color(FL_GRAY0); fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER); + // Draw box border + fl_color(color()); fl_rect(X,Y,W,H); + 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",data[ROW][COL]); + DrawData(s,X,Y,W,H); + return; + default: + return; + } + } +public: + Fluid_Table(int x, int y, int w, int h, const char *l=0L) + : Fl_Table(x, y, w, h, l) { + for ( int r=0; ro : 0; + if (((Fl_Table*)o)->children()==1) { // the FLuid_Table has one extra child + fl_message("Inserting child widgets into an Fl_Table is not recommended.\n" + "Please refer to the documentation on Fl_Table."); + } + ((Fl_Table*)o)->insert(*(c->o), b); + o->redraw(); +} + + // This is called when o is deleted. If it is in the tab group make // sure it is not visible: @@ -217,6 +315,12 @@ void Fl_Tabs_Type::remove_child(Fl_Type* cc) { Fl_Group_Type::remove_child(c); } +void Fl_Table_Type::remove_child(Fl_Type* cc) { + Fl_Widget_Type* c = (Fl_Widget_Type*)cc; + ((Fl_Table*)o)->remove(*(c->o)); + o->redraw(); +} + // move, don't change selected value: void Fl_Group_Type::move_child(Fl_Type* cc, Fl_Type* before) { @@ -227,6 +331,14 @@ void Fl_Group_Type::move_child(Fl_Type* cc, Fl_Type* before) { o->redraw(); } +void Fl_Table_Type::move_child(Fl_Type* cc, Fl_Type* before) { + Fl_Widget_Type* c = (Fl_Widget_Type*)cc; + Fl_Widget* b = before ? ((Fl_Widget_Type*)before)->o : 0; + ((Fl_Table*)o)->remove(*(c->o)); + ((Fl_Table*)o)->insert(*(c->o), b); + o->redraw(); +} + //////////////////////////////////////////////////////////////// // live mode support @@ -261,6 +373,16 @@ Fl_Widget *Fl_Tabs_Type::enter_live_mode(int) { return live_widget; } +Fl_Widget *Fl_Table_Type::enter_live_mode(int) { + Fl_Group *grp = new Fluid_Table(o->x(), o->y(), o->w(), o->h()); + live_widget = grp; + if (live_widget) { + copy_properties(); + grp->end(); + } + return live_widget; +} + void Fl_Group_Type::leave_live_mode() { } -- cgit v1.2.3