chiark / gitweb /
Text demo extended to show cursor position
[clg] / examples / testgtk.lisp
index 24ae1115ed3041e0b05fe974d65c42a974ab2e96..915bba3e86fda36b50f5fbc40b2acb463bc435ab 100644 (file)
@@ -26,7 +26,7 @@
 ;; Kimball, Josh MacDonald and others.
 
 
-;; $Id: testgtk.lisp,v 1.35 2006-04-26 14:59:50 espen Exp $
+;; $Id: testgtk.lisp,v 1.36 2006-09-05 13:49:26 espen Exp $
 
 #+sbcl(require :gtk)
 #+(or cmu clisp)(asdf:oos 'asdf:load-op :gtk)
@@ -1617,7 +1617,34 @@ (define-simple-dialog create-text (dialog "Text" :default-width 400
         :after t)
        
        (container-add dialog (ui-manager-get-widget ui "/ToolBar") :expand nil)
-       (container-add dialog text-view)))))
+       (container-add dialog text-view) 
+
+       (let ((position (make-instance 'label :visible t)))
+         (flet ((update-position (line column)
+                  (setf 
+                   (label-label position)
+                   (format nil "Cursor Position: ~d,~d" (1+ line) column))))
+           (update-position 0 0)
+
+           ;; Callback to display current position when cursor is moved
+           (signal-connect buffer 'mark-set
+            #'(lambda (iter mark)
+                (when (and 
+                       (slot-boundp mark 'name) 
+                       (string= (text-mark-name mark) "insert"))
+                  (update-position 
+                   (text-iter-line iter) (text-iter-line-offset iter)))))
+
+           ;; Callback to display current position after the
+           ;; buffer has been modified
+           (signal-connect buffer 'changed
+            #'(lambda ()
+                (let ((iter (text-buffer-get-iter-at-insert buffer)))
+                  (update-position 
+                   (text-iter-line iter) (text-iter-line-offset iter))))
+            :after t))
+
+         (container-add dialog position :expand nil))))))
 
 
 ;;; Toggle buttons