From: David Elliott Date: Wed, 15 Aug 2007 16:10:19 +0000 (+0000) Subject: Add support for uniquifying to all wxCocoa Objective-C classes. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e7e1ad7d93cdba76983c43d7e0289a00be5a935c?hp=3ac1094bead05e30462122d00e4859725d2ea59f 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 --- diff --git a/include/wx/cocoa/NSTableDataSource.h b/include/wx/cocoa/NSTableDataSource.h index c9c687fe1e..754b859197 100644 --- a/include/wx/cocoa/NSTableDataSource.h +++ b/include/wx/cocoa/NSTableDataSource.h @@ -12,6 +12,8 @@ #ifndef __WX_COCOA_NSTABLEDATASOURCE_H__ #define __WX_COCOA_NSTABLEDATASOURCE_H__ +#include "wx/cocoa/objc/objc_uniquifying.h" + #import // ============================================================================ @@ -28,5 +30,6 @@ objectValueForTableColumn: (NSTableColumn *)tableColumn row: (int)rowIndex; @end // wxCocoaNSTableDataSource +WX_DECLARE_GET_OBJC_CLASS(wxCocoaNSTableDataSource,NSObject) #endif // _WX_COCOA_NSTABLEDATASOURCE_H_ diff --git a/include/wx/cocoa/objc/NSMenu.h b/include/wx/cocoa/objc/NSMenu.h index f9211ddfb0..10807c2db7 100644 --- a/include/wx/cocoa/objc/NSMenu.h +++ b/include/wx/cocoa/objc/NSMenu.h @@ -12,6 +12,8 @@ #ifndef __WX_COCOA_OBJC_NSMENU_H__ #define __WX_COCOA_OBJC_NSMENU_H__ +#include "wx/cocoa/objc/objc_uniquifying.h" + #import // ============================================================================ @@ -24,5 +26,6 @@ - (void)dealloc; @end // WXNSMenu +WX_DECLARE_GET_OBJC_CLASS(WXNSMenu,NSMenu) #endif //ndef __WX_COCOA_OBJC_NSMENU_H__ diff --git a/src/cocoa/NSMenu.mm b/src/cocoa/NSMenu.mm index 819cc1f136..635b2ee96e 100644 --- a/src/cocoa/NSMenu.mm +++ b/src/cocoa/NSMenu.mm @@ -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) diff --git a/src/cocoa/NSScroller.mm b/src/cocoa/NSScroller.mm index 20c9b9d3a8..356391e276 100644 --- a/src/cocoa/NSScroller.mm +++ b/src/cocoa/NSScroller.mm @@ -14,6 +14,8 @@ #include "wx/log.h" #endif // WX_PRECOMP +#include "wx/cocoa/objc/objc_uniquifying.h" + #include "wx/cocoa/NSScroller.h" #import @@ -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 wxCocoaNSScroller::sm_cocoaTarget = [[wxNSScrollerTarget alloc] init]; +const wxObjcAutoRefFromAlloc wxCocoaNSScroller::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSScrollerTarget) alloc] init]; void wxCocoaNSScroller::AssociateNSScroller(WX_NSScroller cocoaNSScroller) { diff --git a/src/cocoa/NSTabView.mm b/src/cocoa/NSTabView.mm index 32a5751196..3d48af6ec0 100644 --- a/src/cocoa/NSTabView.mm +++ b/src/cocoa/NSTabView.mm @@ -15,6 +15,8 @@ #include "wx/cocoa/NSTabView.h" +#include "wx/cocoa/objc/objc_uniquifying.h" + #include // ============================================================================ @@ -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 wxCocoaNSTabView::sm_cocoaDelegate = [[wxNSTabViewDelegate alloc] init]; +wxObjcAutoRefFromAlloc wxCocoaNSTabView::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSTabViewDelegate) alloc] init]; void wxCocoaNSTabView::AssociateNSTabView(WX_NSTabView cocoaNSTabView) { diff --git a/src/cocoa/NSTableView.mm b/src/cocoa/NSTableView.mm index 43d43aabeb..c4b19102bc 100644 --- a/src/cocoa/NSTableView.mm +++ b/src/cocoa/NSTableView.mm @@ -53,4 +53,5 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSTableView) } @end // implementation wxCocoaNSTableDataSource +WX_IMPLEMENT_GET_OBJC_CLASS(wxCocoaNSTableDataSource,NSObject) diff --git a/src/cocoa/NSWindow.mm b/src/cocoa/NSWindow.mm index a9e3f7b58d..9bd527fb46 100644 --- a/src/cocoa/NSWindow.mm +++ b/src/cocoa/NSWindow.mm @@ -25,6 +25,8 @@ #include "wx/cocoa/NSWindow.h" +#include "wx/cocoa/objc/objc_uniquifying.h" + #import #import #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]; } diff --git a/src/cocoa/combobox.mm b/src/cocoa/combobox.mm index 041fd382c5..9986273c6a 100644 --- a/src/cocoa/combobox.mm +++ b/src/cocoa/combobox.mm @@ -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]; diff --git a/src/cocoa/listbox.mm b/src/cocoa/listbox.mm index 1b9a228a34..08603883be 100644 --- a/src/cocoa/listbox.mm +++ b/src/cocoa/listbox.mm @@ -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 diff --git a/src/cocoa/mbarman.mm b/src/cocoa/mbarman.mm index 81930b9135..74694bffdc 100644 --- a/src/cocoa/mbarman.mm +++ b/src/cocoa/mbarman.mm @@ -20,6 +20,7 @@ #include "wx/cocoa/mbarman.h" #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/objc/objc_uniquifying.h" #import #import @@ -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:) diff --git a/src/cocoa/mdi.mm b/src/cocoa/mdi.mm index 63e1bfd0e0..a0c8022306 100644 --- a/src/cocoa/mdi.mm +++ b/src/cocoa/mdi.mm @@ -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:) diff --git a/src/cocoa/menu.mm b/src/cocoa/menu.mm index df0e8612aa..4ec5859993 100644 --- a/src/cocoa/menu.mm +++ b/src/cocoa/menu.mm @@ -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; } diff --git a/src/cocoa/menuitem.mm b/src/cocoa/menuitem.mm index 81ccdd73a3..d6f542e13c 100644 --- a/src/cocoa/menuitem.mm +++ b/src/cocoa/menuitem.mm @@ -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 wxMenuItemCocoa::sm_cocoaTarget = [[wxNSMenuItemTarget alloc] init]; +wxObjcAutoRefFromAlloc wxMenuItemCocoa::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSMenuItemTarget) alloc] init]; // ---------------------------------------------------------------------------- // wxMenuItemBase diff --git a/src/cocoa/notebook.mm b/src/cocoa/notebook.mm index a4f535f2b8..7c7d648541 100644 --- a/src/cocoa/notebook.mm +++ b/src/cocoa/notebook.mm @@ -21,6 +21,7 @@ #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" +#include "wx/cocoa/objc/objc_uniquifying.h" #import #import @@ -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) diff --git a/src/cocoa/sound.mm b/src/cocoa/sound.mm index dbafe8f5f6..b41f82dda9 100644 --- a/src/cocoa/sound.mm +++ b/src/cocoa/sound.mm @@ -23,6 +23,8 @@ #include "wx/cocoa/string.h" #include "wx/cocoa/log.h" +#include "wx/cocoa/objc/objc_uniquifying.h" + #import #import @@ -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 wxSound::sm_cocoaDelegate = [[wxNSSoundDelegate alloc] init]; +const wxObjcAutoRefFromAlloc wxSound::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSSoundDelegate) alloc] init]; // ------------------------------------------------------------------ // wxSound diff --git a/src/cocoa/timer.mm b/src/cocoa/timer.mm index ebcae18430..259011013d 100644 --- a/src/cocoa/timer.mm +++ b/src/cocoa/timer.mm @@ -25,6 +25,8 @@ #include "wx/cocoa/private/timer.h" #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/objc/objc_uniquifying.h" + #import // ======================================================================== @@ -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 diff --git a/src/cocoa/utilsexc.mm b/src/cocoa/utilsexc.mm index 348c1c1060..398834798f 100644 --- a/src/cocoa/utilsexc.mm +++ b/src/cocoa/utilsexc.mm @@ -31,6 +31,8 @@ #include "wx/cocoa/string.h" +#include "wx/cocoa/objc/objc_uniquifying.h" + #import #import @@ -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;