2005-02-15 [colin] 1.0.1cvs7.1
[claws.git] / src / compose.c
index 47c5ea8e08c8cd78d2dfa824b4c83312eada7c4d..07a9a15a87352f1feac663e08c80a873fcd24aa9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtkmenu.h>
@@ -51,6 +52,7 @@
 #include <gtk/gtktreemodel.h>
 
 #include <gtk/gtkdnd.h>
+#include <gtk/gtkclipboard.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,7 +73,6 @@
 #  include <wctype.h>
 #endif
 
-#include "intl.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
@@ -299,10 +300,6 @@ static void compose_undo_state_changed             (UndoMain       *undostruct,
                                                 gint            redo_state,
                                                 gpointer        data);
 
-static gint calc_cursor_xpos   (GtkTextView    *text,
-                                gint            extra,
-                                gint            char_width);
-
 static void compose_create_header_entry        (Compose *compose);
 static void compose_add_header_entry   (Compose *compose, gchar *header, gchar *text);
 static void compose_update_priority_menu_item(Compose * compose);
@@ -482,8 +479,6 @@ static void subject_activated               (GtkWidget      *widget,
                                         Compose        *compose);
 #endif
 
-static void text_activated             (GtkWidget      *widget,
-                                        Compose        *compose);
 static void text_inserted              (GtkTextBuffer  *buffer,
                                         GtkTextIter    *iter,
                                         const gchar    *text,
@@ -512,7 +507,6 @@ static void compose_check_backwards    (Compose *compose);
 static void compose_check_forwards_go     (Compose *compose);
 #endif
 
-static gboolean compose_send_control_enter     (Compose        *compose);
 static gint compose_defer_auto_save_draft      (Compose        *compose);
 static PrefsAccount *compose_guess_forward_account_from_msginfo        (MsgInfo *msginfo);
 
@@ -1335,26 +1329,18 @@ void compose_reedit(MsgInfo *msginfo)
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
                                        
-       g_signal_handlers_block_by_func(G_OBJECT(textbuf),
-                                       G_CALLBACK(text_inserted),
-                                       compose);
-
        if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
                g_warning("Can't get text part\n");
        else {
                while (fgets(buf, sizeof(buf), fp) != NULL) {
                        strcrchomp(buf);
                        gtk_text_buffer_insert(textbuf, &iter, buf, -1);
-                       gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
                }
                fclose(fp);
        }
        
        compose_attach_parts(compose, msginfo);
 
-       g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
-                                       G_CALLBACK(text_inserted),
-                                       compose);
        g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
@@ -1389,7 +1375,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
 
        gtk_widget_grab_focus(compose->header_last->entry);
 
-       filename = procmsg_get_message_file(msginfo);
+       filename = procmsg_get_message_file_path(msginfo);
        if (filename == NULL)
                return NULL;
 
@@ -1414,12 +1400,12 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
 
        compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
-       gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
+       gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
 
        ifactory = gtk_item_factory_from_widget(compose->popupmenu);
        menu_set_sensitive(ifactory, "/Add...", FALSE);
        menu_set_sensitive(ifactory, "/Remove", FALSE);
