]> www.fi.muni.cz Git - evince.git/commitdiff
Reorganizes utility functions.
authorJohannes Buchner <buchner.johannes@gmx.at>
Fri, 27 Jul 2007 05:41:22 +0000 (05:41 +0000)
committerNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Fri, 27 Jul 2007 05:41:22 +0000 (05:41 +0000)
2007-07-27  Johannes Buchner  <buchner.johannes@gmx.at>

* shell/ev-utils.c: (get_num_monitors), (get_screen_dpi):
* shell/ev-utils.h:
* shell/ev-view.c: (ev_view_set_zoom_for_size),
(ev_view_update_view_size):
* shell/ev-view.h:
* shell/ev-window.c: (ev_window_update_actions),
(setup_view_from_metadata), (ev_window_screen_changed),
(ev_window_sizing_mode_changed_cb), (ev_window_zoom_changed_cb),
(zoom_control_changed_cb):
* shell/ev-window.h:

Reorganizes utility functions.

svn path=/trunk/; revision=2582

ChangeLog
shell/ev-utils.c
shell/ev-utils.h
shell/ev-view.c
shell/ev-view.h
shell/ev-window.c
shell/ev-window.h

index 1869dd0b49dd8e47aa1a34112b9ac912b3d6ab99..9bdb3df7e0c8956f047d398a39b60e295db2ad47 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2007-07-27  Johannes Buchner  <buchner.johannes@gmx.at>
+
+       * shell/ev-utils.c: (get_num_monitors), (get_screen_dpi):
+       * shell/ev-utils.h:
+       * shell/ev-view.c: (ev_view_set_zoom_for_size),
+       (ev_view_update_view_size):
+       * shell/ev-view.h:
+       * shell/ev-window.c: (ev_window_update_actions),
+       (setup_view_from_metadata), (ev_window_screen_changed),
+       (ev_window_sizing_mode_changed_cb), (ev_window_zoom_changed_cb),
+       (zoom_control_changed_cb):
+       * shell/ev-window.h:
+       
+       Reorganizes utility functions.
+
 2007-07-26  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-pixbuf-cache.c: (job_page_ready_cb), (job_finished_cb),
@@ -14,7 +29,7 @@
        Add page_ready signal to notify that page is ready as soon as
        possible even if other page elements like links, forms, images or
        text mapping are not ready yet.
-       
+
 2007-07-26  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/dvi/dvi-document.c: (dvi_document_file_exporter_begin),
 
        Use capabilities to know which options should be offered by the
        print dialog depending on the document backend.
-       
+
 2007-07-25  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-view.c: (ev_view_handle_cursor_over_xy):
 
        Give priority to forms over text to set the cursor.
-       
+
 2007-07-24  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-view-private.h:
@@ -64,7 +79,7 @@
 
        Use IBEAM cursor for text form fields and NORMAL cursor for read
        only fields. Remove unused status attribute.
-       
+
 2007-07-20  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-view.c: (ev_view_form_field_button_create_widget):
        Update region for current selected items also for checkbox
        buttons, since they can behave as radio buttons when they are in a
        set.
-       
+
 2007-07-19  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * configure.ac:
        * backend/pdf/ev-poppler.cc: (ev_form_field_from_poppler_field):
 
        Get max length of text form fields.
-       
+
 2007-07-19  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/pdf/ev-poppler.cc: (ev_form_field_from_poppler_field):
        * shell/ev-view.c: (ev_view_form_field_text_create_widget):
 
        Fix build with current poppler cvs head.
-       
+
 2007-07-11  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * cut-n-paste/zoom-control/ephy-zoom-control.c:
 
        Fix build with gtk+ >= 2.11.5 due to gtktooltips
        deprecation. Fixes bug #455667
-       
+
 2007-07-10  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * NEWS:
index 90217262f3dbc2a16041d07346affbfd4fa5ee21..fabdeaa16801e4ce203be4e5a1b4d971fb6b6992 100644 (file)
@@ -369,3 +369,43 @@ ev_gui_menu_position_tree_selection (GtkMenu   *menu,
        ev_gui_sanitise_popup_position (menu, widget, x, y);
 }
 
