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.
This commit is contained in:
Owen Taylor 1998-03-23 06:27:31 +00:00 committed by Owen Taylor
parent f0f650948a
commit 923f3f6992
11 changed files with 162 additions and 15 deletions

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -1,3 +1,12 @@
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.
Sun Mar 22 23:33:50 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.c (gtk_entry_insert_text): Fixed some

View File

@ -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)
@ -3938,11 +3954,36 @@ find_line_params (GtkText* text,
lp.displayable_chars += 1;
}
}
else
{
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;
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);