]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/ObjcPose.h
Fix wxMotif build.
[wxWidgets.git] / include / wx / cocoa / ObjcPose.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/ObjcPose.h
3 // Purpose: Macros for initializing poseAs, among other things
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2002/12/03
7 // RCS-ID: $Id:
8 // Copyright: (c) 2002 David Elliott <dfe@cox.net>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WX_COCOA_PRIVATE_POSER_H__
13 #define __WX_COCOA_PRIVATE_POSER_H__
14
15 /*-------------------------------------------------------------------------
16 Objective-C Poser class initialization
17 -------------------------------------------------------------------------*/
18 #ifdef __OBJC__
19 #import <objc/objc-class.h>
20
21 class wxPoseAsInitializer
22 {
23 public:
24 wxPoseAsInitializer(Class poser)
25 : m_poser(poser)
26 , m_next(sm_first)
27 {
28 sm_first = this;
29 }
30 ~wxPoseAsInitializer()
31 {
32 class_poseAs(m_poser,m_poser->super_class);
33 sm_first = m_next;
34 }
35 static void InitializePosers()
36 {
37 while(sm_first)
38 {
39 delete sm_first;
40 }
41 };
42 protected:
43 Class m_poser;
44 wxPoseAsInitializer *m_next;
45 static wxPoseAsInitializer *sm_first;
46 };
47
48 class wxDummyForPoseAsInitializer
49 {
50 public:
51 wxDummyForPoseAsInitializer(void*) {}
52 };
53
54 #define WX_IMPLEMENT_POSER(poser) \
55 wxDummyForPoseAsInitializer wxDummyPoseAsInitializerFor##poser(new wxPoseAsInitializer([poser class]))
56
57 #endif // __OBJC__
58
59 /*-------------------------------------------------------------------------
60 Basic hashmap stuff, used by everything
61 -------------------------------------------------------------------------*/
62 #define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \
63 class wxCocoa##ObjcClass; \
64 WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash)
65
66 #define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
67 public: \
68 static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \
69 { \
70 wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \
71 if(iter!=sm_cocoaHash.end()) \
72 { \
73 return iter->second; \
74 } \
75 return NULL; \
76 } \
77 protected: \
78 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
79
80 #define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
81 wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
82
83
84 /*-------------------------------------------------------------------------
85 The entire interface, including some boilerplate stuff
86 -------------------------------------------------------------------------*/
87 #define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
88 WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
89 public: \
90 inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
91 { \
92 sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
93 } \
94 inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
95 { \
96 sm_cocoaHash.erase(cocoaObjcClass); \
97 }
98
99 #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
100 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
101
102 /*-------------------------------------------------------------------------
103 Stuff to be used by the wxWindows class (not the Cocoa interface)
104 -------------------------------------------------------------------------*/
105 #define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
106 public: \
107 inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
108 inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
109 protected: \
110 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
111
112 #define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
113 void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
114 { \
115 if(m_cocoa##ObjcRoot) \
116 Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
117 Set##ObjcBase(cocoaObjcClass); \
118 if(m_cocoa##ObjcRoot) \
119 Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
120 }
121
122 #endif // __WX_COCOA_PRIVATE_POSER_H__
123