[evince/wip/recent-view: 12/16] shell: Make a class for EvToolbar to abstract for other toolbars



commit 0451b5a2686d63da202ac638e1690a0ccd153a72
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Tue May 6 23:38:42 2014 -0700

    shell: Make a class for EvToolbar to abstract for other toolbars

 shell/Makefile.am       |    2 +
 shell/ev-toolbar-main.c |  272 +++++++++++++++++++++++++++++++++++++++++++++++
 shell/ev-toolbar-main.h |   59 ++++++++++
 shell/ev-toolbar.c      |  224 ++-------------------------------------
 shell/ev-toolbar.h      |   24 +++--
 shell/ev-window.c       |    8 +-
 6 files changed, 361 insertions(+), 228 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 2a3e3b3..a038281 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -51,6 +51,8 @@ evince_SOURCES=                               \
        ev-recent-view.h                \
        ev-toolbar.c                    \
        ev-toolbar.h                    \
+       ev-toolbar-main.c               \
+       ev-toolbar-main.h               \
        ev-utils.c                      \
        ev-utils.h                      \
        ev-window.c                     \
diff --git a/shell/ev-toolbar-main.c b/shell/ev-toolbar-main.c
new file mode 100644
index 0000000..7e95729
--- /dev/null
+++ b/shell/ev-toolbar-main.c
@@ -0,0 +1,272 @@
+/* ev-toolbar.h
+ *  this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2014 Germán Poo-Caamaño <gpoo gnome org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n.h>
+
+#include "ev-toolbar-main.h"
+
+#include "ev-stock-icons.h"
+#include "ev-zoom-action.h"
+#include "ev-history-action.h"
+#include <math.h>
+
+enum
+{
+        PROP_0,
+        PROP_WINDOW
+};
+
+struct _EvToolbarMainPrivate {
+        EvWindow  *window;
+
+        GtkWidget *view_menu_button;
+        GtkWidget *action_menu_button;
+};
+
+G_DEFINE_TYPE (EvToolbarMain, ev_toolbar_main, EV_TYPE_TOOLBAR)
+
+static void
+ev_toolbar_main_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+        EvToolbarMain *ev_toolbar = EV_TOOLBAR_MAIN (object);
+
+        switch (prop_id) {
+        case PROP_WINDOW:
+                ev_toolbar->priv->window = g_value_get_object (value);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        }
+}
+
+static void
+ev_toolbar_main_constructed (GObject *object)
+{
+        EvToolbarMain  *ev_toolbar = EV_TOOLBAR_MAIN (object);
+        GtkUIManager   *ui_manager;
+        GtkActionGroup *action_group;
+        GtkWidget      *tool_item;
+        GtkWidget      *hbox;
+        GtkAction      *action;
+        GtkWidget      *button;
+        GtkWidget      *menu;
+        gboolean        rtl;
+
+        G_OBJECT_CLASS (ev_toolbar_main_parent_class)->constructed (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);
+
+        /* Navigation */
+        hbox = ev_toolbar_create_button_group (EV_TOOLBAR (ev_toolbar));
+
+        action = gtk_action_group_get_action (action_group, "GoPreviousPage");
+        button = ev_toolbar_create_button (EV_TOOLBAR (ev_toolbar), action);
+        gtk_container_add (GTK_CONTAINER (hbox), button);
+        gtk_widget_show (button);
+
+        action = gtk_action_group_get_action (action_group, "GoNextPage");
+        button = ev_toolbar_create_button (EV_TOOLBAR (ev_toolbar), action);
+        gtk_container_add (GTK_CONTAINER (hbox), button);
+        gtk_widget_show (button);
+
+        tool_item = GTK_WIDGET (gtk_tool_item_new ());
+        if (rtl)
+                gtk_widget_set_margin_left (tool_item, 12);
+        else
+                gtk_widget_set_margin_right (tool_item, 12);
+        gtk_container_add (GTK_CONTAINER (tool_item), hbox);
+        gtk_widget_show (hbox);
+
+        gtk_container_add (GTK_CONTAINER (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);
+        else
+                gtk_widget_set_margin_right (tool_item, 12);
+        gtk_container_add (GTK_CONTAINER (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);
+        else
+                gtk_widget_set_margin_right (tool_item, 12);
+        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+        gtk_widget_show (tool_item);
+
+        /* Find */
+        action = gtk_action_group_get_action (action_group, "EditFind");
+        button = ev_toolbar_create_toggle_button (EV_TOOLBAR (ev_toolbar), action);
+        tool_item = GTK_WIDGET (gtk_tool_item_new ());
+        gtk_container_add (GTK_CONTAINER (tool_item), button);
+        gtk_widget_show (button);
+        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_widget_show (tool_item);
+
+        /* Separator */
+        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);
+
+        /* 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_widget_show (tool_item);
+
+        /* View Menu */
+        menu = gtk_ui_manager_get_widget (ui_manager, "/ViewMenuPopup");
+        button = ev_toolbar_create_menu_button (EV_TOOLBAR (ev_toolbar), "document-properties-symbolic",
+                                                menu, GTK_ALIGN_END);
+        gtk_widget_set_tooltip_text (button, _("View options"));
+        ev_toolbar->priv->view_menu_button = button;
+        tool_item = GTK_WIDGET (gtk_tool_item_new ());
+        gtk_container_add (GTK_CONTAINER (tool_item), button);
+        gtk_widget_show (button);
+        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 (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_widget_show (tool_item);
+}
+
+static void
+ev_toolbar_main_class_init (EvToolbarMainClass *klass)
+{
+        GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+        g_object_class->set_property = ev_toolbar_main_set_property;
+        g_object_class->constructed = ev_toolbar_main_constructed;
+
+        g_object_class_install_property (g_object_class,
+                                         PROP_WINDOW,
+                                         g_param_spec_object ("window",
+                                                              "Window",
+                                                              "The evince window",
+                                                              EV_TYPE_WINDOW,
+                                                              G_PARAM_WRITABLE |
+                                                              G_PARAM_CONSTRUCT_ONLY |
+                                                              G_PARAM_STATIC_STRINGS));
+
+        g_type_class_add_private (g_object_class, sizeof (EvToolbarMainPrivate));
+}
+
+static void
+ev_toolbar_main_init (EvToolbarMain *ev_toolbar_main)
+{
+        ev_toolbar_main->priv = G_TYPE_INSTANCE_GET_PRIVATE (ev_toolbar_main, EV_TYPE_TOOLBAR_MAIN, 
EvToolbarMainPrivate);
+}
+
+GtkWidget *
+ev_toolbar_main_new (EvWindow *window)
+{
+        g_return_val_if_fail (EV_IS_WINDOW (window), NULL);
+
+        return GTK_WIDGET (g_object_new (EV_TYPE_TOOLBAR_MAIN,
+                                         "window", window,
+                                         NULL));
+}
+
+gboolean
+ev_toolbar_main_has_visible_popups (EvToolbarMain *ev_toolbar)
+{
+        GtkAction        *action;
+        GtkActionGroup   *action_group;
+        GtkMenu          *popup_menu;
+        EvToolbarMainPrivate *priv;
+
+        g_return_val_if_fail (EV_IS_TOOLBAR_MAIN (ev_toolbar), FALSE);
+
+        priv = ev_toolbar->priv;
+
+        popup_menu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (priv->view_menu_button));
+        if (gtk_widget_get_visible (GTK_WIDGET (popup_menu)))
+                return TRUE;
+
+        popup_menu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (priv->action_menu_button));
+        if (gtk_widget_get_visible (GTK_WIDGET (popup_menu)))
+                return TRUE;
+
+        action_group = ev_window_get_main_action_group (ev_toolbar->priv->window);
+        action = gtk_action_group_get_action (action_group, "ViewZoom");
+        if (ev_zoom_action_get_popup_shown (EV_ZOOM_ACTION (action)))
+                return TRUE;
+
+        action = gtk_action_group_get_action (action_group, "History");
+        if (ev_history_action_get_popup_shown (EV_HISTORY_ACTION (action)))
+                return TRUE;
+
+        return FALSE;
+}
+
+void
+ev_toolbar_main_action_menu_popup (EvToolbarMain *ev_toolbar)
+{
+        g_return_if_fail (EV_IS_TOOLBAR_MAIN (ev_toolbar));
+
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ev_toolbar->priv->action_menu_button),
+                                      TRUE);
+}
diff --git a/shell/ev-toolbar-main.h b/shell/ev-toolbar-main.h
new file mode 100644
index 0000000..babfdea
--- /dev/null
+++ b/shell/ev-toolbar-main.h
@@ -0,0 +1,59 @@
+/* ev-toolbar.h
+ *  this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2014 Germán Poo-Caamaño <gpoo gnome org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __EV_TOOLBAR_MAIN_H__
+#define __EV_TOOLBAR_MAIN_H__
+
+#include <gtk/gtk.h>
+#include "ev-window.h"
+#include "ev-toolbar.h"
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_TOOLBAR_MAIN              (ev_toolbar_main_get_type())
+#define EV_TOOLBAR_MAIN(object)           (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_TOOLBAR_MAIN, 
EvToolbarMain))
+#define EV_IS_TOOLBAR_MAIN(object)        (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_TOOLBAR_MAIN))
+#define EV_TOOLBAR_MAIN_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_TOOLBAR_MAIN, 
EvToolbarMainClass))
+#define EV_IS_TOOLBAR_MAIN_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_TOOLBAR_MAIN))
+#define EV_TOOLBAR_MAIN_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_TOOLBAR, 
EvToolbarMainClass))
+
+typedef struct _EvToolbarMain        EvToolbarMain;
+typedef struct _EvToolbarMainClass   EvToolbarMainClass;
+typedef struct _EvToolbarMainPrivate EvToolbarMainPrivate;
+
+struct _EvToolbarMain {
+        EvToolbar base_instance;
+
+        EvToolbarMainPrivate *priv;
+};
+
+struct _EvToolbarMainClass {
+        EvToolbarClass base_class;
+};
+
+GType      ev_toolbar_main_get_type           (void);
+GtkWidget *ev_toolbar_main_new                (EvWindow *window);
+gboolean   ev_toolbar_main_has_visible_popups (EvToolbarMain *ev_toolbar);
+void       ev_toolbar_main_action_menu_popup  (EvToolbarMain *ev_toolbar);
+
+G_END_DECLS
+
+#endif /* __EV_TOOLBAR_MAIN_H__ */
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
index f9f87e6..7b3b968 100644
--- a/shell/ev-toolbar.c
+++ b/shell/ev-toolbar.c
@@ -2,6 +2,7 @@
  *  this file is part of evince, a gnome document viewer
  *
  * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2014 Germán Poo-Caamaño <gpoo gnome org>
  *
  * Evince is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
