[evince/gnome3-style: 2/14] Add EvToolbar widget to show a gnome3 style toolbar
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/gnome3-style: 2/14] Add EvToolbar widget to show a gnome3 style toolbar
- Date: Tue, 16 Oct 2012 12:15:52 +0000 (UTC)
commit a03f050178e81a3fd016b6b683504cb05b29be00
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Sat Oct 13 10:56:02 2012 +0200
Add EvToolbar widget to show a gnome3 style toolbar
Based on nautilus toolbar
shell/Makefile.am | 2 +
shell/ev-toolbar.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++
shell/ev-toolbar.h | 55 +++++++++
shell/evince-ui.xml | 49 ++++++++
4 files changed, 413 insertions(+), 0 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 73c8499..5477710 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -65,6 +65,8 @@ evince_SOURCES= \
ev-properties-license.h \
ev-open-recent-action.c \
ev-open-recent-action.h \
+ ev-toolbar.c \
+ ev-toolbar.h \
ev-utils.c \
ev-utils.h \
ev-window.c \
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
new file mode 100644
index 0000000..980876b
--- /dev/null
+++ b/shell/ev-toolbar.c
@@ -0,0 +1,307 @@
+/* ev-toolbar.h
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc 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 "ev-toolbar.h"
+
+#include "ev-stock-icons.h"
+#include <math.h>
+
+enum
+{
+ PROP_0,
+ PROP_WINDOW
+};
+
+struct _EvToolbarPrivate {
+ EvWindow *window;
+};
+
+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 gint
+get_icon_margin (EvToolbar *ev_toolbar)
+{
+ GtkIconSize toolbar_size;
+ gint toolbar_size_px, menu_size_px;
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (ev_toolbar));
+
+ toolbar_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (ev_toolbar));
+
+ gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &menu_size_px, NULL);
+ gtk_icon_size_lookup_for_settings (settings, toolbar_size, &toolbar_size_px, NULL);
+
+ return (gint)floor ((toolbar_size_px - menu_size_px) / 2.0);
+}
+
+static void
+ev_toolbar_set_button_image (EvToolbar *ev_toolbar,
+ GtkButton *button)
+{
+ GtkWidget *image;
+
+ image = gtk_image_new ();
+ g_object_set (image, "margin", get_icon_margin (ev_toolbar), NULL);
+ gtk_button_set_image (button, image);
+}
+
+static void
+ev_toolbar_set_button_action (EvToolbar *ev_toolbar,
+ GtkButton *button,
+ GtkAction *action)
+{
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
+ gtk_button_set_label (button, NULL);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (button), gtk_action_get_tooltip (action));
+}
+
+static GtkWidget *
+ev_toolbar_create_button (EvToolbar *ev_toolbar,
+ GtkAction *action)
+{
+ GtkWidget *button = gtk_button_new ();
+
+ ev_toolbar_set_button_image (ev_toolbar, GTK_BUTTON (button));
+ ev_toolbar_set_button_action (ev_toolbar, GTK_BUTTON (button), action);
+
+ return button;
+}
+
+static GtkWidget *
+ev_toolbar_create_toggle_button (EvToolbar *ev_toolbar,
+ GtkAction *action)
+{
+ GtkWidget *button = gtk_toggle_button_new ();
+
+ ev_toolbar_set_button_image (ev_toolbar, GTK_BUTTON (button));
+ ev_toolbar_set_button_action (ev_toolbar, GTK_BUTTON (button), action);
+
+ return button;
+}
+
+static GtkWidget *
+ev_toolbar_create_menu_button (EvToolbar *ev_toolbar,
+ const gchar *icon_name,
+ GtkWidget *menu,
+ GtkAlign menu_align)
+{
+ GtkWidget *button = gtk_menu_button_new ();
+
+ ev_toolbar_set_button_image (ev_toolbar, GTK_BUTTON (button));
+ gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON (button))),
+ icon_name, GTK_ICON_SIZE_MENU);
+ gtk_widget_set_halign (menu, menu_align);
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu);
+
+ return button;
+}
+
+static GtkWidget *
+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);
+
+ style_context = gtk_widget_get_style_context (box);
+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_RAISED);
+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_LINKED);
+
+ return box;
+}
+
+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;
+
+ G_OBJECT_CLASS (ev_toolbar_parent_class)->constructed (object);
+
+ /* 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 ());
+ 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);
+ gtk_widget_set_margin_right (tool_item, 12);
+ 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);
+ 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);
+
+ /* Find */
+ action = gtk_action_group_get_action (action_group, "EditFind");
+ tool_item = gtk_action_create_tool_item (action);
+ gtk_widget_set_margin_right (tool_item, 12);
+ gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+
+ /* View */
+ hbox = ev_toolbar_create_button_group (ev_toolbar);
+
+ action = gtk_action_group_get_action (action_group, "ViewContinuous");
+ /* I don't know why our icon name is not set for our stock icons */
+ gtk_action_set_icon_name (action, EV_STOCK_VIEW_CONTINUOUS);
+ button = ev_toolbar_create_toggle_button (ev_toolbar, action);
+ gtk_container_add (GTK_CONTAINER (hbox), button);
+ gtk_widget_show (button);
+
+ action = gtk_action_group_get_action (action_group, "ViewDual");
+ /* I don't know why our icon name is not set for our stock icons */
+ gtk_action_set_icon_name (action, EV_STOCK_VIEW_DUAL);
+ button = ev_toolbar_create_toggle_button (ev_toolbar, action);
+ gtk_container_add (GTK_CONTAINER (hbox), button);
+ gtk_widget_show (button);
+
+ action = gtk_action_group_get_action (action_group, "ViewDualOddLeft");
+ /* I don't know why our icon name is not set for our stock icons */
+ gtk_action_set_icon_name (action, EV_STOCK_VIEW_DUAL);
+ button = ev_toolbar_create_toggle_button (ev_toolbar, action);
+ gtk_container_add (GTK_CONTAINER (hbox), button);
+ gtk_widget_show (button);
+
+ menu = gtk_ui_manager_get_widget (ui_manager, "/ViewMenuPopup");
+ button = ev_toolbar_create_menu_button (ev_toolbar, "go-down-symbolic",
+ menu, GTK_ALIGN_END);
+ gtk_container_add (GTK_CONTAINER (hbox), button);
+ gtk_widget_show (button);
+
+ tool_item = GTK_WIDGET (gtk_tool_item_new ());
+ 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);
+
+ /* 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);
+ 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_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)
+{
+ g_return_val_if_fail (EV_IS_WINDOW (window), NULL);
+
+ return GTK_WIDGET (g_object_new (EV_TYPE_TOOLBAR,
+ "window", window,
+ NULL));
+}
+
diff --git a/shell/ev-toolbar.h b/shell/ev-toolbar.h
new file mode 100644
index 0000000..850c281
--- /dev/null
+++ b/shell/ev-toolbar.h
@@ -0,0 +1,55 @@
+/* ev-toolbar.h
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc 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_H__
+#define __EV_TOOLBAR_H__
+
+#include <gtk/gtk.h>
+#include "ev-window.h"
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_TOOLBAR (ev_toolbar_get_type())
+#define EV_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_TOOLBAR, EvToolbar))
+#define EV_IS_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_TOOLBAR))
+#define EV_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_TOOLBAR, EvToolbarClass))
+#define EV_IS_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_TOOLBAR))
+#define EV_TOOLBAR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_TOOLBAR, EvToolbarClass))
+
+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);
+
+G_END_DECLS
+
+#endif /* __EV_TOOLBAR_H__ */
diff --git a/shell/evince-ui.xml b/shell/evince-ui.xml
index 8bfe033..44c2328 100644
--- a/shell/evince-ui.xml
+++ b/shell/evince-ui.xml
@@ -76,6 +76,55 @@
</menu>
</menubar>
+ <popup name="ActionMenu">
+ <menuitem name="FileOpenMenu" action="FileOpen"/>
+ <menuitem name="FileOpenCopyMenu" action="FileOpenCopy"/>
+ <menu name="RecentFilesMenu" action="RecentFiles">
+ <placeholder name="RecentFiles"/>
+ </menu>
+ <menuitem name="FileSaveAsMenu" action="FileSaveAs"/>
+ <menuitem name="FileSendToMenu" action="FileSendTo"/>
+ <menuitem name="FileOpenContainingFolderMenu" action="FileOpenContainingFolder"/>
+ <menuitem name="FilePrintMenu" action="FilePrint"/>
+ <separator/>
+ <menuitem name="FilePropertiesMenu" action="FileProperties"/>
+ <separator/>
+ <menuitem name="EditCopyMenu" action="EditCopy"/>
+ <menuitem name="EditSelectAllMenu" action="EditSelectAll"/>
+ <separator/>
+ <menuitem name="EditSaveSettingsMenu" action="EditSaveSettings"/>
+ <separator/>
+ <menuitem name="GoFirstPageMenu" action="GoFirstPage"/>
+ <menuitem name="GoLastPageMenu" action="GoLastPage"/>
+ <separator/>
+ <menuitem name="BookmarksAddMenu" action="BookmarksAdd"/>
+ <menu name="BookmarksMenu" action="Bookmarks">
+ <placeholder name="BookmarksItems"/>
+ </menu>
+ <separator/>
+ <menuitem name="FileCloseWindowMenu" action="FileCloseWindow"/>
+ <separator/>
+ <menuitem name="HelpAboutMenu" action="HelpAbout"/>
+ <menuitem name="HelpContentsMenu" action="HelpContents"/>
+ </popup>
+
+ <popup name="ViewMenuPopup">
+ <menuitem name="ViewSidebarMenu" action="ViewSidebar"/>
+ <separator/>
+ <menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/>
+ <menuitem name="ViewPresentationMenu" action="ViewPresentation"/>
+ <separator/>
+ <menuitem name="EditRotateLeftMenu" action="EditRotateLeft"/>
+ <menuitem name="EditRotateRightMenu" action="EditRotateRight"/>
+ <separator/>
+ <menuitem name="ViewZoomInMenu" action="ViewZoomIn"/>
+ <menuitem name="ViewZoomOutMenu" action="ViewZoomOut"/>
+ <separator/>
+ <menuitem name="ViewInvertedColors" action="ViewInvertedColors"/>
+ <separator/>
+ <menuitem name="ViewReload" action="ViewReload"/>
+ </popup>
+
<popup name="DocumentPopup" action="DocumentPopupAction">
<menuitem name="OpenLink" action="OpenLink"/>
<menuitem name="CopyLinkAddress" action="CopyLinkAddress"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]