diff --git a/lib/common.c b/lib/common.c index 0133f364ef7ab175d81b3b5d6eadf1312f1bd475..d59fc3584f094f95cdd705e03e61a233ce0807c1 100644 --- a/lib/common.c +++ b/lib/common.c @@ -155,9 +155,8 @@ static gboolean open_browser(DictData *dd, const gchar *uri) } -gboolean dict_start_web_query(DictData *dd, const gchar *word) +gchar *dict_get_web_query_uri(DictData *dd, const gchar *word) { - gboolean success = TRUE; gchar *uri; #if GLIB_CHECK_VERSION(2, 16, 0) @@ -172,6 +171,17 @@ gboolean dict_start_web_query(DictData *dd, const gchar *word) #else uri = str_replace(g_strdup(dd->web_url), "{word}", dd->searched_word); #endif + + return uri; +} + + +gboolean dict_start_web_query(DictData *dd, const gchar *word) +{ + gboolean success = TRUE; + gchar *uri = dict_get_web_query_uri(dd, word); + + if (! NZV(uri)) { xfce_err(_("The search URL is empty. Please check your preferences.")); diff --git a/lib/common.h b/lib/common.h index 7aeac23df22bde67665ad38613952ab173d5a40a..74962743249d12ca4a64c7d2287d01c39b4ff691 100644 --- a/lib/common.h +++ b/lib/common.h @@ -131,5 +131,6 @@ void dict_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gi DictData *dict_create_dictdata(); gboolean dict_start_web_query(DictData *dd, const gchar *word); +gchar *dict_get_web_query_uri(DictData *dd, const gchar *word); #endif diff --git a/lib/dictd.c b/lib/dictd.c index 4221b54007acdcef282c1d9facbc76a6c69d58cd..35fb70d5fdae6e0fa51ffb617144ddc560402281 100644 --- a/lib/dictd.c +++ b/lib/dictd.c @@ -431,11 +431,10 @@ static gboolean process_server_response(DictData *dd) _("Search \"%s\" using \"%s\""), dd->searched_word, label); gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n\n", 2); - gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, text, -1); - dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, label, - &dd->textiter, TAG_LINK, NULL); - dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, dd->searched_word, - &dd->textiter, TAG_ERROR, TAG_BOLD, NULL); + gtk_text_buffer_insert_with_tags_by_name(dd->main_textbuffer, &dd->textiter, + text, -1, TAG_LINK, NULL); + /*dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, dd->searched_word, + &dd->textiter, TAG_BOLD, NULL);*/ g_free(text); } if (NZV(dd->spell_bin)) diff --git a/lib/gui.c b/lib/gui.c index 9f14aefaeb8a4d6b1b396a0f75dc9ff8f3eeacbf..e8eb2bf891f650fe555a304defbe32905f1ff9c9 100644 --- a/lib/gui.c +++ b/lib/gui.c @@ -161,6 +161,7 @@ static void textview_set_cursor_if_appropriate(GtkTextView *view, gint x, gint y g_free(name); break; } + g_free(name); } if (hovering != hovering_over_link) @@ -187,8 +188,6 @@ static gboolean textview_motion_notify_event(GtkWidget *text_view, GdkEventMotio textview_set_cursor_if_appropriate(GTK_TEXT_VIEW(text_view), x, y, event->window); - gdk_window_get_pointer(text_view->window, NULL, NULL, NULL); - return FALSE; } @@ -275,6 +274,41 @@ static gboolean textview_button_press_cb(GtkTextView *view, GdkEventButton *even } +#if GTK_CHECK_VERSION(2, 12, 0) +static gboolean textview_query_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, + GtkTooltip *tooltip, DictData *dd) +{ + gint tx, ty; + GSList *tags = NULL, *tagp = NULL; + GtkTextIter iter; + + gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), + GTK_TEXT_WINDOW_WIDGET, x, y, &tx, &ty); + + gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, tx, ty); + + tags = gtk_text_iter_get_tags(&iter); + for (tagp = tags; tagp != NULL; tagp = tagp->next) + { + GtkTextTag *tag = tagp->data; + gchar *name; + + g_object_get(G_OBJECT(tag), "name", &name, NULL); + if (name != NULL && strcmp("link", name) == 0) + { + gchar *target_uri = dict_get_web_query_uri(dd, dd->searched_word); + gtk_tooltip_set_markup(tooltip, target_uri); + g_free(name); + g_free(target_uri); + return TRUE; + } + g_free(name); + } + return FALSE; +} +#endif + + void dict_gui_textview_apply_tag_to_word(GtkTextBuffer *buffer, const gchar *word, GtkTextIter *pos, const gchar *first_tag, ...) { @@ -733,6 +767,11 @@ void dict_gui_create_main_window(DictData *dd) g_signal_connect(dd->main_textview, "populate-popup", G_CALLBACK(textview_populate_popup_cb), dd); } + /* tooltips */ +#if GTK_CHECK_VERSION(2, 12, 0) + gtk_widget_set_has_tooltip(dd->main_textview, TRUE); + g_signal_connect(dd->main_textview, "query-tooltip", G_CALLBACK(textview_query_tooltip_cb), dd); +#endif gtk_widget_show(dd->main_textview); gtk_container_add(GTK_CONTAINER(scrolledwindow_results), dd->main_textview);