]>
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 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) Jaakko Salli | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_PROPGRID_PROPGRIDDEFS_H_ | |
13 | #define _WX_PROPGRID_PROPGRIDDEFS_H_ | |
14 | ||
15 | #include "wx/dynarray.h" | |
16 | #include "wx/hashmap.h" | |
17 | #include "wx/variant.h" | |
18 | #include "wx/longlong.h" | |
19 | #include "wx/clntdata.h" | |
20 | ||
21 | // ----------------------------------------------------------------------- | |
22 | ||
23 | // | |
24 | // Here are some platform dependent defines | |
25 | // NOTE: More in propertygrid.cpp | |
26 | // | |
27 | ||
28 | #ifndef SWIG | |
29 | ||
30 | #if defined(__WXMSW__) | |
31 | ||
32 | // space between vertical line and value text | |
33 | #define wxPG_XBEFORETEXT 4 | |
34 | // space between vertical line and value editor control | |
35 | #define wxPG_XBEFOREWIDGET 1 | |
36 | ||
37 | // x position adjustment for wxTextCtrl (and like) | |
38 | #define wxPG_TEXTCTRLXADJUST 3 | |
39 | ||
40 | // comment to use bitmap buttons | |
41 | #define wxPG_ICON_WIDTH 9 | |
42 | // 1 if wxRendererNative should be employed | |
43 | #define wxPG_USE_RENDERER_NATIVE 0 | |
44 | ||
45 | // 1 to use double-buffer that guarantees flicker-free painting | |
46 | #define wxPG_DOUBLE_BUFFER 1 | |
47 | ||
48 | // Enable tooltips | |
49 | #define wxPG_SUPPORT_TOOLTIPS 1 | |
50 | ||
51 | // width of optional bitmap/image in front of property | |
52 | #define wxPG_CUSTOM_IMAGE_WIDTH 20 | |
53 | ||
54 | // 1 to create controls out of sight, hide them, and then move them into | |
55 | // correct position | |
56 | #define wxPG_CREATE_CONTROLS_HIDDEN 0 | |
57 | ||
58 | // 1 if splitter drag detect margin and control cannot overlap | |
59 | #define wxPG_NO_CHILD_EVT_MOTION 0 | |
60 | ||
61 | // If 1, then setting empty tooltip actually hides it | |
62 | #define wxPG_ALLOW_EMPTY_TOOLTIPS 1 | |
63 | ||
64 | #define wxPG_NAT_BUTTON_BORDER_ANY 1 | |
65 | #define wxPG_NAT_BUTTON_BORDER_X 1 | |
66 | #define wxPG_NAT_BUTTON_BORDER_Y 1 | |
67 | ||
68 | // If 1 then controls are refreshed after selected was drawn. | |
69 | #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 0 | |
70 | ||
71 | #elif defined(__WXGTK__) | |
72 | ||
73 | // space between vertical line and value text | |
74 | #define wxPG_XBEFORETEXT 5 | |
75 | // space between vertical line and value editor control | |
76 | #define wxPG_XBEFOREWIDGET 1 | |
77 | ||
78 | // x position adjustment for wxTextCtrl (and like) | |
79 | #define wxPG_TEXTCTRLXADJUST 3 | |
80 | ||
81 | // comment to use bitmap buttons | |
82 | #define wxPG_ICON_WIDTH 9 | |
83 | // 1 if wxRendererNative should be employed | |
84 | #define wxPG_USE_RENDERER_NATIVE 0 | |
85 | ||
86 | // 1 to use double-buffer that guarantees flicker-free painting | |
87 | #define wxPG_DOUBLE_BUFFER 1 | |
88 | ||
89 | // Enable tooltips | |
90 | #define wxPG_SUPPORT_TOOLTIPS 1 | |
91 | ||
92 | // width of optional bitmap/image in front of property | |
93 | #define wxPG_CUSTOM_IMAGE_WIDTH 20 | |
94 | ||
95 | // 1 to create controls out of sight, hide them, and then move them into | |
96 | // correct position | |
97 | #define wxPG_CREATE_CONTROLS_HIDDEN 0 | |
98 | ||
99 | // 1 if splitter drag detect margin and control cannot overlap | |
100 | #define wxPG_NO_CHILD_EVT_MOTION 1 | |
101 | ||
102 | // If 1, then setting empty tooltip actually hides it | |
103 | #define wxPG_ALLOW_EMPTY_TOOLTIPS 0 | |
104 | ||
105 | #define wxPG_NAT_BUTTON_BORDER_ANY 1 | |
106 | #define wxPG_NAT_BUTTON_BORDER_X 1 | |
107 | #define wxPG_NAT_BUTTON_BORDER_Y 1 | |
108 | ||
109 | // If 1 then controls are refreshed after selected was drawn. | |
110 | #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 1 | |
111 | ||
112 | #elif defined(__WXMAC__) | |
113 | ||
114 | // space between vertical line and value text | |
115 | #define wxPG_XBEFORETEXT 4 | |
116 | // space between vertical line and value editor widget | |
117 | #define wxPG_XBEFOREWIDGET 1 | |
118 | ||
119 | // x position adjustment for wxTextCtrl (and like) | |
120 | #define wxPG_TEXTCTRLXADJUST 3 | |
121 | ||
122 | // comment to use bitmap buttons | |
123 | #define wxPG_ICON_WIDTH 11 | |
124 | // 1 if wxRendererNative should be employed | |
125 | #define wxPG_USE_RENDERER_NATIVE 1 | |
126 | ||
127 | // 1 to use double-buffer that guarantees flicker-free painting | |
128 | #define wxPG_DOUBLE_BUFFER 0 | |
129 | ||
130 | // Enable tooltips | |
131 | #define wxPG_SUPPORT_TOOLTIPS 1 | |
132 | ||
133 | // width of optional bitmap/image in front of property | |
134 | #define wxPG_CUSTOM_IMAGE_WIDTH 20 | |
135 | ||
136 | // 1 to create controls out of sight, hide them, and then move them into | |
137 | // correct position | |
138 | #define wxPG_CREATE_CONTROLS_HIDDEN 0 | |
139 | ||
140 | // 1 if splitter drag detect margin and control cannot overlap | |
141 | #define wxPG_NO_CHILD_EVT_MOTION 0 | |
142 | ||
143 | // If 1, then setting empty tooltip actually hides it | |
144 | #define wxPG_ALLOW_EMPTY_TOOLTIPS 1 | |
145 | ||
146 | #define wxPG_NAT_BUTTON_BORDER_ANY 0 | |
147 | #define wxPG_NAT_BUTTON_BORDER_X 0 | |
148 | #define wxPG_NAT_BUTTON_BORDER_Y 0 | |
149 | ||
150 | // If 1 then controls are refreshed after selected was drawn. | |
151 | #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 0 | |
152 | ||
153 | #else // defaults | |
154 | ||
155 | // space between vertical line and value text | |
156 | #define wxPG_XBEFORETEXT 5 | |
157 | // space between vertical line and value editor widget | |
158 | #define wxPG_XBEFOREWIDGET 1 | |
159 | ||
160 | // x position adjustment for wxTextCtrl (and like) | |
161 | #define wxPG_TEXTCTRLXADJUST 3 | |
162 | ||
163 | // comment to use bitmap buttons | |
164 | #define wxPG_ICON_WIDTH 9 | |
165 | // 1 if wxRendererNative should be employed | |
166 | #define wxPG_USE_RENDERER_NATIVE 0 | |
167 | ||
168 | // 1 to use double-buffer that guarantees flicker-free painting | |
169 | #define wxPG_DOUBLE_BUFFER 0 | |
170 | ||
171 | // Enable tooltips | |
172 | #define wxPG_SUPPORT_TOOLTIPS 0 | |
173 | ||
174 | // width of optional bitmap/image in front of property | |
175 | #define wxPG_CUSTOM_IMAGE_WIDTH 20 | |
176 | ||
177 | // 1 to create controls out of sight, hide them, and then move them into | |
178 | // correct position | |
179 | #define wxPG_CREATE_CONTROLS_HIDDEN 0 | |
180 | ||
181 | // 1 if splitter drag detect margin and control cannot overlap | |
182 | #define wxPG_NO_CHILD_EVT_MOTION 1 | |
183 | ||
184 | // If 1, then setting empty tooltip actually hides it | |
185 | #define wxPG_ALLOW_EMPTY_TOOLTIPS 0 | |
186 | ||
187 | #define wxPG_NAT_BUTTON_BORDER_ANY 0 | |
188 | #define wxPG_NAT_BUTTON_BORDER_X 0 | |
189 | #define wxPG_NAT_BUTTON_BORDER_Y 0 | |
190 | ||
191 | // If 1 then controls are refreshed after selected was drawn. | |
192 | #define wxPG_REFRESH_CONTROLS_AFTER_REPAINT 1 | |
193 | #endif // platform | |
194 | ||
195 | ||
196 | #define wxPG_CONTROL_MARGIN 0 // space between splitter and control | |
197 | ||
198 | #define wxCC_CUSTOM_IMAGE_MARGIN1 4 // before image | |
199 | #define wxCC_CUSTOM_IMAGE_MARGIN2 5 // after image | |
200 | ||
201 | #define wxPG_DRAG_MARGIN 30 | |
202 | ||
203 | #if wxPG_NO_CHILD_EVT_MOTION | |
204 | #define wxPG_SPLITTERX_DETECTMARGIN1 3 // this much on left | |
205 | #define wxPG_SPLITTERX_DETECTMARGIN2 2 // this much on right | |
206 | #else | |
207 | #define wxPG_SPLITTERX_DETECTMARGIN1 3 // this much on left | |
208 | #define wxPG_SPLITTERX_DETECTMARGIN2 2 // this much on right | |
209 | #endif | |
210 | ||
211 | // Use this macro to generate standard custom image height from | |
212 | #define wxPG_STD_CUST_IMAGE_HEIGHT(LINEHEIGHT) (LINEHEIGHT-3) | |
213 | ||
214 | ||
215 | #if defined(__WXWINCE__) | |
216 | #define wxPG_SMALL_SCREEN 1 | |
217 | #undef wxPG_DOUBLE_BUFFER | |
218 | #define wxPG_DOUBLE_BUFFER 0 | |
219 | #else | |
220 | #define wxPG_SMALL_SCREEN 0 | |
221 | #endif | |
222 | ||
223 | #endif // #ifndef SWIG | |
224 | ||
225 | // Undefine wxPG_ICON_WIDTH to use supplied xpm bitmaps instead | |
226 | // (for tree buttons) | |
227 | //#undef wxPG_ICON_WIDTH | |
228 | ||
229 | // Need to force disable tooltips? | |
230 | #if !wxUSE_TOOLTIPS | |
231 | #undef wxPG_SUPPORT_TOOLTIPS | |
232 | #define wxPG_SUPPORT_TOOLTIPS 0 | |
233 | #endif | |
234 | ||
235 | // Set 1 to include advanced properties (wxFontProperty, wxColourProperty, etc.) | |
236 | #ifndef wxPG_INCLUDE_ADVPROPS | |
237 | #define wxPG_INCLUDE_ADVPROPS 1 | |
238 | #endif | |
239 | ||
240 | // Set 1 to include checkbox editor class | |
241 | #define wxPG_INCLUDE_CHECKBOX 1 | |
242 | ||
243 | // ----------------------------------------------------------------------- | |
244 | ||
245 | ||
246 | // wxPG_CHECK_FOO_DBG - debug check with message that does not | |
247 | // interrupt program flow. | |
248 | #define wxPG_CHECK_RET_DBG(A,B) \ | |
249 | if ( !(A) ) { wxLogWarning(B); return; } | |
250 | #define wxPG_CHECK_MSG_DBG(A,B,C) \ | |
251 | if ( !(A) ) { wxLogWarning(C); return B; } | |
252 | ||
253 | ||
254 | class wxPGEditor; | |
255 | class wxPGProperty; | |
256 | class wxPropertyCategory; | |
257 | class wxPGChoices; | |
258 | class wxPropertyGridPageState; | |
259 | class wxPGCell; | |
260 | class wxPGCellRenderer; | |
261 | class wxPGChoiceEntry; | |
262 | class wxPGPropArgCls; | |
263 | class wxPropertyGridInterface; | |
264 | class wxPropertyGrid; | |
265 | class wxPropertyGridEvent; | |
266 | class wxPropertyGridManager; | |
267 | class wxPGOwnerDrawnComboBox; | |
268 | class wxPGCustomComboControl; | |
269 | class wxPGEditorDialogAdapter; | |
270 | struct wxPGValidationInfo; | |
271 | ||
272 | ||
273 | // ----------------------------------------------------------------------- | |
274 | ||
275 | /** @section propgrid_misc wxPropertyGrid Miscellanous | |
276 | ||
277 | This section describes some miscellanous values, types and macros. | |
278 | @{ | |
279 | */ | |
280 | ||
281 | #ifndef SWIG | |
282 | // Used to tell wxPGProperty to use label as name as well | |
283 | #define wxPG_LABEL (*wxPGProperty::sm_wxPG_LABEL) | |
284 | // This is the value placed in wxPGProperty::sm_wxPG_LABEL | |
285 | #define wxPG_LABEL_STRING wxS("@!") | |
286 | #define wxPG_NULL_BITMAP wxNullBitmap | |
287 | #define wxPG_COLOUR_BLACK (*wxBLACK) | |
288 | #else | |
289 | #define wxPG_NULL_BITMAP wxBitmap_NULL | |
290 | #define wxPG_COLOUR_BLACK wxColour_BLACK | |
291 | #endif // #ifndef SWIG | |
292 | ||
293 | /** Convert Red, Green and Blue to a single 32-bit value. | |
294 | */ | |
295 | #define wxPG_COLOUR(R,G,B) ((wxUint32)(R+(G<<8)+(B<<16))) | |
296 | ||
297 | ||
298 | /** If property is supposed to have custom-painted image, then returning | |
299 | this in OnMeasureImage() will usually be enough. | |
300 | */ | |
301 | #define wxPG_DEFAULT_IMAGE_SIZE wxSize(-1, -1) | |
302 | ||
303 | ||
304 | typedef wxString wxPGCachedString; | |
305 | ||
306 | /** @} | |
307 | */ | |
308 | ||
309 | // ----------------------------------------------------------------------- | |
310 | ||
311 | // Used to indicate wxPGChoices::Add etc that the value is actually not given | |
312 | // by the caller. | |
313 | #define wxPG_INVALID_VALUE INT_MAX | |
314 | ||
315 | // ----------------------------------------------------------------------- | |
316 | ||
317 | #ifndef SWIG | |
318 | ||
319 | #if wxUSE_STL | |
4a84bb72 | 320 | typedef std::vector<wxPGProperty*> wxArrayPGProperty; |
1c4293cb VZ |
321 | #else |
322 | WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(wxPGProperty*, wxArrayPGProperty, | |
323 | wxBaseArrayPtrVoid, | |
324 | class WXDLLIMPEXP_PROPGRID); | |
325 | #endif | |
326 | ||
327 | // Always use wxString based hashmap with unicode, stl, swig and GCC 4.0+ | |
328 | WX_DECLARE_STRING_HASH_MAP_WITH_DECL(void*, | |
329 | wxPGHashMapS2P, | |
330 | class WXDLLIMPEXP_PROPGRID); | |
331 | ||
332 | ||
333 | WX_DECLARE_VOIDPTR_HASH_MAP_WITH_DECL(void*, | |
334 | wxPGHashMapP2P, | |
335 | class WXDLLIMPEXP_PROPGRID); | |
336 | ||
337 | WX_DECLARE_HASH_MAP_WITH_DECL(wxInt32, | |
338 | wxInt32, | |
339 | wxIntegerHash, | |
340 | wxIntegerEqual, | |
341 | wxPGHashMapI2I, | |
342 | class WXDLLIMPEXP_PROPGRID); | |
343 | ||
344 | #endif // #ifndef SWIG | |
345 | ||
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. */ | |
364 | wxPG_FORCE = 0x00000100 | |
365 | ||
366 | }; | |
367 | ||
368 | /** Flags for wxPropertyGrid::SetPropertyAttribute() etc */ | |
369 | #define wxPG_DONT_RECURSE 0x00000000 | |
370 | ||
371 | // ----------------------------------------------------------------------- | |
372 | ||
373 | // Misc argument flags. | |
374 | enum wxPG_MISC_ARG_FLAGS | |
375 | { | |
376 | // Get/Store full value instead of displayed value. | |
377 | wxPG_FULL_VALUE = 0x00000001, | |
378 | ||
379 | wxPG_REPORT_ERROR = 0x00000002, | |
380 | ||
381 | wxPG_PROPERTY_SPECIFIC = 0x00000004, | |
382 | ||
383 | // Get/Store editable value instead of displayed one (should only be | |
384 | // different in the case of common values) | |
385 | wxPG_EDITABLE_VALUE = 0x00000008, | |
386 | ||
387 | // Used when dealing with fragments of composite string value | |
388 | wxPG_COMPOSITE_FRAGMENT = 0x00000010, | |
389 | ||
390 | // Means property for which final string value is for can not really be | |
391 | // edited. | |
392 | wxPG_UNEDITABLE_COMPOSITE_FRAGMENT = 0x00000020 | |
393 | }; | |
394 | ||
395 | // ----------------------------------------------------------------------- | |
396 | ||
397 | // wxPGProperty::SetValue() flags | |
398 | enum wxPG_SETVALUE_FLAGS | |
399 | { | |
400 | wxPG_SETVAL_REFRESH_EDITOR = 0x0001, | |
401 | wxPG_SETVAL_AGGREGATED = 0x0002, | |
8f18b252 JS |
402 | wxPG_SETVAL_FROM_PARENT = 0x0004, |
403 | wxPG_SETVAL_BY_USER = 0x0008 // Set if value changed by user | |
1c4293cb VZ |
404 | }; |
405 | ||
406 | // ----------------------------------------------------------------------- | |
407 | ||
408 | // | |
409 | // Valid constants for wxPG_UINT_BASE attribute | |
410 | // (long because of wxVariant constructor) | |
411 | #define wxPG_BASE_OCT (long)8 | |
412 | #define wxPG_BASE_DEC (long)10 | |
413 | #define wxPG_BASE_HEX (long)16 | |
414 | #define wxPG_BASE_HEXL (long)32 | |
415 | ||
416 | // | |
417 | // Valid constants for wxPG_UINT_PREFIX attribute | |
418 | #define wxPG_PREFIX_NONE (long)0 | |
419 | #define wxPG_PREFIX_0x (long)1 | |
420 | #define wxPG_PREFIX_DOLLAR_SIGN (long)2 | |
421 | ||
422 | // ----------------------------------------------------------------------- | |
423 | // Editor class. | |
424 | ||
425 | #ifndef SWIG | |
426 | ||
427 | // Editor accessor. | |
428 | #define wxPG_EDITOR(T) wxPGEditor_##T | |
429 | ||
430 | // Declare editor class, with optional part. | |
431 | #define WX_PG_DECLARE_EDITOR_WITH_DECL(EDITOR,DECL) \ | |
432 | extern DECL wxPGEditor* wxPGEditor_##EDITOR; \ | |
433 | extern DECL wxPGEditor* wxPGConstruct##EDITOR##EditorClass(); | |
434 | ||
435 | // Declare editor class. | |
436 | #define WX_PG_DECLARE_EDITOR(EDITOR) \ | |
437 | extern wxPGEditor* wxPGEditor_##EDITOR; \ | |
438 | extern wxPGEditor* wxPGConstruct##EDITOR##EditorClass(); | |
439 | ||
440 | // Declare builtin editor classes. | |
441 | WX_PG_DECLARE_EDITOR_WITH_DECL(TextCtrl,WXDLLIMPEXP_PROPGRID) | |
442 | WX_PG_DECLARE_EDITOR_WITH_DECL(Choice,WXDLLIMPEXP_PROPGRID) | |
443 | WX_PG_DECLARE_EDITOR_WITH_DECL(ComboBox,WXDLLIMPEXP_PROPGRID) | |
444 | WX_PG_DECLARE_EDITOR_WITH_DECL(TextCtrlAndButton,WXDLLIMPEXP_PROPGRID) | |
445 | #if wxPG_INCLUDE_CHECKBOX | |
446 | WX_PG_DECLARE_EDITOR_WITH_DECL(CheckBox,WXDLLIMPEXP_PROPGRID) | |
447 | #endif | |
448 | WX_PG_DECLARE_EDITOR_WITH_DECL(ChoiceAndButton,WXDLLIMPEXP_PROPGRID) | |
449 | ||
450 | #endif // !SWIG | |
451 | ||
452 | // ----------------------------------------------------------------------- | |
453 | ||
454 | #ifndef SWIG | |
455 | ||
456 | /** @class wxPGVariantData | |
457 | @ingroup classes | |
458 | wxVariantData with additional functionality. | |
459 | ||
460 | It is usually enough to use supplied to macros to automatically generate | |
461 | variant data class. Like so: | |
462 | ||
463 | @code | |
464 | ||
465 | // In header | |
466 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataMyClass, // Name of the class | |
467 | MyClass, // Name of the data type | |
468 | wxEMPTY_PARAMETER_VALUE) // Declaration | |
469 | ||
470 | // In source | |
471 | WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataMyClass, MyClass) | |
472 | ||
473 | @endcode | |
474 | ||
475 | If your class is derived from wxObject, it is recommended that you use | |
476 | wxObject-versions of the macros (WX_PG_DECLARE_WXOBJECT_VARIANT_DATA and | |
477 | WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA). | |
478 | ||
479 | */ | |
480 | class WXDLLIMPEXP_PROPGRID wxPGVariantData : public wxVariantData | |
481 | { | |
482 | public: | |
483 | virtual void* GetValuePtr() = 0; | |
484 | virtual wxVariant GetDefaultValue() const = 0; | |
485 | protected: | |
486 | }; | |
487 | ||
488 | ||
489 | // | |
490 | // With wxWidgets 2.9 and later we demand native C++ RTTI support | |
491 | #ifdef wxNO_RTTI | |
492 | #error "You need to enable compiler RTTI support for wxPropertyGrid" | |
493 | #endif | |
494 | #define WX_PG_DECLARE_DYNAMIC_CLASS_VARIANTDATA(A) | |
495 | #define WX_PG_IMPLEMENT_DYNAMIC_CLASS_VARIANTDATA(A, B) | |
496 | typedef const std::type_info* wxPGVariantDataClassInfo; | |
497 | #define wxPGVariantDataGetClassInfo(A) (&typeid(*A)) | |
498 | #define wxPG_VARIANT_EQ(A, B) \ | |
499 | ( ((A).GetData() && \ | |
500 | (B).GetData() && typeid(*(A).GetData()) == typeid(*(B).GetData()) && \ | |
501 | (A == B)) || !((A).GetData() && (B).GetData()) ) | |
502 | ||
503 | #ifndef wxDynamicCastVariantData | |
504 | #define wxDynamicCastVariantData wxDynamicCast | |
505 | #endif | |
506 | ||
507 | ||
508 | inline void wxPGDoesNothing() {} | |
509 | ||
510 | ||
511 | #define _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, \ | |
512 | DATATYPE, \ | |
513 | AS_ARG, \ | |
514 | AS_ARG_CONST, \ | |
515 | CTOR_CODE, \ | |
516 | DEFAULT_VALUE, \ | |
517 | SET_CODE) \ | |
518 | WX_PG_DECLARE_DYNAMIC_CLASS_VARIANTDATA(CLASSNAME) \ | |
519 | protected: \ | |
520 | DATATYPE m_value; \ | |
521 | public: \ | |
522 | CLASSNAME() { CTOR_CODE; } \ | |
523 | CLASSNAME(AS_ARG_CONST value) { CTOR_CODE; SET_CODE; m_value = value; } \ | |
524 | DATATYPE GetValue() const { return m_value; } \ | |
525 | AS_ARG_CONST GetValueRef() const { return m_value; } \ | |
526 | AS_ARG GetValueRef() { return m_value; } \ | |
527 | void SetValue(AS_ARG_CONST value) { SET_CODE; m_value = value; } \ | |
528 | virtual bool Eq(wxVariantData&) const { return false; } \ | |
529 | virtual wxString GetType() const { return wxS(#DATATYPE); } \ | |
530 | virtual wxVariantData* Clone() { return new CLASSNAME; } \ | |
531 | virtual bool Read(wxString &) { return false; } \ | |
532 | virtual bool Write(wxString &) const { return true; } \ | |
533 | virtual wxVariant GetDefaultValue() const { return DEFAULT_VALUE; } | |
534 | ||
535 | // | |
536 | // Macro WXVARIANT allows creation of wxVariant from any type supported by | |
537 | // wxWidgets internally, and of all types created using | |
538 | // WX_PG_DECLARE_VARIANT_DATA. | |
539 | template<class T> | |
540 | wxVariant WXVARIANT( const T& value ) | |
541 | { | |
542 | return wxVariant((void*)&value); | |
543 | } | |
544 | ||
545 | template<> inline wxVariant WXVARIANT( const int& value ) | |
546 | { return wxVariant((long)value); } | |
547 | template<> inline wxVariant WXVARIANT( const long& value ) | |
548 | { return wxVariant(value); } | |
549 | template<> inline wxVariant WXVARIANT( const bool& value ) | |
550 | { return wxVariant(value); } | |
551 | template<> inline wxVariant WXVARIANT( const double& value ) | |
552 | { return wxVariant(value); } | |
553 | template<> inline wxVariant WXVARIANT( const wxArrayString& value ) | |
554 | { return wxVariant(value); } | |
555 | template<> inline wxVariant WXVARIANT( const wxString& value ) | |
556 | { return wxVariant(value); } | |
557 | #if wxUSE_DATETIME | |
558 | template<> inline wxVariant WXVARIANT( const wxDateTime& value ) | |
559 | { return wxVariant(value); } | |
560 | #endif | |
561 | ||
562 | #define _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME) \ | |
563 | extern int CLASSNAME##_d_; | |
564 | #define _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER(CLASSNAME) \ | |
565 | int CLASSNAME##_d_; | |
566 | ||
567 | #define _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, \ | |
568 | DATATYPE, \ | |
569 | AS_ARG, \ | |
570 | AS_CONST_ARG, \ | |
571 | NULLVAL, \ | |
572 | BASECLASS) \ | |
573 | _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER(CLASSNAME) \ | |
574 | WX_PG_IMPLEMENT_DYNAMIC_CLASS_VARIANTDATA(CLASSNAME, BASECLASS) \ | |
575 | AS_ARG operator <<( AS_ARG value, const wxVariant &variant ) \ | |
576 | { \ | |
577 | CLASSNAME *data = wxDynamicCastVariantData( variant.GetData(), CLASSNAME ); \ | |
578 | wxASSERT( data ); \ | |
579 | value = data->GetValue(); \ | |
580 | return value; \ | |
581 | } \ | |
582 | wxVariant& operator <<( wxVariant &variant, AS_CONST_ARG value ) \ | |
583 | { \ | |
584 | CLASSNAME *data = new CLASSNAME( value ); \ | |
585 | variant.SetData( data ); \ | |
586 | return variant; \ | |
587 | } \ | |
588 | AS_ARG DATATYPE##FromVariant( const wxVariant& v ) \ | |
589 | { \ | |
590 | CLASSNAME *data = wxDynamicCastVariantData( v.GetData(), CLASSNAME ); \ | |
591 | if ( !data ) \ | |
592 | return NULLVAL; \ | |
593 | return data->GetValueRef(); \ | |
594 | } \ | |
595 | wxVariant DATATYPE##ToVariant( AS_CONST_ARG value ) \ | |
596 | { \ | |
597 | wxVariant variant( new CLASSNAME( value ) ); \ | |
598 | return variant; \ | |
599 | } | |
600 | ||
601 | #define WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE) \ | |
602 | class CLASSNAME : public wxPGVariantData \ | |
603 | { \ | |
604 | _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE, DATATYPE&, \ | |
605 | const DATATYPE&, wxPGDoesNothing(), \ | |
606 | wxVariant(new CLASSNAME(DATATYPE())), \ | |
607 | wxPGDoesNothing()) \ | |
608 | public: \ | |
609 | virtual void* GetValuePtr() { return (void*)&m_value; } \ | |
610 | }; \ | |
611 | _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, \ | |
612 | DATATYPE, \ | |
613 | DATATYPE&, \ | |
614 | const DATATYPE&, \ | |
615 | (DATATYPE&)*((DATATYPE*)NULL), \ | |
616 | wxPGVariantData) | |
617 | ||
618 | #define WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(CLASSNAME, DATATYPE) \ | |
619 | class CLASSNAME : public wxPGVariantData \ | |
620 | { \ | |
621 | _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE, DATATYPE&, \ | |
622 | const DATATYPE&, wxPGDoesNothing(), \ | |
623 | wxVariant(new CLASSNAME(DATATYPE())), \ | |
624 | wxPGDoesNothing()) \ | |
625 | public: \ | |
626 | virtual void* GetValuePtr() { return (void*)&m_value; } \ | |
627 | virtual wxClassInfo* GetValueClassInfo() \ | |
628 | { return m_value.GetClassInfo(); } \ | |
629 | }; \ | |
630 | _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE, DATATYPE&, \ | |
631 | const DATATYPE&, \ | |
632 | (DATATYPE&)*((DATATYPE*)NULL), \ | |
633 | wxPGVariantData) | |
634 | ||
635 | ||
636 | #define WX_PG_DECLARE_VARIANT_DATA(CLASSNAME, DATATYPE, DECL) \ | |
637 | DECL DATATYPE& operator <<( DATATYPE& value, const wxVariant &variant ); \ | |
638 | DECL wxVariant& operator <<( wxVariant &variant, const DATATYPE& value ); \ | |
639 | DECL DATATYPE& DATATYPE##FromVariant( const wxVariant& variant ); \ | |
640 | DECL wxVariant DATATYPE##ToVariant( const DATATYPE& value ); \ | |
641 | template<> inline wxVariant WXVARIANT( const DATATYPE& value ) \ | |
642 | { return DATATYPE##ToVariant(value); } \ | |
643 | DECL _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME); | |
644 | ||
645 | #define WX_PG_DECLARE_WXOBJECT_VARIANT_DATA WX_PG_DECLARE_VARIANT_DATA | |
646 | ||
647 | #define WX_PG_DECLARE_PTR_VARIANT_DATA(CLASSNAME, DATATYPE, DECL) \ | |
648 | DECL DATATYPE* operator <<( DATATYPE* value, const wxVariant &variant ); \ | |
649 | DECL wxVariant& operator <<( wxVariant &variant, DATATYPE* value ); \ | |
650 | DECL DATATYPE* DATATYPE##FromVariant( const wxVariant& variant ); \ | |
651 | DECL wxVariant DATATYPE##ToVariant( DATATYPE* value ); \ | |
652 | DECL _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME); | |
653 | ||
654 | ||
655 | #define WX_PG_IMPLEMENT_PTR_VARIANT_DATA(CLASSNAME, DATATYPE, DEFAULT) \ | |
656 | class CLASSNAME : public wxPGVariantData \ | |
657 | { \ | |
658 | _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE*, DATATYPE*, \ | |
659 | DATATYPE*, m_value = NULL, \ | |
660 | DEFAULT, \ | |
661 | if (m_value) Py_DECREF(m_value); \ | |
662 | if (!value) value = Py_None; \ | |
663 | Py_INCREF(value) ) \ | |
664 | ~CLASSNAME() { if (m_value) Py_DECREF(m_value); } \ | |
665 | public: \ | |
666 | virtual void* GetValuePtr() { return (void*)m_value; } \ | |
667 | }; \ | |
668 | _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE, DATATYPE*, DATATYPE*, \ | |
669 | NULL, wxPGVariantData) | |
670 | ||
671 | ||
672 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataPoint, wxPoint, WXDLLIMPEXP_PROPGRID) | |
673 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataSize, wxSize, WXDLLIMPEXP_PROPGRID) | |
674 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataArrayInt, | |
675 | wxArrayInt, WXDLLIMPEXP_PROPGRID) | |
676 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataLongLong, | |
677 | wxLongLong, WXDLLIMPEXP_PROPGRID) | |
678 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataULongLong, | |
679 | wxULongLong, WXDLLIMPEXP_PROPGRID) | |
680 | ||
681 | WX_PG_DECLARE_WXOBJECT_VARIANT_DATA(wxPGVariantDataFont, | |
682 | wxFont, WXDLLIMPEXP_PROPGRID) | |
683 | template<> inline wxVariant WXVARIANT( const wxColour& value ) | |
684 | { | |
685 | wxVariant variant; | |
686 | variant << value; | |
687 | return variant; | |
688 | } | |
689 | ||
690 | #define WX_PG_VARIANT_GETVALUEREF(P, T) \ | |
691 | (*((T*)((wxPGVariantData*)(P.GetData()))->GetValuePtr())) | |
692 | ||
693 | // Safely converts a wxVariant to (long) int. Supports converting from string | |
694 | // and boolean as well. | |
695 | WXDLLIMPEXP_PROPGRID | |
696 | long wxPGVariantToInt( const wxVariant& variant, long defVal = 1 ); | |
697 | ||
698 | // Safely converts a wxVariant to wxLongLong_t. Returns true on success. | |
699 | WXDLLIMPEXP_PROPGRID | |
700 | bool wxPGVariantToLongLong( const wxVariant& variant, wxLongLong_t* pResult ); | |
701 | ||
702 | // Safely converts a wxVariant to wxULongLong_t. Returns true on success. | |
703 | WXDLLIMPEXP_PROPGRID | |
704 | bool wxPGVariantToULongLong( const wxVariant& variant, wxULongLong_t* pResult ); | |
705 | ||
706 | // Safely converts a wxVariant to double. Supports converting from string and | |
707 | // wxLongLong as well. | |
708 | WXDLLIMPEXP_PROPGRID | |
709 | bool wxPGVariantToDouble( const wxVariant& variant, double* pResult ); | |
710 | ||
711 | #endif // !SWIG | |
712 | ||
713 | // ----------------------------------------------------------------------- | |
714 | ||
715 | #ifndef SWIG | |
716 | ||
717 | WXDLLIMPEXP_PROPGRID | |
718 | wxObject* | |
719 | wxPG_VariantToWxObject( const wxVariant& variant, wxClassInfo* classInfo ); | |
720 | ||
721 | // | |
722 | // Redefine wxGetVariantCast to also take propertygrid variantdata | |
723 | // classes into account. | |
724 | // | |
725 | #undef wxGetVariantCast | |
726 | #define wxGetVariantCast(var,classname) \ | |
727 | (classname*)wxPG_VariantToWxObject(var,&classname::ms_classInfo) | |
728 | ||
729 | // TODO: After a while, remove this. | |
730 | #define WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) \ | |
731 | (CLASSNAME*)wxPG_VariantToWxObject(VARIANT,&CLASSNAME::ms_classInfo) | |
732 | ||
733 | #endif // !SWIG | |
734 | ||
735 | // ----------------------------------------------------------------------- | |
736 | ||
737 | #ifndef SWIG | |
738 | ||
739 | // | |
740 | // Tokenizer macros. | |
741 | // NOTE: I have made two versions - worse ones (performance and consistency | |
742 | // wise) use wxStringTokenizer and better ones (may have unfound bugs) | |
743 | // use custom code. | |
744 | // | |
745 | ||
746 | #include "wx/tokenzr.h" | |
747 | ||
748 | // TOKENIZER1 can be done with wxStringTokenizer | |
749 | #define WX_PG_TOKENIZER1_BEGIN(WXSTRING,DELIMITER) \ | |
750 | wxStringTokenizer tkz(WXSTRING,DELIMITER,wxTOKEN_RET_EMPTY); \ | |
751 | while ( tkz.HasMoreTokens() ) \ | |
752 | { \ | |
753 | wxString token = tkz.GetNextToken(); \ | |
754 | token.Trim(true); \ | |
755 | token.Trim(false); | |
756 | ||
757 | #define WX_PG_TOKENIZER1_END() \ | |
758 | } | |
759 | ||
760 | ||
761 | // | |
762 | // 2nd version: tokens are surrounded by DELIMITERs (for example, C-style | |
763 | // strings). TOKENIZER2 must use custom code (a class) for full compliance with | |
764 | // " surrounded strings with \" inside. | |
765 | // | |
766 | // class implementation is in propgrid.cpp | |
767 | // | |
768 | ||
769 | class WXDLLIMPEXP_PROPGRID wxPGStringTokenizer | |
770 | { | |
771 | public: | |
772 | wxPGStringTokenizer( const wxString& str, wxChar delimeter ); | |
773 | ~wxPGStringTokenizer(); | |
774 | ||
775 | bool HasMoreTokens(); // not const so we can do some stuff in it | |
776 | wxString GetNextToken(); | |
777 | ||
778 | protected: | |
779 | const wxString* m_str; | |
780 | wxString::const_iterator m_curPos; | |
781 | wxString m_readyToken; | |
782 | wxUniChar m_delimeter; | |
783 | }; | |
784 | ||
785 | #define WX_PG_TOKENIZER2_BEGIN(WXSTRING,DELIMITER) \ | |
786 | wxPGStringTokenizer tkz(WXSTRING,DELIMITER); \ | |
787 | while ( tkz.HasMoreTokens() ) \ | |
788 | { \ | |
789 | wxString token = tkz.GetNextToken(); | |
790 | ||
791 | #define WX_PG_TOKENIZER2_END() \ | |
792 | } | |
793 | ||
794 | #endif | |
795 | ||
796 | // ----------------------------------------------------------------------- | |
797 | ||
798 | #endif // _WX_PROPGRID_PROPGRIDDEFS_H_ |