summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorOwen Taylor <owt1@cornell.edu>1998-03-23 06:27:31 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-03-23 06:27:31 +0000
commit923f3f6992154acda20cd0ca21e23f4ec6d697cd (patch)
tree71e8c7e887f7cb8cd3f8f902f4cd8a5d81221fc6 /gtk
parentf0f650948ad1bd2b5b9fb9ef537dd95f84368e7f (diff)
downloadgtk+-923f3f6992154acda20cd0ca21e23f4ec6d697cd.tar.gz
Added optional word wrap, controlled by new function
Mon Mar 23 01:04:51 1998 Owen Taylor <owt1@cornell.edu> * 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.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtktext.c47
-rw-r--r--gtk/gtktext.h3
-rw-r--r--gtk/testgtk.c32
3 files changed, 73 insertions, 9 deletions
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 3b77f44a82..e7ff57e129 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -518,6 +518,22 @@ gtk_text_new (GtkAdjustment *hadj,
}
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);