1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/NSTabView.mm
3 // Purpose: wxCocoaNSTabView
4 // Author: David Elliott
7 // Copyright: (c) 2004 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/cocoa/NSTabView.h"
17 #include "wx/cocoa/objc/objc_uniquifying.h"
19 #include <AppKit/NSTabView.h>
21 // ============================================================================
22 // @class wxNSTabViewDelegate
23 // ============================================================================
24 @interface wxNSTabViewDelegate : NSObject
28 - (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem;
29 - (BOOL)tabView:(NSTabView*)tabView shouldSelectTabViewItem:(NSTabViewItem*)tabViewItem;
30 @end // interface wxNSTabViewDelegate : NSObject
31 WX_DECLARE_GET_OBJC_CLASS(wxNSTabViewDelegate,NSObject)
33 @implementation wxNSTabViewDelegate : NSObject
34 - (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem
36 wxCocoaNSTabView *notebook = wxCocoaNSTabView::GetFromCocoa(tabView);
37 wxCHECK_RET(notebook, wxT("This delegate is for use only with wxCocoa NSTabViews"));
38 notebook->CocoaDelegate_tabView_didSelectTabViewItem(tabViewItem);
42 - (BOOL)tabView:(NSTabView*)tabView shouldSelectTabViewItem:(NSTabViewItem*)tabViewItem
44 wxCocoaNSTabView *notebook = wxCocoaNSTabView::GetFromCocoa(tabView);
45 wxCHECK_MSG(notebook, true, wxT("This delegate is for use only with wxCocoa NSTabViews"));
46 return notebook->CocoaDelegate_tabView_shouldSelectTabViewItem(tabViewItem);
49 @end // implementation wxNSTabViewDelegate : NSObject
50 WX_IMPLEMENT_GET_OBJC_CLASS(wxNSTabViewDelegate,NSObject)
52 // ============================================================================
53 // class wxCocoaNSTabView
54 // ============================================================================
55 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSTabView)
57 wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSTabView::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSTabViewDelegate) alloc] init];
59 void wxCocoaNSTabView::AssociateNSTabView(WX_NSTabView cocoaNSTabView)
63 sm_cocoaHash.insert(wxCocoaNSTabViewHash::value_type(cocoaNSTabView,this));
64 [cocoaNSTabView setDelegate: sm_cocoaDelegate];
68 void wxCocoaNSTabView::DisassociateNSTabView(WX_NSTabView cocoaNSTabView)
72 [cocoaNSTabView setDelegate: nil];
73 sm_cocoaHash.erase(cocoaNSTabView);