|
@@ -116,25 +116,9 @@ void EventDispatcher::dispatchShortcutReleased(const std::vector<EShortcut> & sh
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void EventDispatcher::dispatchMouseDoubleClick(const Point & position)
|
|
|
+void EventDispatcher::dispatchMouseDoubleClick(const Point & position, int tolerance)
|
|
|
{
|
|
|
- bool doubleClicked = false;
|
|
|
- auto hlp = doubleClickInterested;
|
|
|
-
|
|
|
- for(auto & i : hlp)
|
|
|
- {
|
|
|
- if(!vstd::contains(doubleClickInterested, i))
|
|
|
- continue;
|
|
|
-
|
|
|
- if(i->receiveEvent(position, AEventsReceiver::DOUBLECLICK))
|
|
|
- {
|
|
|
- i->clickDouble(position);
|
|
|
- doubleClicked = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!doubleClicked)
|
|
|
- handleLeftButtonClick(position, 0, true);
|
|
|
+ handleDoubleButtonClick(position, tolerance);
|
|
|
}
|
|
|
|
|
|
void EventDispatcher::dispatchMouseLeftButtonPressed(const Point & position, int tolerance)
|
|
@@ -246,6 +230,38 @@ void EventDispatcher::handleLeftButtonClick(const Point & position, int toleranc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void EventDispatcher::handleDoubleButtonClick(const Point & position, int tolerance)
|
|
|
+{
|
|
|
+ // WARNING: this approach is NOT SAFE
|
|
|
+ // 1) We allow (un)registering elements when list itself is being processed/iterated
|
|
|
+ // 2) To avoid iterator invalidation we create a copy of this list for processing
|
|
|
+ // HOWEVER it is completely possible (as in, actually happen, no just theory) to:
|
|
|
+ // 1) element gets unregistered and deleted from lclickable
|
|
|
+ // 2) element is completely deleted, as in - destructor called, memory freed
|
|
|
+ // 3) new element is created *with exactly same address(!)
|
|
|
+ // 4) new element is registered and code will incorrectly assume that this element is still registered
|
|
|
+ // POSSIBLE SOLUTION: make EventReceivers inherit from create_shared_from this and store weak_ptr's in lists
|
|
|
+
|
|
|
+ AEventsReceiver * nearestElement = findElementInToleranceRange(doubleClickInterested, position, AEventsReceiver::DOUBLECLICK, tolerance);
|
|
|
+ bool doubleClicked = false;
|
|
|
+ auto hlp = doubleClickInterested;
|
|
|
+
|
|
|
+ for(auto & i : hlp)
|
|
|
+ {
|
|
|
+ if(!vstd::contains(doubleClickInterested, i))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if(i->receiveEvent(position, AEventsReceiver::DOUBLECLICK) || i == nearestElement)
|
|
|
+ {
|
|
|
+ i->clickDouble(position);
|
|
|
+ doubleClicked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!doubleClicked)
|
|
|
+ handleLeftButtonClick(position, tolerance, true);
|
|
|
+}
|
|
|
+
|
|
|
void EventDispatcher::dispatchMouseScrolled(const Point & distance, const Point & position)
|
|
|
{
|
|
|
EventReceiversList hlp = wheelInterested;
|