]> Pileus Git - ~andy/gtk/commitdiff
Add a :cursor-position property. (#334412, Yevgen Muntyan) `
authorMatthias Clasen <mclasen@redhat.com>
Tue, 9 May 2006 04:44:53 +0000 (04:44 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 9 May 2006 04:44:53 +0000 (04:44 +0000)
2006-05-09  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtktextbuffer.c (gtk_text_buffer_class_init): Add a :cursor-position
property.  (#334412, Yevgen Muntyan)
`

ChangeLog
ChangeLog.pre-2-10
gtk/gtktextbuffer.c

index e4a1169fde23525d87cc5c5b7dc9ccc2a7e5598f..252d22cc108cbaf690c4822525502af5fd0c51de 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-05-09  Matthias Clasen  <mclasen@redhat.com>
 
+       * 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)
 
index e4a1169fde23525d87cc5c5b7dc9ccc2a7e5598f..252d22cc108cbaf690c4822525502af5fd0c51de 100644 (file)
@@ -1,5 +1,8 @@
 2006-05-09  Matthias Clasen  <mclasen@redhat.com>
 
+       * 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)
 
index b9f2f7acb9b4f531139fbfae4b79351d4cf63d71..3ab7602bbba3e14c1b42c50cce03a333ce2bc3d0 100644 (file)
@@ -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