[cells-gtk-cvs] CVS update: root/cells-gtk/textview.lisp

Peter Denno pdenno at common-lisp.net
Sun Mar 6 16:58:52 UTC 2005


Update of /project/cells-gtk/cvsroot/root/cells-gtk
In directory common-lisp.net:/tmp/cvs-serv22226/root/cells-gtk

Modified Files:
	textview.lisp 
Log Message:
New stuff for gtk-text-buffer tags and marks. Requires libcellsgtk.so
Date: Sun Mar  6 17:58:51 2005
Author: pdenno

Index: root/cells-gtk/textview.lisp
diff -u root/cells-gtk/textview.lisp:1.3 root/cells-gtk/textview.lisp:1.4
--- root/cells-gtk/textview.lisp:1.3	Sat Feb 26 23:29:23 2005
+++ root/cells-gtk/textview.lisp	Sun Mar  6 17:58:51 2005
@@ -19,15 +19,21 @@
 (in-package :cgtk)
 
 (def-object text-buffer ()
-  ((text :accessor text :initarg :text :initform nil))
-  ()
+  ((text :accessor text :initarg :text :initform nil)
+   (tag-table :accessor tag-table :initarg :tag-table :initform (c-in nil))
+   (markup :cell nil :accessor markup :initform nil))
   ()
+  (modified-changed)
   :new-args (c? (list c-null)))
 
 (def-c-output text ((self text-buffer))
-  (gtk-text-buffer-set-text (id self) 
-			      (or new-value "")
-			      -1))
+  (let ((buf (id self)))
+    (gtk-text-buffer-set-text buf (or new-value "") -1)
+    ;; Typically if you are interested in watching for modifications,
+    ;; you don't want to see ones such as this, where it is done programmatically.
+    ;; Thus we clear the modified flag. Your on-modified method can check for this.
+    ;; It can even reset it, if you don't like this arrangement.
+    (gtk-text-buffer-set-modified buf nil)))
 
 (def-widget text-view ()
   ((buffer :accessor buffer :initarg :buffer :initform (mk-text-buffer))
@@ -95,8 +101,49 @@
             (setf (old-popups text-view) accum)
             (mapc #'(lambda (i) (to-be i) (gtk-menu-shell-prepend popup-menu (id i))) tops))))))
 
+(defmacro with-text-iters (vars &body body)
+  `(let (,@(loop for var in vars collect `(,var (gtk-adds-text-iter-new))))
+     (unwind-protect 
+       (progn , at body)
+       ,@(loop for var in vars collect `(gtk-text-iter-free ,var)))))
+
+(defun text-buffer-get-text (buffer &optional (start 0) stop)
+  "Get text directly from buffer. Unlike the cell accessor, this sees edits."
+  (let* ((buf (id buffer))
+         (end (or stop (gtk-text-buffer-get-char-count buf))))
+    (with-text-iters (s-iter e-iter)
+      (gtk-text-buffer-get-iter-at-offset buf s-iter start)
+      (gtk-text-buffer-get-iter-at-offset buf e-iter end)
+      (gtk-text-buffer-get-text buf s-iter e-iter nil))))
+
+(defun text-buffer-insert-text (buffer start text)
+  (let ((buf (id buffer)))
+    (with-text-iters (s-iter)
+      (gtk-text-buffer-get-iter-at-offset buf s-iter start)
+      (gtk-text-buffer-insert buf s-iter text (length text))
+      (gtk-text-buffer-set-modified buf t))))
+
+(defun text-buffer-delete-text (buffer start end)
+  (let ((buf (id buffer)))
+    (with-text-iters (s-iter e-iter)
+      (gtk-text-buffer-get-iter-at-offset buf s-iter start)
+      (gtk-text-buffer-get-iter-at-offset buf e-iter end)
+      (gtk-text-buffer-delete buf s-iter e-iter))))
+
+;;; The next two can be used to check and clear the the modified flag.
+;;; The event is registered when you use :on-modified-changed on a text-buffer.
+;;; The def-c-output text ((text-buffer)) clears the flag so as to distinguish
+;;; programmatic updates to the text from ones done by typing.
+(defmethod text-buffer-modified-p ((buffer text-buffer))
+  (gtk-text-buffer-get-modified (id buffer)))
+
+(defmethod (setf text-buffer-modified-p) (val (buffer text-buffer))
+  (gtk-text-buffer-set-modified (id buffer) val))
+
+
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (export '(def-populate-adds populate-adds)))
+  (export '(def-populate-adds populate-adds with-text-iters text-buffer-get-text
+            text-buffer-delete-text text-buffer-insert-text text-buffer-modified-p)))
 
 
 




More information about the Cells-gtk-cvs mailing list