From eb3d8c8e3df570e32e2591eeb650de55dba2f613 Mon Sep 17 00:00:00 2001 From: "Nickolay V. Shmyrev" Date: Sat, 7 Jan 2006 13:18:28 +0000 Subject: [PATCH] Dual mode places even pages to the left. Fix for the bug #309393. * shell/ev-page-cache.c: (build_height_to_page), (ev_page_cache_get_height_to_page): * shell/ev-page-cache.h: * shell/ev-view.c: (view_update_range_and_current_page), (get_page_y_offset), (get_page_extents), (ev_view_next_page), (ev_view_previous_page): Dual mode places even pages to the left. Fix for the bug #309393. * shell/ev-view.h: * shell/ev-window.c: (update_action_sensitivity), (setup_view_from_metadata), (view_menu_popup_cb): Don't restore presentation in empty windows, more intelligent next page behaviour in dual mode. * shell/ev-pixbuf-cache.c: (check_job_size_and_unref), (ev_pixbuf_cache_clear_job_sizes): Cleanup job callback on removal. Fix for the bug #325886. --- ChangeLog | 23 +++++++++++++ shell/ev-page-cache.c | 76 +++++++++++++++++++++++------------------ shell/ev-page-cache.h | 2 ++ shell/ev-pixbuf-cache.c | 20 +++++------ shell/ev-view.c | 70 ++++++++++++++++--------------------- shell/ev-view.h | 2 -- shell/ev-window.c | 13 ++++--- 7 files changed, 115 insertions(+), 91 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12b4b5bc..59db5ec4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2006-01-07 Nickolay V. Shmyrev + + * shell/ev-page-cache.c: (build_height_to_page), + (ev_page_cache_get_height_to_page): + * shell/ev-page-cache.h: + * shell/ev-view.c: (view_update_range_and_current_page), + (get_page_y_offset), (get_page_extents), (ev_view_next_page), + (ev_view_previous_page): + + Dual mode places even pages to the left. Fix for the bug #309393. + + * shell/ev-view.h: + * shell/ev-window.c: (update_action_sensitivity), + (setup_view_from_metadata), (view_menu_popup_cb): + + Don't restore presentation in empty windows, more intelligent + next page behaviour in dual mode. + + * shell/ev-pixbuf-cache.c: (check_job_size_and_unref), + (ev_pixbuf_cache_clear_job_sizes): + + Cleanup job callback on removal. Fix for the bug #325886. + 2006-01-07 Nickolay V. Shmyrev * ps/ps.c: (psscan): diff --git a/shell/ev-page-cache.c b/shell/ev-page-cache.c index a79ba056..389bafca 100644 --- a/shell/ev-page-cache.c +++ b/shell/ev-page-cache.c @@ -117,54 +117,73 @@ build_height_to_page (EvPageCache *page_cache) g_free (page_cache->height_to_page); g_free (page_cache->dual_height_to_page); - page_cache->height_to_page = g_new0(double, page_cache->n_pages); - page_cache->dual_height_to_page = g_new0(double, page_cache->n_pages / 2 + 1); + page_cache->height_to_page = g_new0(double, page_cache->n_pages + 1); + page_cache->dual_height_to_page = g_new0(double, page_cache->n_pages + 2); saved_height = 0; - for (i = 0; i < page_cache->n_pages; i++) { + for (i = 0; i <= page_cache->n_pages; i++) { if (page_cache->uniform) { if (!swap) { uniform_height = page_cache->uniform_height; } else { uniform_height = page_cache->uniform_width; } - page_cache->height_to_page [i] = (i + 1) * uniform_height; + page_cache->height_to_page [i] = i * uniform_height; } else { if (!swap) { page_height = page_cache->size_cache [i].height; } else { page_height = page_cache->size_cache [i].width; } - page_cache->height_to_page [i] = saved_height + page_height; - saved_height = page_cache->height_to_page [i]; + page_cache->height_to_page [i] = saved_height; + saved_height += page_height; } } - - saved_height = 0; - for (i = 0; i < page_cache->n_pages; i += 2) { + + if (DUAL_EVEN_LEFT && !page_cache->uniform) { + if (!swap) { + saved_height = page_cache->size_cache [0].height; + } else { + saved_height = page_cache->size_cache [0].width; + } + } else { + saved_height = 0; + } + for (i = DUAL_EVEN_LEFT; i < page_cache->n_pages + 2; i += 2) { if (page_cache->uniform) { if (!swap) { uniform_height = page_cache->uniform_height; } else { uniform_height = page_cache->uniform_width; } - page_cache->dual_height_to_page [i / 2] = (i / 2 + 1) * uniform_height; + page_cache->dual_height_to_page [i] = ((i + DUAL_EVEN_LEFT) / 2) * uniform_height; + if (i + 1 < page_cache->n_pages + 2) + page_cache->dual_height_to_page [i + 1] = ((i + DUAL_EVEN_LEFT) / 2) * uniform_height; } else { - if (!swap) { - page_height = page_cache->size_cache [i].height; - next_page_height = page_cache->size_cache [i + 1].height; + if (i + 1 < page_cache->n_pages) { + if (!swap) { + next_page_height = page_cache->size_cache [i + 1].height; + } else { + next_page_height = page_cache->size_cache [i + 1].width; + } } else { - page_height = page_cache->size_cache [i].width; - next_page_height = page_cache->size_cache [i + 1].width; + next_page_height = 0; } - if (i == page_cache->n_pages - 1) { - page_cache->dual_height_to_page [i / 2] = - saved_height + page_height; + if (i < page_cache->n_pages) { + if (!swap) { + page_height = page_cache->size_cache [i].height; + } else { + page_height = page_cache->size_cache [i].width; + } + } else { + page_height = 0; } - else { - page_cache->dual_height_to_page [i / 2] = saved_height + - MAX(page_height, next_page_height); - saved_height = page_cache->dual_height_to_page [i / 2]; + if (i + 1 < page_cache->n_pages + 2) { + page_cache->dual_height_to_page [i] = saved_height; + page_cache->dual_height_to_page [i + 1] = saved_height; + saved_height += MAX(page_height, next_page_height); + } else { + page_cache->dual_height_to_page [i] = saved_height; } } } @@ -428,27 +447,18 @@ ev_page_cache_get_height_to_page (EvPageCache *page_cache, gint *height, gint *dual_height) { - double result = 0.0; - double dual_result = 0.0; - g_return_if_fail (EV_IS_PAGE_CACHE (page_cache)); if (page_cache->rotation != rotation) { page_cache->rotation = rotation; build_height_to_page (page_cache); } - - if (page > 0) - result = page_cache->height_to_page [page - 1]; if (height) - *height = result * scale; + *height = page_cache->height_to_page [page] * scale; - if (page > 1) - dual_result = page_cache->dual_height_to_page [page / 2 - 1]; - if (dual_height) - *dual_height = dual_result * scale; + *dual_height = page_cache->dual_height_to_page [page] * scale; } gint diff --git a/shell/ev-page-cache.h b/shell/ev-page-cache.h index 6d8955e8..2886ccec 100644 --- a/shell/ev-page-cache.h +++ b/shell/ev-page-cache.h @@ -23,6 +23,8 @@ #include #include "ev-document.h" +#define DUAL_EVEN_LEFT 1 + G_BEGIN_DECLS #define EV_TYPE_PAGE_CACHE (ev_page_cache_get_type ()) #define EV_PAGE_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_CACHE, EvPageCache)) diff --git a/shell/ev-pixbuf-cache.c b/shell/ev-pixbuf-cache.c index f363e700..fff12499 100644 --- a/shell/ev-pixbuf-cache.c +++ b/shell/ev-pixbuf-cache.c @@ -230,7 +230,8 @@ job_finished_cb (EvJob *job, * given a scale. If it won't, it removes the job and clears it to NULL. */ static void -check_job_size_and_unref (CacheJobInfo *job_info, +check_job_size_and_unref (EvPixbufCache *pixbuf_cache, + CacheJobInfo *job_info, EvPageCache *page_cache, gfloat scale) { @@ -252,12 +253,11 @@ check_job_size_and_unref (CacheJobInfo *job_info, height == EV_JOB_RENDER (job_info->job)->target_height) return; - /* Try to remove the job. If we can't, then the thread has already - * picked it up and we are going get a signal when it's done. If we - * can, then the job is fully dead and will never rnu.. */ - if (ev_job_queue_remove_job (job_info->job)) - g_object_unref (job_info->job); - + g_signal_handlers_disconnect_by_func (job_info->job, + G_CALLBACK (job_finished_cb), + pixbuf_cache); + ev_job_queue_remove_job (job_info->job); + g_object_unref (job_info->job); job_info->job = NULL; } @@ -464,12 +464,12 @@ ev_pixbuf_cache_clear_job_sizes (EvPixbufCache *pixbuf_cache, page_cache = ev_page_cache_get (pixbuf_cache->document); for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) { - check_job_size_and_unref (pixbuf_cache->job_list + i, page_cache, scale); + check_job_size_and_unref (pixbuf_cache, pixbuf_cache->job_list + i, page_cache, scale); } for (i = 0; i < pixbuf_cache->preload_cache_size; i++) { - check_job_size_and_unref (pixbuf_cache->prev_job + i, page_cache, scale); - check_job_size_and_unref (pixbuf_cache->next_job + i, page_cache, scale); + check_job_size_and_unref (pixbuf_cache, pixbuf_cache->prev_job + i, page_cache, scale); + check_job_size_and_unref (pixbuf_cache, pixbuf_cache->next_job + i, page_cache, scale); } } diff --git a/shell/ev-view.c b/shell/ev-view.c index d35d4fc4..311504b1 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -420,6 +420,8 @@ view_set_adjustment_values (EvView *view, static void view_update_range_and_current_page (EvView *view) { + gint current_page; + if (view->pending_scroll != SCROLL_TO_KEEP_POSITION) return; @@ -430,7 +432,6 @@ view_update_range_and_current_page (EvView *view) } else if (view->continuous) { GdkRectangle current_area, unused, page_area; GtkBorder border; - gint current_page; gboolean found = FALSE; int i; @@ -458,28 +459,33 @@ view_update_range_and_current_page (EvView *view) } } - current_page = ev_page_cache_get_current_page (view->page_cache); - - if (current_page < view->start_page || current_page > view->end_page) { - view->current_page = view->start_page; - ev_page_cache_set_current_page (view->page_cache, view->start_page); - } } else { if (view->dual_page) { - if (view->current_page % 2 == 0) { + if (view->current_page % 2 == DUAL_EVEN_LEFT) { view->start_page = view->current_page; if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache)) view->end_page = view->start_page + 1; else view->end_page = view->start_page; } else { - view->start_page = view->current_page - 1; + if (view->current_page - 1 < 0) + view->start_page = view->current_page; + else + view->start_page = view->current_page - 1; view->end_page = view->current_page; } } else { view->start_page = view->current_page; view->end_page = view->current_page; } + + } + + current_page = ev_page_cache_get_current_page (view->page_cache); + + if (current_page < view->start_page || current_page > view->end_page) { + view->current_page = view->start_page; + ev_page_cache_set_current_page (view->page_cache, view->start_page); } ev_pixbuf_cache_set_page_range (view->pixbuf_cache, @@ -717,7 +723,7 @@ get_page_y_offset (EvView *view, int page, double zoom, int *y_offset) if (view->dual_page) { ev_page_cache_get_height_to_page (view->page_cache, page, view->rotation, zoom, NULL, &offset); - offset += (page / 2 + 1) * view->spacing + (page / 2) * (border.top + border.bottom); + offset += ((page + DUAL_EVEN_LEFT) / 2 + 1) * view->spacing + ((page + DUAL_EVEN_LEFT) / 2 ) * (border.top + border.bottom); } else { ev_page_cache_get_height_to_page (view->page_cache, page, view->rotation, zoom, &offset, NULL); @@ -760,9 +766,9 @@ get_page_extents (EvView *view, max_width = max_width + border->left + border->right; /* Get the location of the bounding box */ if (view->dual_page) { - x = view->spacing + (page % 2) * (max_width + view->spacing); + x = view->spacing + ((page % 2 == DUAL_EVEN_LEFT) ? 0 : 1) * (max_width + view->spacing); x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2; - if (page % 2 == 0) + if (page % 2 == DUAL_EVEN_LEFT) x = x + (max_width - width - border->left - border->right); } else { x = view->spacing; @@ -782,10 +788,11 @@ get_page_extents (EvView *view, GtkBorder overall_border; gint other_page; - other_page = page ^ 1; + other_page = (page % 2 == DUAL_EVEN_LEFT) ? page + 1: page - 1; /* First, we get the bounding box of the two pages */ - if (other_page < ev_page_cache_get_n_pages (view->page_cache)) { + if (other_page < ev_page_cache_get_n_pages (view->page_cache) + && (0 <= other_page)) { ev_page_cache_get_size (view->page_cache, other_page, view->rotation, @@ -803,7 +810,7 @@ get_page_extents (EvView *view, y = view->spacing; /* Adjust for being the left or right page */ - if (page % 2 == 0) + if (page % 2 == DUAL_EVEN_LEFT) x = x + max_width - width; else x = x + (max_width + overall_border.left + overall_border.right) + view->spacing; @@ -3938,6 +3945,9 @@ ev_view_next_page (EvView *view) if (page < ev_page_cache_get_n_pages (view->page_cache)) { ev_page_cache_set_current_page (view->page_cache, page); return TRUE; + } else if (ev_view_get_dual_page (view) && page == ev_page_cache_get_n_pages (view->page_cache)) { + ev_page_cache_set_current_page (view->page_cache, page - 1); + return TRUE; } else { return FALSE; } @@ -3956,36 +3966,14 @@ ev_view_previous_page (EvView *view) if (page >= 0) { ev_page_cache_set_current_page (view->page_cache, page); return TRUE; - } else { + } else if (ev_view_get_dual_page (view) && page == -1) { + ev_page_cache_set_current_page (view->page_cache, 0); + return TRUE; + } else { return FALSE; } } -gboolean -ev_view_can_previous_page (EvView *view) -{ - int page; - - g_return_val_if_fail (EV_IS_VIEW (view), FALSE); - - page = ev_page_cache_get_current_page (view->page_cache); - page = ev_view_get_dual_page (view) ? page - 2 : page - 1; - - return (page >=0); -} - -gboolean ev_view_can_next_page (EvView *view) -{ - int page; - - g_return_val_if_fail (EV_IS_VIEW (view), FALSE); - - page = ev_page_cache_get_current_page (view->page_cache); - page = ev_view_get_dual_page (view) ? page + 2 : page + 1; - - return (page < ev_page_cache_get_n_pages (view->page_cache)); -} - /*** Enum description for usage in signal ***/ GType diff --git a/shell/ev-view.h b/shell/ev-view.h index 85692e86..0378f285 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -127,8 +127,6 @@ void ev_view_goto_link (EvView *view, EvLink *link); gboolean ev_view_next_page (EvView *view); gboolean ev_view_previous_page (EvView *view); -gboolean ev_view_can_next_page (EvView *view); -gboolean ev_view_can_previous_page (EvView *view); G_END_DECLS diff --git a/shell/ev-window.c b/shell/ev-window.c index 15d671f5..7e6a1bc9 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -309,8 +309,8 @@ update_action_sensitivity (EvWindow *ev_window) /* Go menu */ if (document) { - set_action_sensitive (ev_window, "GoPreviousPage", ev_view_can_previous_page (view)); - set_action_sensitive (ev_window, "GoNextPage", ev_view_can_next_page (view)); + set_action_sensitive (ev_window, "GoPreviousPage", page > 0); + set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1); set_action_sensitive (ev_window, "GoFirstPage", page > 0); set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1); } else { @@ -751,14 +751,14 @@ setup_view_from_metadata (EvWindow *window) /* Presentation */ if (ev_metadata_manager_get (uri, "presentation", &presentation, FALSE)) { - if (g_value_get_boolean (&presentation)) { + if (g_value_get_boolean (&presentation) && uri) { ev_window_run_presentation (window); } } /* Fullscreen */ if (ev_metadata_manager_get (uri, "fullscreen", &fullscreen, FALSE)) { - if (g_value_get_boolean (&fullscreen)) { + if (g_value_get_boolean (&fullscreen) && uri) { ev_window_run_fullscreen (window); } } @@ -2487,6 +2487,9 @@ view_menu_popup_cb (EvView *view, gboolean show_external = FALSE; gboolean show_internal = FALSE; GtkAction *action; + + if (ev_view_get_presentation (EV_VIEW (ev_window->priv->view))) + return FALSE; if (ev_window->priv->link) g_object_unref (ev_window->priv->link); @@ -2530,7 +2533,7 @@ view_menu_popup_cb (EvView *view, gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time ()); - return TRUE; + return FALSE; } static void -- 2.43.5