Sam wrote:
> // not able to place Sample_Callback as a MyMenubar method
> void Sample_Callback(Fl_Widget *, void *)
Be sure to declare Sample_Callback() as being static.
If that's not the trouble, show us the compiler errors
and the declaration of Sample_Callback() as a global function
in the class.
There's a lot of ways to make menu bars. There's the static
menu array approach:
---- snip
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
class MyMenuBar : public Fl_Menu_Bar {
static void Sample_Callback(Fl_Widget *, void *) {
printf("Sample callback called.\n");
}
public:
MyMenuBar(int X,int Y,int W,int H):Fl_Menu_Bar(X,Y,W,H) {
static Fl_Menu_Item Sample[] = {
{"&File",0,0,0,FL_SUBMENU},
{"&Sample",0,Sample_Callback},
{0},
{0},
};
this->copy(Sample);
}
};
int main() {
Fl_Window win(400,400);
MyMenuBar menu(0,0,400,25);
win.end();
win.show();
return(Fl::run());
}
---- snip
..or my favorite, using add() which is more dynamic,
and in my mind is easier to read/less to type:
---- snip
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
class MyMenuBar : public Fl_Menu_Bar {
static void Sample_Callback(Fl_Widget *, void *) {
printf("Sample callback called.\n");
}
public:
MyMenuBar(int X,int Y,int W,int H):Fl_Menu_Bar(X,Y,W,H) {
add("&File/&Sample", 0, Sample_Callback);
}
};
int main() {
Fl_Window win(400,400);
MyMenuBar menu(0,0,400,25);
win.end();
win.show();
return(Fl::run());
}
---- snip
Note that with this technique, 'this' can be passed to the
callback, so that it has access to this instance of the class. eg:
static void Sample_Callback(Fl_Widget*, void *data) {
MyMenuBar *mmb = (MyMenuBar*)data; // get 'this'
mmb->xxx(); // now can access non-static
class elements/methods
}
[..]
MyMenuBar(int X,int Y,int W,int H):Fl_Menu_Bar(X,Y,W,H) {
add("&File/&Sample", 0, Sample_Callback, (void*)this); // <-- pass
'this' to cb
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk