JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem
  (JNIEnv *env, jobject obj, jobject menuitempeer, jint key, jboolean shift)
{
  void *ptr1, *ptr2;
  GtkWidget *menu;

  gdk_threads_enter ();

  ptr1 = NSA_GET_PTR (env, obj);
  ptr2 = NSA_GET_PTR (env, menuitempeer);

  menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr1));
  gtk_menu_shell_append (GTK_MENU_SHELL(menu), GTK_WIDGET (ptr2));

  if (key)
    {
      gtk_widget_add_accelerator (GTK_WIDGET (ptr2), "activate",
				  gtk_menu_get_accel_group (GTK_MENU (menu)), key, 
				  (GDK_CONTROL_MASK
				   | ((shift) ? GDK_SHIFT_MASK : 0)), 
				  GTK_ACCEL_VISIBLE);
    }

  gdk_threads_leave ();
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup
  (JNIEnv *env, jobject obj, jobject parent)
{
  void *ptr1, *ptr2;

  gdk_threads_enter ();

  ptr1 = NSA_GET_PTR (env, obj);

  if (!parent)
    {
      gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), 
				gtk_accel_group_new ());
    }
  else
    {
      GtkAccelGroup *parent_accel;

      ptr2 = NSA_GET_PTR (env, parent);
      parent_accel = gtk_menu_get_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr2)->submenu));
      
      gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
				parent_accel);
    }
      
  gdk_threads_leave ();
}
int
main                                            (int argc,
                                                 char **argv)
{
    hildon_gtk_init (&argc, &argv);

    HildonProgram *program = hildon_program_get_instance ();

    GtkWidget *window = hildon_window_new ();
    hildon_program_add_window (program, HILDON_WINDOW (window));

    GtkMenu *menu = GTK_MENU (gtk_menu_new ());
    GtkAccelGroup *group = gtk_accel_group_new ();
    gtk_menu_set_accel_group (menu, group);
    GtkWidget *menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT,
		    					       gtk_menu_get_accel_group (menu));
    gtk_widget_show (menu_item);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

    hildon_window_set_main_menu (HILDON_WINDOW (window), menu);

    g_signal_connect_swapped (menu_item, "activate",
		    	      G_CALLBACK (gtk_object_destroy), window);

    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
    gtk_widget_show_all (GTK_WIDGET (window));
    
    gtk_main ();

    return 0;
}
Exemplo n.º 4
0
int
clip_GTK_MENUGETACCELGROUP(ClipMachine * ClipMachineMemory)
{
   C_widget *cmnu = _fetch_cw_arg(ClipMachineMemory);

   C_widget *caccelgroup;

   GtkAccelGroup *accelgroup;

   CHECKCWID(cmnu, GTK_IS_MENU);

   accelgroup = gtk_menu_get_accel_group(GTK_MENU(cmnu->widget));

   if (accelgroup)
    {
       caccelgroup = _list_get_cwidget(ClipMachineMemory, accelgroup);
       if (!caccelgroup)
	  _register_widget(ClipMachineMemory, GTK_WIDGET(accelgroup), NULL);
       if (accelgroup)
	  _clip_mclone(ClipMachineMemory, RETPTR(ClipMachineMemory), &caccelgroup->obj);
    }
   return 0;
 err:
   return 1;
}
Exemplo n.º 5
0
static void buildMenu(GtkWidget *menu, GtkWidget **copy_to_clipboard, GtkWidget **nearest_from_palette)
{
	GtkAccelGroup *accel_group = gtk_menu_get_accel_group(GTK_MENU(menu));
	GtkWidget *item = *copy_to_clipboard = gtk_menu_item_new_with_mnemonic(_("_Copy to clipboard"));
	if (accel_group)
		gtk_widget_add_accelerator(item, "activate", accel_group, GDK_KEY_c, GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
	item = *nearest_from_palette = gtk_menu_item_new_with_mnemonic(_("_Nearest from palette"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
}
Exemplo n.º 6
0
/**
 * gnome_popup_menu_get_accel_group
 * @menu: A menu widget.
 *
 * This function is used to retrieve the accelgroup that was created by
 * gnome_popup_menu_new(). If you want to specify the accelgroup that the popup
 * menu accelerators use, then use gnome_popup_menu_new_with_accelgroup().
 *
 * Returns: The accelgroup associated with the specified #GtkMenu.
 */
GtkAccelGroup *
gnome_popup_menu_get_accel_group(GtkMenu *menu)
{
	g_return_val_if_fail (menu != NULL, NULL);
        g_return_val_if_fail (GTK_IS_MENU (menu), NULL);

#if GTK_CHECK_VERSION(1,2,1)
        return gtk_menu_get_accel_group (menu);
#else
	return NULL;
#endif
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_setupAccelGroup
  (JNIEnv *env, jobject obj, jobject parent)
{
  void *ptr1, *ptr2;
  GtkMenu *menu;

  ptr1 = NSA_GET_PTR (env, obj);
  ptr2 = NSA_GET_PTR (env, parent);

  gdk_threads_enter ();
  menu = GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu);
  gtk_menu_set_accel_group (menu, gtk_accel_group_new ());
  gtk_accel_group_attach (gtk_menu_get_accel_group (menu),
			  GTK_OBJECT (gtk_widget_get_toplevel (ptr2)));
  gdk_threads_leave ();
}
Exemplo n.º 8
0
/*	Insert a menu into the menu bar. */
void EvalCcRqINSERTMENU (CrossCallInfo *pcci)
{
    gint i;
    gchar *title;
    GtkWidget *parent_menu, *root_menu, *sub_menu;
    GtkAccelGroup *accel_group;
    printf("EvalCcRqINSERTMENU\n");

    title = createMnemonicString((gchar *) pcci->p3);
    parent_menu = GTK_WIDGET(pcci->p2);
    sub_menu = GTK_WIDGET(pcci->p4);

    if (GTK_IS_MENU_BAR(parent_menu))
    {
        printf("Adding to a menu bar.\n");
        GtkWidget *frame = gtk_widget_get_parent(gtk_widget_get_parent(parent_menu));
        if (!G_IS_OBJECT(frame))
            frame = gtk_widget_get_parent(parent_menu);
        accel_group = ((GtkAccelGroup*)gtk_accel_groups_from_object (G_OBJECT(frame))->data);
    }
    else
    {
        printf("We're not adding to a menu bar!?!\n");
        accel_group = gtk_menu_get_accel_group (GTK_MENU(parent_menu));
    }

    gtk_menu_set_accel_group (GTK_MENU(sub_menu), accel_group);

    root_menu = gtk_menu_item_new_with_mnemonic(title);
    gtk_widget_set_sensitive(root_menu, (gboolean) pcci->p1);
    gtk_widget_show (root_menu);

    gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), sub_menu);

    if (GTK_IS_MENU_BAR(parent_menu))
    {
        gtk_menu_shell_insert(GTK_MENU_SHELL(parent_menu), root_menu, (gint) pcci->p5);
    } else {
        gtk_menu_insert(GTK_MENU(parent_menu), root_menu, (gint) pcci->p5);
    }

    rfree(title);

    MakeReturn1Cci (pcci, (int64_t) sub_menu);
}
Exemplo n.º 9
0
/**
 * gnome_popup_menu_append:
 * @popup: An existing popup menu.
 * @uiinfo: A #GnomeUIInfo array describing new menu elements.
 *
 * Appends the menu items in @uiinfo the @popup menu.
 */
void
gnome_popup_menu_append (GtkWidget *popup, GnomeUIInfo *uiinfo)
{
	GnomeUIBuilderData uibdata;
	gint length;

	g_return_if_fail (uiinfo != NULL);

	uibdata.connect_func = popup_connect_func;
	uibdata.data = NULL;
	uibdata.is_interp = TRUE;
	uibdata.relay_func = NULL;
	uibdata.destroy_func = NULL;

	for (length = 0; uiinfo[length].type != GNOME_APP_UI_ENDOFINFO; length++)
		if (uiinfo[length].type == GNOME_APP_UI_ITEM_CONFIGURABLE)
			gnome_app_ui_configure_configurable (uiinfo + length);

        global_menushell_hack = popup;
	gnome_app_fill_menu_custom (GTK_MENU_SHELL (popup), uiinfo,
				    &uibdata, gtk_menu_get_accel_group(GTK_MENU(popup)), FALSE, 0);
        global_menushell_hack = NULL;
}
Exemplo n.º 10
0
static G_CONST_RETURN gchar*
gail_menu_item_get_keybinding (AtkAction *action,
                               gint      i)
{
  /*
   * This function returns a string of the form A;B;C where
   * A is the keybinding for the widget; B is the keybinding to traverse
   * from the menubar and C is the accelerator.
   * The items in the keybinding to traverse from the menubar are separated
   * by ":".
   */
  GailMenuItem  *gail_menu_item;
  gchar *keybinding = NULL;
  gchar *item_keybinding = NULL;
  gchar *full_keybinding = NULL;
  gchar *accelerator = NULL;

  gail_menu_item = GAIL_MENU_ITEM (action);
  if (i == 0)
    {
      GtkWidget *item;
      GtkWidget *temp_item;
      GtkWidget *child;
      GtkWidget *parent;

      item = GTK_ACCESSIBLE (action)->widget;
      if (item == NULL)
        /* State is defunct */
        return NULL;

      temp_item = item;
      while (TRUE)
        {
          GdkModifierType mnemonic_modifier = 0;
          guint key_val;
          gchar *key, *temp_keybinding;

          child = gtk_bin_get_child (GTK_BIN (temp_item));
          if (child == NULL)
            {
              /* Possibly a tear off menu item; it could also be a menu 
               * separator generated by gtk_item_factory_create_items()
               */
              return NULL;
            }
          parent = gtk_widget_get_parent (temp_item);
          if (!parent)
            {
              /*
               * parent can be NULL when activating a window from the panel
               */
              return NULL;
            }
          g_return_val_if_fail (GTK_IS_MENU_SHELL (parent), NULL);
          if (GTK_IS_MENU_BAR (parent))
            {
              GtkWidget *toplevel;

              toplevel = gtk_widget_get_toplevel (parent);
              if (toplevel && GTK_IS_WINDOW (toplevel))
                mnemonic_modifier = gtk_window_get_mnemonic_modifier (
                                       GTK_WINDOW (toplevel));
            }
          if (GTK_IS_LABEL (child))
            {
              key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
              if (key_val != GDK_VoidSymbol)
                {
                  key = gtk_accelerator_name (key_val, mnemonic_modifier);
                  if (full_keybinding)
                    temp_keybinding = g_strconcat (key, ":", full_keybinding, NULL);
                  else 
                    temp_keybinding = g_strconcat (key, NULL);
                  if (temp_item == item)
                    {
                      item_keybinding = g_strdup (key); 
                    }
                  g_free (key);
                  g_free (full_keybinding);
                  full_keybinding = temp_keybinding;
                }
              else
                {
                  /* No keybinding */
                  g_free (full_keybinding);
                  full_keybinding = NULL;
                  break;
                }        
            }        
          if (GTK_IS_MENU_BAR (parent))
            /* We have reached the menu bar so we are finished */
            break;
          g_return_val_if_fail (GTK_IS_MENU (parent), NULL);
          temp_item = gtk_menu_get_attach_widget (GTK_MENU (parent));
          if (!GTK_IS_MENU_ITEM (temp_item))
            {
              /* 
               * Menu is attached to something other than a menu item;
               * probably an option menu
               */
              g_free (full_keybinding);
              full_keybinding = NULL;
              break;
            }
        }

      parent = gtk_widget_get_parent (item);
      if (GTK_IS_MENU (parent))
        {
          GtkAccelGroup *group; 
          GtkAccelKey *key;

          group = gtk_menu_get_accel_group (GTK_MENU (parent));

          if (group)
            {
              key = gtk_accel_group_find (group, find_accel, item);
            }
          else
            {
              /*
               * If the menu item is created using GtkAction and GtkUIManager
               * we get here.
               */
              key = NULL;
              child = GTK_BIN (item)->child;
              if (GTK_IS_ACCEL_LABEL (child))
                {
                  GtkAccelLabel *accel_label;

                  accel_label = GTK_ACCEL_LABEL (child);
                  if (accel_label->accel_closure)
                    {
                      key = gtk_accel_group_find (accel_label->accel_group,
                                                  find_accel_new,
                                                  accel_label->accel_closure);
                    }
               
                }
            }

          if (key)
            {           
              accelerator = gtk_accelerator_name (key->accel_key,
                                                  key->accel_mods);
            }
        }
    }
  /*
   * Concatenate the bindings
   */
  if (item_keybinding || full_keybinding || accelerator)
    {
      gchar *temp;
      if (item_keybinding)
        {
          keybinding = g_strconcat (item_keybinding, KEYBINDING_SEPARATOR, NULL);
          g_free (item_keybinding);
        }
      else
        keybinding = g_strconcat (KEYBINDING_SEPARATOR, NULL);

      if (full_keybinding)
        {
          temp = g_strconcat (keybinding, full_keybinding, 
                              KEYBINDING_SEPARATOR, NULL);
          g_free (full_keybinding);
        }
      else
        temp = g_strconcat (keybinding, KEYBINDING_SEPARATOR, NULL);

      g_free (keybinding);
      keybinding = temp;
      if (accelerator)
        {
          temp = g_strconcat (keybinding, accelerator, NULL);
          g_free (accelerator);
          g_free (keybinding);
          keybinding = temp;
      }
    }
  g_free (gail_menu_item->click_keybinding);
  gail_menu_item->click_keybinding = keybinding;
  return keybinding;
}
Exemplo n.º 11
0
/* This function returns a string of the form A;B;C where A is
 * the keybinding for the widget; B is the keybinding to traverse
 * from the menubar and C is the accelerator. The items in the
 * keybinding to traverse from the menubar are separated by ":".
 */
static const gchar *
gtk_menu_item_accessible_get_keybinding (AtkAction *action,
                                         gint       i)
{
  gchar *keybinding = NULL;
  gchar *item_keybinding = NULL;
  gchar *full_keybinding = NULL;
  gchar *accelerator = NULL;
  GtkWidget *item;
  GtkWidget *temp_item;
  GtkWidget *child;
  GtkWidget *parent;

  item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
  if (item == NULL)
    return NULL;

  if (i != 0)
    return NULL;

  temp_item = item;
  while (TRUE)
    {
      GdkModifierType mnemonic_modifier = 0;
      guint key_val;
      gchar *key, *temp_keybinding;

      child = gtk_bin_get_child (GTK_BIN (temp_item));
      if (child == NULL)
        return NULL;

      parent = gtk_widget_get_parent (temp_item);
      if (!parent)
        /* parent can be NULL when activating a window from the panel */
        return NULL;

      if (GTK_IS_MENU_BAR (parent))
        {
          GtkWidget *toplevel;

          toplevel = gtk_widget_get_toplevel (parent);
          if (toplevel && GTK_IS_WINDOW (toplevel))
            mnemonic_modifier =
              gtk_window_get_mnemonic_modifier (GTK_WINDOW (toplevel));
        }

      if (GTK_IS_LABEL (child))
        {
          key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
          if (key_val != GDK_KEY_VoidSymbol)
            {
              key = gtk_accelerator_name (key_val, mnemonic_modifier);
              if (full_keybinding)
                temp_keybinding = g_strconcat (key, ":", full_keybinding, NULL);
              else
                temp_keybinding = g_strdup (key);

              if (temp_item == item)
                item_keybinding = g_strdup (key);

              g_free (key);
              g_free (full_keybinding);
              full_keybinding = temp_keybinding;
            }
          else
            {
              /* No keybinding */
              g_free (full_keybinding);
              full_keybinding = NULL;
              break;
            }
        }

      /* We have reached the menu bar so we are finished */
      if (GTK_IS_MENU_BAR (parent))
        break;

      g_return_val_if_fail (GTK_IS_MENU (parent), NULL);
      temp_item = gtk_menu_get_attach_widget (GTK_MENU (parent));
      if (!GTK_IS_MENU_ITEM (temp_item))
        {
          /* Menu is attached to something other than a menu item;
           * probably an option menu
           */
          g_free (full_keybinding);
          full_keybinding = NULL;
          break;
        }
    }

  parent = gtk_widget_get_parent (item);
  if (GTK_IS_MENU (parent))
    {
      GtkAccelGroup *group;
      GtkAccelKey *key;

      group = gtk_menu_get_accel_group (GTK_MENU (parent));
      if (group)
        key = gtk_accel_group_find (group, find_accel_by_widget, item);
      else
        {
          key = NULL;
          child = gtk_bin_get_child (GTK_BIN (item));
          if (GTK_IS_ACCEL_LABEL (child))
            {
              GtkAccelLabel *accel_label;
              GClosure      *accel_closure;

              accel_label = GTK_ACCEL_LABEL (child);
              g_object_get (accel_label, "accel-closure", &accel_closure, NULL);
              if (accel_closure)
                {
                  key = gtk_accel_group_find (gtk_accel_group_from_accel_closure (accel_closure),
                                              find_accel_by_closure,
                                              accel_closure);
                  g_closure_unref (accel_closure);
                }
            }
        }

     if (key)
       accelerator = gtk_accelerator_name (key->accel_key, key->accel_mods);
   }

  /* Concatenate the bindings */
  if (item_keybinding || full_keybinding || accelerator)
    {
      gchar *temp;
      if (item_keybinding)
        {
          keybinding = g_strconcat (item_keybinding, KEYBINDING_SEPARATOR, NULL);
          g_free (item_keybinding);
        }
      else
        keybinding = g_strdup (KEYBINDING_SEPARATOR);

      if (full_keybinding)
        {
          temp = g_strconcat (keybinding, full_keybinding,
                              KEYBINDING_SEPARATOR, NULL);
          g_free (full_keybinding);
        }
      else
        temp = g_strconcat (keybinding, KEYBINDING_SEPARATOR, NULL);

      g_free (keybinding);
      keybinding = temp;
      if (accelerator)
        {
          temp = g_strconcat (keybinding, accelerator, NULL);
          g_free (accelerator);
          g_free (keybinding);
          keybinding = temp;
      }
    }

  return keybinding;
}
Exemplo n.º 12
0
/**
 * Toggle the visibility of conversation window menu items
 *
 * The method of hiding the menu items is to reparent them back into their
 * original (still hidden) parent window.  This avoids conflicting with other
 * "hiding" methods used by plugins, such as widget sensitivity or visibility.
 *
 * When migrating to the Buddy List, left-justified items are inserted after
 * the last left-justified item.  Right-justified items are inserted before the
 * first right-justified item.  This appears to append conversation menu items
 * while keeping the Buddy List's notification icon on the far right.
 *
 * When migrating back to the conversation window, left-justified items are
 * prepended to all items.  Right-justified items are inserted before the first
 * right-justified item.  This gives the appearance of appending any newly
 * added menu items when they are all migrated to the Buddy List again.
 *
 * @param[in] gtkblist   The Buddy List whose menu needs adjusting
 * @param[in] visible    Whether the menu items are being shown or hidden
**/
void pwm_set_conv_menus_visible(PidginBuddyList *gtkblist, gboolean visible)
{
	PidginWindow *
	    gtkconvwin;		 /*< Conversation window merged into gtkblist */
	GtkMenu *submenu;	/*< A submenu of a conversation menu item    */
	GtkContainer *from_menu; /*< Menu bar of the window losing the items  */
	GtkContainer *to_menu;   /*< Menu bar of the window gaining the items */
	GtkWidget *blist_menu;   /*< The Buddy List menu bar                  */
	GtkWidget *convs_menu;   /*< The conversation window menu bar         */
	GtkWidget *item;	 /*< A menu item widget being transferred     */
	GList *children;	 /*< List of menu items in a given window     */
	GList *child;		 /*< A menu item in the list (iteration)      */
	GList *migrated_items;   /*< List of items added to the Buddy List    */
	gint index_left;	 /*< Position to insert left-justified items  */
	gint index_right;	/*< Position to insert right-justified items */

	gtkconvwin = pwm_blist_get_convs(gtkblist);

	/* Sanity check: Only act on a merged Buddy List window. */
	if (gtkconvwin == NULL)
		return;

	blist_menu = gtk_widget_get_parent(gtkblist->menutray);
	convs_menu = gtkconvwin->menu.menubar;
	from_menu = GTK_CONTAINER(visible ? convs_menu : blist_menu);
	to_menu = GTK_CONTAINER(visible ? blist_menu : convs_menu);
	migrated_items = pwm_fetch(gtkblist, "conv_menus");

	/* XXX: Drop the "Send To" menu to avoid segfaults. */
	if (visible && gtkconvwin->menu.send_to != NULL) {
		gtk_widget_destroy(gtkconvwin->menu.send_to);
		gtkconvwin->menu.send_to = NULL;
	}

	/* Locate the position before the first right-aligned menu item. */
	index_right = 0;
	children = gtk_container_get_children(to_menu);
	for (child = children; child != NULL; child = child->next)
		if (gtk_menu_item_get_right_justified(
			GTK_MENU_ITEM(child->data)))
			break;
		else
			index_right++;
	g_list_free(children);
	index_left = visible ? index_right : 0;

	/* Loop over each conversation menu item to move it to its destination.
	 */
	children =
	    visible ? gtk_container_get_children(from_menu) : migrated_items;
	for (child = children; child != NULL; child = child->next) {
		item = GTK_WIDGET(child->data);

		/* Reparent the item into the window based on existing justified
		 * items. */
		g_object_ref_sink(G_OBJECT(item));
		gtk_container_remove(from_menu, item);
		if (gtk_menu_item_get_right_justified(GTK_MENU_ITEM(item)))
			gtk_menu_shell_insert(GTK_MENU_SHELL(to_menu), item,
					      index_right);
		else
			gtk_menu_shell_insert(GTK_MENU_SHELL(to_menu), item,
					      index_left++);
		g_object_unref(G_OBJECT(item));
		index_right++;

		/* Register/Unregister its accelerator group with the Buddy List
		 * window. */
		submenu =
		    GTK_MENU(gtk_menu_item_get_submenu(GTK_MENU_ITEM(item)));
		if (visible)
			gtk_window_add_accel_group(
			    GTK_WINDOW(gtkblist->window),
			    gtk_menu_get_accel_group(submenu));
		else
			gtk_window_remove_accel_group(
			    GTK_WINDOW(gtkblist->window),
			    gtk_menu_get_accel_group(submenu));

		/* Add this menu item to the list for later restoration, if
		 * necessary. */
		if (visible)
			migrated_items =
			    g_list_append(migrated_items, child->data);
	}
	g_list_free(children);

	/* Update the stored pointer to the list of migrated items. */
	if (visible)
		pwm_store(gtkblist, "conv_menus", migrated_items);
	else
		pwm_clear(gtkblist, "conv_menus");
}
Exemplo n.º 13
0
GuiObject GuiMenuBar_addMenu2 (GuiObject bar, const wchar_t *title, long flags, GuiObject *menuTitle) {
	GuiObject menu;
	*menuTitle = gtk_menu_item_new_with_label (Melder_peekWcsToUtf8 (title));
	menu = gtk_menu_new ();
	GtkAccelGroup *ag = (GtkAccelGroup*)(GTK_IS_MENU_BAR (bar) ? g_object_get_data (G_OBJECT (bar), "accel-group") : gtk_menu_get_accel_group (GTK_MENU (bar)));
	gtk_menu_set_accel_group (GTK_MENU (menu), ag);
	if (flags & GuiMenu_INSENSITIVE)
		gtk_widget_set_sensitive (menu, FALSE);
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (*menuTitle), menu);
	gtk_menu_shell_append (GTK_MENU_SHELL (bar), *menuTitle);
	gtk_widget_show (menu);
	gtk_widget_show (*menuTitle);
	return menu;
}
Exemplo n.º 14
0
GuiObject GuiMenu_addItem (GuiObject menu, const wchar_t *title, long flags,
	void (*commandCallback) (GuiObject, XtPointer, XtPointer), const void *closure)
{
	Boolean toggle = flags & (GuiMenu_CHECKBUTTON | GuiMenu_RADIO_FIRST | GuiMenu_RADIO_NEXT | GuiMenu_TOGGLE_ON) ? True : False;
	GuiObject button;
	int accelerator = flags & 127;
	Melder_assert (title != NULL);
	if (toggle) {
		if (flags & (GuiMenu_RADIO_FIRST)) group = NULL;
		if (flags & (GuiMenu_RADIO_FIRST | GuiMenu_RADIO_NEXT)) {
			button = gtk_radio_menu_item_new_with_label (group, Melder_peekWcsToUtf8 (title));
			group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (button));
			//Melder_casual ("Created a radio menu item with title %ls, group %ld", title, group);
		} else {
			button = gtk_check_menu_item_new_with_label (Melder_peekWcsToUtf8 (title));
		}
	} else {
		button = gtk_menu_item_new_with_label (Melder_peekWcsToUtf8 (title));
	}
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), button);
	Melder_assert (button != NULL);
	if (flags & GuiMenu_INSENSITIVE)
		GuiObject_setSensitive (button, false);
	if (flags & GuiMenu_TOGGLE_ON)
		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (button), TRUE);
	if (accelerator) {
		/*
		 * For printable characters, the Command key is assumed.
		 */
		if (accelerator >= 32)
			flags |= GuiMenu_COMMAND;
		
		static const guint acceleratorKeys [] = { 0,
			GDK_Left, GDK_Right, GDK_Up, GDK_Down, GDK_Pause, GDK_Delete, GDK_Insert, GDK_BackSpace,
			GDK_Tab, GDK_Return, GDK_Home, GDK_End, GDK_Return, GDK_Page_Up, GDK_Page_Down, GDK_Escape,
			GDK_F1, GDK_F2, GDK_F3, GDK_F4, GDK_F5, GDK_F6, GDK_F7, GDK_F8, GDK_F9, GDK_F10, GDK_F11, GDK_F12,
			0, 0, 0 };

		int modifiers = 0;
		if (flags & GuiMenu_COMMAND) modifiers |= GDK_CONTROL_MASK;
		if (flags & GuiMenu_SHIFT)   modifiers |= GDK_SHIFT_MASK;
		if (flags & GuiMenu_OPTION)  modifiers |= GDK_MOD1_MASK;

		guint key;
		if (accelerator < 32) {
			key = acceleratorKeys [accelerator];
		} else {
			// gdk key symbols in the ASCII range are equal to ASCII
			key = accelerator;
		}

		GtkAccelGroup *ag = gtk_menu_get_accel_group (GTK_MENU (menu));

		if (key != 0)
			gtk_widget_add_accelerator (button, toggle ? "toggled" : "activate",
				ag, key, (GdkModifierType)modifiers, GTK_ACCEL_VISIBLE);
	}
	#if mac
		if (flags & GuiMenu_ATTRACTIVE) {
			//Melder_casual ("attractive!");
			SetItemStyle (button -> nat.entry.handle, button -> nat.entry.item, bold);
		}
	#endif
	if (commandCallback != NULL) {
		gulong handlerId = g_signal_connect (G_OBJECT (button),
			toggle ? "toggled" : "activate",
			G_CALLBACK (commandCallback), (gpointer) closure);
		g_object_set_data (G_OBJECT (button), "handlerId", (gpointer) handlerId);
		g_object_set_data (G_OBJECT (button), "commandCallback", (gpointer) commandCallback);
		g_object_set_data (G_OBJECT (button), "commandClosure", (gpointer) closure);
	} else {
		gtk_widget_set_sensitive (button, FALSE);
	}
	gtk_widget_show (button);

	return button;
}
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


#include "gtkpeer.h"
#include "gnu_java_awt_peer_gtk_GtkMenuPeer.h"

static void
accel_attach (GtkMenuItem *menu_item,
	      gpointer *user_data __attribute__((unused)))
{
  GtkAccelGroup *accel;

  accel = gtk_menu_get_accel_group (GTK_MENU (menu_item->submenu));
  _gtk_accel_group_attach (accel, 
    G_OBJECT (gtk_widget_get_toplevel (GTK_WIDGET(menu_item))));
}

JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup
  (JNIEnv *env, jobject obj, jobject parent)
{
  void *ptr1, *ptr2;

  ptr1 = NSA_GET_PTR (env, obj);

  gdk_threads_enter ();
  if (!parent)
    {
      gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),