+;;; Tree Sortable
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (define-enum-type sort-column (:default -1) (:unsorted -2))
+ (define-enum-type sort-order (:before -1) (:equal 0) (:after 1)))
+
+
+(def-callback-marshal %tree-iter-compare-func
+ ((or int sort-order) tree-model (a (copy-of tree-iter)) (b (copy-of tree-iter))))
+
+(defbinding tree-sortable-sort-column-changed () nil
+ (sortable tree-sortable))
+
+(defbinding %tree-sortable-get-sort-column-id () boolean
+ (sortable tree-sortable)
+ (column int :out)
+ (order sort-type :out))
+
+(defun tree-sortable-get-sort-column (sortable)
+ (multiple-value-bind (special-p column order)
+ (%tree-sortable-get-sort-column-id sortable)
+ (values
+ (if special-p
+ (int-to-sort-order column)
+ (column-name sortable column))
+ order)))
+
+(defbinding (tree-sortable-set-sort-column
+ "gtk_tree_sortable_set_sort_column_id")
+ (sortable column order) nil
+ (sortable tree-sortable)
+ ((etypecase column
+ ((or integer sort-column) column)
+ (symbol (column-index sortable column)))
+ (or sort-column int))
+ (order sort-type))
+
+(defbinding %tree-sortable-set-sort-func (sortable column function) nil
+ (sortable tree-sortable)
+ ((column-index sortable column) int)
+ (%tree-iter-compare-func callback)
+ ((register-callback-function function) unsigned-int)
+ (user-data-destroy-func callback))
+
+(defbinding %tree-sortable-set-default-sort-func () nil
+ (sortable tree-sortable)
+ (compare-func (or null pointer))
+ (callback-id unsigned-int)
+ (destroy-func (or null pointer)))
+
+(defun tree-sortable-set-sort-func (sortable column function)
+ "Sets the comparison function used when sorting to be FUNCTION. If
+the current sort column of SORTABLE is the same as COLUMN,
+then the model will sort using this function."
+ (cond
+ ((and (eq column :default) (not function))
+ (%tree-sortable-set-default-sort-func sortable nil 0 nil))
+ ((eq column :default)
+ (%tree-sortable-set-default-sort-func sortable
+ (callback %tree-iter-compare-func)
+ (register-callback-function function)
+ (callback user-data-destroy-func)))
+ ((%tree-sortable-set-sort-func sortable column function))))
+
+(defbinding tree-sortable-has-default-sort-func-p () boolean
+ (sortable tree-sortable))
+