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