static gboolean parent_set_emission_hook (GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer data) { GtkWidget *instance = g_value_get_object (param_values); if (GTK_IS_MENU_ITEM (instance)) { GtkWidget *previous_parent = g_value_get_object (param_values + 1); GtkWidget *menu_shell = NULL; if (GTK_IS_MENU_SHELL (previous_parent)) { menu_shell = previous_parent; } else { GtkWidget *parent; parent = gtk_widget_get_parent (instance); if (GTK_IS_MENU_SHELL (parent)) { menu_shell = parent; } } if (menu_shell) { CarbonMenu *carbon_menu = carbon_menu_get (menu_shell); if (carbon_menu) { #if 0 g_printerr ("%s: item %s %p (%s, %s)\n", G_STRFUNC, previous_parent ? "removed from" : "added to", menu_shell, get_menu_label_text (instance, NULL), g_type_name (G_TYPE_FROM_INSTANCE (instance))); #endif sync_menu_shell (GTK_MENU_SHELL (menu_shell), carbon_menu->menu, carbon_menu->toplevel, FALSE); } } } return TRUE; }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_removeMenuBarPeer (JNIEnv *env, jobject obj) { void *ptr; void *mptr; void *fixed; GList* children; gdk_threads_enter (); ptr = gtkpeer_get_widget (env, obj); fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; children = gtk_container_get_children (GTK_CONTAINER (fixed)); while (children != NULL && !GTK_IS_MENU_SHELL (children->data)) { children = children->next; } /* If there's a menu bar, remove it. */ if (children != NULL) { mptr = children->data; /* This will actually destroy the MenuBar. By removing it from its parent, the reference count for the MenuBar widget will decrement to 0. The widget will be automatically destroyed by GTK. */ gtk_container_remove (GTK_CONTAINER (fixed), GTK_WIDGET (mptr)); } gdk_threads_leave (); }
static void populate_entry_popup(GtkTextView *text, GtkMenu *menu, JamView *view) { GtkWidget *menu_item; g_return_if_fail(menu != NULL); g_return_if_fail(GTK_IS_MENU_SHELL(menu)); menu_item = gtk_separator_menu_item_new(); gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menu_item); gtk_widget_show(menu_item); menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_REDO, NULL); gtk_widget_set_sensitive(menu_item, undomgr_can_redo(view->undomgr)); g_signal_connect_swapped(G_OBJECT(menu_item), "activate", G_CALLBACK(redo_cb), view); gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menu_item); gtk_widget_show(menu_item); menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_UNDO, NULL); gtk_widget_set_sensitive(menu_item, undomgr_can_undo(view->undomgr)); g_signal_connect_swapped(G_OBJECT(menu_item), "activate", G_CALLBACK(undo_cb), view); gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menu_item); gtk_widget_show(menu_item); }
static gboolean gtk_service_button_release_event(GtkWidget *widget, GdkEventButton *event) { GtkService *service = GTK_SERVICE(widget); GtkWidget *parent; if (event->button != 1 && event->button != 3) goto activate; if (event->button == 1) { if (connman_service_is_connected(service->path) == TRUE) connman_service_disconnect(service->path); else { cui_agent_set_selected_service(service->path, connman_service_get_name(service->path)); connman_service_connect(service->path); } } else if (event->button == 3) { service->priv->selected = TRUE; cui_settings_popup(service->path); } activate: parent = gtk_widget_get_parent (widget); if (parent != NULL && GTK_IS_MENU_SHELL(parent) == TRUE) { GtkMenuShell *menu_shell = GTK_MENU_SHELL(parent); gtk_menu_shell_activate_item(menu_shell, widget, TRUE); } return TRUE; }
static gboolean gtk_menu_item_accessible_do_action (AtkAction *action, gint i) { GtkWidget *item, *item_parent; gboolean item_mapped; item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action)); if (item == NULL) return FALSE; if (i != 0) return FALSE; if (!gtk_widget_get_sensitive (item) || !gtk_widget_get_visible (item)) return FALSE; item_parent = gtk_widget_get_parent (item); if (!GTK_IS_MENU_SHELL (item_parent)) return FALSE; gtk_menu_shell_select_item (GTK_MENU_SHELL (item_parent), item); item_mapped = gtk_widget_get_mapped (item); /* This is what is called when <Return> is pressed for a menu item. * The last argument means 'force hide'. */ g_signal_emit_by_name (item_parent, "activate-current", 1); if (!item_mapped) ensure_menus_unposted (GTK_MENU_ITEM_ACCESSIBLE (action)); return TRUE; }
void glade_gtk_menu_item_action_activate (GladeWidgetAdaptor * adaptor, GObject * object, const gchar * action_path) { GObject *obj = NULL, *shell = NULL; GladeWidget *w = glade_widget_get_from_gobject (object); while ((w = glade_widget_get_parent (w))) { obj = glade_widget_get_object (w); if (GTK_IS_MENU_SHELL (obj)) shell = obj; } if (strcmp (action_path, "launch_editor") == 0) { if (shell) object = shell; if (GTK_IS_MENU_BAR (object)) glade_gtk_menu_shell_launch_editor (object, _("Edit Menu Bar")); else if (GTK_IS_MENU (object)) glade_gtk_menu_shell_launch_editor (object, _("Edit Menu")); } else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, object, action_path); if (shell) gtk_menu_shell_deactivate (GTK_MENU_SHELL (shell)); }
static gboolean gtk_technology_button_release_event(GtkWidget *widget, GdkEventButton *event) { GtkTechnology *technology = GTK_TECHNOLOGY(widget); GtkTechnologyPrivate *priv = technology->priv; gboolean enable; if (event->button != 1 && event->button != 3) return TRUE; if (event->button == 3) { GtkWidget *parent; const char *type; type = connman_technology_get_type(technology->path); if (g_strcmp0(type, "wifi") == 0) cui_agent_set_wifi_tethering_settings(technology->path, FALSE); parent = gtk_widget_get_parent (widget); if (parent != NULL && GTK_IS_MENU_SHELL(parent) == TRUE) { GtkMenuShell *menu_shell = GTK_MENU_SHELL(parent); gtk_menu_shell_activate_item(menu_shell, widget, TRUE); } return TRUE; } enable = !gtk_switch_get_active(priv->enabler); if (connman_technology_enable(technology->path, enable) == 0) gtk_widget_set_sensitive((GtkWidget *)priv->enabler, FALSE); return TRUE; }
static gboolean qtcMenuShellLeave(GtkWidget *widget, GdkEventCrossing *event, void *data) { QTC_UNUSED(data); QTC_UNUSED(event); if (GTK_IS_MENU_SHELL(widget) && GTK_IS_CONTAINER(widget)) { GList *children = gtk_container_get_children(GTK_CONTAINER(widget)); for (GList *child = children;child;child = g_list_next(child)) { if ((child->data) && GTK_IS_MENU_ITEM(child->data) && (gtk_widget_get_state(GTK_WIDGET(child->data)) != GTK_STATE_INSENSITIVE)) { GtkWidget *submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(child->data)); GtkWidget *topLevel = submenu ? gtk_widget_get_toplevel(submenu) : NULL; if (submenu && ((!GTK_IS_MENU(submenu)) || (!(gtk_widget_get_realized(submenu) && gtk_widget_get_visible(submenu) && gtk_widget_get_realized(topLevel) && gtk_widget_get_visible(topLevel))))) { gtk_widget_set_state(GTK_WIDGET(child->data), GTK_STATE_NORMAL); } } } if (children) { g_list_free(children); } } return false; }
static gboolean gail_deselect_watcher (GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer data) { GObject *object; GtkWidget *widget; GtkWidget *menu_shell; object = g_value_get_object (param_values + 0); g_return_val_if_fail (GTK_IS_WIDGET(object), FALSE); widget = GTK_WIDGET (object); if (!GTK_IS_MENU_ITEM (widget)) return TRUE; if (subsequent_focus_widget == widget) subsequent_focus_widget = NULL; menu_shell = gtk_widget_get_parent (widget); if (GTK_IS_MENU_SHELL (menu_shell)) { GtkWidget *parent_menu_shell; parent_menu_shell = gtk_menu_shell_get_parent_shell (GTK_MENU_SHELL (menu_shell)); if (parent_menu_shell) { GtkWidget *active_menu_item; active_menu_item = gtk_menu_shell_get_selected_item (GTK_MENU_SHELL (parent_menu_shell)); if (active_menu_item) { gail_focus_notify_when_idle (active_menu_item); } } else { if (!GTK_IS_MENU_BAR (menu_shell)) { gail_focus_notify_when_idle (menu_shell); } } } was_deselect = TRUE; return TRUE; }
static void ide_editor_frame__search_populate_popup (IdeEditorFrame *self, GtkWidget *popup, GdTaggedEntry *entry) { g_assert (IDE_IS_EDITOR_FRAME (self)); g_assert (GTK_IS_WIDGET (popup)); g_assert (GD_IS_TAGGED_ENTRY (entry)); if (GTK_IS_MENU_SHELL (popup)) { GMenu *menu; GActionGroup *group; GAction *action; GtkEntryBuffer *buffer; GtkClipboard *clipboard; gboolean clipboard_contains_text; gboolean entry_has_selection; group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry"); menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "ide-editor-frame-search-menu"); gtk_menu_shell_bind_model (GTK_MENU_SHELL (popup), G_MENU_MODEL (menu), NULL, TRUE); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD); clipboard_contains_text = gtk_clipboard_wait_is_text_available (clipboard); action = g_action_map_lookup_action (G_ACTION_MAP (group), "paste-clipboard"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), clipboard_contains_text); entry_has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), NULL, NULL); action = g_action_map_lookup_action (G_ACTION_MAP (group), "cut-clipboard"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), entry_has_selection); action = g_action_map_lookup_action (G_ACTION_MAP (group), "copy-clipboard"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), entry_has_selection); action = g_action_map_lookup_action (G_ACTION_MAP (group), "delete-selection"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), entry_has_selection); action = g_action_map_lookup_action (G_ACTION_MAP (group), "select-all"); buffer = gtk_entry_get_buffer (GTK_ENTRY (self->search_entry)); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), gtk_entry_buffer_get_length (buffer) > 0); } }
void c_main_window_pack_menus (CMainWindow * self, GtkMenuShell* menus) { g_return_if_fail (C_IS_MAIN_WINDOW (self)); g_return_if_fail (GTK_IS_MENU_SHELL (menus)); if (C_MAIN_WINDOW_GET_IFACE (self)->pack_menus) { C_MAIN_WINDOW_GET_IFACE (self)->pack_menus (self, menus); } else { g_warning ("%s doesn't implement pack_menus()", G_OBJECT_TYPE_NAME (self)); } }
void init_clock_indicator(void) { if(!config.clock.enabled) { gtk_widget_hide(greeter.ui.clock.time_box); return; } if(config.clock.calendar && GTK_IS_MENU_SHELL(greeter.ui.clock.time_menu)) { GtkWidget* calendar_menuitem = NULL; #ifdef CLOCK_USE_IDO_CALENDAR calendar_menuitem = ido_calendar_menu_item_new(); greeter.ui.clock.calendar_widget = ido_calendar_menu_item_get_calendar(IDO_CALENDAR_MENU_ITEM(calendar_menuitem)); #else calendar_menuitem = create_simple_calendar_item(&greeter.ui.clock.calendar_widget); #endif if(!greeter.ui.clock.date_widget) greeter.ui.clock.date_widget = gtk_menu_item_new_with_label(""); gtk_menu_shell_append(GTK_MENU_SHELL(greeter.ui.clock.time_menu), greeter.ui.clock.date_widget); gtk_menu_shell_append(GTK_MENU_SHELL(greeter.ui.clock.time_menu), calendar_menuitem); gtk_widget_add_events(greeter.ui.clock.date_widget, GDK_VISIBILITY_NOTIFY_MASK); visibility_notify_id = g_signal_connect(greeter.ui.clock.date_widget, "visibility-notify-event", G_CALLBACK(on_visibility_notify), NULL); gtk_widget_show_all(greeter.ui.clock.time_menu); if(GTK_IS_MENU_ITEM(greeter.ui.clock.time_widget)) gtk_menu_item_set_submenu(GTK_MENU_ITEM(greeter.ui.clock.time_widget), greeter.ui.clock.time_menu); } else if(GTK_IS_MENU_ITEM(greeter.ui.clock.time_widget)) gtk_menu_item_set_submenu(GTK_MENU_ITEM(greeter.ui.clock.time_widget), NULL); else gtk_widget_hide(greeter.ui.clock.time_menu); if(greeter.ui.clock.time_widget) { clock_handler(NULL); g_timeout_add_seconds(1, (GSourceFunc)clock_handler, (gpointer)TRUE); gtk_widget_show(greeter.ui.clock.time_widget); } }
static void log_window_popup_menu_extend(GtkTextView *textview, GtkMenu *menu, LogWindow *logwin) { GtkWidget *menuitem; cm_return_if_fail(menu != NULL); cm_return_if_fail(GTK_IS_MENU_SHELL(menu)); menuitem = gtk_separator_menu_item_new(); gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem); gtk_widget_show(menuitem); menuitem = gtk_menu_item_new_with_mnemonic(_("Clear _Log")); g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(log_window_clear), logwin); gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem); gtk_widget_show(menuitem); }
void ige_mac_menu_set_menu_bar (GtkMenuShell *menu_shell) { CarbonMenu *current_menu; MenuRef carbon_menubar; g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); if (carbon_menu_quark == 0) carbon_menu_quark = g_quark_from_static_string ("CarbonMenu"); if (carbon_menu_item_quark == 0) carbon_menu_item_quark = g_quark_from_static_string ("CarbonMenuItem"); current_menu = carbon_menu_get (GTK_WIDGET (menu_shell)); if (current_menu) { SetRootMenu (current_menu->menu); return; } CreateNewMenu (0 /*id*/, 0 /*options*/, &carbon_menubar); SetRootMenu (carbon_menubar); setup_menu_event_handler (); if (emission_hook_id == 0) { emission_hook_id = g_signal_add_emission_hook (g_signal_lookup ("parent-set", GTK_TYPE_WIDGET), 0, parent_set_emission_hook, NULL, NULL); } emission_hook_count++; g_signal_connect (menu_shell, "destroy", G_CALLBACK (parent_set_emission_hook_remove), NULL); sync_menu_shell (menu_shell, carbon_menubar, TRUE, FALSE); }
void rbgtk_initialize_gtkobject(VALUE obj, GtkObject *gtkobj) { gtkobj = g_object_ref(gtkobj); gtk_object_sink(gtkobj); G_INITIALIZE(obj, gtkobj); if (GTK_IS_WINDOW(gtkobj) || GTK_IS_MENU_SHELL(gtkobj)) { VALUE klass; klass = rb_obj_class(obj); if (rb_ivar_defined(klass, id__windows__) == Qfalse) { rb_ivar_set(klass, id__windows__, rb_hash_new()); } rb_hash_aset(rb_ivar_get(klass, id__windows__), obj, Qnil); g_signal_connect_after(gtkobj, "destroy", G_CALLBACK(remove_from_windows), (gpointer)obj); } }
static gboolean gail_deactivate_watcher (GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer data) { GObject *object; GtkWidget *widget; GtkMenuShell *shell; GtkWidget *focus = NULL; object = g_value_get_object (param_values + 0); g_return_val_if_fail (GTK_IS_WIDGET(object), FALSE); widget = GTK_WIDGET (object); g_return_val_if_fail (GTK_IS_MENU_SHELL(widget), TRUE); shell = GTK_MENU_SHELL(widget); if (! gtk_menu_shell_get_parent_shell (shell)) focus = focus_before_menu; /* * If we are waiting to report focus on a menubar or a menu item * because of a previous deselect, cancel it. */ if (was_deselect && focus_notify_handler && next_focus_widget && (GTK_IS_MENU_BAR (next_focus_widget) || GTK_IS_MENU_ITEM (next_focus_widget))) { void *vp_next_focus_widget = &next_focus_widget; g_source_remove (focus_notify_handler); g_object_remove_weak_pointer (G_OBJECT (next_focus_widget), vp_next_focus_widget); next_focus_widget = NULL; focus_notify_handler = 0; was_deselect = FALSE; } gail_focus_notify_when_idle (focus); return TRUE; }
static void gimp_ui_manager_item_realize (GtkWidget *widget, GimpUIManager *manager) { GtkWidget *menu; GtkWidget *submenu; g_signal_handlers_disconnect_by_func (widget, gimp_ui_manager_item_realize, manager); menu = gtk_widget_get_parent (widget); if (GTK_IS_MENU_SHELL (menu)) { static GQuark quark_key_press_connected = 0; if (! quark_key_press_connected) quark_key_press_connected = g_quark_from_static_string ("gimp-menu-item-key-press-connected"); if (! GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (menu), quark_key_press_connected))) { g_signal_connect (menu, "key-press-event", G_CALLBACK (gimp_ui_manager_item_key_press), manager); g_object_set_qdata (G_OBJECT (menu), quark_key_press_connected, GINT_TO_POINTER (TRUE)); } } submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); if (submenu) g_object_set_qdata (G_OBJECT (submenu), GIMP_HELP_ID, g_object_get_qdata (G_OBJECT (widget), GIMP_HELP_ID)); }
void sync_menu_takeover_menu (GtkMenuShell *menu_shell) { static MenuRef carbon_menubar = NULL; g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); if (carbon_menu_quark == 0) carbon_menu_quark = g_quark_from_static_string ("CarbonMenu"); if (carbon_menu_item_quark == 0) carbon_menu_item_quark = g_quark_from_static_string ("CarbonMenuItem"); if (!carbon_menubar) { carbon_menubar = AcquireRootMenu(); setup_menu_event_handler (); } sync_menu_shell (menu_shell, carbon_menubar, TRUE); }
void debug_dump_menus_cmd_callback (GtkAction *action, gpointer data) { GList *list; for (list = gimp_menu_factory_get_registered_menus (global_menu_factory); list; list = g_list_next (list)) { GimpMenuFactoryEntry *entry = list->data; GList *managers; managers = gimp_ui_managers_from_name (entry->identifier); if (managers) { GimpUIManager *manager = managers->data; GList *list; for (list = manager->registered_uis; list; list = g_list_next (list)) { GimpUIManagerUIEntry *ui_entry = list->data; if (GTK_IS_MENU_SHELL (ui_entry->widget)) { g_print ("\n\n" "========================================\n" "Menu: %s%s\n" "========================================\n\n", entry->identifier, ui_entry->ui_path); debug_dump_menus_recurse_menu (ui_entry->widget, 1, entry->identifier); g_print ("\n"); } } } } }
static gboolean qtcMenuShellMotion(GtkWidget *widget, GdkEventMotion *event, void *data) { QTC_UNUSED(data); QTC_UNUSED(event); if (GTK_IS_MENU_SHELL(widget)) { int pointer_x, pointer_y; GdkModifierType pointer_mask; gdk_window_get_pointer(gtk_widget_get_window(widget), &pointer_x, &pointer_y, &pointer_mask); if (GTK_IS_CONTAINER(widget)) { GList *children = gtk_container_get_children(GTK_CONTAINER(widget)); for (GList *child = children;child;child = g_list_next(child)) { if ((child->data) && GTK_IS_WIDGET(child->data) && (gtk_widget_get_state(GTK_WIDGET(child->data)) != GTK_STATE_INSENSITIVE)) { QtcRect alloc = qtcWidgetGetAllocation(GTK_WIDGET(child->data)); if ((pointer_x >= alloc.x) && (pointer_y >= alloc.y) && (pointer_x < (alloc.x + alloc.width)) && (pointer_y < (alloc.y + alloc.height))) { gtk_widget_set_state(GTK_WIDGET(child->data), GTK_STATE_PRELIGHT); } else { gtk_widget_set_state(GTK_WIDGET(child->data), GTK_STATE_NORMAL); } } } if (children) { g_list_free(children); } } } return false; }
static gboolean gail_focus_watcher (GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer data) { GObject *object; GtkWidget *widget; GdkEvent *event; object = g_value_get_object (param_values + 0); g_return_val_if_fail (GTK_IS_WIDGET(object), FALSE); event = g_value_get_boxed (param_values + 1); widget = GTK_WIDGET (object); if (event->type == GDK_FOCUS_CHANGE) { if (event->focus_change.in) { if (GTK_IS_WINDOW (widget)) { GtkWidget *focus_widget; GtkWindow *window; GtkWindowType type; window = GTK_WINDOW (widget); focus_widget = gtk_window_get_focus (window); g_object_get (window, "type", &type, NULL); if (focus_widget) { /* * If we already have a potential focus widget set this * windows's focus widget to focus_before_menu so that * it will be reported when menu item is unset. */ if (next_focus_widget) { if (GTK_IS_MENU_ITEM (next_focus_widget) && !focus_before_menu) { void *vp_focus_before_menu = &focus_before_menu; focus_before_menu = focus_widget; g_object_add_weak_pointer (G_OBJECT (focus_before_menu), vp_focus_before_menu); } return TRUE; } widget = focus_widget; } else if (type == GTK_WINDOW_POPUP) { if (GTK_IS_BIN (widget)) { GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget)); if (GTK_IS_WIDGET (child) && gtk_widget_has_grab (child)) { if (GTK_IS_MENU_SHELL (child)) { if (gtk_menu_shell_get_selected_item (GTK_MENU_SHELL (child))) { /* * We have a menu which has a menu item selected * so we do not report focus on the menu. */ return TRUE; } } widget = child; } } else /* popup window has no children; this edge case occurs in some custom code (OOo for instance) */ { return TRUE; } } else /* Widget is a non-popup toplevel with no focus children; don't emit for this case either, as it's useless */ { return TRUE; } } } else { if (next_focus_widget) { GtkWidget *toplevel; toplevel = gtk_widget_get_toplevel (next_focus_widget); if (toplevel == widget) next_focus_widget = NULL; } /* focus out */ widget = NULL; } } else { if (event->type == GDK_MOTION_NOTIFY && gtk_widget_has_focus (widget)) { if (widget == _focus_widget) { return TRUE; } } else { return TRUE; } } #ifdef GDK_WINDOWING_X11 /* * If the focus widget is a GtkSocket without a plug * then ignore the focus notification as the embedded * plug will report a focus notification. */ if (GTK_IS_SOCKET (widget) && gtk_socket_get_plug_window (GTK_SOCKET (widget)) != NULL) return TRUE; #endif /* * The widget may not yet be visible on the screen so we wait until it is. */ gail_focus_notify_when_idle (widget); return TRUE; }
static void thunar_history_show_menu (GtkAction *action, GtkWidget *menu, ThunarHistory *history) { ThunarIconFactory *icon_factory; GtkIconTheme *icon_theme; GCallback handler; GtkWidget *image; GtkWidget *item; GdkPixbuf *icon; GList *lp; guint n; _thunar_return_if_fail (GTK_IS_ACTION (action)); _thunar_return_if_fail (GTK_IS_MENU_SHELL (menu)); _thunar_return_if_fail (THUNAR_IS_HISTORY (history)); /* determine the icon factory to use to load the icons */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (menu)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); /* check if we have "Back" or "Forward" here */ if (action == history->action_back) { /* display the "back" list */ lp = history->back_list; handler = G_CALLBACK (thunar_history_action_back_nth); } else { /* display the "forward" list */ lp = history->forward_list; handler = G_CALLBACK (thunar_history_action_forward_nth); } /* add menu items for all list items */ for (n = 1; lp != NULL; lp = lp->next, ++n) { /* load the icon for the file */ icon = thunar_icon_factory_load_file_icon (icon_factory, lp->data, THUNAR_FILE_ICON_STATE_DEFAULT, 16); /* add an item for this file */ item = gtk_image_menu_item_new_with_label (thunar_file_get_display_name (lp->data)); g_object_set_data (G_OBJECT (item), I_("thunar-history-index"), GUINT_TO_POINTER (n)); g_signal_connect_object (G_OBJECT (item), "activate", handler, history, 0); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* setup the image for the file */ image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); gtk_widget_show (image); /* release the icon */ g_object_unref (G_OBJECT (icon)); } /* release the icon factory */ g_object_unref (G_OBJECT (icon_factory)); }
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; }