static void serializer_visit_label (Serializer* self, GtkLabel* label) { char* label_text; g_return_if_fail (self != NULL); g_return_if_fail (label != NULL); label_text = g_strdup (gtk_label_get_label (label)); g_string_append (self->priv->label_sb, label_text); g_debug ("serializer.vala:143: append text = %s", label_text); if (GTK_IS_ACCEL_LABEL (label)) { GtkLabel* _tmp0_; GtkLabel* _tmp1_; char* accel_string; gboolean _tmp2_ = FALSE; gtk_accel_label_refetch ((_tmp0_ = label, GTK_IS_ACCEL_LABEL (_tmp0_) ? ((GtkAccelLabel*) _tmp0_) : NULL)); accel_string = string_strip ((_tmp1_ = label, GTK_IS_ACCEL_LABEL (_tmp1_) ? ((GtkAccelLabel*) _tmp1_) : NULL)->accel_string); if (string_get_length (accel_string) > 0) { _tmp2_ = _vala_strcmp0 (accel_string, "-/-") != 0; } else { _tmp2_ = FALSE; } if (_tmp2_) { char* _tmp3_; g_string_append (self->priv->sb, _tmp3_ = g_markup_printf_escaped (" accel=\"%s\"", accel_string)); _g_free0 (_tmp3_); } _g_free0 (accel_string); } _g_free0 (label_text); }
static void carbon_menu_item_update_accel_closure (CarbonMenuItem *carbon_item, GtkWidget *widget) { GtkAccelGroup *group; GtkWidget *label; get_menu_label_text (widget, &label); if (carbon_item->accel_closure) { group = gtk_accel_group_from_accel_closure (carbon_item->accel_closure); g_signal_handlers_disconnect_by_func (group, carbon_menu_item_accel_changed, widget); g_closure_unref (carbon_item->accel_closure); carbon_item->accel_closure = NULL; } if (GTK_IS_ACCEL_LABEL (label)) g_object_get (label, "accel-closure", &carbon_item->accel_closure, NULL); if (carbon_item->accel_closure) { group = gtk_accel_group_from_accel_closure (carbon_item->accel_closure); g_signal_connect_object (group, "accel-changed", G_CALLBACK (carbon_menu_item_accel_changed), widget, 0); } carbon_menu_item_update_accelerator (carbon_item, widget); }
static void carbon_menu_item_accel_changed (GtkAccelGroup *accel_group, guint keyval, GdkModifierType modifier, GClosure *accel_closure, GtkWidget *widget) { CarbonMenuItem *carbon_item = carbon_menu_item_get (widget); GtkWidget *label; get_menu_label_text (widget, &label); if (GTK_IS_ACCEL_LABEL (label)) { GClosure *closure; g_object_get (label, "accel-closure", &closure, NULL); if (closure) { if (closure == accel_closure) carbon_menu_item_update_accelerator (carbon_item, widget); g_closure_unref (closure); } } }
static void carbon_menu_item_accel_changed (GtkAccelGroup *accel_group, guint keyval, GdkModifierType modifier, GClosure *accel_closure, GtkWidget *widget) { CarbonMenuItem *carbon_item = carbon_menu_item_get (widget); GtkWidget *label; get_menu_label_text (widget, &label); if (GTK_IS_ACCEL_LABEL (label) && GTK_ACCEL_LABEL (label)->accel_closure == accel_closure) carbon_menu_item_update_accelerator (carbon_item, widget); }
static void gail_label_real_initialize (AtkObject *obj, gpointer data) { GtkWidget *widget; GailLabel *gail_label; ATK_OBJECT_CLASS (gail_label_parent_class)->initialize (obj, data); gail_label = GAIL_LABEL (obj); gail_label->window_create_handler = 0; gail_label->has_top_level = FALSE; gail_label->cursor_position = 0; gail_label->selection_bound = 0; gail_label->textutil = NULL; gail_label->label_length = 0; widget = GTK_WIDGET (data); if (gtk_widget_get_mapped (widget)) gail_label_init_text_util (gail_label, widget); else g_signal_connect (widget, "map", G_CALLBACK (gail_label_map_gtk), gail_label); /* * Check whether ancestor of GtkLabel is a GtkButton and if so * set accessible parent for GailLabel */ while (widget != NULL) { widget = gtk_widget_get_parent (widget); if (GTK_IS_BUTTON (widget)) { atk_object_set_parent (obj, gtk_widget_get_accessible (widget)); break; } } if (GTK_IS_ACCEL_LABEL (widget)) obj->role = ATK_ROLE_ACCEL_LABEL; else obj->role = ATK_ROLE_LABEL; }
/** * dbusmenu_menuitem_property_set_shortcut_menuitem: * @menuitem: The #DbusmenuMenuitem to set the shortcut on * @gmi: A menu item to steal the shortcut off of * * Takes the shortcut that is installed on a menu item and calls * #dbusmenu_menuitem_property_set_shortcut with it. It also sets * up listeners to watch it change. * * Return value: Whether it was successful at setting the property. */ gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); g_return_val_if_fail(GTK_IS_MENU_ITEM(gmi), FALSE); GClosure * closure = NULL; GtkWidget *label = gtk_bin_get_child(GTK_BIN (gmi)); if (GTK_IS_ACCEL_LABEL (label)) { g_object_get (label, "accel-closure", &closure, NULL); } if (closure == NULL) { /* As a fallback, check for a closure in the related menu item. This actually happens with SWT menu items. */ GList * closures = gtk_widget_list_accel_closures (GTK_WIDGET (gmi)); if (closures == NULL) return FALSE; closure = closures->data; g_list_free (closures); } GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure); /* Apparently this is more common than I thought. */ if (group == NULL) { return FALSE; } GtkAccelKey * key = gtk_accel_group_find(group, find_closure, closure); /* Again, not much we can do except complain loudly. */ g_return_val_if_fail(key != NULL, FALSE); if (!gtk_accelerator_valid (key->accel_key, key->accel_mods)) return FALSE; return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); }
static void set_accel (GtkApplication *app, GtkWidget *widget) { GtkWidget *accel_label; const gchar *action; gchar **accels; guint key; GdkModifierType mods; accel_label = gtk_bin_get_child (GTK_BIN (widget)); g_assert (GTK_IS_ACCEL_LABEL (accel_label)); action = gtk_actionable_get_action_name (GTK_ACTIONABLE (widget)); accels = gtk_application_get_accels_for_action (app, action); gtk_accelerator_parse (accels[0], &key, &mods); gtk_accel_label_set_accel (GTK_ACCEL_LABEL (accel_label), key, mods); g_strfreev (accels); }
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; }
static void carbon_menu_item_update_accelerator (CarbonMenuItem *carbon_item, GtkWidget *widget) { GtkWidget *label; get_menu_label_text (widget, &label); if (GTK_IS_ACCEL_LABEL (label)) { GClosure *closure; g_object_get (label, "accel-closure", &closure, NULL); if (closure) { GtkAccelGroup *group; GtkAccelKey *key; group = gtk_accel_group_from_accel_closure (closure); key = gtk_accel_group_find (group, accel_find_func, closure); g_closure_unref (closure); if (key && key->accel_key && key->accel_flags & GTK_ACCEL_VISIBLE) { GdkDisplay *display = gtk_widget_get_display (widget); GdkKeymap *keymap = gdk_keymap_get_for_display (display); GdkKeymapKey *keys; gint n_keys; if (gdk_keymap_get_entries_for_keyval (keymap, key->accel_key, &keys, &n_keys)) { UInt8 modifiers = 0; SetMenuItemCommandKey (carbon_item->menu, carbon_item->index, true, keys[0].keycode); g_free (keys); if (key->accel_mods) { if (key->accel_mods & GDK_SHIFT_MASK) modifiers |= kMenuShiftModifier; if (key->accel_mods & GDK_MOD1_MASK) modifiers |= kMenuOptionModifier; } if (!(key->accel_mods & GDK_META_MASK)) { modifiers |= kMenuNoCommandModifier; } SetMenuItemModifiers (carbon_item->menu, carbon_item->index, modifiers); return; } } } } /* otherwise, clear the menu shortcut */ SetMenuItemModifiers (carbon_item->menu, carbon_item->index, kMenuNoModifiers | kMenuNoCommandModifier); ChangeMenuItemAttributes (carbon_item->menu, carbon_item->index, 0, kMenuItemAttrUseVirtualKey); SetMenuItemCommandKey (carbon_item->menu, carbon_item->index, false, 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; }