]>
Commit | Line | Data |
---|---|---|
1c4293cb VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/propgrid/props.h | |
3 | // Purpose: wxPropertyGrid Property Classes | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: 2007-03-28 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) Jaakko Salli | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_PROPGRID_PROPS_H_ | |
13 | #define _WX_PROPGRID_PROPS_H_ | |
14 | ||
15 | // ----------------------------------------------------------------------- | |
16 | ||
17 | class wxArrayEditorDialog; | |
18 | ||
19 | #include "wx/propgrid/editors.h" | |
20 | ||
21 | // ----------------------------------------------------------------------- | |
22 | ||
23 | // | |
24 | // Additional property class declaration helper macros | |
25 | // | |
26 | ||
27 | // | |
28 | // Property class implementation helper macros. | |
29 | // | |
30 | ||
31 | #define WX_PG_DECLARE_BASIC_TYPE_METHODS() \ | |
32 | virtual wxString GetValueAsString( int argFlags = 0 ) const; \ | |
33 | virtual bool StringToValue( wxVariant& variant, \ | |
34 | const wxString& text, \ | |
35 | int argFlags = 0 ) const; | |
36 | ||
37 | #define WX_PG_DECLARE_CHOICE_METHODS() \ | |
38 | virtual bool IntToValue( wxVariant& variant, \ | |
39 | int number, int argFlags = 0 ) const; \ | |
40 | virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo ); | |
41 | ||
42 | #define WX_PG_DECLARE_EVENT_METHODS() \ | |
43 | virtual bool OnEvent( wxPropertyGrid* propgrid, \ | |
44 | wxWindow* primary, wxEvent& event ); | |
45 | ||
46 | #define WX_PG_DECLARE_PARENTAL_METHODS() \ | |
47 | virtual void ChildChanged( wxVariant& thisValue, \ | |
48 | int childIndex, wxVariant& childValue ) const; \ | |
49 | virtual void RefreshChildren(); | |
50 | ||
51 | #define WX_PG_DECLARE_CUSTOM_PAINT_METHODS() \ | |
52 | virtual wxSize OnMeasureImage( int item ) const; \ | |
53 | virtual void OnCustomPaint( wxDC& dc, \ | |
54 | const wxRect& rect, wxPGPaintData& paintdata ); | |
55 | ||
56 | #define WX_PG_DECLARE_ATTRIBUTE_METHODS() \ | |
57 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
58 | ||
59 | #define WX_PG_DECLARE_VALIDATOR_METHODS() \ | |
60 | virtual wxValidator* DoGetValidator() const; | |
61 | ||
62 | // Adds constructor function as well. | |
63 | #define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\ | |
64 | UPCLASS,T,T_AS_ARG,EDITOR) \ | |
65 | IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \ | |
66 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR) | |
67 | ||
68 | // A regular property | |
69 | #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \ | |
70 | WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR) | |
71 | ||
72 | #define WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(CLASSNAME) \ | |
73 | DECLARE_DYNAMIC_CLASS(CLASSNAME) | |
74 | ||
75 | // Derived property class is one that inherits from an existing working property | |
76 | // class, but assumes same value and editor type. | |
77 | #define WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,UPNAME,T_AS_ARG) \ | |
78 | IMPLEMENT_DYNAMIC_CLASS(NAME, UPNAME) | |
79 | ||
80 | // ----------------------------------------------------------------------- | |
81 | ||
82 | #define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences | |
83 | #define wxPG_ESCAPE 0 // Escape sequences | |
84 | ||
85 | #define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \ | |
86 | DECL NAME : public wxLongStringProperty \ | |
87 | { \ | |
88 | WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(NAME) \ | |
89 | public: \ | |
90 | NAME( const wxString& name = wxPG_LABEL, \ | |
91 | const wxString& label = wxPG_LABEL, \ | |
92 | const wxString& value = wxEmptyString); \ | |
93 | virtual ~NAME(); \ | |
94 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \ | |
95 | WX_PG_DECLARE_VALIDATOR_METHODS() \ | |
96 | }; | |
97 | ||
98 | #define WX_PG_DECLARE_STRING_PROPERTY(NAME) \ | |
99 | WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \ | |
100 | ||
101 | #define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \ | |
102 | WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,wxLongStringProperty,\ | |
103 | const wxString&) \ | |
104 | NAME::NAME( const wxString& name, \ | |
105 | const wxString& label, \ | |
106 | const wxString& value ) \ | |
107 | : wxLongStringProperty(name,label,value) \ | |
108 | { \ | |
109 | m_flags |= FLAGS; \ | |
110 | } \ | |
111 | NAME::~NAME() { } | |
112 | ||
113 | #define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \ | |
114 | WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \ | |
115 | wxValidator* NAME::DoGetValidator () const \ | |
116 | { return (wxValidator*) NULL; } | |
117 | ||
118 | // ----------------------------------------------------------------------- | |
119 | ||
120 | #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME,DECL) \ | |
121 | DECL CLASSNAME : public wxFlagsProperty \ | |
122 | { \ | |
123 | WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \ | |
124 | public: \ | |
125 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
126 | const wxString& name = wxPG_LABEL, \ | |
127 | long value = -1 ); \ | |
128 | virtual ~CLASSNAME(); \ | |
129 | }; | |
130 | ||
131 | #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(CLASSNAME) \ | |
132 | WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME, class) | |
133 | ||
134 | // This will create interface for wxFlagsProperty derived class | |
135 | // named CLASSNAME. | |
136 | #define WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \ | |
137 | WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME,wxFlagsProperty,long_##CLASSNAME,\ | |
138 | long,TextCtrl) \ | |
139 | CLASSNAME::CLASSNAME( const wxString& label, \ | |
140 | const wxString& name, \ | |
141 | long value ) \ | |
142 | : wxFlagsProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \ | |
143 | { \ | |
144 | m_flags |= wxPG_PROP_STATIC_CHOICES; \ | |
145 | } \ | |
146 | CLASSNAME::~CLASSNAME() { } | |
147 | ||
148 | ||
149 | // ----------------------------------------------------------------------- | |
150 | ||
151 | #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, DECL) \ | |
152 | class CLASSNAME : public wxEnumProperty \ | |
153 | { \ | |
154 | WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \ | |
155 | public: \ | |
156 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
157 | const wxString& name = wxPG_LABEL, \ | |
158 | int value = -1 ); \ | |
159 | virtual ~CLASSNAME(); \ | |
160 | }; | |
161 | ||
162 | #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(CLASSNAME) \ | |
163 | WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, class) | |
164 | ||
165 | #define WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \ | |
166 | WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxEnumProperty, long_##CLASSNAME, \ | |
167 | int, Choice) \ | |
168 | CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, int value ) \ | |
169 | : wxEnumProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \ | |
170 | { \ | |
171 | m_flags |= wxPG_PROP_STATIC_CHOICES; \ | |
172 | } \ | |
173 | CLASSNAME::~CLASSNAME() { } | |
174 | ||
175 | ||
176 | // ----------------------------------------------------------------------- | |
177 | ||
178 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \ | |
179 | DECL CLASSNAME : public wxSystemColourProperty \ | |
180 | { \ | |
181 | DECLARE_DYNAMIC_CLASS(CLASSNAME) \ | |
182 | public: \ | |
183 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
184 | const wxString& name = wxPG_LABEL, \ | |
185 | const wxColourPropertyValue& value = wxColourPropertyValue() ); \ | |
186 | virtual ~CLASSNAME(); \ | |
187 | virtual wxColour GetColour( int index ) const; \ | |
188 | }; | |
189 | ||
190 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \ | |
191 | WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class) | |
192 | ||
193 | #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\ | |
194 | LABELS,VALUES,COLOURS) \ | |
195 | static wxPGChoices gs_##CLASSNAME##_choicesCache; \ | |
196 | WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \ | |
197 | const wxColourPropertyValue&) \ | |
198 | CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \ | |
199 | const wxColourPropertyValue& value ) \ | |
200 | : wxSystemColourProperty(label, name, LABELS, VALUES, \ | |
201 | &gs_##CLASSNAME##_choicesCache, value ) \ | |
202 | { \ | |
203 | m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \ | |
204 | } \ | |
205 | CLASSNAME::~CLASSNAME () { } \ | |
206 | wxColour CLASSNAME::GetColour ( int index ) const \ | |
207 | { \ | |
208 | if ( !m_choices.HasValue(index) ) \ | |
209 | { \ | |
210 | wxASSERT( index < (int)m_choices.GetCount() ); \ | |
211 | return COLOURS[index]; \ | |
212 | } \ | |
213 | return COLOURS[m_choices.GetValue(index)]; \ | |
214 | } | |
215 | ||
216 | // ----------------------------------------------------------------------- | |
217 | ||
218 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\ | |
219 | DECL) \ | |
220 | DECL CLASSNAME : public wxSystemColourProperty \ | |
221 | { \ | |
222 | WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \ | |
223 | public: \ | |
224 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
225 | const wxString& name = wxPG_LABEL, \ | |
226 | const wxColour& value = wxColour() ); \ | |
227 | virtual ~CLASSNAME(); \ | |
228 | virtual wxString GetValueAsString( int argFlags ) const; \ | |
229 | virtual wxColour GetColour( int index ) const; \ | |
230 | virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \ | |
231 | void Init( wxColour colour ); \ | |
232 | }; | |
233 | ||
234 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \ | |
235 | WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class) | |
236 | ||
237 | #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \ | |
238 | LABELS, \ | |
239 | VALUES, \ | |
240 | COLOURS, \ | |
241 | EDITOR) \ | |
242 | static wxPGChoices gs_##CLASSNAME##_choicesCache; \ | |
243 | WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \ | |
244 | wxColour, const wxColour&,EDITOR) \ | |
245 | CLASSNAME::CLASSNAME( const wxString& label, \ | |
246 | const wxString& name, \ | |
247 | const wxColour& value ) \ | |
248 | : wxSystemColourProperty(label, name, LABELS, VALUES, \ | |
249 | &gs_##CLASSNAME##_choicesCache, value ) \ | |
250 | { \ | |
251 | if ( &value ) \ | |
252 | Init( value ); \ | |
253 | else \ | |
254 | Init( *wxWHITE ); \ | |
255 | m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \ | |
256 | } \ | |
257 | CLASSNAME::~CLASSNAME() { } \ | |
258 | void CLASSNAME::Init( wxColour colour ) \ | |
259 | { \ | |
260 | if ( !colour.Ok() ) \ | |
261 | colour = *wxWHITE; \ | |
262 | wxVariant variant; \ | |
263 | variant << colour; \ | |
264 | m_value = variant; \ | |
265 | int ind = ColToInd(colour); \ | |
266 | if ( ind < 0 ) \ | |
267 | ind = m_choices.GetCount() - 1; \ | |
268 | SetIndex( ind ); \ | |
269 | } \ | |
270 | wxString CLASSNAME::GetValueAsString( int argFlags ) const \ | |
271 | { \ | |
272 | const wxPGEditor* editor = GetEditorClass(); \ | |
273 | if ( editor != wxPG_EDITOR(Choice) && \ | |
274 | editor != wxPG_EDITOR(ChoiceAndButton) && \ | |
275 | editor != wxPG_EDITOR(ComboBox) ) \ | |
276 | argFlags |= wxPG_PROPERTY_SPECIFIC; \ | |
277 | return wxSystemColourProperty::GetValueAsString(argFlags); \ | |
278 | } \ | |
279 | wxColour CLASSNAME::GetColour( int index ) const \ | |
280 | { \ | |
281 | if ( !m_choices.HasValue(index) ) \ | |
282 | { \ | |
283 | wxASSERT( index < (int)GetItemCount() ); \ | |
284 | return COLOURS[index]; \ | |
285 | } \ | |
286 | return COLOURS[m_choices.GetValue(index)]; \ | |
287 | } \ | |
288 | wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \ | |
289 | { \ | |
290 | wxVariant variant; \ | |
291 | variant << v.m_colour; \ | |
292 | return variant; \ | |
293 | } | |
294 | ||
295 | ||
296 | #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \ | |
297 | LABELS, \ | |
298 | VALUES, \ | |
299 | COLOURS) \ | |
300 | WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \ | |
301 | LABELS, \ | |
302 | VALUES, \ | |
303 | COLOURS, \ | |
304 | Choice) | |
305 | ||
306 | // ----------------------------------------------------------------------- | |
307 | ||
308 | // | |
309 | // These macros help creating DoGetValidator | |
310 | #define WX_PG_DOGETVALIDATOR_ENTRY() \ | |
311 | static wxValidator* s_ptr = (wxValidator*) NULL; \ | |
312 | if ( s_ptr ) return s_ptr; | |
313 | ||
314 | // Common function exit | |
315 | #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \ | |
316 | s_ptr = VALIDATOR; \ | |
317 | wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \ | |
318 | return VALIDATOR; | |
319 | ||
320 | // ----------------------------------------------------------------------- | |
321 | ||
322 | #ifndef SWIG | |
323 | ||
324 | /** @class wxPGInDialogValidator | |
325 | @ingroup classes | |
326 | Creates and manages a temporary wxTextCtrl for validation purposes. | |
327 | Uses wxPropertyGrid's current editor, if available. | |
328 | */ | |
329 | class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator | |
330 | { | |
331 | public: | |
332 | wxPGInDialogValidator() | |
333 | { | |
334 | m_textCtrl = NULL; | |
335 | } | |
336 | ||
337 | ~wxPGInDialogValidator() | |
338 | { | |
339 | if ( m_textCtrl ) | |
340 | m_textCtrl->Destroy(); | |
341 | } | |
342 | ||
343 | bool DoValidate( wxPropertyGrid* propGrid, | |
344 | wxValidator* validator, | |
345 | const wxString& value ); | |
346 | ||
347 | private: | |
348 | wxTextCtrl* m_textCtrl; | |
349 | }; | |
350 | ||
351 | #endif // SWIG | |
352 | ||
353 | ||
354 | // ----------------------------------------------------------------------- | |
355 | // Property classes | |
356 | // ----------------------------------------------------------------------- | |
357 | ||
358 | #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2 | |
359 | ||
360 | /** @class wxStringProperty | |
361 | @ingroup classes | |
362 | Basic property with string value. | |
363 | ||
364 | <b>Supported special attributes:</b> | |
365 | - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor. | |
366 | ||
367 | @remarks | |
368 | - If value "<composed>" is set, then actual value is formed (or composed) | |
369 | from values of child properties. | |
370 | */ | |
371 | class WXDLLIMPEXP_PROPGRID wxStringProperty : public wxPGProperty | |
372 | { | |
373 | WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty) | |
374 | public: | |
375 | wxStringProperty( const wxString& label = wxPG_LABEL, | |
376 | const wxString& name = wxPG_LABEL, | |
377 | const wxString& value = wxEmptyString ); | |
378 | virtual ~wxStringProperty(); | |
379 | ||
380 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
381 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
382 | ||
383 | /** This is updated so "<composed>" special value can be handled. | |
384 | */ | |
385 | virtual void OnSetValue(); | |
386 | ||
387 | protected: | |
388 | }; | |
389 | ||
390 | // ----------------------------------------------------------------------- | |
391 | ||
392 | #ifndef SWIG | |
393 | /** Constants used with DoValidation() methods. | |
394 | */ | |
395 | enum | |
396 | { | |
397 | /** Instead of modifying the value, show an error message. | |
398 | */ | |
399 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE = 0, | |
400 | ||
401 | /** Modify value, but stick with the limitations. | |
402 | */ | |
403 | wxPG_PROPERTY_VALIDATION_SATURATE = 1, | |
404 | ||
405 | /** Modify value, wrap around on overflow. | |
406 | */ | |
407 | wxPG_PROPERTY_VALIDATION_WRAP = 2 | |
408 | }; | |
409 | #endif | |
410 | ||
411 | // ----------------------------------------------------------------------- | |
412 | ||
413 | /** @class wxIntProperty | |
414 | @ingroup classes | |
415 | Basic property with integer value. | |
416 | ||
417 | Seamlessly supports 64-bit integer (wxLongLong) on overflow. | |
418 | ||
419 | <b>Example how to use seamless 64-bit integer support</b> | |
420 | ||
421 | Getting value: | |
422 | ||
423 | @code | |
424 | wxLongLong_t value = pg->GetPropertyValueAsLongLong(); | |
425 | @endcode | |
426 | ||
427 | or | |
428 | ||
429 | @code | |
430 | wxLongLong_t value; | |
431 | wxVariant variant = property->GetValue(); | |
432 | if ( variant.GetType() == "wxLongLong" ) | |
433 | value = wxLongLongFromVariant(variant); | |
434 | else | |
435 | value = variant.GetLong(); | |
436 | @endcode | |
437 | ||
438 | Setting value: | |
439 | ||
440 | @code | |
441 | pg->SetPropertyValue(longLongVal); | |
442 | @endcode | |
443 | ||
444 | or | |
445 | ||
446 | @code | |
447 | property->SetValue(WXVARIANT(longLongVal)); | |
448 | @endcode | |
449 | ||
450 | ||
451 | <b>Supported special attributes:</b> | |
452 | - "Min", "Max": Specify acceptable value range. | |
453 | */ | |
454 | class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxPGProperty | |
455 | { | |
456 | WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty) | |
457 | public: | |
458 | wxIntProperty( const wxString& label = wxPG_LABEL, | |
459 | const wxString& name = wxPG_LABEL, | |
460 | long value = 0 ); | |
461 | virtual ~wxIntProperty(); | |
462 | ||
463 | wxIntProperty( const wxString& label, | |
464 | const wxString& name, | |
465 | const wxLongLong& value ); | |
466 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
467 | virtual bool ValidateValue( wxVariant& value, | |
468 | wxPGValidationInfo& validationInfo ) const; | |
469 | virtual bool IntToValue( wxVariant& variant, | |
470 | int number, | |
471 | int argFlags = 0 ) const; | |
472 | static wxValidator* GetClassValidator(); | |
473 | virtual wxValidator* DoGetValidator() const; | |
474 | ||
475 | /** Validation helper. | |
476 | */ | |
477 | static bool DoValidation( const wxPGProperty* property, | |
478 | wxLongLong_t& value, | |
479 | wxPGValidationInfo* pValidationInfo, | |
480 | int mode = | |
481 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); | |
482 | ||
483 | protected: | |
484 | }; | |
485 | ||
486 | // ----------------------------------------------------------------------- | |
487 | ||
488 | /** @class wxUIntProperty | |
489 | @ingroup classes | |
490 | Basic property with unsigned integer value. | |
491 | Seamlessly supports 64-bit integer (wxULongLong) on overflow. | |
492 | ||
493 | <b>Supported special attributes:</b> | |
494 | - "Min", "Max": Specify acceptable value range. | |
495 | - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC, | |
496 | wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases | |
497 | are <b>not</b> supported. | |
498 | - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and | |
499 | wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal | |
500 | numbers. | |
501 | ||
502 | @remarks | |
503 | - For example how to use seamless 64-bit integer support, see wxIntProperty | |
504 | documentation (just use wxULongLong instead of wxLongLong). | |
505 | */ | |
506 | class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxPGProperty | |
507 | { | |
508 | WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty) | |
509 | public: | |
510 | wxUIntProperty( const wxString& label = wxPG_LABEL, | |
511 | const wxString& name = wxPG_LABEL, | |
512 | unsigned long value = 0 ); | |
513 | virtual ~wxUIntProperty(); | |
514 | wxUIntProperty( const wxString& label, | |
515 | const wxString& name, | |
516 | const wxULongLong& value ); | |
517 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
518 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
519 | virtual bool ValidateValue( wxVariant& value, | |
520 | wxPGValidationInfo& validationInfo ) const; | |
521 | virtual bool IntToValue( wxVariant& variant, | |
522 | int number, | |
523 | int argFlags = 0 ) const; | |
524 | protected: | |
525 | wxByte m_base; | |
526 | wxByte m_realBase; // translated to 8,16,etc. | |
527 | wxByte m_prefix; | |
528 | private: | |
529 | void Init(); | |
530 | }; | |
531 | ||
532 | // ----------------------------------------------------------------------- | |
533 | ||
534 | /** @class wxFloatProperty | |
535 | @ingroup classes | |
536 | Basic property with double-precision floating point value. | |
537 | ||
538 | <b>Supported special attributes:</b> | |
539 | - "Precision": Sets the (max) precision used when floating point value is | |
540 | rendered as text. The default -1 means infinite precision. | |
541 | */ | |
542 | class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxPGProperty | |
543 | { | |
544 | WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty) | |
545 | public: | |
546 | wxFloatProperty( const wxString& label = wxPG_LABEL, | |
547 | const wxString& name = wxPG_LABEL, | |
548 | double value = 0.0 ); | |
549 | virtual ~wxFloatProperty(); | |
550 | ||
551 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
552 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
553 | virtual bool ValidateValue( wxVariant& value, | |
554 | wxPGValidationInfo& validationInfo ) const; | |
555 | ||
556 | /** Validation helper. | |
557 | */ | |
558 | static bool DoValidation( const wxPGProperty* property, | |
559 | double& value, | |
560 | wxPGValidationInfo* pValidationInfo, | |
561 | int mode = | |
562 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); | |
563 | ||
564 | protected: | |
565 | int m_precision; | |
566 | virtual wxValidator* DoGetValidator () const; | |
567 | }; | |
568 | ||
569 | // ----------------------------------------------------------------------- | |
570 | ||
571 | // Exclude class from wxPython bindings | |
572 | #ifndef SWIG | |
573 | ||
574 | /** @class wxBoolProperty | |
575 | @ingroup classes | |
576 | Basic property with boolean value. | |
577 | ||
578 | <b>Supported special attributes:</b> | |
579 | - "UseCheckbox": Set to 1 to use check box editor instead of combo box. | |
580 | - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list. | |
581 | */ | |
582 | class WXDLLIMPEXP_PROPGRID wxBoolProperty : public wxPGProperty | |
583 | { | |
584 | WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty) | |
585 | public: | |
586 | wxBoolProperty( const wxString& label = wxPG_LABEL, | |
587 | const wxString& name = wxPG_LABEL, | |
588 | bool value = false ); | |
589 | virtual ~wxBoolProperty(); | |
590 | ||
591 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
592 | WX_PG_DECLARE_CHOICE_METHODS() | |
593 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
594 | }; | |
595 | ||
596 | #endif // !SWIG | |
597 | ||
598 | // ----------------------------------------------------------------------- | |
599 | ||
600 | /** @class wxBaseEnumProperty | |
601 | @ingroup classes | |
602 | Derive dynamic custom properties with choices from this class. | |
603 | ||
604 | @remarks | |
605 | - Updating private index is important. You can do this either by calling | |
606 | SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue | |
607 | be called (by not implementing it, or by calling super class function in | |
608 | it) -OR- you can just call SetIndex in OnSetValue. | |
609 | */ | |
610 | class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty : public wxPGProperty | |
611 | { | |
612 | public: | |
613 | wxBaseEnumProperty( const wxString& label = wxPG_LABEL, | |
614 | const wxString& name = wxPG_LABEL ); | |
615 | ||
616 | virtual void OnSetValue(); | |
617 | virtual wxString GetValueAsString( int argFlags ) const; | |
618 | virtual bool StringToValue( wxVariant& variant, | |
619 | const wxString& text, | |
620 | int argFlags = 0 ) const; | |
621 | virtual bool ValidateValue( wxVariant& value, | |
622 | wxPGValidationInfo& validationInfo ) const; | |
623 | ||
624 | // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted | |
625 | // as index to choices list. Otherwise, it is actual value. | |
626 | virtual bool IntToValue( wxVariant& variant, | |
627 | int number, | |
628 | int argFlags = 0 ) const; | |
629 | ||
630 | // | |
631 | // Additional virtuals | |
632 | ||
633 | // This must be overridden to have non-index based value | |
634 | virtual int GetIndexForValue( int value ) const; | |
635 | ||
636 | // This returns string and value for index | |
637 | // Returns NULL if beyond last item | |
638 | // pvalue is never NULL - always set it. | |
639 | virtual const wxString* GetEntry( size_t index, int* pvalue ) const = 0; | |
640 | ||
641 | int GetValueForIndex( size_t index ) const | |
642 | { | |
643 | int v; | |
644 | GetEntry( index, &v ); | |
645 | return v; | |
646 | } | |
647 | ||
648 | protected: | |
649 | ||
650 | int GetIndex() const; | |
651 | void SetIndex( int index ); | |
652 | ||
653 | bool ValueFromString_( wxVariant& value, | |
654 | const wxString& text, | |
655 | int argFlags ) const; | |
656 | bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const; | |
657 | ||
658 | static void ResetNextIndex() { ms_nextIndex = -2; } | |
659 | ||
660 | private: | |
661 | // This is private so that classes are guaranteed to use GetIndex | |
662 | // for up-to-date index value. | |
663 | int m_index; | |
664 | ||
665 | // Relies on ValidateValue being called always before OnSetValue | |
666 | static int ms_nextIndex; | |
667 | }; | |
668 | ||
669 | // ----------------------------------------------------------------------- | |
670 | ||
671 | // If set, then selection of choices is static and should not be | |
672 | // changed (i.e. returns NULL in GetPropertyChoices). | |
673 | #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1 | |
674 | ||
675 | /** @class wxEnumProperty | |
676 | @ingroup classes | |
677 | You can derive custom properties with choices from this class. See | |
678 | wxBaseEnumProperty for remarks. | |
679 | */ | |
680 | class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxBaseEnumProperty | |
681 | { | |
682 | WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty) | |
683 | public: | |
684 | ||
685 | #ifndef SWIG | |
686 | wxEnumProperty( const wxString& label = wxPG_LABEL, | |
687 | const wxString& name = wxPG_LABEL, | |
688 | const wxChar** labels = NULL, | |
689 | const long* values = NULL, | |
690 | int value = 0 ); | |
691 | wxEnumProperty( const wxString& label, | |
692 | const wxString& name, | |
693 | wxPGChoices& choices, | |
694 | int value = 0 ); | |
695 | ||
696 | // Special constructor for caching choices (used by derived class) | |
697 | wxEnumProperty( const wxString& label, | |
698 | const wxString& name, | |
699 | const wxChar** labels, | |
700 | const long* values, | |
701 | wxPGChoices* choicesCache, | |
702 | int value = 0 ); | |
703 | ||
704 | wxEnumProperty( const wxString& label, | |
705 | const wxString& name, | |
706 | const wxArrayString& labels, | |
707 | const wxArrayInt& values = wxArrayInt(), | |
708 | int value = 0 ); | |
709 | #else | |
710 | wxEnumProperty( const wxString& label = wxPG_LABEL, | |
711 | const wxString& name = wxPG_LABEL, | |
712 | const wxArrayString& labels = wxArrayString(), | |
713 | const wxArrayInt& values = wxArrayInt(), | |
714 | int value = 0 ); | |
715 | #endif | |
716 | ||
717 | virtual ~wxEnumProperty(); | |
718 | ||
719 | virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo ); | |
720 | virtual int GetIndexForValue( int value ) const; | |
721 | virtual const wxString* GetEntry( size_t index, int* pvalue ) const; | |
722 | ||
723 | size_t GetItemCount() const { return m_choices.GetCount(); } | |
724 | const wxPGChoices& GetChoices() const { return m_choices; } | |
725 | ||
726 | protected: | |
727 | wxPGChoices m_choices; | |
728 | }; | |
729 | ||
730 | // ----------------------------------------------------------------------- | |
731 | ||
732 | /** @class wxEditEnumProperty | |
733 | @ingroup classes | |
734 | wxEnumProperty with wxString value and writable combo box editor. | |
735 | ||
736 | @remarks | |
737 | Uses int value, similar to wxEnumProperty, unless text entered by user is | |
738 | is not in choices (in which case string value is used). | |
739 | */ | |
740 | class WXDLLIMPEXP_PROPGRID wxEditEnumProperty : public wxEnumProperty | |
741 | { | |
742 | WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty) | |
743 | public: | |
744 | ||
745 | wxEditEnumProperty( const wxString& label, | |
746 | const wxString& name, | |
747 | const wxChar** labels, | |
748 | const long* values, | |
749 | const wxString& value ); | |
750 | wxEditEnumProperty( const wxString& label = wxPG_LABEL, | |
751 | const wxString& name = wxPG_LABEL, | |
752 | const wxArrayString& labels = wxArrayString(), | |
753 | const wxArrayInt& values = wxArrayInt(), | |
754 | const wxString& value = wxEmptyString ); | |
755 | wxEditEnumProperty( const wxString& label, | |
756 | const wxString& name, | |
757 | wxPGChoices& choices, | |
758 | const wxString& value = wxEmptyString ); | |
759 | ||
760 | // Special constructor for caching choices (used by derived class) | |
761 | wxEditEnumProperty( const wxString& label, | |
762 | const wxString& name, | |
763 | const wxChar** labels, | |
764 | const long* values, | |
765 | wxPGChoices* choicesCache, | |
766 | const wxString& value ); | |
767 | ||
768 | virtual ~wxEditEnumProperty(); | |
769 | ||
770 | protected: | |
771 | }; | |
772 | ||
773 | // ----------------------------------------------------------------------- | |
774 | ||
775 | /** @class wxFlagsProperty | |
776 | @ingroup classes | |
777 | Represents a bit set that fits in a long integer. wxBoolProperty | |
778 | sub-properties are created for editing individual bits. Textctrl is created | |
779 | to manually edit the flags as a text; a continous sequence of spaces, | |
780 | commas and semicolons is considered as a flag id separator. | |
781 | <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty, | |
782 | you will need to use SetPropertyChoices - otherwise they will not get | |
783 | updated properly. | |
784 | */ | |
785 | class WXDLLIMPEXP_PROPGRID wxFlagsProperty : public wxPGProperty | |
786 | { | |
787 | WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty) | |
788 | public: | |
789 | ||
790 | #ifndef SWIG | |
791 | wxFlagsProperty( const wxString& label, | |
792 | const wxString& name, | |
793 | const wxChar** labels, | |
794 | const long* values = NULL, | |
795 | long value = 0 ); | |
796 | wxFlagsProperty( const wxString& label, | |
797 | const wxString& name, | |
798 | wxPGChoices& choices, | |
799 | long value = 0 ); | |
800 | #endif | |
801 | wxFlagsProperty( const wxString& label = wxPG_LABEL, | |
802 | const wxString& name = wxPG_LABEL, | |
803 | const wxArrayString& labels = wxArrayString(), | |
804 | const wxArrayInt& values = wxArrayInt(), | |
805 | int value = 0 ); | |
806 | virtual ~wxFlagsProperty (); | |
807 | ||
808 | virtual void OnSetValue(); | |
809 | virtual wxString GetValueAsString( int argFlags ) const; | |
810 | virtual bool StringToValue( wxVariant& variant, | |
811 | const wxString& text, | |
812 | int flags ) const; | |
813 | virtual void ChildChanged( wxVariant& thisValue, | |
814 | int childIndex, | |
815 | wxVariant& childValue ) const; | |
816 | virtual void RefreshChildren(); | |
817 | ||
818 | // this is necessary for conveying m_choices | |
819 | virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo ); | |
820 | ||
821 | // helpers | |
822 | size_t GetItemCount() const { return m_choices.GetCount(); } | |
823 | const wxString& GetLabel( size_t ind ) const | |
824 | { return m_choices.GetLabel(ind); } | |
825 | ||
826 | protected: | |
827 | wxPGChoices m_choices; | |
828 | ||
829 | // Used to detect if choices have been changed | |
830 | wxPGChoicesData* m_oldChoicesData; | |
831 | ||
832 | // Needed to properly mark changed sub-properties | |
833 | long m_oldValue; | |
834 | ||
835 | // Converts string id to a relevant bit. | |
836 | long IdToBit( const wxString& id ) const; | |
837 | ||
838 | // Creates children and sets value. | |
839 | void Init(); | |
840 | }; | |
841 | ||
842 | // ----------------------------------------------------------------------- | |
843 | ||
844 | /** @class wxPGFileDialogAdapter | |
845 | @ingroup classes | |
846 | */ | |
847 | class WXDLLIMPEXP_PROPGRID | |
848 | wxPGFileDialogAdapter : public wxPGEditorDialogAdapter | |
849 | { | |
850 | public: | |
851 | virtual bool DoShowDialog( wxPropertyGrid* propGrid, | |
852 | wxPGProperty* property ); | |
853 | }; | |
854 | ||
855 | // ----------------------------------------------------------------------- | |
856 | ||
857 | #include "wx/filename.h" | |
858 | ||
859 | // Indicates first bit useable by derived properties. | |
860 | #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1 | |
861 | ||
862 | /** @class wxFileProperty | |
863 | @ingroup classes | |
864 | Like wxLongStringProperty, but the button triggers file selector instead. | |
865 | ||
866 | <b>Supported special attributes:</b> | |
867 | - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All | |
868 | files..." is default. | |
869 | - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive | |
870 | and directory are hidden). | |
871 | - "ShowRelativePath": If set, then the filename is shown relative to the | |
872 | given path string. | |
873 | - "InitialPath": Sets the initial path of where to look for files. | |
874 | - "DialogTitle": Sets a specific title for the dir dialog. | |
875 | */ | |
876 | class WXDLLIMPEXP_PROPGRID wxFileProperty : public wxPGProperty | |
877 | { | |
878 | friend class wxPGFileDialogAdapter; | |
879 | WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty) | |
880 | public: | |
881 | ||
882 | wxFileProperty( const wxString& label = wxPG_LABEL, | |
883 | const wxString& name = wxPG_LABEL, | |
884 | const wxString& value = wxEmptyString ); | |
885 | virtual ~wxFileProperty (); | |
886 | ||
887 | virtual void OnSetValue(); | |
888 | virtual wxString GetValueAsString( int argFlags ) const; | |
889 | virtual bool StringToValue( wxVariant& variant, | |
890 | const wxString& text, | |
891 | int argFlags = 0 ) const; | |
892 | virtual wxPGEditorDialogAdapter* GetEditorDialog() const; | |
893 | ||
894 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
895 | ||
896 | static wxValidator* GetClassValidator(); | |
897 | virtual wxValidator* DoGetValidator() const; | |
898 | ||
899 | protected: | |
900 | wxString m_wildcard; | |
901 | wxString m_basePath; // If set, then show path relative to it | |
902 | wxString m_initialPath; // If set, start the file dialog here | |
903 | wxString m_dlgTitle; // If set, used as title for file dialog | |
904 | wxFileName m_filename; // used as primary storage | |
905 | int m_indFilter; // index to the selected filter | |
906 | }; | |
907 | ||
908 | // ----------------------------------------------------------------------- | |
909 | ||
910 | #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1 | |
911 | ||
912 | ||
913 | /** @class wxPGLongStringDialogAdapter | |
914 | @ingroup classes | |
915 | */ | |
916 | class WXDLLIMPEXP_PROPGRID | |
917 | wxPGLongStringDialogAdapter : public wxPGEditorDialogAdapter | |
918 | { | |
919 | public: | |
920 | virtual bool DoShowDialog( wxPropertyGrid* propGrid, | |
921 | wxPGProperty* property ); | |
922 | }; | |
923 | ||
924 | ||
925 | /** @class wxLongStringProperty | |
926 | @ingroup classes | |
927 | Like wxStringProperty, but has a button that triggers a small text | |
928 | editor dialog. | |
929 | */ | |
930 | class WXDLLIMPEXP_PROPGRID wxLongStringProperty : public wxPGProperty | |
931 | { | |
932 | WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty) | |
933 | public: | |
934 | ||
935 | wxLongStringProperty( const wxString& label = wxPG_LABEL, | |
936 | const wxString& name = wxPG_LABEL, | |
937 | const wxString& value = wxEmptyString ); | |
938 | virtual ~wxLongStringProperty(); | |
939 | ||
940 | virtual wxString GetValueAsString( int argFlags = 0 ) const; | |
941 | virtual bool StringToValue( wxVariant& variant, | |
942 | const wxString& text, | |
943 | int argFlags = 0 ) const; | |
944 | ||
945 | WX_PG_DECLARE_EVENT_METHODS() | |
946 | ||
947 | // Shows string editor dialog. Value to be edited should be read from | |
948 | // value, and if dialog is not cancelled, it should be stored back and true | |
949 | // should be returned if that was the case. | |
950 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); | |
951 | ||
952 | static bool DisplayEditorDialog( wxPGProperty* prop, | |
953 | wxPropertyGrid* propGrid, | |
954 | wxString& value ); | |
955 | ||
956 | protected: | |
957 | }; | |
958 | ||
959 | // ----------------------------------------------------------------------- | |
960 | ||
961 | ||
962 | // Exclude class from wxPython bindings | |
963 | #ifndef SWIG | |
964 | ||
965 | /** @class wxDirProperty | |
966 | @ingroup classes | |
967 | Like wxLongStringProperty, but the button triggers dir selector instead. | |
968 | ||
969 | <b>Supported special attributes:</b> | |
970 | - "DialogMessage": Sets specific message in the dir selector. | |
971 | */ | |
972 | class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty | |
973 | { | |
974 | #ifndef SWIG | |
975 | DECLARE_DYNAMIC_CLASS(wxDirProperty) | |
976 | #endif | |
977 | public: | |
978 | wxDirProperty( const wxString& name = wxPG_LABEL, | |
979 | const wxString& label = wxPG_LABEL, | |
980 | const wxString& value = wxEmptyString ); | |
981 | virtual ~wxDirProperty(); | |
982 | ||
983 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
984 | WX_PG_DECLARE_VALIDATOR_METHODS() | |
985 | ||
986 | virtual bool OnButtonClick ( wxPropertyGrid* propGrid, wxString& value ); | |
987 | ||
988 | protected: | |
989 | wxString m_dlgMessage; | |
990 | }; | |
991 | ||
992 | #endif // !SWIG | |
993 | ||
994 | // ----------------------------------------------------------------------- | |
995 | ||
996 | // wxBoolProperty specific flags | |
997 | #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1 | |
998 | // DCC = Double Click Cycles | |
999 | #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2 | |
1000 | ||
1001 | ||
1002 | // ----------------------------------------------------------------------- | |
1003 | ||
1004 | /** @class wxArrayStringProperty | |
1005 | @ingroup classes | |
1006 | Property that manages a list of strings. | |
1007 | */ | |
1008 | class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty | |
1009 | { | |
1010 | WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty) | |
1011 | public: | |
1012 | ||
1013 | wxArrayStringProperty( const wxString& label = wxPG_LABEL, | |
1014 | const wxString& name = wxPG_LABEL, | |
1015 | const wxArrayString& value = wxArrayString() ); | |
1016 | virtual ~wxArrayStringProperty(); | |
1017 | ||
1018 | virtual void OnSetValue(); | |
1019 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
1020 | WX_PG_DECLARE_EVENT_METHODS() | |
1021 | ||
1022 | virtual void GenerateValueAsString(); | |
1023 | ||
1024 | // Shows string editor dialog. Value to be edited should be read from | |
1025 | // value, and if dialog is not cancelled, it should be stored back and true | |
1026 | // should be returned if that was the case. | |
1027 | virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); | |
1028 | ||
1029 | // Helper. | |
1030 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, | |
1031 | wxWindow* primary, | |
1032 | const wxChar* cbt ); | |
1033 | ||
1034 | #ifndef SWIG | |
1035 | // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick. | |
1036 | virtual wxArrayEditorDialog* CreateEditorDialog(); | |
1037 | #endif | |
1038 | ||
1039 | protected: | |
1040 | wxString m_display; // Cache for displayed text. | |
1041 | }; | |
1042 | ||
1043 | // ----------------------------------------------------------------------- | |
1044 | ||
1045 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \ | |
1046 | DECL) \ | |
1047 | DECL PROPNAME : public wxArrayStringProperty \ | |
1048 | { \ | |
1049 | WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \ | |
1050 | public: \ | |
1051 | PROPNAME( const wxString& label = wxPG_LABEL, \ | |
1052 | const wxString& name = wxPG_LABEL, \ | |
1053 | const wxArrayString& value = wxArrayString() ); \ | |
1054 | ~PROPNAME(); \ | |
1055 | virtual void GenerateValueAsString(); \ | |
1056 | virtual bool StringToValue( wxVariant& value, \ | |
1057 | const wxString& text, int = 0 ) const; \ | |
1058 | virtual bool OnEvent( wxPropertyGrid* propgrid, \ | |
1059 | wxWindow* primary, wxEvent& event ); \ | |
1060 | virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \ | |
1061 | WX_PG_DECLARE_VALIDATOR_METHODS() \ | |
1062 | }; | |
1063 | ||
1064 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \ | |
1065 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class) | |
1066 | ||
1067 | #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ | |
1068 | DELIMCHAR, \ | |
1069 | CUSTBUTTXT) \ | |
1070 | WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \ | |
1071 | wxArrayString, const wxArrayString&, \ | |
1072 | TextCtrlAndButton) \ | |
1073 | PROPNAME::PROPNAME( const wxString& label, \ | |
1074 | const wxString& name, \ | |
1075 | const wxArrayString& value ) \ | |
1076 | : wxArrayStringProperty(label,name,value) \ | |
1077 | { \ | |
1078 | PROPNAME::GenerateValueAsString(); \ | |
1079 | } \ | |
1080 | PROPNAME::~PROPNAME() { } \ | |
1081 | void PROPNAME::GenerateValueAsString() \ | |
1082 | { \ | |
1083 | wxChar delimChar = DELIMCHAR; \ | |
1084 | if ( delimChar == wxS('"') ) \ | |
1085 | wxArrayStringProperty::GenerateValueAsString(); \ | |
1086 | else \ | |
1087 | wxPropertyGrid::ArrayStringToString(m_display, \ | |
1088 | m_value.GetArrayString(), \ | |
1089 | 0,DELIMCHAR,0); \ | |
1090 | } \ | |
1091 | bool PROPNAME::StringToValue( wxVariant& variant, \ | |
1092 | const wxString& text, int ) const \ | |
1093 | { \ | |
1094 | wxChar delimChar = DELIMCHAR; \ | |
1095 | if ( delimChar == wxS('"') ) \ | |
1096 | return wxArrayStringProperty::StringToValue(variant, text, 0); \ | |
1097 | \ | |
1098 | wxArrayString arr; \ | |
1099 | WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \ | |
1100 | arr.Add( token ); \ | |
1101 | WX_PG_TOKENIZER1_END() \ | |
1102 | variant = arr; \ | |
1103 | return true; \ | |
1104 | } \ | |
1105 | bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \ | |
1106 | wxWindow* primary, wxEvent& event ) \ | |
1107 | { \ | |
1108 | if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \ | |
1109 | return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \ | |
1110 | return false; \ | |
1111 | } | |
1112 | ||
1113 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \ | |
1114 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME) | |
1115 | ||
1116 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \ | |
1117 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL) | |
1118 | ||
1119 | #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \ | |
1120 | WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ | |
1121 | DELIMCHAR, \ | |
1122 | CUSTBUTTXT) \ | |
1123 | wxValidator* PROPNAME::DoGetValidator () const \ | |
1124 | { return (wxValidator*) NULL; } | |
1125 | ||
1126 | ||
1127 | // ----------------------------------------------------------------------- | |
1128 | // wxArrayEditorDialog | |
1129 | // ----------------------------------------------------------------------- | |
1130 | ||
1131 | #include "wx/textctrl.h" | |
1132 | #include "wx/button.h" | |
1133 | #include "wx/listbox.h" | |
1134 | ||
1135 | #define wxAEDIALOG_STYLE \ | |
1136 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
1137 | ||
1138 | class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog : public wxDialog | |
1139 | { | |
1140 | public: | |
1141 | wxArrayEditorDialog(); | |
1142 | virtual ~wxArrayEditorDialog() { } | |
1143 | ||
1144 | void Init(); | |
1145 | ||
1146 | wxArrayEditorDialog( wxWindow *parent, | |
1147 | const wxString& message, | |
1148 | const wxString& caption, | |
1149 | long style = wxAEDIALOG_STYLE, | |
1150 | const wxPoint& pos = wxDefaultPosition, | |
1151 | const wxSize& sz = wxDefaultSize ); | |
1152 | ||
1153 | bool Create( wxWindow *parent, | |
1154 | const wxString& message, | |
1155 | const wxString& caption, | |
1156 | long style = wxAEDIALOG_STYLE, | |
1157 | const wxPoint& pos = wxDefaultPosition, | |
1158 | const wxSize& sz = wxDefaultSize ); | |
1159 | ||
1160 | /** Set value modified by dialog. | |
1161 | */ | |
1162 | virtual void SetDialogValue( const wxVariant& WXUNUSED(value) ) | |
1163 | { | |
1164 | wxFAIL_MSG(wxT("re-implement this member function in derived class")); | |
1165 | } | |
1166 | ||
1167 | /** Return value modified by dialog. | |
1168 | */ | |
1169 | virtual wxVariant GetDialogValue() const | |
1170 | { | |
1171 | wxFAIL_MSG(wxT("re-implement this member function in derived class")); | |
1172 | return wxVariant(); | |
1173 | } | |
1174 | ||
1175 | /** Override to return wxValidator to be used with the wxTextCtrl | |
1176 | in dialog. Note that the validator is used in the standard | |
1177 | wx way, ie. it immediately prevents user from entering invalid | |
1178 | input. | |
1179 | ||
1180 | @remarks | |
1181 | Dialog frees the validator. | |
1182 | */ | |
1183 | virtual wxValidator* GetTextCtrlValidator() const | |
1184 | { | |
1185 | return (wxValidator*) NULL; | |
1186 | } | |
1187 | ||
1188 | // Returns true if array was actually modified | |
1189 | bool IsModified() const { return m_modified; } | |
1190 | ||
1191 | //const wxArrayString& GetStrings() const { return m_array; } | |
1192 | ||
1193 | // implementation from now on | |
1194 | void OnUpdateClick(wxCommandEvent& event); | |
1195 | void OnAddClick(wxCommandEvent& event); | |
1196 | void OnDeleteClick(wxCommandEvent& event); | |
1197 | void OnListBoxClick(wxCommandEvent& event); | |
1198 | void OnUpClick(wxCommandEvent& event); | |
1199 | void OnDownClick(wxCommandEvent& event); | |
1200 | //void OnCustomEditClick(wxCommandEvent& event); | |
1201 | void OnIdle(wxIdleEvent& event); | |
1202 | ||
1203 | protected: | |
1204 | wxTextCtrl* m_edValue; | |
1205 | wxListBox* m_lbStrings; | |
1206 | ||
1207 | wxButton* m_butAdd; // Button pointers | |
1208 | wxButton* m_butCustom; // required for disabling/enabling changing. | |
1209 | wxButton* m_butUpdate; | |
1210 | wxButton* m_butRemove; | |
1211 | wxButton* m_butUp; | |
1212 | wxButton* m_butDown; | |
1213 | ||
1214 | //wxArrayString m_array; | |
1215 | ||
1216 | const wxChar* m_custBtText; | |
1217 | //wxArrayStringPropertyClass* m_pCallingClass; | |
1218 | ||
1219 | bool m_modified; | |
1220 | ||
1221 | unsigned char m_curFocus; | |
1222 | ||
1223 | // These must be overridden - must return true on success. | |
1224 | virtual wxString ArrayGet( size_t index ) = 0; | |
1225 | virtual size_t ArrayGetCount() = 0; | |
1226 | virtual bool ArrayInsert( const wxString& str, int index ) = 0; | |
1227 | virtual bool ArraySet( size_t index, const wxString& str ) = 0; | |
1228 | virtual void ArrayRemoveAt( int index ) = 0; | |
1229 | virtual void ArraySwap( size_t first, size_t second ) = 0; | |
1230 | ||
1231 | private: | |
1232 | #ifndef SWIG | |
1233 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog) | |
1234 | DECLARE_EVENT_TABLE() | |
1235 | #endif | |
1236 | }; | |
1237 | ||
1238 | // ----------------------------------------------------------------------- | |
1239 | // wxPGArrayStringEditorDialog | |
1240 | // ----------------------------------------------------------------------- | |
1241 | ||
1242 | class WXDLLIMPEXP_PROPGRID | |
1243 | wxPGArrayStringEditorDialog : public wxArrayEditorDialog | |
1244 | { | |
1245 | public: | |
1246 | wxPGArrayStringEditorDialog(); | |
1247 | virtual ~wxPGArrayStringEditorDialog() { } | |
1248 | ||
1249 | void Init(); | |
1250 | ||
1251 | virtual void SetDialogValue( const wxVariant& value ) | |
1252 | { | |
1253 | m_array = value.GetArrayString(); | |
1254 | } | |
1255 | ||
1256 | virtual wxVariant GetDialogValue() const | |
1257 | { | |
1258 | return m_array; | |
1259 | } | |
1260 | ||
1261 | void SetCustomButton( const wxChar* custBtText, wxArrayStringProperty* pcc ) | |
1262 | { | |
1263 | m_custBtText = custBtText; | |
1264 | m_pCallingClass = pcc; | |
1265 | } | |
1266 | ||
1267 | void OnCustomEditClick(wxCommandEvent& event); | |
1268 | ||
1269 | protected: | |
1270 | wxArrayString m_array; | |
1271 | ||
1272 | wxArrayStringProperty* m_pCallingClass; | |
1273 | ||
1274 | virtual wxString ArrayGet( size_t index ); | |
1275 | virtual size_t ArrayGetCount(); | |
1276 | virtual bool ArrayInsert( const wxString& str, int index ); | |
1277 | virtual bool ArraySet( size_t index, const wxString& str ); | |
1278 | virtual void ArrayRemoveAt( int index ); | |
1279 | virtual void ArraySwap( size_t first, size_t second ); | |
1280 | ||
1281 | private: | |
1282 | #ifndef SWIG | |
1283 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog) | |
1284 | DECLARE_EVENT_TABLE() | |
1285 | #endif | |
1286 | }; | |
1287 | ||
1288 | // ----------------------------------------------------------------------- | |
1289 | ||
1290 | #endif // _WX_PROPGRID_PROPS_H_ |