+/**
+ * get_num_monitors: Get the number of user monitors.
+ * @window: optional GtkWindow to look at.
+ *
+ * Returns: Number of monitors, -1 if uncertain situation (like multiple screens)
+ */
+gint 
+get_num_monitors (GtkWindow * window)
+{
+       GdkDisplay * display; 
+       GdkScreen * screen;
+       gint num_screen = gdk_display_get_n_screens(display);
+       
+       display = gdk_display_get_default();
+       
+       if (num_screen != 1)
+               return -1;
+       
+       if (window)
+               screen = gtk_window_get_screen(window);
+       else
+               screen = gdk_display_get_screen(display, 0);
+
+       return gdk_screen_get_n_monitors(screen);
+}
+
+gdouble
+get_screen_dpi (GtkWindow * window)
+{
+       GdkScreen *screen;
+       gdouble    xdpi, ydpi;
+
+       screen = gtk_window_get_screen (window);
+
+       xdpi = 25.4 * gdk_screen_get_width (screen) / gdk_screen_get_width_mm (screen);
+       ydpi = 25.4 * gdk_screen_get_height (screen) / gdk_screen_get_height_mm (screen);
+       
+       return (xdpi + ydpi) / 2.0;
+}
+
index 5afb5a68c6bd5bace84ab26542e3c07e7ac2568d..705beaa0f0b7216aef24947c01c081e56f47acc7 100644 (file)
@@ -34,11 +34,11 @@ GdkPixbuf*          ev_pixbuf_add_shadow (GdkPixbuf *src, int size,
 
 void                   ev_print_region_contents (GdkRegion *region);
 
-void ev_gui_menu_position_tree_selection (GtkMenu   *menu,
-                                         gint      *x,
-                                         gint      *y,
-                                         gboolean  *push_in,
-                                         gpointer   user_data);
+void                   ev_gui_menu_position_tree_selection (GtkMenu   *menu,
+                                                            gint      *x,
+                                                            gint      *y,
+                                                            gboolean  *push_in,
+                                                            gpointer   user_data);
 
 #ifdef WITH_GNOME_PRINT
 GnomePrintConfig*      load_print_config_from_file (void);
@@ -46,6 +46,9 @@ void                  save_print_config_to_file (GnomePrintConfig *config);
 gboolean               using_postscript_printer (GnomePrintConfig *config);
 gboolean               using_pdf_printer (GnomePrintConfig *config);
 #endif
+gint                   get_num_monitors (GtkWindow * window);
+
+gdouble                get_screen_dpi (GtkWindow * window);
 
 G_END_DECLS
 
index 6a17aa8591f2370ce6d59e4edec459c06bfd1d5d..6182fec2858893abd25f1d40fc9edc0cff4b0863 100644 (file)
@@ -4685,13 +4685,14 @@ ev_view_zoom_for_size_single_page (EvView *view,
        ev_view_set_zoom (view, scale, FALSE);
 }
 
-void
+static void
 ev_view_set_zoom_for_size (EvView *view,
                           int     width,
                           int     height,
                           int     vsb_width,
                           int     hsb_height)
 {
+       g_return_if_fail (EV_IS_VIEW (view));
        g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
                          view->sizing_mode == EV_SIZING_BEST_FIT);
        g_return_if_fail (width >= 0);
@@ -5564,3 +5565,37 @@ ev_scroll_type_get_type (void)
   }
   return etype;
 }
+
+void
+ev_view_update_view_size (EvView *view, GtkScrolledWindow * scrolled_window)
+{
+       int width, height;
+       GtkRequisition vsb_requisition;
+       GtkRequisition hsb_requisition;
+       int scrollbar_spacing;
+       
+       /* Calculate the width available for the content */ 
+       width  = GTK_WIDGET (scrolled_window)->allocation.width;
+       height = GTK_WIDGET (scrolled_window)->allocation.height;
+
+       if (gtk_scrolled_window_get_shadow_type (scrolled_window) == GTK_SHADOW_IN 
+           && view) {
+               width -=  2 * GTK_WIDGET(view)->style->xthickness;
+               height -= 2 * GTK_WIDGET(view)->style->ythickness;
+       }
+
+       gtk_widget_size_request (scrolled_window->vscrollbar, &vsb_requisition);
+       gtk_widget_size_request (scrolled_window->hscrollbar, &hsb_requisition);
+       gtk_widget_style_get (GTK_WIDGET (scrolled_window), 
+                             "scrollbar_spacing", 
+                             &scrollbar_spacing, 
+                             NULL);
+       
+       if (EV_IS_VIEW(view)) {
+               ev_view_set_zoom_for_size (EV_VIEW (view),
+                                          MAX (1, width),
+                                          MAX (1, height),
+                                          vsb_requisition.width + scrollbar_spacing,
+                                          hsb_requisition.height + scrollbar_spacing);
+       }
+}
index 78fc6598ac83a145c76aad04287d4e01453a21f6..698b7b2db3e3a0a7ebb451224a06c9897a65a8bd 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <gtk/gtkwidget.h>
 #include <gtk/gtklayout.h>
