*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <gtk/gtk.h>
#include "ev-document-misc.h"
-#include "ev-document-thumbnails.h"
#include "ev-job-scheduler.h"
#include "ev-sidebar-page.h"
#include "ev-sidebar-thumbnails.h"
gint n_pages, pages_done;
int rotation;
+ gboolean inverted_colors;
/* Visible pages */
gint start_page, end_page;
PROP_WIDGET,
};
-static void ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar);
-static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
- EvDocument *document);
-static void ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface);
-static const gchar* ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page);
-static void thumbnail_job_completed_callback (EvJobThumbnail *job,
- EvSidebarThumbnails *sidebar_thumbnails);
-static void adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails);
+static void ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar);
+static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+static void ev_sidebar_thumbnails_page_iface_init (EvSidebarPageInterface *iface);
+static const gchar* ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page);
+static void thumbnail_job_completed_callback (EvJobThumbnail *job,
+ EvSidebarThumbnails *sidebar_thumbnails);
+static void adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails);
G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails,
ev_sidebar_thumbnails,
/* Thumbnails dimensions cache */
#define EV_THUMBNAILS_SIZE_CACHE_KEY "ev-thumbnails-size-cache"
+static void
+get_thumbnail_size_for_page (EvDocument *document,
+ guint page,
+ gint *width,
+ gint *height)
+{
+ gdouble scale;
+ gdouble w, h;
+
+ ev_document_get_page_size (document, page, &w, &h);
+ scale = (gdouble)THUMBNAIL_WIDTH / w;
+
+ *width = MAX ((gint)(w * scale + 0.5), 1);
+ *height = MAX ((gint)(h * scale + 0.5), 1);
+}
+
static EvThumbsSizeCache *
ev_thumbnails_size_cache_new (EvDocument *document)
{
EvThumbsSizeCache *cache;
- EvRenderContext *rc;
- gint i, n_pages;
- EvThumbsSize *thumb_size;
+ gint i, n_pages;
+ EvThumbsSize *thumb_size;
cache = g_new0 (EvThumbsSizeCache, 1);
- n_pages = ev_document_get_n_pages (document);
+ if (ev_document_is_page_size_uniform (document)) {
+ cache->uniform = TRUE;
+ get_thumbnail_size_for_page (document, 0,
+ &cache->uniform_width,
+ &cache->uniform_height);
+ return cache;
+ }
- /* Assume all pages are the same size until proven otherwise */
- cache->uniform = TRUE;
+ n_pages = ev_document_get_n_pages (document);
+ cache->sizes = g_new0 (EvThumbsSize, n_pages);
for (i = 0; i < n_pages; i++) {
- EvPage *page;
- gdouble page_width, page_height;
- gint thumb_width = 0;
- gint thumb_height = 0;
-
- page = ev_document_get_page (document, i);
-
- ev_document_get_page_size (document, i, &page_width, &page_height);
-
- if (!rc) {
- rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width);
- } else {
- ev_render_context_set_page (rc, page);
- ev_render_context_set_scale (rc, (gdouble)THUMBNAIL_WIDTH / page_width);
- }
-
- ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (document),
- rc, &thumb_width, &thumb_height);
-
- if (i == 0) {
- cache->uniform_width = thumb_width;
- cache->uniform_height = thumb_height;
- } else if (cache->uniform &&
- (cache->uniform_width != thumb_width ||
- cache->uniform_height != thumb_height)) {
- /* It's a different thumbnail size. Backfill the array. */
- int j;
-
- cache->sizes = g_new0 (EvThumbsSize, n_pages);
-
- for (j = 0; j < i; j++) {
- thumb_size = &(cache->sizes[j]);
- thumb_size->width = cache->uniform_width;
- thumb_size->height = cache->uniform_height;
- }
- cache->uniform = FALSE;
- }
-
- if (! cache->uniform) {
- thumb_size = &(cache->sizes[i]);
-
- thumb_size->width = thumb_width;
- thumb_size->height = thumb_height;
- }
-
- g_object_unref (page);
- }
-
- if (rc) {
- g_object_unref (rc);
+ thumb_size = &(cache->sizes[i]);
+ get_thumbnail_size_for_page (document, i,
+ &thumb_size->width,
+ &thumb_size->height);
}
return cache;
gint width,
gint height)
{
+ EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
GdkPixbuf *icon;
gchar *key;
key = g_strdup_printf ("%dx%d", width, height);
- icon = g_hash_table_lookup (sidebar_thumbnails->priv->loading_icons, key);
+ icon = g_hash_table_lookup (priv->loading_icons, key);
if (!icon) {
- icon = ev_document_misc_get_thumbnail_frame (width, height, NULL);
- g_hash_table_insert (sidebar_thumbnails->priv->loading_icons,
- key, icon);
+ gboolean inverted_colors;
+
+ inverted_colors = ev_document_model_get_inverted_colors (priv->model);
+ icon = ev_document_misc_get_loading_thumbnail (width, height, inverted_colors);
+ g_hash_table_insert (priv->loading_icons, key, icon);
} else {
g_free (key);
}
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_MAPPED (sidebar_thumbnails))
+ if (!gtk_widget_get_mapped (GTK_WIDGET (sidebar_thumbnails)))
return;
- if (priv->vadjustment->page_size == 0)
+ 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_REALIZED (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) priv->vadjustment->value,
+ 0, (int) value,
NULL, &wy1);
gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
- 0, (int) (priv->vadjustment->value + priv->vadjustment->page_size),
+ 0, (int) (value + page_size),
NULL, &wy2);
gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
1, wy1 + 1, &path,
1, wy2 -1, &path2,
NULL, NULL, NULL);
} else if (priv->icon_view) {
- if (! GTK_WIDGET_REALIZED (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;
}
static void
-ev_sidebar_thumbnails_rotation_changed_cb (EvDocumentModel *model,
- GParamSpec *pspec,
- EvSidebarThumbnails *sidebar_thumbnails)
+ev_sidebar_thumbnails_reload (EvSidebarThumbnails *sidebar_thumbnails)
{
- gint rotation = ev_document_model_get_rotation (model);
+ EvDocumentModel *model;
- sidebar_thumbnails->priv->rotation = rotation;
if (sidebar_thumbnails->priv->loading_icons)
g_hash_table_remove_all (sidebar_thumbnails->priv->loading_icons);
sidebar_thumbnails->priv->n_pages <= 0)
return;
+ model = sidebar_thumbnails->priv->model;
+
ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
g_idle_add ((GSourceFunc)refresh, sidebar_thumbnails);
}
+static void
+ev_sidebar_thumbnails_rotation_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvSidebarThumbnails *sidebar_thumbnails)
+{
+ gint rotation = ev_document_model_get_rotation (model);
+
+ sidebar_thumbnails->priv->rotation = rotation;
+ ev_sidebar_thumbnails_reload (sidebar_thumbnails);
+}
+
+static void
+ev_sidebar_thumbnails_inverted_colors_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvSidebarThumbnails *sidebar_thumbnails)
+{
+ gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
+
+ sidebar_thumbnails->priv->inverted_colors = inverted_colors;
+ ev_sidebar_thumbnails_reload (sidebar_thumbnails);
+}
+
static void
thumbnail_job_completed_callback (EvJobThumbnail *job,
EvSidebarThumbnails *sidebar_thumbnails)
GtkTreeIter *iter;
iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
+ if (priv->inverted_colors)
+ ev_document_misc_invert_pixbuf (job->thumbnail);
gtk_list_store_set (priv->list_store,
iter,
COLUMN_PIXBUF, job->thumbnail,
EvDocument *document = ev_document_model_get_document (model);
EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
- if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
- ev_document_get_n_pages (document) <= 0 ||
+ if (ev_document_get_n_pages (document) <= 0 ||
!ev_document_check_dimensions (document)) {
return;
}
priv->document = document;
priv->n_pages = ev_document_get_n_pages (document);
priv->rotation = ev_document_model_get_rotation (model);
+ priv->inverted_colors = ev_document_model_get_inverted_colors (model);
priv->loading_icons = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
g_signal_connect (priv->model, "notify::rotation",
G_CALLBACK (ev_sidebar_thumbnails_rotation_changed_cb),
sidebar_thumbnails);
+ g_signal_connect (priv->model, "notify::inverted-colors",
+ G_CALLBACK (ev_sidebar_thumbnails_inverted_colors_changed_cb),
+ sidebar_thumbnails);
sidebar_thumbnails->priv->start_page = -1;
sidebar_thumbnails->priv->end_page = -1;
ev_sidebar_thumbnails_set_current_page (sidebar_thumbnails,
ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
EvDocument *document)
{
- return (EV_IS_DOCUMENT_THUMBNAILS (document));
+ return TRUE;
}
static const gchar*
}
static void
-ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface)
+ev_sidebar_thumbnails_page_iface_init (EvSidebarPageInterface *iface)
{
iface->support_document = ev_sidebar_thumbnails_support_document;
iface->set_model = ev_sidebar_thumbnails_set_model;
iface->get_label = ev_sidebar_thumbnails_get_label;
}
-