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