2 * Copyright (C) 2003, 2004 Marco Pesenti Gritti
3 * Copyright (C) 2003, 2004 Christian Persch
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <glib/gi18n.h>
31 #include "ev-page-action.h"
32 #include "ev-page-action-widget.h"
34 struct _EvPageActionPrivate
36 EvDocumentModel *doc_model;
41 static void ev_page_action_init (EvPageAction *action);
42 static void ev_page_action_class_init (EvPageActionClass *class);
50 static guint signals[N_SIGNALS] = {0, };
52 G_DEFINE_TYPE (EvPageAction, ev_page_action, GTK_TYPE_ACTION)
54 #define EV_PAGE_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_PAGE_ACTION, EvPageActionPrivate))
62 create_tool_item (GtkAction *action)
66 proxy = g_object_new (EV_TYPE_PAGE_ACTION_WIDGET, NULL);
72 update_model (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
74 ev_page_action_widget_update_links_model (proxy, page->priv->model);
78 activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action)
80 g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
84 connect_proxy (GtkAction *action, GtkWidget *proxy)
86 EvPageAction *page = EV_PAGE_ACTION (action);
88 if (GTK_IS_TOOL_ITEM (proxy)) {
89 ev_page_action_widget_set_model (EV_PAGE_ACTION_WIDGET (proxy),
90 page->priv->doc_model);
91 g_signal_connect (proxy, "activate_link",
92 G_CALLBACK (activate_link_cb),
94 g_signal_connect_object (action, "notify::model",
95 G_CALLBACK (update_model),
99 GTK_ACTION_CLASS (ev_page_action_parent_class)->connect_proxy (action, proxy);
103 ev_page_action_dispose (GObject *object)
105 EvPageAction *page = EV_PAGE_ACTION (object);
107 if (page->priv->model) {
108 g_object_unref (page->priv->model);
109 page->priv->model = NULL;
112 page->priv->doc_model = NULL;
114 G_OBJECT_CLASS (ev_page_action_parent_class)->dispose (object);
118 ev_page_action_set_property (GObject *object,
123 EvPageAction *page = EV_PAGE_ACTION (object);
128 ev_page_action_set_links_model (page, g_value_get_object (value));
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137 ev_page_action_get_property (GObject *object,
142 EvPageAction *page = EV_PAGE_ACTION (object);
147 g_value_set_object (value, page->priv->model);
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
156 ev_page_action_set_model (EvPageAction *page,
157 EvDocumentModel *model)
159 g_return_if_fail (EV_IS_PAGE_ACTION (page));
160 g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
162 if (page->priv->doc_model == model)
165 page->priv->doc_model = model;
169 ev_page_action_set_links_model (EvPageAction *page,
170 GtkTreeModel *links_model)
172 g_return_if_fail (EV_IS_PAGE_ACTION (page));
173 g_return_if_fail (GTK_IS_TREE_MODEL (links_model));
175 if (page->priv->model == links_model)
178 if (page->priv->model)
179 g_object_unref (page->priv->model);
180 page->priv->model = g_object_ref (links_model);
182 g_object_notify (G_OBJECT (page), "model");
186 ev_page_action_grab_focus (EvPageAction *page_action)
190 proxies = gtk_action_get_proxies (GTK_ACTION (page_action));
191 for (; proxies != NULL; proxies = proxies->next) {
192 EvPageActionWidget *proxy;
194 proxy = EV_PAGE_ACTION_WIDGET (proxies->data);
196 if (gtk_widget_get_mapped (GTK_WIDGET (proxy)))
197 ev_page_action_widget_grab_focus (proxy);
202 ev_page_action_init (EvPageAction *page)
204 page->priv = EV_PAGE_ACTION_GET_PRIVATE (page);
208 ev_page_action_class_init (EvPageActionClass *class)
210 GObjectClass *object_class = G_OBJECT_CLASS (class);
211 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
213 object_class->dispose = ev_page_action_dispose;
214 object_class->set_property = ev_page_action_set_property;
215 object_class->get_property = ev_page_action_get_property;
217 action_class->toolbar_item_type = GTK_TYPE_TOOL_ITEM;
218 action_class->create_tool_item = create_tool_item;
219 action_class->connect_proxy = connect_proxy;
221 signals[ACTIVATE_LINK] = g_signal_new ("activate_link",
222 G_OBJECT_CLASS_TYPE (object_class),
223 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
224 G_STRUCT_OFFSET (EvPageActionClass, activate_link),
226 g_cclosure_marshal_VOID__OBJECT,
230 g_object_class_install_property (object_class,
232 g_param_spec_object ("model",
234 "Current Links Model",
238 g_type_class_add_private (object_class, sizeof (EvPageActionPrivate));