]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow many Objective-C classes to be uniquified at runtime.
authorDavid Elliott <dfe@tgwbd.org>
Sun, 27 May 2007 04:52:04 +0000 (04:52 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Sun, 27 May 2007 04:52:04 +0000 (04:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46227 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/NSApplication.h
include/wx/cocoa/objc/NSView.h
src/cocoa/NSButton.mm
src/cocoa/NSControl.mm
src/cocoa/NSView.mm
src/cocoa/app.mm
src/cocoa/control.mm
src/cocoa/radiobox.mm
src/cocoa/toplevel.mm
src/cocoa/window.mm

index 6ce223f48e6dfdc5c41eae8c26de69bc98ead0c6..d1fc4c6677c5c9103fc30003ac19737e67117ff7 100644 (file)
@@ -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__
index 4bedd94b4fd1dc73d54355fdc1ef9852c8b7c85c..2f2ab86ff719ea8f012549b25052cce9e0badb1c 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef __WX_COCOA_OBJC_NSVIEW_H__
 #define __WX_COCOA_OBJC_NSVIEW_H__
 
+#include "wx/cocoa/objc/objc_uniquifying.h"
+
 #import <AppKit/NSView.h>
 
 // ============================================================================
@@ -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__
index e2436fca0a4080113d7048022b212a0b52e698e1..00bace286bc2707d63c44c5e18b04a32a68910bd 100644 (file)
@@ -22,6 +22,7 @@
     #include "wx/log.h"
 #endif // WX_PRECOMP
 
+#include "wx/cocoa/objc/objc_uniquifying.h"
 #include "wx/cocoa/NSButton.h"
 #import <AppKit/NSButton.h>
 
@@ -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<struct objc_object*> wxCocoaNSButton::sm_cocoaTarget = [[wxNSButtonTarget alloc] init];
+const wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSButton::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSButtonTarget) alloc] init];
 
 void wxCocoaNSButton::AssociateNSButton(WX_NSButton cocoaNSButton)
 {
index ab10708d20852b8a0855644e2b573b7f7788b869..1e6a632de7e3d393085bae7a899237392e3ea2f6 100644 (file)
@@ -22,6 +22,7 @@
     #include "wx/log.h"
 #endif // WX_PRECOMP
 
+#include "wx/cocoa/objc/objc_uniquifying.h"
 #include "wx/cocoa/NSControl.h"
 
 #import <Foundation/NSObject.h>
@@ -35,6 +36,7 @@
 
 - (void)wxNSControlAction: (id)sender;
 @end //interface wxNSControlTarget
+WX_DECLARE_GET_OBJC_CLASS(wxNSControlTarget,NSObject)
 
 @implementation wxNSControlTarget : NSObject
 
 }
 
 @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];
 
index b9bc51957436dab230511c2254f978b4c8e0fc7a..b794f269497abcbacf1cae19b532a9f06a9cdfb4 100644 (file)
@@ -22,6 +22,7 @@
     #include "wx/window.h"
 #endif // WX_PRECOMP
 
+#include "wx/cocoa/objc/objc_uniquifying.h"
 #include "wx/cocoa/NSView.h"
 
 #import <Foundation/NSNotification.h>
@@ -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];
 
index f1d604d3791e577b924f41370bb1229334212f1d..e2f29aac351a1390c61e59fccf8ebefecf8fb9c5 100644 (file)
@@ -37,7 +37,7 @@
 bool      wxApp::sm_isEmbedded = false; // Normally we're not a plugin
 
 // wxNSApplicationObserver singleton.
-static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[wxNSApplicationObserver alloc] init];
+static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[WX_GET_OBJC_CLASS(wxNSApplicationObserver) alloc] init];
 
 // ========================================================================
 // wxNSApplicationDelegate
@@ -53,6 +53,7 @@ static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[
 }
 
 @end // implementation wxNSApplicationDelegate : NSObject
+WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject)
 
 // ========================================================================
 // wxNSApplicationObserver
@@ -90,6 +91,7 @@ static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> 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];
     }
 
index 1d14483d6df9db6f402dfc232e558ff06f5819a1..e45aae8bf74305ec3eb7aae17f96f04ba0a6ad3e 100644 (file)
@@ -18,6 +18,7 @@
 #endif
 
 #include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/objc/objc_uniquifying.h"
 
 #import <AppKit/NSControl.h>
 #import <AppKit/NSCell.h>
@@ -44,6 +45,7 @@
 - (void)otherMouseUp:(NSEvent *)theEvent;
 - (void)resetCursorRects;
 @end // wxNonControlNSControl
+WX_DECLARE_GET_OBJC_CLASS(wxNonControlNSControl,NSControl)
 
 @implementation wxNonControlNSControl : NSControl
 
 }
 
 @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];
index 4b4f7522e25466401b1faa1af5d00edf87079e34..8cf200fb4de4ac3c44137334a1d567c12e4eb9a0 100644 (file)
@@ -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);
index fbcf064b1b7d938a27f21c1e3f399111150519fb..83dd00623d1cc066665c0a69cb0063b0c3af6bb2 100644 (file)
@@ -36,6 +36,7 @@
 #include "wx/cocoa/objc/NSView.h"
 #include "wx/cocoa/objc/NSWindow.h"
 #import <AppKit/NSPanel.h>
+
 // ----------------------------------------------------------------------------
 // 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);
 
index 6529cdf7be8fbab8127667a9462d33e9ff924128..09736de17386e96a44c5e9815ce0ea6d734cdfe5 100644 (file)
@@ -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)