2005-02-15 [colin] 1.0.1cvs7.1
[claws.git] / src / compose.c
index af899870255e906c2dad99a18d7f41697e00c86f..07a9a15a87352f1feac663e08c80a873fcd24aa9 100644 (file)
@@ -300,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);
@@ -2445,16 +2441,17 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        gunichar uc;                                            \
                                                                \
        uc = gtk_text_iter_get_char(iter_p);                    \
-       if (uc != 0)                                            \
+       if (uc != 0) {                                          \
                len = g_unichar_to_utf8(uc, buf) > 1 ? 2 : 1;   \
-       else {                                                  \
+               buf[len]='\0';                                  \
+       } else {                                                \
                buf[0] = '\0';                                  \
                len = 1;                                        \
        }                                                       \
 }
 #define DISP_WIDTH(len) \
-       ((len > 2 && conv_get_locale_charset() == C_UTF_8) ? 2 : \
-        (len == 2 && conv_get_locale_charset() == C_UTF_8) ? 1 : len)
+       ((len > 2) ? 2 : \
+        (len == 2) ? 1 : len)
 
 #define SPACE_CHARS    " \t"
 
@@ -2591,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);
@@ -2619,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);
        }
 }
 
@@ -2987,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 ? */
@@ -3103,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) {
@@ -3625,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;
@@ -3653,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;
@@ -3663,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);
 
@@ -4940,10 +4940,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
        clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
        gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
-       clipboard = gtk_clipboard_get(GDK_SELECTION_SECONDARY);
-       gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
-       clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
-       gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
        
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
 
@@ -6228,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
@@ -6255,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);
        }
 
@@ -6868,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);
@@ -6888,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);