1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2004 Red Hat, Inc.
6 * Jonathan Blandford <jrb@alum.mit.edu>
8 * Evince is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Evince is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
30 #include "ev-sidebar.h"
31 #include "ev-document-thumbnails.h"
32 #include "ev-document-links.h"
33 #include "ev-sidebar-links.h"
34 #include "ev-sidebar-thumbnails.h"
40 GtkWidget *main_widget;
47 PAGE_COLUMN_MAIN_WIDGET,
48 PAGE_COLUMN_NOTEBOOK_INDEX,
52 struct _EvSidebarPrivate {
53 GtkWidget *option_menu;
56 GtkTreeModel *page_model;
59 static void ev_sidebar_omenu_changed_cb (GtkComboBox *combo_box,
62 G_DEFINE_TYPE (EvSidebar, ev_sidebar, GTK_TYPE_VBOX)
64 #define EV_SIDEBAR_GET_PRIVATE(object) \
65 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR, EvSidebarPrivate))
68 ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class)
70 GObjectClass *g_object_class;
72 g_object_class = G_OBJECT_CLASS (ev_sidebar_class);
74 g_type_class_add_private (g_object_class, sizeof (EvSidebarPrivate));
79 ev_sidebar_init (EvSidebar *ev_sidebar)
82 GtkCellRenderer *renderer;
84 ev_sidebar->priv = EV_SIDEBAR_GET_PRIVATE (ev_sidebar);
85 gtk_box_set_spacing (GTK_BOX (ev_sidebar), 6);
88 ev_sidebar->priv->page_model = (GtkTreeModel *)
89 gtk_list_store_new (PAGE_COLUMN_NUM_COLS,
96 hbox = gtk_hbox_new (FALSE, 6);
97 gtk_box_pack_start (GTK_BOX (ev_sidebar), hbox,
99 ev_sidebar->priv->option_menu =
100 gtk_combo_box_new_with_model (ev_sidebar->priv->page_model);
101 g_signal_connect (ev_sidebar->priv->option_menu, "changed",
102 G_CALLBACK (ev_sidebar_omenu_changed_cb), ev_sidebar);
103 gtk_box_pack_start (GTK_BOX (hbox),
104 ev_sidebar->priv->option_menu,
107 renderer = gtk_cell_renderer_text_new ();
108 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (ev_sidebar->priv->option_menu),
110 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (ev_sidebar->priv->option_menu),
112 "text", PAGE_COLUMN_TITLE,
115 ev_sidebar->priv->notebook = gtk_notebook_new ();
116 gtk_notebook_set_show_border (GTK_NOTEBOOK (ev_sidebar->priv->notebook), FALSE);
117 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ev_sidebar->priv->notebook), FALSE);
118 gtk_box_pack_start (GTK_BOX (ev_sidebar), ev_sidebar->priv->notebook,
120 gtk_widget_show_all (GTK_WIDGET (ev_sidebar));
124 ev_sidebar_omenu_changed_cb (GtkComboBox *combo_box,
128 EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
130 if (gtk_combo_box_get_active_iter (combo_box, &iter)) {
133 gtk_tree_model_get (ev_sidebar->priv->page_model,
135 PAGE_COLUMN_NOTEBOOK_INDEX, &index,
137 gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
143 /* Public functions */
146 ev_sidebar_new (void)
148 GtkWidget *ev_sidebar;
150 ev_sidebar = g_object_new (EV_TYPE_SIDEBAR, NULL);
156 ev_sidebar_add_page (EvSidebar *ev_sidebar,
157 const gchar *page_id,
159 GtkWidget *main_widget)
164 g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
165 g_return_if_fail (page_id != NULL);
166 g_return_if_fail (title != NULL);
167 g_return_if_fail (GTK_IS_WIDGET (main_widget));
169 index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
172 gtk_list_store_insert_with_values (GTK_LIST_STORE (ev_sidebar->priv->page_model),
174 PAGE_COLUMN_ID, page_id,
175 PAGE_COLUMN_TITLE, title,
176 PAGE_COLUMN_MAIN_WIDGET, main_widget,
177 PAGE_COLUMN_NOTEBOOK_INDEX, index,
180 /* Set the first item added as active */
181 if (gtk_combo_box_get_active (GTK_COMBO_BOX (ev_sidebar->priv->option_menu)))
182 gtk_combo_box_set_active (GTK_COMBO_BOX (ev_sidebar->priv->option_menu), 0);
186 ev_sidebar_set_document (EvSidebar *sidebar,
187 EvDocument *document)
189 EvSidebarPrivate *priv;
193 g_return_if_fail (EV_IS_SIDEBAR (sidebar));
194 g_return_if_fail (EV_IS_DOCUMENT (document));
196 priv = sidebar->priv;
198 /* FIXME: We should prolly make sidebars have an interface. For now, we
199 * do this bad hack (TM)
201 for (result = gtk_tree_model_get_iter_first (priv->page_model, &iter);
203 result = gtk_tree_model_iter_next (priv->page_model, &iter)) {
206 gtk_tree_model_get (priv->page_model, &iter,
207 PAGE_COLUMN_MAIN_WIDGET, &widget,
210 if (EV_IS_SIDEBAR_LINKS (widget)
211 && EV_IS_DOCUMENT_LINKS (document)
212 && ev_document_links_has_document_links (EV_DOCUMENT_LINKS (document)))
213 ev_sidebar_links_set_document (EV_SIDEBAR_LINKS (widget),
215 else if (EV_IS_SIDEBAR_THUMBNAILS (widget) &&
216 EV_IS_DOCUMENT_THUMBNAILS (document))
217 ev_sidebar_thumbnails_set_document (EV_SIDEBAR_THUMBNAILS (widget),
225 ev_sidebar_clear (EvSidebar *ev_sidebar)
227 g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
229 gtk_list_store_clear (GTK_LIST_STORE (ev_sidebar->priv->page_model));