Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-sidebar.c File Reference
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "ev-sidebar.h"
#include "ev-sidebar-page.h"
+ Include dependency graph for ev-sidebar.c:

Go to the source code of this file.

Data Structures

struct  _EvSidebarPrivate
 

Macros

#define EV_SIDEBAR_GET_PRIVATE(object)   (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR, EvSidebarPrivate))
 

Enumerations

enum  { PROP_0, PROP_CURRENT_PAGE }
 
enum  {
  PAGE_COLUMN_TITLE, PAGE_COLUMN_MENU_ITEM, PAGE_COLUMN_MAIN_WIDGET, PAGE_COLUMN_NOTEBOOK_INDEX,
  PAGE_COLUMN_NUM_COLS
}
 

Functions

static void ev_sidebar_dispose (GObject *object)
 
static void ev_sidebar_select_page (EvSidebar *ev_sidebar, GtkTreeIter *iter)
 
void ev_sidebar_set_page (EvSidebar *ev_sidebar, GtkWidget *main_widget)
 
static void ev_sidebar_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 
static GtkWidget * ev_sidebar_get_current_page (EvSidebar *sidebar)
 
static void ev_sidebar_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 
static void ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class)
 
static void ev_sidebar_menu_position_under (GtkMenu *menu, int *x, int *y, gboolean *push_in, 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_deactivate_cb (GtkWidget *widget, gpointer user_data)
 
static void ev_sidebar_menu_detach_cb (GtkWidget *widget, GtkMenu *menu)
 
static void ev_sidebar_menu_item_activate_cb (GtkWidget *widget, gpointer user_data)
 
static void ev_sidebar_init (EvSidebar *ev_sidebar)
 
GtkWidget * ev_sidebar_new (void)
 
void ev_sidebar_add_page (EvSidebar *ev_sidebar, GtkWidget *main_widget)
 
static gboolean ev_sidebar_current_page_support_document (EvSidebar *sidebar, EvDocument *document)
 
static void ev_sidebar_document_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvSidebar *sidebar)
 
void ev_sidebar_set_model (EvSidebar *sidebar, EvDocumentModel *model)
 

Macro Definition Documentation

#define EV_SIDEBAR_GET_PRIVATE (   object)    (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR, EvSidebarPrivate))

Definition at line 63 of file ev-sidebar.c.

Enumeration Type Documentation

anonymous enum
Enumerator
PROP_0 
PROP_CURRENT_PAGE 

Definition at line 35 of file ev-sidebar.c.

36 {
37  PROP_0,
39 };
anonymous enum
Enumerator
PAGE_COLUMN_TITLE 
PAGE_COLUMN_MENU_ITEM 
PAGE_COLUMN_MAIN_WIDGET 
PAGE_COLUMN_NOTEBOOK_INDEX 
PAGE_COLUMN_NUM_COLS 

Definition at line 41 of file ev-sidebar.c.

Function Documentation

void ev_sidebar_add_page ( EvSidebar ev_sidebar,
GtkWidget *  main_widget 
)

Definition at line 432 of file ev-sidebar.c.

434 {
435  GtkTreeIter iter;
436  GtkWidget *menu_item;
437  gchar *label_title;
438  const gchar *title;
439  int index;
440 
441  g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
442  g_return_if_fail (EV_IS_SIDEBAR_PAGE (main_widget));
443  g_return_if_fail (GTK_IS_WIDGET (main_widget));
444 
446  ev_sidebar->priv->model);
447  title = ev_sidebar_page_get_label (EV_SIDEBAR_PAGE (main_widget));
448 
449  index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
450  main_widget, NULL);
451 
452  menu_item = gtk_image_menu_item_new_with_label (title);
453  g_signal_connect (menu_item, "activate",
455  ev_sidebar);
456  gtk_widget_show (menu_item);
457  gtk_menu_shell_append (GTK_MENU_SHELL (ev_sidebar->priv->menu),
458  menu_item);
459 
460  /* Insert and move to end */
461  gtk_list_store_insert_with_values (GTK_LIST_STORE (ev_sidebar->priv->page_model),
462  &iter, 0,
463  PAGE_COLUMN_TITLE, title,
464  PAGE_COLUMN_MENU_ITEM, menu_item,
465  PAGE_COLUMN_MAIN_WIDGET, main_widget,
467  -1);
468  gtk_list_store_move_before(GTK_LIST_STORE(ev_sidebar->priv->page_model),
469  &iter, NULL);
470 
471 
472  /* Set the first item added as active */
473  gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
474  gtk_tree_model_get (ev_sidebar->priv->page_model,
475  &iter,
476  PAGE_COLUMN_TITLE, &label_title,
478  -1);
479 
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),
483  index);
484  g_free (label_title);
485 }

