]> git.saurik.com Git - wxWidgets.git/blame - include/wx/clntdata.h
Comment-only update
[wxWidgets.git] / include / wx / clntdata.h
CommitLineData
88a9f974
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/clntdata.h
3// Purpose: A mixin class for holding a wxClientData or void pointer
4// Author: Robin Dunn
5// Modified by:
6// Created: 9-Oct-2001
77ffb593 7// Copyright: (c) wxWidgets team
65571936 8// Licence: wxWindows licence
88a9f974
RD
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_CLNTDATAH__
12#define _WX_CLNTDATAH__
13
88a9f974 14#include "wx/defs.h"
16d38102 15#include "wx/string.h"
619f45aa
RR
16#include "wx/hashmap.h"
17
18typedef int (*wxShadowObjectMethod)(void*, void*);
0a64bfdf
VZ
19WX_DECLARE_STRING_HASH_MAP_WITH_DECL(
20 wxShadowObjectMethod,
21 wxShadowObjectMethods,
22 class WXDLLIMPEXP_BASE
3f5c62f9 23);
0a64bfdf
VZ
24WX_DECLARE_STRING_HASH_MAP_WITH_DECL(
25 void *,
26 wxShadowObjectFields,
27 class WXDLLIMPEXP_BASE
3f5c62f9 28);
619f45aa
RR
29
30class WXDLLIMPEXP_BASE wxShadowObject
31{
32public:
33 wxShadowObject() { }
84006e65 34
619f45aa 35 void AddMethod( const wxString &name, wxShadowObjectMethod method )
84006e65 36 {
619f45aa
RR
37 wxShadowObjectMethods::iterator it = m_methods.find( name );
38 if (it == m_methods.end())
39 m_methods[ name ] = method;
40 else
41 it->second = method;
42 }
84006e65 43
619f45aa 44 bool InvokeMethod( const wxString &name, void* window, void* param, int* returnValue )
84006e65 45 {
619f45aa
RR
46 wxShadowObjectMethods::iterator it = m_methods.find( name );
47 if (it == m_methods.end())
48 return false;
49 wxShadowObjectMethod method = it->second;
50 int ret = (*method)(window, param);
51 if (returnValue)
52 *returnValue = ret;
53 return true;
54 }
84006e65 55
619f45aa
RR
56 void AddField( const wxString &name, void* initialValue = NULL )
57 {
58 wxShadowObjectFields::iterator it = m_fields.find( name );
59 if (it == m_fields.end())
60 m_fields[ name ] = initialValue;
61 else
62 it->second = initialValue;
63 }
84006e65 64
619f45aa
RR
65 void SetField( const wxString &name, void* value )
66 {
67 wxShadowObjectFields::iterator it = m_fields.find( name );
68 if (it == m_fields.end())
69 return;
70 it->second = value;
71 }
84006e65 72
619f45aa
RR
73 void* GetField( const wxString &name, void *defaultValue = NULL )
74 {
75 wxShadowObjectFields::iterator it = m_fields.find( name );
76 if (it == m_fields.end())
77 return defaultValue;
78 return it->second;
79 }
84006e65 80
619f45aa
RR
81private:
82 wxShadowObjectMethods m_methods;
83 wxShadowObjectFields m_fields;
84};
88a9f974 85
6900d12d 86
88a9f974
RD
87// ----------------------------------------------------------------------------
88
89// what kind of client data do we have?
90enum wxClientDataType
91{
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
95};
96
6b91e252 97class WXDLLIMPEXP_BASE wxClientData
88a9f974
RD
98{
99public:
100 wxClientData() { }
101 virtual ~wxClientData() { }
102};
103
6b91e252 104class WXDLLIMPEXP_BASE wxStringClientData : public wxClientData
88a9f974
RD
105{
106public:
d84afea9 107 wxStringClientData() : m_data() { }
88a9f974
RD
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; }
111
112private:
113 wxString m_data;
114};
115
16d38102
RD
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
ae500232 118// object in which case it is managed by the container (i.e. it will delete
16d38102 119// the data when it's destroyed) or an untyped pointer which won't be deleted
2aab8f16
RD
120// by the container - but not both of them
121//
122// NOTE: This functionality is currently duplicated in wxEvtHandler in order
ae500232 123// to avoid having more than one vtable in that class hierarchy.
16d38102 124
6b91e252 125class WXDLLIMPEXP_BASE wxClientDataContainer
88a9f974
RD
126{
127public:
128 wxClientDataContainer();
16d38102 129 virtual ~wxClientDataContainer();
88a9f974 130
88a9f974
RD
131 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
132 wxClientData *GetClientObject() const { return DoGetClientObject(); }
133
134 void SetClientData( void *data ) { DoSetClientData(data); }
135 void *GetClientData() const { return DoGetClientData(); }
136
137protected:
16d38102 138 // The user data: either an object which will be deleted by the container
ae500232
JS
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
b88c44e7 141 // the void data and then associate the container with wxClientData or vice
ae500232 142 // versa.
88a9f974
RD
143 union
144 {
145 wxClientData *m_clientObject;
146 void *m_clientData;
147 };
148
149 // client data accessors
150 virtual void DoSetClientObject( wxClientData *data );
151 virtual wxClientData *DoGetClientObject() const;
152
153 virtual void DoSetClientData( void *data );
154 virtual void *DoGetClientData() const;
155
156 // what kind of data do we have?
157 wxClientDataType m_clientDataType;
158
159};
2aab8f16 160
84006e65 161#endif // _WX_CLNTDATAH__
88a9f974 162