Commit 2630943e authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]

Sun Mar  1 03:20:39 1998  Owen Taylor  <owt1@cornell.edu>

	* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]

	Turned off debugging in gtktext.c

	Bug fixes for cutting, pasting, deleting, etc.

	Some of the bugs that were there before have definitely
	been fixed.

	* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
	to make things look nicer.
parent 9205edae
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
Sun Mar 1 03:20:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtk/gtktext.[ch] gtkeditable.[ch]
Turned off debugging in gtktext.c
Bug fixes for cutting, pasting, deleting, etc.
Some of the bugs that were there before have definitely
been fixed.
* gtk/testgtk.c gtk/testgtkrc: Removed my ugly orange backgrounds,
to make things look nicer.
Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkentry.[ch] gtktext.c gtkeditable.[ch]
* gtk/gtkentry.[ch] gtktext.[ch] gtkeditable.[ch]
Created a new base widget type Editable for the entry and
text widgets, which encapsulates most of the selection and
......@@ -17,8 +31,15 @@ Sat Feb 28 23:58:54 1998 Owen Taylor <owt1@cornell.edu>
- Clipboard style cut and paste
- Emacs style key bindings (~same as Entry)
- Word motion
- "changed" signal
There are definitely still some bugs in the new stuff.
Use style->base for the background and style->text for
the foreground.
* gtkfilesel.c gtkspinbutton.c testgtk.c: small changes
to fit the new interface more exactly.
Sat Feb 28 19:29:09 1998 Tim Janik <timj@gimp.org>
......
......@@ -142,3 +142,63 @@ TODO AFTER GTK 1.0
( You'd have to extend gdk_window_set_hints to accept the
window gravity option to get it right. )
* Text/Edit widget: (some of these might be bugs that should be fixed now)
Bugs:
- In Entry and Text widget, you can ungrab while still
dragging by pressing button-1, pressing button 3, releaseing 3,
then releasing 1.
- When selecting on a Text or Entry widget, the selection isn't
claimed until you release the button, and that shows by the
color of the selection. (Which is the real problem - it probably
is OK/better to delay claiming the selection)
- Related to the above, when you Shift/arrow to select text, the
selected text doesn't show that you have the selection immediately.
- Selecting an entire line with triple-click doesn't work write -
it should select the wrapped portion too.
- Selecting an entire line should probably select the newline as
well, so when the selection is cut/deleted, the newline goes
along.
- Do something about the bg pixmap situation. (It will produce
garbage when editing is enabled)
Improvements:
- Finish making the key bindings consistent between the Entry
and Text widgets
- Unify the key binding support in some fashion between the
two widgets (???)
- When inserting or deleting large chunks of text, do a freeze/thaw
automatically, to avoid scrolling around for ever on screen.
- Jump scroll on large insertions/deletions
- Prune the line start cache. But since it is only 68 bytes
per line, and it is a lot faster when lines are in the cache,
it may be better not to, at least for now.
- Show the non-editable state by changing colors. (Use the
style entries for insensitive?)
- Multibyte support for the Text widget.
- Unicode support to do the multi-byte right.
- Support an .inputrc. (The readline one doesn't really work,
unless it is extended because it can't represent X keysyms,
just terminal type input)
- A vi mode
- Word wrap, instead of line folding. (Should the continuation
characters be shown?)
- Horizontal scrolling
......@@ -53,9 +53,9 @@ typedef void (*GtkEditableSignal2) (GtkObject *object,
gpointer data);
typedef gpointer (*GtkEditableSignal3) (GtkObject *object,
gint arg1,
gint arg2,
gpointer data);
gint arg1,
gint arg2,
gpointer data);
static void gtk_editable_marshal_signal_1 (GtkObject *object,
......@@ -312,8 +312,8 @@ gtk_editable_finalize (GtkObject *object)
void
gtk_editable_insert_text (GtkEditable *editable,
const gchar *new_text,
guint new_text_length,
guint *position)
gint new_text_length,
gint *position)
{
gchar buf[64];
gchar *text;
......@@ -338,8 +338,8 @@ gtk_editable_insert_text (GtkEditable *editable,
void
gtk_editable_delete_text (GtkEditable *editable,
guint start_pos,
guint end_pos)
gint start_pos,
gint end_pos)
{
g_return_if_fail (editable != NULL);
g_return_if_fail (GTK_IS_EDITABLE (editable));
......@@ -363,8 +363,8 @@ gtk_editable_update_text (GtkEditable *editable,
gchar *
gtk_editable_get_chars (GtkEditable *editable,
guint start,
guint end)
gint start,
gint end)
{
gchar *retval = NULL;
......@@ -444,7 +444,8 @@ gtk_editable_selection_handler (GtkWidget *widget,
{
selection_start_pos = MIN (editable->selection_start_pos, editable->selection_end_pos);
selection_end_pos = MAX (editable->selection_start_pos, editable->selection_end_pos);
str = gtk_editable_get_chars(editable, selection_start_pos,
str = gtk_editable_get_chars(editable,
selection_start_pos,
selection_end_pos);
length = selection_end_pos - selection_start_pos;
}
......@@ -576,14 +577,15 @@ gtk_editable_selection_received (GtkWidget *widget,
void
gtk_editable_delete_selection (GtkEditable *editable)
{
if (editable->selection_start_pos != editable->selection_end_pos)
gtk_editable_delete_text (editable,
MIN (editable->selection_start_pos, editable->selection_end_pos),
MAX (editable->selection_start_pos, editable->selection_end_pos));
guint start = editable->selection_start_pos;
guint end = editable->selection_end_pos;
editable->selection_start_pos = 0;
editable->selection_end_pos = 0;
if (start != end)
gtk_editable_delete_text (editable, MIN (start, end), MAX (start,end));
if (editable->has_selection)
{
editable->has_selection = FALSE;
......@@ -614,8 +616,8 @@ gtk_editable_claim_selection (GtkEditable *editable,
void
gtk_editable_select_region (GtkEditable *editable,
guint start,
guint end)
gint start,
gint end)
{
if (GTK_WIDGET_REALIZED (editable))
gtk_editable_claim_selection (editable, start != end, GDK_CURRENT_TIME);
......@@ -645,8 +647,8 @@ gtk_editable_copy_clipboard (GtkEditable *editable, GdkEventKey *event)
clipboard_atom,
event->time))
editable->clipboard_text = gtk_editable_get_chars (editable,
editable->selection_start_pos,
editable->selection_end_pos);
selection_start_pos,
selection_end_pos);
}
}
......
......@@ -59,37 +59,37 @@ struct _GtkEditableClass
void (* insert_text) (GtkEditable *editable,
const gchar *text,
guint length,
guint *position);
gint length,
gint *position);
void (* delete_text) (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
void (* update_text) (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
gchar* (* get_chars) (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
void (* set_selection)(GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
void (* changed) (GtkEditable *editable);
};
guint gtk_editable_get_type (void);
void gtk_editable_select_region (GtkEditable *editable,
guint start,
guint end);
gint start,
gint end);
void gtk_editable_insert_text (GtkEditable *editable,
const gchar *new_text,
guint new_text_length,
guint *position);
gint new_text_length,
gint *position);
void gtk_editable_delete_text (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
gchar * gtk_editable_get_chars (GtkEditable *editable,
guint start,
guint end);
gint start_pos,
gint end_pos);
void gtk_editable_cut_clipboard (GtkEditable *editable,
GdkEventKey *event);
void gtk_editable_copy_clipboard (GtkEditable *editable,
......
......@@ -75,19 +75,19 @@ static gint gtk_entry_position (GtkEntry *entry,
gint x);
void gtk_entry_adjust_scroll (GtkEntry *entry);
static void gtk_entry_grow_text (GtkEntry *entry);
static void gtk_entry_insert_text (GtkEditable *editable,
static void gtk_entry_insert_text (GtkEditable *editable,
const gchar *new_text,
guint new_text_length,
guint *position);
static void gtk_entry_delete_text (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint new_text_length,
gint *position);
static void gtk_entry_delete_text (GtkEditable *editable,
gint start_pos,
gint end_pos);
static void gtk_entry_update_text (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
static gchar *gtk_entry_get_chars (GtkEditable *editable,
guint start,
guint end);
gint start_pos,
gint end_pos);
static gint move_backward_character (gchar *str, gint index);
static void gtk_move_forward_character (GtkEntry *entry);
......@@ -107,8 +107,8 @@ static void gtk_select_line (GtkEntry *entry);
static void gtk_entry_set_selection (GtkEditable *editable,
guint start,
guint end);
gint start,
gint end);
static GtkWidgetClass *parent_class = NULL;
static gint entry_signals[LAST_SIGNAL] = { 0 };
......@@ -1383,9 +1383,9 @@ gtk_entry_grow_text (GtkEntry *entry)
static void
gtk_entry_insert_text (GtkEditable *editable,
const gchar *new_text,
guint new_text_length,
guint *position)
const gchar *new_text,
gint new_text_length,
gint *position)
{
gchar *text;
gint start_pos;
......@@ -1435,8 +1435,8 @@ gtk_entry_insert_text (GtkEditable *editable,
static void
gtk_entry_delete_text (GtkEditable *editable,
guint start_pos,
guint end_pos)
gint start_pos,
gint end_pos)
{
gchar *text;
gint deletion_length;
......@@ -1454,6 +1454,9 @@ gtk_entry_delete_text (GtkEditable *editable,
if (editable->selection_end_pos > start_pos)
editable->selection_end_pos -= MIN(end_pos, editable->selection_end_pos) - start_pos;
if (end_pos < 0)
end_pos = entry->text_length;
if ((start_pos < end_pos) &&
(start_pos >= 0) &&
(end_pos <= entry->text_length))
......@@ -1476,16 +1479,16 @@ gtk_entry_delete_text (GtkEditable *editable,
static void
gtk_entry_update_text (GtkEditable *editable,
guint start_pos,
guint end_pos)
gint start_pos,
gint end_pos)
{
gtk_entry_queue_draw (GTK_ENTRY(editable));
}
gchar *
gtk_entry_get_chars (GtkEditable *editable,
guint start,
guint end)
gint start_pos,
gint end_pos)
{
gchar *retval;
GtkEntry *entry;
......@@ -1496,15 +1499,18 @@ gtk_entry_get_chars (GtkEditable *editable,
entry = GTK_ENTRY (editable);
start = MIN(entry->text_length, start);
end = MIN(entry->text_length, end);
if (end_pos < 0)
end_pos = entry->text_length;
start_pos = MIN(entry->text_length, start_pos);
end_pos = MIN(entry->text_length, end_pos);
c = entry->text[end];
entry->text[end] = '\0';
c = entry->text[end_pos];
entry->text[end_pos] = '\0';
retval = g_strdup (&entry->text[start]);
retval = g_strdup (&entry->text[start_pos]);
entry->text[end] = c;
entry->text[end_pos] = c;
return retval;
}
......@@ -1772,11 +1778,14 @@ gtk_select_line (GtkEntry *entry)
static void
gtk_entry_set_selection (GtkEditable *editable,
guint start,
guint end)
gint start,
gint end)
{
g_return_if_fail (GTK_IS_ENTRY (editable));
if (end < 0)
end = GTK_ENTRY (editable)->text_length;
editable->selection_start_pos = start;
editable->selection_end_pos = end;
......@@ -1785,8 +1794,8 @@ gtk_entry_set_selection (GtkEditable *editable,
void
gtk_entry_select_region (GtkEntry *entry,
guint start,
guint end)
gint start,
gint end)
{
gtk_editable_select_region (GTK_EDITABLE(entry), start, end);
}
......
......@@ -73,8 +73,8 @@ void gtk_entry_set_position (GtkEntry *entry,
gint position);
gchar* gtk_entry_get_text (GtkEntry *entry);
void gtk_entry_select_region (GtkEntry *entry,
guint start,
guint end);
gint start,
gint end);
void gtk_entry_set_visibility (GtkEntry *entry,
gboolean visible);
void gtk_entry_set_editable (GtkEntry *entry,
......
......@@ -169,20 +169,20 @@ static void gtk_text_disconnect (GtkAdjustment *adjustment,
static void gtk_text_insert_text (GtkEditable *editable,
const gchar *new_text,
guint new_text_length,
guint *position);
static void gtk_text_delete_text (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint new_text_length,
gint *position);
static void gtk_text_delete_text (GtkEditable *editable,
gint start_pos,
gint end_pos);
static void gtk_text_update_text (GtkEditable *editable,
guint start_pos,
guint end_pos);
gint start_pos,
gint end_pos);
static gchar *gtk_text_get_chars (GtkEditable *editable,
guint start,
guint end);
gint start,
gint end);
static void gtk_text_set_selection (GtkEditable *editable,
guint start,
guint end);
gint start,
gint end);
/* Event handlers */
static void gtk_text_draw (GtkWidget *widget,
......@@ -289,7 +289,7 @@ static void gtk_text_delete_to_line_end (GtkText *text);
static void gtk_text_select_word (GtkText *text);
static void gtk_text_select_line (GtkText *text);
#define DEBUG_GTK_TEXT
/* #define DEBUG_GTK_TEXT */
#if defined(DEBUG_GTK_TEXT) && defined(__GNUC__)
/* Debugging utilities. */
......@@ -636,6 +636,7 @@ gtk_text_insert (GtkText *text,
gint length)
{
gint i;
GtkEditable *editable = GTK_EDITABLE (text);
gint new_line_count = 1;
guint old_height = 0;
......@@ -671,6 +672,11 @@ gtk_text_insert (GtkText *text,
if (text->point.index < text->first_line_start_index)
text->first_line_start_index += length;
if (text->point.index < editable->selection_start_pos)
editable->selection_start_pos += length;
if (text->point.index < editable->selection_end_pos)
editable->selection_end_pos += length;
move_gap_to_point (text);
if (font == NULL)
......@@ -708,9 +714,10 @@ gtk_text_backward_delete (GtkText *text,
gint
gtk_text_forward_delete (GtkText *text,
guint nchars)
guint nchars)
{
guint old_lines, old_height;
GtkEditable *editable = GTK_EDITABLE (text);
g_return_val_if_fail (text != NULL, 0);
g_return_val_if_fail (GTK_IS_TEXT (text), 0);
......@@ -738,6 +745,11 @@ gtk_text_forward_delete (GtkText *text,
text->first_line_start_index -= nchars;
}
if (text->point.index < editable->selection_start_pos)
editable->selection_start_pos -= nchars;
if (text->point.index < editable->selection_end_pos)
editable->selection_end_pos -= nchars;
move_gap_to_point (text);
text->gap_size += nchars;
......@@ -752,42 +764,44 @@ gtk_text_forward_delete (GtkText *text,
static gchar *
gtk_text_get_chars (GtkEditable *editable,
guint index,
guint nchars)
gint start_pos,
gint end_pos)
{
GtkText *text;
gchar *retval;
gchar *p;
guint n;
guint n, nchars;
if (end_pos < 0)
end_pos = TEXT_LENGTH (text);
g_return_val_if_fail (editable != NULL, NULL);
g_return_val_if_fail (GTK_IS_TEXT (editable), NULL);
text = GTK_TEXT (editable);
if (index+nchars > TEXT_LENGTH (text))
if (end_pos > TEXT_LENGTH (text))
return NULL;
if (nchars < 0)
nchars = TEXT_LENGTH (text) - index;
nchars = end_pos - start_pos;
retval = g_new (gchar, nchars+1);
p = retval;
if (index < text->gap_position)
if (start_pos < text->gap_position)
{
n = MIN (text->gap_position - index, nchars);
memcpy (p, &text->text[index], n);
n = MIN (text->gap_position - start_pos, nchars);
memcpy (p, &text->text[start_pos], n);
p += n;
index += n;
start_pos += n;
nchars -= n;