]>
Commit | Line | Data |
---|---|---|
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 | // Copyright: (c) 2002 David Elliott <dfe@cox.net> | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef __WX_COCOA_OBJC_ASSOCIATE_H__ | |
12 | #define __WX_COCOA_OBJC_ASSOCIATE_H__ | |
13 | ||
14 | /*------------------------------------------------------------------------- | |
15 | Basic hashmap stuff, used by everything | |
16 | -------------------------------------------------------------------------*/ | |
17 | #define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \ | |
18 | class wxCocoa##ObjcClass; \ | |
19 | WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash) | |
20 | ||
21 | #define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \ | |
22 | public: \ | |
23 | static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \ | |
24 | { \ | |
25 | wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \ | |
26 | if(iter!=sm_cocoaHash.end()) \ | |
27 | { \ | |
28 | return iter->second; \ | |
29 | } \ | |
30 | return NULL; \ | |
31 | } \ | |
32 | protected: \ | |
33 | static wxCocoa##ObjcClass##Hash sm_cocoaHash; | |
34 | ||
35 | #define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \ | |
36 | wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash; | |
37 | ||
38 | ||
39 | /*------------------------------------------------------------------------- | |
40 | The entire interface, including some boilerplate stuff | |
41 | -------------------------------------------------------------------------*/ | |
42 | #define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \ | |
43 | WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \ | |
44 | public: \ | |
45 | inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ | |
46 | { \ | |
47 | if(cocoaObjcClass) \ | |
48 | sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \ | |
49 | } \ | |
50 | inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ | |
51 | { \ | |
52 | if(cocoaObjcClass) \ | |
53 | sm_cocoaHash.erase(cocoaObjcClass); \ | |
54 | } | |
55 | ||
56 | #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \ | |
57 | WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) | |
58 | ||
59 | /*------------------------------------------------------------------------- | |
60 | Stuff to be used by the wxWidgets class (not the Cocoa interface) | |
61 | -------------------------------------------------------------------------*/ | |
62 | #define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \ | |
63 | public: \ | |
64 | inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \ | |
65 | inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \ | |
66 | protected: \ | |
67 | void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass); | |
68 | ||
69 | #define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \ | |
70 | void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ | |
71 | { \ | |
72 | Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \ | |
73 | Set##ObjcBase(cocoaObjcClass); \ | |
74 | Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \ | |
75 | } | |
76 | ||
77 | #endif // __WX_COCOA_OBJC_ASSOCIATE_H__ |