X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/2a8752b025e5b22396c063505279a35e08dc3778..f4ba8dcb96baefeab615d39c901769b7136e32aa:/gtk/gtktree.lisp diff --git a/gtk/gtktree.lisp b/gtk/gtktree.lisp index 5bbc67a..5e4ca4e 100644 --- a/gtk/gtktree.lisp +++ b/gtk/gtktree.lisp @@ -15,7 +15,7 @@ ;; License along with this library; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -;; $Id: gtktree.lisp,v 1.2 2004-11-15 19:24:03 espen Exp $ +;; $Id: gtktree.lisp,v 1.6 2005-02-03 23:09:09 espen Exp $ (in-package "GTK") @@ -54,14 +54,14 @@ (column int)) (def-callback-marshal %cell-layout-data-func - (nil cell-layout cell-renderer tree-model tree-iter)) + (nil cell-layout cell-renderer tree-model (copy-of tree-iter))) (defbinding cell-layout-set-cell-data-func (cell-layout cell function) nil (cell-layout cell-layout) (cell cell-renderer) ((callback %cell-layout-data-func) pointer) ((register-callback-function function) unsigned-int) - ((callback %destroy-user-data) pointer)) + ((callback user-data-destroy-func) pointer)) (defbinding cell-layout-clear-attributes () nil (cell-layout cell-layout) @@ -93,10 +93,26 @@ ((length columns) unsigned-int) (columns (vector gtype))) -(defbinding list-store-remove () boolean +(defbinding %list-store-remove () boolean (list-store list-store) (tree-iter tree-iter)) +(defun list-store-remove (store row) + (etypecase row + (tree-iter + (%list-store-remove store row)) + (tree-path + (multiple-value-bind (valid iter) (tree-model-get-iter store row) + (if valid + (%list-store-remove store iter) + (error "~A not poiniting to av valid iterator in ~A" row store)))) + (tree-row-reference + (let ((path (tree-row-reference-get-path row))) + (if path + (list-store-remove store path) + (error "~A not valid" row)))))) + + (defbinding %list-store-insert () nil (list-store list-store) (tree-iter tree-iter) @@ -192,12 +208,12 @@ (funcall (writer-function 'pointer) c-vector location (size-of 'int)) location)) -(defun %tree-path-to-vector (location &optional (destroy-p t)) - (prog1 - (map-c-vector 'vector #'identity (%tree-path-get-indices location) - 'int (%tree-path-get-depth location)) - (when destroy-p - (%tree-path-free location)))) +(defun %tree-path-to-vector (location) + (let ((indices (%tree-path-get-indices location)) + (depth (%tree-path-get-depth location))) + (if (null-pointer-p indices) + #() + (map-c-vector 'vector #'identity indices 'int depth)))) (eval-when (:compile-toplevel :load-toplevel :execute) (defmethod alien-type ((type (eql 'tree-path)) &rest args) @@ -212,25 +228,51 @@ (declare (ignore type args)) `(%make-tree-path ,path)) - (defmethod to-alien-function ((type (eql 'tree-path)) &rest args) - (declare (ignore type args)) - #'%make-tree-path) - (defmethod from-alien-form (location (type (eql 'tree-path)) &rest args) (declare (ignore type args)) - `(%tree-path-to-vector ,location)) + `(let ((location ,location)) + (prog1 + (%tree-path-to-vector location) + (%tree-path-free location)))) - (defmethod from-alien-function ((type (eql 'tree-path)) &rest args) + (defmethod copy-from-alien-form (location (type (eql 'tree-path)) &rest args) (declare (ignore type args)) - #'%tree-path-to-vector) + `(%tree-path-to-vector ,location)) (defmethod cleanup-form (location (type (eql 'tree-path)) &rest args) (declare (ignore type args)) - `(%tree-path-free ,location)) + `(%tree-path-free ,location))) + +(defmethod to-alien-function ((type (eql 'tree-path)) &rest args) + (declare (ignore type args)) + #'%make-tree-path) - (defmethod cleanup-function ((type (eql 'tree-path)) &rest args) - (declare (ignore type args)) - #'%tree-path-free)) +(defmethod from-alien-function ((type (eql 'tree-path)) &rest args) + (declare (ignore type args)) + #'(lambda (location) + (prog1 + (%tree-path-to-vector location) + (%tree-path-free location)))) + +(defmethod copy-from-alien-function ((type (eql 'tree-path)) &rest args) + (declare (ignore type args)) + #'%tree-path-to-vector) + +(defmethod cleanup-function ((type (eql 'tree-path)) &rest args) + (declare (ignore type args)) + #'%tree-path-free) + +(defmethod writer-function ((type (eql 'tree-path)) &rest args) + (declare (ignore type args)) + (let ((writer (writer-function 'pointer))) + #'(lambda (path location &optional (offset 0)) + (funcall writer (%make-tree-path path) location offset)))) + +(defmethod reader-function ((type (eql 'tree-path)) &rest args) + (declare (ignore type args)) + (let ((reader (reader-function 'pointer))) + #'(lambda (location &optional (offset 0)) + (%tree-path-to-vector (funcall reader location offset))))) (defbinding %tree-row-reference-new () pointer @@ -238,7 +280,6 @@ (path tree-path)) (defmethod initialize-instance ((reference tree-row-reference) &key model path) - (declare (ignore initargs)) (setf (slot-value reference 'location) (%tree-row-reference-new model path)) @@ -251,7 +292,7 @@ (reference tree-row-reference)) -(defbinding tree-model-get-column-type () type-number +(defbinding tree-model-get-column-type () gtype ;type-number (tree-model tree-model) (index int)) @@ -271,9 +312,9 @@ (column int) (gvalue gvalue)) -(defun tree-model-get-column-value (model iter column) +(defun tree-model-column-value (model iter column) (let ((index (column-index model column))) - (with-gvalue (gvalue (tree-model-get-column-type model index)) + (with-gvalue (gvalue) (%tree-model-get-value model iter index gvalue)))) (defbinding tree-model-iter-next () boolean @@ -296,7 +337,7 @@ (iter tree-iter)) (defbinding tree-model-iter-nth-child - (tree-model parent &optional (iter (make-instance 'tree-iter))) boolean + (tree-model parent n &optional (iter (make-instance 'tree-iter))) boolean (tree-model tree-model) (iter tree-iter :return) (parent (or null tree-iter)) @@ -308,12 +349,8 @@ (iter tree-iter :return) (child tree-iter)) -(defbinding tree-model-get-string-from-iter () string - (tree-model tree-model) - (iter tree-iter)) - (def-callback-marshal %tree-model-foreach-func - (boolean tree-model tree-path tree-iter)) + (boolean tree-model (path (copy-of tree-path)) (iter (copy-of tree-iter)))) (defbinding %tree-model-foreach () nil (tree-model tree-model) @@ -381,7 +418,8 @@ (let ((setter (mkbinding (column-setter-name model) nil (type-of model) 'tree-iter 'int - (type-from-number (tree-model-get-column-type model index)) +; (type-from-number (tree-model-get-column-type model index)) + (tree-model-get-column-type model index) 'int))) #'(lambda (value iter) (funcall setter model iter index value -1)))))))) @@ -420,6 +458,97 @@ while rest)))) +;;; Tree Selection + +(def-callback-marshal %tree-selection-func (boolean tree-selection tree-model (path (copy-of tree-path)) (path-currently-selected boolean))) + +(defbinding tree-selection-set-select-function (selection function) nil + (selection tree-selection) + ((callback %tree-selection-func) pointer) + ((register-callback-function function) unsigned-int) + ((callback user-data-destroy-func) pointer)) + +(defbinding tree-selection-get-selected + (selection &optional (iter (make-instance 'tree-iter))) boolean + (selection tree-selection) + (nil null) + (iter tree-iter :return)) + +(def-callback-marshal %tree-selection-foreach-func (nil tree-model (path (copy-of tree-path)) (iter (copy-of tree-iter)))) + +(defbinding %tree-selection-selected-foreach () nil + (tree-selection tree-selection) + ((callback %tree-selection-foreach-func) pointer) + (callback-id unsigned-int)) + +(defun tree-selection-selected-foreach (selection function) + (with-callback-function (id function) + (%tree-selection-selected-foreach selection id))) + +(defbinding tree-selection-get-selected-rows () (glist tree-path) + (tree-selection tree-selection) + (nil null)) + +(defbinding tree-selection-count-selected-rows () int + (tree-selection tree-selection)) + +(defbinding %tree-selection-select-path () nil + (tree-selection tree-selection) + (tree-path tree-path)) + +(defbinding %tree-selection-unselect-path () nil + (tree-selection tree-selection) + (tree-path tree-path)) + +(defbinding %tree-selection-path-is-selected () boolean + (tree-selection tree-selection) + (tree-path tree-path)) + +(defbinding %tree-selection-select-iter () nil + (tree-selection tree-selection) + (tree-path tree-path)) + +(defbinding %tree-selection-unselect-iter () nil + (tree-selection tree-selection) + (tree-path tree-path)) + +(defbinding %tree-selection-iter-is-selected () boolean + (tree-selection tree-selection) + (tree-path tree-path)) + +(defun tree-selection-select (selection row) + (etypecase row + (tree-path (%tree-selection-select-path selection row)) + (tree-iter (%tree-selection-select-iter selection row)))) + +(defun tree-selection-unselect (selection row) + (etypecase row + (tree-path (%tree-selection-unselect-path selection row)) + (tree-iter (%tree-selection-unselect-iter selection row)))) + +(defun tree-selection-is-selected-p (selection row) + (etypecase row + (tree-path (%tree-selection-path-is-selected selection row)) + (tree-iter (%tree-selection-iter-is-selected selection row)))) + +(defbinding tree-selection-select-all () nil + (tree-selection tree-selection)) + +(defbinding tree-selection-unselect-all () nil + (tree-selection tree-selection)) + +(defbinding tree-selection-select-range () nil + (tree-selection tree-selection) + (start tree-path) + (end tree-path)) + +(defbinding tree-selection-unselect-range () nil + (tree-selection tree-selection) + (start tree-path) + (end tree-path)) + + + ;;; Tree Store (defbinding %tree-store-set-column-types () nil @@ -460,7 +589,7 @@ (parent (or null tree-iter)) (sibling (or null tree-iter))) -(defun tree-store-insert-after +(defun tree-store-insert-before (store parent sibling &optional data (iter (make-instance 'tree-iter))) (%tree-store-insert-before store iter parent sibling) (when data (%tree-model-set store iter data)) @@ -537,16 +666,14 @@ ;;; Tree View -(defmethod initialize-instance ((tree-view tree-view) &key column) +(defmethod initialize-instance ((tree-view tree-view) &rest initargs + &key column) (call-next-method) (mapc #'(lambda (column) (tree-view-append-column tree-view column)) (get-all initargs :column))) -(defbinding tree-view-get-selection () tree-selection - (tree-view tree-view)) - (defbinding tree-view-columns-autosize () nil (tree-view tree-view)) @@ -558,7 +685,7 @@ (tree-view tree-view) (tree-view-column tree-view-column)) -(defbinding tree-view-insert-column (view columnd position) int +(defbinding tree-view-insert-column (view column position) int (view tree-view) (column tree-view-column) ((if (eq position :end) -1 position) int)) @@ -629,7 +756,7 @@ (tree-view tree-view) (path tree-path)) -(def-callback-marshal %tree-view-mapping-func (nil tree-view tree-path)) +(def-callback-marshal %tree-view-mapping-func (nil tree-view (path (copy-of tree-path)))) (defbinding %tree-view-map-expanded-rows () nil (tree-view tree-view)