+#include <gtk/gtkscrolledwindow.h>
 
 #include "ev-document.h"
 #include "ev-link.h"
@@ -108,11 +109,6 @@ void               ev_view_set_zoom          (EvView         *view,
                                           double          factor,
                                           gboolean        relative);
 double         ev_view_get_zoom          (EvView         *view);
-void           ev_view_set_zoom_for_size (EvView         *view,
-                                          int             width,
-                                          int             height,
-                                          int             vsb_width,
-                                          int             hsb_height);
 void            ev_view_set_screen_dpi    (EvView         *view,
                                           gdouble         dpi);
 void           ev_view_rotate_left       (EvView         *view);
@@ -146,6 +142,8 @@ gboolean       ev_view_next_page      (EvView         *view);
 gboolean       ev_view_previous_page     (EvView         *view);
 gchar*         ev_view_page_label_from_dest (EvView *view, EvLinkDest *dest);
 
+void           ev_view_update_view_size (EvView *view, GtkScrolledWindow *scrolled_window);
+
 G_END_DECLS
 
 #endif /* __EV_VIEW_H__ */
index 41b683644ef75237e42a2942564b886a8b995c6b..7e686c35d82f4ad59a8d3bb4ecee9c2f66745e49 100644 (file)
@@ -273,20 +273,6 @@ static void        view_handle_link_cb                     (EvView *view,
 
 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
 
-static gdouble
-ev_window_get_screen_dpi (EvWindow *ev_window)
-{
-       GdkScreen *screen;
-       gdouble    xdpi, ydpi;
-
-       screen = gtk_window_get_screen (GTK_WINDOW (ev_window));
-
-       xdpi = 25.4 * gdk_screen_get_width (screen) / gdk_screen_get_width_mm (screen);
-       ydpi = 25.4 * gdk_screen_get_height (screen) / gdk_screen_get_height_mm (screen);
-       
-       return (xdpi + ydpi) / 2.0;
-}
-
 static void
 ev_window_set_action_sensitive (EvWindow   *ev_window,
                                const char *name,
@@ -457,7 +443,7 @@ ev_window_update_actions (EvWindow *ev_window)
                                                      ZOOM_CONTROL_ACTION);
 
                real_zoom = ev_view_get_zoom (EV_VIEW (ev_window->priv->view));
-               real_zoom *= 72.0 / ev_window_get_screen_dpi (ev_window);
+               real_zoom *= 72.0 / get_screen_dpi (GTK_WINDOW (ev_window));
                zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
 
                ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
@@ -987,7 +973,7 @@ setup_view_from_metadata (EvWindow *window)
                gdouble zoom_value;
 
                zoom_value = g_value_get_double (&zoom);
-               zoom_value *= ev_window_get_screen_dpi (window) / 72.0;
+               zoom_value *= get_screen_dpi (GTK_WINDOW (window)) / 72.0;
                ev_view_set_zoom (view, zoom_value, FALSE);
                g_value_unset (&zoom);
        }
@@ -3032,7 +3018,7 @@ ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
 {
        gboolean presentation;
 
-        g_return_if_fail (EV_IS_WINDOW (window));
+       g_return_if_fail (EV_IS_WINDOW (window));
        ev_window_stop_fullscreen (window);
 
        presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
@@ -3106,7 +3092,7 @@ ev_window_screen_changed (GtkWidget *widget,
 #endif
        
        ev_view_set_screen_dpi (EV_VIEW (window->priv->view),
-                               ev_window_get_screen_dpi (window));
+                               get_screen_dpi (GTK_WINDOW (window)));
        
        if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
                GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
@@ -3503,38 +3489,6 @@ ev_window_cmd_escape (GtkAction *action, EvWindow *window)
        }
 }
 