@@ -31,39 +32,9 @@
 #include "ev-history-action.h"
 #include <math.h>
 
-enum
-{
-        PROP_0,
-        PROP_WINDOW
-};
-
-struct _EvToolbarPrivate {
-        EvWindow  *window;
-
-        GtkWidget *view_menu_button;
-        GtkWidget *action_menu_button;
-};
-
 G_DEFINE_TYPE (EvToolbar, ev_toolbar, GTK_TYPE_TOOLBAR)
 
-static void
-ev_toolbar_set_property (GObject      *object,
-                         guint         prop_id,
-                         const GValue *value,
-                         GParamSpec   *pspec)
-{
-        EvToolbar *ev_toolbar = EV_TOOLBAR (object);
-
-        switch (prop_id) {
-        case PROP_WINDOW:
-                ev_toolbar->priv->window = g_value_get_object (value);
-                break;
-        default:
-                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-        }
-}
-
-static void
+void
 ev_toolbar_set_button_action (EvToolbar *ev_toolbar,
                               GtkButton *button,
                               GtkAction *action)
@@ -74,7 +45,7 @@ ev_toolbar_set_button_action (EvToolbar *ev_toolbar,
         gtk_widget_set_tooltip_text (GTK_WIDGET (button), gtk_action_get_tooltip (action));
 }
 
