2006-06-06 [paul] 2.2.1cvs4
[claws.git] / src / textview.c
index b182f576c06c663b824bccc51ecd0ba7f6244426..3354b350ef48caf965f257e49bcf662c9587e61c 100644 (file)
@@ -79,6 +79,11 @@ static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0}
 };
 
+static GdkColor quote_bgcolors[3] = {
+       {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
+       {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
+       {(gulong)0, (gushort)0, (gushort)0, (gushort)0}
+};
 static GdkColor signature_color = {
        (gulong)0,
        (gushort)0x7fff,
@@ -390,28 +395,43 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
        gtk_text_buffer_create_tag(buffer, "header_title",
                                   "font-desc", bold_font_desc,
                                   NULL);
-       gtk_text_buffer_create_tag(buffer, "quote0",
-                                  "foreground-gdk", &quote_colors[0],
-                                  NULL);
-       gtk_text_buffer_create_tag(buffer, "quote1",
-                                  "foreground-gdk", &quote_colors[1],
-                                  NULL);
-       gtk_text_buffer_create_tag(buffer, "quote2",
-                                  "foreground-gdk", &quote_colors[2],
-                                  NULL);
+       if (prefs_common.enable_bgcolor) {
+               gtk_text_buffer_create_tag(buffer, "quote0",
+                               "foreground-gdk", &quote_colors[0],
+                               "paragraph-background-gdk", &quote_bgcolors[0],
+                               NULL);
+               gtk_text_buffer_create_tag(buffer, "quote1",
+                               "foreground-gdk", &quote_colors[1],
+                               "paragraph-background-gdk", &quote_bgcolors[1],
+                               NULL);
+               gtk_text_buffer_create_tag(buffer, "quote2",
+                               "foreground-gdk", &quote_colors[2],
+                               "paragraph-background-gdk", &quote_bgcolors[2],
+                               NULL);
+       } else {
+               gtk_text_buffer_create_tag(buffer, "quote0",
+                               "foreground-gdk", &quote_colors[0],
+                               NULL);
+               gtk_text_buffer_create_tag(buffer, "quote1",
+                               "foreground-gdk", &quote_colors[1],
+                               NULL);
+               gtk_text_buffer_create_tag(buffer, "quote2",
+                               "foreground-gdk", &quote_colors[2],
+                               NULL);
+       }
        gtk_text_buffer_create_tag(buffer, "emphasis",
-                                  "foreground-gdk", &emphasis_color,
-                                  NULL);
-       gtk_text_buffer_create_tag(buffer, "signature",
-                                  "foreground-gdk", &signature_color,
-                                  NULL);
-       tag = gtk_text_buffer_create_tag(buffer, "link",
-                                        "foreground-gdk", &uri_color,
-                                        NULL);
+                       "foreground-gdk", &emphasis_color,
+                       NULL);
+       gtk_text_buffer_create_tag(buffer, "signature",
+                       "foreground-gdk", &signature_color,
+                       NULL);
+       tag = gtk_text_buffer_create_tag(buffer, "link",
+                       "foreground-gdk", &uri_color,
+                       NULL);
        gtk_text_buffer_create_tag(buffer, "link-hover",
-                                  "foreground-gdk", &uri_color,
-                                  "underline", PANGO_UNDERLINE_SINGLE,
-                                  NULL);
+                       "foreground-gdk", &uri_color,
+                       "underline", PANGO_UNDERLINE_SINGLE,
+                       NULL);
        g_signal_connect(G_OBJECT(tag), "event",
                          G_CALLBACK(textview_uri_button_pressed), textview);
  }
@@ -431,11 +451,19 @@ void textview_init(TextView *textview)
        textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
 }
 
-#define CHANGE_TAG_COLOR(tagname, color) { \
+#if GTK_CHECK_VERSION(2, 8, 0)
+ #define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
        tag = gtk_text_tag_table_lookup(tags, tagname); \
        if (tag) \
-               g_object_set(G_OBJECT(tag), "foreground-gdk", color, NULL); \
-}
+               g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, "paragraph-background-gdk", colorbg, NULL); \
+ }
+#else
+ #define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
+       tag = gtk_text_tag_table_lookup(tags, tagname); \
+       if (tag) \
+               g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, NULL); \
+ }
+#endif
 
 static void textview_update_message_colors(TextView *textview)
 {
@@ -446,6 +474,10 @@ static void textview_update_message_colors(TextView *textview)
        GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
        GtkTextTag *tag = NULL;
 
+       quote_bgcolors[0] = quote_bgcolors[1] = quote_bgcolors[2] = black;
+       quote_colors[0] = quote_colors[1] = quote_colors[2] = 
+               uri_color = emphasis_color = signature_color = black;
+
        if (prefs_common.enable_color) {
                /* grab the quote colors, converting from an int to a GdkColor */
                gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
@@ -459,18 +491,27 @@ static void textview_update_message_colors(TextView *textview)
                gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
                                               &signature_color);
                emphasis_color = colored_emphasis;
+       }
+       if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
+               gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
+                                                  &quote_bgcolors[0]);
+               gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
+                                                  &quote_bgcolors[1]);
+               gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
+                                                  &quote_bgcolors[2]);
+               CHANGE_TAG_COLOR("quote0", &quote_colors[0], &quote_bgcolors[0]);
+               CHANGE_TAG_COLOR("quote1", &quote_colors[1], &quote_bgcolors[1]);
+               CHANGE_TAG_COLOR("quote2", &quote_colors[2], &quote_bgcolors[2]);
        } else {
-               quote_colors[0] = quote_colors[1] = quote_colors[2] = 
-                       uri_color = emphasis_color = signature_color = black;
+               CHANGE_TAG_COLOR("quote0", &quote_colors[0], NULL);
+               CHANGE_TAG_COLOR("quote1", &quote_colors[1], NULL);
+               CHANGE_TAG_COLOR("quote2", &quote_colors[2], NULL);
        }
