Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2004-12-22 05:30:35 (GMT)
committer Havoc Pennington <hp@src.gnome.org>2004-12-22 05:30:35 (GMT)
commit110ec8e1d24701cae441a5fe511611aaa478fd3b (patch)
tree315e12f8b6639b58d73c0382ce881c7a97ff2034
parentd97441740d457e1463083d561afdb719ca99e66b (diff)
connect to "found" signal (expose_bin_window): draw find highlights
2004-12-22 Havoc Pennington <hp@redhat.com> * shell/ev-view.c (ev_view_set_document): connect to "found" signal (expose_bin_window): draw find highlights * shell/ev-window.c (find_bar_search_changed_cb): implement * pdf/xpdf/pdf-document.cc (pdf_document_begin_find) (pdf_document_end_find): implement this interface * backend/ev-document.c (ev_document_found): add this to emit signal
-rw-r--r--ChangeLog13
-rw-r--r--backend/ev-document.c12
-rw-r--r--backend/ev-document.h10
-rw-r--r--pdf/xpdf/pdf-document.cc85
-rw-r--r--shell/ev-view.c68
-rw-r--r--shell/ev-window.c12
6 files changed, 195 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index b13df8b..532f307 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-12-22 Havoc Pennington <hp@redhat.com>
+
+ * shell/ev-view.c (ev_view_set_document): connect to "found" signal
+ (expose_bin_window): draw find highlights
+
+ * shell/ev-window.c (find_bar_search_changed_cb): implement
+
+ * pdf/xpdf/pdf-document.cc (pdf_document_begin_find)
+ (pdf_document_end_find): implement this interface
+
+ * backend/ev-document.c (ev_document_found): add this to emit
+ signal
+
Tue Dec 21 23:57:37 2004 Owen Taylor <otaylor@redhat.com>
* data/evince-ui.xml: Add a few more toolbar items.
diff --git a/backend/ev-document.c b/backend/ev-document.c
index 4aea1d1..2f50dcc 100644
--- a/backend/ev-document.c
+++ b/backend/ev-document.c
@@ -159,3 +159,15 @@ ev_document_end_find (EvDocument *document)
EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
iface->end_find (document);
}
+
+void
+ev_document_found (EvDocument *document,
+ const EvFindResult *results,
+ int n_results,
+ double percent_complete)
+{
+ g_signal_emit_by_name (document,
+ "found",
+ results, n_results, percent_complete);
+}
+
diff --git a/backend/ev-document.h b/backend/ev-document.h
index 8d58f0c..4cf4601 100644
--- a/backend/ev-document.h
+++ b/backend/ev-document.h
@@ -80,7 +80,9 @@ struct _EvDocumentIface
/* Signals */
/* "found" emitted at least 1 time (possibly with n_results == 0)
- * for any call to begin_find.
+ * for any call to begin_find; also emitted with NULL,0 when
+ * you end_find. Calling begin_find twice without calling end_find
+ * is considered OK.
*/
void (* found) (EvDocument *document,
const EvFindResult *results,
@@ -117,6 +119,12 @@ void ev_document_begin_find (EvDocument *document,
gboolean case_sensitive);
void ev_document_end_find (EvDocument *document);
+void ev_document_found (EvDocument *document,
+ const EvFindResult *results,
+ int n_results,
+ double percent_complete);
+
+
G_END_DECLS
#endif
diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc
index a25f663..be15d7c 100644
--- a/pdf/xpdf/pdf-document.cc
+++ b/pdf/xpdf/pdf-document.cc
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* pdfdocument.h: Implementation of EvDocument for PDF
* Copyright (C) 2004, Red Hat, Inc.
*
@@ -271,6 +272,88 @@ pdf_document_render (EvDocument *document,
draw.width, draw.height);
}
+void
+pdf_document_begin_find (EvDocument *document,
+ const char *search_string,
+ gboolean case_sensitive)
+{
+ /* FIXME make this incremental (idle handler) and multi-page */
+ /* Right now it's fully synchronous plus only does the current page */
+
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ gunichar *ucs4;
+ glong ucs4_len;
+ int xMin, yMin, xMax, yMax;
+ GArray *results;
+ EvFindResult result;
+
+ /* FIXME case_sensitive (right now XPDF
+ * code is always case insensitive for ASCII
+ * and case sensitive for all other languaages)
+ */
+
+ g_assert (sizeof (gunichar) == sizeof (Unicode));
+ ucs4 = g_utf8_to_ucs4_fast (search_string, -1,
+ &ucs4_len);
+
+ results = g_array_new (FALSE,
+ FALSE,
+ sizeof (EvFindResult));
+
+ if (pdf_document->out->findText (ucs4, ucs4_len,
+ gTrue, gTrue, // startAtTop, stopAtBottom
+ gFalse, gFalse, // startAtLast, stopAtLast
+ &xMin, &yMin, &xMax, &yMax)) {
+
+ result.page_num = pdf_document->page;
+
+ result.highlight_area.x = xMin;
+ result.highlight_area.y = yMin;
+ result.highlight_area.width = xMax - xMin;
+ result.highlight_area.height = yMax - yMin;
+
+ g_array_append_val (results, result);
+
+ /* Now find further results */
+
+ while (pdf_document->out->findText (ucs4, ucs4_len,
+ gFalse, gTrue,
+ gTrue, gFalse,
+ &xMin, &yMin, &xMax, &yMax)) {
+
+ result.page_num = pdf_document->page;
+
+ result.highlight_area.x = xMin;
+ result.highlight_area.y = yMin;
+ result.highlight_area.width = xMax - xMin;
+ result.highlight_area.height = yMax - yMin;
+
+ g_array_append_val (results, result);
+ }
+ }
+
+ ev_document_found (document,
+ (EvFindResult*) results->data,
+ results->len,
+ 1.0);
+
+ g_array_free (results, TRUE);
+}
+
+void
+pdf_document_end_find (EvDocument *document)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+ /* FIXME this will do something once begin_find queues
+ * an incremental find
+ */
+
+ // this should probably be shared among EvDocument
+ // implementations somehow?
+ ev_document_found (document, NULL, 0, 1.0);
+}
+
static void
pdf_document_finalize (GObject *object)
{
@@ -306,6 +389,8 @@ pdf_document_document_iface_init (EvDocumentIface *iface)
iface->set_page_offset = pdf_document_set_page_offset;
iface->get_page_size = pdf_document_get_page_size;
iface->render = pdf_document_render;
+ iface->begin_find = pdf_document_begin_find;
+ iface->end_find = pdf_document_end_find;
}
static void
diff --git a/shell/ev-view.c b/shell/ev-view.c
index 7aaa59a..a928ed3 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,8 @@ struct _EvView {
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
+
+ GArray *find_results;
};
struct _EvViewClass {
@@ -135,6 +138,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 +291,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 +334,6 @@ ev_view_expose_event (GtkWidget *widget,
return GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event (widget, event);
return FALSE;
-
}
static gboolean
@@ -430,6 +459,29 @@ ev_view_init (EvView *view)
static const GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
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 +501,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);
diff --git a/shell/ev-window.c b/shell/ev-window.c
index ec21ae9..df7bf25 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -593,8 +593,18 @@ find_bar_search_changed_cb (EggFindBar *find_bar,
visible = GTK_WIDGET_VISIBLE (find_bar);
search_string = egg_find_bar_get_search_string (find_bar);
- /* FIXME */
+#if 0
g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
+#endif
+
+ /* We don't require begin/end find calls to be matched up, it's really
+ * start_find and cancel_any_find_that_may_not_be_finished
+ */
+ if (visible && search_string) {
+ ev_document_begin_find (ev_window->priv->document, search_string, case_sensitive);
+ } else {
+ ev_document_end_find (ev_window->priv->document);
+ }
}
static void