Add support for uniquifying to all wxCocoa Objective-C classes.

Patch from Mark Taylor.
Copyright 2007 Software 2000 Ltd.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48106 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2007-08-15 16:10:19 +00:00
parent 3ac1094bea
commit e7e1ad7d93
17 changed files with 67 additions and 15 deletions

View File

@@ -12,6 +12,8 @@
#ifndef __WX_COCOA_NSTABLEDATASOURCE_H__
#define __WX_COCOA_NSTABLEDATASOURCE_H__
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <Foundation/NSObject.h>
// ============================================================================
@@ -28,5 +30,6 @@
objectValueForTableColumn: (NSTableColumn *)tableColumn
row: (int)rowIndex;
@end // wxCocoaNSTableDataSource
WX_DECLARE_GET_OBJC_CLASS(wxCocoaNSTableDataSource,NSObject)
#endif // _WX_COCOA_NSTABLEDATASOURCE_H_

View File

@@ -12,6 +12,8 @@
#ifndef __WX_COCOA_OBJC_NSMENU_H__
#define __WX_COCOA_OBJC_NSMENU_H__
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <AppKit/NSMenu.h>
// ============================================================================
@@ -24,5 +26,6 @@
- (void)dealloc;
@end // WXNSMenu
WX_DECLARE_GET_OBJC_CLASS(WXNSMenu,NSMenu)
#endif //ndef __WX_COCOA_OBJC_NSMENU_H__

View File

@@ -35,6 +35,7 @@
}
@end // WXNSMenu
WX_IMPLEMENT_GET_OBJC_CLASS(WXNSMenu,NSMenu)
// ============================================================================
// @class wxNSMenuNotificationObserver
@@ -43,14 +44,13 @@
{
}
struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = [[wxNSMenuNotificationObserver alloc] init];
- (void)menuDidAddItem: (NSNotification *)notification;
- (void)menuDidChangeItem: (NSNotification *)notification;
- (void)menuDidRemoveItem: (NSNotification *)notification;
- (void)menuDidSendAction: (NSNotification *)notification;
- (void)menuWillSendAction: (NSNotification *)notification;
@end // interface wxNSMenuNotificationObserver
WX_DECLARE_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject)
@implementation wxNSMenuNotificationObserver : NSObject
@@ -90,12 +90,15 @@ struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = [[wxNSMenuNotificationObse
}
@end // implementation wxNSMenuNotificationObserver
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject)
// ========================================================================
// wxCocoaNSMenu
// ========================================================================
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSMenu)
struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = [[WX_GET_OBJC_CLASS(wxNSMenuNotificationObserver) alloc] init];
void wxCocoaNSMenu::AssociateNSMenu(WX_NSMenu cocoaNSMenu, unsigned int flags)
{
if(cocoaNSMenu)

View File

@@ -14,6 +14,8 @@
#include "wx/log.h"
#endif // WX_PRECOMP
#include "wx/cocoa/objc/objc_uniquifying.h"
#include "wx/cocoa/NSScroller.h"
#import <AppKit/NSScroller.h>
@@ -28,6 +30,7 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSScroller)
- (void)wxNSScrollerAction: (id)sender;
@end // wxNSScrollerTarget
WX_DECLARE_GET_OBJC_CLASS(wxNSScrollerTarget,NSObject)
@implementation wxNSScrollerTarget : NSObject
- (void)wxNSScrollerAction: (id)sender
@@ -38,11 +41,12 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSScroller)
}
@end // implementation wxNSScrollerTarget
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSScrollerTarget,NSObject)
// ============================================================================
// class wxCocoaNSScroller
// ============================================================================
const wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSScroller::sm_cocoaTarget = [[wxNSScrollerTarget alloc] init];
const wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSScroller::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSScrollerTarget) alloc] init];
void wxCocoaNSScroller::AssociateNSScroller(WX_NSScroller cocoaNSScroller)
{

View File

@@ -15,6 +15,8 @@
#include "wx/cocoa/NSTabView.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#include <AppKit/NSTabView.h>
// ============================================================================
@@ -27,6 +29,7 @@
- (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem;
- (BOOL)tabView:(NSTabView*)tabView shouldSelectTabViewItem:(NSTabViewItem*)tabViewItem;
@end // interface wxNSTabViewDelegate : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxNSTabViewDelegate,NSObject)
@implementation wxNSTabViewDelegate : NSObject
- (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem
@@ -45,13 +48,14 @@
}
@end // implementation wxNSTabViewDelegate : NSObject
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSTabViewDelegate,NSObject)
// ============================================================================
// class wxCocoaNSTabView
// ============================================================================
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSTabView)
wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSTabView::sm_cocoaDelegate = [[wxNSTabViewDelegate alloc] init];
wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSTabView::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSTabViewDelegate) alloc] init];
void wxCocoaNSTabView::AssociateNSTabView(WX_NSTabView cocoaNSTabView)
{

View File

@@ -53,4 +53,5 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSTableView)
}
@end // implementation wxCocoaNSTableDataSource
WX_IMPLEMENT_GET_OBJC_CLASS(wxCocoaNSTableDataSource,NSObject)

