[evince] libview: Add an option to show odd pages on the left in dual mode
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] libview: Add an option to show odd pages on the left in dual mode
- Date: Sat, 17 Dec 2011 11:00:51 +0000 (UTC)
commit f065e36dcc014fd3279d34e9c27f588edca2e990
Author: Cyril Soldani <cyril soldani legiasoft com>
Date: Sat Dec 17 11:55:15 2011 +0100
libview: Add an option to show odd pages on the left in dual mode
Added a dual_even_left flag to EvView. When this flag is false, odd
pages appear left instead of even ones.
All the logic has been added to get_dual_even_left(). The patch is a bit
more involved because build_height_to_page() was computing
dual_even_left directly instead of calling get_dual_even_left(). Rather
than implementing the logic twice, we replaced its EvDocument argument
by its enclosing EvView in order to be able to call get_dual_even_left()
directly. This function was renamed into
ev_view_build_height_to_page_cache() to reflect it is now a view method.
See bug #444587.
libview/ev-view-private.h | 1 +
libview/ev-view.c | 61 ++++++++++++++++++++++++--------------------
2 files changed, 34 insertions(+), 28 deletions(-)
---
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index 3355457..e46b86d 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -160,6 +160,7 @@ struct _EvView {
gboolean loading;
gboolean continuous;
gboolean dual_page;
+ gboolean dual_even_left;
gboolean fullscreen;
EvSizingMode sizing_mode;
GtkWidget *loading_window;
diff --git a/libview/ev-view.c b/libview/ev-view.c
index d540dc1..c46addd 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -301,9 +301,8 @@ G_DEFINE_TYPE_WITH_CODE (EvView, ev_view, GTK_TYPE_CONTAINER,
#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;
@@ -311,17 +310,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);
@@ -393,21 +393,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) {
@@ -433,7 +418,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,
@@ -449,16 +434,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);
@@ -1330,7 +1317,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
@@ -4952,6 +4940,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;
@@ -5352,6 +5341,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)
@@ -5413,6 +5415,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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]