-static GtkWidget *
+GtkWidget *
 ev_toolbar_create_button (EvToolbar *ev_toolbar,
                           GtkAction *action)
 {
@@ -87,7 +58,7 @@ ev_toolbar_create_button (EvToolbar *ev_toolbar,
         return button;
 }
 
-static GtkWidget *
+GtkWidget *
 ev_toolbar_create_toggle_button (EvToolbar *ev_toolbar,
                                  GtkAction *action)
 {
@@ -100,7 +71,7 @@ ev_toolbar_create_toggle_button (EvToolbar *ev_toolbar,
         return button;
 }
 
-static GtkWidget *
+GtkWidget *
 ev_toolbar_create_menu_button (EvToolbar   *ev_toolbar,
                                const gchar *icon_name,
                                GtkWidget   *menu,
@@ -118,7 +89,7 @@ ev_toolbar_create_menu_button (EvToolbar   *ev_toolbar,
         return button;
 }
 
-static GtkWidget *
+GtkWidget *
 ev_toolbar_create_button_group (EvToolbar *ev_toolbar)
 {
         GtkStyleContext *style_context;
@@ -136,130 +107,7 @@ ev_toolbar_create_button_group (EvToolbar *ev_toolbar)
 static void
 ev_toolbar_constructed (GObject *object)
 {
-        EvToolbar      *ev_toolbar = EV_TOOLBAR (object);
-        GtkUIManager   *ui_manager;
-        GtkActionGroup *action_group;
-        GtkWidget      *tool_item;
-        GtkWidget      *hbox;
-        GtkAction      *action;
-        GtkWidget      *button;
-        GtkWidget      *menu;
-        gboolean        rtl;
-
         G_OBJECT_CLASS (ev_toolbar_parent_class)->constructed (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);
-
-        /* Navigation */
-        hbox = ev_toolbar_create_button_group (ev_toolbar);
-
-        action = gtk_action_group_get_action (action_group, "GoPreviousPage");
-        button = ev_toolbar_create_button (ev_toolbar, action);
-        gtk_container_add (GTK_CONTAINER (hbox), button);
-        gtk_widget_show (button);
-
-        action = gtk_action_group_get_action (action_group, "GoNextPage");
-        button = ev_toolbar_create_button (ev_toolbar, action);
-        gtk_container_add (GTK_CONTAINER (hbox), button);
-        gtk_widget_show (button);
-
-        tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        if (rtl)
-                gtk_widget_set_margin_left (tool_item, 12);
-        else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (tool_item), hbox);
-        gtk_widget_show (hbox);
-
-        gtk_container_add (GTK_CONTAINER (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);
-        else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (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);
-        else
-                gtk_widget_set_margin_right (tool_item, 12);
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
-        gtk_widget_show (tool_item);
-
-        /* Find */
-        action = gtk_action_group_get_action (action_group, "EditFind");
-        button = ev_toolbar_create_toggle_button (ev_toolbar, action);
-        tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        gtk_container_add (GTK_CONTAINER (tool_item), button);
-        gtk_widget_show (button);
-        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_widget_show (tool_item);
-
-        /* Separator */
-        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);
-
-        /* 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_widget_show (tool_item);
-
-        /* View Menu */
-        menu = gtk_ui_manager_get_widget (ui_manager, "/ViewMenuPopup");
-        button = ev_toolbar_create_menu_button (ev_toolbar, "document-properties-symbolic",
-                                                menu, GTK_ALIGN_END);
-        gtk_widget_set_tooltip_text (button, _("View options"));
-        ev_toolbar->priv->view_menu_button = button;
-        tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        gtk_container_add (GTK_CONTAINER (tool_item), button);
-        gtk_widget_show (button);
-        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_widget_show (tool_item);
 }
 
 static void
@@ -267,75 +115,17 @@ ev_toolbar_class_init (EvToolbarClass *klass)
 {
         GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
 
-        g_object_class->set_property = ev_toolbar_set_property;
         g_object_class->constructed = ev_toolbar_constructed;
-
-        g_object_class_install_property (g_object_class,
-                                         PROP_WINDOW,
-                                         g_param_spec_object ("window",
-                                                              "Window",
-                                                              "The evince window",
-                                                              EV_TYPE_WINDOW,
-                                                              G_PARAM_WRITABLE |
-                                                              G_PARAM_CONSTRUCT_ONLY |
-                                                              G_PARAM_STATIC_STRINGS));
-
-        g_type_class_add_private (g_object_class, sizeof (EvToolbarPrivate));
 }
 
 static void
 ev_toolbar_init (EvToolbar *ev_toolbar)
 {
-        ev_toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (ev_toolbar, EV_TYPE_TOOLBAR, EvToolbarPrivate);
 }
 
 GtkWidget *
-ev_toolbar_new (EvWindow *window)
+ev_toolbar_new ()
 {
-        g_return_val_if_fail (EV_IS_WINDOW (window), NULL);
-
         return GTK_WIDGET (g_object_new (EV_TYPE_TOOLBAR,
-                                         "window", window,
                                          NULL));
 }
-
-gboolean
-ev_toolbar_has_visible_popups (EvToolbar *ev_toolbar)
-{
-        GtkAction        *action;
-        GtkActionGroup   *action_group;
-        GtkMenu          *popup_menu;
-        EvToolbarPrivate *priv;
-
-        g_return_val_if_fail (EV_IS_TOOLBAR (ev_toolbar), FALSE);
-
-        priv = ev_toolbar->priv;
-
-        popup_menu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (priv->view_menu_button));
-        if (gtk_widget_get_visible (GTK_WIDGET (popup_menu)))
-                return TRUE;
-
-        popup_menu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (priv->action_menu_button));
-        if (gtk_widget_get_visible (GTK_WIDGET (popup_menu)))
-                return TRUE;
-
-        action_group = ev_window_get_main_action_group (ev_toolbar->priv->window);
-        action = gtk_action_group_get_action (action_group, "ViewZoom");
-        if (ev_zoom_action_get_popup_shown (EV_ZOOM_ACTION (action)))
-                return TRUE;
-
-        action = gtk_action_group_get_action (action_group, "History");
-        if (ev_history_action_get_popup_shown (EV_HISTORY_ACTION (action)))
-                return TRUE;
-
-        return FALSE;
-}
-
-void
-ev_toolbar_action_menu_popup (EvToolbar *ev_toolbar)
-{
-        g_return_if_fail (EV_IS_TOOLBAR (ev_toolbar));
-
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ev_toolbar->priv->action_menu_button),
-                                      TRUE);
-}
diff --git a/shell/ev-toolbar.h b/shell/ev-toolbar.h
index 0c54932..be51b4a 100644
--- a/shell/ev-toolbar.h
+++ b/shell/ev-toolbar.h
@@ -2,6 +2,7 @@
  *  this file is part of evince, a gnome document viewer
  *
  * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2014 Germán Poo-Caamaño <gpoo gnome org>
  *
  * Evince is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
