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