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