@@ -35,22 +36,31 @@ G_BEGIN_DECLS
 
 typedef struct _EvToolbar        EvToolbar;
 typedef struct _EvToolbarClass   EvToolbarClass;
-typedef struct _EvToolbarPrivate EvToolbarPrivate;
 
 struct _EvToolbar {
         GtkToolbar base_instance;
-
-        EvToolbarPrivate *priv;
 };
 
 struct _EvToolbarClass {
         GtkToolbarClass base_class;
 };
 
-GType      ev_toolbar_get_type           (void);
-GtkWidget *ev_toolbar_new                (EvWindow *window);
-gboolean   ev_toolbar_has_visible_popups (EvToolbar *ev_toolbar);
-void       ev_toolbar_action_menu_popup  (EvToolbar *ev_toolbar);
+GType      ev_toolbar_get_type             (void);
+GtkWidget *ev_toolbar_new                  (void);
+gboolean   ev_toolbar_has_visible_popups   (EvToolbar *ev_toolbar);
+void       ev_toolbar_action_menu_popup    (EvToolbar *ev_toolbar);
+void       ev_toolbar_set_button_action    (EvToolbar *ev_toolbar,
+                                           GtkButton *button,
+                                           GtkAction *action);
+GtkWidget *ev_toolbar_create_button        (EvToolbar *ev_toolbar,
+                                           GtkAction *action);
+GtkWidget *ev_toolbar_create_toggle_button (EvToolbar *ev_toolbar,
+                                           GtkAction *action);
+GtkWidget *ev_toolbar_create_menu_button   (EvToolbar   *ev_toolbar,
+                                           const gchar *icon_name,
+                                           GtkWidget   *menu,
+                                           GtkAlign     menu_align);
+GtkWidget *ev_toolbar_create_button_group  (EvToolbar *ev_toolbar);
 
 G_END_DECLS
 
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 174284a..43a20f5 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -90,7 +90,7 @@
 #include "ev-bookmarks.h"
 #include "ev-bookmark-action.h"
 #include "ev-zoom-action.h"
