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
This commit is contained in:
David Elliott
2007-05-27 04:52:04 +00:00
parent 931d76980e
commit a24aa4279a
10 changed files with 43 additions and 16 deletions

View File

@@ -12,6 +12,8 @@
#ifndef _WX_COCOA_NSAPPLICATION_H__ #ifndef _WX_COCOA_NSAPPLICATION_H__
#define _WX_COCOA_NSAPPLICATION_H__ #define _WX_COCOA_NSAPPLICATION_H__
#include "wx/cocoa/objc/objc_uniquifying.h"
// ======================================================================== // ========================================================================
// wxNSApplicationDelegate // wxNSApplicationDelegate
// ======================================================================== // ========================================================================
@@ -32,6 +34,7 @@
// Delegate methods // Delegate methods
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
@end // interface wxNSApplicationDelegate : NSObject @end // interface wxNSApplicationDelegate : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject)
// ======================================================================== // ========================================================================
// wxNSApplicationObserver // wxNSApplicationObserver
@@ -60,5 +63,6 @@
// Other notifications // Other notifications
- (void)controlTintChanged:(NSNotification *)notification; - (void)controlTintChanged:(NSNotification *)notification;
@end // interface wxNSApplicationObserver : NSObject @end // interface wxNSApplicationObserver : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxNSApplicationObserver,NSObject)
#endif //ndef _WX_COCOA_NSAPPLICATION_H__ #endif //ndef _WX_COCOA_NSAPPLICATION_H__

View File

@@ -12,6 +12,8 @@
#ifndef __WX_COCOA_OBJC_NSVIEW_H__ #ifndef __WX_COCOA_OBJC_NSVIEW_H__
#define __WX_COCOA_OBJC_NSVIEW_H__ #define __WX_COCOA_OBJC_NSVIEW_H__
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <AppKit/NSView.h> #import <AppKit/NSView.h>
// ============================================================================ // ============================================================================
@@ -36,5 +38,6 @@
- (void)otherMouseUp:(NSEvent *)theEvent; - (void)otherMouseUp:(NSEvent *)theEvent;
- (void)resetCursorRects; - (void)resetCursorRects;
@end // WXNSView @end // WXNSView
WX_DECLARE_GET_OBJC_CLASS(WXNSView,NSView)
#endif //ndef __WX_COCOA_OBJC_NSVIEW_H__ #endif //ndef __WX_COCOA_OBJC_NSVIEW_H__

View File

@@ -22,6 +22,7 @@
#include "wx/log.h" #include "wx/log.h"
#endif // WX_PRECOMP #endif // WX_PRECOMP
#include "wx/cocoa/objc/objc_uniquifying.h"
#include "wx/cocoa/NSButton.h" #include "wx/cocoa/NSButton.h"
#import <AppKit/NSButton.h> #import <AppKit/NSButton.h>
@@ -39,6 +40,7 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSButton)
- (void)wxNSButtonAction: (id)sender; - (void)wxNSButtonAction: (id)sender;
@end // wxNSButtonTarget @end // wxNSButtonTarget
WX_DECLARE_GET_OBJC_CLASS(wxNSButtonTarget,NSObject)
@implementation wxNSButtonTarget : NSObject @implementation wxNSButtonTarget : NSObject
- (void)wxNSButtonAction: (id)sender - (void)wxNSButtonAction: (id)sender
@@ -49,11 +51,12 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSButton)
} }
@end // implementation wxNSButtonTarget @end // implementation wxNSButtonTarget
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSButtonTarget,NSObject)
// ============================================================================ // ============================================================================
// class wxCocoaNSButton // 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) void wxCocoaNSButton::AssociateNSButton(WX_NSButton cocoaNSButton)
{ {

View File

@@ -22,6 +22,7 @@
#include "wx/log.h" #include "wx/log.h"
#endif // WX_PRECOMP #endif // WX_PRECOMP
#include "wx/cocoa/objc/objc_uniquifying.h"
#include "wx/cocoa/NSControl.h" #include "wx/cocoa/NSControl.h"
#import <Foundation/NSObject.h> #import <Foundation/NSObject.h>
@@ -35,6 +36,7 @@
- (void)wxNSControlAction: (id)sender; - (void)wxNSControlAction: (id)sender;
@end //interface wxNSControlTarget @end //interface wxNSControlTarget
WX_DECLARE_GET_OBJC_CLASS(wxNSControlTarget,NSObject)
@implementation wxNSControlTarget : NSObject @implementation wxNSControlTarget : NSObject
@@ -47,11 +49,12 @@
} }
@end //implementation wxNSControlTarget @end //implementation wxNSControlTarget
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSControlTarget,NSObject)
// ============================================================================ // ============================================================================
// wxNSControl // wxNSControl
// ============================================================================ // ============================================================================
WX_IMPLEMENT_OBJC_INTERFACE(NSControl) 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];

