123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- /*
- ==============================================================================
- This file is part of the JUCE library.
- Copyright (c) 2013 - Raw Material Software Ltd.
- Permission is granted to use this software under the terms of either:
- a) the GPL v2 (or any later version)
- b) the Affero GPL v3
- Details of these licenses can be found at: www.gnu.org/licenses
- JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- ------------------------------------------------------------------------------
- To release a closed-source product which uses JUCE, commercial licenses are
- available: visit www.juce.com for more information.
- ==============================================================================
- */
- extern bool isIOSAppActive;
- } // (juce namespace)
- @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
- {
- }
- - (void) applicationDidFinishLaunching: (UIApplication*) application;
- - (void) applicationWillTerminate: (UIApplication*) application;
- - (void) applicationDidEnterBackground: (UIApplication*) application;
- - (void) applicationWillEnterForeground: (UIApplication*) application;
- - (void) applicationDidBecomeActive: (UIApplication*) application;
- - (void) applicationWillResignActive: (UIApplication*) application;
- @end
- @implementation JuceAppStartupDelegate
- - (void) applicationDidFinishLaunching: (UIApplication*) application
- {
- (void) application;
- initialiseJuce_GUI();
- JUCEApplicationBase* app = JUCEApplicationBase::createInstance();
- if (! app->initialiseApp())
- exit (0);
- }
- - (void) applicationWillTerminate: (UIApplication*) application
- {
- (void) application;
- JUCEApplicationBase::appWillTerminateByForce();
- }
- - (void) applicationDidEnterBackground: (UIApplication*) application
- {
- (void) application;
- if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
- app->suspended();
- }
- - (void) applicationWillEnterForeground: (UIApplication*) application
- {
- (void) application;
- if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
- app->resumed();
- }
- - (void) applicationDidBecomeActive: (UIApplication*) application
- {
- (void) application;
- isIOSAppActive = true;
- }
- - (void) applicationWillResignActive: (UIApplication*) application
- {
- (void) application;
- isIOSAppActive = false;
- }
- @end
- namespace juce
- {
- int juce_iOSMain (int argc, const char* argv[]);
- int juce_iOSMain (int argc, const char* argv[])
- {
- return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
- }
- //==============================================================================
- void LookAndFeel::playAlertSound()
- {
- //xxx
- //AudioServicesPlaySystemSound ();
- }
- //==============================================================================
- class iOSMessageBox;
- } // (juce namespace)
- @interface JuceAlertBoxDelegate : NSObject <UIAlertViewDelegate>
- {
- @public
- iOSMessageBox* owner;
- }
- - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
- @end
- namespace juce
- {
- class iOSMessageBox
- {
- public:
- iOSMessageBox (const String& title, const String& message,
- NSString* button1, NSString* button2, NSString* button3,
- ModalComponentManager::Callback* cb, const bool async)
- : result (0), resultReceived (false), delegate (nil), alert (nil),
- callback (cb), isYesNo (button3 != nil), isAsync (async)
- {
- delegate = [[JuceAlertBoxDelegate alloc] init];
- delegate->owner = this;
- alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
- message: juceStringToNS (message)
- delegate: delegate
- cancelButtonTitle: button1
- otherButtonTitles: button2, button3, nil];
- [alert retain];
- [alert show];
- }
- ~iOSMessageBox()
- {
- [alert release];
- [delegate release];
- }
- int getResult()
- {
- jassert (callback == nullptr);
- JUCE_AUTORELEASEPOOL
- {
- while (! (alert.hidden || resultReceived))
- [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
- }
- return result;
- }
- void buttonClicked (const int buttonIndex) noexcept
- {
- result = buttonIndex;
- resultReceived = true;
- if (callback != nullptr)
- callback->modalStateFinished (result);
- if (isAsync)
- delete this;
- }
- private:
- int result;
- bool resultReceived;
- JuceAlertBoxDelegate* delegate;
- UIAlertView* alert;
- ScopedPointer<ModalComponentManager::Callback> callback;
- const bool isYesNo, isAsync;
- JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iOSMessageBox)
- };
- } // (juce namespace)
- @implementation JuceAlertBoxDelegate
- - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
- {
- owner->buttonClicked ((int) buttonIndex);
- alertView.hidden = true;
- }
- @end
- namespace juce
- {
- //==============================================================================
- #if JUCE_MODAL_LOOPS_PERMITTED
- void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType /*iconType*/,
- const String& title, const String& message,
- Component* /*associatedComponent*/)
- {
- JUCE_AUTORELEASEPOOL
- {
- iOSMessageBox mb (title, message, @"OK", nil, nil, nullptr, false);
- (void) mb.getResult();
- }
- }
- #endif
- void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType /*iconType*/,
- const String& title, const String& message,
- Component* /*associatedComponent*/,
- ModalComponentManager::Callback* callback)
- {
- new iOSMessageBox (title, message, @"OK", nil, nil, callback, true);
- }
- bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType /*iconType*/,
- const String& title, const String& message,
- Component* /*associatedComponent*/,
- ModalComponentManager::Callback* callback)
- {
- ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"OK",
- nil, callback, callback != nullptr));
- if (callback == nullptr)
- return mb->getResult() == 1;
- mb.release();
- return false;
- }
- int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType /*iconType*/,
- const String& title, const String& message,
- Component* /*associatedComponent*/,
- ModalComponentManager::Callback* callback)
- {
- ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"Yes", @"No", callback, callback != nullptr));
- if (callback == nullptr)
- return mb->getResult();
- mb.release();
- return 0;
- }
- //==============================================================================
- bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray&, bool)
- {
- jassertfalse; // no such thing on iOS!
- return false;
- }
- bool DragAndDropContainer::performExternalDragDropOfText (const String&)
- {
- jassertfalse; // no such thing on iOS!
- return false;
- }
- //==============================================================================
- void Desktop::setScreenSaverEnabled (const bool isEnabled)
- {
- [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
- }
- bool Desktop::isScreenSaverEnabled()
- {
- return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
- }
- //==============================================================================
- bool juce_areThereAnyAlwaysOnTopWindows()
- {
- return false;
- }
- //==============================================================================
- Image juce_createIconForFile (const File&)
- {
- return Image::null;
- }
- //==============================================================================
- void SystemClipboard::copyTextToClipboard (const String& text)
- {
- [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
- forPasteboardType: @"public.text"];
- }
- String SystemClipboard::getTextFromClipboard()
- {
- NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
- return text == nil ? String::empty
- : nsStringToJuce (text);
- }
- //==============================================================================
- bool MouseInputSource::SourceList::addSource()
- {
- addSource (sources.size(), false);
- return true;
- }
- bool Desktop::canUseSemiTransparentWindows() noexcept
- {
- return true;
- }
- Point<float> MouseInputSource::getCurrentRawMousePosition()
- {
- return juce_lastMousePos;
- }
- void MouseInputSource::setRawMousePosition (Point<float>)
- {
- }
- double Desktop::getDefaultMasterScale()
- {
- return 1.0;
- }
- Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
- {
- return Orientations::convertToJuce ([[UIApplication sharedApplication] statusBarOrientation]);
- }
- void Desktop::Displays::findDisplays (float masterScale)
- {
- JUCE_AUTORELEASEPOOL
- {
- UIScreen* s = [UIScreen mainScreen];
- Display d;
- d.userArea = UIViewComponentPeer::realScreenPosToRotated (convertToRectInt ([s applicationFrame])) / masterScale;
- d.totalArea = UIViewComponentPeer::realScreenPosToRotated (convertToRectInt ([s bounds])) / masterScale;
- d.isMain = true;
- d.scale = masterScale;
- if ([s respondsToSelector: @selector (scale)])
- d.scale *= s.scale;
- d.dpi = 160 * d.scale;
- displays.add (d);
- }
- }
|