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.

380 lines
16KB

  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_DESKTOP_JUCEHEADER__
  19. #define __JUCE_DESKTOP_JUCEHEADER__
  20. #include "juce_Component.h"
  21. #include "../../core/juce_Time.h"
  22. #include "../../utilities/juce_DeletedAtShutdown.h"
  23. #include "../../events/juce_Timer.h"
  24. #include "../../events/juce_AsyncUpdater.h"
  25. #include "../../containers/juce_OwnedArray.h"
  26. #include "../graphics/geometry/juce_RectangleList.h"
  27. #include "layout/juce_ComponentAnimator.h"
  28. class MouseInputSource;
  29. class MouseInputSourceInternal;
  30. class MouseListener;
  31. //==============================================================================
  32. /**
  33. Classes can implement this interface and register themselves with the Desktop class
  34. to receive callbacks when the currently focused component changes.
  35. @see Desktop::addFocusChangeListener, Desktop::removeFocusChangeListener
  36. */
  37. class JUCE_API FocusChangeListener
  38. {
  39. public:
  40. /** Destructor. */
  41. virtual ~FocusChangeListener() {}
  42. /** Callback to indicate that the currently focused component has changed. */
  43. virtual void globalFocusChanged (Component* focusedComponent) = 0;
  44. };
  45. //==============================================================================
  46. /**
  47. Describes and controls aspects of the computer's desktop.
  48. */
  49. class JUCE_API Desktop : private DeletedAtShutdown,
  50. private Timer,
  51. private AsyncUpdater
  52. {
  53. public:
  54. //==============================================================================
  55. /** There's only one dektop object, and this method will return it.
  56. */
  57. static Desktop& JUCE_CALLTYPE getInstance();
  58. //==============================================================================
  59. /** Returns a list of the positions of all the monitors available.
  60. The first rectangle in the list will be the main monitor area.
  61. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  62. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  63. */
  64. const RectangleList getAllMonitorDisplayAreas (bool clippedToWorkArea = true) const throw();
  65. /** Returns the position and size of the main monitor.
  66. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  67. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  68. */
  69. const Rectangle<int> getMainMonitorArea (bool clippedToWorkArea = true) const throw();
  70. /** Returns the position and size of the monitor which contains this co-ordinate.
  71. If none of the monitors contains the point, this will just return the
  72. main monitor.
  73. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  74. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  75. */
  76. const Rectangle<int> getMonitorAreaContaining (const Point<int>& position, bool clippedToWorkArea = true) const;
  77. //==============================================================================
  78. /** Returns the mouse position.
  79. The co-ordinates are relative to the top-left of the main monitor.
  80. Note that this is just a shortcut for calling getMainMouseSource().getScreenPosition(), and
  81. you should only resort to grabbing the global mouse position if there's really no
  82. way to get the coordinates via a mouse event callback instead.
  83. */
  84. static const Point<int> getMousePosition();
  85. /** Makes the mouse pointer jump to a given location.
  86. The co-ordinates are relative to the top-left of the main monitor.
  87. */
  88. static void setMousePosition (const Point<int>& newPosition);
  89. /** Returns the last position at which a mouse button was pressed.
  90. Note that this is just a shortcut for calling getMainMouseSource().getLastMouseDownPosition(),
  91. and in a multi-touch environment, it doesn't make much sense. ALWAYS prefer to
  92. get this information via other means, such as MouseEvent::getMouseDownScreenPosition()
  93. if possible, and only ever call this as a last resort.
  94. */
  95. static const Point<int> getLastMouseDownPosition();
  96. /** Returns the number of times the mouse button has been clicked since the
  97. app started.
  98. Each mouse-down event increments this number by 1.
  99. */
  100. static int getMouseButtonClickCounter();
  101. //==============================================================================
  102. /** This lets you prevent the screensaver from becoming active.
  103. Handy if you're running some sort of presentation app where having a screensaver
  104. appear would be annoying.
  105. Pass false to disable the screensaver, and true to re-enable it. (Note that this
  106. won't enable a screensaver unless the user has actually set one up).
  107. The disablement will only happen while the Juce application is the foreground
  108. process - if another task is running in front of it, then the screensaver will
  109. be unaffected.
  110. @see isScreenSaverEnabled
  111. */
  112. static void setScreenSaverEnabled (bool isEnabled);
  113. /** Returns true if the screensaver has not been turned off.
  114. This will return the last value passed into setScreenSaverEnabled(). Note that
  115. it won't tell you whether the user is actually using a screen saver, just
  116. whether this app is deliberately preventing one from running.
  117. @see setScreenSaverEnabled
  118. */
  119. static bool isScreenSaverEnabled();
  120. //==============================================================================
  121. /** Registers a MouseListener that will receive all mouse events that occur on
  122. any component.
  123. @see removeGlobalMouseListener
  124. */
  125. void addGlobalMouseListener (MouseListener* listener);
  126. /** Unregisters a MouseListener that was added with the addGlobalMouseListener()
  127. method.
  128. @see addGlobalMouseListener
  129. */
  130. void removeGlobalMouseListener (MouseListener* listener);
  131. //==============================================================================
  132. /** Registers a MouseListener that will receive a callback whenever the focused
  133. component changes.
  134. */
  135. void addFocusChangeListener (FocusChangeListener* listener);
  136. /** Unregisters a listener that was added with addFocusChangeListener(). */
  137. void removeFocusChangeListener (FocusChangeListener* listener);
  138. //==============================================================================
  139. /** Takes a component and makes it full-screen, removing the taskbar, dock, etc.
  140. The component must already be on the desktop for this method to work. It will
  141. be resized to completely fill the screen and any extraneous taskbars, menu bars,
  142. etc will be hidden.
  143. To exit kiosk mode, just call setKioskModeComponent (0). When this is called,
  144. the component that's currently being used will be resized back to the size
  145. and position it was in before being put into this mode.
  146. If allowMenusAndBars is true, things like the menu and dock (on mac) are still
  147. allowed to pop up when the mouse moves onto them. If this is false, it'll try
  148. to hide as much on-screen paraphenalia as possible.
  149. */
  150. void setKioskModeComponent (Component* componentToUse,
  151. bool allowMenusAndBars = true);
  152. /** Returns the component that is currently being used in kiosk-mode.
  153. This is the component that was last set by setKioskModeComponent(). If none
  154. has been set, this returns 0.
  155. */
  156. Component* getKioskModeComponent() const throw() { return kioskModeComponent; }
  157. //==============================================================================
  158. /** Returns the number of components that are currently active as top-level
  159. desktop windows.
  160. @see getComponent, Component::addToDesktop
  161. */
  162. int getNumComponents() const throw();
  163. /** Returns one of the top-level desktop window components.
  164. The index is from 0 to getNumComponents() - 1. This could return 0 if the
  165. index is out-of-range.
  166. @see getNumComponents, Component::addToDesktop
  167. */
  168. Component* getComponent (int index) const throw();
  169. /** Finds the component at a given screen location.
  170. This will drill down into top-level windows to find the child component at
  171. the given position.
  172. Returns 0 if the co-ordinates are inside a non-Juce window.
  173. */
  174. Component* findComponentAt (const Point<int>& screenPosition) const;
  175. /** The Desktop object has a ComponentAnimator instance which can be used for performing
  176. your animations.
  177. Having a single shared ComponentAnimator object makes it more efficient when multiple
  178. components are being moved around simultaneously. It's also more convenient than having
  179. to manage your own instance of one.
  180. @see ComponentAnimator
  181. */
  182. ComponentAnimator& getAnimator() throw() { return animator; }
  183. //==============================================================================
  184. /** Returns the number of MouseInputSource objects the system has at its disposal.
  185. In a traditional single-mouse system, there might be only one object. On a multi-touch
  186. system, there could be one input source per potential finger.
  187. To find out how many mouse events are currently happening, use getNumDraggingMouseSources().
  188. @see getMouseSource
  189. */
  190. int getNumMouseSources() const throw() { return mouseSources.size(); }
  191. /** Returns one of the system's MouseInputSource objects.
  192. The index should be from 0 to getNumMouseSources() - 1. Out-of-range indexes will return
  193. a null pointer.
  194. In a traditional single-mouse system, there might be only one object. On a multi-touch
  195. system, there could be one input source per potential finger.
  196. */
  197. MouseInputSource* getMouseSource (int index) const throw() { return mouseSources [index]; }
  198. /** Returns the main mouse input device that the system is using.
  199. @see getNumMouseSources()
  200. */
  201. MouseInputSource& getMainMouseSource() const throw() { return *mouseSources.getUnchecked(0); }
  202. /** Returns the number of mouse-sources that are currently being dragged.
  203. In a traditional single-mouse system, this will be 0 or 1, depending on whether a
  204. juce component has the button down on it. In a multi-touch system, this could
  205. be any number from 0 to the number of simultaneous touches that can be detected.
  206. */
  207. int getNumDraggingMouseSources() const throw();
  208. /** Returns one of the mouse sources that's currently being dragged.
  209. The index should be between 0 and getNumDraggingMouseSources() - 1. If the index is
  210. out of range, or if no mice or fingers are down, this will return a null pointer.
  211. */
  212. MouseInputSource* getDraggingMouseSource (int index) const throw();
  213. //==============================================================================
  214. /** In a tablet device which can be turned around, this is used to inidicate the orientation. */
  215. enum DisplayOrientation
  216. {
  217. upright = 1, /**< Indicates that the display is the normal way up. */
  218. upsideDown = 2, /**< Indicates that the display is upside-down. */
  219. rotatedClockwise = 4, /**< Indicates that the display is turned 90 degrees clockwise from its upright position. */
  220. rotatedAntiClockwise = 8, /**< Indicates that the display is turned 90 degrees anti-clockwise from its upright position. */
  221. allOrientations = 1 + 2 + 4 + 8 /**< A combination of all the orientation values */
  222. };
  223. /** In a tablet device which can be turned around, this returns the current orientation. */
  224. DisplayOrientation getCurrentOrientation() const;
  225. /** Sets which orientations the display is allowed to auto-rotate to.
  226. For devices that support rotating desktops, this lets you specify which of the orientations your app can use.
  227. The parameter is a bitwise or-ed combination of the values in DisplayOrientation, and must contain at least one
  228. set bit.
  229. */
  230. void setOrientationsEnabled (int allowedOrientations);
  231. /** Returns whether the display is allowed to auto-rotate to the given orientation.
  232. Each orientation can be enabled using setOrientationEnabled(). By default, all orientations are allowed.
  233. */
  234. bool isOrientationEnabled (DisplayOrientation orientation) const throw();
  235. //==============================================================================
  236. /** Tells this object to refresh its idea of what the screen resolution is.
  237. (Called internally by the native code).
  238. */
  239. void refreshMonitorSizes();
  240. /** True if the OS supports semitransparent windows */
  241. static bool canUseSemiTransparentWindows() throw();
  242. private:
  243. //==============================================================================
  244. static Desktop* instance;
  245. friend class Component;
  246. friend class ComponentPeer;
  247. friend class MouseInputSource;
  248. friend class MouseInputSourceInternal;
  249. friend class DeletedAtShutdown;
  250. friend class TopLevelWindowManager;
  251. OwnedArray <MouseInputSource> mouseSources;
  252. void createMouseInputSources();
  253. ListenerList <MouseListener> mouseListeners;
  254. ListenerList <FocusChangeListener> focusListeners;
  255. Array <Component*> desktopComponents;
  256. Array <Rectangle<int> > monitorCoordsClipped, monitorCoordsUnclipped;
  257. Point<int> lastFakeMouseMove;
  258. void sendMouseMove();
  259. int mouseClickCounter;
  260. void incrementMouseClickCounter() throw();
  261. Component* kioskModeComponent;
  262. Rectangle<int> kioskComponentOriginalBounds;
  263. int allowedOrientations;
  264. ComponentAnimator animator;
  265. static const Point<int> getRawMousePosition();
  266. void timerCallback();
  267. void resetTimer();
  268. int getNumDisplayMonitors() const throw();
  269. const Rectangle<int> getDisplayMonitorCoordinates (int index, bool clippedToWorkArea) const throw();
  270. void addDesktopComponent (Component* c);
  271. void removeDesktopComponent (Component* c);
  272. void componentBroughtToFront (Component* c);
  273. void triggerFocusCallback();
  274. void handleAsyncUpdate();
  275. Desktop();
  276. ~Desktop();
  277. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Desktop);
  278. };
  279. #endif // __JUCE_DESKTOP_JUCEHEADER__