From 923f3f6992154acda20cd0ca21e23f4ec6d697cd Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Mon, 23 Mar 1998 06:27:31 +0000 Subject: [PATCH] Added optional word wrap, controlled by new function Mon Mar 23 01:04:51 1998 Owen Taylor * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled by new function gtk_text_set_word_wrap; and a check button in the Text test. * gtk/gtktext.c: First line wasn't getting updated properly when selection was removed. --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-0 | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-2 | 9 +++++++++ ChangeLog.pre-2-4 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ gtk/gtktext.c | 47 +++++++++++++++++++++++++++++++++++++++++++--- gtk/gtktext.h | 3 +++ gtk/testgtk.c | 32 +++++++++++++++++++++++++------ tests/testgtk.c | 32 +++++++++++++++++++++++++------ 11 files changed, 162 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5c4cdbfe85..4b7f0efbfc 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +Mon Mar 23 01:04:51 1998 Owen Taylor + + * gtk/gtktext.[ch] testgtk.c: Added optional word wrap, controlled + by new function gtk_text_set_word_wrap; and a check button + in the Text test. + + * gtk/gtktext.c: First line wasn't getting updated + properly when selection was removed. + Sun Mar 22 23:33:50 1998 Owen Taylor * gtk/gtkentry.c (gtk_entry_insert_text): Fixed some diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 3b77f44a82..e7ff57e129 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -517,6 +517,22 @@ gtk_text_new (GtkAdjustment *hadj, return GTK_WIDGET (text); } +void +gtk_text_set_word_wrap (GtkText *text, + gint word_wrap) +{ + g_return_if_fail (text != NULL); + g_return_if_fail (GTK_IS_TEXT (text)); + + text->word_wrap = (word_wrap != FALSE); + + if (GTK_WIDGET_DRAWABLE (text)) + { + recompute_geometry (text); + gtk_widget_queue_draw (GTK_WIDGET (text)); + } +} + void gtk_text_set_editable (GtkText *text, gint editable) @@ -3940,8 +3956,33 @@ find_line_params (GtkText* text, } else { - /* Don't include this character, it will wrap. */ - decrement_mark (&lp.end); + if (text->word_wrap) + { + GtkPropertyMark saved_mark = lp.end; + guint saved_characters = lp.displayable_chars; + + lp.displayable_chars += 1; + + while (!isspace (GTK_TEXT_INDEX (text, lp.end.index)) && + (lp.end.index > lp.start.index)) + { + decrement_mark (&lp.end); + lp.displayable_chars -= 1; + } + + /* If whole line is one word, revert to char wrapping */ + if (lp.end.index == lp.start.index) + { + lp.end = saved_mark; + lp.displayable_chars = saved_characters; + decrement_mark (&lp.end); + } + } + else + { + /* Don't include this character, it will wrap. */ + decrement_mark (&lp.end); + } } lp.tab_cont_next = *next_cont; @@ -4502,7 +4543,7 @@ gtk_text_update_text (GtkEditable *editable, if (CACHE_DATA(cache).end.index >= start_pos) { if (area.y < 0) - area.y = pixels; + area.y = MAX(0,pixels); area.height = pixels + LINE_HEIGHT(CACHE_DATA(cache)) - area.y; } } diff --git a/gtk/gtktext.h b/gtk/gtktext.h index 82aa25e7ab..12ca037bed 100644 --- a/gtk/gtktext.h +++ b/gtk/gtktext.h @@ -103,6 +103,7 @@ struct _GtkText guint line_wrap : 1; /* Frozen, don't do updates. @@@ fixme */ guint freeze : 1; + guint word_wrap : 1; /* TEXT PROPERTIES */ @@ -161,6 +162,8 @@ GtkWidget* gtk_text_new (GtkAdjustment *hadj, GtkAdjustment *vadj); void gtk_text_set_editable (GtkText *text, gint editable); +void gtk_text_set_word_wrap (GtkText *text, + gint word_wrap); void gtk_text_set_adjustments (GtkText *text, GtkAdjustment *hadj, GtkAdjustment *vadj); diff --git a/gtk/testgtk.c b/gtk/testgtk.c index c18bf26e6a..b60780b506 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -3659,6 +3659,14 @@ text_toggle_editable (GtkWidget *checkbutton, GTK_TOGGLE_BUTTON(checkbutton)->active); } +static void +text_toggle_word_wrap (GtkWidget *checkbutton, + GtkWidget *text) +{ + gtk_text_set_word_wrap(GTK_TEXT(text), + GTK_TOGGLE_BUTTON(checkbutton)->active); +} + /* * GtkText */ @@ -3668,8 +3676,9 @@ create_text () static GtkWidget *window = NULL; GtkWidget *box1; GtkWidget *box2; + GtkWidget *hbox; GtkWidget *button; - GtkWidget *editable_check; + GtkWidget *check; GtkWidget *separator; GtkWidget *table; GtkWidget *hscrollbar; @@ -3760,12 +3769,23 @@ create_text () gtk_text_thaw (GTK_TEXT (text)); - editable_check = gtk_check_button_new_with_label("Editable"); - gtk_box_pack_start (GTK_BOX (box2), editable_check, FALSE, TRUE, 0); - gtk_signal_connect (GTK_OBJECT(editable_check), "toggled", + hbox = gtk_hbutton_box_new (); + gtk_box_pack_start (GTK_BOX (box2), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + check = gtk_check_button_new_with_label("Editable"); + gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT(check), "toggled", GTK_SIGNAL_FUNC(text_toggle_editable), text); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(editable_check), TRUE); - gtk_widget_show (editable_check); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE); + gtk_widget_show (check); + + check = gtk_check_button_new_with_label("Wrap Words"); + gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); + gtk_signal_connect (GTK_OBJECT(check), "toggled", + GTK_SIGNAL_FUNC(text_toggle_word_wrap), text); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), FALSE); + gtk_widget_show (check); separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); diff --git a/tests/testgtk.c b/tests/testgtk.c index c18bf26e6a..b60780b506 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -3659,6 +3659,14 @@ text_toggle_editable (GtkWidget *checkbutton, GTK_TOGGLE_BUTTON(checkbutton)->active); } +static void +text_toggle_word_wrap (GtkWidget *checkbutton, + GtkWidget *text) +{ + gtk_text_set_word_wrap(GTK_TEXT(text), + GTK_TOGGLE_BUTTON(checkbutton)->active); +} + /* * GtkText */ @@ -3668,8 +3676,9 @@ create_text () static GtkWidget *window = NULL; GtkWidget *box1; GtkWidget *box2; + GtkWidget *hbox; GtkWidget *button; - GtkWidget *editable_check; + GtkWidget *check; GtkWidget *separator; GtkWidget *table; GtkWidget *hscrollbar; @@ -3760,12 +3769,23 @@ create_text () gtk_text_thaw (GTK_TEXT (text)); - editable_check = gtk_check_button_new_with_label("Editable"); - gtk_box_pack_start (GTK_BOX (box2), editable_check, FALSE, TRUE, 0); - gtk_signal_connect (GTK_OBJECT(editable_check), "toggled", + hbox = gtk_hbutton_box_new (); + gtk_box_pack_start (GTK_BOX (box2), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + check = gtk_check_button_new_with_label("Editable"); + gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT(check), "toggled", GTK_SIGNAL_FUNC(text_toggle_editable), text); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(editable_check), TRUE); - gtk_widget_show (editable_check); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE); + gtk_widget_show (check); + + check = gtk_check_button_new_with_label("Wrap Words"); + gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); + gtk_signal_connect (GTK_OBJECT(check), "toggled", + GTK_SIGNAL_FUNC(text_toggle_word_wrap), text); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), FALSE); + gtk_widget_show (check); separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);