+ /* Clear the areas we no longer display */
+ if (old_start_page >= 0 && old_start_page < start_page)
+ clear_range (sidebar_thumbnails, old_start_page, MIN (start_page - 1, old_end_page));
+
+ if (old_end_page > 0 && old_end_page > end_page)
+ clear_range (sidebar_thumbnails, MAX (end_page + 1, old_start_page), old_end_page);
+
+ add_range (sidebar_thumbnails, start_page, end_page);
+
+ priv->start_page = start_page;
+ priv->end_page = end_page;
+}
+
+static void
+adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails)
+{
+ EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
+ GtkTreePath *path = NULL;
+ GtkTreePath *path2 = NULL;
+ gdouble page_size;
+ gdouble value;
+ gint wy1;
+ gint wy2;
+
+ /* Widget is not currently visible */
+ if (!gtk_widget_get_mapped (GTK_WIDGET (sidebar_thumbnails)))
+ return;
+
+ page_size = gtk_adjustment_get_page_size (priv->vadjustment);
+
+ if (page_size == 0)
+ return;
+
+ value = gtk_adjustment_get_value (priv->vadjustment);
+
+ if (priv->tree_view) {
+ if (! gtk_widget_get_realized (priv->tree_view))
+ return;
+
+ gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
+ 0, (int) value,
+ NULL, &wy1);
+ gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
+ 0, (int) (value + page_size),
+ NULL, &wy2);
+ gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
+ 1, wy1 + 1, &path,
+ NULL, NULL, NULL);
+ gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
+ 1, wy2 -1, &path2,
+ NULL, NULL, NULL);
+ } else if (priv->icon_view) {
+ if (! gtk_widget_get_realized (priv->icon_view))
+ return;
+ if (! gtk_icon_view_get_visible_range (GTK_ICON_VIEW (priv->icon_view), &path, &path2))
+ return;
+ } else {
+ return;
+ }
+
+ if (path && path2) {
+ update_visible_range (sidebar_thumbnails,
+ gtk_tree_path_get_indices (path)[0],
+ gtk_tree_path_get_indices (path2)[0]);
+ }
+
+ gtk_tree_path_free (path);
+ gtk_tree_path_free (path2);
+}
+
+static void
+ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
+{
+ EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
+ GtkTreeIter iter;
+ int i;
+ gint prev_width = -1;
+ gint prev_height = -1;
+
+ for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
+ gchar *page_label;
+ gchar *page_string;
+ GdkPixbuf *loading_icon = NULL;
+ gint width, height;
+
+ page_label = ev_document_get_page_label (priv->document, i);
+ page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
+ ev_thumbnails_size_cache_get_size (sidebar_thumbnails->priv->size_cache, i,
+ sidebar_thumbnails->priv->rotation,
+ &width, &height);
+ if (!loading_icon || (width != prev_width && height != prev_height)) {
+ loading_icon =
+ ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
+ width, height);
+ }
+
+ prev_width = width;
+ prev_height = height;
+
+ gtk_list_store_append (priv->list_store, &iter);
+ gtk_list_store_set (priv->list_store, &iter,
+ COLUMN_PAGE_STRING, page_string,
+ COLUMN_PIXBUF, loading_icon,
+ COLUMN_THUMBNAIL_SET, FALSE,
+ -1);
+ g_free (page_label);
+ g_free (page_string);
+ }