From 06e8fe2d26f02fd17a4dc19ea10d7ee00dc33243 Mon Sep 17 00:00:00 2001 From: Johannes Buchner Date: Fri, 27 Jul 2007 05:41:22 +0000 Subject: [PATCH] Reorganizes utility functions. 2007-07-27 Johannes Buchner * 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 | 31 ++++++++++++++------ shell/ev-utils.c | 40 ++++++++++++++++++++++++++ shell/ev-utils.h | 13 +++++---- shell/ev-view.c | 37 +++++++++++++++++++++++- shell/ev-view.h | 8 ++---- shell/ev-window.c | 72 +++++++++-------------------------------------- shell/ev-window.h | 2 +- 7 files changed, 124 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1869dd0b..9bdb3df7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-07-27 Johannes Buchner + + * 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 * 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 * backend/dvi/dvi-document.c: (dvi_document_file_exporter_begin), @@ -48,13 +63,13 @@ Use capabilities to know which options should be offered by the print dialog depending on the document backend. - + 2007-07-25 Carlos Garcia Campos * 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 * 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 * shell/ev-view.c: (ev_view_form_field_button_create_widget): @@ -72,14 +87,14 @@ 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 * 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 * backend/pdf/ev-poppler.cc: (ev_form_field_from_poppler_field): @@ -87,7 +102,7 @@ * shell/ev-view.c: (ev_view_form_field_text_create_widget): Fix build with current poppler cvs head. - + 2007-07-11 Carlos Garcia Campos * cut-n-paste/zoom-control/ephy-zoom-control.c: @@ -95,7 +110,7 @@ Fix build with gtk+ >= 2.11.5 due to gtktooltips deprecation. Fixes bug #455667 - + 2007-07-10 Nickolay V. Shmyrev * NEWS: diff --git a/shell/ev-utils.c b/shell/ev-utils.c index 90217262..fabdeaa1 100644 --- a/shell/ev-utils.c +++ b/shell/ev-utils.c @@ -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; +} + diff --git a/shell/ev-utils.h b/shell/ev-utils.h index 5afb5a68..705beaa0 100644 --- a/shell/ev-utils.h +++ b/shell/ev-utils.h @@ -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 diff --git a/shell/ev-view.c b/shell/ev-view.c index 6a17aa85..6182fec2 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -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); + } +} diff --git a/shell/ev-view.h b/shell/ev-view.h index 78fc6598..698b7b2d 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -22,6 +22,7 @@ #include #include +#include #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__ */ diff --git a/shell/ev-window.c b/shell/ev-window.c index 41b68364..7e686c35 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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", diff --git a/shell/ev-window.h b/shell/ev-window.h index d269b7de..0b8158f3 100644 --- a/shell/ev-window.h +++ b/shell/ev-window.h @@ -25,6 +25,7 @@ #include #include +#include #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 */ - -- 2.43.5