]> git.saurik.com Git - wxWidgets.git/blob - include/wx/object.h
wxUpdateUIEvent derives from wxCommandEvent now
[wxWidgets.git] / include / wx / object.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: object.h
3 // Purpose: wxObject class, plus run-time type information macros
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_OBJECTH__
13 #define _WX_OBJECTH__
14
15 #ifdef __GNUG__
16 #pragma interface "object.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 class WXDLLEXPORT wxObject;
22
23 #if USE_DYNAMIC_CLASSES
24
25 #ifdef __GNUWIN32__
26 #ifdef GetClassName
27 #undef GetClassName
28 #endif
29 #endif
30
31 class WXDLLEXPORT wxClassInfo;
32 class WXDLLEXPORT ostream;
33 class WXDLLEXPORT wxInputStream;
34 class WXDLLIMPORT wxObjectInputStream;
35 class WXDLLIMPORT wxObjectOutputStream;
36
37 /*
38 * Dynamic object system declarations
39 */
40
41 typedef wxObject * (*wxObjectConstructorFn) (void);
42
43 class WXDLLEXPORT wxClassInfo
44 {
45 public:
46 char *className;
47 char *baseClassName1;
48 char *baseClassName2;
49 int objectSize;
50 wxObjectConstructorFn objectConstructor;
51
52 // Pointers to base wxClassInfos: set in InitializeClasses
53 // called from wx_main.cc
54 wxClassInfo *baseInfo1;
55 wxClassInfo *baseInfo2;
56
57 static wxClassInfo *first;
58 wxClassInfo *next;
59
60 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
61
62 wxObject *CreateObject(void);
63
64 inline char *GetClassName(void) const { return className; }
65 inline char *GetBaseClassName1(void) const { return baseClassName1; }
66 inline char *GetBaseClassName2(void) const { return baseClassName2; }
67 inline int GetSize(void) const { return objectSize; }
68 bool IsKindOf(wxClassInfo *info);
69
70 static wxClassInfo *FindClass(char *c);
71 // Initializes parent pointers for fast searching.
72 static void InitializeClasses(void);
73 };
74
75 wxObject* WXDLLEXPORT wxCreateDynamicObject(char *name);
76
77 #ifdef USE_STORABLE_CLASSES
78 wxObject* WXDLLEXPORT wxCreateStoredObject( wxInputStream& stream );
79 #endif
80
81 #define DECLARE_DYNAMIC_CLASS(name) \
82 public:\
83 static wxClassInfo class##name;\
84 wxClassInfo *GetClassInfo() \
85 { return &name::class##name; }
86
87 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
88 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
89
90 //////
91 ////// for concrete classes
92 //////
93
94 // Single inheritance with one base class
95 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
96 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
97 { return new name; }\
98 wxClassInfo name::class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
99
100 // Multiple inheritance with two base classes
101 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
102 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
103 { return new name; }\
104 wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
105
106 //////
107 ////// for abstract classes
108 //////
109
110 // Single inheritance with one base class
111 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
112 wxClassInfo name::class##name((char *) #name, (char *) #basename, \
113 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
114
115 // Multiple inheritance with two base classes
116 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
117 wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
118
119 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
120 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
121
122 #define CLASSINFO(name) (&name::class##name)
123
124 #else
125
126 // No dynamic class system: so stub out the macros
127 #define DECLARE_DYNAMIC_CLASS(name)
128 #define DECLARE_ABSTRACT_CLASS(name)
129 #define DECLARE_CLASS(name)
130 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
131 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
132 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
133 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
134 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
135 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
136
137 #endif
138
139 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className)
140
141 // Unfortunately Borland seems to need this include.
142 #ifdef __BORLANDC__
143 #if USE_IOSTREAMH
144 #include <iostream.h>
145 #else
146 #include <iostream>
147 #endif
148 #endif
149
150 class WXDLLEXPORT wxObjectRefData;
151
152 class WXDLLEXPORT wxObject
153 {
154 public:
155
156 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
157 static wxClassInfo classwxObject;
158
159 wxObject(void);
160 virtual ~wxObject(void);
161
162 virtual wxClassInfo *GetClassInfo(void) { return &classwxObject; }
163
164 bool IsKindOf(wxClassInfo *info);
165
166 #if WXDEBUG && USE_MEMORY_TRACING
167 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
168 void operator delete (void * buf);
169
170 // Cause problems for VC++
171 #ifndef _MSC_VER
172 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
173 void operator delete[] (void * buf);
174 #endif
175
176 #endif
177
178 #if WXDEBUG || USE_DEBUG_CONTEXT
179 virtual void Dump(ostream& str);
180 #endif
181
182 #ifdef USE_STORABLE_CLASSES
183 virtual void StoreObject( wxObjectOutputStream &stream );
184 virtual void LoadObject( wxObjectInputStream &stream );
185 #endif
186
187 // make a 'clone' of the object
188 void Ref(const wxObject& clone);
189
190 // destroy a reference
191 void UnRef(void);
192
193 inline wxObjectRefData *GetRefData(void) const { return m_refData; }
194 inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
195
196 protected:
197 wxObjectRefData *m_refData;
198 };
199
200 /*
201 * wxObjectData
202 */
203
204 class WXDLLEXPORT wxObjectRefData {
205
206 friend class wxObject;
207
208 public:
209 wxObjectRefData(void);
210 virtual ~wxObjectRefData(void);
211
212 inline int GetRefCount(void) const { return m_count; }
213 private:
214 int m_count;
215 };
216
217 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
218 #ifndef WXDEBUG_NEW
219 #define WXDEBUG_NEW new(__FILE__,__LINE__)
220 #endif
221 #define new WXDEBUG_NEW
222 #endif
223
224 #endif
225 // _WX_OBJECTH__
226
227