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