+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2004 Red Hat, Inc
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
+
+ GArray *find_results;
+
+ double scale;
};
struct _EvViewClass {
ev_view_set_scroll_adjustments (view, NULL, NULL);
+ g_array_free (view->find_results, TRUE);
+ view->find_results = NULL;
+
G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
}
GdkEventExpose *event)
{
EvView *view = EV_VIEW (widget);
+ int i;
+ const EvFindResult *results;
if (view->document)
ev_document_render (view->document,
event->area.x, event->area.y,
event->area.width, event->area.height);
+
+ results = (EvFindResult*) view->find_results->data;
+ i = 0;
+ while (i < view->find_results->len) {
+#if 0
+ g_printerr ("highlighting result %d at %d,%d %dx%d\n",
+ i,
+ results[i].highlight_area.x,
+ results[i].highlight_area.y,
+ results[i].highlight_area.width,
+ results[i].highlight_area.height);
+#endif
+ // if (results[i].page_num == current_page) FIXME
+ gdk_draw_rectangle (view->bin_window,
+ widget->style->base_gc[GTK_STATE_SELECTED],
+ FALSE,
+ results[i].highlight_area.x,
+ results[i].highlight_area.y,
+ results[i].highlight_area.width,
+ results[i].highlight_area.height);
+ ++i;
+ }
}
static gboolean
return GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event (widget, event);
return FALSE;
-
}
static gboolean
ev_view_init (EvView *view)
{
static const GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
+
+ view->scale = 1.0;
gtk_widget_modify_bg (GTK_WIDGET (view), GTK_STATE_NORMAL, &white);
+
+ view->find_results = g_array_new (FALSE,
+ FALSE,
+ sizeof (EvFindResult));
+}
+
+
+static void
+found_results_callback (EvDocument *document,
+ const EvFindResult *results,
+ int n_results,
+ double percent_complete,
+ void *data)
+{
+ EvView *view = EV_VIEW (data);
+
+ g_array_set_size (view->find_results, 0);
+
+ if (n_results > 0)
+ g_array_append_vals (view->find_results,
+ results, n_results);
+
+ gtk_widget_queue_draw (GTK_WIDGET (view));
}
/*** Public API ***/
if (document != view->document) {
int old_page = ev_view_get_page (view);
- if (view->document)
+ if (view->document) {
g_object_unref (view->document);
+ g_signal_handlers_disconnect_by_func (view->document,
+ found_results_callback,
+ view);
+ g_array_set_size (view->find_results, 0);
+ }
view->document = document;
- if (view->document)
+ if (view->document) {
g_object_ref (view->document);
+ g_signal_connect (view->document,
+ "found",
+ G_CALLBACK (found_results_callback),
+ view);
+ }
if (GTK_WIDGET_REALIZED (view))
ev_document_set_target (view->document, view->bin_window);
else
return 1;
}
+
+#define ZOOM_IN_FACTOR 1.2
+#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
+
+#define MIN_SCALE 0.05409
+#define MAX_SCALE 18.4884
+
+static void
+ev_view_zoom (EvView *view,
+ double factor,
+ gboolean relative)
+{
+ double scale;
+
+ if (relative)
+ scale = view->scale * factor;
+ else
+ scale = factor;
+
+ view->scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
+
+ ev_document_set_scale (view->document, view->scale);
+
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
+void
+ev_view_zoom_in (EvView *view)
+{
+ ev_view_zoom (view, ZOOM_IN_FACTOR, TRUE);
+}
+
+void
+ev_view_zoom_out (EvView *view)
+{
+ ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE);
+}
+
+void
+ev_view_normal_size (EvView *view)
+{
+ ev_view_zoom (view, 1.0, FALSE);
+}
+
+void
+ev_view_best_fit (EvView *view)
+{
+ double scale;
+ int width, height;
+
+ width = height = 0;
+ ev_document_get_page_size (view->document, &width, &height);
+
+ scale = 1.0;
+ if (width != 0 && height != 0) {
+ double scale_w, scale_h;
+
+ scale_w = (double)GTK_WIDGET (view)->allocation.width / width;
+ scale_h = (double)GTK_WIDGET (view)->allocation.height / height;
+
+ scale = (scale_w < scale_h) ? scale_w : scale_h;
+ }
+
+ ev_view_zoom (view, scale, FALSE);
+}
+
+void
+ev_view_fit_width (EvView *view)
+{
+ double scale = 1.0;
+ int width;
+
+ width = 0;
+ ev_document_get_page_size (view->document, &width, NULL);
+
+ scale = 1.0;
+ if (width != 0)
+ scale = (double)GTK_WIDGET (view)->allocation.width / width;
+
+ ev_view_zoom (view, scale, FALSE);
+}