]>
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 | |
320 | typedef WXDLLIMPEXP_PROPGRID std::vector<wxPGProperty*> wxArrayPGProperty; | |
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, | |
402 | wxPG_SETVAL_FROM_PARENT = 0x0004 | |
403 | }; | |
404 | ||
405 | // ----------------------------------------------------------------------- | |
406 | ||
407 | // | |
408 | // Valid constants for wxPG_UINT_BASE attribute | |
409 | // (long because of wxVariant constructor) | |
410 | #define wxPG_BASE_OCT (long)8 | |
411 | #define wxPG_BASE_DEC (long)10 | |
412 | #define wxPG_BASE_HEX (long)16 | |
413 | #define wxPG_BASE_HEXL (long)32 | |
414 | ||
415 | // | |
416 | // Valid constants for wxPG_UINT_PREFIX attribute | |
417 | #define wxPG_PREFIX_NONE (long)0 | |
418 | #define wxPG_PREFIX_0x (long)1 | |
419 | #define wxPG_PREFIX_DOLLAR_SIGN (long)2 | |
420 | ||
421 | // ----------------------------------------------------------------------- | |
422 | // Editor class. | |
423 | ||
424 | #ifndef SWIG | |
425 | ||
426 | // Editor accessor. | |
427 | #define wxPG_EDITOR(T) wxPGEditor_##T | |
428 | ||
429 | // Declare editor class, with optional part. | |
430 | #define WX_PG_DECLARE_EDITOR_WITH_DECL(EDITOR,DECL) \ | |
431 | extern DECL wxPGEditor* wxPGEditor_##EDITOR; \ | |
432 | extern DECL wxPGEditor* wxPGConstruct##EDITOR##EditorClass(); | |
433 | ||
434 | // Declare editor class. | |
435 | #define WX_PG_DECLARE_EDITOR(EDITOR) \ | |
436 | extern wxPGEditor* wxPGEditor_##EDITOR; \ | |
437 | extern wxPGEditor* wxPGConstruct##EDITOR##EditorClass(); | |
438 | ||
439 | // Declare builtin editor classes. | |
440 | WX_PG_DECLARE_EDITOR_WITH_DECL(TextCtrl,WXDLLIMPEXP_PROPGRID) | |
441 | WX_PG_DECLARE_EDITOR_WITH_DECL(Choice,WXDLLIMPEXP_PROPGRID) | |
442 | WX_PG_DECLARE_EDITOR_WITH_DECL(ComboBox,WXDLLIMPEXP_PROPGRID) | |
443 | WX_PG_DECLARE_EDITOR_WITH_DECL(TextCtrlAndButton,WXDLLIMPEXP_PROPGRID) | |
444 | #if wxPG_INCLUDE_CHECKBOX | |
445 | WX_PG_DECLARE_EDITOR_WITH_DECL(CheckBox,WXDLLIMPEXP_PROPGRID) | |
446 | #endif | |
447 | WX_PG_DECLARE_EDITOR_WITH_DECL(ChoiceAndButton,WXDLLIMPEXP_PROPGRID) | |
448 | ||
449 | #endif // !SWIG | |
450 | ||
451 | // ----------------------------------------------------------------------- | |
452 | ||
453 | #ifndef SWIG | |
454 | ||
455 | /** @class wxPGVariantData | |
456 | @ingroup classes | |
457 | wxVariantData with additional functionality. | |
458 | ||
459 | It is usually enough to use supplied to macros to automatically generate | |
460 | variant data class. Like so: | |
461 | ||
462 | @code | |
463 | ||
464 | // In header | |
465 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataMyClass, // Name of the class | |
466 | MyClass, // Name of the data type | |
467 | wxEMPTY_PARAMETER_VALUE) // Declaration | |
468 | ||
469 | // In source | |
470 | WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataMyClass, MyClass) | |
471 | ||
472 | @endcode | |
473 | ||
474 | If your class is derived from wxObject, it is recommended that you use | |
475 | wxObject-versions of the macros (WX_PG_DECLARE_WXOBJECT_VARIANT_DATA and | |
476 | WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA). | |
477 | ||
478 | */ | |
479 | class WXDLLIMPEXP_PROPGRID wxPGVariantData : public wxVariantData | |
480 | { | |
481 | public: | |
482 | virtual void* GetValuePtr() = 0; | |
483 | virtual wxVariant GetDefaultValue() const = 0; | |
484 | protected: | |
485 | }; | |
486 | ||
487 | ||
488 | // | |
489 | // With wxWidgets 2.9 and later we demand native C++ RTTI support | |
490 | #ifdef wxNO_RTTI | |
491 | #error "You need to enable compiler RTTI support for wxPropertyGrid" | |
492 | #endif | |
493 | #define WX_PG_DECLARE_DYNAMIC_CLASS_VARIANTDATA(A) | |
494 | #define WX_PG_IMPLEMENT_DYNAMIC_CLASS_VARIANTDATA(A, B) | |
495 | typedef const std::type_info* wxPGVariantDataClassInfo; | |
496 | #define wxPGVariantDataGetClassInfo(A) (&typeid(*A)) | |
497 | #define wxPG_VARIANT_EQ(A, B) \ | |
498 | ( ((A).GetData() && \ | |
499 | (B).GetData() && typeid(*(A).GetData()) == typeid(*(B).GetData()) && \ | |
500 | (A == B)) || !((A).GetData() && (B).GetData()) ) | |
501 | ||
502 | #ifndef wxDynamicCastVariantData | |
503 | #define wxDynamicCastVariantData wxDynamicCast | |
504 | #endif | |
505 | ||
506 | ||
507 | inline void wxPGDoesNothing() {} | |
508 | ||
509 | ||
510 | #define _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, \ | |
511 | DATATYPE, \ | |
512 | AS_ARG, \ | |
513 | AS_ARG_CONST, \ | |
514 | CTOR_CODE, \ | |
515 | DEFAULT_VALUE, \ | |
516 | SET_CODE) \ | |
517 | WX_PG_DECLARE_DYNAMIC_CLASS_VARIANTDATA(CLASSNAME) \ | |
518 | protected: \ | |
519 | DATATYPE m_value; \ | |
520 | public: \ | |
521 | CLASSNAME() { CTOR_CODE; } \ | |
522 | CLASSNAME(AS_ARG_CONST value) { CTOR_CODE; SET_CODE; m_value = value; } \ | |
523 | DATATYPE GetValue() const { return m_value; } \ | |
524 | AS_ARG_CONST GetValueRef() const { return m_value; } \ | |
525 | AS_ARG GetValueRef() { return m_value; } \ | |
526 | void SetValue(AS_ARG_CONST value) { SET_CODE; m_value = value; } \ | |
527 | virtual bool Eq(wxVariantData&) const { return false; } \ | |
528 | virtual wxString GetType() const { return wxS(#DATATYPE); } \ | |
529 | virtual wxVariantData* Clone() { return new CLASSNAME; } \ | |
530 | virtual bool Read(wxString &) { return false; } \ | |
531 | virtual bool Write(wxString &) const { return true; } \ | |
532 | virtual wxVariant GetDefaultValue() const { return DEFAULT_VALUE; } | |
533 | ||
534 | // | |
535 | // Macro WXVARIANT allows creation of wxVariant from any type supported by | |
536 | // wxWidgets internally, and of all types created using | |
537 | // WX_PG_DECLARE_VARIANT_DATA. | |
538 | template<class T> | |
539 | wxVariant WXVARIANT( const T& value ) | |
540 | { | |
541 | return wxVariant((void*)&value); | |
542 | } | |
543 | ||
544 | template<> inline wxVariant WXVARIANT( const int& value ) | |
545 | { return wxVariant((long)value); } | |
546 | template<> inline wxVariant WXVARIANT( const long& value ) | |
547 | { return wxVariant(value); } | |
548 | template<> inline wxVariant WXVARIANT( const bool& value ) | |
549 | { return wxVariant(value); } | |
550 | template<> inline wxVariant WXVARIANT( const double& value ) | |
551 | { return wxVariant(value); } | |
552 | template<> inline wxVariant WXVARIANT( const wxArrayString& value ) | |
553 | { return wxVariant(value); } | |
554 | template<> inline wxVariant WXVARIANT( const wxString& value ) | |
555 | { return wxVariant(value); } | |
556 | #if wxUSE_DATETIME | |
557 | template<> inline wxVariant WXVARIANT( const wxDateTime& value ) | |
558 | { return wxVariant(value); } | |
559 | #endif | |
560 | ||
561 | #define _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME) \ | |
562 | extern int CLASSNAME##_d_; | |
563 | #define _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER(CLASSNAME) \ | |
564 | int CLASSNAME##_d_; | |
565 | ||
566 | #define _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, \ | |
567 | DATATYPE, \ | |
568 | AS_ARG, \ | |
569 | AS_CONST_ARG, \ | |
570 | NULLVAL, \ | |
571 | BASECLASS) \ | |
572 | _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER(CLASSNAME) \ | |
573 | WX_PG_IMPLEMENT_DYNAMIC_CLASS_VARIANTDATA(CLASSNAME, BASECLASS) \ | |
574 | AS_ARG operator <<( AS_ARG value, const wxVariant &variant ) \ | |
575 | { \ | |
576 | CLASSNAME *data = wxDynamicCastVariantData( variant.GetData(), CLASSNAME ); \ | |
577 | wxASSERT( data ); \ | |
578 | value = data->GetValue(); \ | |
579 | return value; \ | |
580 | } \ | |
581 | wxVariant& operator <<( wxVariant &variant, AS_CONST_ARG value ) \ | |
582 | { \ | |
583 | CLASSNAME *data = new CLASSNAME( value ); \ | |
584 | variant.SetData( data ); \ | |
585 | return variant; \ | |
586 | } \ | |
587 | AS_ARG DATATYPE##FromVariant( const wxVariant& v ) \ | |
588 | { \ | |
589 | CLASSNAME *data = wxDynamicCastVariantData( v.GetData(), CLASSNAME ); \ | |
590 | if ( !data ) \ | |
591 | return NULLVAL; \ | |
592 | return data->GetValueRef(); \ | |
593 | } \ | |
594 | wxVariant DATATYPE##ToVariant( AS_CONST_ARG value ) \ | |
595 | { \ | |
596 | wxVariant variant( new CLASSNAME( value ) ); \ | |
597 | return variant; \ | |
598 | } | |
599 | ||
600 | #define WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE) \ | |
601 | class CLASSNAME : public wxPGVariantData \ | |
602 | { \ | |
603 | _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE, DATATYPE&, \ | |
604 | const DATATYPE&, wxPGDoesNothing(), \ | |
605 | wxVariant(new CLASSNAME(DATATYPE())), \ | |
606 | wxPGDoesNothing()) \ | |
607 | public: \ | |
608 | virtual void* GetValuePtr() { return (void*)&m_value; } \ | |
609 | }; \ | |
610 | _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, \ | |
611 | DATATYPE, \ | |
612 | DATATYPE&, \ | |
613 | const DATATYPE&, \ | |
614 | (DATATYPE&)*((DATATYPE*)NULL), \ | |
615 | wxPGVariantData) | |
616 | ||
617 | #define WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(CLASSNAME, DATATYPE) \ | |
618 | class CLASSNAME : public wxPGVariantData \ | |
619 | { \ | |
620 | _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE, DATATYPE&, \ | |
621 | const DATATYPE&, wxPGDoesNothing(), \ | |
622 | wxVariant(new CLASSNAME(DATATYPE())), \ | |
623 | wxPGDoesNothing()) \ | |
624 | public: \ | |
625 | virtual void* GetValuePtr() { return (void*)&m_value; } \ | |
626 | virtual wxClassInfo* GetValueClassInfo() \ | |
627 | { return m_value.GetClassInfo(); } \ | |
628 | }; \ | |
629 | _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE, DATATYPE&, \ | |
630 | const DATATYPE&, \ | |
631 | (DATATYPE&)*((DATATYPE*)NULL), \ | |
632 | wxPGVariantData) | |
633 | ||
634 | ||
635 | #define WX_PG_DECLARE_VARIANT_DATA(CLASSNAME, DATATYPE, DECL) \ | |
636 | DECL DATATYPE& operator <<( DATATYPE& value, const wxVariant &variant ); \ | |
637 | DECL wxVariant& operator <<( wxVariant &variant, const DATATYPE& value ); \ | |
638 | DECL DATATYPE& DATATYPE##FromVariant( const wxVariant& variant ); \ | |
639 | DECL wxVariant DATATYPE##ToVariant( const DATATYPE& value ); \ | |
640 | template<> inline wxVariant WXVARIANT( const DATATYPE& value ) \ | |
641 | { return DATATYPE##ToVariant(value); } \ | |
642 | DECL _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME); | |
643 | ||
644 | #define WX_PG_DECLARE_WXOBJECT_VARIANT_DATA WX_PG_DECLARE_VARIANT_DATA | |
645 | ||
646 | #define WX_PG_DECLARE_PTR_VARIANT_DATA(CLASSNAME, DATATYPE, DECL) \ | |
647 | DECL DATATYPE* operator <<( DATATYPE* value, const wxVariant &variant ); \ | |
648 | DECL wxVariant& operator <<( wxVariant &variant, DATATYPE* value ); \ | |
649 | DECL DATATYPE* DATATYPE##FromVariant( const wxVariant& variant ); \ | |
650 | DECL wxVariant DATATYPE##ToVariant( DATATYPE* value ); \ | |
651 | DECL _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME); | |
652 | ||
653 | ||
654 | #define WX_PG_IMPLEMENT_PTR_VARIANT_DATA(CLASSNAME, DATATYPE, DEFAULT) \ | |
655 | class CLASSNAME : public wxPGVariantData \ | |
656 | { \ | |
657 | _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE*, DATATYPE*, \ | |
658 | DATATYPE*, m_value = NULL, \ | |
659 | DEFAULT, \ | |
660 | if (m_value) Py_DECREF(m_value); \ | |
661 | if (!value) value = Py_None; \ | |
662 | Py_INCREF(value) ) \ | |
663 | ~CLASSNAME() { if (m_value) Py_DECREF(m_value); } \ | |
664 | public: \ | |
665 | virtual void* GetValuePtr() { return (void*)m_value; } \ | |
666 | }; \ | |
667 | _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE, DATATYPE*, DATATYPE*, \ | |
668 | NULL, wxPGVariantData) | |
669 | ||
670 | ||
671 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataPoint, wxPoint, WXDLLIMPEXP_PROPGRID) | |
672 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataSize, wxSize, WXDLLIMPEXP_PROPGRID) | |
673 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataArrayInt, | |
674 | wxArrayInt, WXDLLIMPEXP_PROPGRID) | |
675 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataLongLong, | |
676 | wxLongLong, WXDLLIMPEXP_PROPGRID) | |
677 | WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataULongLong, | |
678 | wxULongLong, WXDLLIMPEXP_PROPGRID) | |
679 | ||
680 | WX_PG_DECLARE_WXOBJECT_VARIANT_DATA(wxPGVariantDataFont, | |
681 | wxFont, WXDLLIMPEXP_PROPGRID) | |
682 | template<> inline wxVariant WXVARIANT( const wxColour& value ) | |
683 | { | |
684 | wxVariant variant; | |
685 | variant << value; | |
686 | return variant; | |
687 | } | |
688 | ||
689 | #define WX_PG_VARIANT_GETVALUEREF(P, T) \ | |
690 | (*((T*)((wxPGVariantData*)(P.GetData()))->GetValuePtr())) | |
691 | ||
692 | // Safely converts a wxVariant to (long) int. Supports converting from string | |
693 | // and boolean as well. | |
694 | WXDLLIMPEXP_PROPGRID | |
695 | long wxPGVariantToInt( const wxVariant& variant, long defVal = 1 ); | |
696 | ||
697 | // Safely converts a wxVariant to wxLongLong_t. Returns true on success. | |
698 | WXDLLIMPEXP_PROPGRID | |
699 | bool wxPGVariantToLongLong( const wxVariant& variant, wxLongLong_t* pResult ); | |
700 | ||
701 | // Safely converts a wxVariant to wxULongLong_t. Returns true on success. | |
702 | WXDLLIMPEXP_PROPGRID | |
703 | bool wxPGVariantToULongLong( const wxVariant& variant, wxULongLong_t* pResult ); | |
704 | ||
705 | // Safely converts a wxVariant to double. Supports converting from string and | |
706 | // wxLongLong as well. | |
707 | WXDLLIMPEXP_PROPGRID | |
708 | bool wxPGVariantToDouble( const wxVariant& variant, double* pResult ); | |
709 | ||
710 | #endif // !SWIG | |
711 | ||
712 | // ----------------------------------------------------------------------- | |
713 | ||
714 | #ifndef SWIG | |
715 | ||
716 | WXDLLIMPEXP_PROPGRID | |
717 | wxObject* | |
718 | wxPG_VariantToWxObject( const wxVariant& variant, wxClassInfo* classInfo ); | |
719 | ||
720 | // | |
721 | // Redefine wxGetVariantCast to also take propertygrid variantdata | |
722 | // classes into account. | |
723 | // | |
724 | #undef wxGetVariantCast | |
725 | #define wxGetVariantCast(var,classname) \ | |
726 | (classname*)wxPG_VariantToWxObject(var,&classname::ms_classInfo) | |
727 | ||
728 | // TODO: After a while, remove this. | |
729 | #define WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) \ | |
730 | (CLASSNAME*)wxPG_VariantToWxObject(VARIANT,&CLASSNAME::ms_classInfo) | |
731 | ||
732 | #endif // !SWIG | |
733 | ||
734 | // ----------------------------------------------------------------------- | |
735 | ||
736 | #ifndef SWIG | |
737 | ||
738 | // | |
739 | // Tokenizer macros. | |
740 | // NOTE: I have made two versions - worse ones (performance and consistency | |
741 | // wise) use wxStringTokenizer and better ones (may have unfound bugs) | |
742 | // use custom code. | |
743 | // | |
744 | ||
745 | #include "wx/tokenzr.h" | |
746 | ||
747 | // TOKENIZER1 can be done with wxStringTokenizer | |
748 | #define WX_PG_TOKENIZER1_BEGIN(WXSTRING,DELIMITER) \ | |
749 | wxStringTokenizer tkz(WXSTRING,DELIMITER,wxTOKEN_RET_EMPTY); \ | |
750 | while ( tkz.HasMoreTokens() ) \ | |
751 | { \ | |
752 | wxString token = tkz.GetNextToken(); \ | |
753 | token.Trim(true); \ | |
754 | token.Trim(false); | |
755 | ||
756 | #define WX_PG_TOKENIZER1_END() \ | |
757 | } | |
758 | ||
759 | ||
760 | // | |
761 | // 2nd version: tokens are surrounded by DELIMITERs (for example, C-style | |
762 | // strings). TOKENIZER2 must use custom code (a class) for full compliance with | |
763 | // " surrounded strings with \" inside. | |
764 | // | |
765 | // class implementation is in propgrid.cpp | |
766 | // | |
767 | ||
768 | class WXDLLIMPEXP_PROPGRID wxPGStringTokenizer | |
769 | { | |
770 | public: | |
771 | wxPGStringTokenizer( const wxString& str, wxChar delimeter ); | |
772 | ~wxPGStringTokenizer(); | |
773 | ||
774 | bool HasMoreTokens(); // not const so we can do some stuff in it | |
775 | wxString GetNextToken(); | |
776 | ||
777 | protected: | |
778 | const wxString* m_str; | |
779 | wxString::const_iterator m_curPos; | |
780 | wxString m_readyToken; | |
781 | wxUniChar m_delimeter; | |
782 | }; | |
783 | ||
784 | #define WX_PG_TOKENIZER2_BEGIN(WXSTRING,DELIMITER) \ | |
785 | wxPGStringTokenizer tkz(WXSTRING,DELIMITER); \ | |
786 | while ( tkz.HasMoreTokens() ) \ | |
787 | { \ | |
788 | wxString token = tkz.GetNextToken(); | |
789 | ||
790 | #define WX_PG_TOKENIZER2_END() \ | |
791 | } | |
792 | ||
793 | #endif | |
794 | ||
795 | // ----------------------------------------------------------------------- | |
796 | ||
797 | #endif // _WX_PROPGRID_PROPGRIDDEFS_H_ |