]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/ObjcAssociate.h
Include some more declarations & defines.
[wxWidgets.git] / include / wx / cocoa / ObjcAssociate.h
CommitLineData
e6686511
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/cocoa/ObjcAssociate.h
3// Purpose: Associates an Objective-C class with a C++ class
4// Author: David Elliott
1c4e8f38 5// Modified by:
e6686511 6// Created: 2002/12/03
1c4e8f38 7// RCS-ID: $Id$
e6686511 8// Copyright: (c) 2002 David Elliott <dfe@cox.net>
65571936 9// Licence: wxWindows licence
e6686511
DE
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __WX_COCOA_OBJC_ASSOCIATE_H__
13#define __WX_COCOA_OBJC_ASSOCIATE_H__
14
15/*-------------------------------------------------------------------------
16Basic hashmap stuff, used by everything
17-------------------------------------------------------------------------*/
18#define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \
19class wxCocoa##ObjcClass; \
20WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash)
21
22#define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
23public: \
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 } \
33protected: \
34 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
35
36#define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
37wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
38
39
40/*-------------------------------------------------------------------------
41The entire interface, including some boilerplate stuff
42-------------------------------------------------------------------------*/
43#define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
44WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
45public: \
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) \
58WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
59
60/*-------------------------------------------------------------------------
77ffb593 61Stuff to be used by the wxWidgets class (not the Cocoa interface)
e6686511
DE
62-------------------------------------------------------------------------*/
63#define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
64public: \
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; } \
67protected: \
68 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
69
70#define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
71void 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__