[evince] shell: Use a GtkHeaderBar instead of a GtkToolbar and window decorations



commit c9127524e1409d582f038439e9143695d1fadc0d
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sat May 10 11:03:10 2014 +0200

    shell: Use a GtkHeaderBar instead of a GtkToolbar and window decorations
    
    Based on patch by Yosef Or Boczko.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711078

 libmisc/ev-page-action-widget.c |   23 +++++++++++-
 shell/ev-toolbar.c              |   77 ++++++++++++++++-----------------------
 shell/ev-toolbar.h              |    4 +-
 shell/ev-window.c               |    7 +---
 4 files changed, 56 insertions(+), 55 deletions(-)
---
diff --git a/libmisc/ev-page-action-widget.c b/libmisc/ev-page-action-widget.c
index 6b88635..5eb5039 100644
--- a/libmisc/ev-page-action-widget.c
+++ b/libmisc/ev-page-action-widget.c
@@ -319,11 +319,30 @@ ev_page_action_widget_finalize (GObject *object)
 }
 
 static void
-ev_page_action_widget_class_init (EvPageActionWidgetClass *class)
+ev_page_action_widget_get_preferred_width (GtkWidget *widget,
+                                           gint      *minimum_width,
+                                           gint      *natural_width)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (class);
+        GtkWidget *child;
+
+        *minimum_width = *natural_width = 0;
+
+        child = gtk_bin_get_child (GTK_BIN (widget));
+        if (!child || !gtk_widget_get_visible (child))
+                return;
+
+        gtk_widget_get_preferred_width (child, minimum_width, natural_width);
+        *natural_width = *minimum_width;
+}
+
+static void
+ev_page_action_widget_class_init (EvPageActionWidgetClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        object_class->finalize = ev_page_action_widget_finalize;
+        widget_class->get_preferred_width = ev_page_action_widget_get_preferred_width;
 
        widget_signals[WIDGET_ACTIVATE_LINK] =
                g_signal_new ("activate_link",
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
index f9f87e6..48b4280 100644
--- a/shell/ev-toolbar.c
+++ b/shell/ev-toolbar.c
@@ -44,7 +44,7 @@ struct _EvToolbarPrivate {
         GtkWidget *action_menu_button;
 };
 
-G_DEFINE_TYPE (EvToolbar, ev_toolbar, GTK_TYPE_TOOLBAR)
+G_DEFINE_TYPE (EvToolbar, ev_toolbar, GTK_TYPE_HEADER_BAR)
 
 static void
 ev_toolbar_set_property (GObject      *object,
@@ -124,7 +124,7 @@ ev_toolbar_create_button_group (EvToolbar *ev_toolbar)
         GtkStyleContext *style_context;
         GtkWidget *box;
 
-        box = gtk_box_new (gtk_orientable_get_orientation (GTK_ORIENTABLE (ev_toolbar)), 0);
+        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
         style_context = gtk_widget_get_style_context (box);
         gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_RAISED);
@@ -150,11 +150,6 @@ ev_toolbar_constructed (GObject *object)
 
         rtl = gtk_widget_get_direction (GTK_WIDGET (ev_toolbar)) == GTK_TEXT_DIR_RTL;
 
-        /* Set the MENUBAR style class so it's possible to drag the app
-         * using the toolbar. */
-        gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (ev_toolbar)),
-                                     GTK_STYLE_CLASS_MENUBAR);
-
         action_group = ev_window_get_main_action_group (ev_toolbar->priv->window);
         ui_manager = ev_window_get_ui_manager (ev_toolbar->priv->window);
 
@@ -173,33 +168,33 @@ ev_toolbar_constructed (GObject *object)
 
         tool_item = GTK_WIDGET (gtk_tool_item_new ());
         if (rtl)
-                gtk_widget_set_margin_left (tool_item, 12);
+                gtk_widget_set_margin_left (tool_item, 6);
         else
-                gtk_widget_set_margin_right (tool_item, 12);
+                gtk_widget_set_margin_right (tool_item, 6);
         gtk_container_add (GTK_CONTAINER (tool_item), hbox);
         gtk_widget_show (hbox);
 
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+        gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 
         /* Page selector */
         action = gtk_action_group_get_action (action_group, "PageSelector");
         tool_item = gtk_action_create_tool_item (action);
         if (rtl)
-                gtk_widget_set_margin_left (tool_item, 12);
+                gtk_widget_set_margin_left (tool_item, 6);
         else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+                gtk_widget_set_margin_right (tool_item, 6);
