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