Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-annotations-toolbar.c
Go to the documentation of this file.
1 /* ev-annotations-toolbar.c
2  * this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2015 Carlos Garcia Campos <carlosgc@gnome.org>
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 #include "config.h"
22 
23 #include "ev-annotations-toolbar.h"
24 #include <evince-document.h>
25 #include <glib/gi18n.h>
26 
27 enum {
31 };
32 
34  GtkToolbar base_instance;
35 
36  GtkWidget *text_button;
37  GtkWidget *highlight_button;
38 };
39 
41  GtkToolbarClass base_class;
42 
43 };
44 
45 static guint signals[N_SIGNALS];
46 
47 G_DEFINE_TYPE (EvAnnotationsToolbar, ev_annotations_toolbar, GTK_TYPE_TOOLBAR)
48 
49 static void
51  EvAnnotationsToolbar *toolbar)
52 {
53  EvAnnotationType annot_type;
54 
55  if (!gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (button))) {
56  g_signal_emit (toolbar, signals[CANCEL_ADD_ANNOT], 0, NULL);
57  return;
58  }
59 
60  if (button == toolbar->text_button) {
61  annot_type = EV_ANNOTATION_TYPE_TEXT;
62  gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (toolbar->highlight_button), FALSE);
63  } else if (button == toolbar->highlight_button) {
64  annot_type = EV_ANNOTATION_TYPE_TEXT_MARKUP;
65  gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (toolbar->text_button), FALSE);
66  } else {
67  g_assert_not_reached ();
68  }
69 
70  g_signal_emit (toolbar, signals[BEGIN_ADD_ANNOT], 0, annot_type);
71 }
72 
73 static gboolean
75  GtkToggleToolButton *button)
76 {
77  if (!gtk_toggle_tool_button_get_active (button))
78  return FALSE;
79 
80  g_signal_handlers_block_by_func (button,
82  toolbar);
83  gtk_toggle_tool_button_set_active (button, FALSE);
84  g_signal_handlers_unblock_by_func (button,
86  toolbar);
87 
88  return TRUE;
89 }
90 
91 static GtkWidget *
93  const gchar *icon_name,
94  const gchar *tooltip)
95 {
96  GtkWidget *button = GTK_WIDGET (gtk_toggle_tool_button_new ());
97 
98  gtk_widget_set_tooltip_text (button, tooltip);
99  gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (button), icon_name);
100  /* For some reason adding text-button class to the GtkToogleButton makes the button smaller */
101  gtk_style_context_add_class (gtk_widget_get_style_context (gtk_bin_get_child (GTK_BIN (button))), "text-button");
102  g_signal_connect (button, "toggled",
104  toolbar);
105 
106  return button;
107 }
108 
109 static void
111 {
112  gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), GTK_ORIENTATION_HORIZONTAL);
113 
114  gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU);
115  gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (toolbar)),
116  GTK_STYLE_CLASS_INLINE_TOOLBAR);
117 
119  "document-new-symbolic",
120  _("Add text annotation"));
121  gtk_container_add (GTK_CONTAINER(toolbar), toolbar->text_button);
122  gtk_widget_show (toolbar->text_button);
123 
124  /* FIXME: use a better icon than select-all */
126  "edit-select-all-symbolic",
127  _("Add highlight annotation"));
128  gtk_container_add (GTK_CONTAINER (toolbar), toolbar->highlight_button);
129  gtk_widget_show (toolbar->highlight_button);
130 }
131 
132 static void
134 {
135  GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
136 
138  g_signal_new ("begin-add-annot",
139  G_TYPE_FROM_CLASS (g_object_class),
140  G_SIGNAL_RUN_LAST,
141  0,
142  NULL, NULL,
143  g_cclosure_marshal_VOID__ENUM,
144  G_TYPE_NONE, 1,
145  EV_TYPE_ANNOTATION_TYPE);
146 
148  g_signal_new ("cancel-add-annot",
149  G_TYPE_FROM_CLASS (g_object_class),
150  G_SIGNAL_RUN_LAST,
151  0,
152  NULL, NULL,
153  g_cclosure_marshal_VOID__VOID,
154  G_TYPE_NONE, 0,
155  G_TYPE_NONE);
156 }
157 
158 GtkWidget *
160 {
161  return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATIONS_TOOLBAR, NULL));
162 }
163 
164 void
166 {
167  g_return_if_fail (EV_IS_ANNOTATIONS_TOOLBAR (toolbar));
168 
169  if (ev_annotations_toolbar_toggle_button_if_active (toolbar, GTK_TOGGLE_TOOL_BUTTON (toolbar->text_button)))
170  return;
171 
172  ev_annotations_toolbar_toggle_button_if_active (toolbar, GTK_TOGGLE_TOOL_BUTTON (toolbar->highlight_button));
173 }