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.

297 lines
9.1KB

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