What I'd like to do is have a top-level menu item called, say, "View"
with a sub menu of file names with check boxes. So far, so good.
Now, when "View" is clicked, and the list of files comes into
view, I'd like to be able to deactivate the ones that don't
exist (or cannot be opened). I thought I might do that by checking
the file status in the callback for the top level menu item, but
it seems that the callback is invoked not when the item is clicked,
but when the sub menu is "closed," either by selecting from it
or by clicking the top level item again. That's too late :)
I guess I'm looking for the moral equivalent of when() for
menu items. Any ideas on how I might go about this would be
appreciated. Using fltk 1.1.8 on XP at the moment. The
following bare bones example is illustrative, I hope.
TIA
Stan
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <unistd.h>
#include <fcntl.h>
char const* const filename = "strategy.log";
Fl_Menu_Item menu_[] = {
{"View", 0, 0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
{filename, 0, 0, 0, FL_MENU_TOGGLE | FL_MENU_VALUE,
FL_NORMAL_LABEL, 0, 14, 0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
class Window : public Fl_Double_Window {
public:
Window(int w, int h);
private:
Fl_Menu_Bar menu_bar_;
Fl_Menu_Item* view_;
Fl_Menu_Item* filename_;
static void view_cb(Fl_Widget*, void* self)
{ static_cast<Window*>(self)->view_cb(); }
void view_cb();
};
Window::Window(int w, int h)
: Fl_Double_Window(w, h)
, menu_bar_(0, 0, w, 30)
, view_(&menu_[0])
, filename_(&menu_[1])
{
menu_bar_.menu(menu_);
view_->callback(view_cb, this);
filename_->clear();
}
void
Window::view_cb()
{
int fd = open(filename, O_RDONLY);
if(fd >= 0) {
filename_->activate();
close(fd);
}
else {
filename_->deactivate();
}
}
int main()
{
Window win(300, 500);
win.show();
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk