mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Minor refactoring of obj-C internals.
This commit is contained in:
parent
e40903a9b6
commit
dab9295611
7 changed files with 138 additions and 165 deletions
|
|
@ -992,6 +992,7 @@ public:
|
|||
addMethod (@selector (applicationWillTerminate:), applicationWillTerminate, "v@:@");
|
||||
addMethod (@selector (viewDidMoveToWindow), viewDidMoveToWindow, "v@:");
|
||||
addMethod (@selector (mouseDownCanMoveWindow), mouseDownCanMoveWindow, "c@:");
|
||||
|
||||
registerClass();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,8 +116,6 @@ struct ObjCClass
|
|||
jassert (b); (void) b;
|
||||
}
|
||||
|
||||
Class cls;
|
||||
|
||||
static id sendSuperclassMessage (id self, SEL selector)
|
||||
{
|
||||
objc_super s = { self, [SuperclassType class] };
|
||||
|
|
@ -132,6 +130,8 @@ struct ObjCClass
|
|||
return v;
|
||||
}
|
||||
|
||||
Class cls;
|
||||
|
||||
private:
|
||||
static String getRandomisedName (const char* root)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,13 +30,72 @@ typedef bool (*CheckEventBlockedByModalComps) (NSEvent*);
|
|||
CheckEventBlockedByModalComps isEventBlockedByModalComps = nullptr;
|
||||
|
||||
//==============================================================================
|
||||
struct AppDelegateClass : public ObjCClass <NSObject>
|
||||
struct AppDelegate
|
||||
{
|
||||
public:
|
||||
AppDelegate()
|
||||
{
|
||||
static AppDelegateClass cls;
|
||||
delegate = [cls.createInstance() init];
|
||||
|
||||
if (JUCEApplicationBase::isStandaloneApp())
|
||||
{
|
||||
[NSApp setDelegate: delegate];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter] addObserver: delegate
|
||||
selector: @selector (broadcastMessageCallback:)
|
||||
name: getBroacastEventName()
|
||||
object: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center addObserver: delegate selector: @selector (applicationDidResignActive:)
|
||||
name: NSApplicationDidResignActiveNotification object: NSApp];
|
||||
|
||||
[center addObserver: delegate selector: @selector (applicationDidBecomeActive:)
|
||||
name: NSApplicationDidBecomeActiveNotification object: NSApp];
|
||||
|
||||
[center addObserver: delegate selector: @selector (applicationWillUnhide:)
|
||||
name: NSApplicationWillUnhideNotification object: NSApp];
|
||||
}
|
||||
}
|
||||
|
||||
~AppDelegate()
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: delegate];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: delegate];
|
||||
|
||||
if (JUCEApplicationBase::isStandaloneApp())
|
||||
{
|
||||
[NSApp setDelegate: nil];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter] removeObserver: delegate
|
||||
name: getBroacastEventName()
|
||||
object: nil];
|
||||
}
|
||||
|
||||
[delegate release];
|
||||
}
|
||||
|
||||
static NSString* getBroacastEventName()
|
||||
{
|
||||
return juceStringToNS ("juce_" + String::toHexString (File::getSpecialLocation (File::currentExecutableFile).hashCode64()));
|
||||
}
|
||||
|
||||
MessageQueue messageQueue;
|
||||
|
||||
private:
|
||||
id delegate;
|
||||
CFRunLoopRef runLoop;
|
||||
CFRunLoopSourceRef runLoopSource;
|
||||
|
||||
//==============================================================================
|
||||
struct AppDelegateClass : public ObjCClass <NSObject>
|
||||
{
|
||||
AppDelegateClass() : ObjCClass ("JUCEAppDelegate_")
|
||||
{
|
||||
addMethod (@selector (init), init, "@@:");
|
||||
addMethod (@selector (dealloc), dealloc, "v@:");
|
||||
addMethod (@selector (unregisterObservers), unregisterObservers, "v@:");
|
||||
addMethod (@selector (applicationShouldTerminate:), applicationShouldTerminate, "I@:@");
|
||||
addMethod (@selector (applicationWillTerminate:), applicationWillTerminate, "v@:@");
|
||||
addMethod (@selector (application:openFile:), application_openFile, "c@:@@");
|
||||
|
|
@ -50,67 +109,14 @@ struct AppDelegateClass : public ObjCClass <NSObject>
|
|||
registerClass();
|
||||
}
|
||||
|
||||
static NSString* getBroacastEventName()
|
||||
{
|
||||
return juceStringToNS ("juce_" + String::toHexString (File::getSpecialLocation (File::currentExecutableFile).hashCode64()));
|
||||
}
|
||||
|
||||
private:
|
||||
static id init (id self, SEL)
|
||||
{
|
||||
self = sendSuperclassMessage (self, @selector (init));
|
||||
|
||||
if (JUCEApplicationBase::isStandaloneApp())
|
||||
{
|
||||
[NSApp setDelegate: self];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter] addObserver: self
|
||||
selector: @selector (broadcastMessageCallback:)
|
||||
name: getBroacastEventName()
|
||||
object: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center addObserver: self selector: @selector (applicationDidResignActive:)
|
||||
name: NSApplicationDidResignActiveNotification object: NSApp];
|
||||
|
||||
[center addObserver: self selector: @selector (applicationDidBecomeActive:)
|
||||
name: NSApplicationDidBecomeActiveNotification object: NSApp];
|
||||
|
||||
[center addObserver: self selector: @selector (applicationWillUnhide:)
|
||||
name: NSApplicationWillUnhideNotification object: NSApp];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void dealloc (id self, SEL)
|
||||
{
|
||||
sendSuperclassMessage (self, @selector (dealloc));
|
||||
}
|
||||
|
||||
static void unregisterObservers (id self, SEL)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: self];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
if (JUCEApplicationBase::isStandaloneApp())
|
||||
{
|
||||
[NSApp setDelegate: nil];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter] removeObserver: self
|
||||
name: getBroacastEventName()
|
||||
object: nil];
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static NSApplicationTerminateReply applicationShouldTerminate (id /*self*/, SEL, NSApplication*)
|
||||
{
|
||||
if (JUCEApplicationBase::getInstance() != nullptr)
|
||||
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
|
||||
|
||||
if (app != nullptr)
|
||||
{
|
||||
JUCEApplicationBase::getInstance()->systemRequestedQuit();
|
||||
app->systemRequestedQuit();
|
||||
|
||||
if (! MessageManager::getInstance()->hasStopMessageBeenSent())
|
||||
return NSTerminateCancel;
|
||||
|
|
@ -126,9 +132,11 @@ private:
|
|||
|
||||
static BOOL application_openFile (id /*self*/, SEL, NSApplication*, NSString* filename)
|
||||
{
|
||||
if (JUCEApplicationBase::getInstance() != nullptr)
|
||||
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
|
||||
|
||||
if (app != nullptr)
|
||||
{
|
||||
JUCEApplicationBase::getInstance()->anotherInstanceStarted (quotedIfContainsSpaces (filename));
|
||||
app->anotherInstanceStarted (quotedIfContainsSpaces (filename));
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
@ -136,13 +144,18 @@ private:
|
|||
}
|
||||
|
||||
static void application_openFiles (id /*self*/, SEL, NSApplication*, NSArray* filenames)
|
||||
{
|
||||
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
|
||||
|
||||
if (app != nullptr)
|
||||
{
|
||||
StringArray files;
|
||||
for (unsigned int i = 0; i < [filenames count]; ++i)
|
||||
files.add (quotedIfContainsSpaces ((NSString*) [filenames objectAtIndex: i]));
|
||||
|
||||
if (files.size() > 0 && JUCEApplicationBase::getInstance() != nullptr)
|
||||
JUCEApplicationBase::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
|
||||
if (files.size() > 0)
|
||||
app->anotherInstanceStarted (files.joinIntoString (" "));
|
||||
}
|
||||
}
|
||||
|
||||
static void applicationDidBecomeActive (id /*self*/, SEL, NSNotification*) { focusChanged(); }
|
||||
|
|
@ -158,7 +171,7 @@ private:
|
|||
|
||||
static void dummyMethod (id /*self*/, SEL) {} // (used as a way of running a dummy thread)
|
||||
|
||||
private:
|
||||
private:
|
||||
static void focusChanged()
|
||||
{
|
||||
if (appFocusChangeCallback != nullptr)
|
||||
|
|
@ -173,6 +186,7 @@ private:
|
|||
|
||||
return s;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -251,34 +265,12 @@ void initialiseNSApplication()
|
|||
[NSApplication sharedApplication];
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
struct AppDelegateHolder
|
||||
{
|
||||
public:
|
||||
AppDelegateHolder()
|
||||
{
|
||||
static AppDelegateClass cls;
|
||||
delegate = [cls.createInstance() init];
|
||||
}
|
||||
|
||||
~AppDelegateHolder()
|
||||
{
|
||||
[delegate performSelector: @selector (unregisterObservers)];
|
||||
[delegate release];
|
||||
}
|
||||
|
||||
id delegate;
|
||||
CFRunLoopRef runLoop;
|
||||
CFRunLoopSourceRef runLoopSource;
|
||||
MessageQueue messageQueue;
|
||||
};
|
||||
|
||||
static AppDelegateHolder* appDelegate = nullptr;
|
||||
static AppDelegate* appDelegate = nullptr;
|
||||
|
||||
void MessageManager::doPlatformSpecificInitialisation()
|
||||
{
|
||||
if (appDelegate == nil)
|
||||
appDelegate = new AppDelegateHolder();
|
||||
appDelegate = new AppDelegate();
|
||||
|
||||
#if ! (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
|
||||
// This launches a dummy thread, which forces Cocoa to initialise NSThreads correctly (needed prior to 10.5)
|
||||
|
|
@ -307,7 +299,7 @@ void MessageManager::broadcastMessage (const String& message)
|
|||
NSDictionary* info = [NSDictionary dictionaryWithObject: juceStringToNS (message)
|
||||
forKey: nsStringLiteral ("message")];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName: AppDelegateClass::getBroacastEventName()
|
||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName: AppDelegate::getBroacastEventName()
|
||||
object: nil
|
||||
userInfo: info];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ struct FileChooserDelegateClass : public ObjCClass <NSObject>
|
|||
{
|
||||
addIvar<StringArray*> ("filters");
|
||||
|
||||
addMethod (@selector (initWithFilters:), initWithFilters, "@@:^v");
|
||||
addMethod (@selector (dealloc), dealloc, "v@:");
|
||||
addMethod (@selector (panel:shouldShowFilename:), shouldShowFilename, "c@:@@");
|
||||
|
||||
|
|
@ -42,14 +41,12 @@ struct FileChooserDelegateClass : public ObjCClass <NSObject>
|
|||
registerClass();
|
||||
}
|
||||
|
||||
private:
|
||||
static id initWithFilters (id self, SEL, StringArray* filters)
|
||||
static void setFilters (id self, StringArray* filters)
|
||||
{
|
||||
self = sendSuperclassMessage (self, @selector (init));
|
||||
object_setInstanceVariable (self, "filters", filters);
|
||||
return self;
|
||||
}
|
||||
|
||||
private:
|
||||
static void dealloc (id self, SEL)
|
||||
{
|
||||
delete getIvar<StringArray*> (self, "filters");
|
||||
|
|
@ -157,8 +154,8 @@ void FileChooser::showPlatformDialog (Array<File>& results,
|
|||
#endif
|
||||
|
||||
static FileChooserDelegateClass cls;
|
||||
DelegateType* delegate = [[cls.createInstance() performSelector: @selector (initWithFilters:)
|
||||
withObject: (id) filters] autorelease];
|
||||
DelegateType* delegate = (DelegateType*) [[cls.createInstance() init] autorelease];
|
||||
FileChooserDelegateClass::setFilters (delegate, filters);
|
||||
|
||||
NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
|
||||
: [NSOpenPanel openPanel];
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ public:
|
|||
lastUpdateTime (0)
|
||||
{
|
||||
static JuceMenuCallbackClass cls;
|
||||
callback = [cls.createInstance() performSelector: @selector (initWithOwner:)
|
||||
withObject: (id) this];
|
||||
callback = [cls.createInstance() init];
|
||||
JuceMenuCallbackClass::setOwner (callback, this);
|
||||
}
|
||||
|
||||
~JuceMainMenuHandler()
|
||||
|
|
@ -399,7 +399,6 @@ private:
|
|||
{
|
||||
addIvar<JuceMainMenuHandler*> ("owner");
|
||||
|
||||
addMethod (@selector (initWithOwner:), initWithOwner, "@@:^v");
|
||||
addMethod (@selector (menuItemInvoked:), menuItemInvoked, "v@:@");
|
||||
addMethod (@selector (menuNeedsUpdate:), menuNeedsUpdate, "v@:@");
|
||||
|
||||
|
|
@ -410,14 +409,12 @@ private:
|
|||
registerClass();
|
||||
}
|
||||
|
||||
private:
|
||||
static id initWithOwner (id self, SEL, JuceMainMenuHandler* owner)
|
||||
static void setOwner (id self, JuceMainMenuHandler* owner)
|
||||
{
|
||||
self = sendSuperclassMessage (self, @selector (init));
|
||||
object_setInstanceVariable (self, "owner", owner);
|
||||
return self;
|
||||
}
|
||||
|
||||
private:
|
||||
static void menuItemInvoked (id self, SEL, id menu)
|
||||
{
|
||||
JuceMainMenuHandler* const owner = getIvar<JuceMainMenuHandler*> (self, "owner");
|
||||
|
|
|
|||
|
|
@ -38,17 +38,10 @@ struct DownloadClickDetectorClass : public ObjCClass <NSObject>
|
|||
registerClass();
|
||||
}
|
||||
|
||||
static void setOwner (id self, WebBrowserComponent* owner)
|
||||
{
|
||||
object_setInstanceVariable (self, "owner", owner);
|
||||
}
|
||||
static void setOwner (id self, WebBrowserComponent* owner) { object_setInstanceVariable (self, "owner", owner); }
|
||||
static WebBrowserComponent* getOwner (id self) { return getIvar<WebBrowserComponent*> (self, "owner"); }
|
||||
|
||||
private:
|
||||
static WebBrowserComponent* getOwner (id self)
|
||||
{
|
||||
return getIvar<WebBrowserComponent*> (self, "owner");
|
||||
}
|
||||
|
||||
static void decidePolicyForNavigationAction (id self, SEL, WebView*, NSDictionary* actionInformation,
|
||||
NSURLRequest*, WebFrame*, id <WebPolicyDecisionListener> listener)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -224,17 +224,10 @@ private:
|
|||
registerClass();
|
||||
}
|
||||
|
||||
static void setOwner (id self, QTCameraDeviceInternal* owner)
|
||||
{
|
||||
object_setInstanceVariable (self, "owner", owner);
|
||||
}
|
||||
static void setOwner (id self, QTCameraDeviceInternal* owner) { object_setInstanceVariable (self, "owner", owner); }
|
||||
static QTCameraDeviceInternal* getOwner (id self) { return getIvar<QTCameraDeviceInternal*> (self, "owner"); }
|
||||
|
||||
private:
|
||||
static QTCameraDeviceInternal* getOwner (id self)
|
||||
{
|
||||
return getIvar<QTCameraDeviceInternal*> (self, "owner");
|
||||
}
|
||||
|
||||
static void didOutputVideoFrame (id self, SEL, QTCaptureOutput* captureOutput,
|
||||
CVImageBufferRef videoFrame, QTSampleBuffer* sampleBuffer,
|
||||
QTCaptureConnection* connection)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue