+
+/* This function will reset the selection on pages that no longer have them, and
+ * will update the target_selection on those that need it. It will _not_ free
+ * the previous selection_list -- that's up to caller to do.
+ */
+void
+ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
+ GList *selection_list)
+{
+ EvPageCache *page_cache;
+ EvViewSelection *selection;
+ GList *list = selection_list;
+ int page;
+ int i;
+
+ g_return_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache));
+
+ if (!EV_IS_SELECTION (pixbuf_cache->document))
+ return;
+
+ page_cache = ev_page_cache_get (pixbuf_cache->document);
+
+ /* We check each area to see what needs updating, and what needs freeing; */
+ page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
+ for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
+ if (page < 0) {
+ page ++;
+ continue;
+ }
+
+ selection = NULL;
+ while (list) {
+ if (((EvViewSelection *)list->data)->page == page) {
+ selection = list->data;
+ break;
+ } else if (((EvViewSelection *)list->data)->page > page)
+ break;
+ list = list->next;
+ }
+
+ if (selection)
+ update_job_selection (pixbuf_cache->prev_job + i, selection);
+ else
+ clear_job_selection (pixbuf_cache->prev_job + i);
+ page ++;
+ }
+
+ page = pixbuf_cache->start_page;
+ for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
+ selection = NULL;
+ while (list) {
+ if (((EvViewSelection *)list->data)->page == page) {
+ selection = list->data;
+ break;
+ } else if (((EvViewSelection *)list->data)->page > page)
+ break;
+ list = list->next;
+ }
+
+ if (selection)
+ update_job_selection (pixbuf_cache->job_list + i, selection);
+ else
+ clear_job_selection (pixbuf_cache->job_list + i);
+ page ++;
+ }
+
+ for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
+ if (page >= ev_page_cache_get_n_pages (page_cache))
+ break;
+
+ selection = NULL;
+ while (list) {
+ if (((EvViewSelection *)list->data)->page == page) {
+ selection = list->data;
+ break;
+ } else if (((EvViewSelection *)list->data)->page > page)
+ break;
+ list = list->next;
+ }
+
+ if (selection)
+ update_job_selection (pixbuf_cache->next_job + i, selection);
+ else
+ clear_job_selection (pixbuf_cache->next_job + i);
+ page ++;
+ }
+}
+
+
+/* Returns what the pixbuf cache thinks is */
+
+GList *
+ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
+{
+ EvPageCache *page_cache;
+ EvViewSelection *selection;
+ GList *retval = NULL;
+ int page;
+ int i;
+
+ g_return_val_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache), NULL);
+
+ page_cache = ev_page_cache_get (pixbuf_cache->document);
+
+ /* We check each area to see what needs updating, and what needs freeing; */
+ page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
+ for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
+ if (page < 0) {
+ page ++;
+ continue;
+ }
+
+ if (pixbuf_cache->prev_job[i].selection_points.x1 != -1) {
+ selection = g_new0 (EvViewSelection, 1);
+ selection->page = page;
+ selection->rect = pixbuf_cache->prev_job[i].selection_points;
+ if (pixbuf_cache->prev_job[i].selection_region)
+ selection->covered_region = gdk_region_copy (pixbuf_cache->prev_job[i].selection_region);
+ retval = g_list_append (retval, selection);
+ }
+
+ page ++;
+ }
+
+ page = pixbuf_cache->start_page;
+ for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
+ if (pixbuf_cache->job_list[i].selection_points.x1 != -1) {
+ selection = g_new0 (EvViewSelection, 1);
+ selection->page = page;
+ selection->rect = pixbuf_cache->job_list[i].selection_points;
+ if (pixbuf_cache->job_list[i].selection_region)
+ selection->covered_region = gdk_region_copy (pixbuf_cache->job_list[i].selection_region);
+ retval = g_list_append (retval, selection);
+ }
+
+ page ++;
+ }
+
+ for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
+ if (page >= ev_page_cache_get_n_pages (page_cache))
+ break;
+
+ if (pixbuf_cache->next_job[i].selection_points.x1 != -1) {
+ selection = g_new0 (EvViewSelection, 1);
+ selection->page = page;
+ selection->rect = pixbuf_cache->next_job[i].selection_points;
+ if (pixbuf_cache->next_job[i].selection_region)
+ selection->covered_region = gdk_region_copy (pixbuf_cache->next_job[i].selection_region);
+ retval = g_list_append (retval, selection);
+ }
+
+ page ++;
+ }
+
+ return retval;
+}
+
+void
+ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
+ GdkRegion *region,
+ gint page,
+ gint rotation,
+ gdouble scale)
+{
+ CacheJobInfo *job_info;
+ EvPageCache *page_cache;
+ gint width, height;
+
+ job_info = find_job_cache (pixbuf_cache, page);
+ if (job_info == NULL)
+ return;
+
+ page_cache = ev_page_cache_get (pixbuf_cache->document);
+ ev_page_cache_get_size (page_cache, page, rotation, scale,
+ &width, &height);
+
+ add_job (pixbuf_cache, job_info, page_cache, region,
+ width, height, page, rotation, scale,
+ EV_JOB_PRIORITY_HIGH);
+}
+
+