1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: A mixin class for holding a wxClientData or void pointer
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CLNTDATAH__
12 #define _WX_CLNTDATAH__
15 #include "wx/string.h"
16 #include "wx/hashmap.h"
18 typedef int (*wxShadowObjectMethod
)(void*, void*);
19 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(
21 wxShadowObjectMethods
,
22 class WXDLLIMPEXP_BASE
24 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(
27 class WXDLLIMPEXP_BASE
30 class WXDLLIMPEXP_BASE wxShadowObject
35 void AddMethod( const wxString
&name
, wxShadowObjectMethod method
)
37 wxShadowObjectMethods::iterator it
= m_methods
.find( name
);
38 if (it
== m_methods
.end())
39 m_methods
[ name
] = method
;
44 bool InvokeMethod( const wxString
&name
, void* window
, void* param
, int* returnValue
)
46 wxShadowObjectMethods::iterator it
= m_methods
.find( name
);
47 if (it
== m_methods
.end())
49 wxShadowObjectMethod method
= it
->second
;
50 int ret
= (*method
)(window
, param
);
56 void AddField( const wxString
&name
, void* initialValue
= NULL
)
58 wxShadowObjectFields::iterator it
= m_fields
.find( name
);
59 if (it
== m_fields
.end())
60 m_fields
[ name
] = initialValue
;
62 it
->second
= initialValue
;
65 void SetField( const wxString
&name
, void* value
)
67 wxShadowObjectFields::iterator it
= m_fields
.find( name
);
68 if (it
== m_fields
.end())
73 void* GetField( const wxString
&name
, void *defaultValue
= NULL
)
75 wxShadowObjectFields::iterator it
= m_fields
.find( name
);
76 if (it
== m_fields
.end())
82 wxShadowObjectMethods m_methods
;
83 wxShadowObjectFields m_fields
;
87 // ----------------------------------------------------------------------------
89 // what kind of client data do we have?
92 wxClientData_None
, // we don't know yet because we don't have it at all
93 wxClientData_Object
, // our client data is typed and we own it
94 wxClientData_Void
// client data is untyped and we don't own it
97 class WXDLLIMPEXP_BASE wxClientData
101 virtual ~wxClientData() { }
104 class WXDLLIMPEXP_BASE wxStringClientData
: public wxClientData
107 wxStringClientData() : m_data() { }
108 wxStringClientData( const wxString
&data
) : m_data(data
) { }
109 void SetData( const wxString
&data
) { m_data
= data
; }
110 const wxString
& GetData() const { return m_data
; }
116 // This class is a mixin that provides storage and management of "client
117 // data." The client data stored can either be a pointer to a wxClientData
118 // object in which case it is managed by the container (i.e. it will delete
119 // the data when it's destroyed) or an untyped pointer which won't be deleted
120 // by the container - but not both of them
122 // NOTE: This functionality is currently duplicated in wxEvtHandler in order
123 // to avoid having more than one vtable in that class hierarchy.
125 class WXDLLIMPEXP_BASE wxClientDataContainer
128 wxClientDataContainer();
129 virtual ~wxClientDataContainer();
131 void SetClientObject( wxClientData
*data
) { DoSetClientObject(data
); }
132 wxClientData
*GetClientObject() const { return DoGetClientObject(); }
134 void SetClientData( void *data
) { DoSetClientData(data
); }
135 void *GetClientData() const { return DoGetClientData(); }
138 // The user data: either an object which will be deleted by the container
139 // when it's deleted or some raw pointer which we do nothing with. Only
140 // one type of data can be used with the given window, i.e. you cannot set
141 // the void data and then associate the container with wxClientData or vice
145 wxClientData
*m_clientObject
;
149 // client data accessors
150 virtual void DoSetClientObject( wxClientData
*data
);
151 virtual wxClientData
*DoGetClientObject() const;
153 virtual void DoSetClientData( void *data
);
154 virtual void *DoGetClientData() const;
156 // what kind of data do we have?
157 wxClientDataType m_clientDataType
;
161 #endif // _WX_CLNTDATAH__