-       menu_set_sensitive(ifactory, "/Property...", FALSE);
+       menu_set_sensitive(ifactory, "/Properties...", FALSE);
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        menu_set_sensitive(ifactory, "/Message/Save", FALSE);
@@ -1427,10 +1413,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
        menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
        menu_set_sensitive(ifactory, "/Edit", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
+       menu_set_sensitive(ifactory, "/Options", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
        
@@ -1595,6 +1578,8 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
        gchar *bcc = NULL;
        gchar *subject = NULL;
        gchar *body = NULL;
+       gchar *temp = NULL;
+       gint  len = 0;
 
        scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
 
@@ -1605,7 +1590,13 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
        if (bcc)
                compose_entry_append(compose, bcc, COMPOSE_BCC);
        if (subject)
-               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
+               if (!g_utf8_validate (subject, -1, NULL)) {
+                       temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
+                       gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
+                       g_free(temp);
+               } else {
+                       gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
+               }
        if (body) {
                GtkTextView *text = GTK_TEXT_VIEW(compose->text);
                GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
@@ -1615,7 +1606,13 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
                mark = gtk_text_buffer_get_insert(buffer);
                gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
 
-               gtk_text_buffer_insert(buffer, &iter, body, -1);
+               if (!g_utf8_validate (body, -1, NULL)) {
+                       temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
+                       gtk_text_buffer_insert(buffer, &iter, temp, -1);
+                       g_free(temp);
+               } else {
+                       gtk_text_buffer_insert(buffer, &iter, body, -1);
+               }
                gtk_text_buffer_insert(buffer, &iter, "\n", 1);
        }
 
@@ -2155,6 +2152,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        GtkTextBuffer *buffer;
        GtkTextMark *mark;
        GtkTextIter iter;
+       const gchar *cur_encoding;
        gchar buf[BUFFSIZE];
        gint len;
        FILE *fp;
@@ -2176,14 +2174,12 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                        G_CALLBACK(text_inserted),
                                        compose);
 
+       cur_encoding = conv_get_locale_charset_str();
+
        while (fgets(buf, sizeof(buf), fp) != NULL) {
-               const gchar *cur_encoding = conv_get_current_charset_str();
-               gchar *str = NULL;
-               if (!g_utf8_validate(buf, -1, NULL))
-                       str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
-               else
-                       str = g_strdup(buf);
+               gchar *str;
 
+               str = conv_codeset_strdup(buf, cur_encoding, CS_INTERNAL);
                if (!str) continue;
 
                /* strip <CR> if DOS/Windows file,
@@ -2194,9 +2190,9 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                        while (--len >= 0)
                                if (str[len] == '\r') str[len] = '\n';
                }
-               gtk_text_buffer_insert(buffer, &iter, str, -1);
 
-               g_free (str);
+               gtk_text_buffer_insert(buffer, &iter, str, -1);
+               g_free(str);
        }
 
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
@@ -2439,37 +2435,23 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 #define CHAR_BUF_SIZE 8
 #undef NEXT_PART_NOT_CHILD
 
-#define GET_CHAR(iter_p, buf, len)                                          \
-{                                                                           \
-       GtkTextIter end_iter;                                                \
-       gchar *tmp;                                                          \
-       end_iter = *iter_p;                                                  \
-       gtk_text_iter_forward_char(&end_iter);                               \
-       tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE);   \
-       if (tmp) {                                                           \
-               glong items_read, items_witten;                              \
-               GError *error = NULL;                                        \
-               gunichar *wide_char;                                         \
-               strncpy2(buf, tmp, CHAR_BUF_SIZE);                           \
-               wide_char = g_utf8_to_ucs4(tmp, -1,                          \
-                                          &items_read, &items_witten,       \
-                                          &error);                          \
-               if (error != NULL) {                                         \
-                       g_warning("%s\n", error->message);                   \
-                       g_error_free(error);                                 \
-               }                                                            \
-               len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1;     \
-               g_free(wide_char);                                           \
-       } else {                                                             \
-               buf[0] = '\0';                                               \
-               len = 1;                                                     \
-       }                                                                    \
-       g_free(tmp);                                                         \
-}
 
+#define GET_CHAR(iter_p, buf, len)                             \
+{                                                              \
+       gunichar uc;                                            \
+                                                               \
+       uc = gtk_text_iter_get_char(iter_p);                    \
+       if (uc != 0) {                                          \
+               len = g_unichar_to_utf8(uc, buf) > 1 ? 2 : 1;   \
+               buf[len]='\0';                                  \
+       } else {                                                \
+               buf[0] = '\0';                                  \
+               len = 1;                                        \
+       }                                                       \
+}
 #define DISP_WIDTH(len) \
-       ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
-        (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
+       ((len > 2) ? 2 : \
+        (len == 2) ? 1 : len)
 
 #define SPACE_CHARS    " \t"
 
@@ -2606,7 +2588,7 @@ static void compose_wrap_line(Compose *compose)
 
                if (space) {
                        line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
+                       line_len = cur_len + DISP_WIDTH(ch_len);
                }
 
                gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
@@ -2634,16 +2616,12 @@ static void compose_wrap_line(Compose *compose)
                        p_end++;
                        cur_pos++;
                        line_pos++;
-                       cur_len = cur_len - line_len + ch_len;
+                       cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
                        line_len = 0;
                        continue;
                }
 
-               if (ch_len > 1) {
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
-               }
-               cur_len += ch_len;
+               cur_len += DISP_WIDTH(ch_len);
        }
 }
 
@@ -2652,15 +2630,15 @@ static void compose_wrap_line(Compose *compose)
 /* Darko: used when I debug wrapping */
 void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
 {
-       gint i, clen;
-       gchar cbuf[CHAR_BUF_SIZE];
        GtkTextIter iter, end_iter;
+       gint clen;
+       gchar cbuf[CHAR_BUF_SIZE];
 
        printf("%d [", pos);
        gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
        gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
        for (; gtk_text_iter_forward_char(&iter) &&
-                    gtk_text_iter_compare(&iter, &end_iter) < 0;) {
+            gtk_text_iter_compare(&iter, &end_iter) < 0; ) {
                GET_CHAR(&iter, cbuf, clen);
                if (clen < 0) break;
                if (breakoncr && clen == 1 && cbuf[0] == '\n')
@@ -2683,23 +2661,25 @@ typedef enum {
    uppercase characters immediately followed by >,
    and the repeating sequences of the above */
 /* return indent length */
-static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
+static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos,
+                              guint text_len)
 {
+       GtkTextIter iter;
        guint i_len = 0;
-       guint i, ch_len, alnum_cnt = 0;
+       guint ch_len, alnum_cnt = 0;
        IndentState state = WAIT_FOR_INDENT_CHAR;
        gchar cbuf[CHAR_BUF_SIZE];
        gboolean is_space;
        gboolean is_indent;
+       gboolean iter_next = TRUE;
 
        if (prefs_common.quote_chars == NULL) {
                return 0 ;
        }
 
-       for (i = start_pos; i < text_len; i++) {
-               GtkTextIter iter;
+       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos);
 
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
+       while (iter_next == TRUE) {
                GET_CHAR(&iter, cbuf, ch_len);
                if (ch_len > 1)
                        break;
@@ -2747,6 +2727,7 @@ static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint te
                }
 
                i_len++;
+               iter_next = gtk_text_iter_forward_char(&iter);
        }
 
 out:
@@ -2999,7 +2980,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                /* possible line break */
                if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
                        line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
+                       line_len = cur_len + DISP_WIDTH(ch_len);
                }
 
                /* are we over wrapping length set in preferences ? */
@@ -3115,12 +3096,8 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                        continue;
                }
 
-               if (ch_len > 1) {
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
-               }
                /* advance to next character in buffer */
-               cur_len += ch_len;
+               cur_len += DISP_WIDTH(ch_len);
        }
 
        if (set_editable_pos && editable_pos <= tlen) {
@@ -3234,11 +3211,11 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
 
 #endif
 
-       if (account->default_sign)
+       if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
                menu_set_active(ifactory, "/Options/Sign", TRUE);
        else
                menu_set_active(ifactory, "/Options/Sign", FALSE);
-       if (account->default_encrypt)
+       if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
                menu_set_active(ifactory, "/Options/Encrypt", TRUE);
        else
                menu_set_active(ifactory, "/Options/Encrypt", FALSE);
@@ -3307,7 +3284,7 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
 
                aval = alertpanel(_("Send"),
                                  _("Subject is empty. Send it anyway?"),
-                                 _("Yes"), _("No"), NULL);
+                                 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
                if (aval != G_ALERTDEFAULT)
                        return FALSE;
        }
@@ -3626,7 +3603,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
                else
                        encoding = procmime_get_encoding_for_charset(out_codeset);
 
-               src_codeset = CS_UTF_8;
+               src_codeset = CS_INTERNAL;
                /* if current encoding is US-ASCII, set it the same as
                   outgoing one to prevent code conversion failure */
                if (!g_ascii_strcasecmp(src_codeset, CS_US_ASCII))
@@ -3637,6 +3614,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
 
                if (action == COMPOSE_WRITE_FOR_SEND) {
                        buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
+                       
                        if (!buf) {
                                AlertValue aval;
                                gchar *msg;
@@ -3665,6 +3643,13 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
        }
        g_free(chars);
 
+       if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
+               if (!strncmp(buf, "From ", sizeof("From ")-1) ||
+                   strstr(buf, "\nFrom ") != NULL) {
+                       encoding = ENC_QUOTED_PRINTABLE;
+               }
+       }
+
        mimetext = procmime_mimeinfo_new();
        mimetext->content = MIMECONTENT_MEM;
        mimetext->data.mem = buf;
@@ -3675,7 +3660,10 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
        /* protect trailing spaces when signing message */
        if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && 
            privacy_system_can_sign(compose->privacy_system))
-               encoding = ENC_QUOTED_PRINTABLE;
+               if (encoding == ENC_7BIT)
+                       encoding = ENC_QUOTED_PRINTABLE;
+               else if (encoding == ENC_8BIT)
+                       encoding = ENC_BASE64;
        if (encoding != ENC_UNKNOWN)
                procmime_encode_content(mimetext, encoding);
 
@@ -3735,9 +3723,9 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        gtk_text_buffer_get_end_iter(buffer, &end);
        tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
 
-       src_codeset = CS_UTF_8;
-       dest_codeset = conv_get_current_charset_str();
-       chars = conv_codeset_strdup(tmp, src_codeset, dest_codeset);
+       chars = conv_codeset_strdup
+               (tmp, CS_INTERNAL, conv_get_locale_charset_str());
+
        g_free(tmp);
        if (!chars) return -1;
 
@@ -4453,8 +4441,6 @@ static void compose_create_header_entry(Compose *compose)
        g_signal_connect(G_OBJECT(entry), "changed", 
                         G_CALLBACK(compose_headerentry_changed_cb), 
                         headerentry);
-       g_signal_connect(G_OBJECT(entry), "activate", 
-                        G_CALLBACK(text_activated), compose);
        g_signal_connect(G_OBJECT(entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_before_cb), compose);
        g_signal_connect_after(G_OBJECT(entry), "grab_focus",
@@ -4814,7 +4800,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        gchar *titles[N_ATTACH_COLS];
        guint n_menu_entries;
-       GtkStyle  *style, *new_style;
        GdkColormap *cmap;
        GdkColor color[1];
        gboolean success[1];
@@ -4919,8 +4904,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        subject_entry = gtk_entry_new();
        gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
-       g_signal_connect(G_OBJECT(subject_entry), "activate", 
-                        G_CALLBACK(text_activated), compose);
        g_signal_connect(G_OBJECT(subject_entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_before_cb), compose);
        g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
@@ -4940,13 +4923,14 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        ruler = gtk_shruler_new();
        gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
        gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
-                          BORDER_WIDTH + 1);
-       gtk_widget_set_size_request(ruler_hbox, 1, -1);
+                          BORDER_WIDTH);
 
        /* text widget */
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
+                                           GTK_SHADOW_IN);
        gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
        gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
 
