]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/ObjcAssociate.h
(blindly) fixed header case confusion (replacement for patch 763760)
[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
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/*-------------------------------------------------------------------------
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 { \
48 sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
49 } \
50 inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
51 { \
52 sm_cocoaHash.erase(cocoaObjcClass); \
53 }
54
55#define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
56WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
57
58/*-------------------------------------------------------------------------
59Stuff to be used by the wxWindows class (not the Cocoa interface)
60-------------------------------------------------------------------------*/
61#define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
62public: \
63 inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
64 inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
65protected: \
66 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
67
68#define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
69void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
70{ \
71 if(m_cocoa##ObjcRoot) \
72 Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
73 Set##ObjcBase(cocoaObjcClass); \
74 if(m_cocoa##ObjcRoot) \
75 Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
76}
77
78#endif // __WX_COCOA_OBJC_ASSOCIATE_H__
79