-#include "ev-toolbar.h"
+#include "ev-toolbar-main.h"
 
 #ifdef ENABLE_DBUS
 #include "ev-gdbus-generated.h"
@@ -4093,7 +4093,7 @@ ev_window_update_fullscreen_action (EvWindow *window)
 static void
 ev_window_fullscreen_hide_toolbar (EvWindow *window)
 {
-       if (!ev_toolbar_has_visible_popups (EV_TOOLBAR (window->priv->toolbar)))
+       if (!ev_toolbar_main_has_visible_popups (EV_TOOLBAR_MAIN (window->priv->toolbar)))
                gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->fs_revealer), FALSE);
 }
 
@@ -5019,7 +5019,7 @@ static void
 ev_window_cmd_action_menu (GtkAction *action, EvWindow *ev_window)
 {
        ev_window_fullscreen_show_toolbar (ev_window);
-       ev_toolbar_action_menu_popup (EV_TOOLBAR (ev_window->priv->toolbar));
+       ev_toolbar_main_action_menu_popup (EV_TOOLBAR_MAIN (ev_window->priv->toolbar));
 }
 
 static void
@@ -7355,7 +7355,7 @@ ev_window_init (EvWindow *ev_window)
                                  G_CALLBACK (ev_window_setup_recent),
                                  ev_window);
 
-       ev_window->priv->toolbar = ev_toolbar_new (ev_window);
+       ev_window->priv->toolbar = ev_toolbar_main_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);


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