Audio plugin host https://kx.studio/carla
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.

331 lines
9.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. } // (juce namespace)
  18. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  19. {
  20. }
  21. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  22. - (void) applicationWillTerminate: (UIApplication*) application;
  23. - (void) applicationDidEnterBackground: (UIApplication*) application;
  24. - (void) applicationWillEnterForeground: (UIApplication*) application;
  25. @end
  26. @implementation JuceAppStartupDelegate
  27. - (void) applicationDidFinishLaunching: (UIApplication*) application
  28. {
  29. initialiseJuce_GUI();
  30. JUCEApplicationBase* app = JUCEApplicationBase::createInstance();
  31. if (! app->initialiseApp())
  32. exit (0);
  33. }
  34. - (void) applicationWillTerminate: (UIApplication*) application
  35. {
  36. JUCEApplicationBase::appWillTerminateByForce();
  37. }
  38. - (void) applicationDidEnterBackground: (UIApplication*) application
  39. {
  40. if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
  41. app->suspended();
  42. }
  43. - (void) applicationWillEnterForeground: (UIApplication*) application
  44. {
  45. if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
  46. app->resumed();
  47. }
  48. @end
  49. namespace juce
  50. {
  51. int juce_iOSMain (int argc, const char* argv[])
  52. {
  53. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  54. }
  55. //==============================================================================
  56. void LookAndFeel::playAlertSound()
  57. {
  58. //xxx
  59. //AudioServicesPlaySystemSound ();
  60. }
  61. //==============================================================================
  62. class iOSMessageBox;
  63. } // (juce namespace)
  64. @interface JuceAlertBoxDelegate : NSObject
  65. {
  66. @public
  67. iOSMessageBox* owner;
  68. }
  69. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  70. @end
  71. namespace juce
  72. {
  73. class iOSMessageBox
  74. {
  75. public:
  76. iOSMessageBox (const String& title, const String& message,
  77. NSString* button1, NSString* button2, NSString* button3,
  78. ModalComponentManager::Callback* cb, const bool async)
  79. : result (0), delegate (nil), alert (nil),
  80. callback (cb), isYesNo (button3 != nil), isAsync (async)
  81. {
  82. delegate = [[JuceAlertBoxDelegate alloc] init];
  83. delegate->owner = this;
  84. alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  85. message: juceStringToNS (message)
  86. delegate: delegate
  87. cancelButtonTitle: button1
  88. otherButtonTitles: button2, button3, nil];
  89. [alert retain];
  90. [alert show];
  91. }
  92. ~iOSMessageBox()
  93. {
  94. [alert release];
  95. [delegate release];
  96. }
  97. int getResult()
  98. {
  99. jassert (callback == nullptr);
  100. JUCE_AUTORELEASEPOOL
  101. {
  102. while (! alert.hidden && alert.superview != nil)
  103. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  104. }
  105. return result;
  106. }
  107. void buttonClicked (const int buttonIndex) noexcept
  108. {
  109. result = buttonIndex;
  110. if (callback != nullptr)
  111. callback->modalStateFinished (result);
  112. if (isAsync)
  113. delete this;
  114. }
  115. private:
  116. int result;
  117. JuceAlertBoxDelegate* delegate;
  118. UIAlertView* alert;
  119. ScopedPointer<ModalComponentManager::Callback> callback;
  120. const bool isYesNo, isAsync;
  121. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iOSMessageBox)
  122. };
  123. } // (juce namespace)
  124. @implementation JuceAlertBoxDelegate
  125. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  126. {
  127. owner->buttonClicked (buttonIndex);
  128. alertView.hidden = true;
  129. }
  130. @end
  131. namespace juce
  132. {
  133. //==============================================================================
  134. #if JUCE_MODAL_LOOPS_PERMITTED
  135. void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType iconType,
  136. const String& title, const String& message,
  137. Component* associatedComponent)
  138. {
  139. JUCE_AUTORELEASEPOOL
  140. {
  141. iOSMessageBox mb (title, message, @"OK", nil, nil, nullptr, false);
  142. (void) mb.getResult();
  143. }
  144. }
  145. #endif
  146. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
  147. const String& title, const String& message,
  148. Component* associatedComponent,
  149. ModalComponentManager::Callback* callback)
  150. {
  151. new iOSMessageBox (title, message, @"OK", nil, nil, callback, true);
  152. }
  153. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,
  154. const String& title, const String& message,
  155. Component* associatedComponent,
  156. ModalComponentManager::Callback* callback)
  157. {
  158. ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"OK",
  159. nil, callback, callback != nullptr));
  160. if (callback == nullptr)
  161. return mb->getResult() == 1;
  162. mb.release();
  163. return false;
  164. }
  165. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,
  166. const String& title, const String& message,
  167. Component* associatedComponent,
  168. ModalComponentManager::Callback* callback)
  169. {
  170. ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"Yes", @"No", callback, callback != nullptr));
  171. if (callback == nullptr)
  172. return mb->getResult();
  173. mb.release();
  174. return 0;
  175. }
  176. //==============================================================================
  177. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  178. {
  179. jassertfalse; // no such thing on iOS!
  180. return false;
  181. }
  182. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183. {
  184. jassertfalse; // no such thing on iOS!
  185. return false;
  186. }
  187. //==============================================================================
  188. void Desktop::setScreenSaverEnabled (const bool isEnabled)
  189. {
  190. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  191. }
  192. bool Desktop::isScreenSaverEnabled()
  193. {
  194. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  195. }
  196. //==============================================================================
  197. bool juce_areThereAnyAlwaysOnTopWindows()
  198. {
  199. return false;
  200. }
  201. //==============================================================================
  202. Image juce_createIconForFile (const File& file)
  203. {
  204. return Image::null;
  205. }
  206. //==============================================================================
  207. void SystemClipboard::copyTextToClipboard (const String& text)
  208. {
  209. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  210. forPasteboardType: @"public.text"];
  211. }
  212. String SystemClipboard::getTextFromClipboard()
  213. {
  214. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  215. return text == nil ? String::empty
  216. : nsStringToJuce (text);
  217. }
  218. //==============================================================================
  219. bool MouseInputSource::SourceList::addSource()
  220. {
  221. addSource (sources.size(), false);
  222. return true;
  223. }
  224. bool Desktop::canUseSemiTransparentWindows() noexcept
  225. {
  226. return true;
  227. }
  228. Point<int> MouseInputSource::getCurrentRawMousePosition()
  229. {
  230. return juce_lastMousePos;
  231. }
  232. void MouseInputSource::setRawMousePosition (Point<int>)
  233. {
  234. }
  235. double Desktop::getDefaultMasterScale()
  236. {
  237. return 1.0;
  238. }
  239. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
  240. {
  241. return Orientations::convertToJuce ([[UIApplication sharedApplication] statusBarOrientation]);
  242. }
  243. void Desktop::Displays::findDisplays (float masterScale)
  244. {
  245. JUCE_AUTORELEASEPOOL
  246. {
  247. UIScreen* s = [UIScreen mainScreen];
  248. Display d;
  249. d.userArea = UIViewComponentPeer::realScreenPosToRotated (convertToRectInt ([s applicationFrame])) / masterScale;
  250. d.totalArea = UIViewComponentPeer::realScreenPosToRotated (convertToRectInt ([s bounds])) / masterScale;
  251. d.isMain = true;
  252. d.scale = masterScale;
  253. if ([s respondsToSelector: @selector (scale)])
  254. d.scale *= s.scale;
  255. d.dpi = 160 * d.scale;
  256. displays.add (d);
  257. }
  258. }