Add cursor-position, selection-bound properties. (#62148, reported by

Mon Oct 22 11:47:47 2001  Owen Taylor  <otaylor@redhat.com>

	* gtk/gtklabel.c: Add cursor-position, selection-bound
	properties. (#62148, reported by Padraig O'Briain)

	* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
	to cursor_position. (1.3.x addition, text_position is an awful
	name.) Make cursor_position read-only to avoid sticky questions
	of interaction with selection_bound. (#62636, reported by
	Padraig O'Briain)
This commit is contained in:
Owen Taylor 2001-10-22 21:01:47 +00:00 committed by Owen Taylor
parent 92d2dc0ba6
commit c8b58228d6
9 changed files with 166 additions and 31 deletions

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -1,3 +1,13 @@
Mon Oct 22 11:47:47 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtklabel.c: Add cursor-position, selection-bound
properties. (#62148, Reported by Padraig O'briain)
* gtk/gtkentry.c (gtk_entry_class_init): Rename text_position
to cursor_position. (1.3.x addition, text_position is an awful
name.) Make cursor_position read-only to avoid sticky questions
of interaction with selection_bound.
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com>
Fixing popup menus to have "Paste" sensitized correctly. Original Fixing popup menus to have "Paste" sensitized correctly. Original
@ -4515,7 +4525,7 @@ Mon Jun 4 12:50:11 2001 Owen Taylor <otaylor@redhat.com>
2001-06-04 Havoc Pennington <hp@pobox.com> 2001-06-04 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore * gdk/x11/gdkevents-x11.c (gdk_event_translate): Ignore
releases for buttons 6, 7 r eleases for buttons 6, 7
2001-06-04 Havoc Pennington <hp@redhat.com> 2001-06-04 Havoc Pennington <hp@redhat.com>

View File

@ -70,7 +70,8 @@ enum {
enum { enum {
PROP_0, PROP_0,
PROP_TEXT_POSITION, PROP_CURSOR_POSITION,
PROP_SELECTION_BOUND,
PROP_EDITABLE, PROP_EDITABLE,
PROP_MAX_LENGTH, PROP_MAX_LENGTH,
PROP_VISIBILITY, PROP_VISIBILITY,
@ -402,14 +403,24 @@ gtk_entry_class_init (GtkEntryClass *class)
class->activate = gtk_entry_real_activate; class->activate = gtk_entry_real_activate;
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_TEXT_POSITION, PROP_CURSOR_POSITION,
g_param_spec_int ("text_position", g_param_spec_int ("cursor_position",
_("Text Position"), _("Cursor Position"),
_("The current position of the insertion point"), _("The current position of the insertion cursor in chars."),
0, 0,
G_MAXINT, G_MAXINT,
0, 0,
G_PARAM_READABLE | G_PARAM_WRITABLE)); G_PARAM_READABLE));
g_object_class_install_property (gobject_class,
PROP_SELECTION_BOUND,
g_param_spec_int ("selection_bound",
_("Selection Bound"),
_("The position of the opposite end of the selection from the cursor in chars."),
0,
G_MAXINT,
0,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_EDITABLE, PROP_EDITABLE,
@ -775,11 +786,6 @@ gtk_entry_set_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_TEXT_POSITION:
gtk_editable_set_position (GTK_EDITABLE (object),
g_value_get_int (value));
break;
case PROP_EDITABLE: case PROP_EDITABLE:
{ {
gboolean new_value = g_value_get_boolean (value); gboolean new_value = g_value_get_boolean (value);
@ -821,6 +827,7 @@ gtk_entry_set_property (GObject *object,
break; break;
case PROP_SCROLL_OFFSET: case PROP_SCROLL_OFFSET:
case PROP_CURSOR_POSITION:
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -839,9 +846,12 @@ gtk_entry_get_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_TEXT_POSITION: case PROP_CURSOR_POSITION:
g_value_set_int (value, entry->current_pos); g_value_set_int (value, entry->current_pos);
break; break;
case PROP_SELECTION_BOUND:
g_value_set_int (value, entry->selection_bound);
break;
case PROP_EDITABLE: case PROP_EDITABLE:
g_value_set_boolean (value, entry->editable); g_value_set_boolean (value, entry->editable);
break; break;
@ -2273,13 +2283,15 @@ gtk_entry_set_positions (GtkEntry *entry,
{ {
gboolean changed = FALSE; gboolean changed = FALSE;
g_object_freeze_notify (G_OBJECT (entry));
if (current_pos != -1 && if (current_pos != -1 &&
entry->current_pos != current_pos) entry->current_pos != current_pos)
{ {
entry->current_pos = current_pos; entry->current_pos = current_pos;
changed = TRUE; changed = TRUE;
g_object_notify (G_OBJECT (entry), "text_position"); g_object_notify (G_OBJECT (entry), "cursor_position");
} }
if (selection_bound != -1 && if (selection_bound != -1 &&
@ -2287,8 +2299,12 @@ gtk_entry_set_positions (GtkEntry *entry,
{ {
entry->selection_bound = selection_bound; entry->selection_bound = selection_bound;
changed = TRUE; changed = TRUE;
g_object_notify (G_OBJECT (entry), "selection_bound");
} }
g_object_thaw_notify (G_OBJECT (entry));
if (changed) if (changed)
gtk_entry_recompute (entry); gtk_entry_recompute (entry);
} }

View File

@ -66,7 +66,9 @@ enum {
PROP_WRAP, PROP_WRAP,
PROP_SELECTABLE, PROP_SELECTABLE,
PROP_MNEMONIC_KEYVAL, PROP_MNEMONIC_KEYVAL,
PROP_MNEMONIC_WIDGET PROP_MNEMONIC_WIDGET,
PROP_CURSOR_POSITION,
PROP_SELECTION_BOUND
}; };
static guint signals[LAST_SIGNAL] = { 0 }; static guint signals[LAST_SIGNAL] = { 0 };
@ -351,6 +353,26 @@ gtk_label_class_init (GtkLabelClass *class)
GTK_TYPE_WIDGET, GTK_TYPE_WIDGET,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_CURSOR_POSITION,
g_param_spec_int ("cursor_position",
_("Cursor Position"),
_("The current position of the insertion cursor in chars."),
0,
G_MAXINT,
0,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class,
PROP_SELECTION_BOUND,
g_param_spec_int ("selection_bound",
_("Selection Bound"),
_("The position of the opposite end of the selection from the cursor in chars."),
0,
G_MAXINT,
0,
G_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class, gtk_widget_class_install_style_property (widget_class,
g_param_spec_boxed ("cursor_color", g_param_spec_boxed ("cursor_color",
_("Cursor color"), _("Cursor color"),
@ -522,6 +544,26 @@ gtk_label_get_property (GObject *object,
case PROP_MNEMONIC_WIDGET: case PROP_MNEMONIC_WIDGET:
g_value_set_object (value, (GObject*) label->mnemonic_widget); g_value_set_object (value, (GObject*) label->mnemonic_widget);
break; break;
case PROP_CURSOR_POSITION:
if (label->select_info)
{
gint offset = g_utf8_pointer_to_offset (label->label,
label->label + label->select_info->selection_end);
g_value_set_int (value, offset);
}
else
g_value_set_int (value, 0);
break;
case PROP_SELECTION_BOUND:
if (label->select_info)
{
gint offset = g_utf8_pointer_to_offset (label->label,
label->label + label->select_info->selection_anchor);
g_value_set_int (value, offset);
}
else
g_value_set_int (value, 0);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -2139,17 +2181,15 @@ gtk_label_button_press (GtkWidget *widget,
min = MIN (min, index); min = MIN (min, index);
max = MAX (max, index); max = MAX (max, index);
gtk_label_select_region_index (label,
min,
max);
/* ensure the anchor is opposite index */ /* ensure the anchor is opposite index */
if (index == label->select_info->selection_anchor) if (index == min)
{ {
gint tmp = label->select_info->selection_end; gint tmp = min;
label->select_info->selection_end = label->select_info->selection_anchor; min = max;
label->select_info->selection_anchor = tmp; max = tmp;
} }
gtk_label_select_region_index (label, min, max);
} }
else else
{ {
@ -2332,7 +2372,11 @@ gtk_label_set_selectable (GtkLabel *label,
} }
if (setting != old_setting) if (setting != old_setting)
{ {
g_object_freeze_notify (G_OBJECT (label));
g_object_notify (G_OBJECT (label), "selectable"); g_object_notify (G_OBJECT (label), "selectable");
g_object_notify (G_OBJECT (label), "cursor_position");
g_object_notify (G_OBJECT (label), "selection_bound");
g_object_thaw_notify (G_OBJECT (label));
gtk_widget_queue_draw (GTK_WIDGET (label)); gtk_widget_queue_draw (GTK_WIDGET (label));
} }
} }
@ -2451,6 +2495,11 @@ gtk_label_select_region_index (GtkLabel *label,
gtk_label_clear_layout (label); gtk_label_clear_layout (label);
gtk_widget_queue_draw (GTK_WIDGET (label)); gtk_widget_queue_draw (GTK_WIDGET (label));
g_object_freeze_notify (G_OBJECT (label));
g_object_notify (G_OBJECT (label), "cursor_position");
g_object_notify (G_OBJECT (label), "selection_bound");
g_object_thaw_notify (G_OBJECT (label));
} }
} }