30 #include <gdk/gdkkeysyms.h>
63 #define EV_SIDEBAR_GET_PRIVATE(object) \
64 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR, EvSidebarPrivate))
71 if (ev_sidebar->priv->menu) {
72 gtk_menu_detach (GTK_MENU (ev_sidebar->priv->menu));
73 ev_sidebar->priv->menu = NULL;
76 if (ev_sidebar->priv->page_model) {
77 g_object_unref (ev_sidebar->priv->page_model);
78 ev_sidebar->priv->page_model = NULL;
82 G_OBJECT_CLASS (ev_sidebar_parent_class)->dispose (
object);
91 gtk_tree_model_get (ev_sidebar->priv->page_model, iter,
96 gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook), index);
97 gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), title);
104 GtkWidget *main_widget)
109 valid = gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
114 gtk_tree_model_get (ev_sidebar->priv->page_model, &iter,
118 if (widget == main_widget) {
122 valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter);
124 g_object_unref (widget);
127 g_object_notify (G_OBJECT (ev_sidebar),
"current-page");
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
151 GtkNotebook *notebook = GTK_NOTEBOOK (sidebar->priv->notebook);
153 return gtk_notebook_get_nth_page
154 (notebook, gtk_notebook_get_current_page (notebook));
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
178 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_sidebar_class);
186 g_object_class_install_property (g_object_class,
188 g_param_spec_object (
"current-page",
190 "The currently visible page",
193 G_PARAM_STATIC_STRINGS));
204 GtkAllocation allocation;
206 g_return_if_fail (GTK_IS_BUTTON (user_data));
207 g_return_if_fail (!gtk_widget_get_has_window (GTK_WIDGET (user_data)));
209 widget = GTK_WIDGET (user_data);
211 gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
212 gtk_widget_get_allocation (widget, &allocation);
215 *y += allocation.y + allocation.height;
222 GdkEventButton *event,
227 if (event->button == 1) {
228 GtkRequisition requisition;
229 GtkAllocation allocation;
232 gtk_widget_get_allocation (widget, &allocation);
233 width = allocation.width;
234 gtk_widget_set_size_request (ev_sidebar->priv->menu, -1, -1);
235 gtk_widget_get_preferred_size (ev_sidebar->priv->menu, &requisition, NULL);
236 gtk_widget_set_size_request (ev_sidebar->priv->menu,
237 MAX (width, requisition.width), -1);
239 gtk_widget_grab_focus (widget);
241 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
TRUE);
242 gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
244 event->button, event->time);
259 if (event->keyval == GDK_KEY_space ||
260 event->keyval == GDK_KEY_KP_Space ||
261 event->keyval == GDK_KEY_Return ||
262 event->keyval == GDK_KEY_KP_Enter) {
263 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
TRUE);
264 gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
279 gtk_widget_hide (GTK_WIDGET (ev_sidebar));
286 GtkWidget *menu_button;
288 menu_button = GTK_WIDGET (user_data);
290 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button),
FALSE);
299 ev_sidebar->priv->menu = NULL;
308 GtkWidget *menu_item, *item;
311 menu_item = gtk_menu_get_active (GTK_MENU (ev_sidebar->priv->menu));
312 valid = gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
315 gtk_tree_model_get (ev_sidebar->priv->page_model, &iter,
319 if (item == menu_item) {
323 valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter);
325 g_object_unref (item);
328 g_object_notify (G_OBJECT (ev_sidebar),
"current-page");
335 GtkWidget *close_button;
336 GtkWidget *select_hbox;
337 GtkWidget *separator;
343 ev_sidebar->priv->page_model = (GtkTreeModel *)
351 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
352 gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
353 ev_sidebar->priv->hbox = hbox;
354 gtk_box_pack_start (GTK_BOX (ev_sidebar), hbox,
FALSE,
FALSE, 0);
355 gtk_widget_show (hbox);
358 separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
359 gtk_box_pack_start (GTK_BOX (ev_sidebar), separator,
FALSE,
FALSE, 0);
360 gtk_widget_show (separator);
362 ev_sidebar->priv->select_button = gtk_toggle_button_new ();
363 gtk_button_set_relief (GTK_BUTTON (ev_sidebar->priv->select_button), GTK_RELIEF_NONE);
364 g_signal_connect (ev_sidebar->priv->select_button,
"button_press_event",
367 g_signal_connect (ev_sidebar->priv->select_button,
"key_press_event",
371 select_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
373 ev_sidebar->priv->label = gtk_label_new (
"");
374 gtk_box_pack_start (GTK_BOX (select_hbox),
375 ev_sidebar->priv->label,
377 gtk_widget_show (ev_sidebar->priv->label);
379 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
380 gtk_box_pack_end (GTK_BOX (select_hbox), arrow,
FALSE,
FALSE, 0);
381 gtk_widget_show (arrow);
383 gtk_container_add (GTK_CONTAINER (ev_sidebar->priv->select_button), select_hbox);
384 gtk_widget_show (select_hbox);
386 gtk_box_set_center_widget (GTK_BOX (hbox), ev_sidebar->priv->select_button);
387 gtk_widget_show (ev_sidebar->priv->select_button);
389 close_button = gtk_button_new_from_icon_name (
"window-close-symbolic", GTK_ICON_SIZE_BUTTON);
390 gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
391 g_signal_connect (close_button,
"clicked",
394 gtk_box_pack_end (GTK_BOX (hbox), close_button,
FALSE,
FALSE, 0);
395 gtk_widget_show (close_button);
397 ev_sidebar->priv->menu = gtk_menu_new ();
398 g_signal_connect (ev_sidebar->priv->menu,
"deactivate",
400 ev_sidebar->priv->select_button);
401 gtk_menu_attach_to_widget (GTK_MENU (ev_sidebar->priv->menu),
402 GTK_WIDGET (ev_sidebar),
404 gtk_widget_show (ev_sidebar->priv->menu);
406 ev_sidebar->priv->notebook = gtk_notebook_new ();
407 gtk_notebook_set_show_border (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
FALSE);
408 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
FALSE);
409 gtk_box_pack_start (GTK_BOX (ev_sidebar), ev_sidebar->priv->notebook,
411 gtk_widget_show (ev_sidebar->priv->notebook);
413 gtk_widget_set_sensitive (GTK_WIDGET (ev_sidebar->priv->notebook),
FALSE);
414 gtk_widget_set_sensitive (GTK_WIDGET (ev_sidebar->priv->select_button),
FALSE);
422 GtkWidget *ev_sidebar;
425 "orientation", GTK_ORIENTATION_VERTICAL,
433 GtkWidget *main_widget)
436 GtkWidget *menu_item;
443 g_return_if_fail (GTK_IS_WIDGET (main_widget));
446 ev_sidebar->priv->model);
449 index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
452 menu_item = gtk_image_menu_item_new_with_label (title);
453 g_signal_connect (menu_item,
"activate",
456 gtk_widget_show (menu_item);
457 gtk_menu_shell_append (GTK_MENU_SHELL (ev_sidebar->priv->menu),
461 gtk_list_store_insert_with_values (GTK_LIST_STORE (ev_sidebar->priv->page_model),
468 gtk_list_store_move_before(GTK_LIST_STORE(ev_sidebar->priv->page_model),
473 gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
474 gtk_tree_model_get (ev_sidebar->priv->page_model,
480 gtk_menu_set_active (GTK_MENU (ev_sidebar->priv->menu), index);
481 gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), label_title);
482 gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
484 g_free (label_title);
506 GtkWidget *first_supported_page = NULL;
508 for (valid = gtk_tree_model_get_iter_first (priv->
page_model, &iter);
510 valid = gtk_tree_model_iter_next (priv->
page_model, &iter)) {
512 GtkWidget *menu_widget;
520 gtk_widget_set_sensitive (menu_widget,
TRUE);
521 if (!first_supported_page)
522 first_supported_page = widget;
524 gtk_widget_set_sensitive (menu_widget,
FALSE);
526 g_object_unref (widget);
527 g_object_unref (menu_widget);
530 if (first_supported_page != NULL) {
534 gtk_widget_set_sensitive (GTK_WIDGET (sidebar->priv->notebook),
TRUE);
535 gtk_widget_set_sensitive (GTK_WIDGET (sidebar->priv->select_button),
TRUE);
537 gtk_widget_hide (GTK_WIDGET (sidebar));
548 if (model == sidebar->priv->model)
551 sidebar->priv->model = model;
552 g_signal_connect (model,
"notify::document",