[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about double-clicks



Andrew,
  The best way to think of double clicks is as an extension of a single
click.  It the first click selects an object, then the second click
should do the action.  For example:


(require 'quickdraw)

(defclass click-view (view)
  ((view-selected-p :accessor view-selected-p
		        :initform nil)))

;;; Just a method of showing the view to the user
(defmethod view-draw-contents ((me click-view))
  ; draw the view with the approriate color
  (rlet ((my-rect :rect
		      :topleft #@(0 0)
		      :bottomRight (view-size me)))
    (with-fore-color (if (view-selected-p me)
			     *yellow-color*
			     *blue-color*)
      (paint-rect me my-rect))
    (frame-rect me my-rect)))

;;; THIS is what you are interested in -
(defmethod view-click-event-handler ((me click-view) where)
  (declare (ignore where))
  (without-interrupts 
   ; to start, unclick everyone
   (do-subviews (the-click-view (view-window me) 'click-view)
    (setf (view-selected-p the-click-view) nil)
    (invalidate-view the-click-view t))
   ; select or do the action if it is a double click
   (setf (view-selected-p me) t)
   (invalidate-view me t))
  (case *multi-click-count*
      (1 (print "Single click"))
      (2 (when (double-click-p)
           ; Do the action here
           (print "Double click")))
      (t (when (double-click-p)
           ; Do the action here
           (print "Hey -- stop clicking on me")))))

;;; create a test window
(make-instance 'window 
  :window-title "Click-Test"
  :view-size #@(158 84)
  :grow-icon-p nil
  :window-type :document
  :color-p t
  :view-subviews (list
                  (make-instance 'click-view 
                    :view-position #@(10 10)
                    :view-size #@(64 64))
                  (make-instance 'click-view 
                    :view-position #@(84 10)
                    :view-size #@(64 64))))
		
You can see that a single, then a double click is sensed (as it should be).
Another example is clicking on a line:
	1 click = put cursor here
	2 clicks = select a word
	3 clicks = select the entire line
Thus you can perform the actions is sequence.

If the rare case when have completely separate actions depending of the
number of clicks you need to implement a loop and wait for the mouse up
and down events yourself (and check DOUBLE-CLICK-SPACING-P, the time between
mouse clicks, are you in the same view, etc).

Hope this helps,
         Jeffrey
         

======================================
Jeffrey Kane, MD
Kane Biomedical Systems
Boston, MA

Internet    jbk@world.std.com
Compuserve  74206,640
AppleLink   D0738

[Don't take life too seriously... it's not like anyone gets out of it alive.]