[PATCH] GtkText fixes
- From: Owen Taylor <owt1 cornell edu>
- To: gtk-list redhat com
- Subject: [PATCH] GtkText fixes
- Date: 10 Mar 1998 13:38:03 -0500
This patch fixes the two problems reported by Stefan Jeske,
and incorporates Tony Gale's change; it also includes some
extra sanity checks for the Text and Entry widget.
(Would somebody who has a decent connection to va.debian.org
commit this? If not, I'll try late tonight, when things
seem to get better.)
[ The ChangeLog chunk also includes another patch which I'll
post separately ]
*** gtk+0.99.5/ChangeLog Mon Mar 9 23:45:53 1998
--- gtk+/ChangeLog Tue Mar 10 13:35:38 1998
***************
*** 1,3 ****
--- 1,17 ----
+ Tue Mar 10 13:34:29 1998 Owen Taylor <owt1@cornell.edu>
+
+ * gtk/gtkrange.c (gtk_range_default_[vh]trough_click):
+ Take forward/back step arrows into account when computing
+ position for middle button clicks.
+
+ * gtk/gtktext.c gtk/gtkentry.c:
+ - Fixes for deleting characters (don't subtract guints and get
+ negative numbers!)
+ - Reset cursor_virtual_x when moving by words and lines
+ - Extra sanity checks
+ - Fix to gtk_text_get_chars
+ (from Tony Gale <gale@daedalus.dera.gov.uk>)
+
Tue Mar 10 05:42:34 1998 Tim Janik <timj@gimp.org>
* configure.in: Bumped version number to 0.99.5.
--- gtk+CVS-2/gtk/gtktext.c Mon Mar 9 22:22:06 1998
+++ gtk+/gtk/gtktext.c Tue Mar 10 12:06:33 1998
@@ -781,7 +781,7 @@
if (text->point.index < text->first_line_start_index)
{
- if (text->point.index >= text->first_line_start_index - nchars)
+ if (text->point.index + nchars >= text->first_line_start_index)
{
text->first_line_start_index = text->point.index;
while ((text->first_line_start_index > 0) &&
@@ -794,13 +794,15 @@
}
if (text->point.index < editable->selection_start_pos)
- editable->selection_start_pos -= nchars;
+ editable->selection_start_pos -=
+ MIN(nchars, editable->selection_start_pos - text->point.index);
if (text->point.index < editable->selection_end_pos)
- editable->selection_end_pos -= nchars;
+ editable->selection_end_pos -=
+ MIN(nchars, editable->selection_end_pos - text->point.index);
/* We'll reset the cursor later anyways if we aren't frozen */
if (text->point.index < text->cursor_mark.index)
- text->cursor_mark.index -= nchars;
-
+ text->cursor_mark.index -=
+ MIN(nchars, text->cursor_mark.index - text->point.index);
move_gap_to_point (text);
@@ -828,14 +830,14 @@
gchar *p;
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 (end_pos > TEXT_LENGTH (text))
+ if (end_pos < 0)
+ end_pos = TEXT_LENGTH (text);
+
+ if ((end_pos > TEXT_LENGTH (text)) || (end_pos < start_pos))
return NULL;
nchars = end_pos - start_pos;
@@ -1585,7 +1587,8 @@
if (end_pos < 0)
end_pos = TEXT_LENGTH (text);
- gtk_text_forward_delete (text, end_pos - start_pos);
+ if (end_pos > start_pos)
+ gtk_text_forward_delete (text, end_pos - start_pos);
}
static gint
@@ -2033,10 +2036,14 @@
fetch_lines_backward (GtkText* text)
{
GList* new_lines = NULL, *new_line_start;
+ GtkPropertyMark mark;
+
+ if (CACHE_DATA(text->line_start_cache).start.index == 0)
+ return;
- GtkPropertyMark mark = find_this_line_start_mark (text,
- CACHE_DATA(text->line_start_cache).start.index - 1,
- &CACHE_DATA(text->line_start_cache).start);
+ mark = find_this_line_start_mark (text,
+ CACHE_DATA(text->line_start_cache).start.index - 1,
+ &CACHE_DATA(text->line_start_cache).start);
new_line_start = new_lines = fetch_lines (text, &mark, NULL, FetchLinesCount, 1);
@@ -2092,7 +2099,7 @@
if (line == text->current_line)
chars_left -= CACHE_DATA(line).end.index - text->point.index + 1;
else
- chars_left -= CACHE_DATA(line).end.index -CACHE_DATA(line).start.index + 1;
+ chars_left -= CACHE_DATA(line).end.index - CACHE_DATA(line).start.index + 1;
if (!text->line_wrap || !CACHE_DATA(line).wraps)
*lines += 1;
@@ -2591,7 +2598,7 @@
forward_prop->length += len;
}
else if ((MARK_NEXT_LIST_PTR(mark) == NULL) &&
- (MARK_OFFSET(mark) == forward_prop->length - 1))
+ (MARK_OFFSET(mark) + 1 == forward_prop->length))
{
/* Inserting before only the last position in the text */
@@ -3306,6 +3313,8 @@
static void
gtk_text_move_forward_word (GtkText *text)
{
+ text->cursor_virtual_x = 0;
+
undraw_cursor (text, FALSE);
while (!LAST_INDEX (text, text->cursor_mark) &&
@@ -3323,6 +3332,8 @@
static void
gtk_text_move_backward_word (GtkText *text)
{
+ text->cursor_virtual_x = 0;
+
undraw_cursor (text, FALSE);
while ((text->cursor_mark.index > 0) &&
@@ -3340,6 +3351,8 @@
static void
gtk_text_move_beginning_of_line (GtkText *text)
{
+ text->cursor_virtual_x = 0;
+
undraw_cursor (text, FALSE);
while ((text->cursor_mark.index > 0) &&
@@ -3353,6 +3366,8 @@
static void
gtk_text_move_end_of_line (GtkText *text)
{
+ text->cursor_virtual_x = 0;
+
undraw_cursor (text, FALSE);
while (!LAST_INDEX (text, text->cursor_mark) &&
@@ -4453,10 +4468,13 @@
GdkRectangle area;
gint width;
gint height;
-
+
if (end_pos < 0)
end_pos = TEXT_LENGTH (text);
+ if (end_pos < start_pos)
+ return;
+
gdk_window_get_size (text->text_area, &width, &height);
area.x = 0;
area.y = -1;
--- gtk+CVS-2/gtk/gtkentry.c Mon Mar 9 22:21:58 1998
+++ gtk+/gtk/gtkentry.c Tue Mar 10 12:17:55 1998
@@ -1424,9 +1424,12 @@
new_text_length = entry->text_max_length - entry->text_length;
/* Don't insert anything, if there was nothing to insert. */
- if (new_text_length <= 0)
+ if (new_text_length == 0)
return;
+ if (new_text_length < 0)
+ new_text_length = strlen (new_text);
+
start_pos = *position;
end_pos = start_pos + new_text_length;
last_pos = new_text_length + entry->text_length;
@@ -1523,14 +1526,19 @@
start_pos = MIN(entry->text_length, start_pos);
end_pos = MIN(entry->text_length, end_pos);
- c = entry->text[end_pos];
- entry->text[end_pos] = '\0';
-
- retval = g_strdup (&entry->text[start_pos]);
-
- entry->text[end_pos] = c;
-
- return retval;
+ if (start_pos <= end_pos)
+ {
+ c = entry->text[end_pos];
+ entry->text[end_pos] = '\0';
+
+ retval = g_strdup (&entry->text[start_pos]);
+
+ entry->text[end_pos] = c;
+
+ return retval;
+ }
+ else
+ return NULL;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]