Commit 923f3f69 authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

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.
parent f0f65094
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
......
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
......
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
......
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
......
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
......
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
......
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
......
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment