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