diff options
author | bl0ckeduser <[email protected]> | 2014-02-08 22:18:47 -0500 |
---|---|---|
committer | bl0ckeduser <[email protected]> | 2014-02-08 22:18:47 -0500 |
commit | 7f21f2854ad69786568558db9c5d87ba17aa921c (patch) | |
tree | 6a50c22a921509dc89b7591811a36714934ee0c8 | |
parent | 9ba2765d71e217254d2a3429b043430dbc9ff5d1 (diff) | |
download | atril-7f21f2854ad69786568558db9c5d87ba17aa921c.tar.bz2 atril-7f21f2854ad69786568558db9c5d87ba17aa921c.tar.xz |
Implement window expand functionality (#53)
-rw-r--r-- | cut-n-paste/zoom-control/ephy-zoom.c | 6 | ||||
-rw-r--r-- | cut-n-paste/zoom-control/ephy-zoom.h | 4 | ||||
-rw-r--r-- | data/atril-ui.xml | 1 | ||||
-rw-r--r-- | shell/ev-window.c | 62 |
4 files changed, 70 insertions, 3 deletions
diff --git a/cut-n-paste/zoom-control/ephy-zoom.c b/cut-n-paste/zoom-control/ephy-zoom.c index 83bb8291..bc456ecc 100644 --- a/cut-n-paste/zoom-control/ephy-zoom.c +++ b/cut-n-paste/zoom-control/ephy-zoom.c @@ -35,11 +35,13 @@ ephy_zoom_get_zoom_level_index (float level) return 0; } else if (level == EPHY_ZOOM_FIT_WIDTH) { return 1; + } else if (level == EPHY_ZOOM_EXPAND_WINDOW_TO_FIT) { + return 2; } - previous = zoom_levels[3].level; + previous = zoom_levels[4].level; - for (i = 4; i < n_zoom_levels; i++) + for (i = 5; i < n_zoom_levels; i++) { current = zoom_levels[i].level; mean = sqrt (previous * current); diff --git a/cut-n-paste/zoom-control/ephy-zoom.h b/cut-n-paste/zoom-control/ephy-zoom.h index 642e5ba9..1dcb4598 100644 --- a/cut-n-paste/zoom-control/ephy-zoom.h +++ b/cut-n-paste/zoom-control/ephy-zoom.h @@ -34,7 +34,8 @@ G_BEGIN_DECLS #define EPHY_ZOOM_BEST_FIT (-3.0) #define EPHY_ZOOM_FIT_WIDTH (-4.0) -#define EPHY_ZOOM_SEPARATOR (-5.0) +#define EPHY_ZOOM_EXPAND_WINDOW_TO_FIT (-5.0) +#define EPHY_ZOOM_SEPARATOR (-6.0) static const struct @@ -47,6 +48,7 @@ zoom_levels[] = { { N_("Best Fit"), EPHY_ZOOM_BEST_FIT }, { N_("Fit Page Width"), EPHY_ZOOM_FIT_WIDTH }, + { N_("Expand Window To Fit"), EPHY_ZOOM_EXPAND_WINDOW_TO_FIT }, { NULL, EPHY_ZOOM_SEPARATOR }, { N_("50%"), 0.5 }, { N_("70%"), 0.7071067811 }, diff --git a/data/atril-ui.xml b/data/atril-ui.xml index f8e750db..c35d1015 100644 --- a/data/atril-ui.xml +++ b/data/atril-ui.xml @@ -47,6 +47,7 @@ <menuitem name="ViewZoomOutMenu" action="ViewZoomOut"/> <menuitem name="ViewBestFitMenu" action="ViewBestFit"/> <menuitem name="ViewPageWidthMenu" action="ViewPageWidth"/> + <menuitem name="ViewExpandWindowMenu" action="ViewExpandWindow"/> <separator/> <menuitem name="ViewReload" action="ViewReload"/> </menu> diff --git a/shell/ev-window.c b/shell/ev-window.c index 1f989f85..703f5a3c 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -326,6 +326,8 @@ static void ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window); static void ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window); +static void ev_window_cmd_view_expand_window (GtkAction *action, + EvWindow *ev_window); static void view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window); @@ -346,6 +348,10 @@ static void ev_window_emit_closed (EvWindow *window); static void ev_window_emit_doc_loaded (EvWindow *window); #endif +static void zoom_control_changed_cb (EphyZoomAction *action, + float zoom, + EvWindow *ev_window); + static guint ev_window_n_copies = 0; G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW) @@ -447,6 +453,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window) ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages); ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages); ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages); + ev_window_set_action_sensitive (ev_window, "ViewExpandWindow", has_pages); /* Toolbar-specific actions: */ ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages); @@ -4298,6 +4305,14 @@ ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window) } static void +ev_window_cmd_view_expand_window (GtkAction *action, EvWindow *ev_window) +{ + g_return_if_fail (EV_IS_WINDOW (ev_window)); + + zoom_control_changed_cb (NULL, EPHY_ZOOM_EXPAND_WINDOW_TO_FIT, ev_window); +} + +static void ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window) { ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view)); @@ -5027,6 +5042,50 @@ zoom_control_changed_cb (EphyZoomAction *action, EvWindow *ev_window) { EvSizingMode mode; + GtkWindow *window; + gdouble doc_width, doc_height, scale; + gint old_width, old_height; + gint new_width, new_height; + + if (zoom == EPHY_ZOOM_EXPAND_WINDOW_TO_FIT) { + window = GTK_WINDOW (ev_window); + + ev_document_get_max_page_size (ev_window->priv->document, &doc_width, &doc_height); + scale = ev_document_model_get_scale (ev_window->priv->model); + + new_width = (gint)(doc_width * scale); + new_height = (gint)(doc_height * scale); + + /* + * If the sidebar, menu bar, or tool bars are open, + * we must account for their sizes in calculating + * the new expanded window size. + */ + if (ev_window->priv->chrome & EV_CHROME_SIDEBAR) + new_width += ev_window->priv->sidebar_thumbs->allocation.width; + + if (ev_window->priv->chrome & EV_CHROME_TOOLBAR) + new_height += GTK_WIDGET(ev_window->priv->toolbar)->allocation.height; + + if (ev_window->priv->chrome & EV_CHROME_MENUBAR) + new_height += GTK_WIDGET(ev_window->priv->menubar)->allocation.height; + + /* + * Add a little slack + */ + new_width += 50; + new_height += 50; + + /* + * Only resize if the old window isn't already + * big enough. + */ + gtk_window_get_size(window, &old_width, &old_height); + if (!(old_width >= new_width && old_height >= new_height)) + gtk_window_resize (window, new_width, new_height); + + return; + } if (zoom == EPHY_ZOOM_BEST_FIT) { mode = EV_SIZING_BEST_FIT; @@ -5450,6 +5509,9 @@ static const GtkActionEntry entries[] = { { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R", N_("Reload the document"), G_CALLBACK (ev_window_cmd_view_reload) }, + { "ViewExpandWindow", GTK_STOCK_ZOOM_FIT, N_("_Expand Window to Fit"), "<control>e", + N_("Expand Window to Fit"), + G_CALLBACK (ev_window_cmd_view_expand_window) }, { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL, G_CALLBACK (ev_window_cmd_view_autoscroll) }, |