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.

327 lines
13KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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. class MouseInputSource;
  28. class MouseInputSourceInternal;
  29. class MouseListener;
  30. //==============================================================================
  31. /**
  32. Classes can implement this interface and register themselves with the Desktop class
  33. to receive callbacks when the currently focused component changes.
  34. @see Desktop::addFocusChangeListener, Desktop::removeFocusChangeListener
  35. */
  36. class JUCE_API FocusChangeListener
  37. {
  38. public:
  39. /** Destructor. */
  40. virtual ~FocusChangeListener() {}
  41. /** Callback to indicate that the currently focused component has changed. */
  42. virtual void globalFocusChanged (Component* focusedComponent) = 0;
  43. };
  44. //==============================================================================
  45. /**
  46. Describes and controls aspects of the computer's desktop.
  47. */
  48. class JUCE_API Desktop : private DeletedAtShutdown,
  49. private Timer,
  50. private AsyncUpdater
  51. {
  52. public:
  53. //==============================================================================
  54. /** There's only one dektop object, and this method will return it.
  55. */
  56. static Desktop& JUCE_CALLTYPE getInstance();
  57. //==============================================================================
  58. /** Returns a list of the positions of all the monitors available.
  59. The first rectangle in the list will be the main monitor area.
  60. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  61. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  62. */
  63. const RectangleList getAllMonitorDisplayAreas (bool clippedToWorkArea = true) const throw();
  64. /** Returns the position and size of the main monitor.
  65. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  66. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  67. */
  68. const Rectangle<int> getMainMonitorArea (bool clippedToWorkArea = true) const throw();
  69. /** Returns the position and size of the monitor which contains this co-ordinate.
  70. If none of the monitors contains the point, this will just return the
  71. main monitor.
  72. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  73. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  74. */
  75. const Rectangle<int> getMonitorAreaContaining (const Point<int>& position, bool clippedToWorkArea = true) const;
  76. //==============================================================================
  77. /** Returns the mouse position.
  78. The co-ordinates are relative to the top-left of the main monitor.
  79. */
  80. static const Point<int> getMousePosition();
  81. /** Makes the mouse pointer jump to a given location.
  82. The co-ordinates are relative to the top-left of the main monitor.
  83. */
  84. static void setMousePosition (const Point<int>& newPosition);
  85. /** Returns the last position at which a mouse button was pressed.
  86. */
  87. static const Point<int> getLastMouseDownPosition() throw();
  88. /** Returns the number of times the mouse button has been clicked since the
  89. app started.
  90. Each mouse-down event increments this number by 1.
  91. */
  92. static int getMouseButtonClickCounter() throw();
  93. //==============================================================================
  94. /** This lets you prevent the screensaver from becoming active.
  95. Handy if you're running some sort of presentation app where having a screensaver
  96. appear would be annoying.
  97. Pass false to disable the screensaver, and true to re-enable it. (Note that this
  98. won't enable a screensaver unless the user has actually set one up).
  99. The disablement will only happen while the Juce application is the foreground
  100. process - if another task is running in front of it, then the screensaver will
  101. be unaffected.
  102. @see isScreenSaverEnabled
  103. */
  104. static void setScreenSaverEnabled (bool isEnabled) throw();
  105. /** Returns true if the screensaver has not been turned off.
  106. This will return the last value passed into setScreenSaverEnabled(). Note that
  107. it won't tell you whether the user is actually using a screen saver, just
  108. whether this app is deliberately preventing one from running.
  109. @see setScreenSaverEnabled
  110. */
  111. static bool isScreenSaverEnabled() throw();
  112. //==============================================================================
  113. /** Registers a MouseListener that will receive all mouse events that occur on
  114. any component.
  115. @see removeGlobalMouseListener
  116. */
  117. void addGlobalMouseListener (MouseListener* listener);
  118. /** Unregisters a MouseListener that was added with the addGlobalMouseListener()
  119. method.
  120. @see addGlobalMouseListener
  121. */
  122. void removeGlobalMouseListener (MouseListener* listener);
  123. //==============================================================================
  124. /** Registers a MouseListener that will receive a callback whenever the focused
  125. component changes.
  126. */
  127. void addFocusChangeListener (FocusChangeListener* listener);
  128. /** Unregisters a listener that was added with addFocusChangeListener(). */
  129. void removeFocusChangeListener (FocusChangeListener* listener);
  130. //==============================================================================
  131. /** Takes a component and makes it full-screen, removing the taskbar, dock, etc.
  132. The component must already be on the desktop for this method to work. It will
  133. be resized to completely fill the screen and any extraneous taskbars, menu bars,
  134. etc will be hidden.
  135. To exit kiosk mode, just call setKioskModeComponent (0). When this is called,
  136. the component that's currently being used will be resized back to the size
  137. and position it was in before being put into this mode.
  138. If allowMenusAndBars is true, things like the menu and dock (on mac) are still
  139. allowed to pop up when the mouse moves onto them. If this is false, it'll try
  140. to hide as much on-screen paraphenalia as possible.
  141. */
  142. void setKioskModeComponent (Component* componentToUse,
  143. bool allowMenusAndBars = true);
  144. /** Returns the component that is currently being used in kiosk-mode.
  145. This is the component that was last set by setKioskModeComponent(). If none
  146. has been set, this returns 0.
  147. */
  148. Component* getKioskModeComponent() const throw() { return kioskModeComponent; }
  149. //==============================================================================
  150. /** Returns the number of components that are currently active as top-level
  151. desktop windows.
  152. @see getComponent, Component::addToDesktop
  153. */
  154. int getNumComponents() const throw();
  155. /** Returns one of the top-level desktop window components.
  156. The index is from 0 to getNumComponents() - 1. This could return 0 if the
  157. index is out-of-range.
  158. @see getNumComponents, Component::addToDesktop
  159. */
  160. Component* getComponent (int index) const throw();
  161. /** Finds the component at a given screen location.
  162. This will drill down into top-level windows to find the child component at
  163. the given position.
  164. Returns 0 if the co-ordinates are inside a non-Juce window.
  165. */
  166. Component* findComponentAt (const Point<int>& screenPosition) const;
  167. //==============================================================================
  168. /** Returns the number of MouseInputSource objects the system has at its disposal.
  169. In a traditional single-mouse system, there might be only one object. On a multi-touch
  170. system, there could be one input source per potential finger.
  171. To find out how many mouse events are currently happening, use getNumDraggingMouseSources().
  172. @see getMouseSource
  173. */
  174. int getNumMouseSources() const throw() { return mouseSources.size(); }
  175. /** Returns one of the system's MouseInputSource objects.
  176. The index should be from 0 to getNumMouseSources() - 1. Out-of-range indexes will return
  177. a null pointer.
  178. In a traditional single-mouse system, there might be only one object. On a multi-touch
  179. system, there could be one input source per potential finger.
  180. */
  181. MouseInputSource* getMouseSource (int index) const throw() { return mouseSources [index]; }
  182. /** Returns the main mouse input device that the system is using.
  183. @see getNumMouseSources()
  184. */
  185. MouseInputSource& getMainMouseSource() const throw() { return *mouseSources.getUnchecked(0); }
  186. /** Returns the number of mouse-sources that are currently being dragged.
  187. In a traditional single-mouse system, this will be 0 or 1, depending on whether a
  188. juce component has the button down on it. In a multi-touch system, this could
  189. be any number from 0 to the number of simultaneous touches that can be detected.
  190. */
  191. int getNumDraggingMouseSources() const throw();
  192. /** Returns one of the mouse sources that's currently being dragged.
  193. The index should be between 0 and getNumDraggingMouseSources() - 1. If the index is
  194. out of range, or if no mice or fingers are down, this will return a null pointer.
  195. */
  196. MouseInputSource* getDraggingMouseSource (int index) const throw();
  197. //==============================================================================
  198. juce_UseDebuggingNewOperator
  199. /** Tells this object to refresh its idea of what the screen resolution is.
  200. (Called internally by the native code).
  201. */
  202. void refreshMonitorSizes();
  203. /** True if the OS supports semitransparent windows */
  204. static bool canUseSemiTransparentWindows() throw();
  205. private:
  206. //==============================================================================
  207. static Desktop* instance;
  208. friend class Component;
  209. friend class ComponentPeer;
  210. friend class MouseInputSource;
  211. friend class MouseInputSourceInternal;
  212. friend class DeletedAtShutdown;
  213. friend class TopLevelWindowManager;
  214. OwnedArray <MouseInputSource> mouseSources;
  215. void createMouseInputSources();
  216. ListenerList <MouseListener> mouseListeners;
  217. ListenerList <FocusChangeListener> focusListeners;
  218. Array <Component*> desktopComponents;
  219. Array <Rectangle<int> > monitorCoordsClipped, monitorCoordsUnclipped;
  220. Point<int> lastFakeMouseMove;
  221. void sendMouseMove();
  222. int mouseClickCounter;
  223. void incrementMouseClickCounter() throw();
  224. Component* kioskModeComponent;
  225. Rectangle<int> kioskComponentOriginalBounds;
  226. void timerCallback();
  227. void resetTimer();
  228. int getNumDisplayMonitors() const throw();
  229. const Rectangle<int> getDisplayMonitorCoordinates (int index, bool clippedToWorkArea) const throw();
  230. void addDesktopComponent (Component* c);
  231. void removeDesktopComponent (Component* c);
  232. void componentBroughtToFront (Component* c);
  233. void triggerFocusCallback();
  234. void handleAsyncUpdate();
  235. Desktop();
  236. ~Desktop();
  237. Desktop (const Desktop&);
  238. Desktop& operator= (const Desktop&);
  239. };
  240. #endif // __JUCE_DESKTOP_JUCEHEADER__