View File

@@ -25,6 +25,8 @@
#include "wx/cocoa/NSWindow.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <Foundation/NSNotification.h>
#import <Foundation/NSString.h>
#include "wx/cocoa/objc/NSWindow.h"
@@ -53,6 +55,7 @@
- (void)wxMenuItemAction: (NSMenuItem *)menuItem;
- (BOOL)validateMenuItem: (NSMenuItem *)menuItem;
@end //interface wxNSWindowDelegate
WX_DECLARE_GET_OBJC_CLASS(wxNSWindowDelegate,NSObject)
@implementation wxNSWindowDelegate : NSObject
@@ -141,6 +144,7 @@
}
@end //implementation wxNSWindowDelegate
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSWindowDelegate,NSObject)
// ============================================================================
// class wxCocoaNSWindow
@@ -151,7 +155,7 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
wxCocoaNSWindow::wxCocoaNSWindow(wxTopLevelWindowCocoa *tlw)
: m_wxTopLevelWindowCocoa(tlw)
{
m_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
m_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSWindowDelegate) alloc] init];
[m_cocoaDelegate setWxCocoaInterface: this];
}

View File

@@ -80,6 +80,8 @@
#include "wx/combobox.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#ifndef WX_PRECOMP
#include "wx/window.h"
#include "wx/log.h"
@@ -132,6 +134,7 @@ void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox)
- (void)comboBoxWillDismiss:(NSNotification *)notification;
- (void)comboBoxWillPopUp:(NSNotification *)notification;
@end // wxPoserNSComboBox
WX_DECLARE_GET_OBJC_CLASS(wxPoserNSComboBox,NSComboBox)
//WX_IMPLEMENT_POSER(wxPoserNSComboBox);
@implementation wxPoserNSComboBox : NSComboBox
@@ -158,6 +161,7 @@ void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox)
}
@end // implementation wxPoserNSComboBox
WX_IMPLEMENT_GET_OBJC_CLASS(wxPoserNSComboBox,NSComboBox)
#include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h"
@@ -198,7 +202,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID winid,
return false;
m_cocoaNSView = NULL;
SetNSComboBox([[wxPoserNSComboBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
SetNSComboBox([[WX_GET_OBJC_CLASS(wxPoserNSComboBox) alloc] initWithFrame:MakeDefaultNSRect(size)]);
[m_cocoaNSView release];
[GetNSTextField() setStringValue:wxNSStringWithWxString(value.c_str())];
[GetNSControl() sizeToFit];

View File

@@ -98,7 +98,7 @@ The listbox contents are sorted in alphabetical order.
[GetNSTableView() setHeaderView: nil];
// Set up the data source
m_cocoaDataSource = [[wxCocoaNSTableDataSource alloc] init];
m_cocoaDataSource = [[WX_GET_OBJC_CLASS(wxCocoaNSTableDataSource) alloc] init];
[GetNSTableView() setDataSource:m_cocoaDataSource];
// Add the single column

View File

@@ -20,6 +20,7 @@
#include "wx/cocoa/mbarman.h"
#include "wx/cocoa/autorelease.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <Foundation/NSString.h>
#import <Foundation/NSNotification.h>
@@ -51,6 +52,7 @@
- (void)windowWillClose: (NSNotification *)notification;
#endif // 0
@end // interface wxMenuBarManagerObserver : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject)
@implementation wxMenuBarManagerObserver : NSObject
- (id)init
@@ -100,6 +102,7 @@
#endif // 0
@end // implementation wxMenuBarManagerObserver : NSObject
WX_IMPLEMENT_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject)
// ============================================================================
// wxMenuBarManager
@@ -108,7 +111,7 @@ wxMenuBarManager *wxMenuBarManager::sm_mbarmanInstance = NULL;
wxMenuBarManager::wxMenuBarManager()
{
m_observer = [[wxMenuBarManagerObserver alloc]
m_observer = [[WX_GET_OBJC_CLASS(wxMenuBarManagerObserver) alloc]
initWithWxMenuBarManager:this];
[[NSNotificationCenter defaultCenter] addObserver:m_observer
selector:@selector(windowDidBecomeKey:)

View File

@@ -15,6 +15,8 @@
#include "wx/mdi.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
#endif // WX_PRECOMP
@@ -44,6 +46,7 @@ WX_DECLARE_HASH_MAP(int, wxMDIChildFrame*, wxIntegerHash, wxIntegerEqual, wxIntM
- (id)initWithWxMDIParentFrame: (wxMDIParentFrame *)mdiParent;
- (void)windowDidBecomeMain: (NSNotification *)notification;
@end // interface wxMDIParentFrameObserver : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxMDIParentFrameObserver,NSObject)
@implementation wxMDIParentFrameObserver : NSObject
- (id)init
@@ -67,6 +70,7 @@ WX_DECLARE_HASH_MAP(int, wxMDIChildFrame*, wxIntegerHash, wxIntegerEqual, wxIntM
}
@end // implementation wxMDIParentFrameObserver : NSObject
WX_IMPLEMENT_GET_OBJC_CLASS(wxMDIParentFrameObserver,NSObject)
// ========================================================================
// wxMDIParentFrame
@@ -79,7 +83,7 @@ void wxMDIParentFrame::Init()
{
m_clientWindow = NULL;
m_currentChild = NULL;
m_observer = [[wxMDIParentFrameObserver alloc]
m_observer = [[WX_GET_OBJC_CLASS(wxMDIParentFrameObserver) alloc]
initWithWxMDIParentFrame:this];
[[NSNotificationCenter defaultCenter] addObserver:m_observer
selector:@selector(windowDidBecomeMain:)

View File

@@ -46,7 +46,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
bool wxMenu::Create(const wxString& title, long style)
{
wxAutoNSAutoreleasePool pool;
m_cocoaNSMenu = [[WXNSMenu alloc] initWithTitle: wxNSStringWithWxString(title)];
m_cocoaNSMenu = [[WX_GET_OBJC_CLASS(WXNSMenu) alloc] initWithTitle: wxNSStringWithWxString(title)];
AssociateNSMenu(m_cocoaNSMenu);
return true;
}

View File

@@ -23,6 +23,8 @@
#include "wx/menuitem.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#ifndef WX_PRECOMP
#include "wx/menu.h"
#include "wx/utils.h"
@@ -53,6 +55,7 @@
- (void)wxMenuItemAction: (id)sender;
- (BOOL)validateMenuItem: (id)menuItem;
@end //interface wxNSMenuItemTarget
WX_DECLARE_GET_OBJC_CLASS(wxNSMenuItemTarget,NSObject)
@implementation wxNSMenuItemTarget : NSObject
@@ -74,6 +77,7 @@
}
@end //implementation wxNSMenuItemTarget
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSMenuItemTarget,NSObject)
// ============================================================================
// wxMenuItemCocoa implementation
@@ -81,7 +85,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
wxObjcAutoRefFromAlloc<struct objc_object *> wxMenuItemCocoa::sm_cocoaTarget = [[wxNSMenuItemTarget alloc] init];
wxObjcAutoRefFromAlloc<struct objc_object *> wxMenuItemCocoa::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSMenuItemTarget) alloc] init];
// ----------------------------------------------------------------------------
// wxMenuItemBase

View File

@@ -21,6 +21,7 @@
#include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <AppKit/NSTabView.h>
#import <AppKit/NSTabViewItem.h>
@@ -48,6 +49,7 @@
- (NSImage*)image;
- (void)setImage:(NSImage*)image;
@end // interface WXCTabViewImageItem : NSTabViewItem
WX_DECLARE_GET_OBJC_CLASS(WXCTabViewImageItem,NSTabViewItem)
@implementation WXCTabViewImageItem : NSTabViewItem
- (id)init
@@ -120,6 +122,7 @@
}
@end // implementation WXCTabViewImageItem : NSTabViewItem
WX_IMPLEMENT_GET_OBJC_CLASS(WXCTabViewImageItem,NSTabViewItem)
// ========================================================================
// wxNotebookEvent
@@ -218,7 +221,7 @@ bool wxNotebook::InsertPage( size_t pos,
{
wxAutoNSAutoreleasePool pool;
m_pages.Insert(page,pos);
NSTabViewItem *tvitem = [[WXCTabViewImageItem alloc] initWithIdentifier:nil];
NSTabViewItem *tvitem = [[WX_GET_OBJC_CLASS(WXCTabViewImageItem) alloc] initWithIdentifier:nil];
[tvitem setLabel: wxNSStringWithWxString(title)];
const wxBitmap *bmp = (imageId!=-1)?m_imageList->GetBitmapPtr(imageId):NULL;
if(bmp)

View File

@@ -23,6 +23,8 @@
#include "wx/cocoa/string.h"
#include "wx/cocoa/log.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <AppKit/NSSound.h>
#import <Foundation/NSData.h>
@@ -39,6 +41,7 @@ static bool s_loopCurrentSound = false;
// Delegate methods
- (void)sound:(NSSound *)theSound didFinishPlaying:(BOOL)finishedPlaying;
@end // interface wxNSSoundDelegate : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxNSSoundDelegate,NSObject)
@implementation wxNSSoundDelegate : NSObject
@@ -66,8 +69,9 @@ static bool s_loopCurrentSound = false;
}
@end // wxNSSoundDelegate
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSSoundDelegate,NSObject)
const wxObjcAutoRefFromAlloc<struct objc_object*> wxSound::sm_cocoaDelegate = [[wxNSSoundDelegate alloc] init];
const wxObjcAutoRefFromAlloc<struct objc_object*> wxSound::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSSoundDelegate) alloc] init];
// ------------------------------------------------------------------
// wxSound

