comparison src/gtkimhtml.c @ 7707:17756d5dcfdf

[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 <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 03 Dec 2003 01:12:41 +0000
parents 8a40952f5f67
children a1d913ecd0f6
comparison
equal deleted inserted replaced
7706:e6244f1a19a5 7707:17756d5dcfdf
278 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); 278 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
279 GTK_IMHTML(imhtml)->tip_timer = 0; 279 GTK_IMHTML(imhtml)->tip_timer = 0;
280 } 280 }
281 281
282 if(tip){ 282 if(tip){
283 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); 283 if (GTK_IMHTML(imhtml)->editable)
284 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor);
284 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, 285 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT,
285 gtk_imhtml_tip, imhtml); 286 gtk_imhtml_tip, imhtml);
286 } 287 }
287 288
288 GTK_IMHTML(imhtml)->tip = tip; 289 GTK_IMHTML(imhtml)->tip = tip;
486 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); 487 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL);
487 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); 488 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL);
488 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); 489 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL);
489 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); 490 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL);
490 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); 491 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL);
491 492 gtk_text_buffer_create_tag(imhtml->text_buffer, "LINK", "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL);
492 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ 493 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */
493 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); 494 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
494 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); 495 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
495 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); 496 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM);
496 497
1097 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ 1098 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \
1098 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ 1099 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
1099 } \ 1100 } \
1100 } \ 1101 } \
1101 if (url) { \ 1102 if (url) { \
1102 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \
1103 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \ 1103 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \
1104 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ 1104 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "LINK", &siter, &iter); \
1105 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); \ 1105 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); \
1106 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \ 1106 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \
1107 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ 1107 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
1108 } \ 1108 } \
1109 wpos = 0; \ 1109 wpos = 0; \
1127 { 1127 {
1128 gint pos = 0; 1128 gint pos = 0;
1129 GString *str = NULL; 1129 GString *str = NULL;
1130 GtkTextIter iter, siter; 1130 GtkTextIter iter, siter;
1131 GtkTextMark *mark, *mark2; 1131 GtkTextMark *mark, *mark2;
1132 GtkTextTag *texttag; 1132 GtkTextTag *texttag = NULL;
1133 gchar *ws; 1133 gchar *ws;
1134 gchar *tag; 1134 gchar *tag;
1135 gchar *url = NULL; 1135 gchar *url = NULL;
1136 gchar *bg = NULL; 1136 gchar *bg = NULL;
1137 gint len; 1137 gint len;
1996 return imhtml->editable; 1996 return imhtml->editable;
1997 } 1997 }
1998 1998
1999 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) 1999 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml)
2000 { 2000 {
2001 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); 2001 GtkIMHtmlFormatSpan *span;
2002 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 2002 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
2003 GtkTextIter iter; 2003 GtkTextIter iter;
2004 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2004 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2005 if (!imhtml->edit.bold) { 2005 if (!imhtml->edit.bold) {
2006 span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2006 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2007 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2007 span->start_tag = g_strdup("<b>"); 2008 span->start_tag = g_strdup("<b>");
2008 span->end = NULL; 2009 span->end = NULL;
2009 span->end_tag = g_strdup("</b>"); 2010 span->end_tag = g_strdup("</b>");
2010 span->buffer = imhtml->text_buffer; 2011 span->buffer = imhtml->text_buffer;
2018 return imhtml->edit.bold != NULL; 2019 return imhtml->edit.bold != NULL;
2019 } 2020 }
2020 2021
2021 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) 2022 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml)
2022 { 2023 {
2023 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); 2024 GtkIMHtmlFormatSpan *span;
2024 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 2025 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
2025 GtkTextIter iter; 2026 GtkTextIter iter;
2026 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2027 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2027 if (!imhtml->edit.italic) { 2028 if (!imhtml->edit.italic) {
2029 span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2028 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2030 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2029 span->start_tag = g_strdup("<i>"); 2031 span->start_tag = g_strdup("<i>");
2030 span->end = NULL; 2032 span->end = NULL;
2031 span->end_tag = g_strdup("</i>"); 2033 span->end_tag = g_strdup("</i>");
2032 span->buffer = imhtml->text_buffer; 2034 span->buffer = imhtml->text_buffer;
2039 } 2041 }
2040 return imhtml->edit.italic != NULL; 2042 return imhtml->edit.italic != NULL;
2041 } 2043 }
2042 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) 2044 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml)
2043 { 2045 {
2044 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); 2046 GtkIMHtmlFormatSpan *span;
2045 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 2047 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
2046 GtkTextIter iter; 2048 GtkTextIter iter;
2047 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2049 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2048 if (!imhtml->edit.underline) { 2050 if (!imhtml->edit.underline) {
2051 span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2049 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2052 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2050 span->start_tag = g_strdup("<u>"); 2053 span->start_tag = g_strdup("<u>");
2051 span->end = NULL; 2054 span->end = NULL;
2052 span->end_tag = g_strdup("</u>"); 2055 span->end_tag = g_strdup("</u>");
2053 span->buffer = imhtml->text_buffer; 2056 span->buffer = imhtml->text_buffer;
2057 span = imhtml->edit.underline; 2060 span = imhtml->edit.underline;
2058 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2061 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2059 imhtml->edit.underline = NULL; 2062 imhtml->edit.underline = NULL;
2060 } 2063 }
2061 return imhtml->edit.underline != NULL; 2064 return imhtml->edit.underline != NULL;
2065 }
2066
2067 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text)
2068 {
2069 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2070 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
2071 GtkTextIter iter;
2072 GtkTextTag *tag, *linktag;
2073
2074 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL);
2075 g_object_set_data(G_OBJECT(tag), "link_url", g_strdup(url));
2076
2077 linktag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "LINK");
2078
2079 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
2080 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2081 span->buffer = imhtml->text_buffer;
2082 span->start_tag = g_strdup_printf("<a href='%s'>", url);
2083 span->end_tag = g_strdup("</a>");
2084
2085 gtk_text_buffer_insert_with_tags(imhtml->text_buffer, &iter, text, strlen(text), linktag, tag, NULL);
2086 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2087 imhtml->format_spans = g_list_append(imhtml->format_spans, span);
2062 } 2088 }
2063 2089
2064 int span_compare_begin(const GtkIMHtmlFormatSpan *a, const GtkIMHtmlFormatSpan *b, GtkTextBuffer *buffer) 2090 int span_compare_begin(const GtkIMHtmlFormatSpan *a, const GtkIMHtmlFormatSpan *b, GtkTextBuffer *buffer)
2065 { 2091 {
2066 GtkTextIter ia, ib; 2092 GtkTextIter ia, ib;