diff options
Diffstat (limited to 'libview/ev-view.c')
-rw-r--r-- | libview/ev-view.c | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c index 63e0979e..3cbba02a 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -321,9 +321,8 @@ G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_LAYOUT) #define EV_HEIGHT_TO_PAGE_CACHE_KEY "ev-height-to-page-cache" static void -build_height_to_page (EvHeightToPageCache *cache, - EvDocument *document, - gint rotation) +ev_view_build_height_to_page_cache (EvView *view, + EvHeightToPageCache *cache) { gboolean swap, uniform, dual_even_left; int i; @@ -331,17 +330,18 @@ build_height_to_page (EvHeightToPageCache *cache, double saved_height; gdouble u_width, u_height; gint n_pages; + EvDocument *document = view->document; - swap = (rotation == 90 || rotation == 270); + swap = (view->rotation == 90 || view->rotation == 270); uniform = ev_document_is_page_size_uniform (document); n_pages = ev_document_get_n_pages (document); - dual_even_left = (n_pages > 2); + dual_even_left = get_dual_even_left (view); g_free (cache->height_to_page); g_free (cache->dual_height_to_page); - cache->rotation = rotation; + cache->rotation = view->rotation; cache->height_to_page = g_new0 (gdouble, n_pages + 1); cache->dual_height_to_page = g_new0 (gdouble, n_pages + 2); @@ -413,21 +413,6 @@ build_height_to_page (EvHeightToPageCache *cache, } static void -ev_height_to_page_cache_get_height (EvHeightToPageCache *cache, - EvDocument *document, - gint page, - gint rotation, - gdouble *height, - gdouble *dual_height) -{ - if (cache->rotation != rotation) - build_height_to_page (cache, document, rotation); - - *height = cache->height_to_page[page]; - *dual_height = cache->dual_height_to_page[page]; -} - -static void ev_height_to_page_cache_free (EvHeightToPageCache *cache) { if (cache->height_to_page) { @@ -453,7 +438,7 @@ ev_view_get_height_to_page_cache (EvView *view) cache = g_object_get_data (G_OBJECT (view->document), EV_HEIGHT_TO_PAGE_CACHE_KEY); if (!cache) { cache = g_new0 (EvHeightToPageCache, 1); - build_height_to_page (cache, view->document, view->rotation); + ev_view_build_height_to_page_cache (view, cache); g_object_set_data_full (G_OBJECT (view->document), EV_HEIGHT_TO_PAGE_CACHE_KEY, cache, @@ -469,16 +454,18 @@ ev_view_get_height_to_page (EvView *view, gint *height, gint *dual_height) { + EvHeightToPageCache *cache = NULL; gdouble h, dh; if (!view->height_to_page_cache) return; - ev_height_to_page_cache_get_height (view->height_to_page_cache, - view->document, - page, - view->rotation, - &h, &dh); + cache = view->height_to_page_cache; + if (cache->rotation != view->rotation) + ev_view_build_height_to_page_cache (view, cache); + h = cache->height_to_page[page]; + dh = cache->dual_height_to_page[page]; + if (height) *height = (gint)(h * view->scale + 0.5); @@ -1394,7 +1381,8 @@ doc_rect_to_view_rect (EvView *view, static gboolean get_dual_even_left (EvView *view) { - return (ev_document_get_n_pages (view->document) > 2); + gint n_pages = ev_document_get_n_pages (view->document); + return (n_pages > 2 && view->dual_even_left); } static void @@ -5082,6 +5070,7 @@ ev_view_init (EvView *view) view->selection_mode = EV_VIEW_SELECTION_TEXT; view->continuous = TRUE; view->dual_page = FALSE; + view->dual_even_left = TRUE; view->fullscreen = FALSE; view->sizing_mode = EV_SIZING_FIT_WIDTH; view->pending_scroll = SCROLL_TO_KEEP_POSITION; @@ -5534,6 +5523,19 @@ ev_view_dual_page_changed_cb (EvDocumentModel *model, } static void +ev_view_dual_odd_left_changed_cb (EvDocumentModel *model, + GParamSpec *pspec, + EvView *view) +{ + view->dual_even_left = !ev_document_model_get_dual_page_odd_pages_left (model); + + view->pending_scroll = SCROLL_TO_PAGE_POSITION; + /* Total height of some page pairs may changes, recompute cache */ + ev_view_build_height_to_page_cache(view, view->height_to_page_cache); + gtk_widget_queue_resize (GTK_WIDGET (view)); +} + +static void ev_view_fullscreen_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvView *view) @@ -5595,6 +5597,9 @@ ev_view_set_model (EvView *view, g_signal_connect (view->model, "notify::dual-page", G_CALLBACK (ev_view_dual_page_changed_cb), view); + g_signal_connect (view->model, "notify::dual-odd-left", + G_CALLBACK (ev_view_dual_odd_left_changed_cb), + view); g_signal_connect (view->model, "notify::fullscreen", G_CALLBACK (ev_view_fullscreen_changed_cb), view); |