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