Ejemplo n.º 1
0
//------------------------------------------------------------------------------
void mforms::gtk::MenuItemImpl::remove_item(mforms::MenuBase *menu, mforms::MenuItem *item) {
  Gtk::MenuShell *menu_shell = cast<Gtk::MenuShell *>(menu->get_data_ptr());
  if (!menu_shell) {
    Gtk::MenuItem *mi = cast<Gtk::MenuItem *>(menu->get_data_ptr());
    if (mi) {
      if (mi->has_submenu())
        menu_shell = mi->get_submenu();
      else
        logError("Requesting to remove MenuItem from Menu with no sub menu\n");
    } else
      logError("Passed MenuBase %p does not contain neither Gtk::MenuBar nor Gtk::MenuItem\n", menu);
  }

  Gtk::MenuItem *item_to_remove = item ? cast<Gtk::MenuItem *>(item->get_data_ptr()) : 0;
  if (menu_shell) {
    if (item_to_remove)
      menu_shell->remove(*item_to_remove); // May not work needs to be tested
    else {
      typedef Glib::ListHandle<Gtk::Widget *> WList;
      WList list = menu_shell->get_children();
      for (base::const_range<WList> it(list); it; ++it)
        menu_shell->remove(*(*it));
    }
  }
}
Ejemplo n.º 2
0
void mforms::gtk::MenuItemImpl::insert_item(mforms::MenuBase *menub, int index, mforms::MenuItem *item) {
  Gtk::MenuShell *menu_shell = cast<Gtk::MenuShell *>(menub->get_data_ptr());
  Gtk::MenuItem *item_to_insert = cast<Gtk::MenuItem *>(item->get_data_ptr());

  if (!menu_shell) // menub is not a menubar
  {
    Gtk::MenuItem *mi = cast<Gtk::MenuItem *>(menub->get_data_ptr());
    if (mi) {
      Gtk::Menu *menu = 0;
      if (mi->has_submenu()) // item already has submenu, add to it
        menu = mi->get_submenu();
      else { // no submenu yet in item, create one
        menu = Gtk::manage(new Gtk::Menu());
        mi->signal_activate().connect(sigc::bind(sigc::ptr_fun(menu_will_show), menub));
        mi->set_submenu(*menu);
        menu->show();
      }
      menu_shell = menu;
    } else
      logError("Passed MenuBase %p does not contain neither Gtk::MenuBar nor Gtk::MenuItem\n", menub);
  } else {
    if (menub->get_parent() && get_accel_group(menub))
      propagate_accel_group(menub, get_accel_group(menub));
  }
  if (menu_shell && item_to_insert)
    menu_shell->insert(*item_to_insert, index);
  else
    logError("Internal error in MenuBase::insert_item()\n");
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
static void propagate_accel_group(mforms::MenuBase *item, Glib::RefPtr<Gtk::AccelGroup> agroup) {
  Gtk::MenuItem *mi = cast<Gtk::MenuItem *>(item->get_data_ptr());
  if (mi && mi->has_submenu())
    mi->get_submenu()->set_accel_group(agroup);

  for (int i = item->item_count() - 1; i >= 0; --i) {
    mforms::MenuItem *it = item->get_item(i);
    if (!it->get_shortcut().empty())
      mforms::gtk::MenuItemImpl::set_shortcut(it, it->get_shortcut());
    propagate_accel_group(it, agroup);
  }
}