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.

249 lines
7.6KB

  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. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  24. // compiled on its own).
  25. #ifdef JUCE_INCLUDED_FILE
  26. //==============================================================================
  27. ScopedAutoReleasePool::ScopedAutoReleasePool()
  28. {
  29. pool = [[NSAutoreleasePool alloc] init];
  30. }
  31. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  32. {
  33. [((NSAutoreleasePool*) pool) release];
  34. }
  35. //==============================================================================
  36. void PlatformUtilities::beep()
  37. {
  38. NSBeep();
  39. }
  40. //==============================================================================
  41. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  42. bool AlertWindow::showNativeDialogBox (const String& title,
  43. const String& bodyText,
  44. bool isOkCancel)
  45. {
  46. const ScopedAutoReleasePool pool;
  47. return NSRunAlertPanel (juceStringToNS (title),
  48. juceStringToNS (bodyText),
  49. @"Ok",
  50. isOkCancel ? @"Cancel" : nil,
  51. nil) == 0;
  52. }
  53. //==============================================================================
  54. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  55. {
  56. if (files.size() == 0)
  57. return false;
  58. Component* sourceComp = Component::getComponentUnderMouse();
  59. if (sourceComp == 0)
  60. {
  61. jassertfalse // this method must be called in response to a
  62. // component's mouseDrag event!
  63. return false;
  64. }
  65. const ScopedAutoReleasePool pool;
  66. NSView* view = (NSView*) sourceComp->getWindowHandle();
  67. if (view == 0)
  68. return false;
  69. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  70. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  71. owner: nil];
  72. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  73. for (int i = 0; i < files.size(); ++i)
  74. [filesArray addObject: juceStringToNS (files[i])];
  75. [pboard setPropertyList: filesArray
  76. forType: NSFilenamesPboardType];
  77. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  78. fromView: nil];
  79. dragPosition.x -= 16;
  80. dragPosition.y -= 16;
  81. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  82. at: dragPosition
  83. offset: NSMakeSize (0, 0)
  84. event: [[view window] currentEvent]
  85. pasteboard: pboard
  86. source: view
  87. slideBack: YES];
  88. return true;
  89. }
  90. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  91. {
  92. jassertfalse // not implemented!
  93. return false;
  94. }
  95. //==============================================================================
  96. bool Desktop::canUseSemiTransparentWindows() throw()
  97. {
  98. return true;
  99. }
  100. void Desktop::getMousePosition (int& x, int& y) throw()
  101. {
  102. const ScopedAutoReleasePool pool;
  103. const NSPoint p ([NSEvent mouseLocation]);
  104. x = roundFloatToInt (p.x);
  105. y = roundFloatToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  106. }
  107. void Desktop::setMousePosition (int x, int y) throw()
  108. {
  109. // this rubbish needs to be done around the warp call, to avoid causing a
  110. // bizarre glitch..
  111. CGAssociateMouseAndMouseCursorPosition (false);
  112. CGSetLocalEventsSuppressionInterval (0);
  113. CGPoint pos = { x, y };
  114. CGWarpMouseCursorPosition (pos);
  115. CGAssociateMouseAndMouseCursorPosition (true);
  116. }
  117. //==============================================================================
  118. #if MACOS_10_4_OR_EARLIER
  119. class ScreenSaverDefeater : public Timer,
  120. public DeletedAtShutdown
  121. {
  122. public:
  123. ScreenSaverDefeater() throw()
  124. {
  125. startTimer (10000);
  126. timerCallback();
  127. }
  128. ~ScreenSaverDefeater() {}
  129. void timerCallback()
  130. {
  131. if (Process::isForegroundProcess())
  132. UpdateSystemActivity (UsrActivity);
  133. }
  134. };
  135. static ScreenSaverDefeater* screenSaverDefeater = 0;
  136. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  137. {
  138. if (isEnabled)
  139. {
  140. deleteAndZero (screenSaverDefeater);
  141. }
  142. else if (screenSaverDefeater == 0)
  143. {
  144. screenSaverDefeater = new ScreenSaverDefeater();
  145. }
  146. }
  147. bool Desktop::isScreenSaverEnabled() throw()
  148. {
  149. return screenSaverDefeater == 0;
  150. }
  151. #else
  152. //==============================================================================
  153. static IOPMAssertionID screenSaverDisablerID = 0;
  154. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  155. {
  156. if (isEnabled)
  157. {
  158. if (screenSaverDisablerID != 0)
  159. {
  160. IOPMAssertionRelease (screenSaverDisablerID);
  161. screenSaverDisablerID = 0;
  162. }
  163. }
  164. else
  165. {
  166. if (screenSaverDisablerID == 0)
  167. {
  168. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep,
  169. kIOPMAssertionLevelOn, &screenSaverDisablerID);
  170. }
  171. }
  172. }
  173. bool Desktop::isScreenSaverEnabled() throw()
  174. {
  175. return screenSaverDisablerID == 0;
  176. }
  177. #endif
  178. //==============================================================================
  179. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea) throw()
  180. {
  181. const ScopedAutoReleasePool pool;
  182. monitorCoords.clear();
  183. NSArray* screens = [NSScreen screens];
  184. const float mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  185. for (unsigned int i = 0; i < [screens count]; ++i)
  186. {
  187. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  188. NSRect r = clipToWorkArea ? [s visibleFrame]
  189. : [s frame];
  190. monitorCoords.add (Rectangle ((int) r.origin.x,
  191. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  192. (int) r.size.width,
  193. (int) r.size.height));
  194. }
  195. jassert (monitorCoords.size() > 0);
  196. }
  197. #endif
  198. #endif