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-previewer-window.c File Reference
#include <config.h>
#include <glib/gi18n.h>
#include <evince-view.h>
#include "ev-page-action.h"
#include "ev-previewer-window.h"
+ Include dependency graph for ev-previewer-window.c:

Go to the source code of this file.

Data Structures

struct  _EvPreviewerWindow
 
struct  _EvPreviewerWindowClass
 

Macros

#define MIN_SCALE   0.05409
 
#define MAX_SCALE   4.0
 

Enumerations

enum  { PROP_0, PROP_MODEL }
 

Functions

static gdouble get_screen_dpi (EvPreviewerWindow *window)
 
static void ev_previewer_window_close (GtkAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_previous_page (GtkAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_next_page (GtkAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_zoom_in (GtkAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_zoom_out (GtkAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_zoom_fit_page (GtkToggleAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_zoom_fit_width (GtkToggleAction *action, EvPreviewerWindow *window)
 
static void ev_previewer_window_action_page_activated (GtkAction *action, EvLink *link, EvPreviewerWindow *window)
 
static void ev_previewer_window_focus_page_selector (GtkAction *action, EvPreviewerWindow *window)
 
static gboolean view_focus_changed (GtkWidget *widget, GdkEventFocus *event, EvPreviewerWindow *window)
 
static void model_page_changed (EvDocumentModel *model, gint old_page, gint new_page, EvPreviewerWindow *window)
 
static void view_sizing_mode_changed (EvDocumentModel *model, GParamSpec *pspec, EvPreviewerWindow *window)
 
static void ev_previewer_window_set_document (EvPreviewerWindow *window, GParamSpec *pspec, EvDocumentModel *model)
 
static void ev_previewer_window_connect_action_accelerators (EvPreviewerWindow *window)
 
static void ev_previewer_window_dispose (GObject *object)
 
static void ev_previewer_window_init (EvPreviewerWindow *window)
 
static void ev_previewer_window_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 
static gboolean _gtk_css_provider_load_from_resource (GtkCssProvider *provider, const char *resource_path, GError **error)
 
static GObject * ev_previewer_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params)
 
static void ev_previewer_window_class_init (EvPreviewerWindowClass *klass)
 
EvPreviewerWindowev_previewer_window_new (EvDocumentModel *model)
 
void ev_previewer_window_set_print_settings (EvPreviewerWindow *window, const gchar *print_settings)
 
void ev_previewer_window_set_source_file (EvPreviewerWindow *window, const gchar *source_file)
 

Variables

static const GtkActionEntry action_entries []
 
static const GtkActionEntry accel_entries []
 
static const GtkToggleActionEntry toggle_action_entries []
 

Macro Definition Documentation

#define MAX_SCALE   4.0

Definition at line 66 of file ev-previewer-window.c.

#define MIN_SCALE   0.05409

Definition at line 65 of file ev-previewer-window.c.

Enumeration Type Documentation

anonymous enum
Enumerator
PROP_0 
PROP_MODEL 

Definition at line 60 of file ev-previewer-window.c.

60  {
61  PROP_0,
63 };

Function Documentation

static gboolean _gtk_css_provider_load_from_resource ( GtkCssProvider *  provider,
const char *  resource_path,
GError **  error 
)
static

Definition at line 493 of file ev-previewer-window.c.

496 {
497  GBytes *data;
498  gboolean retval;
499 
500  data = g_resources_lookup_data (resource_path, 0, error);
501  if (!data)
502  return FALSE;
503 
504  retval = gtk_css_provider_load_from_data (provider,
505  g_bytes_get_data (data, NULL),
506  g_bytes_get_size (data),
507  error);
508  g_bytes_unref (data);
509 
510  return retval;
511 }

+ Here is the caller graph for this function:

static void ev_previewer_window_action_page_activated ( GtkAction *  action,
EvLink link,
EvPreviewerWindow window 
)
static

Definition at line 155 of file ev-previewer-window.c.

158 {
159  ev_view_handle_link (window->view, link);
160  gtk_widget_grab_focus (GTK_WIDGET (window->view));
161 }

+ Here is the caller graph for this function:

static void ev_previewer_window_class_init ( EvPreviewerWindowClass klass)
static

Definition at line 636 of file ev-previewer-window.c.

637 {
638  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
639 
640  gobject_class->constructor = ev_previewer_window_constructor;
641  gobject_class->set_property = ev_previewer_window_set_property;
642  gobject_class->dispose = ev_previewer_window_dispose;
643 
644  g_object_class_install_property (gobject_class,
645  PROP_MODEL,
646  g_param_spec_object ("model",
647  "Model",
648  "The document model",
650  G_PARAM_WRITABLE |
651  G_PARAM_CONSTRUCT_ONLY));
652 }
static void ev_previewer_window_close ( GtkAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 100 of file ev-previewer-window.c.

102 {
103  gtk_widget_destroy (GTK_WIDGET (window));
104 }
static void ev_previewer_window_connect_action_accelerators ( EvPreviewerWindow window)
static

Definition at line 398 of file ev-previewer-window.c.

399 {
400  GList *actions;
401 
402  gtk_ui_manager_ensure_update (window->ui_manager);
403 
404  actions = gtk_action_group_list_actions (window->action_group);
405  g_list_foreach (actions, (GFunc)gtk_action_connect_accelerator, NULL);
406  g_list_free (actions);
407 }

+ Here is the caller graph for this function:

static GObject* ev_previewer_window_constructor ( GType  type,
guint  n_construct_properties,
GObjectConstructParam *  construct_params 
)
static

Definition at line 514 of file ev-previewer-window.c.

517 {
518  GObject *object;
520  GtkWidget *vbox;
521  GtkWidget *toolbar;
522  GtkAction *action;
523  GError *error = NULL;
524  gdouble dpi;
525  GtkCssProvider *css_provider;
526 
527  object = G_OBJECT_CLASS (ev_previewer_window_parent_class)->constructor (type,
528  n_construct_properties,
529  construct_params);
530  window = EV_PREVIEWER_WINDOW (object);
531 
532  dpi = get_screen_dpi (window);
533  ev_document_model_set_min_scale (window->model, MIN_SCALE * dpi / 72.0);
534  ev_document_model_set_max_scale (window->model, MAX_SCALE * dpi / 72.0);
536  g_signal_connect_swapped (window->model, "notify::document",
538  window);
539 
540  window->action_group = gtk_action_group_new ("PreviewerActions");
541  gtk_action_group_set_translation_domain (window->action_group, NULL);
542  gtk_action_group_add_actions (window->action_group, action_entries,
543  G_N_ELEMENTS (action_entries),
544  window);
545  gtk_action_group_add_toggle_actions (window->action_group, toggle_action_entries,
546  G_N_ELEMENTS (toggle_action_entries),
547  window);
548  gtk_action_group_set_sensitive (window->action_group, FALSE);
549 
550  action = g_object_new (EV_TYPE_PAGE_ACTION,
551  "name", "PageSelector",
552  "label", _("Page"),
553  "tooltip", _("Select Page"),
554  "icon_name", "text-x-generic",
555  "visible_overflown", FALSE,
556  NULL);
557  ev_page_action_set_model (EV_PAGE_ACTION (action), window->model);
558  g_signal_connect (action, "activate_link",
560  window);
561  gtk_action_group_add_action (window->action_group, action);
562  g_object_unref (action);
563 
564  window->accels_group = gtk_action_group_new ("PreviewerAccelerators");
565  gtk_action_group_add_actions (window->accels_group, accel_entries,
566  G_N_ELEMENTS (accel_entries),
567  window);
568  gtk_action_group_set_sensitive (window->accels_group, FALSE);
569 
570  css_provider = gtk_css_provider_new ();
572  "/org/gnome/evince/previewer/ui/evince-previewer.css",
573  &error);
574  g_assert_no_error (error);
575  gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)),
576  GTK_STYLE_PROVIDER (css_provider),
577  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
578  g_object_unref (css_provider);
579 
580  window->ui_manager = gtk_ui_manager_new ();
581  gtk_ui_manager_insert_action_group (window->ui_manager,
582  window->action_group, 0);
583  gtk_ui_manager_insert_action_group (window->ui_manager,
584  window->accels_group, 1);
585  gtk_window_add_accel_group (GTK_WINDOW (window),
586  gtk_ui_manager_get_accel_group (window->ui_manager));
587 
588  gtk_ui_manager_add_ui_from_resource (window->ui_manager, "/org/gnome/evince/previewer/ui/previewer.xml", &error);
589  g_assert_no_error (error);
590 
591  /* GTKUIManager connects actions accels only for menu items,
592  * but not for tool items. See bug #612972.
593  */
595 
596  view_sizing_mode_changed (window->model, NULL, window);
597 
598  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
599 
600  toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/PreviewToolbar");
601  gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
602  GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
603  gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
604  gtk_widget_show (toolbar);
605 
606  window->swindow = gtk_scrolled_window_new (NULL, NULL);
607 
608  window->view = EV_VIEW (ev_view_new ());
609  g_signal_connect_object (window->view, "focus_in_event",
610  G_CALLBACK (view_focus_changed),
611  window, 0);
612  g_signal_connect_object (window->view, "focus_out_event",
613  G_CALLBACK (view_focus_changed),
614  window, 0);
615  ev_view_set_model (window->view, window->model);
617 
618  g_signal_connect_object (window->model, "page-changed",
619  G_CALLBACK (model_page_changed),
620  window, 0);
621 
622  gtk_container_add (GTK_CONTAINER (window->swindow), GTK_WIDGET (window->view));
623  gtk_widget_show (GTK_WIDGET (window->view));
624 
625  gtk_box_pack_start (GTK_BOX (vbox), window->swindow, TRUE, TRUE, 0);
626  gtk_widget_show (window->swindow);
627 
628  gtk_container_add (GTK_CONTAINER (window), vbox);
629  gtk_widget_show (vbox);
630 
631  return object;
632 }

+ Here is the caller graph for this function:

static void ev_previewer_window_dispose ( GObject *  object)
static

Definition at line 410 of file ev-previewer-window.c.

411 {
413 
414  if (window->model) {
415  g_object_unref (window->model);
416  window->model = NULL;
417  }
418 
419  if (window->document) {
420  g_object_unref (window->document);
421  window->document = NULL;
422  }
423 
424  if (window->action_group) {
425  g_object_unref (window->action_group);
426  window->action_group = NULL;
427  }
428 
429  if (window->accels_group) {
430  g_object_unref (window->accels_group);
431  window->accels_group = NULL;
432  }
433 
434  if (window->ui_manager) {
435  g_object_unref (window->ui_manager);
436  window->ui_manager = NULL;
437  }
438 
439  if (window->print_settings) {
440  g_object_unref (window->print_settings);
441  window->print_settings = NULL;
442  }
443 
444  if (window->print_page_setup) {
445  g_object_unref (window->print_page_setup);
446  window->print_page_setup = NULL;
447  }
448 
449 #if GTKUNIXPRINT_ENABLED
450  if (window->printer) {
451  g_object_unref (window->printer);
452  window->printer = NULL;
453  }
454 #endif
455 
456  if (window->print_job_title) {
457  g_free (window->print_job_title);
458  window->print_job_title = NULL;
459  }
460 
461  if (window->source_file) {
462  g_free (window->source_file);
463  window->source_file = NULL;
464  }
465 
466  G_OBJECT_CLASS (ev_previewer_window_parent_class)->dispose (object);
467 }

+ Here is the caller graph for this function:

static void ev_previewer_window_focus_page_selector ( GtkAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 164 of file ev-previewer-window.c.

166 {
167  GtkAction *page_action;
168 
169  page_action = gtk_action_group_get_action (window->action_group,
170  "PageSelector");
172 }
static void ev_previewer_window_init ( EvPreviewerWindow window)
static

Definition at line 470 of file ev-previewer-window.c.

471 {
472  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
473 }
EvPreviewerWindow* ev_previewer_window_new ( EvDocumentModel model)

Definition at line 656 of file ev-previewer-window.c.

657 {
658  return g_object_new (EV_TYPE_PREVIEWER_WINDOW,
659  "application", g_application_get_default (),
660  "model", model,
661  NULL);
662 }

+ Here is the caller graph for this function:

static void ev_previewer_window_next_page ( GtkAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 114 of file ev-previewer-window.c.

116 {
117  ev_view_next_page (window->view);
118 }
static void ev_previewer_window_previous_page ( GtkAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 107 of file ev-previewer-window.c.

109 {
110  ev_view_previous_page (window->view);
111 }
static void ev_previewer_window_set_document ( EvPreviewerWindow window,
GParamSpec *  pspec,
EvDocumentModel model 
)
static

Definition at line 382 of file ev-previewer-window.c.

385 {
386  EvDocument *document = ev_document_model_get_document (model);
387 
388  window->document = g_object_ref (document);
389 
390  g_signal_connect (model, "notify::sizing-mode",
391  G_CALLBACK (view_sizing_mode_changed),
392  window);
393  gtk_action_group_set_sensitive (window->action_group, TRUE);
394  gtk_action_group_set_sensitive (window->accels_group, TRUE);
395 }

+ Here is the caller graph for this function:

void ev_previewer_window_set_print_settings ( EvPreviewerWindow window,
const gchar *  print_settings 
)

Definition at line 665 of file ev-previewer-window.c.

667 {
668  if (window->print_settings)
669  g_object_unref (window->print_settings);
670  if (window->print_page_setup)
671  g_object_unref (window->print_page_setup);
672  if (window->print_job_title)
673  g_free (window->print_job_title);
674 
675  if (print_settings && g_file_test (print_settings, G_FILE_TEST_IS_REGULAR)) {
676  GKeyFile *key_file;
677  GError *error = NULL;
678 
679  key_file = g_key_file_new ();
680  g_key_file_load_from_file (key_file,
682  G_KEY_FILE_KEEP_COMMENTS |
683  G_KEY_FILE_KEEP_TRANSLATIONS,
684  &error);
685  if (!error) {
686  GtkPrintSettings *psettings;
687  GtkPageSetup *psetup;
688  gchar *job_name;
689 
690  psettings = gtk_print_settings_new_from_key_file (key_file,
691  "Print Settings",
692  NULL);
693  window->print_settings = psettings ? psettings : gtk_print_settings_new ();
694 
695  psetup = gtk_page_setup_new_from_key_file (key_file,
696  "Page Setup",
697  NULL);
698  window->print_page_setup = psetup ? psetup : gtk_page_setup_new ();
699 
700  job_name = g_key_file_get_string (key_file,
701  "Print Job", "title",
702  NULL);
703  if (job_name) {
704  window->print_job_title = job_name;
705  gtk_window_set_title (GTK_WINDOW (window), job_name);
706  }
707  } else {
708  window->print_settings = gtk_print_settings_new ();
709  window->print_page_setup = gtk_page_setup_new ();
710  g_error_free (error);
711  }
712 
713  g_key_file_free (key_file);
714  } else {
715  window->print_settings = gtk_print_settings_new ();
716  window->print_page_setup = gtk_page_setup_new ();
717  }
718 }

+ Here is the caller graph for this function:

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

Definition at line 476 of file ev-previewer-window.c.

480 {
482 
483  switch (prop_id) {
484  case PROP_MODEL:
485  window->model = g_value_dup_object (value);
486  break;
487  default:
488  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
489  }
490 }

+ Here is the caller graph for this function:

void ev_previewer_window_set_source_file ( EvPreviewerWindow window,
const gchar *  source_file 
)

Definition at line 721 of file ev-previewer-window.c.

723 {
724  if (window->source_file)
725  g_free (window->source_file);
726  window->source_file = g_strdup (source_file);
727 }

+ Here is the caller graph for this function:

static void ev_previewer_window_zoom_fit_page ( GtkToggleAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 137 of file ev-previewer-window.c.

139 {
141  gtk_toggle_action_get_active (action) ?
143 }

+ Here is the caller graph for this function:

static void ev_previewer_window_zoom_fit_width ( GtkToggleAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 146 of file ev-previewer-window.c.

148 {
150  gtk_toggle_action_get_active (action) ?
152 }

+ Here is the caller graph for this function:

static void ev_previewer_window_zoom_in ( GtkAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 121 of file ev-previewer-window.c.

123 {
125  ev_view_zoom_in (window->view);
126 }
static void ev_previewer_window_zoom_out ( GtkAction *  action,
EvPreviewerWindow window 
)
static

Definition at line 129 of file ev-previewer-window.c.

131 {
133  ev_view_zoom_out (window->view);
134 }
static gdouble get_screen_dpi ( EvPreviewerWindow window)
static

Definition at line 71 of file ev-previewer-window.c.

72 {
73  GdkScreen *screen;
74 
75  screen = gtk_window_get_screen (GTK_WINDOW (window));
76  return ev_document_misc_get_screen_dpi (screen);
77 }

+ Here is the caller graph for this function:

static void model_page_changed ( EvDocumentModel model,
gint  old_page,
gint  new_page,
EvPreviewerWindow window 
)
static

Definition at line 337 of file ev-previewer-window.c.

341 {
342  GtkAction *action;
344 
345  action = gtk_action_group_get_action (window->action_group, "GoPreviousPage");
346  gtk_action_set_sensitive (GTK_ACTION (action), new_page > 0 );
347 
348  action = gtk_action_group_get_action (window->action_group, "GoNextPage");
349  gtk_action_set_sensitive (GTK_ACTION (action), new_page < n_pages - 1);
350 }

+ Here is the caller graph for this function:

static gboolean view_focus_changed ( GtkWidget *  widget,
GdkEventFocus *  event,
EvPreviewerWindow window 
)
static

Definition at line 326 of file ev-previewer-window.c.

329 {
330  if (window->accels_group)
331  gtk_action_group_set_sensitive (window->accels_group, event->in);
332 
333  return FALSE;
334 }

+ Here is the caller graph for this function:

static void view_sizing_mode_changed ( EvDocumentModel model,
GParamSpec *  pspec,
EvPreviewerWindow window 
)
static

Definition at line 353 of file ev-previewer-window.c.

356 {
357  EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
358  GtkAction *action;
359 
360  action = gtk_action_group_get_action (window->action_group, "ViewFitPage");
361  g_signal_handlers_block_by_func (action,
363  window);
364  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
365  sizing_mode == EV_SIZING_FIT_PAGE);
366  g_signal_handlers_unblock_by_func (action,
368  window);
369 
370  action = gtk_action_group_get_action (window->action_group, "ViewFitWidth");
371  g_signal_handlers_block_by_func (action,
373  window);
374  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
375  sizing_mode == EV_SIZING_FIT_WIDTH);
376  g_signal_handlers_unblock_by_func (action,
378  window);
379 }

+ Here is the caller graph for this function:

Variable Documentation

const GtkActionEntry accel_entries[]
static
Initial value:
= {
{ "p", GTK_STOCK_GO_UP, "", "p", NULL,
{ "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
{ "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
{ "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
{ "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
{ "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
{ "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
{ "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
{ "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
{ "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
{ "FocusPageSelector", NULL, "", "<control>l", NULL,
}

Definition at line 290 of file ev-previewer-window.c.

const GtkActionEntry action_entries[]
static
Initial value:
= {
{ "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
NULL,
G_CALLBACK (ev_previewer_window_close) },
{ "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
N_("Go to the previous page"),
{ "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
N_("Go to the next page"),
{ "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
N_("Enlarge the document"),
{ "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
N_("Shrink the document"),
}

Definition at line 266 of file ev-previewer-window.c.

const GtkToggleActionEntry toggle_action_entries[]
static
Initial value:
= {
{ "ViewFitPage", EV_STOCK_ZOOM_PAGE, N_("Fit Pa_ge"), NULL,
N_("Make the current document fill the window"),
{ "ViewFitWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit _Width"), NULL,
N_("Make the current document fill the window width"),
}

Definition at line 316 of file ev-previewer-window.c.