2005-02-21 [paul] 1.0.1cvs15.2
authorPaul Mangan <paul@claws-mail.org>
Mon, 21 Feb 2005 10:18:27 +0000 (10:18 +0000)
committerPaul Mangan <paul@claws-mail.org>
Mon, 21 Feb 2005 10:18:27 +0000 (10:18 +0000)
* po/Makefile.in.in
* src/compose.c
* src/summaryview.c
* src/textview.c
* src/common/utils.c
* src/common/utils.h
sync with main (revision 117)

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
po/Makefile.in.in
src/common/utils.c
src/common/utils.h
src/compose.c
src/summaryview.c
src/textview.c

index b3f0b6c..69b0f0e 100644 (file)
@@ -1,3 +1,13 @@
+2005-02-21 [paul]      1.0.1cvs15.2
+
+       * po/Makefile.in.in
+       * src/compose.c
+       * src/summaryview.c
+       * src/textview.c
+       * src/common/utils.c
+       * src/common/utils.h
+               sync with main (revision 117)
+
 2005-02-20 [colin]     1.0.1cvs151
 
        * src/common/defs.h
index 3e1216e..9c002eb 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.207.2.30 -r 1.207.2.31 src/folderview.c; ) > 1.0.1cvs11.6.patchset
 ( cvs diff -u -r 1.8.2.1 -r 1.8.2.2 src/quote_fmt_lex.l; cvs diff -u -r 1.22.2.6 -r 1.22.2.7 src/quote_fmt_parse.y; ) > 1.0.1cvs14.1.patchset
 ( cvs diff -u -r 1.9.2.9 -r 1.9.2.10 src/common/defs.h; ) > 1.0.1cvs151.patchset
+( cvs diff -u -r 1.6.2.4 -r 1.6.2.5 po/Makefile.in.in; cvs diff -u -r 1.382.2.103 -r 1.382.2.104 src/compose.c; cvs diff -u -r 1.395.2.53 -r 1.395.2.54 src/summaryview.c; cvs diff -u -r 1.96.2.47 -r 1.96.2.48 src/textview.c; cvs diff -u -r 1.36.2.25 -r 1.36.2.26 src/common/utils.c; cvs diff -u -r 1.20.2.13 -r 1.20.2.14 src/common/utils.h; ) > 1.0.1cvs15.2.patchset
index c215ace..c24e7da 100644 (file)
@@ -13,7 +13,7 @@ INTERFACE_AGE=0
 BINARY_AGE=0
 EXTRA_VERSION=15
 EXTRA_RELEASE=
-EXTRA_GTK2_VERSION=.1
+EXTRA_GTK2_VERSION=.2
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}${EXTRA_RELEASE}${EXTRA_GTK2_VERSION}
index 75d72db..c247a95 100644 (file)
@@ -74,11 +74,11 @@ INSTOBJEXT = @INSTOBJEXT@
        $(MSGMERGE) $< $(srcdir)/$(GETTEXT_PACKAGE).pot -o $*.pox
 
 .po.mo:
-       $(MSGFMT) -o $@ $<
+       $(MSGFMT) -c -o $@ $<
 
 .po.gmo:
        file=$(srcdir)/`echo $* | sed 's,.*/,,'`.gmo \
-         && rm -f $$file && $(GMSGFMT) -o $$file $<
+         && rm -f $$file && $(GMSGFMT) -c --statistics -o $$file $<
 
 .po.cat:
        sed -f ../intl/po2msg.sed < $< > $*.msg \
index e339b77..213c45b 100644 (file)
@@ -1543,6 +1543,21 @@ gchar *get_uri_path(const gchar *uri)
                return (gchar *)uri;
 }
 
+gint get_uri_len(const gchar *str)
+{
+       const gchar *p;
+
+       if (is_uri_string(str)) {
+               for (p = str; *p != '\0'; p++) {
+                       if (!g_ascii_isgraph(*p) || strchr("()<>\"", *p))
+                               break;
+               }
+               return p - str;
+       }
+
+       return 0;
+}
+
 /* Decodes URL-Encoded strings (i.e. strings in which spaces are replaced by
  * plusses, and escape characters are used)
  */
index faeb711..a0bc871 100644 (file)
@@ -340,6 +340,7 @@ gchar *trim_string                  (const gchar    *str,
 GList *uri_list_extract_filenames      (const gchar    *uri_list);
 gboolean is_uri_string                 (const gchar    *str);
 gchar *get_uri_path                    (const gchar    *uri);
+gint get_uri_len                       (const gchar    *str);
 void decode_uri                                (gchar          *decoded_uri,
                                         const gchar    *encoded_uri);
 gint scan_mailto_url                   (const gchar    *mailto,
index fde2a2b..de932df 100644 (file)
 
 #include "defs.h"
 
+#ifndef PANGO_ENABLE_ENGINE
+#  define PANGO_ENABLE_ENGINE
+#endif
+
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
@@ -53,6 +57,7 @@
 
 #include <gtk/gtkdnd.h>
 #include <gtk/gtkclipboard.h>
+#include <pango/pango-break.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -220,21 +225,26 @@ static void compose_reply_set_entry               (Compose        *compose,
                                                 followup_and_reply_to);
 static void compose_reedit_set_entry           (Compose        *compose,
                                                 MsgInfo        *msginfo);
+
 static void compose_insert_sig                 (Compose        *compose,
                                                 gboolean        replace);
 static gchar *compose_get_signature_str                (Compose        *compose);
 static ComposeInsertResult compose_insert_file (Compose        *compose,
                                                 const gchar    *file);
+
 static void compose_attach_append              (Compose        *compose,
                                                 const gchar    *file,
                                                 const gchar    *type,
                                                 const gchar    *content_type);
 static void compose_attach_parts               (Compose        *compose,
                                                 MsgInfo        *msginfo);
-static void compose_wrap_line                  (Compose        *compose);
-static void compose_wrap_line_all              (Compose        *compose);
-static void compose_wrap_line_all_full         (Compose        *compose,
+
+static void compose_wrap_paragraph             (Compose        *compose,
+                                                GtkTextIter    *par_iter);
+static void compose_wrap_all                   (Compose        *compose);
+static void compose_wrap_all_full              (Compose        *compose,
                                                 gboolean        autowrap);
+
 static void compose_set_title                  (Compose        *compose);
 static void compose_select_account             (Compose        *compose,
                                                 PrefsAccount   *account,
@@ -385,6 +395,9 @@ static void compose_grab_focus_before_cb(GtkWidget  *widget,
 static void compose_changed_cb         (GtkTextBuffer  *textbuf,
                                         Compose        *compose);
 
+static void compose_wrap_cb            (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
 static void compose_toggle_autowrap_cb (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -625,9 +638,9 @@ static GtkItemFactoryEntry compose_entries[] =
                                        NULL},
        {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
        {N_("/_Edit/_Wrap current paragraph"),
-                                       "<control>L", compose_wrap_line, 0, NULL},
+                                       "<control>L", compose_wrap_cb, 0, NULL},
        {N_("/_Edit/Wrap all long _lines"),
-                                       "<control><alt>L", compose_wrap_line_all, 0, NULL},
+                                       "<control><alt>L", compose_wrap_cb, 1, NULL},
        {N_("/_Edit/Aut_o wrapping"),   "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
        {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
        {N_("/_Edit/Edit with e_xternal editor"),
@@ -1031,7 +1044,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        gtk_text_buffer_place_cursor(textbuf, &iter);
        
        if (quote && prefs_common.linewrap_quote)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        gtk_widget_grab_focus(compose->text);
 
@@ -1125,7 +1138,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        gtk_text_buffer_get_start_iter(textbuf, &iter);
        gtk_text_buffer_place_cursor(textbuf, &iter);
@@ -1203,7 +1216,7 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
                compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        gtk_text_buffer_get_start_iter(textbuf, &iter);
        gtk_text_buffer_place_cursor(textbuf, &iter);
@@ -1553,10 +1566,10 @@ void compose_toolbar_cb(gint action, gpointer data)
                compose_ext_editor_cb(compose, 0, NULL);
                break;
        case A_LINEWRAP_CURRENT:
-               compose_wrap_line(compose);
+               compose_wrap_paragraph(compose, NULL);
                break;
        case A_LINEWRAP_ALL:
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
                break;
        case A_ADDRBOOK:
                compose_address_cb(compose, 0, NULL);
@@ -2431,338 +2444,170 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        procmime_mimeinfo_free_all(mimeinfo);
 }
 
-  
-#define CHAR_BUF_SIZE 8
 #undef NEXT_PART_NOT_CHILD
 
 
-#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) ? 2 : \
-        (len == 2) ? 1 : len)
-
-#define SPACE_CHARS    " \t"
-
-static void compose_wrap_line(Compose *compose)
-{
-       GtkTextView *text = GTK_TEXT_VIEW(compose->text);
-       GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
-       GtkTextMark *mark;
-       GtkTextIter insert_iter, iter;
-       gint ch_len, last_ch_len;
-       gchar cbuf[CHAR_BUF_SIZE], last_ch;
-       guint text_len;
-       gint p_start, p_end;
-       gint line_pos, cur_pos;
-       gint line_len, cur_len;
-       gboolean line_end, quoted;
-
-       text_len = gtk_text_buffer_get_char_count(textbuf);
-       mark = gtk_text_buffer_get_insert(textbuf);
-       gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
-       cur_pos = gtk_text_iter_get_offset(&insert_iter);
-       GET_CHAR(&insert_iter, cbuf, ch_len);
-       if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
-               GtkTextIter prev_iter;
-               if (cur_pos == 0)
-                       return; /* on the paragraph mark */
-               prev_iter = insert_iter;
-               gtk_text_iter_backward_char(&prev_iter);
-               GET_CHAR(&prev_iter, cbuf, ch_len);
-               if (ch_len == 1 && *cbuf == '\n')
-                       return; /* on the paragraph mark */
-       }
-
-       /* find paragraph start. */
-       line_end = quoted = FALSE;
-       for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
-               GET_CHAR(&iter, cbuf, ch_len);
-               if (ch_len == 1 && *cbuf == '\n') {
-                       if (quoted)
-                               return; /* quoted part */
-                       if (line_end) {
-                               gtk_text_iter_forward_chars(&iter, 2);
-                               break;
-                       }
-                       line_end = TRUE;
-               } else {
-                       if (ch_len == 1 
-                           && strchr(prefs_common.quote_chars, *cbuf))
-                               quoted = 1;
-                       else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
-                               quoted = 0;
-
-                       line_end = FALSE;
-               }
-       }
-       p_start = gtk_text_iter_get_offset(&iter);
-
-       /* find paragraph end. */
-       line_end = FALSE;
-       for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
-               GET_CHAR(&iter, cbuf, ch_len);
-               if (ch_len == 1 && *cbuf == '\n') {
-                       if (line_end) {
-                               p_end -= 1;
-                               gtk_text_iter_backward_char(&iter);
-                               break;
-                       }
-                       line_end = TRUE;
-               } else {
-                       if (line_end && ch_len == 1 &&
-                           strchr(prefs_common.quote_chars, *cbuf))
-                               return; /* quoted part */
-
-                       line_end = FALSE;
-               }
-       }
-       p_end = gtk_text_iter_get_offset(&iter);
-
-       if (p_end >= text_len)
-               p_end = text_len;
-
-       if (p_start >= p_end)
-               return;
-
-       line_len = cur_len = 0;
-       last_ch_len = 0;
-       last_ch = '\0';
-       line_pos = p_start;
-       for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
-               gboolean space = FALSE;
-
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
-
-               GET_CHAR(&iter, cbuf, ch_len);
-
-               if (ch_len < 0) {
-                       cbuf[0] = '\0';
-                       ch_len = 1;
-               }
-
-               if (ch_len == 1 && isspace(*(guchar *)cbuf))
-                       space = 1;
-
-               if (ch_len == 1 && *cbuf == '\n') {
-                       gboolean replace = FALSE;
-                       GtkTextIter next_iter = iter;
-
-                       gtk_text_iter_forward_char(&next_iter);
-
-                       if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
-                               if (cur_pos + 1 < p_end) {
-                                       GET_CHAR(&next_iter, cbuf, ch_len);
-                                       if (ch_len == 1 &&
-                                           !isspace(*(guchar *)cbuf))
-                                               replace = TRUE;
-                               }
-                       }
-                       gtk_text_buffer_delete(textbuf, &iter, &next_iter);
-                       if (replace) {
-                               gtk_text_buffer_insert(textbuf, &iter, " ", 1);
-                               space = TRUE;
-                       }
-                       else {
-                               p_end--;
-                               cur_pos--;
-                               gtk_text_buffer_get_iter_at_offset
-                                       (textbuf, &iter, cur_pos);
-                               continue;
-                       }
-               }
-
-               last_ch_len = ch_len;
-               last_ch = *cbuf;
-
-               if (space) {
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len + DISP_WIDTH(ch_len);
-               }
-
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
-
-               if (cur_len + ch_len > prefs_common.linewrap_len &&
-                   line_len > 0) {
-                       gint tlen = ch_len;
-                       GtkTextIter prev_iter = iter;
-
-                       gtk_text_iter_backward_char(&prev_iter);
-
-                       GET_CHAR(&prev_iter, cbuf, ch_len);
-                       if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
-                               gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
-                               iter = prev_iter;
-                               p_end--;
-                               cur_pos--;
-                               line_pos--;
-                               cur_len--;
-                               line_len--;
-                       }
-                       ch_len = tlen;
-
-                       gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
-                       p_end++;
-                       cur_pos++;
-                       line_pos++;
-                       cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
-                       line_len = 0;
-                       continue;
-               }
-
-               cur_len += DISP_WIDTH(ch_len);
-       }
-}
-
-#undef WRAP_DEBUG
-#ifdef WRAP_DEBUG
-/* Darko: used when I debug wrapping */
-void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
-{
-       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; ) {
-               GET_CHAR(&iter, cbuf, clen);
-               if (clen < 0) break;
-               if (breakoncr && clen == 1 && cbuf[0] == '\n')
-                       break;
-               fwrite(cbuf, clen, 1, stdout);
-       }
-       printf("]\n");
-}
-#endif
 
 typedef enum {
-       WAIT_FOR_SPACE,
        WAIT_FOR_INDENT_CHAR,
-       WAIT_FOR_INDENT_CHAR_OR_SPACE
+       WAIT_FOR_INDENT_CHAR_OR_SPACE,
 } IndentState;
 
 /* return indent length, we allow:
-   > followed by spaces/tabs
-   | followed by spaces/tabs
-   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)
-{
-       GtkTextIter iter;
-       guint i_len = 0;
-       guint ch_len, alnum_cnt = 0;
+   indent characters followed by indent characters or spaces/tabs,
+   alphabets and numbers immediately followed by indent characters,
+   and the repeating sequences of the above
+   If quote ends with multiple spaces, only the first one is included. */
+static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
+                                   const GtkTextIter *start, gint *len)
+{
+       GtkTextIter iter = *start;
+       gunichar wc;
+       gchar ch[6];
+       gint clen;
        IndentState state = WAIT_FOR_INDENT_CHAR;
-       gchar cbuf[CHAR_BUF_SIZE];
        gboolean is_space;
        gboolean is_indent;
-       gboolean iter_next = TRUE;
+       gint alnum_count = 0;
+       gint space_count = 0;
+       gint quote_len = 0;
 
        if (prefs_common.quote_chars == NULL) {
                return 0 ;
        }
 
-       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos);
-
-       while (iter_next == TRUE) {
-               GET_CHAR(&iter, cbuf, ch_len);
-               if (ch_len > 1)
+       while (!gtk_text_iter_ends_line(&iter)) {
+               wc = gtk_text_iter_get_char(&iter);
+               if (g_unichar_iswide(wc))
                        break;
-
-               if (cbuf[0] == '\n')
+               clen = g_unichar_to_utf8(wc, ch);
+               if (clen != 1)
                        break;
 
-               is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
-               is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
+               is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
+               is_space = g_unichar_isspace(wc);
 
-               switch (state) {
-               case WAIT_FOR_SPACE:
-                       if (is_space == FALSE)
-                               goto out;
-                       state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
-                       break;
-               case WAIT_FOR_INDENT_CHAR_OR_SPACE:
-                       if (is_indent == FALSE && is_space == FALSE &&
-                           !isupper((guchar)cbuf[0]))
-                               goto out;
-                       if (is_space == TRUE) {
-                               alnum_cnt = 0;
+               if (state == WAIT_FOR_INDENT_CHAR) {
+                       if (!is_indent && !g_unichar_isalnum(wc))
+                               break;
+                       if (is_indent) {
+                               quote_len += alnum_count + space_count + 1;
+                               alnum_count = space_count = 0;
                                state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
-                       } else if (is_indent == TRUE) {
-                               alnum_cnt = 0;
-                               state = WAIT_FOR_SPACE;
+                       } else
+                               alnum_count++;
+               } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
+                       if (!is_indent && !is_space && !g_unichar_isalnum(wc))
+                               break;
+                       if (is_space)
+                               space_count++;
+                       else if (is_indent) {
+                               quote_len += alnum_count + space_count + 1;
+                               alnum_count = space_count = 0;
                        } else {
-                               alnum_cnt++;
+                               alnum_count++;
                                state = WAIT_FOR_INDENT_CHAR;
                        }
-                       break;
-               case WAIT_FOR_INDENT_CHAR:
-                       if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
-                               goto out;
-                       if (is_indent == TRUE) {
-                               if (alnum_cnt > 0 
-                                   && !strchr(prefs_common.quote_chars, cbuf[0]))
-                                       goto out;
-                               alnum_cnt = 0;
-                               state = WAIT_FOR_SPACE;
-                       } else {
-                               alnum_cnt++;
-                       }
-                       break;
                }
 
-               i_len++;
-               iter_next = gtk_text_iter_forward_char(&iter);
+               gtk_text_iter_forward_char(&iter);
        }
 
-out:
-       if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
-               i_len -= alnum_cnt;
+       if (quote_len > 0 && space_count > 0)
+               quote_len++;
+
+       if (len)
+               *len = quote_len;
+
+       if (quote_len > 0) {
+               iter = *start;
+               gtk_text_iter_forward_chars(&iter, quote_len);
+               return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
+       }
 
-       return i_len;
+       return NULL;
 }
 
-/* insert quotation string when line was wrapped */
-static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
-                      guint indent_len,
-                      guint prev_line_pos, guint text_len,
-                      gchar *quote_fmt)
+static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
+                                          const GtkTextIter *start,
+                                          GtkTextIter *break_pos,
+                                          gint max_col,
+                                          gint quote_len)
 {
-       guint ins_len = 0;
+       GtkTextIter iter = *start, line_end = *start;
+       PangoLogAttr *attrs;
+       gchar *str;
+       gchar *p;
+       gint len;
+       gint i;
+       gint col = 0;
+       gint pos = 0;
+       gboolean can_break = FALSE;
+       gboolean do_break = FALSE;
 
-       if (indent_len) {
-               GtkTextIter iter1, iter2;
-               gchar *text;
+       gtk_text_iter_forward_to_line_end(&line_end);
+       str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
+       len = g_utf8_strlen(str, -1);
+       /* g_print("breaking line: %d: %s (len = %d)\n",
+               gtk_text_iter_get_line(&iter), str, len); */
+       attrs = g_new(PangoLogAttr, len + 1);
+
+       pango_default_break(str, -1, NULL, attrs, len + 1);
+
+       p = str;
+
+       /* skip quote and leading spaces */
+       for (i = 0; *p != '\0' && i < len; i++) {
+               gunichar wc;
+
+               wc = g_utf8_get_char(p);
+               if (i >= quote_len && !g_unichar_isspace(wc))
+                       break;
+               col += g_unichar_iswide(wc) ? 2 : 1;
+               p = g_utf8_next_char(p);
+       }
+
+       for (; *p != '\0' && i < len; i++) {
+               PangoLogAttr *attr = attrs + i;
+               gunichar wc;
+               gint uri_len;
 
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
-                                                  prev_line_pos);
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
-                                                  prev_line_pos + indent_len);
-               text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
-               if (!text) return 0;
+               if (attr->is_line_break && can_break)
+                       pos = i;
+
+               /* don't wrap URI */
+               if ((uri_len = get_uri_len(p)) > 0) {
+                       col += uri_len;
+                       if (pos > 0 && col > max_col) {
+                               do_break = TRUE;
+                               break;
+                       }
+                       i += uri_len - 1;
+                       p += uri_len;
+                       can_break = TRUE;
+                       continue;
+               }
 
-               gtk_text_buffer_insert(textbuf, iter, text, -1);
-               ins_len = g_utf8_strlen(text, -1);
+               wc = g_utf8_get_char(p);
+               col += g_unichar_iswide(wc) ? 2 : 1;
+               if (pos > 0 && col > max_col) {
+                       do_break = TRUE;
+                       break;
+               }
 
-               g_free(text);
+               p = g_utf8_next_char(p);
+               can_break = TRUE;
        }
 
-       return ins_len;
+       debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
+
+       g_free(attrs);
+       g_free(str);
+
+       *break_pos = *start;
+       gtk_text_iter_set_line_offset(break_pos, pos);
+
+       return do_break;
 }
 
 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos) 
@@ -2794,321 +2639,172 @@ static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint
        return FALSE;
 }
 
-/* check if we should join the next line */
-static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
-                                        guint start_pos, guint tlen,
-                                        guint prev_ilen, gboolean autowrap)
+static gboolean compose_join_next_line(GtkTextBuffer *buffer,
+                                      GtkTextIter *iter,
+                                      const gchar *quote_str)
 {
-       guint indent_len, ch_len;
-       gboolean do_join = FALSE;
-       gchar cbuf[CHAR_BUF_SIZE];
+       GtkTextIter iter_ = *iter, cur, prev, next;
+       PangoLogAttr attrs[3];
+       gchar *str;
+       gchar *next_quote_str;
+       gunichar wc1, wc2;
+       gint quote_len;
 
-       indent_len = get_indent_length(textbuf, start_pos, tlen);
+       if (!gtk_text_iter_forward_line(&iter_) ||
+           gtk_text_iter_ends_line(&iter_))
+               return FALSE;
 
-       if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
-               GtkTextIter iter;
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
-                                                  start_pos + indent_len);
-               GET_CHAR(&iter, cbuf, ch_len);
-               
-               if (ch_len > 0 && (cbuf[0] != '\n'))
-                       do_join = TRUE;
+       next_quote_str = compose_get_quote_str(buffer, &iter_, &quote_len);
+
+       if ((quote_str || next_quote_str) &&
+           strcmp2(quote_str, next_quote_str) != 0) {
+               g_free(next_quote_str);
+               return FALSE;
        }
+       g_free(next_quote_str);
 
-       return do_join;
-}
+       /* delete quote str */
+       if (quote_len > 0) {
+               GtkTextIter end = iter_;
 
-static void compose_wrap_line_all(Compose *compose)
-{
-       compose_wrap_line_all_full(compose, FALSE);
+               gtk_text_iter_forward_chars(&end, quote_len);
+               if (gtk_text_iter_ends_line(&end))
+                       return FALSE;
+               gtk_text_buffer_delete(buffer, &iter_, &end);
+       }
+
+       /* delete linebreak and extra spaces */
+       prev = cur = iter_;
+       while (gtk_text_iter_backward_char(&cur)) {
+               wc1 = gtk_text_iter_get_char(&cur);
+               if (!g_unichar_isspace(wc1))
+                       break;
+               prev = cur;
+       }
+       next = cur = iter_;
+       while (!gtk_text_iter_ends_line(&cur)) {
+               wc1 = gtk_text_iter_get_char(&cur);
+               if (!g_unichar_isspace(wc1))
+                       break;
+               gtk_text_iter_forward_char(&cur);
+               next = cur;
+       }
+       if (!gtk_text_iter_equal(&prev, &next))
+               gtk_text_buffer_delete(buffer, &prev, &next);
+       iter_ = prev;
+
+       /* insert space if required */
+       gtk_text_iter_backward_char(&prev);
+       wc1 = gtk_text_iter_get_char(&prev);
+       wc2 = gtk_text_iter_get_char(&next);
+       gtk_text_iter_forward_char(&next);
+       str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
+       pango_default_break(str, -1, NULL, attrs, 3);
+       if (!attrs[1].is_line_break ||
+           (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2)))
+               gtk_text_buffer_insert(buffer, &iter_, " ", 1);
+       g_free(str);
+
+       *iter = iter_;
+       return TRUE;
 }
 