@@ -4966,7 +4950,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                         G_CALLBACK(compose_changed_cb), compose);
        g_signal_connect(G_OBJECT(text), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
-       g_signal_connect(G_OBJECT(buffer), "insert-text",
+       g_signal_connect(G_OBJECT(buffer), "insert_text",
                         G_CALLBACK(text_inserted), compose);
 
        /* drag and drop */
@@ -4989,29 +4973,24 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_paned_add2(GTK_PANED(paned), edit_vbox);
        gtk_widget_show_all(paned);
 
-       style = gtk_widget_get_style(text);
-
-       new_style = gtk_style_copy(style);
 
        if (prefs_common.textfont) {
                PangoFontDescription *font_desc;
 
                font_desc = pango_font_description_from_string
-                                       (prefs_common.textfont);
+                       (prefs_common.textfont);
                if (font_desc) {
-                       if (new_style->font_desc)
-                               pango_font_description_free
-                                       (new_style->font_desc);
-                       new_style->font_desc = font_desc;
+                       gtk_widget_modify_font(text, font_desc);
+                       pango_font_description_free(font_desc);
                }
        }
 
-       gtk_widget_set_style(text, new_style);
-
        color[0] = quote_color;
        cmap = gdk_window_get_colormap(window->window);
        gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
        if (success[0] == FALSE) {
+               GtkStyle *style;
+
                g_warning("Compose: color allocation failed.\n");
                style = gtk_widget_get_style(text);
                quote_color = style->black;
@@ -5106,7 +5085,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                    strcmp(prefs_common.dictionary, _("None"))) {
                        gtkaspell = gtkaspell_new(prefs_common.aspell_path,
                                                  prefs_common.dictionary,
-                                                 conv_get_current_charset_str(),
+                                                 conv_get_locale_charset_str(),
                                                  prefs_common.misspelled_col,
                                                  prefs_common.check_while_typing,
                                                  prefs_common.use_alternate,
@@ -5887,8 +5866,8 @@ static void compose_attach_property_create(gboolean *cancelled)
        SET_LABEL_AND_ENTRY(_("Path"),      path_entry,     2);
        SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
 
-       gtkut_button_set_create_stock(&hbbox, &ok_btn, GTK_STOCK_OK,
-                                     &cancel_btn, GTK_STOCK_CANCEL, 
+       gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
+                                     &cancel_btn, GTK_STOCK_CANCEL,
                                      NULL, NULL);
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_btn);
@@ -6245,12 +6224,6 @@ static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
        }
 }
 
-static gint calc_cursor_xpos(GtkTextView *text, gint extra, gint char_width)
-{
-#warning FIXME_GTK2
-       return 0;
-}
-
 /* callback functions */
 
 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
@@ -6272,10 +6245,7 @@ static gboolean compose_edit_size_alloc(GtkEditable *widget,
 
                /* got the maximum */
                gtk_ruler_set_range(GTK_RULER(shruler),
-                                   0.0, line_width_in_chars,
-                                   calc_cursor_xpos(GTK_TEXT_VIEW(widget),
-                                                    allocation->x,
-                                                    char_width),
+                                   0.0, line_width_in_chars, 0,
                                    /*line_width_in_chars*/ char_width);
        }
 
@@ -6528,9 +6498,11 @@ static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
 
                for ( tmp = file_list; tmp; tmp = tmp->next) {
                        gchar *file = (gchar *) tmp->data;
-                       compose_attach_append(compose, file, file, NULL);
+                       gchar *utf8_filename = conv_filename_to_utf8(file);
+                       compose_attach_append(compose, file, utf8_filename, NULL);
                        compose_changed_cb(NULL, compose);
                        g_free(file);
+                       g_free(utf8_filename);
                }
                g_list_free(file_list);
        }               
