word wrap for text widget
- From: Eric Fischer <eric fudge uchicago edu>
- To: gtk-list redhat com
- Subject: word wrap for text widget
- Date: Thu, 19 Mar 1998 14:20:30 -0600 (CST)
[I'm new here, so I apologize for the violation of protocol if this isn't
the right place to send patches]
I see in the TODO file that the Text widget is supposed to wrap lines
at word boundaries instead of right at the edge of the text region like
it does now. Attached is a short patch that will fix that. I'm also
willing to write the vi editing mode if no one else has claimed that task.
Eric
diff -rc ../gtk+-0.99.7/gtk/gtktext.c ./gtk/gtktext.c
*** ../gtk+-0.99.7/gtk/gtktext.c Sat Mar 14 13:03:21 1998
--- ./gtk/gtktext.c Thu Mar 19 14:01:41 1998
***************
*** 3865,3870 ****
--- 3865,3871 ----
gchar ch;
gint ch_width;
GdkFont *font;
+ gint word_wont_fit = 0;
gdk_window_get_size (text->text_area, (gint*) &max_display_pixels, NULL);
max_display_pixels -= LINE_WRAP_ROOM;
***************
*** 3906,3912 ****
ch_width = find_char_width (text, &lp.end, &tab_mark);
! if (ch_width + lp.pixel_width > max_display_pixels)
{
lp.wraps = 1;
--- 3907,3913 ----
ch_width = find_char_width (text, &lp.end, &tab_mark);
! if (ch_width + lp.pixel_width > max_display_pixels || word_wont_fit)
{
lp.wraps = 1;
***************
*** 3948,3953 ****
--- 3949,3985 ----
else
{
lp.displayable_chars += 1;
+ }
+
+ /* If we're looking at a space, check to see if the next word is going
+ * to fit on the line and wrap it if it isn't. Perhaps this should
+ * also wrap at some set of punctuation marks instead of just spaces?
+ *
+ * Eric Fischer <eric@rainbow.uchicago.edu> March 19, 1998 */
+
+ if (ch == ' ')
+ {
+ GtkPropertyMark word_end = lp.end;
+ gint word_width = 0;
+
+ advance_mark (&word_end);
+
+ while (!LAST_INDEX (text, word_end))
+ {
+ gchar c = GTK_TEXT_INDEX (text, word_end.index);
+
+ if (c == LINE_DELIM || c == '\t')
+ break;
+
+ word_width += find_char_width (text, &word_end, &tab_mark);
+ advance_mark (&word_end);
+
+ if (c == ' ')
+ break;
+ }
+
+ if (word_width + lp.pixel_width + ch_width > max_display_pixels)
+ word_wont_fit = 1;
}
lp.font_ascent = MAX (font->ascent, lp.font_ascent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]