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