From 5a7fb79a9faa64e7b877b16a220999945b54a128 Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Wed, 22 Dec 2004 04:21:54 +0000 Subject: Construct an actual sidebar. Tue Dec 21 23:20:35 2004 Jonathan Blandford * shell/ev-sidebar.c: Construct an actual sidebar. * shell/ev-sidebar-bookmarks.[ch]: * shell/ev-sidebar-thumbnails.[ch]: Stub out sidebars. --- (limited to 'shell') diff --git a/shell/Makefile.am b/shell/Makefile.am index 48aa917..67ec0b0 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -26,6 +26,10 @@ evince_SOURCES= \ ev-window.h \ ev-sidebar.c \ ev-sidebar.h \ + ev-sidebar-bookmarks.c \ + ev-sidebar-bookmarks.h \ + ev-sidebar-thumbnails.c \ + ev-sidebar-thumbnails.h \ main.c \ $(NULL) diff --git a/shell/ev-sidebar-bookmarks.c b/shell/ev-sidebar-bookmarks.c new file mode 100644 index 0000000..b7e060f --- /dev/null +++ b/shell/ev-sidebar-bookmarks.c @@ -0,0 +1,100 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2004 Red Hat, Inc. + * + * Author: + * Jonathan Blandford + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "ev-sidebar-bookmarks.h" + +struct _EvSidebarBookmarksPrivate { + GtkWidget *tree_view; +}; + +enum { + BOOKMARKS_COLUMN_MARKUP, + BOOKMARKS_COLUMN_OUTLINE, + BOOKMARKS_COLUMN_PAGE_NUM, + BOOKMARKS_COLUMN_PAGE_VALID, + NUM_COLUMNS +}; + +G_DEFINE_TYPE (EvSidebarBookmarks, ev_sidebar_bookmarks, GTK_TYPE_VBOX) + +#define EV_SIDEBAR_BOOKMARKS_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_BOOKMARKS, EvSidebarBookmarksPrivate)) + +static void +ev_sidebar_bookmarks_class_init (EvSidebarBookmarksClass *ev_sidebar_bookmarks_class) +{ + GObjectClass *g_object_class; + + g_object_class = G_OBJECT_CLASS (ev_sidebar_bookmarks_class); + + g_type_class_add_private (g_object_class, sizeof (EvSidebarBookmarksPrivate)); + +} + + +static void +ev_sidebar_bookmarks_construct (EvSidebarBookmarks *ev_sidebar_bookmarks) +{ + EvSidebarBookmarksPrivate *priv; + GtkWidget *swindow; + + priv = ev_sidebar_bookmarks->priv; + swindow = gtk_scrolled_window_new (NULL, NULL); + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow), + GTK_SHADOW_IN); + + /* Create tree view */ + priv->tree_view = gtk_tree_view_new (); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE); + gtk_container_add (GTK_CONTAINER (swindow), priv->tree_view); + + gtk_box_pack_start (GTK_BOX (ev_sidebar_bookmarks), swindow, TRUE, TRUE, 0); + gtk_widget_show_all (GTK_WIDGET (ev_sidebar_bookmarks)); +} + +static void +ev_sidebar_bookmarks_init (EvSidebarBookmarks *ev_sidebar_bookmarks) +{ + ev_sidebar_bookmarks->priv = EV_SIDEBAR_BOOKMARKS_GET_PRIVATE (ev_sidebar_bookmarks); + + ev_sidebar_bookmarks_construct (ev_sidebar_bookmarks); +} + +GtkWidget * +ev_sidebar_bookmarks_new (void) +{ + GtkWidget *ev_sidebar_bookmarks; + + ev_sidebar_bookmarks = g_object_new (EV_TYPE_SIDEBAR_BOOKMARKS, NULL); + + return ev_sidebar_bookmarks; +} diff --git a/shell/ev-sidebar-bookmarks.h b/shell/ev-sidebar-bookmarks.h new file mode 100644 index 0000000..86902c7 --- /dev/null +++ b/shell/ev-sidebar-bookmarks.h @@ -0,0 +1,59 @@ +/* ev-sidebar-bookmarks.h + * this file is part of evince, a gnome document viewer + * + * Copyright (C) 2004 Red Hat, Inc. + * + * Author: + * Jonathan Blandford + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __EV_SIDEBAR_BOOKMARKS_H__ +#define __EV_SIDEBAR_BOOKMARKS_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _EvSidebarBookmarks EvSidebarBookmarks; +typedef struct _EvSidebarBookmarksClass EvSidebarBookmarksClass; +typedef struct _EvSidebarBookmarksPrivate EvSidebarBookmarksPrivate; + +#define EV_TYPE_SIDEBAR_BOOKMARKS (ev_sidebar_bookmarks_get_type()) +#define EV_SIDEBAR_BOOKMARKS(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_SIDEBAR_BOOKMARKS, EvSidebarBookmarks)) +#define EV_SIDEBAR_BOOKMARKS_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), EV_TYPE_SIDEBAR_BOOKMARKS, EvSidebarBookmarksClass)) +#define EV_IS_SIDEBAR_BOOKMARKS(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_SIDEBAR_BOOKMARKS)) +#define EV_IS_SIDEBAR_BOOKMARKS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_SIDEBAR_BOOKMARKS)) +#define EV_SIDEBAR_BOOKMARKS_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_SIDEBAR_BOOKMARKS, EvSidebarBookmarksClass)) + +struct _EvSidebarBookmarks { + GtkVBox base_instance; + + EvSidebarBookmarksPrivate *priv; +}; + +struct _EvSidebarBookmarksClass { + GtkVBoxClass base_class; +}; + +GType ev_sidebar_bookmarks_get_type (void); +GtkWidget *ev_sidebar_bookmarks_new (void); + +G_END_DECLS + +#endif /* __EV_SIDEBAR_BOOKMARKS_H__ */ + + diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c new file mode 100644 index 0000000..a2f5d76 --- /dev/null +++ b/shell/ev-sidebar-thumbnails.c @@ -0,0 +1,73 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2004 Red Hat, Inc. + * + * Author: + * Jonathan Blandford + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "ev-sidebar-thumbnails.h" + +struct _EvSidebarThumbnailsPrivate { + int dummy; +}; + +G_DEFINE_TYPE (EvSidebarThumbnails, ev_sidebar_thumbnails, GTK_TYPE_VBOX) + +#define EV_SIDEBAR_THUMBNAILS_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsPrivate)) + +static void +ev_sidebar_thumbnails_class_init (EvSidebarThumbnailsClass *ev_sidebar_thumbnails_class) +{ + GObjectClass *g_object_class; + + g_object_class = G_OBJECT_CLASS (ev_sidebar_thumbnails_class); + + g_type_class_add_private (g_object_class, sizeof (EvSidebarThumbnailsPrivate)); + +} + +static void +ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails) +{ + GtkWidget *label; + + ev_sidebar_thumbnails->priv = EV_SIDEBAR_THUMBNAILS_GET_PRIVATE (ev_sidebar_thumbnails); + + label = gtk_label_new ("Thumbnails!"); + gtk_box_pack_start (GTK_BOX (ev_sidebar_thumbnails), label, + TRUE, TRUE, 0); + gtk_widget_show (label); +} + +GtkWidget * +ev_sidebar_thumbnails_new (void) +{ + GtkWidget *ev_sidebar_thumbnails; + + ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL); + + return ev_sidebar_thumbnails; +} diff --git a/shell/ev-sidebar-thumbnails.h b/shell/ev-sidebar-thumbnails.h new file mode 100644 index 0000000..e0ccccf --- /dev/null +++ b/shell/ev-sidebar-thumbnails.h @@ -0,0 +1,59 @@ +/* ev-sidebar-thumbnails.h + * this file is part of evince, a gnome document viewer + * + * Copyright (C) 2004 Red Hat, Inc. + * + * Author: + * Jonathan Blandford + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __EV_SIDEBAR_THUMBNAILS_H__ +#define __EV_SIDEBAR_THUMBNAILS_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _EvSidebarThumbnails EvSidebarThumbnails; +typedef struct _EvSidebarThumbnailsClass EvSidebarThumbnailsClass; +typedef struct _EvSidebarThumbnailsPrivate EvSidebarThumbnailsPrivate; + +#define EV_TYPE_SIDEBAR_THUMBNAILS (ev_sidebar_thumbnails_get_type()) +#define EV_SIDEBAR_THUMBNAILS(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnails)) +#define EV_SIDEBAR_THUMBNAILS_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsClass)) +#define EV_IS_SIDEBAR_THUMBNAILS(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_SIDEBAR_THUMBNAILS)) +#define EV_IS_SIDEBAR_THUMBNAILS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_SIDEBAR_THUMBNAILS)) +#define EV_SIDEBAR_THUMBNAILS_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsClass)) + +struct _EvSidebarThumbnails { + GtkVBox base_instance; + + EvSidebarThumbnailsPrivate *priv; +}; + +struct _EvSidebarThumbnailsClass { + GtkVBoxClass base_class; +}; + +GType ev_sidebar_thumbnails_get_type (void); +GtkWidget *ev_sidebar_thumbnails_new (void); + +G_END_DECLS + +#endif /* __EV_SIDEBAR_THUMBNAILS_H__ */ + + diff --git a/shell/ev-sidebar.c b/shell/ev-sidebar.c index 7f2747d..4ff8405 100644 --- a/shell/ev-sidebar.c +++ b/shell/ev-sidebar.c @@ -29,11 +29,32 @@ #include "ev-sidebar.h" +typedef struct +{ + char *id; + char *title; + GtkWidget *main_widget; +} EvSidebarPage; + +enum +{ + PAGE_COLUMN_ID, + PAGE_COLUMN_TITLE, + PAGE_COLUMN_MAIN_WIDGET, + PAGE_COLUMN_NOTEBOOK_INDEX, + PAGE_COLUMN_NUM_COLS +}; + struct _EvSidebarPrivate { GtkWidget *option_menu; GtkWidget *notebook; + + GtkTreeModel *page_model; }; +static void ev_sidebar_omenu_changed_cb (GtkComboBox *combo_box, + gpointer user_data); + G_DEFINE_TYPE (EvSidebar, ev_sidebar, GTK_TYPE_VBOX) #define EV_SIDEBAR_GET_PRIVATE(object) \ @@ -53,17 +74,67 @@ ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class) static void ev_sidebar_init (EvSidebar *ev_sidebar) { + GtkWidget *hbox; + GtkCellRenderer *renderer; + ev_sidebar->priv = EV_SIDEBAR_GET_PRIVATE (ev_sidebar); - ev_sidebar->priv->notebook = gtk_notebook_new (); + gtk_box_set_spacing (GTK_BOX (ev_sidebar), 6); + /* data model */ + ev_sidebar->priv->page_model = (GtkTreeModel *) + gtk_list_store_new (PAGE_COLUMN_NUM_COLS, + G_TYPE_STRING, + G_TYPE_STRING, + GTK_TYPE_WIDGET, + G_TYPE_INT); + /* top option menu */ + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (ev_sidebar), hbox, + FALSE, FALSE, 0); + ev_sidebar->priv->option_menu = + gtk_combo_box_new_with_model (ev_sidebar->priv->page_model); + g_signal_connect (ev_sidebar->priv->option_menu, "changed", + G_CALLBACK (ev_sidebar_omenu_changed_cb), ev_sidebar); + gtk_box_pack_start (GTK_BOX (hbox), + ev_sidebar->priv->option_menu, + FALSE, FALSE, 0); + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (ev_sidebar->priv->option_menu), + renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (ev_sidebar->priv->option_menu), + renderer, + "text", PAGE_COLUMN_TITLE, + NULL); + ev_sidebar->priv->notebook = gtk_notebook_new (); gtk_notebook_set_show_border (GTK_NOTEBOOK (ev_sidebar->priv->notebook), FALSE); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ev_sidebar->priv->notebook), FALSE); gtk_box_pack_start (GTK_BOX (ev_sidebar), ev_sidebar->priv->notebook, TRUE, TRUE, 0); - gtk_widget_show_all (ev_sidebar->priv->notebook); + gtk_widget_show_all (GTK_WIDGET (ev_sidebar)); } +static void +ev_sidebar_omenu_changed_cb (GtkComboBox *combo_box, + gpointer user_data) +{ + GtkTreeIter iter; + EvSidebar *ev_sidebar = EV_SIDEBAR (user_data); + + if (gtk_combo_box_get_active_iter (combo_box, &iter)) { + gint index; + + gtk_tree_model_get (ev_sidebar->priv->page_model, + &iter, + PAGE_COLUMN_NOTEBOOK_INDEX, &index, + -1); + gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook), + index); + + } +} + +/* Public functions */ GtkWidget * ev_sidebar_new (void) @@ -74,3 +145,37 @@ ev_sidebar_new (void) return ev_sidebar; } + +void +ev_sidebar_add_page (EvSidebar *ev_sidebar, + const gchar *page_id, + const gchar *title, + GtkWidget *main_widget) +{ + GtkTreeIter iter; + int index; + + g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar)); + g_return_if_fail (page_id != NULL); + g_return_if_fail (title != NULL); + g_return_if_fail (GTK_IS_WIDGET (main_widget)); + + index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook), + main_widget, NULL); + + gtk_list_store_insert_with_values (GTK_LIST_STORE (ev_sidebar->priv->page_model), + &iter, 0, + PAGE_COLUMN_ID, page_id, + PAGE_COLUMN_TITLE, title, + PAGE_COLUMN_MAIN_WIDGET, main_widget, + PAGE_COLUMN_NOTEBOOK_INDEX, index, + -1); +} + +void +ev_sidebar_clear (EvSidebar *ev_sidebar) +{ + g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar)); + + gtk_list_store_clear (GTK_LIST_STORE (ev_sidebar->priv->page_model)); +} diff --git a/shell/ev-sidebar.h b/shell/ev-sidebar.h index 4a9ac93..ea97f5f 100644 --- a/shell/ev-sidebar.h +++ b/shell/ev-sidebar.h @@ -51,6 +51,11 @@ struct _EvSidebarClass { GType ev_sidebar_get_type (void); GtkWidget *ev_sidebar_new (void); +void ev_sidebar_add_page (EvSidebar *ev_sidebar, + const gchar *page_id, + const gchar *title, + GtkWidget *main_widget); +void ev_sidebar_clear (EvSidebar *ev_sidebar); G_END_DECLS diff --git a/shell/ev-window.c b/shell/ev-window.c index 72fc627..8d0bcbf 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -28,6 +28,8 @@ #include "ev-window.h" #include "ev-sidebar.h" +#include "ev-sidebar-bookmarks.h" +#include "ev-sidebar-thumbnails.h" #include "ev-view.h" #include "eggfindbar.h" @@ -717,6 +719,7 @@ ev_window_init (EvWindow *ev_window) GtkWidget *scrolled_window; GtkWidget *menubar; GtkWidget *toolbar; + GtkWidget *sidebar_widget; ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window); @@ -775,10 +778,26 @@ ev_window_init (EvWindow *ev_window) gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned), ev_window->priv->sidebar); + /* Stub sidebar, for now */ + sidebar_widget = ev_sidebar_bookmarks_new (); + gtk_widget_show (sidebar_widget); + ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar), + "bookmarks", + _("Bookmarks"), + sidebar_widget); + + sidebar_widget = ev_sidebar_thumbnails_new (); + gtk_widget_show (sidebar_widget); + ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar), + "thumbnails", + _("Thumbnails"), + sidebar_widget); + scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolled_window); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned), scrolled_window); -- cgit v0.9.1