This is a sample code based on the table-simple example by Greg Ercolano with
the popup added.
I hope you can see the problem
Regards.
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Table_Row.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/fl_draw.H>
#define MAX_ROWS 30
#define MAX_COLS 4
// Derive a class from Fl_Table
class MyTable : public Fl_Table_Row {
void DrawData(int X, int Y, int W, int H) {
fl_push_clip(X,Y,W,H);
// Draw cell bg
fl_rectf(X,Y,W,H);
// Draw box border
fl_color(color()); fl_rect(X,Y,W,H);
fl_pop_clip();
}
void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int Y=0,
int W=0, int H=0) {
switch ( context ) {
case CONTEXT_CELL: // Draw data in cells
if (row_selected(ROW))
{
printf("draw_cell Row=%d Col=%d Context=%d X=%d
Y=%d W=%d H=%d\n", ROW, COL, context, X, Y, W, H);
fl_color(FL_YELLOW);
}
else
fl_color(FL_WHITE);
DrawData(X,Y,W,H);
return;
default:
return;
}
}
static void event_callback(Fl_Widget*, void*);
void event_callback2();
public:
Fl_Menu_Button *popmenu;
MyTable(int X, int Y, int W, int H, const char *L=0) :
Fl_Table_Row(X,Y,W,H,L) {
// Rows
rows(MAX_ROWS); // how many rows
// Cols
cols(MAX_COLS); // how many columns
col_width_all(180); // default width of columns
end(); // end the Fl_Table group
callback (&event_callback, (void*)this);
}
~MyTable() { }
};
void MyTable::event_callback(Fl_Widget*, void *data)
{
MyTable *o = (MyTable*)data;
o->event_callback2();
}
void MyTable::event_callback2()
///\brief Callback for table events
{
int R = callback_row(),
C = callback_col();
TableContext context = callback_context();
printf("event_callback2 Row=%d Col=%d Context=%d Event=%d
InteractiveResize? %d\n",
R, C, (int)context, (int)Fl::event(),
(int)is_interactive_resize());
switch (Fl::event())
{
case FL_PUSH: //Any mouse click
if (Fl::event_button () == FL_RIGHT_MOUSE)
{
popmenu->position (Fl::event_x (), Fl::event_y
());
popmenu->show ();
popmenu->popup ();
}
else
{
popmenu->hide ();
}
break;
}
}
Fl_Menu_Item menu_popmenu[] = {
{"Insert Before...", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"Insert After...", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"Delete", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"Edit...", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{0,0,0,0,0,0,0,0,0}
};
int main(int argc, char **argv) {
Fl_Double_Window win(900, 400, "Simple Table");
MyTable table(0,0,880,380);
table.type (MyTable::SELECT_SINGLE);
Fl_Menu_Button popmenu (30,30,100,100);
popmenu.menu(menu_popmenu);
popmenu.type(Fl_Menu_Button::POPUP3);
table.popmenu = &popmenu;
win.end();
win.resizable(table);
win.show(argc,argv);
return(Fl::run());
}
> On 09.11.2011 15:51, David Lopez wrote:
> > Dear members:
> > I have a window containing an Fl_Table, and an Fl_Menu_Button which is
> > normally hidden. The table handles the right click events to show a popup
> > menu that allows user to operate with the current row (Delete, Edit, etc.).
> > That works fine, but the problem is that when the menu option is selected,
> > the click event is alse handled by the table and the selected row changes.
> > I tried to catch the click events in a class derived from Fl_Menu_Button
> > (the popup object) but it does not receive the FL_PUSH event.
> > I am using FLTK 1.3
> > Any helping idea would be appreciated.
> > Thank you very much.
>
> Can you post a short, but complete and compilable example
> program that shows the effect (as short as possible, and w/o
> the extra class you used to catch the click events)?
>
> Reading your description, this looks like a bug, but w/o seeing
> real code it's difficult to decide.
>
> Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk