Better smart wrapping.
authorDarko Koruga <darko@users.sourceforge.net>
Thu, 4 Oct 2001 05:52:29 +0000 (05:52 +0000)
committerDarko Koruga <darko@users.sourceforge.net>
Thu, 4 Oct 2001 05:52:29 +0000 (05:52 +0000)
ChangeLog.claws
configure.in
src/compose.c
src/gtkstext.c
src/gtkstext.h

index 399283e9527bd97e34869c52cde406aae86ba518..4bac1fdb283351ca87ac60ae7a6a084c1e30bd3f 100644 (file)
@@ -1,3 +1,10 @@
+2001-10-04 [darko]     0.6.2claws17
+
+       * src/compose.c
+               better smart wrapping
+       * src/gtkstext.[hc]
+               a function to make text buffer contiguous
+
 2001-10-03 [paul]      0.6.2claws16
 
        * sync with sylpheed 0.6.2cvs10
 2001-10-03 [paul]      0.6.2claws16
 
        * sync with sylpheed 0.6.2cvs10
index 236f3e32d4b65b804a5177e94b71c878680fcb9e..23d8dbac0cc4926b76b8f79801abed1741620534 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws16
+EXTRA_VERSION=claws17
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index 62729f792afabea9dc5b5c945ac251148c41206f..6c871e126ea42a834c7c875adc7fcb3c43d37263 100644 (file)
@@ -2122,6 +2122,29 @@ compose_end:
 #undef GET_STEXT
 }
 
 #undef GET_STEXT
 }
 
+/* return str length if text at start_pos matches str else return zero */
+static gint is_gtkstext_string(GtkSText *text, guint start_pos,
+                              guint text_len, gchar *str) {
+       gint is_str, i, str_len;
+       gchar str_ch;
+
+       is_str = 0;
+       if (str) {
+               str_len = strlen(str);
+               is_str = 1;
+               for (i = 0; (i < str_len) && (start_pos + i < text_len); i++) {
+                       str_ch = GTK_STEXT_INDEX(text, start_pos + i);
+                       if (*(str + i) != str_ch) {
+                               break;
+                       }
+               }
+               if (i == 0 || i < str_len)
+                       is_str = 0;
+       }
+
+       return is_str ? str_len : 0;
+}
+
 static void compose_wrap_line_all(Compose *compose)
 {
        GtkSText *text = GTK_STEXT(compose->text);
 static void compose_wrap_line_all(Compose *compose)
 {
        GtkSText *text = GTK_STEXT(compose->text);
@@ -2129,13 +2152,25 @@ static void compose_wrap_line_all(Compose *compose)
        guint line_pos = 0, cur_pos = 0;
        gint line_len = 0, cur_len = 0;
        gint ch_len;
        guint line_pos = 0, cur_pos = 0;
        gint line_len = 0, cur_len = 0;
        gint ch_len;
+       gint is_new_line = 1;
+       guint quote_len = 0;
+       guint linewrap_quote = prefs_common.linewrap_quote;
+       gchar *quote_fmt = prefs_common.quotemark;
        gchar cbuf[MB_CUR_MAX];
 
        gtk_stext_freeze(text);
 
        gchar cbuf[MB_CUR_MAX];
 
        gtk_stext_freeze(text);
 
+       /* make text buffer contiguous */
+       gtk_stext_compact_buffer(text);
+
        text_len = gtk_stext_get_length(text);
 
        for (; cur_pos < text_len; cur_pos++) {
        text_len = gtk_stext_get_length(text);
 
        for (; cur_pos < text_len; cur_pos++) {
+               if (linewrap_quote && is_new_line) {
+                       quote_len = is_gtkstext_string(text, cur_pos,
+                                                      text_len, quote_fmt);
+                       is_new_line = 0;
+               }
                if (text->use_wchar)
                        ch_len = wctomb
                                (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
                if (text->use_wchar)
                        ch_len = wctomb
                                (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
@@ -2147,6 +2182,8 @@ static void compose_wrap_line_all(Compose *compose)
                if (ch_len == 1 && *cbuf == '\n') {
                        line_pos = cur_pos + 1;
                        line_len = cur_len = 0;
                if (ch_len == 1 && *cbuf == '\n') {
                        line_pos = cur_pos + 1;
                        line_len = cur_len = 0;
+                       quote_len = 0;
+                       is_new_line = 1;
                        continue;
                }
 
                        continue;
                }
 
@@ -2187,6 +2224,19 @@ static void compose_wrap_line_all(Compose *compose)
                        line_pos++;
                        cur_len = cur_len - line_len + ch_len;
                        line_len = 0;
                        line_pos++;
                        cur_len = cur_len - line_len + ch_len;
                        line_len = 0;
+                       if (linewrap_quote && quote_len) {
+                               /* only if line is not already quoted */
+                               if (!is_gtkstext_string(text, line_pos,
+                                                       text_len, quote_fmt)) {
+                                       gtk_stext_insert(text, NULL, NULL, NULL,
+                                                       quote_fmt, quote_len);
+                                       gtk_stext_compact_buffer(text);
+                                       text_len += quote_len;
+                                       cur_pos += quote_len;
+                                       cur_len += quote_len;
+                                       line_len = quote_len;
+                               }
+                       }
                        continue;
                }
 
                        continue;
                }
 
index 0129105ce22c586532a33778bfb64dfe83487082..6e75dce3aa924407e7f4f945c6840801f9477e8b 100644 (file)
@@ -999,6 +999,16 @@ gtk_stext_thaw (GtkSText *text)
   draw_cursor (text, FALSE);
 }
 
   draw_cursor (text, FALSE);
 }
 
+void
+gtk_stext_compact_buffer (GtkSText    *text)
+{
+  GtkEditable *editable = GTK_EDITABLE (text);
+
+  g_return_if_fail (text != NULL);
+  g_return_if_fail (GTK_IS_STEXT (text));
+  move_gap (text, gtk_stext_get_length(text));
+}
+
 void
 gtk_stext_insert (GtkSText    *text,
                 GdkFont    *font,
 void
 gtk_stext_insert (GtkSText    *text,
                 GdkFont    *font,
index 09bb1b98b775e70c34501ddb6fb1373117c8acc8..df7ec3c1f794f25b904a25018582ad442ed80683 100644 (file)
@@ -226,6 +226,7 @@ void       gtk_stext_set_point       (GtkSText       *text,
 guint      gtk_stext_get_point       (GtkSText       *text);
 guint      gtk_stext_get_length      (GtkSText       *text);
 void       gtk_stext_freeze          (GtkSText       *text);
 guint      gtk_stext_get_point       (GtkSText       *text);
 guint      gtk_stext_get_length      (GtkSText       *text);
 void       gtk_stext_freeze          (GtkSText       *text);
+void       gtk_stext_compact_buffer  (GtkSText       *text);
 void       gtk_stext_thaw            (GtkSText       *text);
 void       gtk_stext_insert          (GtkSText       *text,
                                     GdkFont       *font,
 void       gtk_stext_thaw            (GtkSText       *text);
 void       gtk_stext_insert          (GtkSText       *text,
                                     GdkFont       *font,