]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
Applied pop menu patch.
[wxWidgets.git] / include / wx / object.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
b2edef6f 2// Name: wx/object.h
c801d85f
KB
3// Purpose: wxObject class, plus run-time type information macros
4// Author: Julian Smart
0b9ab0bd 5// Modified by: Ron Lee
c801d85f
KB
6// Created: 01/02/97
7// RCS-ID: $Id$
371a5b4e 8// Copyright: (c) 1997 Julian Smart
0b9ab0bd 9// (c) 2001 Ron Lee <ron@debian.org>
3f4a0c5b 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
34138703
JS
13#ifndef _WX_OBJECTH__
14#define _WX_OBJECTH__
c801d85f 15
af49c4b8 16#if defined(__GNUG__) && !defined(__APPLE__)
0d3820b3 17#pragma interface "object.h"
c801d85f
KB
18#endif
19
0b9ab0bd
RL
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
c801d85f 24#include "wx/defs.h"
e55ad60e 25#include "wx/memory.h"
c801d85f 26
bddd7a8d 27class WXDLLIMPEXP_BASE wxObject;
c801d85f 28
47d67540 29#if wxUSE_DYNAMIC_CLASSES
c801d85f 30
0b9ab0bd
RL
31// ----------------------------------------------------------------------------
32// conditional compilation
33// ----------------------------------------------------------------------------
34
b2edef6f
VZ
35// this shouldn't be needed any longer as <wx/msw/private.h> does it but it
36// doesn't hurt neither
c801d85f
KB
37#ifdef GetClassName
38#undef GetClassName
39#endif
3f1af920
JS
40#ifdef GetClassInfo
41#undef GetClassInfo
c801d85f
KB
42#endif
43
bddd7a8d
VZ
44class WXDLLIMPEXP_BASE wxClassInfo;
45class WXDLLIMPEXP_BASE wxHashTable;
46class WXDLLIMPEXP_BASE wxObjectRefData;
c801d85f 47
0b9ab0bd
RL
48// ----------------------------------------------------------------------------
49// wxClassInfo
50// ----------------------------------------------------------------------------
51
52typedef wxObject *(*wxObjectConstructorFn)(void);
c801d85f 53
bddd7a8d 54class WXDLLIMPEXP_BASE wxClassInfo
c801d85f 55{
aac65598 56public:
38befbee
RL
57 wxClassInfo( const wxChar *className,
58 const wxChar *baseName1,
59 const wxChar *baseName2,
60 int size,
61 wxObjectConstructorFn ctor )
0b9ab0bd
RL
62 : m_className(className)
63 , m_baseClassName1(baseName1)
64 , m_baseClassName2(baseName2)
65 , m_objectSize(size)
66 , m_objectConstructor(ctor)
67 , m_baseInfo1(0)
68 , m_baseInfo2(0)
69 , m_next(sm_first)
6d1b9112 70 { sm_first = this; }
0b9ab0bd 71
aa4b7ef9 72 ~wxClassInfo();
1d2eddff 73
0b9ab0bd
RL
74 wxObject *CreateObject() { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
75
76 const wxChar *GetClassName() const { return m_className; }
77 const wxChar *GetBaseClassName1() const { return m_baseClassName1; }
78 const wxChar *GetBaseClassName2() const { return m_baseClassName2; }
79 const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
80 const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
81 int GetSize() const { return m_objectSize; }
82
83 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
84 static const wxClassInfo *GetFirst() { return sm_first; }
85 const wxClassInfo *GetNext() const { return m_next; }
86 static wxClassInfo *FindClass(const wxChar *className);
807d8487 87
0b9ab0bd
RL
88 // Climb upwards through inheritance hierarchy.
89 // Dual inheritance is catered for.
90
91 bool IsKindOf(const wxClassInfo *info) const
92 {
93 return info != 0 &&
94 ( info == this ||
95 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
96 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
97 }
3f4a0c5b 98
0b9ab0bd 99 // Initializes parent pointers and hash table for fast searching.
c801d85f 100
0b9ab0bd 101 static void InitializeClasses();
0c32066b 102
0b9ab0bd 103 // Cleans up hash table used for fast searching.
0c32066b 104
0b9ab0bd 105 static void CleanUpClasses();
0c32066b
JS
106
107public:
0b9ab0bd
RL
108 const wxChar *m_className;
109 const wxChar *m_baseClassName1;
110 const wxChar *m_baseClassName2;
111 int m_objectSize;
112 wxObjectConstructorFn m_objectConstructor;
113
114 // Pointers to base wxClassInfos: set in InitializeClasses
115
116 const wxClassInfo *m_baseInfo1;
117 const wxClassInfo *m_baseInfo2;
118
119 // class info object live in a linked list:
120 // pointers to its head and the next element in it
121
122 static wxClassInfo *sm_first;
123 wxClassInfo *m_next;
124
1f428942
VZ
125 // FIXME: this should be private (currently used directly by way too
126 // many clients)
0b9ab0bd 127 static wxHashTable *sm_classTable;
1f428942
VZ
128
129private:
130 // InitializeClasses() helper
131 static wxClassInfo *GetBaseByName(const wxChar *name);
684242c6
GD
132
133 DECLARE_NO_COPY_CLASS(wxClassInfo)
c801d85f
KB
134};
135
bddd7a8d 136WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
c801d85f 137
0b9ab0bd
RL
138// ----------------------------------------------------------------------------
139// Dynamic class macros
140// ----------------------------------------------------------------------------
141
142#define DECLARE_DYNAMIC_CLASS(name) \
143 public: \
144 static wxClassInfo sm_class##name; \
145 virtual wxClassInfo *GetClassInfo() const \
0c32066b 146 { return &name::sm_class##name; }
c801d85f 147
fc7a2a60
VZ
148#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
149 private: \
150 name& operator=(const name&); \
151 DECLARE_DYNAMIC_CLASS(name)
152
153#define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
154 DECLARE_NO_COPY_CLASS(name) \
155 DECLARE_DYNAMIC_CLASS(name)
156
c801d85f
KB
157#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
158#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
159
0b9ab0bd
RL
160// -----------------------------------
161// for concrete classes
162// -----------------------------------
163
164 // Single inheritance with one base class
c801d85f 165
0b9ab0bd 166#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
648762b1 167 wxObject* wxConstructorFor##name() \
0b9ab0bd
RL
168 { return new name; } \
169 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename), \
170 0, (int) sizeof(name), \
171 (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 172
0b9ab0bd 173 // Multiple inheritance with two base classes
c801d85f 174
0b9ab0bd 175#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
648762b1 176 wxObject* wxConstructorFor##name() \
0b9ab0bd
RL
177 { return new name; } \
178 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
179 wxT(#basename2), (int) sizeof(name), \
180 (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 181
0b9ab0bd
RL
182// -----------------------------------
183// for abstract classes
184// -----------------------------------
c801d85f 185
0b9ab0bd
RL
186 // Single inheritance with one base class
187
188#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
189 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename), \
190 0, (int) sizeof(name), (wxObjectConstructorFn) 0);
191
192 // Multiple inheritance with two base classes
193
194#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
195 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
196 wxT(#basename2), (int) sizeof(name), \
197 (wxObjectConstructorFn) 0);
c801d85f
KB
198
199#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
200#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
201
0b9ab0bd
RL
202// -----------------------------------
203// for pluggable classes
204// -----------------------------------
205
206 // NOTE: this should probably be the very first statement
207 // in the class declaration so wxPluginSentinel is
208 // the first member initialised and the last destroyed.
209
210// _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel;
211
212#if wxUSE_NESTED_CLASSES
213
60b73526
RL
214#define _DECLARE_DL_SENTINEL(name, exportdecl) \
215class exportdecl name##PluginSentinel { \
216private: \
217 static const wxString sm_className; \
218public: \
219 name##PluginSentinel(); \
2e0b1b11 220 ~name##PluginSentinel(); \
60b73526 221}; \
0b9ab0bd 222name##PluginSentinel m_pluginsentinel;
0b9ab0bd
RL
223
224#define _IMPLEMENT_DL_SENTINEL(name) \
225 const wxString name::name##PluginSentinel::sm_className(#name); \
226 name::name##PluginSentinel::name##PluginSentinel() { \
4f89dbc4 227 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 228 if( e != 0 ) { e->RefObj(); } \
0b9ab0bd 229 } \
abad5367 230 name::name##PluginSentinel::~name##PluginSentinel() { \
4f89dbc4 231 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 232 if( e != 0 ) { e->UnrefObj(); } \
0b9ab0bd
RL
233 }
234#else
235
236#define _DECLARE_DL_SENTINEL(name)
237#define _IMPLEMENT_DL_SENTINEL(name)
238
239#endif // wxUSE_NESTED_CLASSES
240
241#define DECLARE_PLUGGABLE_CLASS(name) \
60b73526 242 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
0b9ab0bd 243#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \
60b73526
RL
244 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
245
246#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \
247 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
248#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \
249 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
0b9ab0bd
RL
250
251#define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \
252 IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
253#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \
254 IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
0b9ab0bd
RL
255#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
256 IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
257#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
258 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
259
60b73526
RL
260#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \
261 IMPLEMENT_PLUGGABLE_CLASS(name, basename)
262#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \
263 IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
264#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
265 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
266#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
267 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
268
0b9ab0bd 269
0c32066b 270#define CLASSINFO(name) (&name::sm_class##name)
c801d85f 271
34636400 272#else // !wxUSE_DYNAMIC_CLASSES
c801d85f 273
0b9ab0bd
RL
274 // No dynamic class system: so stub out the macros
275
c801d85f
KB
276#define DECLARE_DYNAMIC_CLASS(name)
277#define DECLARE_ABSTRACT_CLASS(name)
278#define DECLARE_CLASS(name)
279#define IMPLEMENT_DYNAMIC_CLASS(name, basename)
280#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
281#define IMPLEMENT_ABSTRACT_CLASS(name, basename)
282#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
283#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
284#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
285
0b9ab0bd
RL
286#define DECLARE_PLUGGABLE_CLASS(name)
287#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name)
288#define IMPLEMENT_PLUGGABLE_CLASS(name, basename)
289#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
290#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
291#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
292
60b73526
RL
293#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo)
294#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo)
295#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename)
296#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2)
297#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename)
298#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
299
0b9ab0bd
RL
300#endif // wxUSE_DYNAMIC_CLASSES
301
c801d85f 302
3013b6f4
JS
303#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
304
b2edef6f 305// Just seems a bit nicer-looking (pretend it's not a macro)
3013b6f4 306#define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className)
c801d85f 307
b2edef6f 308// to be replaced by dynamic_cast<> in the future
34636400 309#define wxDynamicCast(obj, className) \
768f1af6 310 ((className *) wxCheckDynamicCast((wxObject*)(obj), &className::sm_class##className))
0b9ab0bd 311
b2edef6f
VZ
312// The 'this' pointer is always true, so use this version
313// to cast the this pointer and avoid compiler warnings.
f7637829 314#define wxDynamicCastThis(className) \
0b9ab0bd 315 (IsKindOf(&className::sm_class##className) ? (className *)(this) : (className *)0)
33ac7e6f 316
521196a2
MB
317#ifdef HAVE_CONST_CAST
318#define wxConstCast(obj, className) const_cast<className *>(obj)
319#else
f6bcfd97 320#define wxConstCast(obj, className) ((className *)(obj))
521196a2 321#endif
f6bcfd97 322
0b9ab0bd 323
f6bcfd97 324#ifdef __WXDEBUG__
0b9ab0bd
RL
325inline void wxCheckCast(void *ptr)
326{
327 wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
328}
329#define wxStaticCast(obj, className) \
330 (wxCheckCast(wxDynamicCast(obj, className)), ((className *)(obj)))
f6bcfd97 331
0b9ab0bd
RL
332#else // !__WXDEBUG__
333#define wxStaticCast(obj, className) ((className *)(obj))
f6bcfd97 334
0b9ab0bd 335#endif // __WXDEBUG__
f6bcfd97 336
b2edef6f
VZ
337// ----------------------------------------------------------------------------
338// set up memory debugging macros
339// ----------------------------------------------------------------------------
340
341/*
342 Which new/delete operator variants do we want?
343
344 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
345 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
346 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
347 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
348 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
349 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
350 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
351*/
352
353#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
354
355// All compilers get this one
356#define _WX_WANT_NEW_SIZET_WXCHAR_INT
357
358// Everyone except Visage gets the next one
359#ifndef __VISAGECPP__
360 #define _WX_WANT_DELETE_VOID
c801d85f 361#endif
b2edef6f
VZ
362
363// Only visage gets this one under the correct circumstances
364#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
365 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
366#endif
367
368// Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new
684242c6 369#if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
b2edef6f 370 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
fd85b064 371#endif
c801d85f 372
b2edef6f
VZ
373// Now see who (if anyone) gets the array memory operators
374#if wxUSE_ARRAY_MEMORY_OPERATORS
375
376 // Everyone except Visual C++ (cause problems for VC++ - crashes)
377 #if !defined(__VISUALC__)
378 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
379 #endif
380
381 // Everyone except Visual C++ (cause problems for VC++ - crashes)
382 #if !defined(__VISUALC__)
383 #define _WX_WANT_ARRAY_DELETE_VOID
384 #endif
385
386 // Only CodeWarrior 6 or higher
387 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
388 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
389 #endif
390
391#endif // wxUSE_ARRAY_MEMORY_OPERATORS
392
393#endif // WXDEBUG && wxUSE_MEMORY_TRACING
394
65f19af1
VZ
395#if wxUSE_STD_IOSTREAM && (defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT)
396// needed by wxObject::Dump
397#include "wx/iosfwrap.h"
398#endif
0b9ab0bd
RL
399
400// ----------------------------------------------------------------------------
b2edef6f 401// wxObject: the root class of wxWindows object hierarchy
0b9ab0bd
RL
402// ----------------------------------------------------------------------------
403
bddd7a8d 404class WXDLLIMPEXP_BASE wxObject
c801d85f 405{
684242c6 406 DECLARE_ABSTRACT_CLASS(wxObject)
c801d85f 407
a6391d30
GD
408private:
409 void InitFrom(const wxObject& other);
410
0b9ab0bd 411public:
b2edef6f 412 wxObject() { m_refData = NULL; }
0b9ab0bd 413 virtual ~wxObject() { UnRef(); }
684242c6 414
a6391d30
GD
415 wxObject(const wxObject& other)
416 {
417 InitFrom(other);
418 }
419
420 wxObject& operator=(const wxObject& other)
421 {
422 if ( this != &other )
423 {
424 UnRef();
425 InitFrom(other);
426 }
427 return *this;
428 }
429
0b9ab0bd 430 bool IsKindOf(wxClassInfo *info) const;
c801d85f 431
0b9ab0bd 432
b2edef6f
VZ
433 // Turn on the correct set of new and delete operators
434
435#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
cf760e4c 436 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd 437#endif
27198be4 438
b2edef6f
VZ
439#ifdef _WX_WANT_DELETE_VOID
440 void operator delete ( void * buf );
441#endif
0b9ab0bd 442
b2edef6f
VZ
443#ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
444 void operator delete ( void *buf, const char *_fname, size_t _line );
0b9ab0bd 445#endif
76626af2 446
b2edef6f 447#ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
cf760e4c 448 void operator delete ( void *buf, const wxChar*, int );
b2edef6f 449#endif
8cfc5426 450
b2edef6f 451#ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
cf760e4c 452 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd
RL
453#endif
454
b2edef6f
VZ
455#ifdef _WX_WANT_ARRAY_DELETE_VOID
456 void operator delete[] ( void *buf );
0b9ab0bd 457#endif
27198be4 458
b2edef6f 459#ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
cf760e4c 460 void operator delete[] (void* buf, const wxChar*, int );
b2edef6f 461#endif
c801d85f 462
c801d85f 463
0b9ab0bd
RL
464#if wxUSE_STD_IOSTREAM && (defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT)
465 virtual void Dump(wxSTD ostream& str);
c801d85f
KB
466#endif
467
807d8487
VZ
468 // ref counted data handling methods
469
470 // get/set
471 wxObjectRefData *GetRefData() const { return m_refData; }
472 void SetRefData(wxObjectRefData *data) { m_refData = data; }
473
474 // make a 'clone' of the object
0b9ab0bd 475 void Ref(const wxObject& clone);
c801d85f 476
807d8487 477 // destroy a reference
0b9ab0bd 478 void UnRef();
c801d85f 479
c801d85f 480protected:
807d8487
VZ
481 // ensure that our data is not shared with anybody else: if we have no
482 // data, it is created using CreateRefData() below, if we have shared data
483 // it is copied using CloneRefData(), otherwise nothing is done
484 void AllocExclusive();
485
486 // both methods must be implemented if Unshare() is used, not pure virtual
487 // only because of the backwards compatibility reasons
488
489 // create a new m_refData
490 virtual wxObjectRefData *CreateRefData() const;
491
492 // create a new m_refData initialized with the given one
b8027888 493 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
807d8487 494
0b9ab0bd 495 wxObjectRefData *m_refData;
c801d85f
KB
496};
497
b2edef6f
VZ
498// ----------------------------------------------------------------------------
499// wxObjectRefData: ref counted data meant to be stored in wxObject
500// ----------------------------------------------------------------------------
c801d85f 501
bddd7a8d 502class WXDLLIMPEXP_BASE wxObjectRefData
0b9ab0bd 503{
bddd7a8d 504 friend class WXDLLIMPEXP_BASE wxObject;
c801d85f
KB
505
506public:
b2edef6f
VZ
507 wxObjectRefData() : m_count(1) { }
508 virtual ~wxObjectRefData() { }
509
510 int GetRefCount() const { return m_count; }
c801d85f 511
c801d85f
KB
512private:
513 int m_count;
514};
515
0b9ab0bd 516
ea1e6c4b
RL
517inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
518{
b2edef6f 519 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
ea1e6c4b
RL
520}
521
b2edef6f
VZ
522// ----------------------------------------------------------------------------
523// more debugging macros
524// ----------------------------------------------------------------------------
525
7fe7d506 526#ifdef __WXDEBUG__
b2edef6f
VZ
527 #ifndef WXDEBUG_NEW
528 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
529 #endif
530#else // !__WXDEBUG__
531 #define WXDEBUG_NEW new
7fe7d506
JS
532#endif
533
b2edef6f
VZ
534// Redefine new to be the debugging version. This doesn't work with all
535// compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish
536// to use the debugging version.
7fe7d506
JS
537
538#if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
b2edef6f 539 #define new new(__TFILE__,__LINE__)
c801d85f
KB
540#endif
541
0b9ab0bd 542#endif // _WX_OBJECTH__
c801d85f 543