1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/ObjcPose.h
3 // Purpose: Macros for initializing poseAs, among other things
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott <dfe@cox.net>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_PRIVATE_POSER_H__
13 #define __WX_COCOA_PRIVATE_POSER_H__
15 /*-------------------------------------------------------------------------
16 Objective-C Poser class initialization
17 -------------------------------------------------------------------------*/
19 #import <objc/objc-class.h>
21 class wxPoseAsInitializer
24 wxPoseAsInitializer(Class poser
)
30 ~wxPoseAsInitializer()
32 class_poseAs(m_poser
,m_poser
->super_class
);
35 static void InitializePosers()
44 wxPoseAsInitializer
*m_next
;
45 static wxPoseAsInitializer
*sm_first
;
48 class wxDummyForPoseAsInitializer
51 wxDummyForPoseAsInitializer(void*) {}
54 #define WX_IMPLEMENT_POSER(poser) \
55 wxDummyForPoseAsInitializer wxDummyPoseAsInitializerFor##poser(new wxPoseAsInitializer([poser class]))
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)
66 #define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
68 static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \
70 wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \
71 if(iter!=sm_cocoaHash.end()) \
73 return iter->second; \
78 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
80 #define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
81 wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
84 /*-------------------------------------------------------------------------
85 The entire interface, including some boilerplate stuff
86 -------------------------------------------------------------------------*/
87 #define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
88 WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
90 inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
92 sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
94 inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
96 sm_cocoaHash.erase(cocoaObjcClass); \
99 #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
100 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
102 /*-------------------------------------------------------------------------
103 Stuff to be used by the wxWindows class (not the Cocoa interface)
104 -------------------------------------------------------------------------*/
105 #define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
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; } \
110 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
112 #define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
113 void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
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); \
122 #endif // __WX_COCOA_PRIVATE_POSER_H__