Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

687 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class MouseInputSourceInternal : private AsyncUpdater
  18. {
  19. public:
  20. //==============================================================================
  21. MouseInputSourceInternal (const int i, const bool isMouse)
  22. : index (i), isMouseDevice (isMouse),
  23. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false),
  24. lastPeer (nullptr), currentCursorHandle (nullptr),
  25. mouseEventCounter (0), mouseMovedSignificantlySincePressed (false)
  26. {
  27. }
  28. //==============================================================================
  29. bool isDragging() const noexcept
  30. {
  31. return buttonState.isAnyMouseButtonDown();
  32. }
  33. Component* getComponentUnderMouse() const
  34. {
  35. return componentUnderMouse.get();
  36. }
  37. ModifierKeys getCurrentModifiers() const
  38. {
  39. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  40. }
  41. ComponentPeer* getPeer()
  42. {
  43. if (! ComponentPeer::isValidPeer (lastPeer))
  44. lastPeer = nullptr;
  45. return lastPeer;
  46. }
  47. static Point<int> screenPosToLocalPos (Component& comp, Point<int> pos)
  48. {
  49. if (ComponentPeer* const peer = comp.getPeer())
  50. {
  51. pos = peer->globalToLocal (pos);
  52. Component& peerComp = peer->getComponent();
  53. return comp.getLocalPoint (&peerComp, ScalingHelpers::unscaledScreenPosToScaled (peerComp, pos));
  54. }
  55. return comp.getLocalPoint (nullptr, ScalingHelpers::unscaledScreenPosToScaled (comp, pos));
  56. }
  57. Component* findComponentAt (Point<int> screenPos)
  58. {
  59. if (ComponentPeer* const peer = getPeer())
  60. {
  61. Point<int> relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
  62. peer->globalToLocal (screenPos)));
  63. Component& comp = peer->getComponent();
  64. // (the contains() call is needed to test for overlapping desktop windows)
  65. if (comp.contains (relativePos))
  66. return comp.getComponentAt (relativePos);
  67. }
  68. return nullptr;
  69. }
  70. Point<int> getScreenPosition() const
  71. {
  72. // This needs to return the live position if possible, but it mustn't update the lastScreenPos
  73. // value, because that can cause continuity problems.
  74. return ScalingHelpers::unscaledScreenPosToScaled
  75. (unboundedMouseOffset + (isMouseDevice ? MouseInputSource::getCurrentRawMousePosition()
  76. : lastScreenPos));
  77. }
  78. void setScreenPosition (Point<int> p)
  79. {
  80. MouseInputSource::setRawMousePosition (ScalingHelpers::scaledScreenPosToUnscaled (p));
  81. }
  82. //==============================================================================
  83. #if JUCE_DUMP_MOUSE_EVENTS
  84. #define JUCE_MOUSE_EVENT_DBG(desc) DBG ("Mouse " << desc << " #" << index \
  85. << ": " << screenPosToLocalPos (comp, screenPos).toString() \
  86. << " - Comp: " << String::toHexString ((pointer_sized_int) &comp));
  87. #else
  88. #define JUCE_MOUSE_EVENT_DBG(desc)
  89. #endif
  90. void sendMouseEnter (Component& comp, Point<int> screenPos, Time time)
  91. {
  92. JUCE_MOUSE_EVENT_DBG ("enter")
  93. comp.internalMouseEnter (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
  94. }
  95. void sendMouseExit (Component& comp, Point<int> screenPos, Time time)
  96. {
  97. JUCE_MOUSE_EVENT_DBG ("exit")
  98. comp.internalMouseExit (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
  99. }
  100. void sendMouseMove (Component& comp, Point<int> screenPos, Time time)
  101. {
  102. JUCE_MOUSE_EVENT_DBG ("move")
  103. comp.internalMouseMove (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
  104. }
  105. void sendMouseDown (Component& comp, Point<int> screenPos, Time time)
  106. {
  107. JUCE_MOUSE_EVENT_DBG ("down")
  108. comp.internalMouseDown (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
  109. }
  110. void sendMouseDrag (Component& comp, Point<int> screenPos, Time time)
  111. {
  112. JUCE_MOUSE_EVENT_DBG ("drag")
  113. comp.internalMouseDrag (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
  114. }
  115. void sendMouseUp (Component& comp, Point<int> screenPos, Time time, const ModifierKeys oldMods)
  116. {
  117. JUCE_MOUSE_EVENT_DBG ("up")
  118. comp.internalMouseUp (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, oldMods);
  119. }
  120. void sendMouseWheel (Component& comp, Point<int> screenPos, Time time, const MouseWheelDetails& wheel)
  121. {
  122. JUCE_MOUSE_EVENT_DBG ("wheel")
  123. comp.internalMouseWheel (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, wheel);
  124. }
  125. void sendMagnifyGesture (Component& comp, Point<int> screenPos, Time time, const float amount)
  126. {
  127. JUCE_MOUSE_EVENT_DBG ("magnify")
  128. comp.internalMagnifyGesture (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, amount);
  129. }
  130. //==============================================================================
  131. // (returns true if the button change caused a modal event loop)
  132. bool setButtons (Point<int> screenPos, Time time, const ModifierKeys newButtonState)
  133. {
  134. if (buttonState == newButtonState)
  135. return false;
  136. // (avoid sending a spurious mouse-drag when we receive a mouse-up)
  137. if (! (isDragging() && ! newButtonState.isAnyMouseButtonDown()))
  138. setScreenPos (screenPos, time, false);
  139. // (ignore secondary clicks when there's already a button down)
  140. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  141. {
  142. buttonState = newButtonState;
  143. return false;
  144. }
  145. const int lastCounter = mouseEventCounter;
  146. if (buttonState.isAnyMouseButtonDown())
  147. {
  148. if (Component* const current = getComponentUnderMouse())
  149. {
  150. const ModifierKeys oldMods (getCurrentModifiers());
  151. buttonState = newButtonState; // must change this before calling sendMouseUp, in case it runs a modal loop
  152. sendMouseUp (*current, screenPos + unboundedMouseOffset, time, oldMods);
  153. if (lastCounter != mouseEventCounter)
  154. return true; // if a modal loop happened, then newButtonState is no longer valid.
  155. }
  156. enableUnboundedMouseMovement (false, false);
  157. }
  158. buttonState = newButtonState;
  159. if (buttonState.isAnyMouseButtonDown())
  160. {
  161. Desktop::getInstance().incrementMouseClickCounter();
  162. if (Component* const current = getComponentUnderMouse())
  163. {
  164. registerMouseDown (screenPos, time, *current, buttonState);
  165. sendMouseDown (*current, screenPos, time);
  166. }
  167. }
  168. return lastCounter != mouseEventCounter;
  169. }
  170. void setComponentUnderMouse (Component* const newComponent, Point<int> screenPos, Time time)
  171. {
  172. Component* current = getComponentUnderMouse();
  173. if (newComponent != current)
  174. {
  175. WeakReference<Component> safeNewComp (newComponent);
  176. const ModifierKeys originalButtonState (buttonState);
  177. if (current != nullptr)
  178. {
  179. WeakReference<Component> safeOldComp (current);
  180. setButtons (screenPos, time, ModifierKeys());
  181. if (safeOldComp != nullptr)
  182. {
  183. componentUnderMouse = safeNewComp;
  184. sendMouseExit (*safeOldComp, screenPos, time);
  185. }
  186. buttonState = originalButtonState;
  187. }
  188. current = componentUnderMouse = safeNewComp;
  189. if (current != nullptr)
  190. sendMouseEnter (*current, screenPos, time);
  191. revealCursor (false);
  192. setButtons (screenPos, time, originalButtonState);
  193. }
  194. }
  195. void setPeer (ComponentPeer& newPeer, Point<int> screenPos, Time time)
  196. {
  197. ModifierKeys::updateCurrentModifiers();
  198. if (&newPeer != lastPeer)
  199. {
  200. setComponentUnderMouse (nullptr, screenPos, time);
  201. lastPeer = &newPeer;
  202. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  203. }
  204. }
  205. void setScreenPos (Point<int> newScreenPos, Time time, const bool forceUpdate)
  206. {
  207. if (! isDragging())
  208. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  209. if (newScreenPos != lastScreenPos || forceUpdate)
  210. {
  211. cancelPendingUpdate();
  212. lastScreenPos = newScreenPos;
  213. if (Component* const current = getComponentUnderMouse())
  214. {
  215. if (isDragging())
  216. {
  217. registerMouseDrag (newScreenPos);
  218. sendMouseDrag (*current, newScreenPos + unboundedMouseOffset, time);
  219. if (isUnboundedMouseModeOn)
  220. handleUnboundedDrag (current);
  221. }
  222. else
  223. {
  224. sendMouseMove (*current, newScreenPos, time);
  225. }
  226. }
  227. revealCursor (false);
  228. }
  229. }
  230. //==============================================================================
  231. void handleEvent (ComponentPeer& newPeer, Point<int> positionWithinPeer, Time time, const ModifierKeys newMods)
  232. {
  233. lastTime = time;
  234. ++mouseEventCounter;
  235. const Point<int> screenPos (newPeer.localToGlobal (positionWithinPeer));
  236. if (isDragging() && newMods.isAnyMouseButtonDown())
  237. {
  238. setScreenPos (screenPos, time, false);
  239. }
  240. else
  241. {
  242. setPeer (newPeer, screenPos, time);
  243. if (ComponentPeer* peer = getPeer())
  244. {
  245. if (setButtons (screenPos, time, newMods))
  246. return; // some modal events have been dispatched, so the current event is now out-of-date
  247. peer = getPeer();
  248. if (peer != nullptr)
  249. setScreenPos (screenPos, time, false);
  250. }
  251. }
  252. }
  253. Component* getTargetForGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
  254. Time time, Point<int>& screenPos)
  255. {
  256. lastTime = time;
  257. ++mouseEventCounter;
  258. screenPos = peer.localToGlobal (positionWithinPeer);
  259. setPeer (peer, screenPos, time);
  260. setScreenPos (screenPos, time, false);
  261. triggerFakeMove();
  262. return isDragging() ? nullptr : getComponentUnderMouse();
  263. }
  264. void handleWheel (ComponentPeer& peer, Point<int> positionWithinPeer,
  265. Time time, const MouseWheelDetails& wheel)
  266. {
  267. Desktop::getInstance().incrementMouseWheelCounter();
  268. Point<int> screenPos;
  269. if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos))
  270. sendMouseWheel (*current, screenPos, time, wheel);
  271. }
  272. void handleMagnifyGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
  273. Time time, const float scaleFactor)
  274. {
  275. Point<int> screenPos;
  276. if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos))
  277. sendMagnifyGesture (*current, screenPos, time, scaleFactor);
  278. }
  279. //==============================================================================
  280. Time getLastMouseDownTime() const noexcept { return mouseDowns[0].time; }
  281. Point<int> getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); }
  282. int getNumberOfMultipleClicks() const noexcept
  283. {
  284. int numClicks = 0;
  285. if (mouseDowns[0].time != Time())
  286. {
  287. if (! mouseMovedSignificantlySincePressed)
  288. ++numClicks;
  289. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  290. {
  291. if (mouseDowns[0].canBePartOfMultipleClickWith (mouseDowns[i], MouseEvent::getDoubleClickTimeout() * jmin (i, 2)))
  292. ++numClicks;
  293. else
  294. break;
  295. }
  296. }
  297. return numClicks;
  298. }
  299. bool hasMouseMovedSignificantlySincePressed() const noexcept
  300. {
  301. return mouseMovedSignificantlySincePressed
  302. || lastTime > mouseDowns[0].time + RelativeTime::milliseconds (300);
  303. }
  304. //==============================================================================
  305. void triggerFakeMove()
  306. {
  307. triggerAsyncUpdate();
  308. }
  309. void handleAsyncUpdate() override
  310. {
  311. setScreenPos (lastScreenPos, jmax (lastTime, Time::getCurrentTime()), true);
  312. }
  313. //==============================================================================
  314. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  315. {
  316. enable = enable && isDragging();
  317. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  318. if (enable != isUnboundedMouseModeOn)
  319. {
  320. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  321. {
  322. // when released, return the mouse to within the component's bounds
  323. if (Component* current = getComponentUnderMouse())
  324. Desktop::setMousePosition (current->getScreenBounds()
  325. .getConstrainedPoint (lastScreenPos));
  326. }
  327. isUnboundedMouseModeOn = enable;
  328. unboundedMouseOffset = Point<int>();
  329. revealCursor (true);
  330. }
  331. }
  332. void handleUnboundedDrag (Component* current)
  333. {
  334. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  335. if (! screenArea.contains (lastScreenPos))
  336. {
  337. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  338. unboundedMouseOffset += (lastScreenPos - componentCentre);
  339. Desktop::setMousePosition (componentCentre);
  340. }
  341. else if (isCursorVisibleUntilOffscreen
  342. && (! unboundedMouseOffset.isOrigin())
  343. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  344. {
  345. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  346. unboundedMouseOffset = Point<int>();
  347. }
  348. }
  349. //==============================================================================
  350. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  351. {
  352. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  353. {
  354. cursor = MouseCursor::NoCursor;
  355. forcedUpdate = true;
  356. }
  357. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  358. {
  359. currentCursorHandle = cursor.getHandle();
  360. cursor.showInWindow (getPeer());
  361. }
  362. }
  363. void hideCursor()
  364. {
  365. showMouseCursor (MouseCursor::NoCursor, true);
  366. }
  367. void revealCursor (bool forcedUpdate)
  368. {
  369. MouseCursor mc (MouseCursor::NormalCursor);
  370. if (Component* current = getComponentUnderMouse())
  371. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  372. showMouseCursor (mc, forcedUpdate);
  373. }
  374. //==============================================================================
  375. const int index;
  376. const bool isMouseDevice;
  377. Point<int> lastScreenPos;
  378. ModifierKeys buttonState;
  379. Point<int> unboundedMouseOffset;
  380. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  381. private:
  382. WeakReference<Component> componentUnderMouse;
  383. ComponentPeer* lastPeer;
  384. void* currentCursorHandle;
  385. int mouseEventCounter;
  386. struct RecentMouseDown
  387. {
  388. RecentMouseDown() noexcept : peerID (0) {}
  389. Point<int> position;
  390. Time time;
  391. ModifierKeys buttons;
  392. uint32 peerID;
  393. bool canBePartOfMultipleClickWith (const RecentMouseDown& other, const int maxTimeBetweenMs) const
  394. {
  395. return time - other.time < RelativeTime::milliseconds (maxTimeBetweenMs)
  396. && abs (position.x - other.position.x) < 8
  397. && abs (position.y - other.position.y) < 8
  398. && buttons == other.buttons
  399. && peerID == other.peerID;
  400. }
  401. };
  402. RecentMouseDown mouseDowns[4];
  403. Time lastTime;
  404. bool mouseMovedSignificantlySincePressed;
  405. void registerMouseDown (Point<int> screenPos, Time time,
  406. Component& component, const ModifierKeys modifiers) noexcept
  407. {
  408. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  409. mouseDowns[i] = mouseDowns[i - 1];
  410. mouseDowns[0].position = screenPos;
  411. mouseDowns[0].time = time;
  412. mouseDowns[0].buttons = modifiers.withOnlyMouseButtons();
  413. if (ComponentPeer* const peer = component.getPeer())
  414. mouseDowns[0].peerID = peer->getUniqueID();
  415. else
  416. mouseDowns[0].peerID = 0;
  417. mouseMovedSignificantlySincePressed = false;
  418. }
  419. void registerMouseDrag (Point<int> screenPos) noexcept
  420. {
  421. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  422. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  423. }
  424. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseInputSourceInternal)
  425. };
  426. //==============================================================================
  427. MouseInputSource::MouseInputSource (MouseInputSourceInternal* s) noexcept : pimpl (s) {}
  428. MouseInputSource::MouseInputSource (const MouseInputSource& other) noexcept : pimpl (other.pimpl) {}
  429. MouseInputSource::~MouseInputSource() noexcept {}
  430. MouseInputSource& MouseInputSource::operator= (const MouseInputSource& other) noexcept
  431. {
  432. pimpl = other.pimpl;
  433. return *this;
  434. }
  435. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  436. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  437. bool MouseInputSource::canHover() const { return isMouse(); }
  438. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  439. int MouseInputSource::getIndex() const { return pimpl->index; }
  440. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  441. Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  442. ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  443. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  444. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  445. int MouseInputSource::getNumberOfMultipleClicks() const noexcept { return pimpl->getNumberOfMultipleClicks(); }
  446. Time MouseInputSource::getLastMouseDownTime() const noexcept { return pimpl->getLastMouseDownTime(); }
  447. Point<int> MouseInputSource::getLastMouseDownPosition() const noexcept { return pimpl->getLastMouseDownPosition(); }
  448. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const noexcept { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  449. bool MouseInputSource::canDoUnboundedMovement() const noexcept { return isMouse(); }
  450. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) const
  451. { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  452. bool MouseInputSource::isUnboundedMouseMovementEnabled() const { return pimpl->isUnboundedMouseModeOn; }
  453. bool MouseInputSource::hasMouseCursor() const noexcept { return isMouse(); }
  454. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  455. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  456. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  457. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  458. void MouseInputSource::setScreenPosition (Point<int> p) { pimpl->setScreenPosition (p); }
  459. void MouseInputSource::handleEvent (ComponentPeer& peer, Point<int> positionWithinPeer,
  460. const int64 time, const ModifierKeys mods)
  461. {
  462. pimpl->handleEvent (peer, positionWithinPeer, Time (time), mods.withOnlyMouseButtons());
  463. }
  464. void MouseInputSource::handleWheel (ComponentPeer& peer, Point<int> positionWithinPeer,
  465. const int64 time, const MouseWheelDetails& wheel)
  466. {
  467. pimpl->handleWheel (peer, positionWithinPeer, Time (time), wheel);
  468. }
  469. void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
  470. const int64 time, const float scaleFactor)
  471. {
  472. pimpl->handleMagnifyGesture (peer, positionWithinPeer, Time (time), scaleFactor);
  473. }
  474. //==============================================================================
  475. struct MouseInputSource::SourceList : public Timer
  476. {
  477. SourceList()
  478. {
  479. addSource();
  480. }
  481. bool addSource();
  482. void addSource (int index, bool isMouse)
  483. {
  484. MouseInputSourceInternal* s = new MouseInputSourceInternal (index, isMouse);
  485. sources.add (s);
  486. sourceArray.add (MouseInputSource (s));
  487. }
  488. MouseInputSource* getMouseSource (int index) const noexcept
  489. {
  490. return isPositiveAndBelow (index, sourceArray.size()) ? &sourceArray.getReference (index)
  491. : nullptr;
  492. }
  493. MouseInputSource* getOrCreateMouseInputSource (int touchIndex)
  494. {
  495. jassert (touchIndex >= 0 && touchIndex < 100); // sanity-check on number of fingers
  496. for (;;)
  497. {
  498. if (MouseInputSource* mouse = getMouseSource (touchIndex))
  499. return mouse;
  500. if (! addSource())
  501. {
  502. jassertfalse; // not enough mouse sources!
  503. return nullptr;
  504. }
  505. }
  506. }
  507. int getNumDraggingMouseSources() const noexcept
  508. {
  509. int num = 0;
  510. for (int i = 0; i < sources.size(); ++i)
  511. if (sources.getUnchecked(i)->isDragging())
  512. ++num;
  513. return num;
  514. }
  515. MouseInputSource* getDraggingMouseSource (int index) const noexcept
  516. {
  517. int num = 0;
  518. for (int i = 0; i < sources.size(); ++i)
  519. {
  520. MouseInputSource* const mi = &(sourceArray.getReference(i));
  521. if (mi->isDragging())
  522. {
  523. if (index == num)
  524. return mi;
  525. ++num;
  526. }
  527. }
  528. return nullptr;
  529. }
  530. void beginDragAutoRepeat (const int interval)
  531. {
  532. if (interval > 0)
  533. {
  534. if (getTimerInterval() != interval)
  535. startTimer (interval);
  536. }
  537. else
  538. {
  539. stopTimer();
  540. }
  541. }
  542. void timerCallback() override
  543. {
  544. int numMiceDown = 0;
  545. for (int i = 0; i < sources.size(); ++i)
  546. {
  547. MouseInputSourceInternal* const mi = sources.getUnchecked(i);
  548. if (mi->isDragging())
  549. {
  550. mi->triggerFakeMove();
  551. ++numMiceDown;
  552. }
  553. }
  554. if (numMiceDown == 0)
  555. stopTimer();
  556. }
  557. OwnedArray<MouseInputSourceInternal> sources;
  558. Array<MouseInputSource> sourceArray;
  559. };