Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Bug: ControlNode registers MouseUp/MouseDown events twice (Read 2202 times)
Chris Morgan
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 1
Joined: Dec 13th, 2012
Bug: ControlNode registers MouseUp/MouseDown events twice
Dec 13th, 2012 at 6:06am
Print Post  
I have a Control inside a ControlNode with non-idempotent double-click behaviour (first time will work, second will cause an error). The problem was, the Diagram.NodeDoubleClick event was being fired twice each time. (Ditto for NodeClick where I was handling right-clicking, but that was less important.) I finally pinpointed the problem: the ControlNode is listening to the Control.MouseUp and Control.MouseDown events twice each. Our company having access to the source code, I identified the reason why. The problem appears to be that the ControlNode attaches to the Control events in both OnAdd and SetControl. That is, when the control is set, it registers the mouse event handlers, and then when the ControlNode is added to the Diagram, it registers it a second time.

I believe that the OnAdd/OnRemove ones should be removed. (Having fixed that, it works correctly and as I would expect it to.)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Bug: ControlNode registers MouseUp/MouseDown events twice
Reply #1 - Dec 14th, 2012 at 10:01am
Print Post  
Indeed the events get handled twice. Our developer thinks we still need the OnRemove and OnAdd code though; e.g. in a scenario where you move the node's Control to the form and remove the node from the diagram, the handlers should be removed from OnRemove so that the node no longer listens to the control's events. We'll add some checks for whether there are handlers already attached before attaching again.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Bug: ControlNode registers MouseUp/MouseDown events twice
Reply #2 - Jan 23rd, 2013 at 8:32am
Print Post  
What our developer did is removing the handlers before adding new ones, both in OnAdd and SetControl methods:

Code
Select All
// Detach any event handlers if they are already attached,
// to make sure we won't get double notifications
control.MouseDown -= OnControlMouseDown;
control.MouseUp -= OnControlMouseUp;

// Listen to mouse clicks over the control
control.MouseDown += OnControlMouseDown;
control.MouseUp += OnControlMouseUp;
 



The -= operator will do nothing if there aren't handlers attached, otherwise will remove current handlers. Attaching and detaching in OnAdd / OnRemove is necessary in some scenarios, e.g. if you move a ControlNode between different diagrams.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint