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.

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