]>
Commit | Line | Data |
---|---|---|
e6686511 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/cocoa/ObjcAssociate.h | |
3 | // Purpose: Associates an Objective-C class with a C++ class | |
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_OBJC_ASSOCIATE_H__ | |
13 | #define __WX_COCOA_OBJC_ASSOCIATE_H__ | |
14 | ||
15 | /*------------------------------------------------------------------------- | |
16 | Basic hashmap stuff, used by everything | |
17 | -------------------------------------------------------------------------*/ | |
18 | #define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \ | |
19 | class wxCocoa##ObjcClass; \ | |
20 | WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash) | |
21 | ||
22 | #define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \ | |
23 | public: \ | |
24 | static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \ | |
25 | { \ | |
26 | wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \ | |
27 | if(iter!=sm_cocoaHash.end()) \ | |
28 | { \ | |
29 | return iter->second; \ | |
30 | } \ | |
31 | return NULL; \ | |
32 | } \ | |
33 | protected: \ | |
34 | static wxCocoa##ObjcClass##Hash sm_cocoaHash; | |
35 | ||
36 | #define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \ | |
37 | wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash; | |
38 | ||
39 | ||
40 | /*------------------------------------------------------------------------- | |
41 | The entire interface, including some boilerplate stuff | |
42 | -------------------------------------------------------------------------*/ | |
43 | #define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \ | |
44 | WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \ | |
45 | public: \ | |
46 | inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ | |
47 | { \ | |
bac6f234 DE |
48 | if(cocoaObjcClass) \ |
49 | sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \ | |
e6686511 DE |
50 | } \ |
51 | inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ | |
52 | { \ | |
bac6f234 DE |
53 | if(cocoaObjcClass) \ |
54 | sm_cocoaHash.erase(cocoaObjcClass); \ | |
e6686511 DE |
55 | } |
56 | ||
57 | #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \ | |
58 | WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) | |
59 | ||
60 | /*------------------------------------------------------------------------- | |
61 | Stuff to be used by the wxWindows class (not the Cocoa interface) | |
62 | -------------------------------------------------------------------------*/ | |
63 | #define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \ | |
64 | public: \ | |
65 | inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \ | |
66 | inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \ | |
67 | protected: \ | |
68 | void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass); | |
69 | ||
70 | #define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \ | |
71 | void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ | |
72 | { \ | |
bac6f234 | 73 | Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \ |
e6686511 | 74 | Set##ObjcBase(cocoaObjcClass); \ |
bac6f234 | 75 | Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \ |
e6686511 DE |
76 | } |
77 | ||
78 | #endif // __WX_COCOA_OBJC_ASSOCIATE_H__ | |
79 |