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.

227 lines
8.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #ifndef __JUCE_DESKTOP_JUCEHEADER__
  24. #define __JUCE_DESKTOP_JUCEHEADER__
  25. #include "juce_Component.h"
  26. #include "../../application/juce_DeletedAtShutdown.h"
  27. #include "../../events/juce_Timer.h"
  28. #include "../../events/juce_AsyncUpdater.h"
  29. #include "../../../juce_core/containers/juce_SortedSet.h"
  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() throw();
  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 (const 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 getMainMonitorArea (const 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 getMonitorAreaContaining (int x, int y, const bool clippedToWorkArea = true) const throw();
  76. //==============================================================================
  77. /** Returns the mouse position.
  78. The co-ordinates are relative to the top-left of the main monitor.
  79. */
  80. static void getMousePosition (int& x, int& y) throw();
  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 (int x, int y) throw();
  85. /** Returns the last position at which a mouse button was pressed.
  86. */
  87. static void getLastMouseDownPosition (int& x, int& y) 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. /** Registers a MouseListener that will receive all mouse events that occur on
  95. any component.
  96. @see removeGlobalMouseListener
  97. */
  98. void addGlobalMouseListener (MouseListener* const listener) throw();
  99. /** Unregisters a MouseListener that was added with the addGlobalMouseListener()
  100. method.
  101. @see addGlobalMouseListener
  102. */
  103. void removeGlobalMouseListener (MouseListener* const listener) throw();
  104. //==============================================================================
  105. /** Registers a MouseListener that will receive a callback whenever the focused
  106. component changes.
  107. */
  108. void addFocusChangeListener (FocusChangeListener* const listener) throw();
  109. /** Unregisters a listener that was added with addFocusChangeListener(). */
  110. void removeFocusChangeListener (FocusChangeListener* const listener) throw();
  111. //==============================================================================
  112. /** Returns the number of components that are currently active as top-level
  113. desktop windows.
  114. @see getComponent, Component::addToDesktop
  115. */
  116. int getNumComponents() const throw();
  117. /** Returns one of the top-level desktop window components.
  118. The index is from 0 to getNumComponents() - 1. This could return 0 if the
  119. index is out-of-range.
  120. @see getNumComponents, Component::addToDesktop
  121. */
  122. Component* getComponent (const int index) const throw();
  123. /** Finds the component at a given screen location.
  124. This will drill down into top-level windows to find the child component at
  125. the given position.
  126. Returns 0 if the co-ordinates are inside a non-Juce window.
  127. */
  128. Component* findComponentAt (const int screenX,
  129. const int screenY) const;
  130. //==============================================================================
  131. juce_UseDebuggingNewOperator
  132. /** Tells this object to refresh its idea of what the screen resolution is.
  133. (Called internally by the native code).
  134. */
  135. void refreshMonitorSizes() throw();
  136. /** True if the OS supports semitransparent windows */
  137. static bool canUseSemiTransparentWindows() throw();
  138. private:
  139. //==============================================================================
  140. friend class Component;
  141. friend class ComponentPeer;
  142. SortedSet <void*> mouseListeners, focusListeners;
  143. VoidArray desktopComponents;
  144. friend class DeletedAtShutdown;
  145. friend class TopLevelWindowManager;
  146. Desktop() throw();
  147. ~Desktop() throw();
  148. Array <Rectangle> monitorCoordsClipped, monitorCoordsUnclipped;
  149. int lastMouseX, lastMouseY;
  150. void timerCallback();
  151. void sendMouseMove();
  152. void resetTimer() throw();
  153. int getNumDisplayMonitors() const throw();
  154. const Rectangle getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw();
  155. void addDesktopComponent (Component* const c) throw();
  156. void removeDesktopComponent (Component* const c) throw();
  157. void componentBroughtToFront (Component* const c) throw();
  158. void triggerFocusCallback() throw();
  159. void handleAsyncUpdate();
  160. Desktop (const Desktop&);
  161. const Desktop& operator= (const Desktop&);
  162. };
  163. #endif // __JUCE_DESKTOP_JUCEHEADER__