From a24aa4279a8ef9c25b7d0a512a1def0d823ef8f7 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Sun, 27 May 2007 04:52:04 +0000 Subject: [PATCH 1/1] Allow many Objective-C classes to be uniquified at runtime. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46227 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/NSApplication.h | 4 ++++ include/wx/cocoa/objc/NSView.h | 3 +++ src/cocoa/NSButton.mm | 5 ++++- src/cocoa/NSControl.mm | 5 ++++- src/cocoa/NSView.mm | 16 ++++++++++------ src/cocoa/app.mm | 6 ++++-- src/cocoa/control.mm | 5 ++++- src/cocoa/radiobox.mm | 2 +- src/cocoa/toplevel.mm | 3 ++- src/cocoa/window.mm | 10 +++++++--- 10 files changed, 43 insertions(+), 16 deletions(-) diff --git a/include/wx/cocoa/NSApplication.h b/include/wx/cocoa/NSApplication.h index 6ce223f48e..d1fc4c6677 100644 --- a/include/wx/cocoa/NSApplication.h +++ b/include/wx/cocoa/NSApplication.h @@ -12,6 +12,8 @@ #ifndef _WX_COCOA_NSAPPLICATION_H__ #define _WX_COCOA_NSAPPLICATION_H__ +#include "wx/cocoa/objc/objc_uniquifying.h" + // ======================================================================== // wxNSApplicationDelegate // ======================================================================== @@ -32,6 +34,7 @@ // Delegate methods - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; @end // interface wxNSApplicationDelegate : NSObject +WX_DECLARE_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject) // ======================================================================== // wxNSApplicationObserver @@ -60,5 +63,6 @@ // Other notifications - (void)controlTintChanged:(NSNotification *)notification; @end // interface wxNSApplicationObserver : NSObject +WX_DECLARE_GET_OBJC_CLASS(wxNSApplicationObserver,NSObject) #endif //ndef _WX_COCOA_NSAPPLICATION_H__ diff --git a/include/wx/cocoa/objc/NSView.h b/include/wx/cocoa/objc/NSView.h index 4bedd94b4f..2f2ab86ff7 100644 --- a/include/wx/cocoa/objc/NSView.h +++ b/include/wx/cocoa/objc/NSView.h @@ -12,6 +12,8 @@ #ifndef __WX_COCOA_OBJC_NSVIEW_H__ #define __WX_COCOA_OBJC_NSVIEW_H__ +#include "wx/cocoa/objc/objc_uniquifying.h" + #import // ============================================================================ @@ -36,5 +38,6 @@ - (void)otherMouseUp:(NSEvent *)theEvent; - (void)resetCursorRects; @end // WXNSView +WX_DECLARE_GET_OBJC_CLASS(WXNSView,NSView) #endif //ndef __WX_COCOA_OBJC_NSVIEW_H__ diff --git a/src/cocoa/NSButton.mm b/src/cocoa/NSButton.mm index e2436fca0a..00bace286b 100644 --- a/src/cocoa/NSButton.mm +++ b/src/cocoa/NSButton.mm @@ -22,6 +22,7 @@ #include "wx/log.h" #endif // WX_PRECOMP +#include "wx/cocoa/objc/objc_uniquifying.h" #include "wx/cocoa/NSButton.h" #import @@ -39,6 +40,7 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSButton) - (void)wxNSButtonAction: (id)sender; @end // wxNSButtonTarget +WX_DECLARE_GET_OBJC_CLASS(wxNSButtonTarget,NSObject) @implementation wxNSButtonTarget : NSObject - (void)wxNSButtonAction: (id)sender @@ -49,11 +51,12 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSButton) } @end // implementation wxNSButtonTarget +WX_IMPLEMENT_GET_OBJC_CLASS(wxNSButtonTarget,NSObject) // ============================================================================ // class wxCocoaNSButton // ============================================================================ -const wxObjcAutoRefFromAlloc wxCocoaNSButton::sm_cocoaTarget = [[wxNSButtonTarget alloc] init]; +const wxObjcAutoRefFromAlloc wxCocoaNSButton::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSButtonTarget) alloc] init]; void wxCocoaNSButton::AssociateNSButton(WX_NSButton cocoaNSButton) { diff --git a/src/cocoa/NSControl.mm b/src/cocoa/NSControl.mm index ab10708d20..1e6a632de7 100644 --- a/src/cocoa/NSControl.mm +++ b/src/cocoa/NSControl.mm @@ -22,6 +22,7 @@ #include "wx/log.h" #endif // WX_PRECOMP +#include "wx/cocoa/objc/objc_uniquifying.h" #include "wx/cocoa/NSControl.h" #import @@ -35,6 +36,7 @@ - (void)wxNSControlAction: (id)sender; @end //interface wxNSControlTarget +WX_DECLARE_GET_OBJC_CLASS(wxNSControlTarget,NSObject) @implementation wxNSControlTarget : NSObject @@ -47,11 +49,12 @@ } @end //implementation wxNSControlTarget +WX_IMPLEMENT_GET_OBJC_CLASS(wxNSControlTarget,NSObject) // ============================================================================ // wxNSControl // ============================================================================ WX_IMPLEMENT_OBJC_INTERFACE(NSControl) -struct objc_object *wxCocoaNSControl::sm_cocoaTarget = [[wxNSControlTarget alloc] init]; +struct objc_object *wxCocoaNSControl::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSControlTarget) alloc] init]; diff --git a/src/cocoa/NSView.mm b/src/cocoa/NSView.mm index b9bc519574..b794f26949 100644 --- a/src/cocoa/NSView.mm +++ b/src/cocoa/NSView.mm @@ -22,6 +22,7 @@ #include "wx/window.h" #endif // WX_PRECOMP +#include "wx/cocoa/objc/objc_uniquifying.h" #include "wx/cocoa/NSView.h" #import @@ -166,19 +167,19 @@ void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView) } @end // implementation WXNSView +WX_IMPLEMENT_GET_OBJC_CLASS(WXNSView,NSView) + +// ============================================================================ +// @class wxNSViewNotificationObserver +// ============================================================================ @interface wxNSViewNotificationObserver : NSObject { } -// FIXME: Initializing like this is a really bad idea. If for some reason -// we ever require posing as an NSObject we won't be able to since an instance -// will have already been created here. Of course, catching messages for -// NSObject seems like a LOT of overkill, so I doubt we ever will anyway! -void *wxCocoaNSView::sm_cocoaObserver = [[wxNSViewNotificationObserver alloc] init]; - - (void)notificationFrameChanged: (NSNotification *)notification; @end // interface wxNSViewNotificationObserver +WX_DECLARE_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject) @implementation wxNSViewNotificationObserver : NSObject @@ -190,4 +191,7 @@ void *wxCocoaNSView::sm_cocoaObserver = [[wxNSViewNotificationObserver alloc] in } @end // implementation wxNSViewNotificationObserver +WX_IMPLEMENT_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject) + +void *wxCocoaNSView::sm_cocoaObserver = [[WX_GET_OBJC_CLASS(wxNSViewNotificationObserver) alloc] init]; diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm index f1d604d379..e2f29aac35 100644 --- a/src/cocoa/app.mm +++ b/src/cocoa/app.mm @@ -37,7 +37,7 @@ bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin // wxNSApplicationObserver singleton. -static wxObjcAutoRefFromAlloc sg_cocoaAppObserver = [[wxNSApplicationObserver alloc] init]; +static wxObjcAutoRefFromAlloc sg_cocoaAppObserver = [[WX_GET_OBJC_CLASS(wxNSApplicationObserver) alloc] init]; // ======================================================================== // wxNSApplicationDelegate @@ -53,6 +53,7 @@ static wxObjcAutoRefFromAlloc sg_cocoaAppObserver = [[ } @end // implementation wxNSApplicationDelegate : NSObject +WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject) // ======================================================================== // wxNSApplicationObserver @@ -90,6 +91,7 @@ static wxObjcAutoRefFromAlloc sg_cocoaAppObserver = [[ } @end // implementation wxNSApplicationObserver : NSObject +WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationObserver,NSObject) // ======================================================================== // wxApp @@ -194,7 +196,7 @@ bool wxApp::OnInitGui() if(!sm_isEmbedded) { // Enable response to application delegate messages - m_cocoaAppDelegate = [[wxNSApplicationDelegate alloc] init]; + m_cocoaAppDelegate = [[WX_GET_OBJC_CLASS(wxNSApplicationDelegate) alloc] init]; [m_cocoaApp setDelegate:m_cocoaAppDelegate]; } diff --git a/src/cocoa/control.mm b/src/cocoa/control.mm index 1d14483d6d..e45aae8bf7 100644 --- a/src/cocoa/control.mm +++ b/src/cocoa/control.mm @@ -18,6 +18,7 @@ #endif #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/objc/objc_uniquifying.h" #import #import @@ -44,6 +45,7 @@ - (void)otherMouseUp:(NSEvent *)theEvent; - (void)resetCursorRects; @end // wxNonControlNSControl +WX_DECLARE_GET_OBJC_CLASS(wxNonControlNSControl,NSControl) @implementation wxNonControlNSControl : NSControl @@ -155,6 +157,7 @@ } @end // wxNonControlNSControl +WX_IMPLEMENT_GET_OBJC_CLASS(wxNonControlNSControl,NSControl) IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) BEGIN_EVENT_TABLE(wxControl, wxControlBase) @@ -170,7 +173,7 @@ bool wxControl::Create(wxWindow *parent, wxWindowID winid, return false; wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId()); m_cocoaNSView = NULL; - SetNSControl([[wxNonControlNSControl alloc] initWithFrame: MakeDefaultNSRect(size)]); + SetNSControl([[WX_GET_OBJC_CLASS(wxNonControlNSControl) alloc] initWithFrame: MakeDefaultNSRect(size)]); // NOTE: YES we want to release this (to match the alloc). // DoAddChild(this) will retain us again since addSubView doesn't. [m_cocoaNSView release]; diff --git a/src/cocoa/radiobox.mm b/src/cocoa/radiobox.mm index 4b4f7522e2..8cf200fb4d 100644 --- a/src/cocoa/radiobox.mm +++ b/src/cocoa/radiobox.mm @@ -53,7 +53,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid, { if(!CreateControl(parent,winid,pos,size,style,validator,name)) return false; - SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]); + SetNSView([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]); [m_cocoaNSView release]; if(m_parent) m_parent->CocoaAddChild(this); diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm index fbcf064b1b..83dd00623d 100644 --- a/src/cocoa/toplevel.mm +++ b/src/cocoa/toplevel.mm @@ -36,6 +36,7 @@ #include "wx/cocoa/objc/NSView.h" #include "wx/cocoa/objc/NSWindow.h" #import + // ---------------------------------------------------------------------------- // globals // ---------------------------------------------------------------------------- @@ -139,7 +140,7 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent, else newWindow = [[WXNSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; // Make sure the default content view is a WXNSView - [newWindow setContentView: [[WXNSView alloc] initWithFrame: [[newWindow contentView] frame]]]; + [newWindow setContentView: [[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: [[newWindow contentView] frame]]]; // Associate the window and view SetNSWindow(newWindow); diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index 6529cdf7be..09736de173 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -145,6 +145,7 @@ private: @interface wxDummyNSView : NSView - (NSView *)hitTest:(NSPoint)aPoint; @end +WX_DECLARE_GET_OBJC_CLASS(wxDummyNSView,NSView) @implementation wxDummyNSView : NSView - (NSView *)hitTest:(NSPoint)aPoint @@ -153,6 +154,7 @@ private: } @end +WX_IMPLEMENT_GET_OBJC_CLASS(wxDummyNSView,NSView) // ======================================================================== // wxWindowCocoaHider @@ -162,7 +164,7 @@ wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner) { wxASSERT(owner); wxASSERT(owner->GetNSViewForHiding()); - m_dummyNSView = [[wxDummyNSView alloc] + m_dummyNSView = [[WX_GET_OBJC_CLASS(wxDummyNSView) alloc] initWithFrame:[owner->GetNSViewForHiding() frame]]; [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]]; AssociateNSView(m_dummyNSView); @@ -199,6 +201,7 @@ bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect) @interface wxFlippedNSClipView : NSClipView - (BOOL)isFlipped; @end +WX_DECLARE_GET_OBJC_CLASS(wxFlippedNSClipView,NSClipView) @implementation wxFlippedNSClipView : NSClipView - (BOOL)isFlipped @@ -207,6 +210,7 @@ bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect) } @end +WX_IMPLEMENT_GET_OBJC_CLASS(wxFlippedNSClipView,NSClipView) // ======================================================================== // wxWindowCocoaScrollView @@ -223,7 +227,7 @@ wxWindowCocoaScrollView::wxWindowCocoaScrollView(wxWindow *owner) /* Replace the default NSClipView with a flipped one. This ensures scrolling is "pinned" to the top-left instead of bottom-right. */ - NSClipView *flippedClip = [[wxFlippedNSClipView alloc] + NSClipView *flippedClip = [[WX_GET_OBJC_CLASS(wxFlippedNSClipView) alloc] initWithFrame: [[m_cocoaNSScrollView contentView] frame]]; [m_cocoaNSScrollView setContentView:flippedClip]; [flippedClip release]; @@ -327,7 +331,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid, // TODO: create the window m_cocoaNSView = NULL; - SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]); + SetNSView([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]); [m_cocoaNSView release]; if (m_parent) -- 2.45.2