]> git.saurik.com Git - wxWidgets.git/blob - include/wx/object.h
stack overflow when clicking on the arrow in a notebook fixed
[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 __OBJECTH__
13 #define __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(#name, #basename, NULL, sizeof(name), 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(#name, #basename1, #basename2, sizeof(name), 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(#name, #basename, NULL, sizeof(name), NULL);
113
114 // Multiple inheritance with two base classes
115 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
116 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), NULL);
117
118 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
119 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
120
121 #define CLASSINFO(name) (&name::class##name)
122
123 #else
124
125 // No dynamic class system: so stub out the macros
126 #define DECLARE_DYNAMIC_CLASS(name)
127 #define DECLARE_ABSTRACT_CLASS(name)
128 #define DECLARE_CLASS(name)
129 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
130 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
131 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
132 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
133 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
134 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
135
136 #endif
137
138 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className)
139
140 // Unfortunately Borland seems to need this include.
141 #ifdef __BORLANDC__
142 #if USE_IOSTREAMH
143 #include <iostream.h>
144 #else
145 #include <iostream>
146 #endif
147 #endif
148
149 class WXDLLEXPORT wxObjectRefData;
150
151 class WXDLLEXPORT wxObject
152 {
153 public:
154
155 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
156 static wxClassInfo classwxObject;
157
158 wxObject(void);
159 virtual ~wxObject(void);
160
161 virtual wxClassInfo *GetClassInfo(void) { return &classwxObject; }
162
163 bool IsKindOf(wxClassInfo *info);
164
165 #if WXDEBUG && USE_MEMORY_TRACING
166 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
167 void operator delete (void * buf);
168
169 // Cause problems for VC++
170 #ifndef _MSC_VER
171 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
172 void operator delete[] (void * buf);
173 #endif
174
175 #endif
176
177 #if WXDEBUG || USE_DEBUG_CONTEXT
178 virtual void Dump(ostream& str);
179 #endif
180
181 #ifdef USE_STORABLE_CLASSES
182 virtual void StoreObject( wxObjectOutputStream &stream );
183 virtual void LoadObject( wxObjectInputStream &stream );
184 #endif
185
186 // make a 'clone' of the object
187 void Ref(const wxObject& clone);
188
189 // destroy a reference
190 void UnRef(void);
191
192 inline wxObjectRefData *GetRefData(void) const { return m_refData; }
193 inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
194
195 protected:
196 wxObjectRefData *m_refData;
197 };
198
199 /*
200 * wxObjectData
201 */
202
203 class WXDLLEXPORT wxObjectRefData {
204
205 friend class wxObject;
206
207 public:
208 wxObjectRefData(void);
209 virtual ~wxObjectRefData(void);
210
211 inline int GetRefCount(void) const { return m_count; }
212 private:
213 int m_count;
214 };
215
216 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
217 #ifndef WXDEBUG_NEW
218 #define WXDEBUG_NEW new(__FILE__,__LINE__)
219 #endif
220 #define new WXDEBUG_NEW
221 #endif
222
223 #endif
224 // __OBJECTH__
225
226