Aha!!  Thinking about why the draw() suggestion failed suggested
something that does work!

Thanks again Harvey! (and Ian and Matt)

///////////////////////////////////////////////////////
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Menu_Item.H>
#include <unistd.h>

char const* const filename = "file1.txt";

Fl_Menu_Item theMenu[] = {
 {"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 MyMenuBar : public Fl_Menu_Bar {
public:
    MyMenuBar(int x, int y, int w, int h, char const* label = 0)
        : Fl_Menu_Bar(x, y, w, h, label)
        , view_file1_(&theMenu[1])
    {
        menu(theMenu);
        view_file1_->clear();
    }
private:
    Fl_Menu_Item* view_file1_;
    int handle(int event)
    {
        if(event == FL_PUSH) {
            if(!access(filename, R_OK)) {
                view_file1_->activate();
            }
            else {
                view_file1_->deactivate();
            }
        }
        return Fl_Menu_Bar::handle(event);
    }
};

class Window : public Fl_Double_Window {
public:
    Window(int w, int h)
        : Fl_Double_Window(w, h)
        , menu_bar_(0, 0, w, 30)
    {
        end();
    }
private:
    MyMenuBar menu_bar_;
};

int main()
{
    Window win(300, 500);
    win.resizable(&win);
    win.show();
    return Fl::run();
}

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

Reply via email to