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.

325 lines
10.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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. } // (juce namespace)
  19. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  20. {
  21. }
  22. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  23. - (void) applicationWillTerminate: (UIApplication*) application;
  24. - (void) applicationDidEnterBackground: (UIApplication*) application;
  25. - (void) applicationWillEnterForeground: (UIApplication*) application;
  26. @end
  27. @implementation JuceAppStartupDelegate
  28. - (void) applicationDidFinishLaunching: (UIApplication*) application
  29. {
  30. initialiseJuce_GUI();
  31. JUCEApplication* app = dynamic_cast <JUCEApplication*> (JUCEApplicationBase::createInstance());
  32. if (! app->initialiseApp())
  33. exit (0);
  34. }
  35. - (void) applicationWillTerminate: (UIApplication*) application
  36. {
  37. JUCEApplicationBase::appWillTerminateByForce();
  38. }
  39. - (void) applicationDidEnterBackground: (UIApplication*) application
  40. {
  41. JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
  42. if (app != nullptr)
  43. app->suspended();
  44. }
  45. - (void) applicationWillEnterForeground: (UIApplication*) application
  46. {
  47. JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
  48. if (app != nullptr)
  49. app->resumed();
  50. }
  51. @end
  52. namespace juce
  53. {
  54. int juce_iOSMain (int argc, const char* argv[])
  55. {
  56. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  57. }
  58. //==============================================================================
  59. void LookAndFeel::playAlertSound()
  60. {
  61. //xxx
  62. //AudioServicesPlaySystemSound ();
  63. }
  64. //==============================================================================
  65. class iOSMessageBox;
  66. } // (juce namespace)
  67. @interface JuceAlertBoxDelegate : NSObject
  68. {
  69. @public
  70. iOSMessageBox* owner;
  71. }
  72. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  73. @end
  74. namespace juce
  75. {
  76. class iOSMessageBox
  77. {
  78. public:
  79. iOSMessageBox (const String& title, const String& message,
  80. NSString* button1, NSString* button2, NSString* button3,
  81. ModalComponentManager::Callback* cb, const bool async)
  82. : result (0), delegate (nil), alert (nil),
  83. callback (cb), isYesNo (button3 != nil), isAsync (async)
  84. {
  85. delegate = [[JuceAlertBoxDelegate alloc] init];
  86. delegate->owner = this;
  87. alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  88. message: juceStringToNS (message)
  89. delegate: delegate
  90. cancelButtonTitle: button1
  91. otherButtonTitles: button2, button3, nil];
  92. [alert retain];
  93. [alert show];
  94. }
  95. ~iOSMessageBox()
  96. {
  97. [alert release];
  98. [delegate release];
  99. }
  100. int getResult()
  101. {
  102. jassert (callback == nullptr);
  103. JUCE_AUTORELEASEPOOL
  104. {
  105. while (! alert.hidden && alert.superview != nil)
  106. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  107. }
  108. return result;
  109. }
  110. void buttonClicked (const int buttonIndex) noexcept
  111. {
  112. result = buttonIndex;
  113. if (callback != nullptr)
  114. callback->modalStateFinished (result);
  115. if (isAsync)
  116. delete this;
  117. }
  118. private:
  119. int result;
  120. JuceAlertBoxDelegate* delegate;
  121. UIAlertView* alert;
  122. ModalComponentManager::Callback* callback;
  123. const bool isYesNo, isAsync;
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iOSMessageBox)
  125. };
  126. } // (juce namespace)
  127. @implementation JuceAlertBoxDelegate
  128. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  129. {
  130. owner->buttonClicked (buttonIndex);
  131. alertView.hidden = true;
  132. }
  133. @end
  134. namespace juce
  135. {
  136. //==============================================================================
  137. void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType iconType,
  138. const String& title, const String& message,
  139. Component* associatedComponent)
  140. {
  141. JUCE_AUTORELEASEPOOL
  142. {
  143. iOSMessageBox mb (title, message, @"OK", nil, nil, nullptr, false);
  144. (void) mb.getResult();
  145. }
  146. }
  147. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
  148. const String& title, const String& message,
  149. Component* associatedComponent,
  150. ModalComponentManager::Callback* callback)
  151. {
  152. new iOSMessageBox (title, message, @"OK", nil, nil, callback, true);
  153. }
  154. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,
  155. const String& title, const String& message,
  156. Component* associatedComponent,
  157. ModalComponentManager::Callback* callback)
  158. {
  159. ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"OK",
  160. nil, callback, callback != nullptr));
  161. if (callback == nullptr)
  162. return mb->getResult() == 1;
  163. mb.release();
  164. return false;
  165. }
  166. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,
  167. const String& title, const String& message,
  168. Component* associatedComponent,
  169. ModalComponentManager::Callback* callback)
  170. {
  171. ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"Yes", @"No", callback, callback != nullptr));
  172. if (callback == nullptr)
  173. return mb->getResult();
  174. mb.release();
  175. return 0;
  176. }
  177. //==============================================================================
  178. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  179. {
  180. jassertfalse; // no such thing on iOS!
  181. return false;
  182. }
  183. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184. {
  185. jassertfalse; // no such thing on iOS!
  186. return false;
  187. }
  188. //==============================================================================
  189. void Desktop::setScreenSaverEnabled (const bool isEnabled)
  190. {
  191. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  192. }
  193. bool Desktop::isScreenSaverEnabled()
  194. {
  195. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  196. }
  197. //==============================================================================
  198. bool juce_areThereAnyAlwaysOnTopWindows()
  199. {
  200. return false;
  201. }
  202. //==============================================================================
  203. Image juce_createIconForFile (const File& file)
  204. {
  205. return Image::null;
  206. }
  207. //==============================================================================
  208. void SystemClipboard::copyTextToClipboard (const String& text)
  209. {
  210. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  211. forPasteboardType: @"public.text"];
  212. }
  213. String SystemClipboard::getTextFromClipboard()
  214. {
  215. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  216. return text == nil ? String::empty
  217. : nsStringToJuce (text);
  218. }
  219. //==============================================================================
  220. bool Desktop::addMouseInputSource()
  221. {
  222. mouseSources.add (new MouseInputSource (mouseSources.size(), false));
  223. return true;
  224. }
  225. bool Desktop::canUseSemiTransparentWindows() noexcept
  226. {
  227. return true;
  228. }
  229. Point<int> MouseInputSource::getCurrentMousePosition()
  230. {
  231. return juce_lastMousePos;
  232. }
  233. void Desktop::setMousePosition (Point<int>)
  234. {
  235. }
  236. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
  237. {
  238. return Orientations::convertToJuce ([[UIApplication sharedApplication] statusBarOrientation]);
  239. }
  240. void Desktop::Displays::findDisplays()
  241. {
  242. JUCE_AUTORELEASEPOOL
  243. {
  244. UIScreen* s = [UIScreen mainScreen];
  245. Display d;
  246. d.userArea = UIViewComponentPeer::realScreenPosToRotated (convertToRectInt ([s applicationFrame]));
  247. d.totalArea = UIViewComponentPeer::realScreenPosToRotated (convertToRectInt ([s bounds]));
  248. d.isMain = true;
  249. if ([s respondsToSelector: @selector (scale)])
  250. d.scale = s.scale;
  251. else
  252. d.scale = 1.0;
  253. displays.add (d);
  254. }
  255. }