@@ -6605,7 +6577,7 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
        if (compose->modified) {
                val = alertpanel(_("Discard message"),
                                 _("This message has been modified. discard it?"),
-                                _("Discard"), _("to Draft"), _("Cancel"));
+                                _("Discard"), _("to Draft"), GTK_STOCK_CANCEL);
 
                switch (val) {
                case G_ALERTDEFAULT:
@@ -6643,7 +6615,7 @@ static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
        msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
                              tmpl->name);
        val = alertpanel(_("Apply template"), msg,
-                        _("Replace"), _("Insert"), _("Cancel"));
+                        _("Replace"), _("Insert"), GTK_STOCK_CANCEL);
        g_free(msg);
 
        if (val == G_ALERTDEFAULT)
@@ -6883,7 +6855,6 @@ static void textview_move_next_line (GtkTextView *text)
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
        mark = gtk_text_buffer_get_insert(buffer);
        gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
-#warning FIXME_GTK2 /* should regist current line offset */
        offset = gtk_text_iter_get_line_offset(&ins);
        if (gtk_text_iter_forward_line(&ins)) {
                gtk_text_iter_set_line_offset(&ins, offset);
@@ -6903,7 +6874,6 @@ static void textview_move_previous_line (GtkTextView *text)
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
        mark = gtk_text_buffer_get_insert(buffer);
        gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
-#warning FIXME_GTK2 /* should regist current line offset */
        offset = gtk_text_iter_get_line_offset(&ins);
        if (gtk_text_iter_backward_line(&ins)) {
                gtk_text_iter_set_line_offset(&ins, offset);
@@ -7403,18 +7373,19 @@ static void compose_show_first_last_header(Compose *compose, gboolean show_first
        gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
 }
 
-static void text_activated(GtkWidget *widget, Compose *compose)
-{
-       compose_send_control_enter(compose);
-}
-
 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                          const gchar *text, gint len, Compose *compose)
 {
        gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
                                (G_OBJECT(compose->text), "paste_as_quotation"));
+       GtkTextMark *mark;
+
+       /* CLAWS: pass to default handler only if not pasting as quotation, and 
+        * no autowrap */
+       if (!paste_as_quotation && !compose->autowrap) 
+               return;
 
-       g_return_if_fail(text);
+       g_return_if_fail(text != NULL);
 
        g_signal_handlers_block_by_func(G_OBJECT(buffer),
                                        G_CALLBACK(text_inserted),
@@ -7439,8 +7410,10 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
        } else
                gtk_text_buffer_insert(buffer, iter, text, len);
 
-       if (compose->autowrap)
-               compose_wrap_line_all_full(compose, TRUE);
+       mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
+       compose_wrap_line_all_full(compose, TRUE);
+       gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
+       gtk_text_buffer_delete_mark(buffer, mark);
 
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                          G_CALLBACK(text_inserted),
@@ -7452,7 +7425,6 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                compose->draft_timeout_tag = gtk_timeout_add
                        (500, (GtkFunction) compose_defer_auto_save_draft, compose);
 }
-
 static gint compose_defer_auto_save_draft(Compose *compose)
 {
        compose->draft_timeout_tag = -1;
@@ -7460,45 +7432,6 @@ static gint compose_defer_auto_save_draft(Compose *compose)
        return FALSE;
 }
 
-static gboolean compose_send_control_enter(Compose *compose)
-{
-       GdkEvent *ev;
-       GdkEventKey *kev;
-       GtkItemFactory *ifactory;
-       GtkAccelKey *accel;
-       GtkWidget *send_menu;
-       GSList *list;
-       GdkModifierType ignored_mods =
-               (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
-                GDK_MOD4_MASK | GDK_MOD5_MASK);
-
-       ev = gtk_get_current_event();
-       if (ev->type != GDK_KEY_PRESS) return FALSE;
-
-       kev = (GdkEventKey *)ev;
-       if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
-               return FALSE;
-
-       if (compose->exteditor_tag != -1)
-               return FALSE;
-
-       ifactory = gtk_item_factory_from_widget(compose->menubar);
-       send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
-       list = gtk_accel_groups_from_object(G_OBJECT(send_menu));
-       if (!list)
-               return FALSE;
-
-       accel = (GtkAccelKey *)list->data;
-       if (accel && accel->accel_key == kev->keyval &&
-           (accel->accel_mods & ~ignored_mods) ==
-           (kev->state & ~ignored_mods)) {
-               compose_send_cb(compose, 0, NULL);
-               return TRUE;
-       }
-
-       return FALSE;
-}
-
 #if USE_ASPELL
 static void compose_check_all(Compose *compose)
 {
@@ -7601,7 +7534,44 @@ static void compose_add_field_list( Compose *compose, GList *listAddress ) {
        }
 }
 
+void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list, 
+                                   guint action)
+{
+       gchar *body;
+       GSList *new_msglist = NULL;
+       MsgInfo *tmp_msginfo = NULL;
+       
+       g_return_if_fail(msgview != NULL);
+
+       g_return_if_fail(msginfo_list != NULL);
+
+       if (g_slist_length(msginfo_list) == 1) {
+               MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
+               MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
+               
+               if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE && 
+                   !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
+                       
+                       tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
+                                               orig_msginfo, mimeinfo);
+                       if (tmp_msginfo != NULL) {
+                               new_msglist = g_slist_append(NULL, tmp_msginfo);
+                       } 
+               }
+       }
+
+       body = messageview_get_selection(msgview);
+
+       if (new_msglist) {
+               compose_reply_mode((ComposeMode)action, new_msglist, body);
+               procmsg_msginfo_free(tmp_msginfo);
+               g_slist_free(new_msglist);
+       } else
+               compose_reply_mode((ComposeMode)action, msginfo_list, body);
+
+       g_free(body);
+}
+
 /*
  * End of Source.
  */
-