]> git.saurik.com Git - wxWidgets.git/blob - include/wx/object.h
Added wxFrame::SetStatusBar for wxPython
[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 #include "wx/memory.h"
21
22 class WXDLLEXPORT wxObject;
23
24 #if wxUSE_DYNAMIC_CLASSES
25
26 #ifdef __GNUWIN32__
27 #ifdef GetClassName
28 #undef GetClassName
29 #endif
30 #endif
31
32 class WXDLLEXPORT wxClassInfo;
33 class WXDLLIMPORT ostream;
34 class WXDLLEXPORT wxInputStream;
35 class WXDLLEXPORT wxObjectInputStream;
36 class WXDLLEXPORT wxObjectOutputStream;
37 class WXDLLEXPORT wxHashTable;
38 class WXDLLEXPORT wxObject_Serialize;
39
40 /*
41 * Dynamic object system declarations
42 */
43
44 typedef wxObject * (*wxObjectConstructorFn) (void);
45
46 class WXDLLEXPORT wxClassInfo
47 {
48 public:
49 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
50
51 wxObject *CreateObject(void);
52
53 inline char *GetClassName(void) const { return m_className; }
54 inline char *GetBaseClassName1(void) const { return m_baseClassName1; }
55 inline char *GetBaseClassName2(void) const { return m_baseClassName2; }
56 inline wxClassInfo* GetBaseClass1() const { return m_baseInfo1; }
57 inline wxClassInfo* GetBaseClass2() const { return m_baseInfo2; }
58 inline int GetSize(void) const { return m_objectSize; }
59 inline wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
60 static inline wxClassInfo* GetFirst() { return sm_first; }
61 inline wxClassInfo* GetNext() const { return m_next; }
62 bool IsKindOf(wxClassInfo *info) const;
63
64 static wxClassInfo *FindClass(char *c);
65
66 // Initializes parent pointers and hash table for fast searching.
67 static void InitializeClasses(void);
68
69 // Cleans up hash table used for fast searching.
70 static void CleanUpClasses(void);
71
72 public:
73 char* m_className;
74 char* m_baseClassName1;
75 char* m_baseClassName2;
76 int m_objectSize;
77 wxObjectConstructorFn m_objectConstructor;
78
79 // Pointers to base wxClassInfos: set in InitializeClasses
80 // called from wx_main.cc
81 wxClassInfo* m_baseInfo1;
82 wxClassInfo* m_baseInfo2;
83
84 static wxClassInfo* sm_first;
85 wxClassInfo* m_next;
86
87 static wxHashTable* sm_classTable;
88 };
89
90 wxObject* WXDLLEXPORT wxCreateDynamicObject(const char *name);
91
92 #ifdef wxUSE_SERIAL
93 wxObject* WXDLLEXPORT wxCreateStoredObject( wxInputStream& stream );
94 #endif
95
96 #define DECLARE_DYNAMIC_CLASS(name) \
97 public:\
98 static wxClassInfo sm_class##name;\
99 wxClassInfo *GetClassInfo() const \
100 { return &name::sm_class##name; }
101
102 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
103 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
104
105 //////
106 ////// for concrete classes
107 //////
108
109 // Single inheritance with one base class
110 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
111 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
112 { return new name; }\
113 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
114
115 // Multiple inheritance with two base classes
116 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
117 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
118 { return new name; }\
119 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
120
121 //////
122 ////// for abstract classes
123 //////
124
125 // Single inheritance with one base class
126 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
127 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
128 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
129
130 // Multiple inheritance with two base classes
131 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
132 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
133
134 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
135 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
136
137 #define CLASSINFO(name) (&name::sm_class##name)
138
139 #else
140
141 // No dynamic class system: so stub out the macros
142 #define DECLARE_DYNAMIC_CLASS(name)
143 #define DECLARE_ABSTRACT_CLASS(name)
144 #define DECLARE_CLASS(name)
145 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
146 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
147 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
148 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
149 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
150 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
151
152 #endif
153
154 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
155
156 // Unfortunately Borland seems to need this include.
157 #ifdef __BORLANDC__
158 #if wxUSE_IOSTREAMH
159 #include <iostream.h>
160 #else
161 #include <iostream>
162 #endif
163 #endif
164
165 class WXDLLEXPORT wxObjectRefData;
166
167 class WXDLLEXPORT wxObject
168 {
169 public:
170
171 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
172 static wxClassInfo sm_classwxObject;
173
174 wxObject(void);
175 virtual ~wxObject(void);
176
177 virtual wxClassInfo *GetClassInfo(void) const { return &sm_classwxObject; }
178
179 bool IsKindOf(wxClassInfo *info) const;
180
181 #if WXDEBUG && wxUSE_MEMORY_TRACING
182 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
183 void operator delete (void * buf);
184
185 // VC++ 6.0
186 #if _MSC_VER >= 1200
187 void operator delete(void *buf, char*, int);
188 #endif
189
190 // Cause problems for VC++
191 #ifndef _MSC_VER
192 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
193 void operator delete[] (void * buf);
194 #endif
195
196 #endif
197
198 #if WXDEBUG || wxUSE_DEBUG_CONTEXT
199 virtual void Dump(ostream& str);
200 #endif
201
202 #ifdef wxUSE_SERIAL
203 virtual void StoreObject( wxObjectOutputStream &stream );
204 virtual void LoadObject( wxObjectInputStream &stream );
205 #endif
206
207 // make a 'clone' of the object
208 void Ref(const wxObject& clone);
209
210 // destroy a reference
211 void UnRef(void);
212
213 inline wxObjectRefData *GetRefData(void) const { return m_refData; }
214 inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
215
216 protected:
217 wxObjectRefData* m_refData;
218 #ifdef wxUSE_SERIAL
219 wxObject_Serialize* m_serialObj;
220 #endif
221 };
222
223 /*
224 * wxObjectData
225 */
226
227 class WXDLLEXPORT wxObjectRefData {
228
229 friend class wxObject;
230
231 public:
232 wxObjectRefData(void);
233 virtual ~wxObjectRefData(void);
234
235 inline int GetRefCount(void) const { return m_count; }
236 private:
237 int m_count;
238 };
239
240 #if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
241 //#ifndef WXDEBUG_NEW
242 //#define WXDEBUG_NEW new(__FILE__,__LINE__)
243 //#endif
244 #define new new(__FILE__,__LINE__)
245 #endif
246
247 #endif
248 // _WX_OBJECTH__
249
250