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.

276 lines
11KB

  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 "../../utilities/juce_DeletedAtShutdown.h"
  22. #include "../../events/juce_Timer.h"
  23. #include "../../events/juce_AsyncUpdater.h"
  24. #include "../../containers/juce_SortedSet.h"
  25. //==============================================================================
  26. /**
  27. Classes can implement this interface and register themselves with the Desktop class
  28. to receive callbacks when the currently focused component changes.
  29. @see Desktop::addFocusChangeListener, Desktop::removeFocusChangeListener
  30. */
  31. class JUCE_API FocusChangeListener
  32. {
  33. public:
  34. /** Destructor. */
  35. virtual ~FocusChangeListener() {}
  36. /** Callback to indicate that the currently focused component has changed. */
  37. virtual void globalFocusChanged (Component* focusedComponent) = 0;
  38. };
  39. //==============================================================================
  40. /**
  41. Describes and controls aspects of the computer's desktop.
  42. */
  43. class JUCE_API Desktop : private DeletedAtShutdown,
  44. private Timer,
  45. private AsyncUpdater
  46. {
  47. public:
  48. //==============================================================================
  49. /** There's only one dektop object, and this method will return it.
  50. */
  51. static Desktop& JUCE_CALLTYPE getInstance() throw();
  52. //==============================================================================
  53. /** Returns a list of the positions of all the monitors available.
  54. The first rectangle in the list will be the main monitor area.
  55. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  56. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  57. */
  58. const RectangleList getAllMonitorDisplayAreas (const bool clippedToWorkArea = true) const throw();
  59. /** Returns the position and size of the main monitor.
  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 Rectangle getMainMonitorArea (const bool clippedToWorkArea = true) const throw();
  64. /** Returns the position and size of the monitor which contains this co-ordinate.
  65. If none of the monitors contains the point, this will just return the
  66. main monitor.
  67. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  68. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  69. */
  70. const Rectangle getMonitorAreaContaining (int x, int y, const bool clippedToWorkArea = true) const throw();
  71. //==============================================================================
  72. /** Returns the mouse position.
  73. The co-ordinates are relative to the top-left of the main monitor.
  74. */
  75. static void getMousePosition (int& x, int& y) throw();
  76. /** Makes the mouse pointer jump to a given location.
  77. The co-ordinates are relative to the top-left of the main monitor.
  78. */
  79. static void setMousePosition (int x, int y) throw();
  80. /** Returns the last position at which a mouse button was pressed.
  81. */
  82. static void getLastMouseDownPosition (int& x, int& y) throw();
  83. /** Returns the number of times the mouse button has been clicked since the
  84. app started.
  85. Each mouse-down event increments this number by 1.
  86. */
  87. static int getMouseButtonClickCounter() throw();
  88. //==============================================================================
  89. /** This lets you prevent the screensaver from becoming active.
  90. Handy if you're running some sort of presentation app where having a screensaver
  91. appear would be annoying.
  92. Pass false to disable the screensaver, and true to re-enable it. (Note that this
  93. won't enable a screensaver unless the user has actually set one up).
  94. The disablement will only happen while the Juce application is the foreground
  95. process - if another task is running in front of it, then the screensaver will
  96. be unaffected.
  97. @see isScreenSaverEnabled
  98. */
  99. static void setScreenSaverEnabled (const bool isEnabled) throw();
  100. /** Returns true if the screensaver has not been turned off.
  101. This will return the last value passed into setScreenSaverEnabled(). Note that
  102. it won't tell you whether the user is actually using a screen saver, just
  103. whether this app is deliberately preventing one from running.
  104. @see setScreenSaverEnabled
  105. */
  106. static bool isScreenSaverEnabled() throw();
  107. //==============================================================================
  108. /** Registers a MouseListener that will receive all mouse events that occur on
  109. any component.
  110. @see removeGlobalMouseListener
  111. */
  112. void addGlobalMouseListener (MouseListener* const listener) throw();
  113. /** Unregisters a MouseListener that was added with the addGlobalMouseListener()
  114. method.
  115. @see addGlobalMouseListener
  116. */
  117. void removeGlobalMouseListener (MouseListener* const listener) throw();
  118. //==============================================================================
  119. /** Registers a MouseListener that will receive a callback whenever the focused
  120. component changes.
  121. */
  122. void addFocusChangeListener (FocusChangeListener* const listener) throw();
  123. /** Unregisters a listener that was added with addFocusChangeListener(). */
  124. void removeFocusChangeListener (FocusChangeListener* const listener) throw();
  125. //==============================================================================
  126. /** Takes a component and makes it full-screen, removing the taskbar, dock, etc.
  127. The component must already be on the desktop for this method to work. It will
  128. be resized to completely fill the screen and any extraneous taskbars, menu bars,
  129. etc will be hidden.
  130. To exit kiosk mode, just call setKioskModeComponent (0). When this is called,
  131. the component that's currently being used will be resized back to the size
  132. and position it was in before being put into this mode.
  133. If allowMenusAndBars is true, things like the menu and dock (on mac) are still
  134. allowed to pop up when the mouse moves onto them. If this is false, it'll try
  135. to hide as much on-screen paraphenalia as possible.
  136. */
  137. void setKioskModeComponent (Component* componentToUse,
  138. const bool allowMenusAndBars = true);
  139. /** Returns the component that is currently being used in kiosk-mode.
  140. This is the component that was last set by setKioskModeComponent(). If none
  141. has been set, this returns 0.
  142. */
  143. Component* getKioskModeComponent() const { return kioskModeComponent; }
  144. //==============================================================================
  145. /** Returns the number of components that are currently active as top-level
  146. desktop windows.
  147. @see getComponent, Component::addToDesktop
  148. */
  149. int getNumComponents() const throw();
  150. /** Returns one of the top-level desktop window components.
  151. The index is from 0 to getNumComponents() - 1. This could return 0 if the
  152. index is out-of-range.
  153. @see getNumComponents, Component::addToDesktop
  154. */
  155. Component* getComponent (const int index) const throw();
  156. /** Finds the component at a given screen location.
  157. This will drill down into top-level windows to find the child component at
  158. the given position.
  159. Returns 0 if the co-ordinates are inside a non-Juce window.
  160. */
  161. Component* findComponentAt (const int screenX,
  162. const int screenY) const;
  163. //==============================================================================
  164. juce_UseDebuggingNewOperator
  165. /** Tells this object to refresh its idea of what the screen resolution is.
  166. (Called internally by the native code).
  167. */
  168. void refreshMonitorSizes() throw();
  169. /** True if the OS supports semitransparent windows */
  170. static bool canUseSemiTransparentWindows() throw();
  171. private:
  172. //==============================================================================
  173. friend class Component;
  174. friend class ComponentPeer;
  175. SortedSet <void*> mouseListeners, focusListeners;
  176. Array <Component*> desktopComponents;
  177. friend class DeletedAtShutdown;
  178. friend class TopLevelWindowManager;
  179. Desktop() throw();
  180. ~Desktop() throw();
  181. Array <Rectangle> monitorCoordsClipped, monitorCoordsUnclipped;
  182. int lastMouseX, lastMouseY;
  183. Component* kioskModeComponent;
  184. Rectangle kioskComponentOriginalBounds;
  185. void timerCallback();
  186. void sendMouseMove();
  187. void resetTimer() throw();
  188. int getNumDisplayMonitors() const throw();
  189. const Rectangle getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw();
  190. void addDesktopComponent (Component* const c) throw();
  191. void removeDesktopComponent (Component* const c) throw();
  192. void componentBroughtToFront (Component* const c) throw();
  193. void triggerFocusCallback() throw();
  194. void handleAsyncUpdate();
  195. Desktop (const Desktop&);
  196. const Desktop& operator= (const Desktop&);
  197. };
  198. #endif // __JUCE_DESKTOP_JUCEHEADER__