]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/propgriddefs.h
Document wxDataViewListModel as common abstract base class for
[wxWidgets.git] / include / wx / propgrid / propgriddefs.h
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/propgrid/propgriddefs.h
3// Purpose: wxPropertyGrid miscellaneous definitions
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2008-08-31
ea5af9c5 7// RCS-ID: $Id$
1c4293cb 8// Copyright: (c) Jaakko Salli
526954c5 9// Licence: wxWindows licence
1c4293cb
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_PROPGRID_PROPGRIDDEFS_H_
13#define _WX_PROPGRID_PROPGRIDDEFS_H_
14
6f631217
JS
15#include "wx/defs.h"
16
f4bc1aa2
JS
17#if wxUSE_PROPGRID
18
1c4293cb 19#include "wx/dynarray.h"
f7a094e1 20#include "wx/vector.h"
1c4293cb
VZ
21#include "wx/hashmap.h"
22#include "wx/variant.h"
4e0bdd56 23#include "wx/any.h"
1c4293cb
VZ
24#include "wx/longlong.h"
25#include "wx/clntdata.h"
26
27// -----------------------------------------------------------------------
28
29//
30// Here are some platform dependent defines
31// NOTE: More in propertygrid.cpp
32//
33
1c4293cb
VZ
34#if defined(__WXMSW__)
35
36 // space between vertical line and value text
37 #define wxPG_XBEFORETEXT 4
38 // space between vertical line and value editor control
39 #define wxPG_XBEFOREWIDGET 1
40
1c4293cb
VZ
41 // comment to use bitmap buttons
42 #define wxPG_ICON_WIDTH 9
43 // 1 if wxRendererNative should be employed
44 #define wxPG_USE_RENDERER_NATIVE 0
45
46 // 1 to use double-buffer that guarantees flicker-free painting
47 #define wxPG_DOUBLE_BUFFER 1
48
49 // Enable tooltips
50 #define wxPG_SUPPORT_TOOLTIPS 1
51
52 // width of optional bitmap/image in front of property
53 #define wxPG_CUSTOM_IMAGE_WIDTH 20
54
1c4293cb
VZ
55 // 1 if splitter drag detect margin and control cannot overlap
56 #define wxPG_NO_CHILD_EVT_MOTION 0
57
58 // If 1, then setting empty tooltip actually hides it
59 #define wxPG_ALLOW_EMPTY_TOOLTIPS 1
60
61 #define wxPG_NAT_BUTTON_BORDER_ANY 1
62 #define wxPG_NAT_BUTTON_BORDER_X 1
63 #define wxPG_NAT_BUTTON_BORDER_Y 1
64
65 // If 1 then controls are refreshed after selected was drawn.
66 #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 0
67
68#elif defined(__WXGTK__)
69
70 // space between vertical line and value text
71 #define wxPG_XBEFORETEXT 5
72 // space between vertical line and value editor control
73 #define wxPG_XBEFOREWIDGET 1
74
75 // x position adjustment for wxTextCtrl (and like)
0847e36e
JS
76 // NB: Only define wxPG_TEXTCTRLXADJUST for platforms that do not
77 // (yet) support wxTextEntry::SetMargins() for the left margin.
78 //#define wxPG_TEXTCTRLXADJUST 3
1c4293cb
VZ
79
80 // comment to use bitmap buttons
81 #define wxPG_ICON_WIDTH 9
82 // 1 if wxRendererNative should be employed
9861dc94 83 #define wxPG_USE_RENDERER_NATIVE 1
1c4293cb
VZ
84
85 // 1 to use double-buffer that guarantees flicker-free painting
86 #define wxPG_DOUBLE_BUFFER 1
87
88 // Enable tooltips
89 #define wxPG_SUPPORT_TOOLTIPS 1
90
91 // width of optional bitmap/image in front of property
92 #define wxPG_CUSTOM_IMAGE_WIDTH 20
93
1c4293cb
VZ
94 // 1 if splitter drag detect margin and control cannot overlap
95 #define wxPG_NO_CHILD_EVT_MOTION 1
96
97 // If 1, then setting empty tooltip actually hides it
98 #define wxPG_ALLOW_EMPTY_TOOLTIPS 0
99
100 #define wxPG_NAT_BUTTON_BORDER_ANY 1
101 #define wxPG_NAT_BUTTON_BORDER_X 1
102 #define wxPG_NAT_BUTTON_BORDER_Y 1
103
104 // If 1 then controls are refreshed after selected was drawn.
105 #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 1
106
107#elif defined(__WXMAC__)
108
109 // space between vertical line and value text
110 #define wxPG_XBEFORETEXT 4
111 // space between vertical line and value editor widget
112 #define wxPG_XBEFOREWIDGET 1
113
114 // x position adjustment for wxTextCtrl (and like)
012b4a07 115 #define wxPG_TEXTCTRLXADJUST 0
1c4293cb
VZ
116
117 // comment to use bitmap buttons
118 #define wxPG_ICON_WIDTH 11
119 // 1 if wxRendererNative should be employed
120 #define wxPG_USE_RENDERER_NATIVE 1
121
122 // 1 to use double-buffer that guarantees flicker-free painting
123 #define wxPG_DOUBLE_BUFFER 0
124
125 // Enable tooltips
126 #define wxPG_SUPPORT_TOOLTIPS 1
127
128 // width of optional bitmap/image in front of property
129 #define wxPG_CUSTOM_IMAGE_WIDTH 20
130
1c4293cb
VZ
131 // 1 if splitter drag detect margin and control cannot overlap
132 #define wxPG_NO_CHILD_EVT_MOTION 0
133
134 // If 1, then setting empty tooltip actually hides it
135 #define wxPG_ALLOW_EMPTY_TOOLTIPS 1
136
137 #define wxPG_NAT_BUTTON_BORDER_ANY 0
138 #define wxPG_NAT_BUTTON_BORDER_X 0
139 #define wxPG_NAT_BUTTON_BORDER_Y 0
140
141 // If 1 then controls are refreshed after selected was drawn.
142 #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 0
143
144#else // defaults
145
146 // space between vertical line and value text
147 #define wxPG_XBEFORETEXT 5
148 // space between vertical line and value editor widget
149 #define wxPG_XBEFOREWIDGET 1
150
151 // x position adjustment for wxTextCtrl (and like)
152 #define wxPG_TEXTCTRLXADJUST 3
153
154 // comment to use bitmap buttons
155 #define wxPG_ICON_WIDTH 9
156 // 1 if wxRendererNative should be employed
157 #define wxPG_USE_RENDERER_NATIVE 0
158
159 // 1 to use double-buffer that guarantees flicker-free painting
160 #define wxPG_DOUBLE_BUFFER 0
161
162 // Enable tooltips
163 #define wxPG_SUPPORT_TOOLTIPS 0
164
165 // width of optional bitmap/image in front of property
166 #define wxPG_CUSTOM_IMAGE_WIDTH 20
167
1c4293cb
VZ
168 // 1 if splitter drag detect margin and control cannot overlap
169 #define wxPG_NO_CHILD_EVT_MOTION 1
170
171 // If 1, then setting empty tooltip actually hides it
172 #define wxPG_ALLOW_EMPTY_TOOLTIPS 0
173
174 #define wxPG_NAT_BUTTON_BORDER_ANY 0
175 #define wxPG_NAT_BUTTON_BORDER_X 0
176 #define wxPG_NAT_BUTTON_BORDER_Y 0
177
178 // If 1 then controls are refreshed after selected was drawn.
179 #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 1
180#endif // platform
181
182
183#define wxPG_CONTROL_MARGIN 0 // space between splitter and control
184
185#define wxCC_CUSTOM_IMAGE_MARGIN1 4 // before image
186#define wxCC_CUSTOM_IMAGE_MARGIN2 5 // after image
187
4aee8334
JS
188#define DEFAULT_IMAGE_OFFSET_INCREMENT \
189 (wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2)
190
1c4293cb
VZ
191#define wxPG_DRAG_MARGIN 30
192
193#if wxPG_NO_CHILD_EVT_MOTION
194 #define wxPG_SPLITTERX_DETECTMARGIN1 3 // this much on left
195 #define wxPG_SPLITTERX_DETECTMARGIN2 2 // this much on right
196#else
197 #define wxPG_SPLITTERX_DETECTMARGIN1 3 // this much on left
198 #define wxPG_SPLITTERX_DETECTMARGIN2 2 // this much on right
199#endif
200
201// Use this macro to generate standard custom image height from
202#define wxPG_STD_CUST_IMAGE_HEIGHT(LINEHEIGHT) (LINEHEIGHT-3)
203
204
205#if defined(__WXWINCE__)
206 #define wxPG_SMALL_SCREEN 1
207 #undef wxPG_DOUBLE_BUFFER
208 #define wxPG_DOUBLE_BUFFER 0
209#else
210 #define wxPG_SMALL_SCREEN 0
211#endif
212
1c4293cb
VZ
213
214// Undefine wxPG_ICON_WIDTH to use supplied xpm bitmaps instead
215// (for tree buttons)
216//#undef wxPG_ICON_WIDTH
217
1425eca5
JS
218#if WXWIN_COMPATIBILITY_2_6 || WXWIN_COMPATIBILITY_2_8
219 #define wxPG_COMPATIBILITY_1_4 1
220#else
221 #define wxPG_COMPATIBILITY_1_4 0
222#endif
223
1c4293cb
VZ
224// Need to force disable tooltips?
225#if !wxUSE_TOOLTIPS
226 #undef wxPG_SUPPORT_TOOLTIPS
227 #define wxPG_SUPPORT_TOOLTIPS 0
228#endif
229
230// Set 1 to include advanced properties (wxFontProperty, wxColourProperty, etc.)
231#ifndef wxPG_INCLUDE_ADVPROPS
232 #define wxPG_INCLUDE_ADVPROPS 1
233#endif
234
235// Set 1 to include checkbox editor class
236#define wxPG_INCLUDE_CHECKBOX 1
237
238// -----------------------------------------------------------------------
239
240
1c4293cb
VZ
241class wxPGEditor;
242class wxPGProperty;
243class wxPropertyCategory;
244class wxPGChoices;
245class wxPropertyGridPageState;
246class wxPGCell;
247class wxPGCellRenderer;
248class wxPGChoiceEntry;
249class wxPGPropArgCls;
250class wxPropertyGridInterface;
251class wxPropertyGrid;
252class wxPropertyGridEvent;
253class wxPropertyGridManager;
254class wxPGOwnerDrawnComboBox;
1c4293cb 255class wxPGEditorDialogAdapter;
2a8312bc 256class wxPGValidationInfo;
1c4293cb
VZ
257
258
259// -----------------------------------------------------------------------
260
261/** @section propgrid_misc wxPropertyGrid Miscellanous
262
263 This section describes some miscellanous values, types and macros.
264 @{
265*/
266
ec3cce5a
JS
267// Used to tell wxPGProperty to use label as name as well
268#define wxPG_LABEL (*wxPGProperty::sm_wxPG_LABEL)
269
270// This is the value placed in wxPGProperty::sm_wxPG_LABEL
271#define wxPG_LABEL_STRING wxS("@!")
272#define wxPG_NULL_BITMAP wxNullBitmap
273#define wxPG_COLOUR_BLACK (*wxBLACK)
1c4293cb
VZ
274
275/** Convert Red, Green and Blue to a single 32-bit value.
276*/
277#define wxPG_COLOUR(R,G,B) ((wxUint32)(R+(G<<8)+(B<<16)))
278
279
280/** If property is supposed to have custom-painted image, then returning
281 this in OnMeasureImage() will usually be enough.
282*/
283#define wxPG_DEFAULT_IMAGE_SIZE wxSize(-1, -1)
284
285
43396981
JS
286/** This callback function is used for sorting properties.
287
288 Call wxPropertyGrid::SetSortFunction() to set it.
289
290 Sort function should return a value greater than 0 if position of p1 is
291 after p2. So, for instance, when comparing property names, you can use
292 following implementation:
293
294 @code
295 int MyPropertySortFunction(wxPropertyGrid* propGrid,
296 wxPGProperty* p1,
297 wxPGProperty* p2)
298 {
299 return p1->GetBaseName().compare( p2->GetBaseName() );
300 }
301 @endcode
302*/
303typedef int (*wxPGSortCallback)(wxPropertyGrid* propGrid,
304 wxPGProperty* p1,
305 wxPGProperty* p2);
306
307
308
1c4293cb
VZ
309typedef wxString wxPGCachedString;
310
311/** @}
312*/
313
314// -----------------------------------------------------------------------
315
316// Used to indicate wxPGChoices::Add etc that the value is actually not given
317// by the caller.
318#define wxPG_INVALID_VALUE INT_MAX
319
320// -----------------------------------------------------------------------
321
1c4293cb
VZ
322WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(wxPGProperty*, wxArrayPGProperty,
323 wxBaseArrayPtrVoid,
324 class WXDLLIMPEXP_PROPGRID);
1c4293cb 325
1c4293cb
VZ
326WX_DECLARE_STRING_HASH_MAP_WITH_DECL(void*,
327 wxPGHashMapS2P,
328 class WXDLLIMPEXP_PROPGRID);
329
1425eca5
JS
330WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxString,
331 wxPGHashMapS2S,
332 class WXDLLIMPEXP_PROPGRID);
29a35dd5 333
1c4293cb
VZ
334WX_DECLARE_VOIDPTR_HASH_MAP_WITH_DECL(void*,
335 wxPGHashMapP2P,
336 class WXDLLIMPEXP_PROPGRID);
337
338WX_DECLARE_HASH_MAP_WITH_DECL(wxInt32,
339 wxInt32,
340 wxIntegerHash,
341 wxIntegerEqual,
342 wxPGHashMapI2I,
343 class WXDLLIMPEXP_PROPGRID);
344
8d2c7041
JS
345// Utility to find if specific item is in a vector. Returns index to
346// the item, or wxNOT_FOUND if not present.
347template<typename CONTAINER, typename T>
348int wxPGFindInVector( CONTAINER vector, const T& item )
349{
350 for ( unsigned int i=0; i<vector.size(); i++ )
351 {
352 if ( vector[i] == item )
353 return (int) i;
354 }
355 return wxNOT_FOUND;
356}
357
1c4293cb
VZ
358// -----------------------------------------------------------------------
359
360enum wxPG_GETPROPERTYVALUES_FLAGS
361{
362
363/** Flags for wxPropertyGridInterface::GetPropertyValues */
364wxPG_KEEP_STRUCTURE = 0x00000010,
365
366/** Flags for wxPropertyGrid::SetPropertyAttribute() etc */
367wxPG_RECURSE = 0x00000020,
368
369/** Include attributes for GetPropertyValues. */
370wxPG_INC_ATTRIBUTES = 0x00000040,
371
372/** Used when first starting recursion. */
373wxPG_RECURSE_STARTS = 0x00000080,
374
375/** Force value change. */
0eb877f2
JS
376wxPG_FORCE = 0x00000100,
377
378/** Only sort categories and their immediate children.
379 Sorting done by wxPG_AUTO_SORT option uses this.
380*/
381wxPG_SORT_TOP_LEVEL_ONLY = 0x00000200
1c4293cb
VZ
382
383};
384
385/** Flags for wxPropertyGrid::SetPropertyAttribute() etc */
386#define wxPG_DONT_RECURSE 0x00000000
387
388// -----------------------------------------------------------------------
389
390// Misc argument flags.
391enum wxPG_MISC_ARG_FLAGS
392{
393 // Get/Store full value instead of displayed value.
394 wxPG_FULL_VALUE = 0x00000001,
395
396 wxPG_REPORT_ERROR = 0x00000002,
397
398 wxPG_PROPERTY_SPECIFIC = 0x00000004,
399
400 // Get/Store editable value instead of displayed one (should only be
401 // different in the case of common values)
402 wxPG_EDITABLE_VALUE = 0x00000008,
403
404 // Used when dealing with fragments of composite string value
405 wxPG_COMPOSITE_FRAGMENT = 0x00000010,
406
407 // Means property for which final string value is for can not really be
408 // edited.
1425eca5
JS
409 wxPG_UNEDITABLE_COMPOSITE_FRAGMENT = 0x00000020,
410
411 // ValueToString() called from GetValueAsString()
412 // (guarantees that input wxVariant value is current own value)
f275b5db
JS
413 wxPG_VALUE_IS_CURRENT = 0x00000040,
414
415 // Value is being set programmatically (ie. not by user)
416 wxPG_PROGRAMMATIC_VALUE = 0x00000080
1c4293cb
VZ
417};
418
419// -----------------------------------------------------------------------
420
421// wxPGProperty::SetValue() flags
422enum wxPG_SETVALUE_FLAGS
423{
424 wxPG_SETVAL_REFRESH_EDITOR = 0x0001,
425 wxPG_SETVAL_AGGREGATED = 0x0002,
8f18b252
JS
426 wxPG_SETVAL_FROM_PARENT = 0x0004,
427 wxPG_SETVAL_BY_USER = 0x0008 // Set if value changed by user
1c4293cb
VZ
428};
429
430// -----------------------------------------------------------------------
431
432//
433// Valid constants for wxPG_UINT_BASE attribute
434// (long because of wxVariant constructor)
435#define wxPG_BASE_OCT (long)8
436#define wxPG_BASE_DEC (long)10
437#define wxPG_BASE_HEX (long)16
438#define wxPG_BASE_HEXL (long)32
439
440//
441// Valid constants for wxPG_UINT_PREFIX attribute
442#define wxPG_PREFIX_NONE (long)0
443#define wxPG_PREFIX_0x (long)1
444#define wxPG_PREFIX_DOLLAR_SIGN (long)2
445
446// -----------------------------------------------------------------------
447// Editor class.
448
c26873c8 449// Editor accessor (for backwards compatiblity use only).
1c4293cb
VZ
450#define wxPG_EDITOR(T) wxPGEditor_##T
451
ec3cce5a
JS
452// Macro for declaring editor class, with optional impexpdecl part.
453#ifndef WX_PG_DECLARE_EDITOR_WITH_DECL
454
455 #define WX_PG_DECLARE_EDITOR_WITH_DECL(EDITOR,DECL) \
456 extern DECL wxPGEditor* wxPGEditor_##EDITOR; \
457 extern DECL wxPGEditor* wxPGConstruct##EDITOR##EditorClass();
458
459#endif
1c4293cb
VZ
460
461// Declare editor class.
462#define WX_PG_DECLARE_EDITOR(EDITOR) \
463extern wxPGEditor* wxPGEditor_##EDITOR; \
464extern wxPGEditor* wxPGConstruct##EDITOR##EditorClass();
465
466// Declare builtin editor classes.
467WX_PG_DECLARE_EDITOR_WITH_DECL(TextCtrl,WXDLLIMPEXP_PROPGRID)
468WX_PG_DECLARE_EDITOR_WITH_DECL(Choice,WXDLLIMPEXP_PROPGRID)
469WX_PG_DECLARE_EDITOR_WITH_DECL(ComboBox,WXDLLIMPEXP_PROPGRID)
470WX_PG_DECLARE_EDITOR_WITH_DECL(TextCtrlAndButton,WXDLLIMPEXP_PROPGRID)
471#if wxPG_INCLUDE_CHECKBOX
472WX_PG_DECLARE_EDITOR_WITH_DECL(CheckBox,WXDLLIMPEXP_PROPGRID)
473#endif
474WX_PG_DECLARE_EDITOR_WITH_DECL(ChoiceAndButton,WXDLLIMPEXP_PROPGRID)
475
1c4293cb
VZ
476// -----------------------------------------------------------------------
477
478#ifndef SWIG
479
1c4293cb
VZ
480//
481// Macro WXVARIANT allows creation of wxVariant from any type supported by
482// wxWidgets internally, and of all types created using
483// WX_PG_DECLARE_VARIANT_DATA.
484template<class T>
0372d42e 485wxVariant WXVARIANT( const T& WXUNUSED(value) )
1c4293cb 486{
0372d42e
JS
487 wxFAIL_MSG("Code should always call specializations of this template");
488 return wxVariant();
1c4293cb
VZ
489}
490
491template<> inline wxVariant WXVARIANT( const int& value )
492 { return wxVariant((long)value); }
493template<> inline wxVariant WXVARIANT( const long& value )
494 { return wxVariant(value); }
495template<> inline wxVariant WXVARIANT( const bool& value )
496 { return wxVariant(value); }
497template<> inline wxVariant WXVARIANT( const double& value )
498 { return wxVariant(value); }
499template<> inline wxVariant WXVARIANT( const wxArrayString& value )
500 { return wxVariant(value); }
501template<> inline wxVariant WXVARIANT( const wxString& value )
502 { return wxVariant(value); }
4e00b908
JS
503#if wxUSE_LONGLONG
504template<> inline wxVariant WXVARIANT( const wxLongLong& value )
505 { return wxVariant(value); }
506template<> inline wxVariant WXVARIANT( const wxULongLong& value )
507 { return wxVariant(value); }
508#endif
1c4293cb
VZ
509#if wxUSE_DATETIME
510template<> inline wxVariant WXVARIANT( const wxDateTime& value )
511 { return wxVariant(value); }
512#endif
513
0372d42e
JS
514
515//
516// These are modified versions of DECLARE/WX_PG_IMPLEMENT_VARIANT_DATA
517// macros found in variant.h. Difference are as follows:
518// * These support non-wxObject data
519// * These implement classname##RefFromVariant function which returns
520// reference to data within.
521// * const char* classname##_VariantType which equals classname.
522// * WXVARIANT
523//
524#define WX_PG_DECLARE_VARIANT_DATA(classname) \
525 WX_PG_DECLARE_VARIANT_DATA_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
526
527#define WX_PG_DECLARE_VARIANT_DATA_EXPORTED(classname,expdecl) \
528expdecl classname& operator << ( classname &object, const wxVariant &variant ); \
529expdecl wxVariant& operator << ( wxVariant &variant, const classname &object ); \
530expdecl const classname& classname##RefFromVariant( const wxVariant& variant ); \
531expdecl classname& classname##RefFromVariant( wxVariant& variant ); \
532template<> inline wxVariant WXVARIANT( const classname& value ) \
1c4293cb 533{ \
0372d42e
JS
534 wxVariant variant; \
535 variant << value; \
536 return variant; \
1c4293cb 537} \
0372d42e
JS
538extern expdecl const char* classname##_VariantType;
539
540
541#define WX_PG_IMPLEMENT_VARIANT_DATA(classname) \
542 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
543
a6162a3e
JS
544// Add getter (ie. classname << variant) separately to allow
545// custom implementations.
546#define WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ_NO_GETTER(classname,expdecl) \
0372d42e
JS
547const char* classname##_VariantType = #classname; \
548class classname##VariantData: public wxVariantData \
1c4293cb 549{ \
0372d42e
JS
550public:\
551 classname##VariantData() {} \
552 classname##VariantData( const classname &value ) { m_value = value; } \
553\
554 classname &GetValue() { return m_value; } \
a48fcef3
JS
555\
556 const classname &GetValue() const { return m_value; } \
0372d42e
JS
557\
558 virtual bool Eq(wxVariantData& data) const; \
559\
560 virtual wxString GetType() const; \
561\
562 virtual wxVariantData* Clone() const { return new classname##VariantData(m_value); } \
0372d42e 563\
4e0bdd56 564 DECLARE_WXANY_CONVERSION() \
0372d42e
JS
565protected:\
566 classname m_value; \
567};\
568\
4e0bdd56
JS
569IMPLEMENT_TRIVIAL_WXANY_CONVERSION(classname, classname##VariantData) \
570\
0372d42e
JS
571wxString classname##VariantData::GetType() const\
572{\
573 return wxS(#classname);\
574}\
575\
0372d42e
JS
576expdecl wxVariant& operator << ( wxVariant &variant, const classname &value )\
577{\
578 classname##VariantData *data = new classname##VariantData( value );\
579 variant.SetData( data );\
580 return variant;\
1c4293cb 581} \
0372d42e 582expdecl classname& classname##RefFromVariant( wxVariant& variant ) \
1c4293cb 583{ \
45e82d4c
JS
584 wxASSERT_MSG( variant.GetType() == wxS(#classname), \
585 wxString::Format("Variant type should have been '%s'" \
586 "instead of '%s'", \
587 wxS(#classname), \
588 variant.GetType().c_str())); \
589 classname##VariantData *data = \
590 (classname##VariantData*) variant.GetData(); \
a48fcef3 591 return data->GetValue();\
1c4293cb 592} \
0372d42e 593expdecl const classname& classname##RefFromVariant( const wxVariant& variant ) \
1c4293cb 594{ \
45e82d4c
JS
595 wxASSERT_MSG( variant.GetType() == wxS(#classname), \
596 wxString::Format("Variant type should have been '%s'" \
597 "instead of '%s'", \
598 wxS(#classname), \
599 variant.GetType().c_str())); \
600 classname##VariantData *data = \
601 (classname##VariantData*) variant.GetData(); \
a48fcef3 602 return data->GetValue();\
0372d42e
JS
603}
604
a6162a3e
JS
605#define WX_PG_IMPLEMENT_VARIANT_DATA_GETTER(classname, expdecl) \
606expdecl classname& operator << ( classname &value, const wxVariant &variant )\
607{\
608 wxASSERT( variant.GetType() == #classname );\
609 \
610 classname##VariantData *data = (classname##VariantData*) variant.GetData();\
611 value = data->GetValue();\
612 return value;\
613}
614
615#define WX_PG_IMPLEMENT_VARIANT_DATA_EQ(classname, expdecl) \
0372d42e
JS
616bool classname##VariantData::Eq(wxVariantData& data) const \
617{\
618 wxASSERT( GetType() == data.GetType() );\
619\
620 classname##VariantData & otherData = (classname##VariantData &) data;\
621\
622 return otherData.m_value == m_value;\
623}
624
a6162a3e
JS
625// implements a wxVariantData-derived class using for the Eq() method the
626// operator== which must have been provided by "classname"
627#define WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(classname,expdecl) \
628WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ_NO_GETTER(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
629WX_PG_IMPLEMENT_VARIANT_DATA_GETTER(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
630WX_PG_IMPLEMENT_VARIANT_DATA_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl)
631
0372d42e
JS
632#define WX_PG_IMPLEMENT_VARIANT_DATA(classname) \
633WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
634
635// with Eq() implementation that always returns false
636#define WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(classname,expdecl) \
a6162a3e
JS
637WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ_NO_GETTER(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
638WX_PG_IMPLEMENT_VARIANT_DATA_GETTER(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
0372d42e
JS
639\
640bool classname##VariantData::Eq(wxVariantData& WXUNUSED(data)) const \
641{\
642 return false; \
643}
644
645#define WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(classname) \
646WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(classname, wxEMPTY_PARAMETER_VALUE)
647
648WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxPoint, WXDLLIMPEXP_PROPGRID)
649WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxSize, WXDLLIMPEXP_PROPGRID)
650WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxArrayInt, WXDLLIMPEXP_PROPGRID)
0372d42e
JS
651DECLARE_VARIANT_OBJECT_EXPORTED(wxFont, WXDLLIMPEXP_PROPGRID)
652template<> inline wxVariant WXVARIANT( const wxFont& value )
653{
654 wxVariant variant;
655 variant << value;
656 return variant;
1c4293cb
VZ
657}
658
1c4293cb
VZ
659template<> inline wxVariant WXVARIANT( const wxColour& value )
660{
661 wxVariant variant;
662 variant << value;
663 return variant;
664}
665
0372d42e
JS
666// Define constants for common wxVariant type strings
667
668#define wxPG_VARIANT_TYPE_STRING wxPGGlobalVars->m_strstring
669#define wxPG_VARIANT_TYPE_LONG wxPGGlobalVars->m_strlong
670#define wxPG_VARIANT_TYPE_BOOL wxPGGlobalVars->m_strbool
671#define wxPG_VARIANT_TYPE_LIST wxPGGlobalVars->m_strlist
672#define wxPG_VARIANT_TYPE_DOUBLE wxS("double")
673#define wxPG_VARIANT_TYPE_ARRSTRING wxS("arrstring")
674#define wxPG_VARIANT_TYPE_DATETIME wxS("datetime")
4e00b908
JS
675#define wxPG_VARIANT_TYPE_LONGLONG wxS("longlong")
676#define wxPG_VARIANT_TYPE_ULONGLONG wxS("ulonglong")
1c4293cb
VZ
677
678#endif // !SWIG
679
680// -----------------------------------------------------------------------
681
1c4293cb
VZ
682//
683// Tokenizer macros.
684// NOTE: I have made two versions - worse ones (performance and consistency
685// wise) use wxStringTokenizer and better ones (may have unfound bugs)
686// use custom code.
687//
688
689#include "wx/tokenzr.h"
690
691// TOKENIZER1 can be done with wxStringTokenizer
692#define WX_PG_TOKENIZER1_BEGIN(WXSTRING,DELIMITER) \
693 wxStringTokenizer tkz(WXSTRING,DELIMITER,wxTOKEN_RET_EMPTY); \
694 while ( tkz.HasMoreTokens() ) \
695 { \
696 wxString token = tkz.GetNextToken(); \
697 token.Trim(true); \
698 token.Trim(false);
699
700#define WX_PG_TOKENIZER1_END() \
701 }
702
703
704//
705// 2nd version: tokens are surrounded by DELIMITERs (for example, C-style
706// strings). TOKENIZER2 must use custom code (a class) for full compliance with
707// " surrounded strings with \" inside.
708//
709// class implementation is in propgrid.cpp
710//
711
712class WXDLLIMPEXP_PROPGRID wxPGStringTokenizer
713{
714public:
715 wxPGStringTokenizer( const wxString& str, wxChar delimeter );
716 ~wxPGStringTokenizer();
717
718 bool HasMoreTokens(); // not const so we can do some stuff in it
719 wxString GetNextToken();
720
721protected:
722 const wxString* m_str;
723 wxString::const_iterator m_curPos;
724 wxString m_readyToken;
725 wxUniChar m_delimeter;
726};
727
728#define WX_PG_TOKENIZER2_BEGIN(WXSTRING,DELIMITER) \
729 wxPGStringTokenizer tkz(WXSTRING,DELIMITER); \
730 while ( tkz.HasMoreTokens() ) \
731 { \
732 wxString token = tkz.GetNextToken();
733
734#define WX_PG_TOKENIZER2_END() \
735 }
736
1c4293cb
VZ
737// -----------------------------------------------------------------------
738
f4bc1aa2
JS
739#endif // wxUSE_PROPGRID
740
1c4293cb 741#endif // _WX_PROPGRID_PROPGRIDDEFS_H_