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