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__
#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__

View 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__

View 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)
{

View 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
@@ -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];

View 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];

View 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];
}

View 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
@@ -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];

View 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);

View 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);

View 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)