View File

@@ -22,6 +22,7 @@
#include "wx/window.h" #include "wx/window.h"
#endif // WX_PRECOMP #endif // WX_PRECOMP
#include "wx/cocoa/objc/objc_uniquifying.h"
#include "wx/cocoa/NSView.h" #include "wx/cocoa/NSView.h"
#import <Foundation/NSNotification.h> #import <Foundation/NSNotification.h>
@@ -166,19 +167,19 @@ void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
} }
@end // implementation WXNSView @end // implementation WXNSView
WX_IMPLEMENT_GET_OBJC_CLASS(WXNSView,NSView)
// ============================================================================
// @class wxNSViewNotificationObserver
// ============================================================================
@interface wxNSViewNotificationObserver : NSObject @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; - (void)notificationFrameChanged: (NSNotification *)notification;
@end // interface wxNSViewNotificationObserver @end // interface wxNSViewNotificationObserver
WX_DECLARE_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject)
@implementation wxNSViewNotificationObserver : NSObject @implementation wxNSViewNotificationObserver : NSObject
@@ -190,4 +191,7 @@ void *wxCocoaNSView::sm_cocoaObserver = [[wxNSViewNotificationObserver alloc] in
} }
@end // implementation wxNSViewNotificationObserver @end // implementation wxNSViewNotificationObserver
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject)
void *wxCocoaNSView::sm_cocoaObserver = [[WX_GET_OBJC_CLASS(wxNSViewNotificationObserver) alloc] init];

View File

@@ -37,7 +37,7 @@
bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin
// wxNSApplicationObserver singleton. // wxNSApplicationObserver singleton.
static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[wxNSApplicationObserver alloc] init]; static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[WX_GET_OBJC_CLASS(wxNSApplicationObserver) alloc] init];
// ======================================================================== // ========================================================================
// wxNSApplicationDelegate // wxNSApplicationDelegate
@@ -53,6 +53,7 @@ static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[
} }
@end // implementation wxNSApplicationDelegate : NSObject @end // implementation wxNSApplicationDelegate : NSObject
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject)
// ======================================================================== // ========================================================================
// wxNSApplicationObserver // wxNSApplicationObserver
@@ -90,6 +91,7 @@ static wxObjcAutoRefFromAlloc<wxNSApplicationObserver*> sg_cocoaAppObserver = [[
} }
@end // implementation wxNSApplicationObserver : NSObject @end // implementation wxNSApplicationObserver : NSObject
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationObserver,NSObject)
// ======================================================================== // ========================================================================
// wxApp // wxApp
@@ -194,7 +196,7 @@ bool wxApp::OnInitGui()
if(!sm_isEmbedded) if(!sm_isEmbedded)
{ {
// Enable response to application delegate messages // 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]; [m_cocoaApp setDelegate:m_cocoaAppDelegate];
} }

View File

@@ -18,6 +18,7 @@
#endif #endif
#include "wx/cocoa/autorelease.h" #include "wx/cocoa/autorelease.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <AppKit/NSControl.h> #import <AppKit/NSControl.h>
#import <AppKit/NSCell.h> #import <AppKit/NSCell.h>
@@ -44,6 +45,7 @@
- (void)otherMouseUp:(NSEvent *)theEvent; - (void)otherMouseUp:(NSEvent *)theEvent;
- (void)resetCursorRects; - (void)resetCursorRects;
@end // wxNonControlNSControl @end // wxNonControlNSControl
WX_DECLARE_GET_OBJC_CLASS(wxNonControlNSControl,NSControl)
@implementation wxNonControlNSControl : NSControl @implementation wxNonControlNSControl : NSControl
@@ -155,6 +157,7 @@
} }
@end // wxNonControlNSControl @end // wxNonControlNSControl
WX_IMPLEMENT_GET_OBJC_CLASS(wxNonControlNSControl,NSControl)
IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
BEGIN_EVENT_TABLE(wxControl, wxControlBase) BEGIN_EVENT_TABLE(wxControl, wxControlBase)
@@ -170,7 +173,7 @@ bool wxControl::Create(wxWindow *parent, wxWindowID winid,
return false; return false;
wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId()); wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId());
m_cocoaNSView = NULL; 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). // NOTE: YES we want to release this (to match the alloc).
// DoAddChild(this) will retain us again since addSubView doesn't. // DoAddChild(this) will retain us again since addSubView doesn't.
[m_cocoaNSView release]; [m_cocoaNSView release];

View File

@@ -53,7 +53,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
{ {
if(!CreateControl(parent,winid,pos,size,style,validator,name)) if(!CreateControl(parent,winid,pos,size,style,validator,name))
return false; return false;
SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]); SetNSView([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]);
[m_cocoaNSView release]; [m_cocoaNSView release];
if(m_parent) if(m_parent)
m_parent->CocoaAddChild(this); m_parent->CocoaAddChild(this);

View File

@@ -36,6 +36,7 @@
#include "wx/cocoa/objc/NSView.h" #include "wx/cocoa/objc/NSView.h"
#include "wx/cocoa/objc/NSWindow.h" #include "wx/cocoa/objc/NSWindow.h"
#import <AppKit/NSPanel.h> #import <AppKit/NSPanel.h>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// globals // globals
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -139,7 +140,7 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
else else
newWindow = [[WXNSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; newWindow = [[WXNSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO];
// Make sure the default content view is a WXNSView // 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 // Associate the window and view
SetNSWindow(newWindow); SetNSWindow(newWindow);

View File

@@ -145,6 +145,7 @@ private:
@interface wxDummyNSView : NSView @interface wxDummyNSView : NSView
- (NSView *)hitTest:(NSPoint)aPoint; - (NSView *)hitTest:(NSPoint)aPoint;
@end @end
WX_DECLARE_GET_OBJC_CLASS(wxDummyNSView,NSView)
@implementation wxDummyNSView : NSView @implementation wxDummyNSView : NSView
- (NSView *)hitTest:(NSPoint)aPoint - (NSView *)hitTest:(NSPoint)aPoint
@@ -153,6 +154,7 @@ private:
} }
@end @end
WX_IMPLEMENT_GET_OBJC_CLASS(wxDummyNSView,NSView)
// ======================================================================== // ========================================================================
// wxWindowCocoaHider // wxWindowCocoaHider
@@ -162,7 +164,7 @@ wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
{ {
wxASSERT(owner); wxASSERT(owner);
wxASSERT(owner->GetNSViewForHiding()); wxASSERT(owner->GetNSViewForHiding());
m_dummyNSView = [[wxDummyNSView alloc] m_dummyNSView = [[WX_GET_OBJC_CLASS(wxDummyNSView) alloc]
initWithFrame:[owner->GetNSViewForHiding() frame]]; initWithFrame:[owner->GetNSViewForHiding() frame]];
[m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]]; [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
AssociateNSView(m_dummyNSView); AssociateNSView(m_dummyNSView);
@@ -199,6 +201,7 @@ bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
@interface wxFlippedNSClipView : NSClipView @interface wxFlippedNSClipView : NSClipView
- (BOOL)isFlipped; - (BOOL)isFlipped;
@end @end
WX_DECLARE_GET_OBJC_CLASS(wxFlippedNSClipView,NSClipView)
@implementation wxFlippedNSClipView : NSClipView @implementation wxFlippedNSClipView : NSClipView
- (BOOL)isFlipped - (BOOL)isFlipped
@@ -207,6 +210,7 @@ bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
} }
@end @end
WX_IMPLEMENT_GET_OBJC_CLASS(wxFlippedNSClipView,NSClipView)
// ======================================================================== // ========================================================================
// wxWindowCocoaScrollView // wxWindowCocoaScrollView
@@ -223,7 +227,7 @@ wxWindowCocoaScrollView::wxWindowCocoaScrollView(wxWindow *owner)
/* Replace the default NSClipView with a flipped one. This ensures /* Replace the default NSClipView with a flipped one. This ensures
scrolling is "pinned" to the top-left instead of bottom-right. */ 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]]; initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
[m_cocoaNSScrollView setContentView:flippedClip]; [m_cocoaNSScrollView setContentView:flippedClip];
[flippedClip release]; [flippedClip release];
@@ -327,7 +331,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
// TODO: create the window // TODO: create the window
m_cocoaNSView = NULL; m_cocoaNSView = NULL;
SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]); SetNSView([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]);
[m_cocoaNSView release]; [m_cocoaNSView release];
if (m_parent) if (m_parent)