View File

@@ -25,6 +25,8 @@
#include "wx/cocoa/private/timer.h"
#include "wx/cocoa/autorelease.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <Foundation/NSTimer.h>
// ========================================================================
@@ -40,6 +42,7 @@
- (wxCocoaTimerImpl*)timer;
- (void)onNotify:(NSTimer *)theTimer;
@end // interface wxNSTimerData : NSObject
WX_DECLARE_GET_OBJC_CLASS(wxNSTimerData,NSObject)
@implementation wxNSTimerData : NSObject
- (id)init
@@ -68,6 +71,7 @@
m_timer->Notify();
}
@end
WX_IMPLEMENT_GET_OBJC_CLASS(wxNSTimerData,NSObject)
// ----------------------------------------------------------------------------
// wxCocoaTimerImpl
@@ -89,7 +93,7 @@ bool wxCocoaTimerImpl::Start(int millisecs, bool oneShot)
wxAutoNSAutoreleasePool thePool;
wxNSTimerData *timerData = [[wxNSTimerData alloc] initWithWxTimer:this];
wxNSTimerData *timerData = [[WX_GET_OBJC_CLASS(wxNSTimerData) alloc] initWithWxTimer:this];
m_cocoaNSTimer = [[NSTimer
scheduledTimerWithTimeInterval: millisecs / 1000.0 //seconds
target: timerData

View File

@@ -31,6 +31,8 @@
#include "wx/cocoa/string.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
#import <Foundation/Foundation.h>
#import <AppKit/NSWorkspace.h>
@@ -104,6 +106,7 @@ protected:
-(id)init:(void*)handle processIdentifier:(long)pid;
- (void)termHandler:(NSNotification *)aNotification;
@end
WX_DECLARE_GET_OBJC_CLASS(wxTaskHandler,NSObject)
@implementation wxTaskHandler : NSObject
@@ -135,6 +138,7 @@ protected:
}
@end
WX_IMPLEMENT_GET_OBJC_CLASS(wxTaskHandler,NSObject)
long wxExecute(const wxString& command,
int sync,
@@ -179,7 +183,7 @@ long wxExecute(const wxString& command,
if(sync & wxEXEC_ASYNC)
{
[[wxTaskHandler alloc]init:handle
[[WX_GET_OBJC_CLASS(wxTaskHandler) alloc]init:handle
processIdentifier:[theTask processIdentifier]];
return 0;