-static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
+static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter)
 {
        GtkTextView *text = GTK_TEXT_VIEW(compose->text);
-       GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
-       GtkTextIter iter, end_iter;
-       guint tlen;
-       guint line_pos = 0, cur_pos = 0, p_pos = 0;
-       gint line_len = 0, cur_len = 0;
-       gint ch_len;
-       gboolean is_new_line = TRUE, do_delete = FALSE;
-       guint i_len = 0;
-       gboolean linewrap_quote = prefs_common.linewrap_quote;
-       gboolean set_editable_pos = FALSE;
-       gint editable_pos = 0;
-       guint linewrap_len = prefs_common.linewrap_len;
-       gchar *qfmt = prefs_common.quotemark;
-       gchar cbuf[CHAR_BUF_SIZE];
-       GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
-       
-       tlen = gtk_text_buffer_get_char_count(textbuf);
-
-       for (; cur_pos < tlen; cur_pos++) {
-               /* mark position of new line - needed for quotation wrap */
-               if (is_new_line) {
-                       if (linewrap_quote)
-                               i_len = get_indent_length(textbuf, cur_pos, tlen);
-
-                       is_new_line = FALSE;
-                       p_pos = cur_pos;
-               }
+       GtkTextBuffer *buffer;
+       GtkTextIter iter, break_pos;
+       gchar *quote_str = NULL;
+       gint quote_len;
+       gboolean wrap_quote = prefs_common.linewrap_quote;
 
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
-               GET_CHAR(&iter, cbuf, ch_len);
+       buffer = gtk_text_view_get_buffer(text);
 
-               /* fix line length for tabs */
-               if (ch_len == 1 && *cbuf == '\t') {
-                       guint tab_width = 8;
-                       guint tab_offset = line_len % tab_width;
+       if (par_iter) {
+               iter = *par_iter;
+       } else {
+               GtkTextMark *mark;
+               mark = gtk_text_buffer_get_insert(buffer);
+               gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
+       }
 
-                       line_len += tab_width - tab_offset - 1;
-                       cur_len = line_len;
+       /* move to paragraph start */
+       gtk_text_iter_set_line_offset(&iter, 0);
+       if (gtk_text_iter_ends_line(&iter)) {
+               while (gtk_text_iter_ends_line(&iter) &&
+                      gtk_text_iter_forward_line(&iter))
+                       ;
+       } else {
+               while (gtk_text_iter_backward_line(&iter)) {
+                       if (gtk_text_iter_ends_line(&iter)) {
+                               gtk_text_iter_forward_line(&iter);
+                               break;
+                       }
                }
+       }
 
-               /* we have encountered line break */
-               if (ch_len == 1 && *cbuf == '\n') {
-                       gint clen;
-                       gchar cb[CHAR_BUF_SIZE];
-
-                       /* should we join the next line */
-                       if ((autowrap || i_len != cur_len) && do_delete &&
-                       !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
-                           join_next_line_is_needed
-                               (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
-                               do_delete = TRUE;
-                       } else
-                               do_delete = FALSE;
-
-                       /* skip delete if it is continuous URL */
-                       if (do_delete && (line_pos - p_pos <= i_len) &&
-                           gtkut_text_buffer_is_uri_string(textbuf, line_pos,
-                                                           tlen))
-                               do_delete = FALSE;
-
-                       /* should we delete to perform smart wrapping */
-                       if (line_len < linewrap_len && do_delete) {
-                               /* get rid of newline */
-                               gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                                  &iter,
-                                                                  cur_pos);
-                               end_iter = iter;
-                               gtk_text_iter_forward_char(&end_iter);
-                               gtk_text_buffer_delete(textbuf, &iter, &end_iter);
-                               tlen--;
-
-                               /* if text starts with quote fmt or with
-                                  indent string, delete them */
-                               if (i_len) {
-                                       guint ilen;
-                                       ilen =  gtkut_text_buffer_str_compare_n
-                                               (textbuf, cur_pos, p_pos, i_len,
-                                                tlen);
-                                       if (ilen) {
-                                               end_iter = iter;
-                                               gtk_text_iter_forward_chars
-                                                       (&end_iter, ilen);
-                                               gtk_text_buffer_delete(textbuf,
-                                                                      &iter,
-                                                                      &end_iter);
-                                               tlen -= ilen;
-                                       }
-                               }
-
-                               gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                                  &iter,
-                                                                  cur_pos);
-                               GET_CHAR(&iter, cb, clen);
-
-                               /* insert space if it's alphanumeric */
-                               if ((cur_pos != line_pos) &&
-                                   ((clen > 1) || isalnum((guchar)cb[0]))) {
-                                       GtkTextIter cursor_iter;
-                                       gboolean go_back = FALSE;
-                                       gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
-                                       if (gtk_text_iter_get_offset(&iter) ==
-                                                gtk_text_iter_get_offset(&cursor_iter))
-                                               go_back = TRUE;
-                                       
-                                       gtk_text_buffer_insert(textbuf, &iter,
-                                                              " ", 1);
-                                       if (go_back) {
-                                               gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
-                                               gtk_text_iter_backward_chars(&cursor_iter, 1);
-                                               gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
-                                       }
-                                       tlen++;
-                               }
-
-                               /* and start over with current line */
-                               cur_pos = p_pos - 1;
-                               line_pos = cur_pos;
-                               line_len = cur_len = 0;
-                               do_delete = FALSE;
-                               is_new_line = TRUE;
-#ifdef WRAP_DEBUG
-                               g_print("after delete l_pos=");
-                               dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                               /* move beginning of line if we are on LF */
-                               gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                                  &iter,
-                                                                  line_pos);
-                               GET_CHAR(&iter, cb, clen);
-                               if (clen == 1 && *cb == '\n')
-                                       line_pos++;
-#ifdef WRAP_DEBUG
-                               g_print("new line_pos=%d\n", line_pos);
-#endif
+       if (gtk_text_iter_is_end(&iter)) {
+               if (par_iter)
+                       *par_iter = iter;
+               return;
+       }
 
+       do {
+               quote_str = compose_get_quote_str(buffer, &iter, &quote_len);
+               if (quote_str) {
+                       if (!wrap_quote) {
+                               gtk_text_iter_forward_line(&iter);
+                               g_free(quote_str);
                                continue;
                        }
-
-                       /* mark new line beginning */
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len = 0;
-                       do_delete = FALSE;
-                       is_new_line = TRUE;
-                       continue;
-               }
-
-               if (ch_len < 0) {
-                       cbuf[0] = '\0';
-                       ch_len = 1;
+                       debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
                }
 
-               /* possible line break */
-               if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len + DISP_WIDTH(ch_len);
-               }
+               if (compose_get_line_break_pos(buffer, &iter, &break_pos,
+                                              prefs_common.linewrap_len,
+                                              quote_len)) {
+                       gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
+                       if (quote_str)
+                               gtk_text_buffer_insert(buffer, &break_pos,
+                                                      quote_str, -1);
 
-               /* are we over wrapping length set in preferences ? */
-               if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
-                       gint clen;
+                       iter = break_pos;
+                       compose_join_next_line(buffer, &iter, quote_str);
 
-#ifdef WRAP_DEBUG
-                       g_print("should wrap cur_pos=%d ", cur_pos);
-                       dump_text(textbuf, p_pos, tlen, 1);
-                       dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                       /* force wrapping if it is one long word but not URL */
-                       if (line_pos - p_pos <= i_len)
-                               if (!gtkut_text_buffer_is_uri_string
-                                   (textbuf, line_pos, tlen))
-                                       line_pos = cur_pos - 1;
-#ifdef WRAP_DEBUG
-                       g_print("new line_pos=%d\n", line_pos);
-#endif
+                       /* move iter to current line start */
+                       gtk_text_iter_set_line_offset(&iter, 0);
+               } else {
+                       /* move iter to next line start */
+                       iter = break_pos;
+                       gtk_text_iter_forward_line(&iter);
+               }
 
-                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &iter,
-                                                          line_pos - 1);
-                       GET_CHAR(&iter, cbuf, clen);
-
-                       /* if next character is space delete it */
-                       if (clen == 1 && isspace(*(guchar *)cbuf)) {
-                               if (p_pos + i_len != line_pos ||
-                                   !gtkut_text_buffer_is_uri_string
-                                       (textbuf, line_pos, tlen)) {
-                                       /* workaround for correct cursor
-                                          position */
-                                       if (set_editable_pos == FALSE) {
-                                               GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
-                                               gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
-                                               editable_pos = gtk_text_iter_get_offset(&iter);
-                                               if (editable_pos == line_pos)
-                                                       set_editable_pos = TRUE;
-                                       }
-                                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &iter,
-                                                          line_pos-1);
-                                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &end_iter,
-                                                          line_pos);
-                                       gtk_text_buffer_delete(textbuf, &iter, &end_iter);
-                                       //gtk_stext_set_point(text, line_pos);
-                                       //gtk_stext_backward_delete(text, 1);
-                                       tlen--;
-                                       cur_pos--;
-                                       line_pos--;
-                                       cur_len--;
-                                       line_len--;
-                               }
-                       }
+               g_free(quote_str);
+       } while (!gtk_text_iter_ends_line(&iter));
+       /* stop if paragraph end (empty line) */
 
-                       /* if it is URL at beginning of line don't wrap */
-                       if (p_pos + i_len == line_pos &&
-                           gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
-#ifdef WRAP_DEBUG
-                               g_print("found URL at ");
-                               dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                               continue;
-                       }
+       if (par_iter)
+               *par_iter = iter;
+}
 
-                       /* insert CR */
-                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &iter,
-                                                          line_pos);
-                       gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
-                       //gtk_stext_set_point(text, line_pos);
-                       //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
-                       //gtk_stext_compact_buffer(text);
-                       tlen++;
-                       line_pos++;
-                       /* for loop will increase it */
-                       cur_pos = line_pos - 1;
-                       /* start over with current line */
-                       is_new_line = TRUE;
-                       line_len = cur_len = 0;
-                       if (autowrap || i_len > 0) {
-                               do_delete = TRUE;
-                       } else
-                               do_delete = FALSE;
-#ifdef WRAP_DEBUG
-                       g_print("after CR insert ");
-                       dump_text(textbuf, line_pos, tlen, 1);
-                       dump_text(textbuf, cur_pos, tlen, 1);
-#endif
+static void compose_wrap_all(Compose *compose)
+{
+       compose_wrap_all_full(compose, FALSE);
+}
 
-                       /* should we insert quotation ? */
-                       if (linewrap_quote && i_len) {
-                               /* only if line is not already quoted  */
-                               if (!gtkut_text_buffer_str_compare
-                                       (textbuf, line_pos, tlen, qfmt)) {
-                                       guint ins_len;
-                                       
-                                       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
-                                       
-                                       if (line_pos - p_pos > i_len) {
-                                               ins_len = ins_quote
-                                                       (textbuf, &iter, i_len, p_pos,
-                                                        tlen, qfmt);
-                                               tlen += ins_len;
-                                       }
-#ifdef WRAP_DEBUG
-                                       g_print("after quote insert ");
-                                       dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                               }
-                       }
-                       continue;
-               }
+static void compose_wrap_all_full(Compose *compose, gboolean autowrap)
+{
+       GtkTextView *text = GTK_TEXT_VIEW(compose->text);
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
 
-               /* advance to next character in buffer */
-               cur_len += DISP_WIDTH(ch_len);
-       }
+       buffer = gtk_text_view_get_buffer(text);
 
-       if (set_editable_pos && editable_pos <= tlen) {
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
-               gtk_text_buffer_place_cursor(textbuf, &iter);
-       }
+       gtk_text_buffer_get_start_iter(buffer, &iter);
+       while (!gtk_text_iter_is_end(&iter))
+               compose_wrap_paragraph(compose, &iter);
 }
 
-#undef GET_CHAR
-#undef CHAR_BUF_SIZE
-
 static void compose_set_title(Compose *compose)
 {
        gchar *str;
@@ -3837,7 +3533,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
         if (prefs_common.linewrap_at_send)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        /* write queue header */
        tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
@@ -7073,13 +6769,23 @@ static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
        }
 }
 
+static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
+{
+       Compose *compose = (Compose *)data;
+
+       if (action == 1)
+               compose_wrap_all(compose);
+       else
+               compose_wrap_paragraph(compose, NULL);
+}
+
 static void compose_toggle_autowrap_cb(gpointer data, guint action,
                                       GtkWidget *widget)
 {
        Compose *compose = (Compose *)data;
        compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
        if (compose->autowrap)
-               compose_wrap_line_all_full(compose, TRUE);
+               compose_wrap_all_full(compose, TRUE);
 }
 
 static void compose_toggle_sign_cb(gpointer data, guint action,
@@ -7412,7 +7118,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                gtk_text_buffer_insert(buffer, iter, text, len);
 
        mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
-       compose_wrap_line_all_full(compose, TRUE);
+       compose_wrap_all_full(compose, TRUE);
        gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
        gtk_text_buffer_delete_mark(buffer, mark);
 
index 0a9b8a5..244535e 100644 (file)
@@ -4236,7 +4236,7 @@ static GtkWidget *summary_ctree_create(SummaryView *summaryview)
        gtk_ctree_set_expander_style(GTK_CTREE(ctree),
                                     GTK_CTREE_EXPANDER_TRIANGLE);
 #endif
-       gtk_ctree_set_indent(GTK_CTREE(ctree), 16);
+       gtk_ctree_set_indent(GTK_CTREE(ctree), 12);
        g_object_set_data(G_OBJECT(ctree), "user_data", summaryview);
 
        for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
index 8312425..70404a3 100644 (file)
@@ -145,9 +145,9 @@ static gint textview_key_pressed            (GtkWidget      *widget,
 static gboolean textview_motion_notify         (GtkWidget      *widget,
                                                 GdkEventMotion *motion,
                                                 TextView       *textview);
-static gboolean textview_leave_notify          (GtkWidget      *widget,
+static gboolean textview_leave_notify          (GtkWidget        *widget,
                                                 GdkEventCrossing *event,
-                                                TextView       *textview);
+                                                TextView         *textview);
 static gboolean textview_visibility_notify     (GtkWidget      *widget,
                                                 GdkEventVisibility *event,
                                                 TextView       *textview);
@@ -260,18 +260,14 @@ TextView *textview_create(void)
 
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
 
-       g_signal_connect(G_OBJECT(text), "key_press_event",
-                        G_CALLBACK(textview_key_pressed),
-                        textview);
-       g_signal_connect(G_OBJECT(text), "motion_notify_event",
-                        G_CALLBACK(textview_motion_notify),
-                        textview);
-       g_signal_connect(G_OBJECT(text), "leave_notify_event",
-                        G_CALLBACK(textview_leave_notify),
-                        textview);
-       g_signal_connect(G_OBJECT(text), "visibility_notify_event",
-                        G_CALLBACK(textview_visibility_notify),
-                        textview);
+       g_signal_connect(G_OBJECT(text), "key-press-event",
+                        G_CALLBACK(textview_key_pressed), textview);
+       g_signal_connect(G_OBJECT(text), "motion-notify-event",
+                        G_CALLBACK(textview_motion_notify), textview);
+       g_signal_connect(G_OBJECT(text), "leave-notify-event",
+                        G_CALLBACK(textview_leave_notify), textview);
+       g_signal_connect(G_OBJECT(text), "visibility-notify-event",
+                        G_CALLBACK(textview_visibility_notify), textview);
 
        gtk_widget_show(scrolledwin);