]>
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 | |
ea5af9c5 | 7 | // RCS-ID: $Id$ |
1c4293cb | 8 | // Copyright: (c) Jaakko Salli |
526954c5 | 9 | // Licence: wxWindows licence |
1c4293cb VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_PROPGRID_PROPS_H_ | |
13 | #define _WX_PROPGRID_PROPS_H_ | |
14 | ||
f4bc1aa2 JS |
15 | #if wxUSE_PROPGRID |
16 | ||
1c4293cb VZ |
17 | // ----------------------------------------------------------------------- |
18 | ||
2906967c | 19 | class wxPGArrayEditorDialog; |
1c4293cb VZ |
20 | |
21 | #include "wx/propgrid/editors.h" | |
22 | ||
15096961 JS |
23 | #include "wx/filename.h" |
24 | #include "wx/dialog.h" | |
25 | #include "wx/textctrl.h" | |
26 | #include "wx/button.h" | |
27 | #include "wx/listbox.h" | |
28 | ||
1c4293cb VZ |
29 | // ----------------------------------------------------------------------- |
30 | ||
1c4293cb VZ |
31 | // |
32 | // Property class implementation helper macros. | |
33 | // | |
34 | ||
d61d8cff | 35 | #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME, UPCLASS, T, T_AS_ARG, EDITOR) \ |
1c4293cb | 36 | IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \ |
d61d8cff | 37 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR) |
1c4293cb VZ |
38 | |
39 | // ----------------------------------------------------------------------- | |
40 | ||
41 | // | |
42 | // These macros help creating DoGetValidator | |
43 | #define WX_PG_DOGETVALIDATOR_ENTRY() \ | |
d3b9f782 | 44 | static wxValidator* s_ptr = NULL; \ |
1c4293cb VZ |
45 | if ( s_ptr ) return s_ptr; |
46 | ||
47 | // Common function exit | |
48 | #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \ | |
49 | s_ptr = VALIDATOR; \ | |
f7a094e1 | 50 | wxPGGlobalVars->m_arrValidators.push_back( VALIDATOR ); \ |
1c4293cb VZ |
51 | return VALIDATOR; |
52 | ||
53 | // ----------------------------------------------------------------------- | |
54 | ||
1c4293cb VZ |
55 | /** @class wxPGInDialogValidator |
56 | @ingroup classes | |
57 | Creates and manages a temporary wxTextCtrl for validation purposes. | |
58 | Uses wxPropertyGrid's current editor, if available. | |
59 | */ | |
60 | class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator | |
61 | { | |
62 | public: | |
63 | wxPGInDialogValidator() | |
64 | { | |
65 | m_textCtrl = NULL; | |
66 | } | |
67 | ||
68 | ~wxPGInDialogValidator() | |
69 | { | |
70 | if ( m_textCtrl ) | |
71 | m_textCtrl->Destroy(); | |
72 | } | |
73 | ||
74 | bool DoValidate( wxPropertyGrid* propGrid, | |
75 | wxValidator* validator, | |
76 | const wxString& value ); | |
77 | ||
78 | private: | |
79 | wxTextCtrl* m_textCtrl; | |
80 | }; | |
81 | ||
1c4293cb VZ |
82 | |
83 | // ----------------------------------------------------------------------- | |
84 | // Property classes | |
85 | // ----------------------------------------------------------------------- | |
86 | ||
87 | #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2 | |
88 | ||
89 | /** @class wxStringProperty | |
90 | @ingroup classes | |
91 | Basic property with string value. | |
92 | ||
93 | <b>Supported special attributes:</b> | |
94 | - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor. | |
95 | ||
96 | @remarks | |
97 | - If value "<composed>" is set, then actual value is formed (or composed) | |
98 | from values of child properties. | |
99 | */ | |
100 | class WXDLLIMPEXP_PROPGRID wxStringProperty : public wxPGProperty | |
101 | { | |
102 | WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty) | |
103 | public: | |
104 | wxStringProperty( const wxString& label = wxPG_LABEL, | |
105 | const wxString& name = wxPG_LABEL, | |
106 | const wxString& value = wxEmptyString ); | |
107 | virtual ~wxStringProperty(); | |
108 | ||
1425eca5 | 109 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
7eac5c53 JS |
110 | virtual bool StringToValue( wxVariant& variant, |
111 | const wxString& text, | |
112 | int argFlags = 0 ) const; | |
113 | ||
114 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
1c4293cb VZ |
115 | |
116 | /** This is updated so "<composed>" special value can be handled. | |
117 | */ | |
118 | virtual void OnSetValue(); | |
119 | ||
120 | protected: | |
121 | }; | |
122 | ||
123 | // ----------------------------------------------------------------------- | |
124 | ||
7197bbad | 125 | /** Constants used with NumericValidation<>(). |
1c4293cb | 126 | */ |
7197bbad | 127 | enum wxPGNumericValidationConstants |
1c4293cb VZ |
128 | { |
129 | /** Instead of modifying the value, show an error message. | |
130 | */ | |
131 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE = 0, | |
132 | ||
133 | /** Modify value, but stick with the limitations. | |
134 | */ | |
135 | wxPG_PROPERTY_VALIDATION_SATURATE = 1, | |
136 | ||
137 | /** Modify value, wrap around on overflow. | |
138 | */ | |
139 | wxPG_PROPERTY_VALIDATION_WRAP = 2 | |
140 | }; | |
1c4293cb VZ |
141 | |
142 | // ----------------------------------------------------------------------- | |
143 | ||
144 | /** @class wxIntProperty | |
145 | @ingroup classes | |
146 | Basic property with integer value. | |
147 | ||
148 | Seamlessly supports 64-bit integer (wxLongLong) on overflow. | |
149 | ||
150 | <b>Example how to use seamless 64-bit integer support</b> | |
151 | ||
152 | Getting value: | |
153 | ||
154 | @code | |
155 | wxLongLong_t value = pg->GetPropertyValueAsLongLong(); | |
156 | @endcode | |
157 | ||
158 | or | |
159 | ||
160 | @code | |
161 | wxLongLong_t value; | |
162 | wxVariant variant = property->GetValue(); | |
163 | if ( variant.GetType() == "wxLongLong" ) | |
164 | value = wxLongLongFromVariant(variant); | |
165 | else | |
166 | value = variant.GetLong(); | |
167 | @endcode | |
168 | ||
169 | Setting value: | |
170 | ||
171 | @code | |
172 | pg->SetPropertyValue(longLongVal); | |
173 | @endcode | |
174 | ||
175 | or | |
176 | ||
177 | @code | |
178 | property->SetValue(WXVARIANT(longLongVal)); | |
179 | @endcode | |
180 | ||
181 | ||
182 | <b>Supported special attributes:</b> | |
183 | - "Min", "Max": Specify acceptable value range. | |
184 | */ | |
185 | class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxPGProperty | |
186 | { | |
187 | WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty) | |
188 | public: | |
189 | wxIntProperty( const wxString& label = wxPG_LABEL, | |
190 | const wxString& name = wxPG_LABEL, | |
191 | long value = 0 ); | |
192 | virtual ~wxIntProperty(); | |
193 | ||
194 | wxIntProperty( const wxString& label, | |
195 | const wxString& name, | |
196 | const wxLongLong& value ); | |
1425eca5 | 197 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
7eac5c53 JS |
198 | virtual bool StringToValue( wxVariant& variant, |
199 | const wxString& text, | |
200 | int argFlags = 0 ) const; | |
1c4293cb VZ |
201 | virtual bool ValidateValue( wxVariant& value, |
202 | wxPGValidationInfo& validationInfo ) const; | |
203 | virtual bool IntToValue( wxVariant& variant, | |
204 | int number, | |
205 | int argFlags = 0 ) const; | |
206 | static wxValidator* GetClassValidator(); | |
207 | virtual wxValidator* DoGetValidator() const; | |
208 | ||
209 | /** Validation helper. | |
210 | */ | |
211 | static bool DoValidation( const wxPGProperty* property, | |
212 | wxLongLong_t& value, | |
213 | wxPGValidationInfo* pValidationInfo, | |
214 | int mode = | |
215 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); | |
216 | ||
217 | protected: | |
218 | }; | |
219 | ||
220 | // ----------------------------------------------------------------------- | |
221 | ||
222 | /** @class wxUIntProperty | |
223 | @ingroup classes | |
224 | Basic property with unsigned integer value. | |
225 | Seamlessly supports 64-bit integer (wxULongLong) on overflow. | |
226 | ||
227 | <b>Supported special attributes:</b> | |
228 | - "Min", "Max": Specify acceptable value range. | |
229 | - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC, | |
230 | wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases | |
231 | are <b>not</b> supported. | |
232 | - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and | |
233 | wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal | |
234 | numbers. | |
235 | ||
236 | @remarks | |
237 | - For example how to use seamless 64-bit integer support, see wxIntProperty | |
238 | documentation (just use wxULongLong instead of wxLongLong). | |
239 | */ | |
240 | class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxPGProperty | |
241 | { | |
242 | WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty) | |
243 | public: | |
244 | wxUIntProperty( const wxString& label = wxPG_LABEL, | |
245 | const wxString& name = wxPG_LABEL, | |
246 | unsigned long value = 0 ); | |
247 | virtual ~wxUIntProperty(); | |
248 | wxUIntProperty( const wxString& label, | |
249 | const wxString& name, | |
250 | const wxULongLong& value ); | |
1425eca5 | 251 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
7eac5c53 JS |
252 | virtual bool StringToValue( wxVariant& variant, |
253 | const wxString& text, | |
254 | int argFlags = 0 ) const; | |
255 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
1c4293cb VZ |
256 | virtual bool ValidateValue( wxVariant& value, |
257 | wxPGValidationInfo& validationInfo ) const; | |
258 | virtual bool IntToValue( wxVariant& variant, | |
259 | int number, | |
260 | int argFlags = 0 ) const; | |
261 | protected: | |
262 | wxByte m_base; | |
263 | wxByte m_realBase; // translated to 8,16,etc. | |
264 | wxByte m_prefix; | |
265 | private: | |
266 | void Init(); | |
267 | }; | |
268 | ||
269 | // ----------------------------------------------------------------------- | |
270 | ||
271 | /** @class wxFloatProperty | |
272 | @ingroup classes | |
273 | Basic property with double-precision floating point value. | |
274 | ||
275 | <b>Supported special attributes:</b> | |
276 | - "Precision": Sets the (max) precision used when floating point value is | |
277 | rendered as text. The default -1 means infinite precision. | |
278 | */ | |
279 | class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxPGProperty | |
280 | { | |
281 | WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty) | |
282 | public: | |
283 | wxFloatProperty( const wxString& label = wxPG_LABEL, | |
284 | const wxString& name = wxPG_LABEL, | |
285 | double value = 0.0 ); | |
286 | virtual ~wxFloatProperty(); | |
287 | ||
1425eca5 | 288 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
7eac5c53 JS |
289 | virtual bool StringToValue( wxVariant& variant, |
290 | const wxString& text, | |
291 | int argFlags = 0 ) const; | |
292 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
1c4293cb VZ |
293 | virtual bool ValidateValue( wxVariant& value, |
294 | wxPGValidationInfo& validationInfo ) const; | |
295 | ||
296 | /** Validation helper. | |
297 | */ | |
298 | static bool DoValidation( const wxPGProperty* property, | |
299 | double& value, | |
300 | wxPGValidationInfo* pValidationInfo, | |
301 | int mode = | |
302 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); | |
470f357f | 303 | virtual wxValidator* DoGetValidator () const; |
1c4293cb VZ |
304 | |
305 | protected: | |
306 | int m_precision; | |
1c4293cb VZ |
307 | }; |
308 | ||
309 | // ----------------------------------------------------------------------- | |
310 | ||
1c4293cb VZ |
311 | /** @class wxBoolProperty |
312 | @ingroup classes | |
313 | Basic property with boolean value. | |
314 | ||
315 | <b>Supported special attributes:</b> | |
316 | - "UseCheckbox": Set to 1 to use check box editor instead of combo box. | |
317 | - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list. | |
318 | */ | |
319 | class WXDLLIMPEXP_PROPGRID wxBoolProperty : public wxPGProperty | |
320 | { | |
321 | WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty) | |
322 | public: | |
323 | wxBoolProperty( const wxString& label = wxPG_LABEL, | |
324 | const wxString& name = wxPG_LABEL, | |
325 | bool value = false ); | |
326 | virtual ~wxBoolProperty(); | |
327 | ||
1425eca5 | 328 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
7eac5c53 JS |
329 | virtual bool StringToValue( wxVariant& variant, |
330 | const wxString& text, | |
331 | int argFlags = 0 ) const; | |
332 | virtual bool IntToValue( wxVariant& variant, | |
333 | int number, int argFlags = 0 ) const; | |
334 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
1c4293cb VZ |
335 | }; |
336 | ||
1c4293cb VZ |
337 | // ----------------------------------------------------------------------- |
338 | ||
78f2d746 JS |
339 | // If set, then selection of choices is static and should not be |
340 | // changed (i.e. returns NULL in GetPropertyChoices). | |
341 | #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1 | |
342 | ||
343 | /** @class wxEnumProperty | |
1c4293cb | 344 | @ingroup classes |
78f2d746 JS |
345 | You can derive custom properties with choices from this class. See |
346 | wxBaseEnumProperty for remarks. | |
1c4293cb VZ |
347 | |
348 | @remarks | |
349 | - Updating private index is important. You can do this either by calling | |
350 | SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue | |
351 | be called (by not implementing it, or by calling super class function in | |
352 | it) -OR- you can just call SetIndex in OnSetValue. | |
353 | */ | |
78f2d746 | 354 | class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty |
1c4293cb | 355 | { |
78f2d746 | 356 | WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty) |
1c4293cb | 357 | public: |
78f2d746 JS |
358 | |
359 | #ifndef SWIG | |
360 | wxEnumProperty( const wxString& label = wxPG_LABEL, | |
361 | const wxString& name = wxPG_LABEL, | |
a243da29 | 362 | const wxChar* const* labels = NULL, |
78f2d746 JS |
363 | const long* values = NULL, |
364 | int value = 0 ); | |
365 | wxEnumProperty( const wxString& label, | |
366 | const wxString& name, | |
367 | wxPGChoices& choices, | |
368 | int value = 0 ); | |
369 | ||
370 | // Special constructor for caching choices (used by derived class) | |
371 | wxEnumProperty( const wxString& label, | |
372 | const wxString& name, | |
a243da29 | 373 | const wxChar* const* labels, |
78f2d746 JS |
374 | const long* values, |
375 | wxPGChoices* choicesCache, | |
376 | int value = 0 ); | |
377 | ||
378 | wxEnumProperty( const wxString& label, | |
379 | const wxString& name, | |
380 | const wxArrayString& labels, | |
381 | const wxArrayInt& values = wxArrayInt(), | |
382 | int value = 0 ); | |
383 | #else | |
384 | wxEnumProperty( const wxString& label = wxPG_LABEL, | |
385 | const wxString& name = wxPG_LABEL, | |
386 | const wxArrayString& labels = wxArrayString(), | |
387 | const wxArrayInt& values = wxArrayInt(), | |
388 | int value = 0 ); | |
389 | #endif | |
390 | ||
391 | virtual ~wxEnumProperty(); | |
392 | ||
393 | size_t GetItemCount() const { return m_choices.GetCount(); } | |
1c4293cb VZ |
394 | |
395 | virtual void OnSetValue(); | |
1425eca5 | 396 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
1c4293cb VZ |
397 | virtual bool StringToValue( wxVariant& variant, |
398 | const wxString& text, | |
399 | int argFlags = 0 ) const; | |
400 | virtual bool ValidateValue( wxVariant& value, | |
401 | wxPGValidationInfo& validationInfo ) const; | |
402 | ||
403 | // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted | |
404 | // as index to choices list. Otherwise, it is actual value. | |
405 | virtual bool IntToValue( wxVariant& variant, | |
406 | int number, | |
407 | int argFlags = 0 ) const; | |
408 | ||
409 | // | |
410 | // Additional virtuals | |
411 | ||
412 | // This must be overridden to have non-index based value | |
413 | virtual int GetIndexForValue( int value ) const; | |
414 | ||
939d9364 JS |
415 | // GetChoiceSelection needs to overridden since m_index is |
416 | // the true index, and various property classes derived from | |
417 | // this take advantage of it. | |
418 | virtual int GetChoiceSelection() const { return m_index; } | |
419 | ||
d8812c6e JS |
420 | virtual void OnValidationFailure( wxVariant& pendingValue ); |
421 | ||
1c4293cb VZ |
422 | protected: |
423 | ||
424 | int GetIndex() const; | |
425 | void SetIndex( int index ); | |
426 | ||
427 | bool ValueFromString_( wxVariant& value, | |
428 | const wxString& text, | |
429 | int argFlags ) const; | |
430 | bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const; | |
431 | ||
432 | static void ResetNextIndex() { ms_nextIndex = -2; } | |
433 | ||
434 | private: | |
435 | // This is private so that classes are guaranteed to use GetIndex | |
436 | // for up-to-date index value. | |
437 | int m_index; | |
438 | ||
439 | // Relies on ValidateValue being called always before OnSetValue | |
440 | static int ms_nextIndex; | |
441 | }; | |
442 | ||
443 | // ----------------------------------------------------------------------- | |
444 | ||
1c4293cb VZ |
445 | /** @class wxEditEnumProperty |
446 | @ingroup classes | |
447 | wxEnumProperty with wxString value and writable combo box editor. | |
448 | ||
449 | @remarks | |
450 | Uses int value, similar to wxEnumProperty, unless text entered by user is | |
451 | is not in choices (in which case string value is used). | |
452 | */ | |
453 | class WXDLLIMPEXP_PROPGRID wxEditEnumProperty : public wxEnumProperty | |
454 | { | |
455 | WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty) | |
456 | public: | |
457 | ||
458 | wxEditEnumProperty( const wxString& label, | |
459 | const wxString& name, | |
a243da29 | 460 | const wxChar* const* labels, |
1c4293cb VZ |
461 | const long* values, |
462 | const wxString& value ); | |
463 | wxEditEnumProperty( const wxString& label = wxPG_LABEL, | |
464 | const wxString& name = wxPG_LABEL, | |
465 | const wxArrayString& labels = wxArrayString(), | |
466 | const wxArrayInt& values = wxArrayInt(), | |
467 | const wxString& value = wxEmptyString ); | |
468 | wxEditEnumProperty( const wxString& label, | |
469 | const wxString& name, | |
470 | wxPGChoices& choices, | |
471 | const wxString& value = wxEmptyString ); | |
472 | ||
473 | // Special constructor for caching choices (used by derived class) | |
474 | wxEditEnumProperty( const wxString& label, | |
475 | const wxString& name, | |
a243da29 | 476 | const wxChar* const* labels, |
1c4293cb VZ |
477 | const long* values, |
478 | wxPGChoices* choicesCache, | |
479 | const wxString& value ); | |
480 | ||
481 | virtual ~wxEditEnumProperty(); | |
482 | ||
483 | protected: | |
484 | }; | |
485 | ||
486 | // ----------------------------------------------------------------------- | |
487 | ||
488 | /** @class wxFlagsProperty | |
489 | @ingroup classes | |
490 | Represents a bit set that fits in a long integer. wxBoolProperty | |
491 | sub-properties are created for editing individual bits. Textctrl is created | |
492 | to manually edit the flags as a text; a continous sequence of spaces, | |
493 | commas and semicolons is considered as a flag id separator. | |
494 | <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty, | |
495 | you will need to use SetPropertyChoices - otherwise they will not get | |
496 | updated properly. | |
497 | */ | |
498 | class WXDLLIMPEXP_PROPGRID wxFlagsProperty : public wxPGProperty | |
499 | { | |
500 | WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty) | |
501 | public: | |
502 | ||
503 | #ifndef SWIG | |
504 | wxFlagsProperty( const wxString& label, | |
505 | const wxString& name, | |
a243da29 | 506 | const wxChar* const* labels, |
1c4293cb VZ |
507 | const long* values = NULL, |
508 | long value = 0 ); | |
509 | wxFlagsProperty( const wxString& label, | |
510 | const wxString& name, | |
511 | wxPGChoices& choices, | |
512 | long value = 0 ); | |
513 | #endif | |
514 | wxFlagsProperty( const wxString& label = wxPG_LABEL, | |
515 | const wxString& name = wxPG_LABEL, | |
516 | const wxArrayString& labels = wxArrayString(), | |
517 | const wxArrayInt& values = wxArrayInt(), | |
518 | int value = 0 ); | |
519 | virtual ~wxFlagsProperty (); | |
520 | ||
521 | virtual void OnSetValue(); | |
1425eca5 | 522 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
1c4293cb VZ |
523 | virtual bool StringToValue( wxVariant& variant, |
524 | const wxString& text, | |
525 | int flags ) const; | |
b8b1ff48 JS |
526 | virtual wxVariant ChildChanged( wxVariant& thisValue, |
527 | int childIndex, | |
528 | wxVariant& childValue ) const; | |
1c4293cb | 529 | virtual void RefreshChildren(); |
16372f0d | 530 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); |
1c4293cb | 531 | |
939d9364 JS |
532 | // GetChoiceSelection needs to overridden since m_choices is |
533 | // used and value is integer, but it is not index. | |
534 | virtual int GetChoiceSelection() const { return wxNOT_FOUND; } | |
1c4293cb VZ |
535 | |
536 | // helpers | |
537 | size_t GetItemCount() const { return m_choices.GetCount(); } | |
538 | const wxString& GetLabel( size_t ind ) const | |
539 | { return m_choices.GetLabel(ind); } | |
540 | ||
541 | protected: | |
1c4293cb VZ |
542 | // Used to detect if choices have been changed |
543 | wxPGChoicesData* m_oldChoicesData; | |
544 | ||
545 | // Needed to properly mark changed sub-properties | |
546 | long m_oldValue; | |
547 | ||
548 | // Converts string id to a relevant bit. | |
549 | long IdToBit( const wxString& id ) const; | |
550 | ||
551 | // Creates children and sets value. | |
552 | void Init(); | |
553 | }; | |
554 | ||
555 | // ----------------------------------------------------------------------- | |
556 | ||
557 | /** @class wxPGFileDialogAdapter | |
558 | @ingroup classes | |
559 | */ | |
560 | class WXDLLIMPEXP_PROPGRID | |
561 | wxPGFileDialogAdapter : public wxPGEditorDialogAdapter | |
562 | { | |
563 | public: | |
564 | virtual bool DoShowDialog( wxPropertyGrid* propGrid, | |
565 | wxPGProperty* property ); | |
566 | }; | |
567 | ||
568 | // ----------------------------------------------------------------------- | |
569 | ||
1c4293cb VZ |
570 | // Indicates first bit useable by derived properties. |
571 | #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1 | |
572 | ||
573 | /** @class wxFileProperty | |
574 | @ingroup classes | |
575 | Like wxLongStringProperty, but the button triggers file selector instead. | |
576 | ||
577 | <b>Supported special attributes:</b> | |
578 | - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All | |
579 | files..." is default. | |
580 | - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive | |
581 | and directory are hidden). | |
582 | - "ShowRelativePath": If set, then the filename is shown relative to the | |
583 | given path string. | |
584 | - "InitialPath": Sets the initial path of where to look for files. | |
585 | - "DialogTitle": Sets a specific title for the dir dialog. | |
586 | */ | |
587 | class WXDLLIMPEXP_PROPGRID wxFileProperty : public wxPGProperty | |
588 | { | |
589 | friend class wxPGFileDialogAdapter; | |
590 | WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty) | |
591 | public: | |
592 | ||
593 | wxFileProperty( const wxString& label = wxPG_LABEL, | |
594 | const wxString& name = wxPG_LABEL, | |
595 | const wxString& value = wxEmptyString ); | |
596 | virtual ~wxFileProperty (); | |
597 | ||
598 | virtual void OnSetValue(); | |
1425eca5 | 599 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
1c4293cb VZ |
600 | virtual bool StringToValue( wxVariant& variant, |
601 | const wxString& text, | |
602 | int argFlags = 0 ) const; | |
603 | virtual wxPGEditorDialogAdapter* GetEditorDialog() const; | |
7eac5c53 | 604 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); |
1c4293cb VZ |
605 | |
606 | static wxValidator* GetClassValidator(); | |
607 | virtual wxValidator* DoGetValidator() const; | |
608 | ||
1425eca5 JS |
609 | /** |
610 | Returns filename to file represented by current value. | |
611 | */ | |
612 | wxFileName GetFileName() const; | |
613 | ||
1c4293cb VZ |
614 | protected: |
615 | wxString m_wildcard; | |
616 | wxString m_basePath; // If set, then show path relative to it | |
617 | wxString m_initialPath; // If set, start the file dialog here | |
618 | wxString m_dlgTitle; // If set, used as title for file dialog | |
1c4293cb VZ |
619 | int m_indFilter; // index to the selected filter |
620 | }; | |
621 | ||
622 | // ----------------------------------------------------------------------- | |
623 | ||
624 | #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1 | |
625 | ||
626 | ||
627 | /** @class wxPGLongStringDialogAdapter | |
628 | @ingroup classes | |
629 | */ | |
630 | class WXDLLIMPEXP_PROPGRID | |
631 | wxPGLongStringDialogAdapter : public wxPGEditorDialogAdapter | |
632 | { | |
633 | public: | |
634 | virtual bool DoShowDialog( wxPropertyGrid* propGrid, | |
635 | wxPGProperty* property ); | |
636 | }; | |
637 | ||
638 | ||
639 | /** @class wxLongStringProperty | |
640 | @ingroup classes | |
641 | Like wxStringProperty, but has a button that triggers a small text | |
642 | editor dialog. | |
643 | */ | |
644 | class WXDLLIMPEXP_PROPGRID wxLongStringProperty : public wxPGProperty | |
645 | { | |
646 | WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty) | |
647 | public: | |
648 | ||
649 | wxLongStringProperty( const wxString& label = wxPG_LABEL, | |
650 | const wxString& name = wxPG_LABEL, | |
651 | const wxString& value = wxEmptyString ); | |
652 | virtual ~wxLongStringProperty(); | |
653 | ||
1425eca5 | 654 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
1c4293cb VZ |
655 | virtual bool StringToValue( wxVariant& variant, |
656 | const wxString& text, | |
657 | int argFlags = 0 ) const; | |
7eac5c53 JS |
658 | virtual bool OnEvent( wxPropertyGrid* propgrid, |
659 | wxWindow* primary, wxEvent& event ); | |
1c4293cb VZ |
660 | |
661 | // Shows string editor dialog. Value to be edited should be read from | |
662 | // value, and if dialog is not cancelled, it should be stored back and true | |
663 | // should be returned if that was the case. | |
664 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); | |
665 | ||
666 | static bool DisplayEditorDialog( wxPGProperty* prop, | |
667 | wxPropertyGrid* propGrid, | |
668 | wxString& value ); | |
669 | ||
670 | protected: | |
671 | }; | |
672 | ||
673 | // ----------------------------------------------------------------------- | |
674 | ||
675 | ||
1c4293cb VZ |
676 | /** @class wxDirProperty |
677 | @ingroup classes | |
678 | Like wxLongStringProperty, but the button triggers dir selector instead. | |
679 | ||
680 | <b>Supported special attributes:</b> | |
681 | - "DialogMessage": Sets specific message in the dir selector. | |
682 | */ | |
683 | class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty | |
684 | { | |
1c4293cb | 685 | DECLARE_DYNAMIC_CLASS(wxDirProperty) |
1c4293cb VZ |
686 | public: |
687 | wxDirProperty( const wxString& name = wxPG_LABEL, | |
688 | const wxString& label = wxPG_LABEL, | |
689 | const wxString& value = wxEmptyString ); | |
690 | virtual ~wxDirProperty(); | |
691 | ||
7eac5c53 JS |
692 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); |
693 | virtual wxValidator* DoGetValidator() const; | |
1c4293cb VZ |
694 | |
695 | virtual bool OnButtonClick ( wxPropertyGrid* propGrid, wxString& value ); | |
696 | ||
697 | protected: | |
698 | wxString m_dlgMessage; | |
699 | }; | |
700 | ||
1c4293cb VZ |
701 | // ----------------------------------------------------------------------- |
702 | ||
703 | // wxBoolProperty specific flags | |
704 | #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1 | |
705 | // DCC = Double Click Cycles | |
706 | #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2 | |
707 | ||
708 | ||
709 | // ----------------------------------------------------------------------- | |
710 | ||
711 | /** @class wxArrayStringProperty | |
712 | @ingroup classes | |
713 | Property that manages a list of strings. | |
714 | */ | |
715 | class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty | |
716 | { | |
717 | WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty) | |
718 | public: | |
1c4293cb VZ |
719 | wxArrayStringProperty( const wxString& label = wxPG_LABEL, |
720 | const wxString& name = wxPG_LABEL, | |
721 | const wxArrayString& value = wxArrayString() ); | |
722 | virtual ~wxArrayStringProperty(); | |
723 | ||
724 | virtual void OnSetValue(); | |
1425eca5 | 725 | virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; |
7eac5c53 JS |
726 | virtual bool StringToValue( wxVariant& variant, |
727 | const wxString& text, | |
728 | int argFlags = 0 ) const; | |
729 | virtual bool OnEvent( wxPropertyGrid* propgrid, | |
730 | wxWindow* primary, wxEvent& event ); | |
525b2912 | 731 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); |
1c4293cb | 732 | |
525b2912 JS |
733 | // Implement in derived class for custom array-to-string conversion. |
734 | virtual void ConvertArrayToString(const wxArrayString& arr, | |
735 | wxString* pString, | |
736 | const wxUniChar& delimiter) const; | |
1c4293cb VZ |
737 | |
738 | // Shows string editor dialog. Value to be edited should be read from | |
739 | // value, and if dialog is not cancelled, it should be stored back and true | |
740 | // should be returned if that was the case. | |
741 | virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); | |
742 | ||
743 | // Helper. | |
744 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, | |
745 | wxWindow* primary, | |
746 | const wxChar* cbt ); | |
747 | ||
2906967c JS |
748 | // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick. |
749 | virtual wxPGArrayEditorDialog* CreateEditorDialog(); | |
1c4293cb | 750 | |
525b2912 JS |
751 | enum ConversionFlags |
752 | { | |
753 | Escape = 0x01, | |
754 | QuoteStrings = 0x02 | |
755 | }; | |
756 | ||
757 | /** | |
758 | Generates contents for string dst based on the contents of | |
759 | wxArrayString src. | |
760 | */ | |
761 | static void ArrayStringToString( wxString& dst, const wxArrayString& src, | |
762 | wxUniChar delimiter, int flags ); | |
763 | ||
1c4293cb | 764 | protected: |
525b2912 JS |
765 | // Previously this was to be implemented in derived class for array-to- |
766 | // string conversion. Now you should implement ConvertValueToString() | |
767 | // instead. | |
768 | virtual void GenerateValueAsString(); | |
769 | ||
1c4293cb | 770 | wxString m_display; // Cache for displayed text. |
525b2912 | 771 | wxUniChar m_delimiter; |
1c4293cb VZ |
772 | }; |
773 | ||
774 | // ----------------------------------------------------------------------- | |
775 | ||
776 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \ | |
777 | DECL) \ | |
778 | DECL PROPNAME : public wxArrayStringProperty \ | |
779 | { \ | |
780 | WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \ | |
781 | public: \ | |
782 | PROPNAME( const wxString& label = wxPG_LABEL, \ | |
783 | const wxString& name = wxPG_LABEL, \ | |
784 | const wxArrayString& value = wxArrayString() ); \ | |
785 | ~PROPNAME(); \ | |
1c4293cb VZ |
786 | virtual bool OnEvent( wxPropertyGrid* propgrid, \ |
787 | wxWindow* primary, wxEvent& event ); \ | |
788 | virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \ | |
7eac5c53 | 789 | virtual wxValidator* DoGetValidator() const; \ |
1c4293cb VZ |
790 | }; |
791 | ||
792 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \ | |
793 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class) | |
794 | ||
795 | #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ | |
796 | DELIMCHAR, \ | |
797 | CUSTBUTTXT) \ | |
798 | WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \ | |
799 | wxArrayString, const wxArrayString&, \ | |
800 | TextCtrlAndButton) \ | |
801 | PROPNAME::PROPNAME( const wxString& label, \ | |
802 | const wxString& name, \ | |
803 | const wxArrayString& value ) \ | |
804 | : wxArrayStringProperty(label,name,value) \ | |
805 | { \ | |
806 | PROPNAME::GenerateValueAsString(); \ | |
525b2912 | 807 | m_delimiter = DELIMCHAR; \ |
1c4293cb VZ |
808 | } \ |
809 | PROPNAME::~PROPNAME() { } \ | |
1c4293cb VZ |
810 | bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \ |
811 | wxWindow* primary, wxEvent& event ) \ | |
812 | { \ | |
813 | if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \ | |
814 | return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \ | |
815 | return false; \ | |
816 | } | |
817 | ||
818 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \ | |
819 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME) | |
820 | ||
821 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \ | |
822 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL) | |
823 | ||
824 | #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \ | |
825 | WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ | |
826 | DELIMCHAR, \ | |
827 | CUSTBUTTXT) \ | |
828 | wxValidator* PROPNAME::DoGetValidator () const \ | |
d3b9f782 | 829 | { return NULL; } |
1c4293cb VZ |
830 | |
831 | ||
832 | // ----------------------------------------------------------------------- | |
2906967c | 833 | // wxPGArrayEditorDialog |
1c4293cb VZ |
834 | // ----------------------------------------------------------------------- |
835 | ||
2906967c JS |
836 | #if wxUSE_EDITABLELISTBOX |
837 | ||
838 | class WXDLLIMPEXP_FWD_ADV wxEditableListBox; | |
839 | class WXDLLIMPEXP_FWD_CORE wxListEvent; | |
840 | ||
1c4293cb VZ |
841 | #define wxAEDIALOG_STYLE \ |
842 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
843 | ||
2906967c | 844 | class WXDLLIMPEXP_PROPGRID wxPGArrayEditorDialog : public wxDialog |
1c4293cb VZ |
845 | { |
846 | public: | |
2906967c JS |
847 | wxPGArrayEditorDialog(); |
848 | virtual ~wxPGArrayEditorDialog() { } | |
1c4293cb VZ |
849 | |
850 | void Init(); | |
851 | ||
2906967c | 852 | wxPGArrayEditorDialog( wxWindow *parent, |
1c4293cb VZ |
853 | const wxString& message, |
854 | const wxString& caption, | |
855 | long style = wxAEDIALOG_STYLE, | |
856 | const wxPoint& pos = wxDefaultPosition, | |
857 | const wxSize& sz = wxDefaultSize ); | |
858 | ||
859 | bool Create( wxWindow *parent, | |
860 | const wxString& message, | |
861 | const wxString& caption, | |
862 | long style = wxAEDIALOG_STYLE, | |
863 | const wxPoint& pos = wxDefaultPosition, | |
864 | const wxSize& sz = wxDefaultSize ); | |
865 | ||
895e26a0 JS |
866 | void EnableCustomNewAction() |
867 | { | |
868 | m_hasCustomNewAction = true; | |
869 | } | |
870 | ||
1c4293cb VZ |
871 | /** Set value modified by dialog. |
872 | */ | |
873 | virtual void SetDialogValue( const wxVariant& WXUNUSED(value) ) | |
874 | { | |
875 | wxFAIL_MSG(wxT("re-implement this member function in derived class")); | |
876 | } | |
877 | ||
878 | /** Return value modified by dialog. | |
879 | */ | |
880 | virtual wxVariant GetDialogValue() const | |
881 | { | |
882 | wxFAIL_MSG(wxT("re-implement this member function in derived class")); | |
883 | return wxVariant(); | |
884 | } | |
885 | ||
886 | /** Override to return wxValidator to be used with the wxTextCtrl | |
887 | in dialog. Note that the validator is used in the standard | |
888 | wx way, ie. it immediately prevents user from entering invalid | |
889 | input. | |
890 | ||
891 | @remarks | |
892 | Dialog frees the validator. | |
893 | */ | |
894 | virtual wxValidator* GetTextCtrlValidator() const | |
895 | { | |
d3b9f782 | 896 | return NULL; |
1c4293cb VZ |
897 | } |
898 | ||
899 | // Returns true if array was actually modified | |
900 | bool IsModified() const { return m_modified; } | |
901 | ||
2906967c JS |
902 | // wxEditableListBox utilities |
903 | int GetSelection() const; | |
904 | ||
1c4293cb | 905 | // implementation from now on |
1c4293cb VZ |
906 | void OnAddClick(wxCommandEvent& event); |
907 | void OnDeleteClick(wxCommandEvent& event); | |
1c4293cb VZ |
908 | void OnUpClick(wxCommandEvent& event); |
909 | void OnDownClick(wxCommandEvent& event); | |
2906967c | 910 | void OnEndLabelEdit(wxListEvent& event); |
1c4293cb VZ |
911 | void OnIdle(wxIdleEvent& event); |
912 | ||
913 | protected: | |
2906967c | 914 | wxEditableListBox* m_elb; |
1c4293cb | 915 | |
2906967c JS |
916 | // These are used for focus repair |
917 | wxWindow* m_elbSubPanel; | |
918 | wxWindow* m_lastFocused; | |
1c4293cb | 919 | |
2906967c JS |
920 | // A new item, edited by user, is pending at this index. |
921 | // It will be committed once list ctrl item editing is done. | |
922 | int m_itemPendingAtIndex; | |
1c4293cb | 923 | |
2906967c | 924 | bool m_modified; |
895e26a0 | 925 | bool m_hasCustomNewAction; |
1c4293cb VZ |
926 | |
927 | // These must be overridden - must return true on success. | |
928 | virtual wxString ArrayGet( size_t index ) = 0; | |
929 | virtual size_t ArrayGetCount() = 0; | |
930 | virtual bool ArrayInsert( const wxString& str, int index ) = 0; | |
931 | virtual bool ArraySet( size_t index, const wxString& str ) = 0; | |
932 | virtual void ArrayRemoveAt( int index ) = 0; | |
933 | virtual void ArraySwap( size_t first, size_t second ) = 0; | |
895e26a0 JS |
934 | virtual bool OnCustomNewAction(wxString* WXUNUSED(resString)) |
935 | { | |
936 | return false; | |
937 | } | |
1c4293cb VZ |
938 | |
939 | private: | |
2906967c | 940 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog) |
1c4293cb | 941 | DECLARE_EVENT_TABLE() |
1c4293cb VZ |
942 | }; |
943 | ||
2906967c JS |
944 | #endif // wxUSE_EDITABLELISTBOX |
945 | ||
1c4293cb VZ |
946 | // ----------------------------------------------------------------------- |
947 | // wxPGArrayStringEditorDialog | |
948 | // ----------------------------------------------------------------------- | |
949 | ||
950 | class WXDLLIMPEXP_PROPGRID | |
2906967c | 951 | wxPGArrayStringEditorDialog : public wxPGArrayEditorDialog |
1c4293cb VZ |
952 | { |
953 | public: | |
954 | wxPGArrayStringEditorDialog(); | |
955 | virtual ~wxPGArrayStringEditorDialog() { } | |
956 | ||
957 | void Init(); | |
958 | ||
959 | virtual void SetDialogValue( const wxVariant& value ) | |
960 | { | |
961 | m_array = value.GetArrayString(); | |
962 | } | |
963 | ||
964 | virtual wxVariant GetDialogValue() const | |
965 | { | |
966 | return m_array; | |
967 | } | |
968 | ||
895e26a0 JS |
969 | void SetCustomButton( const wxString& custBtText, |
970 | wxArrayStringProperty* pcc ) | |
1c4293cb | 971 | { |
895e26a0 JS |
972 | if ( custBtText.length() ) |
973 | { | |
974 | EnableCustomNewAction(); | |
975 | m_pCallingClass = pcc; | |
976 | } | |
1c4293cb VZ |
977 | } |
978 | ||
895e26a0 | 979 | virtual bool OnCustomNewAction(wxString* resString); |
1c4293cb VZ |
980 | |
981 | protected: | |
982 | wxArrayString m_array; | |
983 | ||
984 | wxArrayStringProperty* m_pCallingClass; | |
985 | ||
986 | virtual wxString ArrayGet( size_t index ); | |
987 | virtual size_t ArrayGetCount(); | |
988 | virtual bool ArrayInsert( const wxString& str, int index ); | |
989 | virtual bool ArraySet( size_t index, const wxString& str ); | |
990 | virtual void ArrayRemoveAt( int index ); | |
991 | virtual void ArraySwap( size_t first, size_t second ); | |
992 | ||
993 | private: | |
1c4293cb VZ |
994 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog) |
995 | DECLARE_EVENT_TABLE() | |
1c4293cb VZ |
996 | }; |
997 | ||
998 | // ----------------------------------------------------------------------- | |
999 | ||
f4bc1aa2 JS |
1000 | #endif // wxUSE_PROPGRID |
1001 | ||
1c4293cb | 1002 | #endif // _WX_PROPGRID_PROPS_H_ |