static void gtk_tool_item_set_related_action (GtkToolItem *item, GtkAction *action) { if (item->priv->action == action) return; gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action); item->priv->action = action; if (action) { gtk_tool_item_rebuild_menu (item); } }
JNIEXPORT void JNICALL Java_org_gnome_gtk_GtkToolItem_gtk_1tool_1item_1rebuild_1menu ( JNIEnv* env, jclass cls, jlong _self ) { GtkToolItem* self; // convert parameter self self = (GtkToolItem*) _self; // call function gtk_tool_item_rebuild_menu(self); // cleanup parameter self }
static VALUE rg_rebuild_menu(VALUE self) { gtk_tool_item_rebuild_menu(_SELF(self)); return self; }
static void gtk_tool_button_construct_contents (GtkToolItem *tool_item) { GtkToolButton *button = GTK_TOOL_BUTTON (tool_item); GtkWidget *label = NULL; GtkWidget *icon = NULL; GtkToolbarStyle style; gboolean need_label = FALSE; gboolean need_icon = FALSE; GtkIconSize icon_size; GtkWidget *box = NULL; guint icon_spacing; GtkOrientation text_orientation = GTK_ORIENTATION_HORIZONTAL; GtkSizeGroup *size_group = NULL; button->priv->contents_invalid = FALSE; gtk_widget_style_get (GTK_WIDGET (tool_item), "icon-spacing", &icon_spacing, NULL); if (button->priv->icon_widget && button->priv->icon_widget->parent) { gtk_container_remove (GTK_CONTAINER (button->priv->icon_widget->parent), button->priv->icon_widget); } if (button->priv->label_widget && button->priv->label_widget->parent) { gtk_container_remove (GTK_CONTAINER (button->priv->label_widget->parent), button->priv->label_widget); } if (GTK_BIN (button->priv->button)->child) { /* Note: we are not destroying the label_widget or icon_widget * here because they were removed from their containers above */ gtk_widget_destroy (GTK_BIN (button->priv->button)->child); } style = gtk_tool_item_get_toolbar_style (GTK_TOOL_ITEM (button)); if (style != GTK_TOOLBAR_TEXT) need_icon = TRUE; if (style != GTK_TOOLBAR_ICONS && style != GTK_TOOLBAR_BOTH_HORIZ) need_label = TRUE; if (style == GTK_TOOLBAR_BOTH_HORIZ && (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (button)) || gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL || gtk_tool_item_get_text_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL)) { need_label = TRUE; } if (style == GTK_TOOLBAR_ICONS && button->priv->icon_widget == NULL && button->priv->stock_id == NULL && button->priv->icon_name == NULL) { need_label = TRUE; need_icon = FALSE; style = GTK_TOOLBAR_TEXT; } if (style == GTK_TOOLBAR_TEXT && button->priv->label_widget == NULL && button->priv->stock_id == NULL && button->priv->label_text == NULL) { need_label = FALSE; need_icon = TRUE; style = GTK_TOOLBAR_ICONS; } if (need_label) { if (button->priv->label_widget) { label = button->priv->label_widget; } else { GtkStockItem stock_item; gboolean elide; gchar *label_text; if (button->priv->label_text) { label_text = button->priv->label_text; elide = button->priv->use_underline; } else if (button->priv->stock_id && gtk_stock_lookup (button->priv->stock_id, &stock_item)) { label_text = stock_item.label; elide = TRUE; } else { label_text = ""; elide = FALSE; } if (elide) label_text = _gtk_toolbar_elide_underscores (label_text); else label_text = g_strdup (label_text); label = gtk_label_new (label_text); g_free (label_text); gtk_widget_show (label); } gtk_label_set_ellipsize (GTK_LABEL (label), gtk_tool_item_get_ellipsize_mode (GTK_TOOL_ITEM (button))); text_orientation = gtk_tool_item_get_text_orientation (GTK_TOOL_ITEM (button)); if (text_orientation == GTK_ORIENTATION_HORIZONTAL) { gtk_label_set_angle (GTK_LABEL (label), 0); gtk_misc_set_alignment (GTK_MISC (label), gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button)), 0.5); } else { gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_NONE); if (gtk_widget_get_direction (GTK_WIDGET (tool_item)) == GTK_TEXT_DIR_RTL) gtk_label_set_angle (GTK_LABEL (label), -90); else gtk_label_set_angle (GTK_LABEL (label), 90); gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1 - gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button))); } } icon_size = gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (button)); if (need_icon) { if (button->priv->icon_widget) { icon = button->priv->icon_widget; if (GTK_IS_IMAGE (icon)) { g_object_set (button->priv->icon_widget, "icon-size", icon_size, NULL); } } else if (button->priv->stock_id && gtk_icon_factory_lookup_default (button->priv->stock_id)) { icon = gtk_image_new_from_stock (button->priv->stock_id, icon_size); gtk_widget_show (icon); } else if (button->priv->icon_name) { icon = gtk_image_new_from_icon_name (button->priv->icon_name, icon_size); gtk_widget_show (icon); } if (icon && text_orientation == GTK_ORIENTATION_HORIZONTAL) gtk_misc_set_alignment (GTK_MISC (icon), 1.0 - gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button)), 0.5); else if (icon) gtk_misc_set_alignment (GTK_MISC (icon), 0.5, gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button))); if (icon) { size_group = gtk_tool_item_get_text_size_group (GTK_TOOL_ITEM (button)); if (size_group != NULL) gtk_size_group_add_widget (size_group, icon); } } switch (style) { case GTK_TOOLBAR_ICONS: if (icon) gtk_container_add (GTK_CONTAINER (button->priv->button), icon); break; case GTK_TOOLBAR_BOTH: if (text_orientation == GTK_ORIENTATION_HORIZONTAL) box = gtk_vbox_new (FALSE, icon_spacing); else box = gtk_hbox_new (FALSE, icon_spacing); if (icon) gtk_box_pack_start (GTK_BOX (box), icon, TRUE, TRUE, 0); gtk_box_pack_end (GTK_BOX (box), label, FALSE, TRUE, 0); gtk_container_add (GTK_CONTAINER (button->priv->button), box); break; case GTK_TOOLBAR_BOTH_HORIZ: if (text_orientation == GTK_ORIENTATION_HORIZONTAL) { box = gtk_hbox_new (FALSE, icon_spacing); if (icon) gtk_box_pack_start (GTK_BOX (box), icon, label? FALSE : TRUE, TRUE, 0); if (label) gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0); } else { box = gtk_vbox_new (FALSE, icon_spacing); if (icon) gtk_box_pack_end (GTK_BOX (box), icon, label ? FALSE : TRUE, TRUE, 0); if (label) gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); } gtk_container_add (GTK_CONTAINER (button->priv->button), box); break; case GTK_TOOLBAR_TEXT: gtk_container_add (GTK_CONTAINER (button->priv->button), label); break; } if (box) gtk_widget_show (box); gtk_button_set_relief (GTK_BUTTON (button->priv->button), gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (button))); gtk_tool_item_rebuild_menu (tool_item); gtk_widget_queue_resize (GTK_WIDGET (button)); }