Drag'n drop with multiple controls

Started by krunch, October 03, 2010, 03:18:25 PM

Previous topic - Next topic

krunch

I want to manage drag'n drop with several picture controls, so I need the base + destination controls for each drag'n drop event...

> If I have N controls I have to place N DragnDropFromControl-event functions ?
   No general function can retrieves the control that triggered the current event ??

> DragnDropFromControl event needs a transparent function (with at least a princ) on DragnDropBegin event to trigger ???

owenwengerd

You can use the same event handler function for all controls, but you'll have to maintain your own state data separately. Offhand I don't know why DragnDropFromControl would need DragnDropBegin to be defined. It might be a bug, in which case a simple example would be useful.
Owen Wengerd (Outside The Box) / ManuSoft

krunch

Hi
Here is a simple example with 3 pictures, the lisp code below manages drag'n drop by flipping colors of the pictures...

question1 : the 3 'DragnDropFrom events' just serve to retrieve the 'dest' control of the drag'n drop.. I was looking for a way to get a reference to this control, to do the same thing by 1 function instead of 1 function per control...

question2 : the 'dummy function' can be the same for all pictures, but if you turn off the DragnDropBegin event for one of the picture the DragnDropFrom event is not triggered anymore..


Code (autolisp) Select

(command "OPENDCL")

(defun c:Go ()
  (dcl_Project_Load "Dragtest" T)
  (dcl_Form_Show Dragtest_Form)
  (princ)
)

; Dummy function
(defun c:Dragtest_Form_PictureBox1_OnDragnDropBegin (/)
  (princ)
)
; DragnDropFrom events
(defun c:Dragtest_Form_PictureBox1_OnDragnDropFromControl (ProjectName FormName ControlName DropPoint /)
  (Flip ControlName "PictureBox1")
)
(defun c:Dragtest_Form_PictureBox2_OnDragnDropFromControl (ProjectName FormName ControlName DropPoint /)
  (Flip ControlName "PictureBox2")
)
(defun c:Dragtest_Form_PictureBox3_OnDragnDropFromControl (ProjectName FormName ControlName DropPoint /)
  (Flip ControlName "PictureBox3")
)
; Flip colors
(defun Flip (from dest / tmp)
  (setq tmp (dcl_Control_GetBackColor "Dragtest" "Form" from))
  (dcl_Control_SetBackColor "Dragtest" "Form" from (dcl_Control_GetBackColor "Dragtest" "Form" dest))
  (dcl_Control_SetBackColor "Dragtest" "Form" dest tmp)
)

krunch

Hi. May be I've been forgotten, so I'd like to ask my double-question again...

- On a general point of view, if a form contains 20 buttons to watch... does I necessarily need 20 triggered functions to get the control reference ?
Or is there a way to get the control from the current event ?

- In my example (I re-join the lisp code) I think there's a drag'n drop problem : just turn off the DragnDropBegin event for one of the pictures and the DragnDropBegin dosn't works ...
Apparently it needs a (princ) function ?

owenwengerd

Quote- On a general point of view, if a form contains 20 buttons to watch... does I necessarily need 20 triggered functions to get the control reference ?
Or is there a way to get the control from the current event ?

Strictly speaking, you can use the same event handler for multiple controls, but there is no intrinsic way to discern which control triggered a given event. In some cases you may be able to use other information to determine which control triggered the event. For example, in the case of DragnDropFromControl you could use the DropPoint to determine which control triggered the event.


Quote- In my example (I re-join the lisp code) I think there's a drag'n drop problem : just turn off the DragnDropBegin event for one of the pictures and the DragnDropBegin dosn't works ...
Apparently it needs a (princ) function ?

You're correct, this was a bug, now fixed for the next build.  BTW, that was an excellent sample; it was short and to the point, demonstrated the bug clearly, and was even kind of fun to play with!
Owen Wengerd (Outside The Box) / ManuSoft

krunch

Hi, thanks for your answer
I retrieve this problem as I finish my project...

QuoteFor example, in the case of DragnDropFromControl you could use the DropPoint to determine which control triggered the event.
> The DropPoint argument specifies the control client coordinates, relatives to the PictureBox origin.. so it can't help me to determine the control.

So I suppose there's no way  :( and as a conclusion : if a form contains 20 buttons it needs 20 triggered functions to watch them..