71 g_clear_object (&priv->
job);
82 G_OBJECT_CLASS (ev_find_sidebar_parent_class)->dispose (
object);
88 GObjectClass *g_object_class = G_OBJECT_CLASS (find_sidebar_class);
93 g_signal_new (
"result-activated",
94 G_TYPE_FROM_CLASS (g_object_class),
97 g_cclosure_marshal_generic,
114 priv = sidebar->
priv;
120 gtk_tree_model_get (model, iter,
134 if (gtk_tree_selection_get_selected (selection, &model, &iter))
140 GdkEventButton *event,
148 priv = sidebar->
priv;
150 gtk_tree_view_get_path_at_pos (view, event->x, event->y, &path,
157 gtk_tree_path_free (path);
161 model = gtk_tree_view_get_model (view);
162 gtk_tree_model_get_iter (model, &iter, path);
163 gtk_tree_path_free (path);
178 model = gtk_list_store_new (
N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
179 gtk_tree_view_set_model (GTK_TREE_VIEW (sidebar->
priv->
tree_view),
180 GTK_TREE_MODEL (model));
181 g_object_unref (model);
189 GtkTreeViewColumn *column;
190 GtkCellRenderer *renderer;
191 GtkTreeSelection *selection;
194 priv = sidebar->
priv;
196 swindow = gtk_scrolled_window_new (NULL, NULL);
197 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
198 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
203 gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->
tree_view), -1);
204 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->
tree_view),
FALSE);
205 gtk_container_add (GTK_CONTAINER (swindow), priv->
tree_view);
208 gtk_box_pack_start (GTK_BOX (sidebar), swindow,
TRUE,
TRUE, 0);
209 gtk_widget_show (swindow);
211 column = gtk_tree_view_column_new ();
212 gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column),
TRUE);
213 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->
tree_view), column);
215 renderer = (GtkCellRenderer *)g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
219 gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer,
TRUE);
220 gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
224 renderer = gtk_cell_renderer_text_new ();
225 gtk_tree_view_column_pack_end (GTK_TREE_VIEW_COLUMN (column), renderer,
FALSE);
226 gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
229 g_object_set (G_OBJECT (renderer),
"style", PANGO_STYLE_ITALIC, NULL);
231 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
232 priv->
selection_id = g_signal_connect (selection,
"changed",
235 g_signal_connect (priv->
tree_view,
"button-press-event",
244 "orientation", GTK_ORIENTATION_VERTICAL,
252 GtkTreeSelection *selection;
254 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
258 g_signal_handler_unblock (selection, priv->
selection_id);
272 for (i = 0; i < page; i++)
287 const gchar *start_ptr;
288 const gchar *end_ptr;
292 if (end - start <= 0)
295 start_ptr = g_utf8_offset_to_pointer (text, start);
296 end_ptr = g_utf8_offset_to_pointer (start_ptr, end - start);
298 retval = g_malloc (end_ptr - start_ptr + 1);
301 while (p != end_ptr) {
304 next = g_utf8_next_char (p);
306 if (next != end_ptr) {
307 GUnicodeBreakType break_type;
309 break_type = g_unichar_break_type (g_utf8_get_char (p));
310 if (break_type == G_UNICODE_BREAK_HYPHEN && *next ==
'\n') {
311 p = g_utf8_next_char (next);
317 strncpy (retval + len, p, next - p);
320 *(retval + len) =
' ';
340 const gchar *find_text,
341 gboolean case_sensitive,
342 PangoLogAttr *log_attrs,
343 gint log_attrs_length,
353 iter = MAX (0, offset - 1);
354 while (!log_attrs[iter].is_word_start && iter > 0)
360 offset += g_utf8_strlen (find_text, -1);
362 match = g_utf8_substring (text, iter, offset);
364 iter = MIN (log_attrs_length, offset + 1);
365 max_chars = MIN (log_attrs_length - 1, iter + 100);
369 while (!log_attrs[word].is_word_end && word < max_chars)
372 if (word > max_chars)
380 markup = g_markup_printf_escaped (
"%s<span weight=\"bold\">%s</span>%s",
381 prec ? prec :
"", match ? match : find_text, succ ? succ :
"");
421 y = (match->
y1 + match->
y2) / 2;
428 if (x >= area->
x1 && x < area->x2 &&
429 y >= area->
y1 && y <= area->y2) {
433 i = (i + 1) % n_areas;
434 }
while (i != offset);
451 g_clear_object (&priv->
job);
456 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->
tree_view));
466 PangoLogAttr *text_log_attrs;
467 gulong text_log_attrs_length;
473 matches = priv->
job->
pages[current_page];
479 page_text =
get_page_text (document, page, &areas, &n_areas);
480 g_object_unref (page);
484 text_log_attrs_length = g_utf8_strlen (page_text, -1);
485 text_log_attrs = g_new0 (PangoLogAttr, text_log_attrs_length + 1);
486 pango_get_log_attrs (page_text, -1, -1, NULL, text_log_attrs, text_log_attrs_length + 1);
493 for (l = matches, result = 0; l; l = g_list_next (l), result++) {
500 g_warning (
"No offset found for match \"%s\" at page %d after processing %d results\n",
501 priv->
job->
text, current_page, result);
506 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
508 gtk_list_store_insert (GTK_LIST_STORE (model), &iter,
517 text_log_attrs_length,
520 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
531 g_free (text_log_attrs);
562 if (priv->
job == job)
566 priv->
job = g_object_ref (job);
567 g_signal_connect_object (job,
"updated",
570 g_signal_connect_object (job,
"cancelled",
584 gint first_match_page = -1;
599 first_match_page = index;
604 if (first_match_page != -1)
646 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->
tree_view));
648 while (gtk_tree_model_iter_next (model, &iter))
664 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->
tree_view));
666 if (gtk_tree_model_iter_next (model, &iter)) {