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