X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-view.c;h=78a75d99e8889d2df17bb6fa42d46031cc4a35cc;hb=7f32f6e5c1cd8f8868f6b0a26dde7259e79e5411;hp=7aaa59aba9a611ab083baa466a81e181a439a03b;hpb=d97441740d457e1463083d561afdb719ca99e66b;p=evince.git diff --git a/shell/ev-view.c b/shell/ev-view.c index 7aaa59ab..78a75d99 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1,3 +1,4 @@ +/* -*- 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 @@ -38,6 +39,10 @@ struct _EvView { GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + + GArray *find_results; + + double scale; }; struct _EvViewClass { @@ -135,6 +140,9 @@ ev_view_finalize (GObject *object) 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); } @@ -285,11 +293,35 @@ expose_bin_window (GtkWidget *widget, 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 @@ -304,7 +336,6 @@ ev_view_expose_event (GtkWidget *widget, return GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event (widget, event); return FALSE; - } static gboolean @@ -428,8 +459,33 @@ static void 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 ***/ @@ -449,13 +505,23 @@ ev_view_set_document (EvView *view, 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); @@ -490,3 +556,84 @@ ev_view_get_page (EvView *view) 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); +}