-static void
-update_view_size (EvView *view, EvWindow *window)
-{
-       int width, height;
-       GtkRequisition vsb_requisition;
-       GtkRequisition hsb_requisition;
-       int scrollbar_spacing;
-
-       /* Calculate the width available for the */
-       width = window->priv->scrolled_window->allocation.width;
-       height = window->priv->scrolled_window->allocation.height;
-
-       if (gtk_scrolled_window_get_shadow_type (GTK_SCROLLED_WINDOW (window->priv->scrolled_window)) == GTK_SHADOW_IN) {
-               width -= 2 * window->priv->view->style->xthickness;
-               height -= 2 * window->priv->view->style->ythickness;
-       }
-
-       gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->priv->scrolled_window)->vscrollbar,
-                                &vsb_requisition);
-       gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->priv->scrolled_window)->hscrollbar,
-                                &hsb_requisition);
-       gtk_widget_style_get (window->priv->scrolled_window,
-                             "scrollbar_spacing", &scrollbar_spacing,
-                             NULL);
-
-       ev_view_set_zoom_for_size (EV_VIEW (window->priv->view),
-                                  MAX (1, width),
-                                  MAX (1, height),
-                                  vsb_requisition.width + scrollbar_spacing,
-                                  hsb_requisition.height + scrollbar_spacing);
-}
-
 static void
 save_sizing_mode (EvWindow *window)
 {
@@ -3562,10 +3516,10 @@ ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec,
 
        scrolled_window = ev_window->priv->scrolled_window;
 
-       g_signal_handlers_disconnect_by_func (ev_window->priv->view, update_view_size, ev_window);
+       g_signal_handlers_disconnect_by_func (ev_window->priv->view, ev_view_update_view_size, scrolled_window);
 
        if (sizing_mode != EV_SIZING_FREE)
-               update_view_size (NULL, ev_window);
+               ev_view_update_view_size (ev_window->priv->view, GTK_SCROLLED_WINDOW (scrolled_window));
 
        switch (sizing_mode) {
                case EV_SIZING_BEST_FIT:
@@ -3574,8 +3528,8 @@ ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec,
                                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
                                      NULL);
                        g_signal_connect (ev_window->priv->view, "zoom_invalid",
-                                         G_CALLBACK (update_view_size),
-                                         ev_window);
+                                         G_CALLBACK (ev_view_update_view_size),
+                                         scrolled_window);
                        break;
                case EV_SIZING_FIT_WIDTH:
                        g_object_set (G_OBJECT (scrolled_window),
@@ -3583,8 +3537,8 @@ ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec,
                                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
                                      NULL);
                        g_signal_connect (ev_window->priv->view, "zoom_invalid",
-                                         G_CALLBACK (update_view_size),
-                                         ev_window);
+                                         G_CALLBACK (ev_view_update_view_size),
+                                         scrolled_window);
                        break;
                case EV_SIZING_FREE:
                        g_object_set (G_OBJECT (scrolled_window),
@@ -3607,7 +3561,7 @@ ev_window_zoom_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window)
                gdouble zoom;
 
                zoom = ev_view_get_zoom (view);
-               zoom *= 72.0 / ev_window_get_screen_dpi (ev_window);
+               zoom *= 72.0 / get_screen_dpi (GTK_WINDOW(ev_window));
                ev_metadata_manager_set_double (ev_window->priv->uri, "zoom", zoom);
        }
 }
@@ -4075,7 +4029,7 @@ zoom_control_changed_cb (EphyZoomAction *action,
        
        if (mode == EV_SIZING_FREE) {
                ev_view_set_zoom (EV_VIEW (ev_window->priv->view),
-                                 zoom * ev_window_get_screen_dpi (ev_window) / 72.0,
+                                 zoom * get_screen_dpi (GTK_WINDOW (ev_window)) / 72.0,
                                  FALSE);
        }
 }
@@ -5305,7 +5259,7 @@ ev_window_init (EvWindow *ev_window)
 
        ev_window->priv->view = ev_view_new ();
        ev_view_set_screen_dpi (EV_VIEW (ev_window->priv->view),
-                               ev_window_get_screen_dpi (ev_window));
+                               get_screen_dpi (GTK_WINDOW (ev_window)));
        ev_window->priv->password_view = ev_password_view_new ();
        g_signal_connect_swapped (ev_window->priv->password_view,
                                  "unlock",
index d269b7dea5809e641a53cc005b2b036e8508bb1f..0b8158f3918b4567aa3972b22083e5db05449bc4 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <glib-object.h>
 #include <gtk/gtkwindow.h>
+#include <gtk/gtkscrolledwindow.h>
 
 #include "ev-link.h"
 #include "ev-page-cache.h"
@@ -88,4 +89,3 @@ void          ev_window_print_range     (EvWindow       *ev_window,
 G_END_DECLS
 
 #endif /* !EV_WINDOW_H */
-