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.

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