gtk-- accel_group problem




I'm seeing some strange behavior with gtk-- and accel group,
or maybe just a bug in my program.
I've attached an accelerator to a menu item, but I seem to
be able to move this accelerator around.  If I popup up the menu,
then move the mouse over a different menu item, then use the
accelerator, it switches the accelerator to that menuitem,
though it doesnt transfer the signal I think.  The signal becomes
inactive. I'll attach the example program.  I'm use gtk-- from a cvs
update about a week old.

C.J. Beyer
cj@styx.phy.vanderbilt.edu
http://styx.phy.vanderbilt.edu/~cj/

//-------------------------------------------------------------------
#include <gtk--.h>

//
// menubar_factory.cc
// c++ `gtkmm-config --cflags` menubar_factory.cc -o menubar_factory `gtkmm-config --libs`
//

static GtkItemFactoryEntry menu_items[] = 
{
  {"/File",               0,            0, 0, "<Branch>"},
  {"/File/Nothing",       0,            0, 0, 0 },
  {"/File/",              0,            0, 0, "<Separator>" },
  {"/File/Quit",          "<control>Q", 0, 0, 0 },
  {"/Toggle",             0,            0, 0, "<Branch>"},
  {"/Toggle/ToggleItem",  0,            0, 0, "<ToggleItem>"},
  {"/Check",              0,            0, 0, "<Branch>"},
  {"/Check/CheckItem",    0,            0, 0, "<CheckItem>"},
  {"/Radio",              0,            0, 0, "<Branch>"},
  {"/Radio/A",            0,            0, 0, "<RadioItem>"},
  {"/Radio/B",            0,            0, 0, "/Radio/A"},
  {"/Radio/C",            0,            0, 0, "/Radio/B"},
  {"/Help",               0,            0, 0, "<LastBranch>"},
  {"/Help/NOT",           0,            0, 0, 0}
};
static int nmenu_items = sizeof(menu_items)/sizeof(menu_items[0]);

class MyMenuBar : public Gtk_Window {
private:
  Gtk_AccelGroup accel_group;
  Gtk_ItemFactory_MenuBar main_factory;
public:
  MyMenuBar() : 
    accel_group(),
    main_factory( "<Main>", accel_group )
    {
      main_factory.create_items( nmenu_items, menu_items, 0 );

      // attach a callback to quit
      Gtk_MenuItem *quit = main_factory.get_menuitem_widget("/File/Quit");
      connect_to_method( quit->activate, Gtk_Main::instance(), &Gtk_Main::quit );

      // set Help->NOT insensitive
      Gtk_MenuItem *NOT = main_factory.get_menuitem_widget("/Help/NOT");
      NOT->set_sensitive( FALSE );

      Gtk_MenuBar *menubar_ptr = main_factory.get_menubar_widget("");
      add(menubar_ptr);
      accel_group.attach( *this );
    }
};

int main( int argc, char **argv )
{
   Gtk_Main main( &argc, &argv );
   MyMenuBar menubar_window;

   menubar_window.show_all();

   main.run();
   return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]