+ Here is the caller graph for this function:

static void ev_sidebar_class_init ( EvSidebarClass ev_sidebar_class)
static

Definition at line 176 of file ev-sidebar.c.

177 {
178  GObjectClass *g_object_class = G_OBJECT_CLASS (ev_sidebar_class);
179 
180  g_type_class_add_private (g_object_class, sizeof (EvSidebarPrivate));
181 
182  g_object_class->dispose = ev_sidebar_dispose;
183  g_object_class->get_property = ev_sidebar_get_property;
184  g_object_class->set_property = ev_sidebar_set_property;
185 
186  g_object_class_install_property (g_object_class,
188  g_param_spec_object ("current-page",
189  "Current page",
190  "The currently visible page",
191  GTK_TYPE_WIDGET,
192  G_PARAM_READWRITE |
193  G_PARAM_STATIC_STRINGS));
194 }
static void ev_sidebar_close_clicked_cb ( GtkWidget *  widget,
gpointer  user_data 
)
static

Definition at line 274 of file ev-sidebar.c.

276 {
277  EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
278 
279  gtk_widget_hide (GTK_WIDGET (ev_sidebar));
280 }

+ Here is the caller graph for this function:

static gboolean ev_sidebar_current_page_support_document ( EvSidebar sidebar,
EvDocument document 
)
static

Definition at line 488 of file ev-sidebar.c.

490 {
491  GtkWidget *current_page = ev_sidebar_get_current_page (sidebar);
492 
493  return ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (current_page), document);
494 }

+ Here is the caller graph for this function:

static void ev_sidebar_dispose ( GObject *  object)
static

Definition at line 67 of file ev-sidebar.c.

68 {
69  EvSidebar *ev_sidebar = EV_SIDEBAR (object);
70 
71  if (ev_sidebar->priv->menu) {
72  gtk_menu_detach (GTK_MENU (ev_sidebar->priv->menu));
73  ev_sidebar->priv->menu = NULL;
74  }
75 
76  if (ev_sidebar->priv->page_model) {
77  g_object_unref (ev_sidebar->priv->page_model);
78  ev_sidebar->priv->page_model = NULL;
79  }
80 
81 
82  G_OBJECT_CLASS (ev_sidebar_parent_class)->dispose (object);
83 }

+ Here is the caller graph for this function:

static void ev_sidebar_document_changed_cb ( EvDocumentModel model,
GParamSpec *  pspec,
EvSidebar sidebar 
)
static

Definition at line 498 of file ev-sidebar.c.

501 {
502  EvSidebarPrivate *priv = sidebar->priv;
503  EvDocument *document = ev_document_model_get_document (model);
504  GtkTreeIter iter;
505  gboolean valid;
506  GtkWidget *first_supported_page = NULL;
507 
508  for (valid = gtk_tree_model_get_iter_first (priv->page_model, &iter);
509  valid;
510  valid = gtk_tree_model_iter_next (priv->page_model, &iter)) {
511  GtkWidget *widget;
512  GtkWidget *menu_widget;
513 
514  gtk_tree_model_get (priv->page_model, &iter,
515  PAGE_COLUMN_MAIN_WIDGET, &widget,
516  PAGE_COLUMN_MENU_ITEM, &menu_widget,
517  -1);
518 
519  if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (widget), document)) {
520  gtk_widget_set_sensitive (menu_widget, TRUE);
521  if (!first_supported_page)
522  first_supported_page = widget;
523  } else {
524  gtk_widget_set_sensitive (menu_widget, FALSE);
525  }
526  g_object_unref (widget);
527  g_object_unref (menu_widget);
528  }
529 
530  if (first_supported_page != NULL) {
531  if (!ev_sidebar_current_page_support_document (sidebar, document)) {
532  ev_sidebar_set_page (sidebar, first_supported_page);
533  }
534  gtk_widget_set_sensitive (GTK_WIDGET (sidebar->priv->notebook), TRUE);
535  gtk_widget_set_sensitive (GTK_WIDGET (sidebar->priv->select_button), TRUE);
536  } else {
537  gtk_widget_hide (GTK_WIDGET (sidebar));
538  }
539 }

+ Here is the caller graph for this function:

static GtkWidget* ev_sidebar_get_current_page ( EvSidebar sidebar)
static

Definition at line 149 of file ev-sidebar.c.

