]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/ObjcPose.h
Added original works and stubs to CVS repository
[wxWidgets.git] / include / wx / cocoa / ObjcPose.h
CommitLineData
fb896a32
DE
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/*-------------------------------------------------------------------------
16Objective-C Poser class initialization
17-------------------------------------------------------------------------*/
18#ifdef __OBJC__
19#import <objc/objc-class.h>
20
21class wxPoseAsInitializer
22{
23public:
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 };
42protected:
43 Class m_poser;
44 wxPoseAsInitializer *m_next;
45 static wxPoseAsInitializer *sm_first;
46};
47
48class wxDummyForPoseAsInitializer
49{
50public:
51 wxDummyForPoseAsInitializer(void*) {}
52};
53
54#define WX_IMPLEMENT_POSER(poser) \
55wxDummyForPoseAsInitializer wxDummyPoseAsInitializerFor##poser(new wxPoseAsInitializer([poser class]))
56
57#endif // __OBJC__
58
59/*-------------------------------------------------------------------------
60Basic hashmap stuff, used by everything
61-------------------------------------------------------------------------*/
62#define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \
63class wxCocoa##ObjcClass; \
64WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash)
65
66#define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
67public: \
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 } \
77protected: \
78 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
79
80#define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
81wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
82
83
84/*-------------------------------------------------------------------------
85The entire interface, including some boilerplate stuff
86-------------------------------------------------------------------------*/
87#define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
88WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
89public: \
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) \
100WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
101
102/*-------------------------------------------------------------------------
103Stuff to be used by the wxWindows class (not the Cocoa interface)
104-------------------------------------------------------------------------*/
105#define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
106public: \
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; } \
109protected: \
110 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
111
112#define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
113void 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