diff options
-rw-r--r-- | font-viewer/gd-main-toolbar.c | 599 | ||||
-rw-r--r-- | font-viewer/gd-main-toolbar.h | 48 |
2 files changed, 405 insertions, 242 deletions
diff --git a/font-viewer/gd-main-toolbar.c b/font-viewer/gd-main-toolbar.c index 4a0b4434..9ec8fc0c 100644 --- a/font-viewer/gd-main-toolbar.c +++ b/font-viewer/gd-main-toolbar.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Red Hat, Inc. + * Copyright (c) 2011, 2012 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -26,6 +26,12 @@ G_DEFINE_TYPE (GdMainToolbar, gd_main_toolbar, GTK_TYPE_TOOLBAR) +typedef enum { + CHILD_NORMAL = 0, + CHILD_TOGGLE = 1, + CHILD_MENU = 2, +} ChildType; + struct _GdMainToolbarPrivate { GtkSizeGroup *size_group; GtkSizeGroup *vertical_size_group; @@ -35,25 +41,27 @@ struct _GdMainToolbarPrivate { GtkToolItem *right_group; GtkWidget *left_grid; - GtkWidget *back; + GtkWidget *center_grid; + GtkWidget *labels_grid; GtkWidget *title_label; GtkWidget *detail_label; + GtkWidget *modes_box; + + GtkWidget *center_menu; + GtkWidget *center_menu_child; + GtkWidget *right_grid; - GdMainToolbarMode mode; + gboolean show_modes; }; enum { - SELECTION_MODE_REQUEST = 1, - GO_BACK_REQUEST, - CLEAR_REQUEST, - NUM_SIGNALS + PROP_0, + PROP_SHOW_MODES, }; -static guint signals[NUM_SIGNALS] = { 0, }; - static void gd_main_toolbar_dispose (GObject *obj) { @@ -65,30 +73,102 @@ gd_main_toolbar_dispose (GObject *obj) G_OBJECT_CLASS (gd_main_toolbar_parent_class)->dispose (obj); } -static gint -get_icon_margin (void) +static GtkWidget * +get_empty_button (ChildType type) +{ + GtkWidget *button; + + switch (type) + { + case CHILD_MENU: + button = gtk_menu_button_new (); + break; + case CHILD_TOGGLE: + button = gtk_toggle_button_new (); + break; + case CHILD_NORMAL: + default: + button = gtk_button_new (); + break; + } + + return button; +} + +static GtkWidget * +get_symbolic_button (const gchar *icon_name, + ChildType type) +{ + GtkWidget *button, *w; + + switch (type) + { + case CHILD_MENU: + button = gtk_menu_button_new (); + gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button))); + break; + case CHILD_TOGGLE: + button = gtk_toggle_button_new (); + break; + case CHILD_NORMAL: + default: + button = gtk_button_new (); + break; + } + + gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised"); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button"); + + w = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); + gtk_widget_show (w); + gtk_container_add (GTK_CONTAINER (button), w); + + return button; +} + +static GtkWidget * +get_text_button (const gchar *label, + ChildType type) { - gint toolbar_size, menu_size; + GtkWidget *button, *w; + + switch (type) + { + case CHILD_MENU: + button = gtk_menu_button_new (); + gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button))); - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &menu_size, NULL); - gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &toolbar_size, NULL); - return (gint) floor ((toolbar_size - menu_size) / 2.0); + w = gtk_label_new (label); + gtk_widget_show (w); + gtk_container_add (GTK_CONTAINER (button), w); + break; + case CHILD_TOGGLE: + button = gtk_toggle_button_new_with_label (label); + break; + case CHILD_NORMAL: + default: + button = gtk_button_new_with_label (label); + break; + } + + gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised"); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "text-button"); + + return button; } static GtkSizeGroup * -get_vertical_size_group (void) +get_vertical_size_group (GdMainToolbar *self) { GtkSizeGroup *retval; - GtkWidget *w, *dummy; - gint icon_margin; + GtkWidget *dummy; + GtkToolItem *container; - icon_margin = get_icon_margin (); - - dummy = gtk_toggle_button_new (); - w = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); - g_object_set (w, "margin", icon_margin, NULL); - gtk_container_add (GTK_CONTAINER (dummy), w); - gtk_widget_show_all (dummy); + dummy = get_text_button ("Dummy", CHILD_NORMAL); + container = gtk_tool_item_new (); + gtk_widget_set_no_show_all (GTK_WIDGET (container), TRUE); + gtk_container_add (GTK_CONTAINER (container), dummy); + gtk_toolbar_insert (GTK_TOOLBAR (self), container, -1); retval = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL); gtk_size_group_add_widget (retval, dummy); @@ -96,40 +176,79 @@ get_vertical_size_group (void) return retval; } -static GtkWidget * -get_symbolic_button (const gchar *icon_name) +gboolean +gd_main_toolbar_get_show_modes (GdMainToolbar *self) { - GtkWidget *button, *w; + return self->priv->show_modes; +} - button = gtk_button_new (); - gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised"); +void +gd_main_toolbar_set_show_modes (GdMainToolbar *self, + gboolean show_modes) +{ + if (self->priv->show_modes == show_modes) + return; - w = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); - g_object_set (w, "margin", get_icon_margin (), NULL); - gtk_widget_show (w); - gtk_container_add (GTK_CONTAINER (button), w); + self->priv->show_modes = show_modes; + if (self->priv->show_modes) + { + gtk_widget_set_no_show_all (self->priv->labels_grid, TRUE); + gtk_widget_hide (self->priv->labels_grid); - return button; + gtk_widget_set_valign (self->priv->center_grid, GTK_ALIGN_FILL); + gtk_widget_set_no_show_all (self->priv->modes_box, FALSE); + gtk_widget_show_all (self->priv->modes_box); + } + else + { + gtk_widget_set_no_show_all (self->priv->modes_box, TRUE); + gtk_widget_hide (self->priv->modes_box); + + gtk_widget_set_valign (self->priv->center_grid, GTK_ALIGN_CENTER); + gtk_widget_set_no_show_all (self->priv->labels_grid, FALSE); + gtk_widget_show_all (self->priv->labels_grid); + } + + g_object_notify (G_OBJECT (self), "show-modes"); } -static GtkWidget * -get_text_button (const gchar *label) +static void +gd_main_toolbar_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - GtkWidget *w; - w = gtk_button_new_with_label (label); - gtk_widget_set_vexpand (w, TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (w), "raised"); + GdMainToolbar *self = GD_MAIN_TOOLBAR (object); - return w; + switch (prop_id) + { + case PROP_SHOW_MODES: + gd_main_toolbar_set_show_modes (GD_MAIN_TOOLBAR (self), g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -on_back_button_clicked (GtkButton *b, - gpointer user_data) +gd_main_toolbar_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - GdMainToolbar *self = user_data; - g_signal_emit (self, signals[GO_BACK_REQUEST], 0); + GdMainToolbar *self = GD_MAIN_TOOLBAR (object); + + switch (prop_id) + { + case PROP_SHOW_MODES: + g_value_set_boolean (value, self->priv->show_modes); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void @@ -141,7 +260,7 @@ gd_main_toolbar_constructed (GObject *obj) G_OBJECT_CLASS (gd_main_toolbar_parent_class)->constructed (obj); - self->priv->vertical_size_group = get_vertical_size_group (); + self->priv->vertical_size_group = get_vertical_size_group (self); /* left section */ self->priv->left_group = gtk_tool_item_new (); @@ -154,37 +273,41 @@ gd_main_toolbar_constructed (GObject *obj) self->priv->left_grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (self->priv->left_grid), 12); gtk_container_add (GTK_CONTAINER (self->priv->left_group), self->priv->left_grid); - - self->priv->back = get_symbolic_button ("go-previous-symbolic"); - gtk_widget_set_no_show_all (self->priv->back, TRUE); - gtk_container_add (GTK_CONTAINER (self->priv->left_grid), self->priv->back); - - g_signal_connect (self->priv->back, "clicked", - G_CALLBACK (on_back_button_clicked), self); + gtk_widget_set_halign (self->priv->left_grid, GTK_ALIGN_START); /* center section */ self->priv->center_group = gtk_tool_item_new (); gtk_tool_item_set_expand (self->priv->center_group, TRUE); gtk_toolbar_insert (tb, self->priv->center_group, -1); + self->priv->center_grid = gtk_grid_new (); + gtk_widget_set_halign (self->priv->center_grid, GTK_ALIGN_CENTER); + gtk_widget_set_valign (self->priv->center_grid, GTK_ALIGN_CENTER); + gtk_container_add (GTK_CONTAINER (self->priv->center_group), self->priv->center_grid); gtk_size_group_add_widget (self->priv->vertical_size_group, GTK_WIDGET (self->priv->center_group)); /* centered label group */ - grid = gtk_grid_new (); - gtk_widget_set_halign (grid, GTK_ALIGN_CENTER); - gtk_widget_set_valign (grid, GTK_ALIGN_CENTER); - gtk_container_add (GTK_CONTAINER (self->priv->center_group), grid); + self->priv->labels_grid = grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_container_add (GTK_CONTAINER (self->priv->center_grid), grid); self->priv->title_label = gtk_label_new (NULL); gtk_label_set_ellipsize (GTK_LABEL (self->priv->title_label), PANGO_ELLIPSIZE_END); gtk_container_add (GTK_CONTAINER (grid), self->priv->title_label); self->priv->detail_label = gtk_label_new (NULL); + gtk_label_set_ellipsize (GTK_LABEL (self->priv->detail_label), PANGO_ELLIPSIZE_END); gtk_widget_set_no_show_all (self->priv->detail_label, TRUE); - gtk_widget_set_margin_left (self->priv->detail_label, 12); gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->detail_label), "dim-label"); gtk_container_add (GTK_CONTAINER (grid), self->priv->detail_label); + /* centered mode group */ + self->priv->modes_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_set_homogeneous (GTK_BOX (self->priv->modes_box), TRUE); + gtk_widget_set_no_show_all (self->priv->modes_box, TRUE); + gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->modes_box), "linked"); + gtk_container_add (GTK_CONTAINER (self->priv->center_grid), self->priv->modes_box); + /* right section */ self->priv->right_group = gtk_tool_item_new (); gtk_widget_set_margin_left (GTK_WIDGET (self->priv->right_group), 12); @@ -195,6 +318,7 @@ gd_main_toolbar_constructed (GObject *obj) self->priv->right_grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (self->priv->right_grid), 12); gtk_container_add (GTK_CONTAINER (self->priv->right_group), self->priv->right_grid); + gtk_widget_set_halign (self->priv->right_grid, GTK_ALIGN_END); self->priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (self->priv->size_group, GTK_WIDGET (self->priv->left_group)); @@ -205,7 +329,6 @@ static void gd_main_toolbar_init (GdMainToolbar *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_MAIN_TOOLBAR, GdMainToolbarPrivate); - self->priv->mode = GD_MAIN_TOOLBAR_MODE_INVALID; } static void @@ -215,162 +338,35 @@ gd_main_toolbar_class_init (GdMainToolbarClass *klass) oclass = G_OBJECT_CLASS (klass); oclass->constructed = gd_main_toolbar_constructed; + oclass->set_property = gd_main_toolbar_set_property; + oclass->get_property = gd_main_toolbar_get_property; oclass->dispose = gd_main_toolbar_dispose; - signals[SELECTION_MODE_REQUEST] = - g_signal_new ("selection-mode-request", - GD_TYPE_MAIN_TOOLBAR, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, - 1, G_TYPE_BOOLEAN); - signals[GO_BACK_REQUEST] = - g_signal_new ("go-back-request", - GD_TYPE_MAIN_TOOLBAR, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 0); - signals[CLEAR_REQUEST] = - g_signal_new ("clear-request", - GD_TYPE_MAIN_TOOLBAR, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 0); + g_object_class_install_property (oclass, + PROP_SHOW_MODES, + g_param_spec_boolean ("show-modes", + "Show Modes", + "Show Modes", + FALSE, + G_PARAM_READWRITE)); g_type_class_add_private (klass, sizeof (GdMainToolbarPrivate)); } -static void -on_selection_mode_button_clicked (GtkButton *b, - gpointer user_data) -{ - GdMainToolbar *self = user_data; - g_signal_emit (self, signals[SELECTION_MODE_REQUEST], 0, TRUE); -} - -static void -on_selection_mode_done_button_clicked (GtkButton *b, - gpointer user_data) -{ - GdMainToolbar *self = user_data; - g_signal_emit (self, signals[SELECTION_MODE_REQUEST], 0, FALSE); -} - -static void -gd_main_toolbar_populate_for_selection (GdMainToolbar *self) -{ - GtkWidget *w; - - gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), - "documents-selection-mode"); - gtk_widget_reset_style (GTK_WIDGET (self)); - - /* right section */ - w = get_text_button (_("Done")); - gtk_container_add (GTK_CONTAINER (self->priv->right_grid), w); - - g_signal_connect (w, "clicked", - G_CALLBACK (on_selection_mode_done_button_clicked), self); - - gtk_widget_show_all (GTK_WIDGET (self)); -} - -static void -gd_main_toolbar_populate_for_overview (GdMainToolbar *self) -{ - GtkWidget *button; - - /* right section */ - button = get_symbolic_button ("emblem-default-symbolic"); - gtk_container_add (GTK_CONTAINER (self->priv->right_grid), button); - - g_signal_connect (button, "clicked", - G_CALLBACK (on_selection_mode_button_clicked), self); - - gtk_widget_show_all (GTK_WIDGET (self)); -} - -static void -gd_main_toolbar_populate_for_preview (GdMainToolbar *self) -{ - gtk_widget_show (self->priv->back); - gtk_widget_show_all (GTK_WIDGET (self)); -} - -static void -on_left_grid_clear (GtkWidget *w, - gpointer user_data) -{ - GdMainToolbar *self = user_data; - - if (w != self->priv->back) - gtk_widget_destroy (w); -} - -static void +void gd_main_toolbar_clear (GdMainToolbar *self) { - GtkStyleContext *context; - /* reset labels */ gtk_label_set_text (GTK_LABEL (self->priv->title_label), ""); gtk_label_set_text (GTK_LABEL (self->priv->detail_label), ""); - /* clear all on the left, except the back button */ - gtk_widget_hide (self->priv->back); + /* clear all added buttons */ gtk_container_foreach (GTK_CONTAINER (self->priv->left_grid), - on_left_grid_clear, self); - - /* clear all on the right */ + (GtkCallback) gtk_widget_destroy, self); + gtk_container_foreach (GTK_CONTAINER (self->priv->modes_box), + (GtkCallback) gtk_widget_destroy, self); gtk_container_foreach (GTK_CONTAINER (self->priv->right_grid), (GtkCallback) gtk_widget_destroy, self); - - context = gtk_widget_get_style_context (GTK_WIDGET (self)); - if (gtk_style_context_has_class (context, "documents-selection-mode")) - { - gtk_style_context_remove_class (context, "documents-selection-mode"); - gtk_widget_reset_style (GTK_WIDGET (self)); - } - - g_signal_emit (self, signals[CLEAR_REQUEST], 0); -} - -/** - * gd_main_toolbar_set_mode: - * @mode: - * - */ -void -gd_main_toolbar_set_mode (GdMainToolbar *self, - GdMainToolbarMode mode) -{ - if (mode == self->priv->mode) - return; - - gd_main_toolbar_clear (self); - self->priv->mode = mode; - - switch (mode) - { - case GD_MAIN_TOOLBAR_MODE_OVERVIEW: - gd_main_toolbar_populate_for_overview (self); - break; - case GD_MAIN_TOOLBAR_MODE_SELECTION: - gd_main_toolbar_populate_for_selection (self); - break; - case GD_MAIN_TOOLBAR_MODE_PREVIEW: - gd_main_toolbar_populate_for_preview (self); - break; - default: - g_assert_not_reached (); - break; - } -} - -GdMainToolbarMode -gd_main_toolbar_get_mode (GdMainToolbar *self) -{ - return self->priv->mode; } /** @@ -415,53 +411,204 @@ gd_main_toolbar_set_labels (GdMainToolbar *self, g_free (real_primary); } +GtkWidget * +gd_main_toolbar_new (void) +{ + return g_object_new (GD_TYPE_MAIN_TOOLBAR, NULL); +} + +static GtkWidget * +add_button_internal (GdMainToolbar *self, + const gchar *icon_name, + const gchar *label, + gboolean pack_start, + ChildType type) +{ + GtkWidget *button; + + if (icon_name != NULL) + { + button = get_symbolic_button (icon_name, type); + if (label != NULL) + gtk_widget_set_tooltip_text (button, label); + } + else if (label != NULL) + { + button = get_text_button (label, type); + } + else + { + button = get_empty_button (type); + } + + gd_main_toolbar_add_widget (self, button, pack_start); + + gtk_widget_show_all (button); + + return button; +} + /** - * gd_main_toolbar_set_back_visible: + * gd_main_toolbar_set_labels_menu: * @self: - * @visible: + * @menu: (allow-none): * */ void -gd_main_toolbar_set_back_visible (GdMainToolbar *self, - gboolean visible) +gd_main_toolbar_set_labels_menu (GdMainToolbar *self, + GMenuModel *menu) { - if (visible != gtk_widget_get_visible (self->priv->back)) - gtk_widget_set_visible (self->priv->back, visible); + GtkWidget *button, *grid, *w; + + if (menu == NULL && + ((gtk_widget_get_parent (self->priv->labels_grid) == self->priv->center_grid) || + self->priv->center_menu_child == NULL)) + return; + + if (menu != NULL) + { + g_object_ref (self->priv->labels_grid); + gtk_container_remove (GTK_CONTAINER (self->priv->center_grid), + self->priv->labels_grid); + + self->priv->center_menu_child = grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + gtk_container_add (GTK_CONTAINER (grid), self->priv->labels_grid); + g_object_unref (self->priv->labels_grid); + + w = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + gtk_container_add (GTK_CONTAINER (grid), w); + + self->priv->center_menu = button = gtk_menu_button_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->center_menu), + "selection-menu"); + gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button))); + gtk_widget_set_halign (button, GTK_ALIGN_CENTER); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), menu); + gtk_container_add (GTK_CONTAINER (self->priv->center_menu), grid); + + gtk_container_add (GTK_CONTAINER (self->priv->center_grid), button); + } + else + { + g_object_ref (self->priv->labels_grid); + gtk_container_remove (GTK_CONTAINER (self->priv->center_menu_child), + self->priv->labels_grid); + gtk_widget_destroy (self->priv->center_menu); + self->priv->center_menu = NULL; + self->priv->center_menu_child = NULL; + + gtk_container_add (GTK_CONTAINER (self->priv->center_grid), + self->priv->labels_grid); + g_object_unref (self->priv->labels_grid); + } + + gtk_widget_show_all (self->priv->center_grid); } +/** + * gd_main_toolbar_add_mode: + * @self: + * @label: + * + * Returns: (transfer none): + */ GtkWidget * -gd_main_toolbar_new (void) +gd_main_toolbar_add_mode (GdMainToolbar *self, + const gchar *label) { - return g_object_new (GD_TYPE_MAIN_TOOLBAR, NULL); + GtkWidget *button; + GList *group; + + button = gtk_radio_button_new_with_label (NULL, label); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE); + gtk_widget_set_size_request (button, 100, -1); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised"); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "text-button"); + + group = gtk_container_get_children (GTK_CONTAINER (self->priv->modes_box)); + if (group != NULL) + { + gtk_radio_button_join_group (GTK_RADIO_BUTTON (button), GTK_RADIO_BUTTON (group->data)); + g_list_free (group); + } + + gtk_container_add (GTK_CONTAINER (self->priv->modes_box), button); + gtk_widget_show (button); + + return button; } +/** + * gd_main_toolbar_add_button: + * @self: + * @icon_name: (allow-none): + * @label: (allow-none): + * @pack_start: + * + * Returns: (transfer none): + */ GtkWidget * gd_main_toolbar_add_button (GdMainToolbar *self, const gchar *icon_name, const gchar *label, gboolean pack_start) { - GtkWidget *button; + return add_button_internal (self, icon_name, label, pack_start, CHILD_NORMAL); +} - if (icon_name != NULL) - { - button = get_symbolic_button (icon_name); - if (label != NULL) - gtk_widget_set_tooltip_text (button, label); - } - else if (label != NULL) - { - button = get_text_button (label); - } +/** + * gd_main_toolbar_add_menu: + * @self: + * @icon_name: (allow-none): + * @label: (allow-none): + * @pack_start: + * + * Returns: (transfer none): + */ +GtkWidget * +gd_main_toolbar_add_menu (GdMainToolbar *self, + const gchar *icon_name, + const gchar *label, + gboolean pack_start) +{ + return add_button_internal (self, icon_name, label, pack_start, CHILD_MENU); +} + +/** + * gd_main_toolbar_add_toggle: + * @self: + * @icon_name: (allow-none): + * @label: (allow-none): + * @pack_start: + * + * Returns: (transfer none): + */ +GtkWidget * +gd_main_toolbar_add_toggle (GdMainToolbar *self, + const gchar *icon_name, + const gchar *label, + gboolean pack_start) +{ + return add_button_internal (self, icon_name, label, pack_start, CHILD_TOGGLE); +} +/** + * gd_main_toolbar_add_widget: + * @self: + * @widget: + * @pack_start: + * + */ +void +gd_main_toolbar_add_widget (GdMainToolbar *self, + GtkWidget *widget, + gboolean pack_start) +{ if (pack_start) - gtk_container_add (GTK_CONTAINER (self->priv->left_grid), button); + gtk_container_add (GTK_CONTAINER (self->priv->left_grid), widget); else - gtk_container_add (GTK_CONTAINER (self->priv->right_grid), button); - - gtk_widget_show_all (button); - - return button; + gtk_container_add (GTK_CONTAINER (self->priv->right_grid), widget); } diff --git a/font-viewer/gd-main-toolbar.h b/font-viewer/gd-main-toolbar.h index 56534115..4fa7b532 100644 --- a/font-viewer/gd-main-toolbar.h +++ b/font-viewer/gd-main-toolbar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Red Hat, Inc. + * Copyright (c) 2011, 2012 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -54,13 +54,6 @@ typedef struct _GdMainToolbar GdMainToolbar; typedef struct _GdMainToolbarClass GdMainToolbarClass; typedef struct _GdMainToolbarPrivate GdMainToolbarPrivate; -typedef enum { - GD_MAIN_TOOLBAR_MODE_INVALID, - GD_MAIN_TOOLBAR_MODE_OVERVIEW, - GD_MAIN_TOOLBAR_MODE_SELECTION, - GD_MAIN_TOOLBAR_MODE_PREVIEW -} GdMainToolbarMode; - struct _GdMainToolbar { GtkToolbar parent; @@ -77,19 +70,42 @@ GType gd_main_toolbar_get_type (void) G_GNUC_CONST; GtkWidget *gd_main_toolbar_new (void); -void gd_main_toolbar_set_mode (GdMainToolbar *self, - GdMainToolbarMode mode); -GdMainToolbarMode gd_main_toolbar_get_mode (GdMainToolbar *self); -void gd_main_toolbar_set_labels (GdMainToolbar *self, - const gchar *primary, - const gchar *detail); -void gd_main_toolbar_set_back_visible (GdMainToolbar *self, - gboolean visible); +void gd_main_toolbar_set_labels (GdMainToolbar *self, + const gchar *primary, + const gchar *detail); + +void gd_main_toolbar_set_labels_menu (GdMainToolbar *self, + GMenuModel *menu); + +GtkWidget * gd_main_toolbar_add_mode (GdMainToolbar *self, + const gchar *label); + +void gd_main_toolbar_clear (GdMainToolbar *self); + GtkWidget * gd_main_toolbar_add_button (GdMainToolbar *self, const gchar *icon_name, const gchar *label, gboolean pack_start); +GtkWidget * gd_main_toolbar_add_toggle (GdMainToolbar *self, + const gchar *icon_name, + const gchar *label, + gboolean pack_start); + +GtkWidget * gd_main_toolbar_add_menu (GdMainToolbar *self, + const gchar *icon_name, + const gchar *label, + gboolean pack_start); + +void gd_main_toolbar_add_widget (GdMainToolbar *self, + GtkWidget *widget, + gboolean pack_start); + +gboolean gd_main_toolbar_get_show_modes (GdMainToolbar *self); + +void gd_main_toolbar_set_show_modes (GdMainToolbar *self, + gboolean show_modes); + G_END_DECLS #endif /* __GD_MAIN_TOOLBAR_H__ */ |