Gtk--: deletion from MenuBar



   I've been having some trouble deleting MenuItems from a MenuBar. After
deletion, the label is not erased until the next expose event.  Worse, if I
add a new MenuItem to the MenuBar, it skips past the space allocated to the
first MenuItem.  The following code demonstrates the problem.
I'll work around it by creating and destroying the MenuBar for now, but I'd
like to know whether I've failed to do some cleanup during deletion, or
there's a bug in MenuBar.

-Drake


#include <gtk--.h>

Gtk_MenuItem* newitem=0;
Gtk_MenuBar* global_menubar=0;

void destroy_callback() {
  if (newitem) delete newitem;
  newitem=0;
}

void create_callback() {
  if (newitem) destroy_callback();
  newitem = new Gtk_MenuItem("new");
  newitem->show();
  global_menubar->append(newitem);
}

int main(int argc,char **argv) {
  Gtk_Main app(&argc,&argv);
  Gtk_Window w(GTK_WINDOW_TOPLEVEL);
  Gtk_MenuItem file("File");
  Gtk_Menu filemenu;
  Gtk_MenuBar menubar;
  Gtk_MenuItem create("create");
  Gtk_MenuItem destroy("destroy");
  Gtk_VBox vbox(false,1);

  global_menubar = &menubar;

  connect_to_function(create.activate, &create_callback);
  connect_to_function(destroy.activate, &destroy_callback);

  create.show();
  destroy.show();
  filemenu.append(&create);
  filemenu.append(&destroy);
  file.show();
  file.set_submenu(&filemenu);
  menubar.append(&file);
  menubar.show();
  vbox.pack_start(&menubar,FALSE,FALSE,0);
  vbox.show();
  w.add(&vbox);
  w.show();

  app.run();
}

  





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