+        gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 
         /* History */
         action = gtk_action_group_get_action (action_group, "History");
         tool_item = gtk_action_create_tool_item (action);
         if (rtl)
-                gtk_widget_set_margin_left (tool_item, 12);
+                gtk_widget_set_margin_left (tool_item, 6);
         else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+                gtk_widget_set_margin_right (tool_item, 6);
+        gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 
         /* Find */
@@ -209,26 +204,23 @@ ev_toolbar_constructed (GObject *object)
         gtk_container_add (GTK_CONTAINER (tool_item), button);
         gtk_widget_show (button);
         if (rtl)
-                gtk_widget_set_margin_left (tool_item, 12);
+                gtk_widget_set_margin_left (tool_item, 6);
         else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+                gtk_widget_set_margin_right (tool_item, 6);
+        gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 
-        /* Separator */
+        /* Action Menu */
+        menu = gtk_ui_manager_get_widget (ui_manager, "/ActionMenu");
+        button = ev_toolbar_create_menu_button (ev_toolbar, "emblem-system-symbolic",
+                                                menu, GTK_ALIGN_END);
+        gtk_widget_set_tooltip_text (button, _("File options"));
+        ev_toolbar->priv->action_menu_button = button;
         tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
-        gtk_widget_show (tool_item);
+        gtk_container_add (GTK_CONTAINER (tool_item), button);
+        gtk_widget_show (button);
 
-        /* Zoom selector */
-        action = gtk_action_group_get_action (action_group, "ViewZoom");
-        tool_item = gtk_action_create_tool_item (action);
-        if (rtl)
-                gtk_widget_set_margin_left (tool_item, 12);
-        else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+        gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 
         /* View Menu */
@@ -240,25 +232,18 @@ ev_toolbar_constructed (GObject *object)
         tool_item = GTK_WIDGET (gtk_tool_item_new ());
         gtk_container_add (GTK_CONTAINER (tool_item), button);
         gtk_widget_show (button);
+
+        gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), tool_item);
+        gtk_widget_show (tool_item);
+
+        /* Zoom selector */
+        action = gtk_action_group_get_action (action_group, "ViewZoom");
+        tool_item = gtk_action_create_tool_item (action);
         if (rtl)
                 gtk_widget_set_margin_left (tool_item, 6);
         else
                 gtk_widget_set_margin_right (tool_item, 6);
-
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
-        gtk_widget_show (tool_item);
-
-        /* Action Menu */
-        menu = gtk_ui_manager_get_widget (ui_manager, "/ActionMenu");
-        button = ev_toolbar_create_menu_button (ev_toolbar, "emblem-system-symbolic",
-                                                menu, GTK_ALIGN_END);
-        gtk_widget_set_tooltip_text (button, _("File options"));
-        ev_toolbar->priv->action_menu_button = button;
-        tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        gtk_container_add (GTK_CONTAINER (tool_item), button);
-        gtk_widget_show (button);
-
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+        gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 }
 
diff --git a/shell/ev-toolbar.h b/shell/ev-toolbar.h
index 0c54932..7b79725 100644
--- a/shell/ev-toolbar.h
+++ b/shell/ev-toolbar.h
@@ -38,13 +38,13 @@ typedef struct _EvToolbarClass   EvToolbarClass;
 typedef struct _EvToolbarPrivate EvToolbarPrivate;
 
 struct _EvToolbar {
-        GtkToolbar base_instance;
+        GtkHeaderBar base_instance;
 
         EvToolbarPrivate *priv;
 };
 
 struct _EvToolbarClass {
-        GtkToolbarClass base_class;
+        GtkHeaderBarClass base_class;
 };
 
 GType      ev_toolbar_get_type           (void);
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 174284a..9d74bdb 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -7357,11 +7357,8 @@ ev_window_init (EvWindow *ev_window)
 
        ev_window->priv->toolbar = ev_toolbar_new (ev_window);
        gtk_widget_set_no_show_all (ev_window->priv->toolbar, TRUE);
-       gtk_widget_set_halign (ev_window->priv->toolbar, GTK_ALIGN_FILL);
-       gtk_widget_set_valign (ev_window->priv->toolbar, GTK_ALIGN_START);
-       gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
-                           ev_window->priv->toolbar,
-                           FALSE, TRUE, 0);
+       gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (ev_window->priv->toolbar), TRUE);
+       gtk_window_set_titlebar (GTK_WINDOW (ev_window), ev_window->priv->toolbar);
        gtk_widget_show (ev_window->priv->toolbar);
 
        /* Find Bar */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]