150 {
151  GtkNotebook *notebook = GTK_NOTEBOOK (sidebar->priv->notebook);
152 
153  return gtk_notebook_get_nth_page
154  (notebook, gtk_notebook_get_current_page (notebook));
155 }

+ Here is the caller graph for this function:

static void ev_sidebar_get_property ( GObject *  object,
guint  prop_id,
GValue *  value,
GParamSpec *  pspec 
)
static

Definition at line 158 of file ev-sidebar.c.

162 {
163  EvSidebar *sidebar = EV_SIDEBAR (object);
164 
165  switch (prop_id)
166  {
167  case PROP_CURRENT_PAGE:
168  g_value_set_object (value, ev_sidebar_get_current_page (sidebar));
169  break;
170  default:
171  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172  }
173 }

+ Here is the caller graph for this function:

static void ev_sidebar_init ( EvSidebar ev_sidebar)
static

Definition at line 332 of file ev-sidebar.c.

333 {
334  GtkWidget *hbox;
335  GtkWidget *close_button;
336  GtkWidget *select_hbox;
337  GtkWidget *separator;
338  GtkWidget *arrow;
339 
340  ev_sidebar->priv = EV_SIDEBAR_GET_PRIVATE (ev_sidebar);
341 
342  /* data model */
343  ev_sidebar->priv->page_model = (GtkTreeModel *)
344  gtk_list_store_new (PAGE_COLUMN_NUM_COLS,
345  G_TYPE_STRING,
346  GTK_TYPE_WIDGET,
347  GTK_TYPE_WIDGET,
348  G_TYPE_INT);
349 
350  /* top option menu */
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);
356 
357  /* separator */
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);
361 
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",
366  ev_sidebar);
367  g_signal_connect (ev_sidebar->priv->select_button, "key_press_event",
369  ev_sidebar);
370 
371  select_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
372 
373  ev_sidebar->priv->label = gtk_label_new ("");
374  gtk_box_pack_start (GTK_BOX (select_hbox),
375  ev_sidebar->priv->label,
376  FALSE, FALSE, 0);
377  gtk_widget_show (ev_sidebar->priv->label);
378 
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);
382 
383  gtk_container_add (GTK_CONTAINER (ev_sidebar->priv->select_button), select_hbox);
384  gtk_widget_show (select_hbox);
385 
386  gtk_box_set_center_widget (GTK_BOX (hbox), ev_sidebar->priv->select_button);
387  gtk_widget_show (ev_sidebar->priv->select_button);
388 
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",
392  G_CALLBACK (ev_sidebar_close_clicked_cb),
393  ev_sidebar);
394  gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
395  gtk_widget_show (close_button);
396 
397  ev_sidebar->priv->menu = gtk_menu_new ();
398  g_signal_connect (ev_sidebar->priv->menu, "deactivate",
399  G_CALLBACK (ev_sidebar_menu_deactivate_cb),
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);
405 
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,
410  TRUE, TRUE, 0);
411  gtk_widget_show (ev_sidebar->priv->notebook);
412 
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);
415 }
static void ev_sidebar_menu_deactivate_cb ( GtkWidget *  widget,
gpointer  user_data 
)
static

Definition at line 283 of file ev-sidebar.c.

285 {
286  GtkWidget *menu_button;
287 
288  menu_button = GTK_WIDGET (user_data);
289 
290  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button), FALSE);
291 }

+ Here is the caller graph for this function:

static void ev_sidebar_menu_detach_cb ( GtkWidget *  widget,
GtkMenu *  menu 
)
static

Definition at line 294 of file ev-sidebar.c.

296 {
297  EvSidebar *ev_sidebar = EV_SIDEBAR (widget);
298 
299  ev_sidebar->priv->menu = NULL;
300 }

+ Here is the caller graph for this function:

static void ev_sidebar_menu_item_activate_cb ( GtkWidget *  widget,
gpointer  user_data 
)
static

Definition at line 303 of file ev-sidebar.c.

305 {
306  EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
307  GtkTreeIter iter;
308  GtkWidget *menu_item, *item;
309  gboolean valid;
310 
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);
313 
314  while (valid) {
315  gtk_tree_model_get (ev_sidebar->priv->page_model, &iter,
316  PAGE_COLUMN_MENU_ITEM, &item,
317  -1);
318 
319  if (item == menu_item) {
320  ev_sidebar_select_page (ev_sidebar, &iter);
321  valid = FALSE;
322  } else {
323  valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter);
324  }
325  g_object_unref (item);
326  }
327 
328  g_object_notify (G_OBJECT (ev_sidebar), "current-page");
329 }

+ Here is the caller graph for this function:

