From b44fcd55dd42fcac81ac81ee7e7f2d56ce2bc9cf Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 9 May 2006 04:44:53 +0000 Subject: [PATCH] Add a :cursor-position property. (#334412, Yevgen Muntyan) ` 2006-05-09 Matthias Clasen * gtk/gtktextbuffer.c (gtk_text_buffer_class_init): Add a :cursor-position property. (#334412, Yevgen Muntyan) ` --- ChangeLog | 3 +++ ChangeLog.pre-2-10 | 3 +++ gtk/gtktextbuffer.c | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4a1169fde..252d22cc10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-05-09 Matthias Clasen + * gtk/gtktextbuffer.c (gtk_text_buffer_class_init): Add a :cursor-position + property. (#334412, Yevgen Muntyan) + * gtk/gtk.symbols: * gtk/gtkmessagedialog.[hc]: Add an image property. (#337306, Alex Graveley) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index e4a1169fde..252d22cc10 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,8 @@ 2006-05-09 Matthias Clasen + * gtk/gtktextbuffer.c (gtk_text_buffer_class_init): Add a :cursor-position + property. (#334412, Yevgen Muntyan) + * gtk/gtk.symbols: * gtk/gtkmessagedialog.[hc]: Add an image property. (#337306, Alex Graveley) diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index b9f2f7acb9..3ab7602bbb 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -95,6 +95,7 @@ enum { /* Normal */ PROP_TEXT, PROP_HAS_SELECTION, + PROP_CURSOR_POSITION, PROP_COPY_TARGET_LIST, PROP_PASTE_TARGET_LIST }; @@ -213,6 +214,22 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass) FALSE, GTK_PARAM_READABLE)); + /** + * GtkTextBuffer:cursor-position: + * + * The position of the insert mark (as offset from the beginning of the buffer). + * It is useful for getting notified when the cursor moves. + * + * Since: 2.10 + */ + g_object_class_install_property (object_class, + PROP_CURSOR_POSITION, + g_param_spec_int ("cursor-position", + P_("Cursor position"), + P_("The position of the insert mark (as offset from the beginning of the buffer)"), + 0, G_MAXINT, 0, + GTK_PARAM_READABLE)); + /** * GtkTextBuffer:copy-target-list: * @@ -467,6 +484,7 @@ gtk_text_buffer_get_property (GObject *object, GParamSpec *pspec) { GtkTextBuffer *text_buffer; + GtkTextIter iter; text_buffer = GTK_TEXT_BUFFER (object); @@ -493,6 +511,12 @@ gtk_text_buffer_get_property (GObject *object, g_value_set_boolean (value, text_buffer->has_selection); break; + case PROP_CURSOR_POSITION: + gtk_text_buffer_get_iter_at_mark (text_buffer, &iter, + gtk_text_buffer_get_insert (text_buffer)); + g_value_set_int (value, gtk_text_iter_get_offset (&iter)); + break; + case PROP_COPY_TARGET_LIST: g_value_set_boxed (value, gtk_text_buffer_get_copy_target_list (text_buffer)); break; @@ -655,6 +679,7 @@ gtk_text_buffer_real_insert_text (GtkTextBuffer *buffer, _gtk_text_btree_insert (iter, text, len); g_signal_emit (buffer, signals[CHANGED], 0); + g_object_notify (G_OBJECT (buffer), "cursor-position"); } static void @@ -1373,6 +1398,7 @@ gtk_text_buffer_real_delete_range (GtkTextBuffer *buffer, update_selection_clipboards (buffer); g_signal_emit (buffer, signals[CHANGED], 0); + g_object_notify (G_OBJECT (buffer), "cursor-position"); } static void @@ -2272,8 +2298,11 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer, const GtkTextIter *iter, GtkTextMark *mark) { - if (mark == gtk_text_buffer_get_insert (buffer) || - mark == gtk_text_buffer_get_selection_bound (buffer)) + GtkTextMark *insert; + + insert = gtk_text_buffer_get_insert (buffer); + + if (mark == insert || mark == gtk_text_buffer_get_selection_bound (buffer)) { gboolean has_selection; @@ -2287,6 +2316,9 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer, g_object_notify (G_OBJECT (buffer), "has-selection"); } } + + if (mark == insert) + g_object_notify (G_OBJECT (buffer), "cursor-position"); } static void