+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.
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);
+}
+
/* 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,
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
+/* -*- 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.
*
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)
{
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
+/* -*- 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;
};
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
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 ***/
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);
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