From cbdf70711628f910e1337fe84e4f2f73d0d124ff Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 11 Aug 2016 11:02:04 +0100 Subject: [PATCH] Windows touch with CallOutBox bug fix --- .../native/juce_win32_Windowing.cpp | 3 +-- .../windows/juce_CallOutBox.cpp | 19 ++++++++++++++++++- .../juce_gui_basics/windows/juce_CallOutBox.h | 6 +++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 49c2c7ec62..4c7236430e 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -1967,8 +1967,7 @@ private: { bool isCancel = false; - // touchIndex zero is reserved for the mouse - const int touchIndex = currentTouches.getIndexOfTouch (touch.dwID) + 1; + const int touchIndex = currentTouches.getIndexOfTouch (touch.dwID); const int64 time = getMouseEventTime(); const Point pos (globalToLocal (Point (touch.x / 100.0f, touch.y / 100.0f))); diff --git a/modules/juce_gui_basics/windows/juce_CallOutBox.cpp b/modules/juce_gui_basics/windows/juce_CallOutBox.cpp index 55bf420245..4e60941055 100644 --- a/modules/juce_gui_basics/windows/juce_CallOutBox.cpp +++ b/modules/juce_gui_basics/windows/juce_CallOutBox.cpp @@ -41,7 +41,11 @@ CallOutBox::CallOutBox (Component& c, const Rectangle& area, Component* con .getDisplayContaining (area.getCentre()).userArea); addToDesktop (ComponentPeer::windowIsTemporary); + + startTimer (100); } + + creationTime = Time::getCurrentTime(); } CallOutBox::~CallOutBox() @@ -129,7 +133,14 @@ void CallOutBox::inputAttemptWhenModal() // if you click on the area that originally popped-up the callout, you expect it // to get rid of the box, but deleting the box here allows the click to pass through and // probably re-trigger it, so we need to dismiss the box asynchronously to consume the click.. - dismiss(); + + // For touchscreens, we make sure not to dismiss the CallOutBox immediately, + // as Windows still sends touch events before the CallOutBox had a chance + // to really open. + + RelativeTime elapsed = Time::getCurrentTime() - creationTime; + if (elapsed.inMilliseconds() > 200) + dismiss(); } else { @@ -240,3 +251,9 @@ void CallOutBox::refreshPath() targetPoint - getPosition().toFloat(), 9.0f, arrowSize * 0.7f); } + +void CallOutBox::timerCallback() +{ + toFront (true); + stopTimer(); +} diff --git a/modules/juce_gui_basics/windows/juce_CallOutBox.h b/modules/juce_gui_basics/windows/juce_CallOutBox.h index 82c3cb4206..1e598eb219 100644 --- a/modules/juce_gui_basics/windows/juce_CallOutBox.h +++ b/modules/juce_gui_basics/windows/juce_CallOutBox.h @@ -53,7 +53,8 @@ The call-out will resize and position itself when the content changes size. */ -class JUCE_API CallOutBox : public Component +class JUCE_API CallOutBox : public Component, + private Timer { public: //============================================================================== @@ -173,7 +174,10 @@ private: Image background; bool dismissalMouseClicksAreAlwaysConsumed; + Time creationTime; + void refreshPath(); + void timerCallback() override; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CallOutBox) };