On 07/15/13 18:25, Furqan Ullah wrote:
> Is there anyway to hide any widget in FLTK 1.3.2?
> For example i was to hide Fl_Menu_Bar in run time and also Fl_Check_Button.
w->hide(); should work for widgets like the menubar itself,
and widgets like check buttons.
> By pressing button, main menu and some buttons should hide and then [again
> by pressing button all show up?
Yes, toggling hide() and show() for widgets should make them appear/disappear.
I'd tell the whole window to redraw() though after making such a change, ie.
your_app_win->redraw();
Similarly you can deactivate ('grey out') widgets using
w->deactivate(), and return them to normal with w->activate()
For menu items (such as in a main menu), those items are not really widgets,
so they are manipulated a bit differently.. they have a 'flags' value that
is a collection of bit flags. From Fl_Menu_Item.H:
enum { // values for flags:
FL_MENU_INACTIVE = 1, ///< Deactivate menu item (gray out)
FL_MENU_TOGGLE= 2, ///< Item is a checkbox toggle (shows checkbox for on/off state)
FL_MENU_VALUE = 4, ///< The on/off state for checkbox/radio buttons (if set, state is 'on')
FL_MENU_RADIO = 8, ///< Item is a radio button (one checkbox of many can be on)
FL_MENU_INVISIBLE = 0x10, ///< Item will not show up (shortcut will work)
FL_SUBMENU_POINTER = 0x20, ///< Indicates user_data() is a pointer to another menu array
FL_SUBMENU = 0x40, ///< This item is a submenu to other items
FL_MENU_DIVIDER = 0x80, ///< Creates divider line below this item. Also ends a group of radio buttons.
FL_MENU_HORIZONTAL = 0x100 ///< ??? -- reserved
};
So to toggle invisibility, you'd want to toggle the FL_MENU_INVISIBLE flag,
and to toggle activation (grey out), toggle the FL_MENU_INACTIVE flag.
So if you want to selectively make the File/Quit menu item inactive
from a button's callback, in your callback's code you'd do something like:
Fl_Menu_Item *item = menubar->find_item("File/Quit");
item->flags |= FL_MENU_INACTIVE;
Here's a complete program that shows that:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Button.H>
//
// Demonstrate toggling the File -> Quit menu item (toggle 'graying it out')
//
void Button_CB(Fl_Widget *w, void *data) {
Fl_Menu_Bar *menubar = (Fl_Menu_Bar*)data;
Fl_Menu_Item *item = (Fl_Menu_Item*)menubar->find_item("File/Quit");
if ( !item ) { fprintf(stderr, "ITEM NOT FOUND!\n"); return; }
item->flags ^= FL_MENU_INACTIVE;
}
int main() {
// Make the window
Fl_Window *win = new Fl_Window(400,200);
// Make the menubar with a few menu items
Fl_Menu_Bar *menubar = new Fl_Menu_Bar(0,0,400,25);
menubar->add("File/Open", 0,0,0);
menubar->add("File/Preferences", 0,0,0);
menubar->add("File/Quit", 0,0,0);
// Make a button to toggle the File/Quit menu item's activation state
Fl_Button *butt = new Fl_Button(30,50,100,25,"Toggle");
butt->callback(Button_CB, (void*)menubar);
win->end();
win->show();
return(Fl::run());
}
When you push the 'Toggle' button, the File -> Quit menu should gray out,
or return to normal each time you push it.