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