> Consider the following program:

------------
>       public:
>               MainWindow(int w, int h, char *s = 0): Window(w, h, s) {
>                       begin();
>                               menu = new PopupMenu(0, 0, w, h);
>                               menu->type(PopupMenu::POPUP3);
>                               menu->begin();
>                                       about_item = new Item("About clock");
>                                       exit_item = new Item("Exit clock");
>                               menu->end();
>                               menu->callback(cb_menu, this);
>
>                               win = new Window(100, 100);
>                       end();
>                       color(12);
>                       show();
>                       win->show();
>               }
>
> };

> This window in its begin/end block first creates and defines PopupMenu (menu),
> and then it creates one subwindow (win). After compiling and running it, it
> behaves as expected, with third mouse button click on main window, menu
> appears.

I am not sure which version of fltk you are using, perhaps the previous weekly 
snapshot.  I just downloaded the latest weekly snapshot 5782, and the behaviour 
is a little different to what you describe.

When I compile the first program, it does not create one subwindow, it creates 
a top level window, the menu is functional as you say, but the subwindow is not 
created.  The reason the subwindow is not created , is that the constructor 
used to create MainWindow::win is the top level window constructor (Window(int 
w,int h,const char *) ) , instead of the subwindow constructor ( Window(int 
x,int y,int w,int h,const char *) ) (see 
http://www.fltk.org/doc-2.0/html/classWindow.html#a0).

In the second version of the program which you show below, the behaviour i get 
is that again, MainWindow::win is created as a top level window not a 
subwindow, but as for you the menu is not functional.

The reason for this it seems is that the top level window constructor includes 
the command Group::current(0) which effectively end()s the begin() called 
earlier.  This can be seen on lines 151,152 in the file Window.cxx in the 
source code.

So I guess the solution is to simply change:
 win = new Window(100, 100);
to
 win = new Window(x,y,100,100);
and then it doesn't matter if MainWindow::win is constructed before or after 
the popup menu, they will both behave as expected.

> However, if it was subwindow that was first created, followed by menu creation
> and definition, like in the following:
>

-----------------------

>
>       public:
>               MainWindow(int w, int h, char *s = 0): Window(w, h, s) {
>                       begin();
>                               win = new Window(100, 100);
>
>                               menu = new PopupMenu(0, 0, w, h);
>                               menu->type(PopupMenu::POPUP3);
>                               menu->begin();
>                                       about_item = new Item("About clock");
>                                       exit_item = new Item("Exit clock");
>                               menu->end();
>                               menu->callback(cb_menu, this);
>                       end();
>                       color(12);
>                       show();
>                       win->show();
>               }
>
> };
>

---------------

> then right mouse button click on main window wont bring up the menu!?
>

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to