static void ev_sidebar_menu_position_under ( GtkMenu *  menu,
int *  x,
int *  y,
gboolean *  push_in,
gpointer  user_data 
)
static

Definition at line 197 of file ev-sidebar.c.

202 {
203  GtkWidget *widget;
204  GtkAllocation allocation;
205 
206  g_return_if_fail (GTK_IS_BUTTON (user_data));
207  g_return_if_fail (!gtk_widget_get_has_window (GTK_WIDGET (user_data)));
208 
209  widget = GTK_WIDGET (user_data);
210 
211  gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
212  gtk_widget_get_allocation (widget, &allocation);
213 
214  *x += allocation.x;
215  *y += allocation.y + allocation.height;
216 
217  *push_in = FALSE;
218 }

+ Here is the caller graph for this function:

GtkWidget* ev_sidebar_new ( void  )

Definition at line 420 of file ev-sidebar.c.

421 {
422  GtkWidget *ev_sidebar;
423 
424  ev_sidebar = g_object_new (EV_TYPE_SIDEBAR,
425  "orientation", GTK_ORIENTATION_VERTICAL,
426  NULL);
427 
428  return ev_sidebar;
429 }

+ Here is the caller graph for this function:

static gboolean ev_sidebar_select_button_key_press_cb ( GtkWidget *  widget,
GdkEventKey *  event,
gpointer  user_data 
)
static

Definition at line 253 of file ev-sidebar.c.

256 {
257  EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
258 
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),
265  NULL, NULL, ev_sidebar_menu_position_under, widget,
266  1, event->time);
267  return TRUE;
268  }
269 
270  return FALSE;
271 }

+ Here is the caller graph for this function:

static gboolean ev_sidebar_select_button_press_cb ( GtkWidget *  widget,
GdkEventButton *  event,
gpointer  user_data 
)
static

Definition at line 221 of file ev-sidebar.c.

224 {
225  EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
226 
227  if (event->button == 1) {
228  GtkRequisition requisition;
229  GtkAllocation allocation;
230  gint width;
231 
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);
238 
239  gtk_widget_grab_focus (widget);
240 
241  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
242  gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
243  NULL, NULL, ev_sidebar_menu_position_under, widget,
244  event->button, event->time);
245 
246  return TRUE;
247  }
248 
249  return FALSE;
250 }

+ Here is the caller graph for this function:

static void ev_sidebar_select_page ( EvSidebar ev_sidebar,
GtkTreeIter *  iter 
)
static

Definition at line 86 of file ev-sidebar.c.

87 {
88  char *title;
89  int index;
90 
91  gtk_tree_model_get (ev_sidebar->priv->page_model, iter,
92  PAGE_COLUMN_TITLE, &title,
94  -1);
95 
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);
98 
99  g_free (title);
100 }

+ Here is the caller graph for this function:

void ev_sidebar_set_model ( EvSidebar sidebar,
EvDocumentModel model 
)

Definition at line 542 of file ev-sidebar.c.

544 {
545  g_return_if_fail (EV_IS_SIDEBAR (sidebar));
546  g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
547 
548  if (model == sidebar->priv->model)
549  return;
550 
551  sidebar->priv->model = model;
552  g_signal_connect (model, "notify::document",
553  G_CALLBACK (ev_sidebar_document_changed_cb),
554  sidebar);
555 }

+ Here is the caller graph for this function:

void ev_sidebar_set_page ( EvSidebar ev_sidebar,
GtkWidget *  main_widget 
)

Definition at line 103 of file ev-sidebar.c.

105 {
106  GtkTreeIter iter;
107  gboolean valid;
108 
109  valid = gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
110 
111  while (valid) {
112  GtkWidget *widget;
113 
114  gtk_tree_model_get (ev_sidebar->priv->page_model, &iter,
115  PAGE_COLUMN_MAIN_WIDGET, &widget,
116  -1);
117 
118  if (widget == main_widget) {
119  ev_sidebar_select_page (ev_sidebar, &iter);
120  valid = FALSE;
121  } else {
122  valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter);
123  }
124  g_object_unref (widget);
125  }
126 
127  g_object_notify (G_OBJECT (ev_sidebar), "current-page");
128 }

+ Here is the caller graph for this function:

static void ev_sidebar_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
)
static

Definition at line 131 of file ev-sidebar.c.

135 {
136  EvSidebar *sidebar = EV_SIDEBAR (object);
137 
138  switch (prop_id)
139  {
140  case PROP_CURRENT_PAGE:
141  ev_sidebar_set_page (sidebar, g_value_get_object (value));
142  break;
143  default:
144  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145  }
146 }

+ Here is the caller graph for this function: