The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

190 lines
8.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__
  19. #define __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__
  20. #include "../keyboard/juce_ModifierKeys.h"
  21. #include "../../../core/juce_Time.h"
  22. #include "../../../memory/juce_ScopedPointer.h"
  23. #include "../../graphics/geometry/juce_Point.h"
  24. #include "../juce_Desktop.h"
  25. class MouseInputSourceInternal;
  26. //==============================================================================
  27. /**
  28. Represents a linear source of mouse events from a mouse device or individual finger
  29. in a multi-touch environment.
  30. Each MouseEvent object contains a reference to the MouseInputSource that generated
  31. it. In an environment with a single mouse for input, all events will come from the
  32. same source, but in a multi-touch system, there may be multiple MouseInputSource
  33. obects active, each representing a stream of events coming from a particular finger.
  34. Events coming from a single MouseInputSource are always sent in a fixed and predictable
  35. order: a mouseMove will never be called without a mouseEnter having been sent beforehand,
  36. the only events that can happen between a mouseDown and its corresponding mouseUp are
  37. mouseDrags, etc.
  38. When there are multiple touches arriving from multiple MouseInputSources, their
  39. event streams may arrive in an interleaved order, so you should use the getIndex()
  40. method to find out which finger each event came from.
  41. @see MouseEvent
  42. */
  43. class JUCE_API MouseInputSource
  44. {
  45. public:
  46. //==============================================================================
  47. /** Creates a MouseInputSource.
  48. You should never actually create a MouseInputSource in your own code - the
  49. library takes care of managing these objects.
  50. */
  51. MouseInputSource (int index, bool isMouseDevice);
  52. /** Destructor. */
  53. ~MouseInputSource();
  54. //==============================================================================
  55. /** Returns true if this object represents a normal desk-based mouse device. */
  56. bool isMouse() const;
  57. /** Returns true if this object represents a source of touch events - i.e. a finger or stylus. */
  58. bool isTouch() const;
  59. /** Returns true if this source has an on-screen pointer that can hover over
  60. items without clicking them.
  61. */
  62. bool canHover() const;
  63. /** Returns true if this source may have a scroll wheel. */
  64. bool hasMouseWheel() const;
  65. /** Returns this source's index in the global list of possible sources.
  66. If the system only has a single mouse, there will only be a single MouseInputSource
  67. with an index of 0.
  68. If the system supports multi-touch input, then the index will represent a finger
  69. number, starting from 0. When the first touch event begins, it will have finger
  70. number 0, and then if a second touch happens while the first is still down, it
  71. will have index 1, etc.
  72. */
  73. int getIndex() const;
  74. /** Returns true if this device is currently being pressed. */
  75. bool isDragging() const;
  76. /** Returns the last-known screen position of this source. */
  77. const Point<int> getScreenPosition() const;
  78. /** Returns a set of modifiers that indicate which buttons are currently
  79. held down on this device.
  80. */
  81. const ModifierKeys getCurrentModifiers() const;
  82. /** Returns the component that was last known to be under this pointer. */
  83. Component* getComponentUnderMouse() const;
  84. /** Tells the device to dispatch a mouse-move or mouse-drag event.
  85. This is asynchronous - the event will occur on the message thread.
  86. */
  87. void triggerFakeMove() const;
  88. /** Returns the number of clicks that should be counted as belonging to the
  89. current mouse event.
  90. So the mouse is currently down and it's the second click of a double-click, this
  91. will return 2.
  92. */
  93. int getNumberOfMultipleClicks() const throw();
  94. /** Returns the time at which the last mouse-down occurred. */
  95. const Time getLastMouseDownTime() const throw();
  96. /** Returns the screen position at which the last mouse-down occurred. */
  97. const Point<int> getLastMouseDownPosition() const throw();
  98. /** Returns true if this mouse is currently down, and if it has been dragged more
  99. than a couple of pixels from the place it was pressed.
  100. */
  101. bool hasMouseMovedSignificantlySincePressed() const throw();
  102. /** Returns true if this input source uses a visible mouse cursor. */
  103. bool hasMouseCursor() const throw();
  104. /** Changes the mouse cursor, (if there is one). */
  105. void showMouseCursor (const MouseCursor& cursor);
  106. /** Hides the mouse cursor (if there is one). */
  107. void hideCursor();
  108. /** Un-hides the mouse cursor if it was hidden by hideCursor(). */
  109. void revealCursor();
  110. /** Forces an update of the mouse cursor for whatever component it's currently over. */
  111. void forceMouseCursorUpdate();
  112. /** Returns true if this mouse can be moved indefinitely in any direction without running out of space. */
  113. bool canDoUnboundedMovement() const throw();
  114. /** Allows the mouse to move beyond the edges of the screen.
  115. Calling this method when the mouse button is currently pressed will remove the cursor
  116. from the screen and allow the mouse to (seem to) move beyond the edges of the screen.
  117. This means that the co-ordinates returned to mouseDrag() will be unbounded, and this
  118. can be used for things like custom slider controls or dragging objects around, where
  119. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  120. The unbounded mode is automatically turned off when the mouse button is released, or
  121. it can be turned off explicitly by calling this method again.
  122. @param isEnabled whether to turn this mode on or off
  123. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  124. hidden; if true, it will only be hidden when it
  125. is moved beyond the edge of the screen
  126. */
  127. void enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen = false);
  128. //==============================================================================
  129. /** @internal */
  130. void handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, int64 time, const ModifierKeys& mods);
  131. /** @internal */
  132. void handleWheel (ComponentPeer* peer, const Point<int>& positionWithinPeer, int64 time, float x, float y);
  133. private:
  134. //==============================================================================
  135. friend class Desktop;
  136. friend class ComponentPeer;
  137. friend class MouseInputSourceInternal;
  138. ScopedPointer<MouseInputSourceInternal> pimpl;
  139. static const Point<int> getCurrentMousePosition();
  140. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseInputSource);
  141. };
  142. #endif // __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__