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.

681 lines
27KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. extern bool isIOSAppActive;
  21. struct AppInactivityCallback // NB: careful, this declaration is duplicated in other modules
  22. {
  23. virtual ~AppInactivityCallback() = default;
  24. virtual void appBecomingInactive() = 0;
  25. };
  26. // This is an internal list of callbacks (but currently used between modules)
  27. Array<AppInactivityCallback*> appBecomingInactiveCallbacks;
  28. }
  29. #if JUCE_PUSH_NOTIFICATIONS && defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  30. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate, UNUserNotificationCenterDelegate>
  31. #else
  32. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  33. #endif
  34. {
  35. UIBackgroundTaskIdentifier appSuspendTask;
  36. }
  37. @property (strong, nonatomic) UIWindow *window;
  38. - (id) init;
  39. - (void) dealloc;
  40. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  41. - (void) applicationWillTerminate: (UIApplication*) application;
  42. - (void) applicationDidEnterBackground: (UIApplication*) application;
  43. - (void) applicationWillEnterForeground: (UIApplication*) application;
  44. - (void) applicationDidBecomeActive: (UIApplication*) application;
  45. - (void) applicationWillResignActive: (UIApplication*) application;
  46. - (void) application: (UIApplication*) application handleEventsForBackgroundURLSession: (NSString*) identifier
  47. completionHandler: (void (^)(void)) completionHandler;
  48. - (void) applicationDidReceiveMemoryWarning: (UIApplication *) application;
  49. #if JUCE_PUSH_NOTIFICATIONS
  50. - (void) application: (UIApplication*) application didRegisterUserNotificationSettings: (UIUserNotificationSettings*) notificationSettings;
  51. - (void) application: (UIApplication*) application didRegisterForRemoteNotificationsWithDeviceToken: (NSData*) deviceToken;
  52. - (void) application: (UIApplication*) application didFailToRegisterForRemoteNotificationsWithError: (NSError*) error;
  53. - (void) application: (UIApplication*) application didReceiveRemoteNotification: (NSDictionary*) userInfo;
  54. - (void) application: (UIApplication*) application didReceiveRemoteNotification: (NSDictionary*) userInfo
  55. fetchCompletionHandler: (void (^)(UIBackgroundFetchResult result)) completionHandler;
  56. - (void) application: (UIApplication*) application handleActionWithIdentifier: (NSString*) identifier
  57. forRemoteNotification: (NSDictionary*) userInfo withResponseInfo: (NSDictionary*) responseInfo
  58. completionHandler: (void(^)()) completionHandler;
  59. - (void) application: (UIApplication*) application didReceiveLocalNotification: (UILocalNotification*) notification;
  60. - (void) application: (UIApplication*) application handleActionWithIdentifier: (NSString*) identifier
  61. forLocalNotification: (UILocalNotification*) notification completionHandler: (void(^)()) completionHandler;
  62. - (void) application: (UIApplication*) application handleActionWithIdentifier: (NSString*) identifier
  63. forLocalNotification: (UILocalNotification*) notification withResponseInfo: (NSDictionary*) responseInfo
  64. completionHandler: (void(^)()) completionHandler;
  65. #if defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  66. - (void) userNotificationCenter: (UNUserNotificationCenter*) center willPresentNotification: (UNNotification*) notification
  67. withCompletionHandler: (void (^)(UNNotificationPresentationOptions options)) completionHandler;
  68. - (void) userNotificationCenter: (UNUserNotificationCenter*) center didReceiveNotificationResponse: (UNNotificationResponse*) response
  69. withCompletionHandler: (void(^)())completionHandler;
  70. #endif
  71. #endif
  72. @end
  73. @implementation JuceAppStartupDelegate
  74. NSObject* _pushNotificationsDelegate;
  75. - (id) init
  76. {
  77. self = [super init];
  78. appSuspendTask = UIBackgroundTaskInvalid;
  79. #if JUCE_PUSH_NOTIFICATIONS && defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  80. [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  81. #endif
  82. return self;
  83. }
  84. - (void) dealloc
  85. {
  86. [super dealloc];
  87. }
  88. - (void) applicationDidFinishLaunching: (UIApplication*) application
  89. {
  90. ignoreUnused (application);
  91. initialiseJuce_GUI();
  92. if (auto* app = JUCEApplicationBase::createInstance())
  93. {
  94. if (! app->initialiseApp())
  95. exit (app->shutdownApp());
  96. }
  97. else
  98. {
  99. jassertfalse; // you must supply an application object for an iOS app!
  100. }
  101. }
  102. - (void) applicationWillTerminate: (UIApplication*) application
  103. {
  104. ignoreUnused (application);
  105. JUCEApplicationBase::appWillTerminateByForce();
  106. }
  107. - (void) applicationDidEnterBackground: (UIApplication*) application
  108. {
  109. if (auto* app = JUCEApplicationBase::getInstance())
  110. {
  111. #if JUCE_EXECUTE_APP_SUSPEND_ON_BACKGROUND_TASK
  112. appSuspendTask = [application beginBackgroundTaskWithName:@"JUCE Suspend Task" expirationHandler:^{
  113. if (appSuspendTask != UIBackgroundTaskInvalid)
  114. {
  115. [application endBackgroundTask:appSuspendTask];
  116. appSuspendTask = UIBackgroundTaskInvalid;
  117. }
  118. }];
  119. MessageManager::callAsync ([app] { app->suspended(); });
  120. #else
  121. ignoreUnused (application);
  122. app->suspended();
  123. #endif
  124. }
  125. }
  126. - (void) applicationWillEnterForeground: (UIApplication*) application
  127. {
  128. ignoreUnused (application);
  129. if (auto* app = JUCEApplicationBase::getInstance())
  130. app->resumed();
  131. }
  132. - (void) applicationDidBecomeActive: (UIApplication*) application
  133. {
  134. application.applicationIconBadgeNumber = 0;
  135. isIOSAppActive = true;
  136. }
  137. - (void) applicationWillResignActive: (UIApplication*) application
  138. {
  139. ignoreUnused (application);
  140. isIOSAppActive = false;
  141. for (int i = appBecomingInactiveCallbacks.size(); --i >= 0;)
  142. appBecomingInactiveCallbacks.getReference(i)->appBecomingInactive();
  143. }
  144. - (void) application: (UIApplication*) application handleEventsForBackgroundURLSession: (NSString*)identifier
  145. completionHandler: (void (^)(void))completionHandler
  146. {
  147. ignoreUnused (application);
  148. URL::DownloadTask::juce_iosURLSessionNotify (nsStringToJuce (identifier));
  149. completionHandler();
  150. }
  151. - (void) applicationDidReceiveMemoryWarning: (UIApplication*) application
  152. {
  153. ignoreUnused (application);
  154. if (auto* app = JUCEApplicationBase::getInstance())
  155. app->memoryWarningReceived();
  156. }
  157. - (void) setPushNotificationsDelegateToUse: (NSObject*) delegate
  158. {
  159. _pushNotificationsDelegate = delegate;
  160. }
  161. #if JUCE_PUSH_NOTIFICATIONS
  162. - (void) application: (UIApplication*) application didRegisterUserNotificationSettings: (UIUserNotificationSettings*) notificationSettings
  163. {
  164. ignoreUnused (application);
  165. SEL selector = NSSelectorFromString (@"application:didRegisterUserNotificationSettings:");
  166. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  167. {
  168. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  169. [invocation setSelector: selector];
  170. [invocation setTarget: _pushNotificationsDelegate];
  171. [invocation setArgument: &application atIndex:2];
  172. [invocation setArgument: &notificationSettings atIndex:3];
  173. [invocation invoke];
  174. }
  175. }
  176. - (void) application: (UIApplication*) application didRegisterForRemoteNotificationsWithDeviceToken: (NSData*) deviceToken
  177. {
  178. ignoreUnused (application);
  179. SEL selector = NSSelectorFromString (@"application:didRegisterForRemoteNotificationsWithDeviceToken:");
  180. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  181. {
  182. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  183. [invocation setSelector: selector];
  184. [invocation setTarget: _pushNotificationsDelegate];
  185. [invocation setArgument: &application atIndex:2];
  186. [invocation setArgument: &deviceToken atIndex:3];
  187. [invocation invoke];
  188. }
  189. }
  190. - (void) application: (UIApplication*) application didFailToRegisterForRemoteNotificationsWithError: (NSError*) error
  191. {
  192. ignoreUnused (application);
  193. SEL selector = NSSelectorFromString (@"application:didFailToRegisterForRemoteNotificationsWithError:");
  194. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  195. {
  196. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  197. [invocation setSelector: selector];
  198. [invocation setTarget: _pushNotificationsDelegate];
  199. [invocation setArgument: &application atIndex:2];
  200. [invocation setArgument: &error atIndex:3];
  201. [invocation invoke];
  202. }
  203. }
  204. - (void) application: (UIApplication*) application didReceiveRemoteNotification: (NSDictionary*) userInfo
  205. {
  206. ignoreUnused (application);
  207. SEL selector = NSSelectorFromString (@"application:didReceiveRemoteNotification:");
  208. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  209. {
  210. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  211. [invocation setSelector: selector];
  212. [invocation setTarget: _pushNotificationsDelegate];
  213. [invocation setArgument: &application atIndex:2];
  214. [invocation setArgument: &userInfo atIndex:3];
  215. [invocation invoke];
  216. }
  217. }
  218. - (void) application: (UIApplication*) application didReceiveRemoteNotification: (NSDictionary*) userInfo
  219. fetchCompletionHandler: (void (^)(UIBackgroundFetchResult result)) completionHandler
  220. {
  221. ignoreUnused (application);
  222. SEL selector = NSSelectorFromString (@"application:didReceiveRemoteNotification:fetchCompletionHandler:");
  223. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  224. {
  225. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  226. [invocation setSelector: selector];
  227. [invocation setTarget: _pushNotificationsDelegate];
  228. [invocation setArgument: &application atIndex:2];
  229. [invocation setArgument: &userInfo atIndex:3];
  230. [invocation setArgument: &completionHandler atIndex:4];
  231. [invocation invoke];
  232. }
  233. }
  234. - (void) application: (UIApplication*) application handleActionWithIdentifier: (NSString*) identifier
  235. forRemoteNotification: (NSDictionary*) userInfo withResponseInfo: (NSDictionary*) responseInfo
  236. completionHandler: (void(^)()) completionHandler
  237. {
  238. ignoreUnused (application);
  239. SEL selector = NSSelectorFromString (@"application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler:");
  240. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  241. {
  242. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  243. [invocation setSelector: selector];
  244. [invocation setTarget: _pushNotificationsDelegate];
  245. [invocation setArgument: &application atIndex:2];
  246. [invocation setArgument: &identifier atIndex:3];
  247. [invocation setArgument: &userInfo atIndex:4];
  248. [invocation setArgument: &responseInfo atIndex:5];
  249. [invocation setArgument: &completionHandler atIndex:6];
  250. [invocation invoke];
  251. }
  252. }
  253. - (void) application: (UIApplication*) application didReceiveLocalNotification: (UILocalNotification*) notification
  254. {
  255. ignoreUnused (application);
  256. SEL selector = NSSelectorFromString (@"application:didReceiveLocalNotification:");
  257. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  258. {
  259. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  260. [invocation setSelector: selector];
  261. [invocation setTarget: _pushNotificationsDelegate];
  262. [invocation setArgument: &application atIndex:2];
  263. [invocation setArgument: &notification atIndex:3];
  264. [invocation invoke];
  265. }
  266. }
  267. - (void) application: (UIApplication*) application handleActionWithIdentifier: (NSString*) identifier
  268. forLocalNotification: (UILocalNotification*) notification completionHandler: (void(^)()) completionHandler
  269. {
  270. ignoreUnused (application);
  271. SEL selector = NSSelectorFromString (@"application:handleActionWithIdentifier:forLocalNotification:completionHandler:");
  272. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  273. {
  274. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  275. [invocation setSelector: selector];
  276. [invocation setTarget: _pushNotificationsDelegate];
  277. [invocation setArgument: &application atIndex:2];
  278. [invocation setArgument: &identifier atIndex:3];
  279. [invocation setArgument: &notification atIndex:4];
  280. [invocation setArgument: &completionHandler atIndex:5];
  281. [invocation invoke];
  282. }
  283. }
  284. - (void) application: (UIApplication*) application handleActionWithIdentifier: (NSString*) identifier
  285. forLocalNotification: (UILocalNotification*) notification withResponseInfo: (NSDictionary*) responseInfo
  286. completionHandler: (void(^)()) completionHandler
  287. {
  288. ignoreUnused (application);
  289. SEL selector = NSSelectorFromString (@"application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:");
  290. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  291. {
  292. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  293. [invocation setSelector: selector];
  294. [invocation setTarget: _pushNotificationsDelegate];
  295. [invocation setArgument: &application atIndex:2];
  296. [invocation setArgument: &identifier atIndex:3];
  297. [invocation setArgument: &notification atIndex:4];
  298. [invocation setArgument: &responseInfo atIndex:5];
  299. [invocation setArgument: &completionHandler atIndex:6];
  300. [invocation invoke];
  301. }
  302. }
  303. #if defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  304. - (void) userNotificationCenter: (UNUserNotificationCenter*) center willPresentNotification: (UNNotification*) notification
  305. withCompletionHandler: (void (^)(UNNotificationPresentationOptions options)) completionHandler
  306. {
  307. ignoreUnused (center);
  308. SEL selector = NSSelectorFromString (@"userNotificationCenter:willPresentNotification:withCompletionHandler:");
  309. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  310. {
  311. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  312. [invocation setSelector: selector];
  313. [invocation setTarget: _pushNotificationsDelegate];
  314. [invocation setArgument: &center atIndex:2];
  315. [invocation setArgument: &notification atIndex:3];
  316. [invocation setArgument: &completionHandler atIndex:4];
  317. [invocation invoke];
  318. }
  319. }
  320. - (void) userNotificationCenter: (UNUserNotificationCenter*) center didReceiveNotificationResponse: (UNNotificationResponse*) response
  321. withCompletionHandler: (void(^)()) completionHandler
  322. {
  323. ignoreUnused (center);
  324. SEL selector = NSSelectorFromString (@"userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:");
  325. if (_pushNotificationsDelegate != nil && [_pushNotificationsDelegate respondsToSelector: selector])
  326. {
  327. NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: [_pushNotificationsDelegate methodSignatureForSelector: selector]];
  328. [invocation setSelector: selector];
  329. [invocation setTarget: _pushNotificationsDelegate];
  330. [invocation setArgument: &center atIndex:2];
  331. [invocation setArgument: &response atIndex:3];
  332. [invocation setArgument: &completionHandler atIndex:4];
  333. [invocation invoke];
  334. }
  335. }
  336. #endif
  337. #endif
  338. @end
  339. namespace juce
  340. {
  341. int juce_iOSMain (int argc, const char* argv[], void* customDelegatePtr);
  342. int juce_iOSMain (int argc, const char* argv[], void* customDelegatePtr)
  343. {
  344. Class delegateClass = (customDelegatePtr != nullptr ? reinterpret_cast<Class> (customDelegatePtr) : [JuceAppStartupDelegate class]);
  345. return UIApplicationMain (argc, const_cast<char**> (argv), nil, NSStringFromClass (delegateClass));
  346. }
  347. //==============================================================================
  348. void LookAndFeel::playAlertSound()
  349. {
  350. // TODO
  351. }
  352. //==============================================================================
  353. class iOSMessageBox
  354. {
  355. public:
  356. iOSMessageBox (const String& title, const String& message,
  357. NSString* button1, NSString* button2, NSString* button3,
  358. ModalComponentManager::Callback* cb, const bool async)
  359. : result (0), resultReceived (false), callback (cb), isAsync (async)
  360. {
  361. if (currentlyFocusedPeer != nullptr)
  362. {
  363. UIAlertController* alert = [UIAlertController alertControllerWithTitle: juceStringToNS (title)
  364. message: juceStringToNS (message)
  365. preferredStyle: UIAlertControllerStyleAlert];
  366. addButton (alert, button1, 0);
  367. addButton (alert, button2, 1);
  368. addButton (alert, button3, 2);
  369. [currentlyFocusedPeer->controller presentViewController: alert
  370. animated: YES
  371. completion: nil];
  372. }
  373. else
  374. {
  375. // Since iOS8, alert windows need to be associated with a window, so you need to
  376. // have at least one window on screen when you use this
  377. jassertfalse;
  378. }
  379. }
  380. int getResult()
  381. {
  382. jassert (callback == nullptr);
  383. JUCE_AUTORELEASEPOOL
  384. {
  385. while (! resultReceived)
  386. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  387. }
  388. return result;
  389. }
  390. void buttonClicked (const int buttonIndex) noexcept
  391. {
  392. result = buttonIndex;
  393. resultReceived = true;
  394. if (callback != nullptr)
  395. callback->modalStateFinished (result);
  396. if (isAsync)
  397. delete this;
  398. }
  399. private:
  400. int result;
  401. bool resultReceived;
  402. std::unique_ptr<ModalComponentManager::Callback> callback;
  403. const bool isAsync;
  404. void addButton (UIAlertController* alert, NSString* text, int index)
  405. {
  406. if (text != nil)
  407. [alert addAction: [UIAlertAction actionWithTitle: text
  408. style: UIAlertActionStyleDefault
  409. handler: ^(UIAlertAction*) { this->buttonClicked (index); }]];
  410. }
  411. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iOSMessageBox)
  412. };
  413. //==============================================================================
  414. #if JUCE_MODAL_LOOPS_PERMITTED
  415. void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType /*iconType*/,
  416. const String& title, const String& message,
  417. Component* /*associatedComponent*/)
  418. {
  419. JUCE_AUTORELEASEPOOL
  420. {
  421. iOSMessageBox mb (title, message, @"OK", nil, nil, nullptr, false);
  422. ignoreUnused (mb.getResult());
  423. }
  424. }
  425. #endif
  426. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType /*iconType*/,
  427. const String& title, const String& message,
  428. Component* /*associatedComponent*/,
  429. ModalComponentManager::Callback* callback)
  430. {
  431. new iOSMessageBox (title, message, @"OK", nil, nil, callback, true);
  432. }
  433. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType /*iconType*/,
  434. const String& title, const String& message,
  435. Component* /*associatedComponent*/,
  436. ModalComponentManager::Callback* callback)
  437. {
  438. std::unique_ptr<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"OK",
  439. nil, callback, callback != nullptr));
  440. if (callback == nullptr)
  441. return mb->getResult() == 1;
  442. mb.release();
  443. return false;
  444. }
  445. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType /*iconType*/,
  446. const String& title, const String& message,
  447. Component* /*associatedComponent*/,
  448. ModalComponentManager::Callback* callback)
  449. {
  450. std::unique_ptr<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"Yes", @"No", callback, callback != nullptr));
  451. if (callback == nullptr)
  452. return mb->getResult();
  453. mb.release();
  454. return 0;
  455. }
  456. int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (AlertWindow::AlertIconType /*iconType*/,
  457. const String& title, const String& message,
  458. Component* /*associatedComponent*/,
  459. ModalComponentManager::Callback* callback)
  460. {
  461. std::unique_ptr<iOSMessageBox> mb (new iOSMessageBox (title, message, @"No", @"Yes", nil, callback, callback != nullptr));
  462. if (callback == nullptr)
  463. return mb->getResult();
  464. mb.release();
  465. return 0;
  466. }
  467. //==============================================================================
  468. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray&, bool, Component*, std::function<void()>)
  469. {
  470. jassertfalse; // no such thing on iOS!
  471. return false;
  472. }
  473. bool DragAndDropContainer::performExternalDragDropOfText (const String&, Component*, std::function<void()>)
  474. {
  475. jassertfalse; // no such thing on iOS!
  476. return false;
  477. }
  478. //==============================================================================
  479. void Desktop::setScreenSaverEnabled (const bool isEnabled)
  480. {
  481. if (! SystemStats::isRunningInAppExtensionSandbox())
  482. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  483. }
  484. bool Desktop::isScreenSaverEnabled()
  485. {
  486. if (SystemStats::isRunningInAppExtensionSandbox())
  487. return true;
  488. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  489. }
  490. //==============================================================================
  491. bool juce_areThereAnyAlwaysOnTopWindows()
  492. {
  493. return false;
  494. }
  495. //==============================================================================
  496. Image juce_createIconForFile (const File&)
  497. {
  498. return Image();
  499. }
  500. //==============================================================================
  501. void SystemClipboard::copyTextToClipboard (const String& text)
  502. {
  503. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  504. forPasteboardType: @"public.text"];
  505. }
  506. String SystemClipboard::getTextFromClipboard()
  507. {
  508. return nsStringToJuce ([[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"]);
  509. }
  510. //==============================================================================
  511. bool MouseInputSource::SourceList::addSource()
  512. {
  513. addSource (sources.size(), MouseInputSource::InputSourceType::touch);
  514. return true;
  515. }
  516. bool MouseInputSource::SourceList::canUseTouch()
  517. {
  518. return true;
  519. }
  520. bool Desktop::canUseSemiTransparentWindows() noexcept
  521. {
  522. return true;
  523. }
  524. Point<float> MouseInputSource::getCurrentRawMousePosition()
  525. {
  526. return juce_lastMousePos;
  527. }
  528. void MouseInputSource::setRawMousePosition (Point<float>)
  529. {
  530. }
  531. double Desktop::getDefaultMasterScale()
  532. {
  533. return 1.0;
  534. }
  535. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
  536. {
  537. UIInterfaceOrientation orientation = SystemStats::isRunningInAppExtensionSandbox() ? UIInterfaceOrientationPortrait
  538. : getWindowOrientation();
  539. return Orientations::convertToJuce (orientation);
  540. }
  541. void Displays::findDisplays (float masterScale)
  542. {
  543. JUCE_AUTORELEASEPOOL
  544. {
  545. UIScreen* s = [UIScreen mainScreen];
  546. Display d;
  547. d.userArea = d.totalArea = convertToRectInt ([s bounds]) / masterScale;
  548. d.isMain = true;
  549. d.scale = masterScale * s.scale;
  550. d.dpi = 160 * d.scale;
  551. displays.add (d);
  552. }
  553. }
  554. } // namespace juce