# HG changeset patch # User Sean Egan # Date 1070413961 0 # Node ID 17756d5dcfdf45d80c57ca5c0d78f1e67cdd00cb # Parent e6244f1a19a57b7ad259602ac003ed57a4b6d5c8 [gaim-migrate @ 8352] WYSIWYGed links. They'll have tooltips, but they won't be clickable. That sounds like the right thing to do to me. committer: Tailor Script diff -r e6244f1a19a5 -r 17756d5dcfdf src/dialogs.c --- a/src/dialogs.c Tue Dec 02 23:59:23 2003 +0000 +++ b/src/dialogs.c Wed Dec 03 01:12:41 2003 +0000 @@ -934,8 +934,7 @@ if (!strlen(showtext)) showtext = urltext; - g_snprintf(open_tag, 2048, "%s", urltext, showtext); - gaim_gtk_surround(gtkconv, open_tag, ""); + gtk_imhtml_insert_link(GTK_IMHTML(gtkconv->entry), urltext, showtext); g_free(open_tag); } diff -r e6244f1a19a5 -r 17756d5dcfdf src/gtkimhtml.c --- a/src/gtkimhtml.c Tue Dec 02 23:59:23 2003 +0000 +++ b/src/gtkimhtml.c Wed Dec 03 01:12:41 2003 +0000 @@ -280,7 +280,8 @@ } if(tip){ - gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); + if (GTK_IMHTML(imhtml)->editable) + gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, gtk_imhtml_tip, imhtml); } @@ -488,7 +489,7 @@ gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); - + gtk_text_buffer_create_tag(imhtml->text_buffer, "LINK", "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); @@ -1099,9 +1100,8 @@ } \ } \ if (url) { \ - texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \ - gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ + gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "LINK", &siter, &iter); \ texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); \ g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \ gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ @@ -1129,7 +1129,7 @@ GString *str = NULL; GtkTextIter iter, siter; GtkTextMark *mark, *mark2; - GtkTextTag *texttag; + GtkTextTag *texttag = NULL; gchar *ws; gchar *tag; gchar *url = NULL; @@ -1998,11 +1998,12 @@ gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) { - GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); + GtkIMHtmlFormatSpan *span; GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); if (!imhtml->edit.bold) { + span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); span->start_tag = g_strdup(""); span->end = NULL; @@ -2020,11 +2021,12 @@ gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) { - GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); + GtkIMHtmlFormatSpan *span; GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); if (!imhtml->edit.italic) { + span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); span->start_tag = g_strdup(""); span->end = NULL; @@ -2041,11 +2043,12 @@ } gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) { - GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); + GtkIMHtmlFormatSpan *span; GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); if (!imhtml->edit.underline) { + span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); span->start_tag = g_strdup(""); span->end = NULL; @@ -2061,6 +2064,29 @@ return imhtml->edit.underline != NULL; } +void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text) +{ + GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); + GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); + GtkTextIter iter; + GtkTextTag *tag, *linktag; + + tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); + g_object_set_data(G_OBJECT(tag), "link_url", g_strdup(url)); + + linktag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "LINK"); + + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); + span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); + span->buffer = imhtml->text_buffer; + span->start_tag = g_strdup_printf("", url); + span->end_tag = g_strdup(""); + + gtk_text_buffer_insert_with_tags(imhtml->text_buffer, &iter, text, strlen(text), linktag, tag, NULL); + span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); + imhtml->format_spans = g_list_append(imhtml->format_spans, span); +} + int span_compare_begin(const GtkIMHtmlFormatSpan *a, const GtkIMHtmlFormatSpan *b, GtkTextBuffer *buffer) { GtkTextIter ia, ib; diff -r e6244f1a19a5 -r 17756d5dcfdf src/gtkimhtml.h --- a/src/gtkimhtml.h Tue Dec 02 23:59:23 2003 +0000 +++ b/src/gtkimhtml.h Wed Dec 03 01:12:41 2003 +0000 @@ -206,6 +206,8 @@ gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml); gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml); gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml); +void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text); + char *gtk_imhtml_get_markup(GtkIMHtml *imhtml); char *gtk_imhtml_get_text(GtkIMHtml *imhtml);