All Manuals > CAPI User Guide > 16 Drag and Drop > 16.3 Dropping > 16.3.2 Dropping in a choice

NextPrevUpTopContentsIndex Example: dropping in a list

This drop-callback simply appends the dropped string at the end of the list:

(defun list-drop-callback (pane drop-object stage)
  (format t "list drop callback ~S ~S ~S" pane  drop-object stage)
  (case stage
     (set-drop-object-supported-formats drop-object
                                        (list :string)))
     (when (and (drop-object-provides-format drop-object
                (drop-object-allows-drop-effect-p drop-object
       (setf (drop-object-drop-effect drop-object) :copy)))
     (when (and (drop-object-provides-format drop-object
                (drop-object-allows-drop-effect-p drop-object
       (setf (drop-object-drop-effect drop-object) :copy)
       (add-list-item pane drop-object)))))
(defun add-list-item (pane drop-object)
        (list (string-capitalize 
               (drop-object-get-object drop-object 
                                       pane :string)))))
 (make-instance 'list-panel
                :title "Shopping list"
                :items (list "Tea" "Bread")
                :drop-callback 'list-drop-callback))

Try dragging an item from the tree-view created in Example: dragging from a tree.

Below is a more sophisticated version of add-list-item which inserts the item at the expected position within the list. This position is obtained using drop-object-collection-index :

(defun add-list-item (pane drop-object)
  (multiple-value-bind (index placement)
      (drop-object-collection-index drop-object)
    (list-panel-add-item pane 
                           drop-object pane :string))
                         index placement))))))
(defun list-panel-add-item (pane item index placement)
  (let ((item-count (count-collection-items pane)))
    (let ((adjusted-index (if (eq placement :above)
                            (1+ index)))
          (current-items (collection-items pane)))
      (setf (collection-items pane)
            (concatenate 'simple-vector
                         (subseq current-items 0 adjusted-index)
                         (vector item)
                         (subseq current-items adjusted-index 

CAPI User Guide (Macintosh version) - 30 Aug 2011