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