I wrote:
> In fltk1 / fluid, if I create the following conceptual hierarchy
>
> UserInterface : WidgetClass (set to Fl_Double_Window)
> m_menuGroup : Group
> m_menuBar : Menu_Bar
> m_fileMenu : Submenu
> m_quitMenuItem : MenuItem
In the cold light of dawn I've revisited this to make a complete
example that demonstrates the structure above.
In the fluid UserInterface/C++ tab I can put 'onWindowClose' in the
Callback field and 'this' in the User Data field to call the static
member function. This works as expected.
//static
void UserInterface::onWindowClose(
Fl_Double_Window* widget,
void* userData)
{
UserInterface* userInterface = (UserInterface*)userData;
userInterface->doWindowClose(widget, userInterface);
}
However, I can't do the same trick in the fluid MenuItem/C++ tab
to call the 'onFileQuit2' static member function with widget and
userdata because fluid writes 'this' outside the class scope.
[Try it for yourself by changing the attached fluid file :-) ]
What I can do is leave the User Data field blank, and call the one
parameter 'onFileQuit1' static member function, but the question is
how to get the UserInterface object to call the 'doFileQuit' member ?
//static
void UserInterface::onFileQuit1(Fl_Menu_Item* widget)
{
UserInterface* userInterface = ?; // what goes here?
userInterface->doFileQuit(widget, userInterface);
}
So I have three questions:
1. What widget type do I need in the xxFileQuit() declarations ?
2. What parent() magic do I need to get onFileQuit1() to work ?
3. Is there an obscure fluid way to pass 'this' to onFileQuit2() ?
Cheers
Duncan
# data file for the Fltk User Interface Designer (fluid)
version 1.0109
header_name {.h}
code_name {.cxx}
decl {\#include <stdio.h>} {}
widget_class UserInterface {
user_data this
callback onWindowClose open
xywh {977 21 200 100} type Double
class Fl_Double_Window visible
} {
Fl_Group m_menuGroup {open
xywh {0 0 200 25}
} {
Fl_Menu_Bar m_menuBar {open
xywh {0 0 200 25}
} {
Submenu m_fileMenu {
label File open
xywh {0 0 63 25}
} {
MenuItem m_fileQuit {
label Quit
callback onFileQuit1
xywh {0 0 30 25}
}
}
}
}
Function {onWindowClose(Fl_Double_Window* widget, void* userData)}
{return_type {static void}
} {
code {UserInterface* userInterface = (UserInterface*)userData;
userInterface->doWindowClose(widget, userData);} {}
}
Function {doWindowClose(Fl_Double_Window* widget, void *userData)}
{return_type void
} {
code {printf("doWindowClose(widget=%p, userData=%p\\n", widget, userData);}
{}
}
Function {onFileQuit1(Fl_Menu_Item* widget)} {open return_type {static void}
} {
code {// UserInterface* userInterface = widget->parent()...
// userInterface->doFileQuit(widget, userInterface);} {}
}
Function {onFileQuit2(Fl_Menu_Item* widget, void* userData)} {open
return_type {static void}
} {
code {UserInterface* userInterface = (UserInterface*)userData;
userInterface->doFileQuit(widget, userInterface);} {selected
}
}
Function {doFileQuit(Fl_Menu_Item* widget, void* userData)} {return_type void
} {
code {printf("doWindowClose(widget=%p, userData=%p\\n", widget, userData);}
{}
}
}
Function {} {open
} {
code {UserInterface ui(200, 100, "Ui");
ui.show(argc, argv);} {}
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk