Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evince/ChangeLog,v
retrieving revision 1.193
diff -u -u -r1.193 ChangeLog
--- ChangeLog	17 Feb 2005 14:41:25 -0000	1.193
+++ ChangeLog	17 Feb 2005 19:10:42 -0000
@@ -1,3 +1,8 @@
+2005-02-17  Carlos Garcia Campos <carlosgc@gnome.org> 
+
+	* shell/ev-sidebar.[ch], shell/ev-window.c: Improved sidebar widget.
+	Fixes #166683
+
 2005-02-17  Alexander Shopov  <ash@contact.bg>
 
 	* configure.in (ALL_LINGUAS): Added "bg" (Bulgarian)
Index: shell/ev-sidebar.c
===================================================================
RCS file: /cvs/gnome/evince/shell/ev-sidebar.c,v
retrieving revision 1.7
diff -u -u -r1.7 ev-sidebar.c
--- shell/ev-sidebar.c	10 Jan 2005 19:08:15 -0000	1.7
+++ shell/ev-sidebar.c	17 Feb 2005 19:10:42 -0000
@@ -26,6 +26,7 @@
 
 #include <string.h>
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 
 #include "ev-sidebar.h"
 #include "ev-document-thumbnails.h"
@@ -44,20 +45,48 @@
 {
 	PAGE_COLUMN_ID,
 	PAGE_COLUMN_TITLE,
+	PAGE_COLUMN_MENU_ITEM,
 	PAGE_COLUMN_MAIN_WIDGET,
 	PAGE_COLUMN_NOTEBOOK_INDEX,
 	PAGE_COLUMN_NUM_COLS
 };
 
 struct _EvSidebarPrivate {
-	GtkWidget *option_menu;
 	GtkWidget *notebook;
+	GtkWidget *menu;
+	GtkWidget *frame;
+	GtkWidget *hbox;
+	GtkWidget *label;
+	   
 
 	GtkTreeModel *page_model;
 };
 
-static void ev_sidebar_omenu_changed_cb (GtkComboBox *combo_box,
-					 gpointer     user_data);
+static gboolean ev_sidebar_select_button_press_cb     (GtkWidget *widget,
+													   GdkEventButton *event,
+													   gpointer user_data);
+static gboolean ev_sidebar_select_button_key_press_cb (GtkWidget *widget,
+													   GdkEventKey *event,
+													   gpointer user_data);
+static void ev_sidebar_close_clicked_cb               (GtkWidget *widget,
+													   gpointer user_data);
+static void ev_sidebar_menu_item_activate_cb          (GtkWidget *widget,
+													   gpointer user_data);
+static void ev_sidebar_menu_deactivate_cb             (GtkWidget *widget,
+													   gpointer user_data);
+static void ev_sidebar_menu_detach_cb                 (GtkWidget *widget,
+													   GtkMenu *menu);
+
+static void ev_sidebar_destroy                        (GtkObject *object);
+static void ev_sidebar_size_allocate                  (GtkWidget *widget,
+													   GtkAllocation *allocation);
+
+enum {
+	CLOSE_REQUESTED,
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE (EvSidebar, ev_sidebar, GTK_TYPE_VBOX)
 
@@ -68,18 +97,38 @@
 ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class)
 {
 	GObjectClass *g_object_class;
+	GtkWidgetClass *widget_class;
+	GtkObjectClass *gtk_object_klass;
 
 	g_object_class = G_OBJECT_CLASS (ev_sidebar_class);
+	widget_class = GTK_WIDGET_CLASS (ev_sidebar_class);
+	gtk_object_klass = GTK_OBJECT_CLASS (ev_sidebar_class);
 
 	g_type_class_add_private (g_object_class, sizeof (EvSidebarPrivate));
 
+	widget_class->size_allocate = ev_sidebar_size_allocate;
+	gtk_object_klass->destroy = ev_sidebar_destroy;
+
+	signals[CLOSE_REQUESTED] = g_signal_new
+		("close_requested",
+		 G_TYPE_FROM_CLASS (ev_sidebar_class),
+		 G_SIGNAL_RUN_LAST,
+		 G_STRUCT_OFFSET (EvSidebarClass, close_requested),
+		 NULL, NULL,
+		 g_cclosure_marshal_VOID__VOID,
+		 G_TYPE_NONE, 0);
 }
 
 static void
 ev_sidebar_init (EvSidebar *ev_sidebar)
 {
+	GtkWidget *frame;
 	GtkWidget *hbox;
-	GtkCellRenderer *renderer;
+	GtkWidget *close_button;
+	GtkWidget *select_button;
+	GtkWidget *select_hbox;
+	GtkWidget *arrow;
+	GtkWidget *image;
 	
 	ev_sidebar->priv = EV_SIDEBAR_GET_PRIVATE (ev_sidebar);
 	gtk_box_set_spacing (GTK_BOX (ev_sidebar), 6);
@@ -89,54 +138,246 @@
 		gtk_list_store_new (PAGE_COLUMN_NUM_COLS,
 				    G_TYPE_STRING,
 				    G_TYPE_STRING,
+					GTK_TYPE_WIDGET,
 				    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);
+	frame = gtk_frame_new (NULL);
+	ev_sidebar->priv->frame = frame;
+	gtk_widget_show (frame);
+	gtk_box_pack_start (GTK_BOX (ev_sidebar), frame, FALSE, FALSE, 0);
+	
+	hbox = gtk_hbox_new (FALSE, 0);
+	ev_sidebar->priv->hbox = hbox;
+	gtk_widget_show (hbox);
+	gtk_container_add (GTK_CONTAINER (frame), hbox);
+	
+	select_button = gtk_toggle_button_new ();
+	gtk_button_set_relief (GTK_BUTTON (select_button), GTK_RELIEF_NONE);
+	gtk_widget_show (select_button);
+
+	g_signal_connect (select_button, "button_press_event",
+					  G_CALLBACK (ev_sidebar_select_button_press_cb),
+					  ev_sidebar);
+	g_signal_connect (select_button, "key_press_event",
+					  G_CALLBACK (ev_sidebar_select_button_key_press_cb),
+					  ev_sidebar);
+	
+	select_hbox = gtk_hbox_new (FALSE, 0);
+	gtk_widget_show (select_hbox);
+
+	ev_sidebar->priv->label = gtk_label_new ("");
+
+	gtk_widget_show (ev_sidebar->priv->label);
+	gtk_box_pack_start (GTK_BOX (select_hbox),
+						ev_sidebar->priv->label,
+						FALSE, FALSE, 0);
+
+	arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
+	gtk_widget_show (arrow);
+	gtk_box_pack_end (GTK_BOX (select_hbox), arrow, FALSE, FALSE, 0);
+
+	gtk_container_add (GTK_CONTAINER (select_button), select_hbox);
+	gtk_box_pack_start (GTK_BOX (hbox), select_button, FALSE, FALSE, 0);
+
+	close_button = gtk_button_new ();
+	gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+	g_signal_connect (close_button, "clicked",
+					  G_CALLBACK (ev_sidebar_close_clicked_cb),
+					  ev_sidebar);
+
+	gtk_widget_show (close_button);
+
+	image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
+									  GTK_ICON_SIZE_SMALL_TOOLBAR);
+	gtk_widget_show (image);
+
+	gtk_container_add (GTK_CONTAINER (close_button), image);
+
+	gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
+
+	ev_sidebar->priv->menu = gtk_menu_new ();
+	g_signal_connect (ev_sidebar->priv->menu, "deactivate",
+					  G_CALLBACK (ev_sidebar_menu_deactivate_cb),
+					  select_button);
+	gtk_menu_attach_to_widget (GTK_MENU (ev_sidebar->priv->menu),
+							   GTK_WIDGET (ev_sidebar),
+							   ev_sidebar_menu_detach_cb);
+
+	gtk_widget_show (ev_sidebar->priv->menu);
 
 	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 (GTK_WIDGET (ev_sidebar));
 }
 
 static void
-ev_sidebar_omenu_changed_cb (GtkComboBox *combo_box,
-			     gpointer     user_data)
+ev_sidebar_destroy (GtkObject *object)
+{
+	EvSidebar *ev_sidebar = EV_SIDEBAR (object);
+
+	if (ev_sidebar->priv->menu) {
+		gtk_menu_detach (GTK_MENU (ev_sidebar->priv->menu));
+		ev_sidebar->priv->menu = NULL;
+	}
+
+	(* GTK_OBJECT_CLASS (ev_sidebar_parent_class)->destroy) (object);
+}
+
+static void
+ev_sidebar_size_allocate (GtkWidget *widget,
+						  GtkAllocation *allocation)
+{
+	EvSidebar *ev_sidebar = EV_SIDEBAR (widget);
+	GtkWidget *frame;
+	GtkWidget *hbox;
+	GtkAllocation child_allocation;
+	GtkRequisition child_requisition;
+	gint width;
+
+	GTK_WIDGET_CLASS (ev_sidebar_parent_class)->size_allocate (widget, allocation);
+
+	frame = ev_sidebar->priv->frame;
+	hbox = ev_sidebar->priv->hbox;
+
+	gtk_widget_get_child_requisition (hbox, &child_requisition);
+	width = child_requisition.width;
+
+	child_allocation = frame->allocation;
+	child_allocation.width = MAX (width, frame->allocation.width);
+
+	gtk_widget_size_allocate (frame, &child_allocation);
+}
+
+static void
+ev_sidebar_menu_position_under (GtkMenu *menu,
+								int *x,
+								int *y,
+								gboolean *push_in,
+								gpointer user_data)
+{
+	GtkWidget *widget;
+
+	g_return_if_fail (GTK_IS_BUTTON (user_data));
+	g_return_if_fail (GTK_WIDGET_NO_WINDOW (user_data));
+
+	widget = GTK_WIDGET (user_data);
+
+	gdk_window_get_origin (widget->window, x, y);
+
+	*x += widget->allocation.x;
+	*y += widget->allocation.y + widget->allocation.height;
+
+	*push_in = FALSE;
+}
+
+static gboolean
+ev_sidebar_select_button_press_cb (GtkWidget *widget,
+								   GdkEventButton *event,
+								   gpointer user_data)
+{
+	EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
+
+	if ((event->type == GDK_BUTTON_PRESS) && event->button == 1) {
+		gtk_widget_grab_focus (widget);
+
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+		gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
+						NULL, NULL, ev_sidebar_menu_position_under, widget,
+						event->button, event->time);
+		
+		return TRUE;
+	}
+	
+	return FALSE;
+}
+
+static gboolean
+ev_sidebar_select_button_key_press_cb (GtkWidget *widget,
+									   GdkEventKey *event,
+									   gpointer user_data)
+{
+	EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
+
+	if (event->keyval == GDK_space ||
+		event->keyval == GDK_KP_Space ||
+		event->keyval == GDK_Return ||
+		event->keyval == GDK_KP_Enter) {
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+		gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
+						NULL, NULL, ev_sidebar_menu_position_under, widget,
+						1, event->time);
+		return TRUE;
+	}
+	
+	return FALSE;
+}
+
+static void
+ev_sidebar_close_clicked_cb (GtkWidget *widget,
+							 gpointer user_data)
+{
+	EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
+
+	g_signal_emit (ev_sidebar, signals[CLOSE_REQUESTED], 0);
+}
+
+static void
+ev_sidebar_menu_deactivate_cb (GtkWidget *widget,
+							   gpointer user_data)
+{
+	GtkWidget *menu_button;
+	
+	menu_button = GTK_WIDGET (user_data);
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button), FALSE);
+}
+
+static void
+ev_sidebar_menu_detach_cb (GtkWidget *widget,
+						   GtkMenu *menu)
+{
+	EvSidebar *ev_sidebar = EV_SIDEBAR (widget);
+
+	ev_sidebar->priv->menu = NULL;
+}
+
+static void
+ev_sidebar_menu_item_activate_cb (GtkWidget *widget,
+								  gpointer user_data)
 {
-	GtkTreeIter iter;
 	EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
+	GtkTreeIter iter;
+	GtkWidget *menu_item, *item;
+	gchar *title;
+	gboolean valid;
+	gint index;
 
-	if (gtk_combo_box_get_active_iter (combo_box, &iter)) {
-		gint index;
+	menu_item = gtk_menu_get_active (GTK_MENU (ev_sidebar->priv->menu));
+	valid = gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
 
+	while (valid) {
 		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);
-					       
+							&iter,
+							PAGE_COLUMN_TITLE, &title, 
+							PAGE_COLUMN_MENU_ITEM, &item,
+							PAGE_COLUMN_NOTEBOOK_INDEX, &index,
+							-1);
+		
+		if (item == menu_item) {
+			gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
+									 index);
+			gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), title);
+			
+			valid = FALSE;
+		} else {
+			valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter);
+		}
 	}
 }
 
@@ -159,6 +400,8 @@
 		     GtkWidget   *main_widget)
 {
 	GtkTreeIter iter;
+	GtkWidget *menu_item;
+	gchar *label_title;
 	int index;
 
 	g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
@@ -168,18 +411,36 @@
 
 	index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
 					  main_widget, NULL);
-					  
+
+	menu_item = gtk_image_menu_item_new_with_label (title);
+	g_signal_connect (menu_item, "activate",
+					  G_CALLBACK (ev_sidebar_menu_item_activate_cb),
+					  ev_sidebar);
+	gtk_widget_show (menu_item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (ev_sidebar->priv->menu),
+						   menu_item);
+	
 	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_MENU_ITEM, menu_item,
 					   PAGE_COLUMN_MAIN_WIDGET, main_widget,
 					   PAGE_COLUMN_NOTEBOOK_INDEX, index,
 					   -1);
 
 	/* Set the first item added as active */
-	if (gtk_combo_box_get_active (GTK_COMBO_BOX (ev_sidebar->priv->option_menu)))
-		gtk_combo_box_set_active (GTK_COMBO_BOX (ev_sidebar->priv->option_menu), 0);
+	gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
+	gtk_tree_model_get (ev_sidebar->priv->page_model,
+						&iter,
+						PAGE_COLUMN_TITLE, &label_title,
+					     PAGE_COLUMN_NOTEBOOK_INDEX, &index,
+						-1);
+	
+	gtk_menu_set_active (GTK_MENU (ev_sidebar->priv->menu), index);
+	gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), label_title);
+	gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
+							 index);
 }
 
 void
@@ -217,8 +478,6 @@
 			ev_sidebar_thumbnails_set_document (EV_SIDEBAR_THUMBNAILS (widget),
 							    document);
 	}
-	
-
 }
 
 void
Index: shell/ev-sidebar.h
===================================================================
RCS file: /cvs/gnome/evince/shell/ev-sidebar.h,v
retrieving revision 1.3
diff -u -u -r1.3 ev-sidebar.h
--- shell/ev-sidebar.h	22 Dec 2004 18:41:31 -0000	1.3
+++ shell/ev-sidebar.h	17 Feb 2005 19:10:42 -0000
@@ -48,6 +48,8 @@
 
 struct _EvSidebarClass {
 	GtkVBoxClass base_class;
+
+     void (*close_requested) (EvSidebar *ev_sidebar);
 };
 
 GType      ev_sidebar_get_type     (void);
Index: shell/ev-window.c
===================================================================
RCS file: /cvs/gnome/evince/shell/ev-window.c,v
retrieving revision 1.69
diff -u -u -r1.69 ev-window.c
--- shell/ev-window.c	16 Feb 2005 19:06:40 -0000	1.69
+++ shell/ev-window.c	17 Feb 2005 19:10:43 -0000
@@ -1588,6 +1588,17 @@
 }
 
 static void
+ev_window_sidebar_close_requested_cb (GtkWidget *widget, EvWindow *ev_window)
+{
+	GtkAction *action;
+
+	action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
+
+	ev_window_view_sidebar_cb (action, ev_window);
+}
+
+static void
 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
 {
 	GtkAction *action;
@@ -2160,6 +2171,9 @@
 			    TRUE, TRUE, 0);
 
 	ev_window->priv->sidebar = ev_sidebar_new ();
+	g_signal_connect (ev_window->priv->sidebar, "close_requested",
+			  G_CALLBACK (ev_window_sidebar_close_requested_cb),
+			  ev_window);
 	gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
 			ev_window->priv->sidebar);
 