-       CHANGE_TAG_COLOR("quote0", &quote_colors[0]);
-       CHANGE_TAG_COLOR("quote1", &quote_colors[1]);
-       CHANGE_TAG_COLOR("quote2", &quote_colors[2]);
-       CHANGE_TAG_COLOR("emphasis", &emphasis_color);
-       CHANGE_TAG_COLOR("signature", &signature_color);
-       CHANGE_TAG_COLOR("link", &uri_color);
-       CHANGE_TAG_COLOR("link-hover", &uri_color);
 
+       CHANGE_TAG_COLOR("emphasis", &emphasis_color, NULL);
+       CHANGE_TAG_COLOR("signature", &signature_color, NULL);
+       CHANGE_TAG_COLOR("link", &uri_color, NULL);
+       CHANGE_TAG_COLOR("link-hover", &uri_color, NULL);
 }
 #undef CHANGE_TAG_COLOR
 
@@ -865,7 +906,9 @@ static void textview_show_html(TextView *textview, FILE *fp,
                                /* ALF - the sylpheed html parser returns an empty string,
                                 * if still inside an <a>, but already parsed past HREF */
                                str = strtok(str, " ");
-                               if (str) { 
+                               if (str) {
+                                       while (str && *str && g_ascii_isspace(*str))
+                                               str++; 
                                        parser->href = g_strdup(str);
                                        /* the URL may (or not) be followed by the
                                         * referenced text */
@@ -1109,6 +1152,9 @@ void textview_write_link(TextView *textview, const gchar *str,
        if (!uri)
                return;
 
+       while (uri && *uri && g_ascii_isspace(*uri))
+               uri++;
+               
        text = GTK_TEXT_VIEW(textview->text);
        buffer = gtk_text_view_get_buffer(text);
        gtk_text_buffer_get_end_iter(buffer, &iter);
@@ -1147,6 +1193,11 @@ void textview_write_link(TextView *textview, const gchar *str,
        textview->uri_list = g_slist_append(textview->uri_list, r_uri);
 }
 
+static void textview_set_cursor(GdkWindow *window, GdkCursor *cursor)
+{
+       if (GDK_IS_WINDOW(window))
+               gdk_window_set_cursor(window, cursor);
+}
 void textview_clear(TextView *textview)
 {
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
@@ -1160,6 +1211,7 @@ void textview_clear(TextView *textview)
        TEXTVIEW_STATUSBAR_POP(textview);
        textview_uri_list_remove_all(textview->uri_list);
        textview->uri_list = NULL;
+       textview->uri_hover = NULL;
 
        textview->body_pos = 0;
        if (textview->image) 
@@ -1167,9 +1219,9 @@ void textview_clear(TextView *textview)
        textview->image = NULL;
 
        if (textview->messageview->mainwin->cursor_count == 0) {
-               gdk_window_set_cursor(window, text_cursor);
+               textview_set_cursor(window, text_cursor);
        } else {
-               gdk_window_set_cursor(window, watch_cursor);
+               textview_set_cursor(window, watch_cursor);
        }
 }
 
@@ -1489,7 +1541,9 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                          procheader_headername_equal(header->name, "From") ||
                          procheader_headername_equal(header->name, "To") ||
                          procheader_headername_equal(header->name, "Cc") ||
-                         procheader_headername_equal(header->name, "Bcc");
+                         procheader_headername_equal(header->name, "Bcc") ||
+                         procheader_headername_equal(header->name, "Reply-To") ||
+                         procheader_headername_equal(header->name, "Sender");
                        textview_make_clickable_parts(textview, "header", 
                                                      "link", header->body, 
                                                      hdr);
@@ -1810,7 +1864,7 @@ void textview_cursor_wait(TextView *textview)
        GdkWindow *window = gtk_text_view_get_window(
                        GTK_TEXT_VIEW(textview->text),
                        GTK_TEXT_WINDOW_TEXT);
-       gdk_window_set_cursor(window, watch_cursor);
+       textview_set_cursor(window, watch_cursor);
 }
 
 void textview_cursor_normal(TextView *textview)
@@ -1818,7 +1872,7 @@ void textview_cursor_normal(TextView *textview)
        GdkWindow *window = gtk_text_view_get_window(
                        GTK_TEXT_VIEW(textview->text),
                        GTK_TEXT_WINDOW_TEXT);
-       gdk_window_set_cursor(window, text_cursor);
+       textview_set_cursor(window, text_cursor);
 }
 
 static void textview_uri_update(TextView *textview, gint x, gint y)
@@ -1880,9 +1934,9 @@ static void textview_uri_update(TextView *textview, gint x, gint y)
                window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview->text),
                                                  GTK_TEXT_WINDOW_TEXT);
                if (textview->messageview->mainwin->cursor_count == 0) {
-                       gdk_window_set_cursor(window, uri ? hand_cursor : text_cursor);
+                       textview_set_cursor(window, uri ? hand_cursor : text_cursor);
                } else {
-                       gdk_window_set_cursor(window, watch_cursor);
+                       textview_set_cursor(window, watch_cursor);
                }
 
                TEXTVIEW_STATUSBAR_POP(textview);