1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/props.cpp
3 // Purpose: Basic Property Classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcclient.h"
30 #include "wx/dcmemory.h"
31 #include "wx/button.h"
34 #include "wx/cursor.h"
35 #include "wx/dialog.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
38 #include "wx/choice.h"
39 #include "wx/stattext.h"
40 #include "wx/scrolwin.h"
41 #include "wx/dirdlg.h"
42 #include "wx/combobox.h"
43 #include "wx/layout.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
51 #include <wx/filename.h>
53 #include <wx/propgrid/propgrid.h>
55 #define wxPG_CUSTOM_IMAGE_WIDTH 20 // for wxColourProperty etc.
60 // -----------------------------------------------------------------------
62 // -----------------------------------------------------------------------
64 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxStringProperty
,wxPGProperty
,
65 wxString
,const wxString
&,TextCtrl
)
67 wxStringProperty::wxStringProperty( const wxString
& label
,
69 const wxString
& value
)
70 : wxPGProperty(label
,name
)
75 void wxStringProperty::OnSetValue()
77 if ( !m_value
.IsNull() && m_value
.GetString() == wxS("<composed>") )
78 SetFlag(wxPG_PROP_COMPOSED_VALUE
);
80 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
83 GenerateComposedValue(s
, 0);
88 wxStringProperty::~wxStringProperty() { }
90 wxString
wxStringProperty::GetValueAsString( int argFlags
) const
92 wxString s
= m_value
.GetString();
94 if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
96 // Value stored in m_value is non-editable, non-full value
97 if ( (argFlags
& wxPG_FULL_VALUE
) || (argFlags
& wxPG_EDITABLE_VALUE
) )
98 GenerateComposedValue(s
, argFlags
);
103 // If string is password and value is for visual purposes,
104 // then return asterisks instead the actual string.
105 if ( (m_flags
& wxPG_PROP_PASSWORD
) && !(argFlags
& (wxPG_FULL_VALUE
|wxPG_EDITABLE_VALUE
)) )
106 return wxString(wxChar('*'), s
.Length());
111 bool wxStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
113 if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
114 return wxPGProperty::StringToValue(variant
, text
, argFlags
);
116 if ( m_value
.GetString() != text
)
125 bool wxStringProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
127 if ( name
== wxPG_STRING_PASSWORD
)
129 m_flags
&= ~(wxPG_PROP_PASSWORD
);
130 if ( wxPGVariantToInt(value
) ) m_flags
|= wxPG_PROP_PASSWORD
;
137 // -----------------------------------------------------------------------
139 // -----------------------------------------------------------------------
141 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxIntProperty
,wxPGProperty
,
144 wxIntProperty::wxIntProperty( const wxString
& label
, const wxString
& name
,
145 long value
) : wxPGProperty(label
,name
)
150 wxIntProperty::wxIntProperty( const wxString
& label
, const wxString
& name
,
151 const wxLongLong
& value
) : wxPGProperty(label
,name
)
153 SetValue(wxLongLongToVariant(value
));
156 wxIntProperty::~wxIntProperty() { }
158 wxString
wxIntProperty::GetValueAsString( int ) const
160 if ( wxPGIsVariantType(m_value
, long) )
161 return wxString::Format(wxS("%li"),m_value
.GetLong());
163 wxLongLong
* ll
= &wxLongLongFromVariant(m_value
);
165 return ll
->ToString();
167 return wxEmptyString
;
170 bool wxIntProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
175 if ( text
.length() == 0 )
181 // We know it is a number, but let's still check
183 if ( text
.IsNumber() )
185 // Remove leading zeroes, so that the number is not interpreted as octal
186 wxString::const_iterator i
= text
.begin();
187 wxString::const_iterator iMax
= text
.end() - 1; // Let's allow one, last zero though
189 int firstNonZeroPos
= 0;
191 for ( ; i
!= iMax
; i
++ )
194 if ( c
!= wxS('0') && c
!= wxS(' ') )
199 wxString useText
= text
.substr(firstNonZeroPos
, text
.length() - firstNonZeroPos
);
201 bool isPrevLong
= wxPGIsVariantType(variant
, long);
203 wxLongLong_t value64
= 0;
205 if ( useText
.ToLongLong(&value64
, 10) &&
206 ( value64
>= INT_MAX
|| value64
<= INT_MIN
)
209 wxLongLong
* _m_value64
= &wxLongLongFromVariant(m_value
);
210 if ( isPrevLong
|| !_m_value64
|| _m_value64
->GetValue() != value64
)
212 variant
= wxLongLongToVariant(value64
);
217 if ( useText
.ToLong( &value32
, 0 ) )
219 if ( !isPrevLong
|| m_value
.GetLong() != value32
)
226 else if ( argFlags
& wxPG_REPORT_ERROR
)
232 bool wxIntProperty::IntToValue( wxVariant
& variant
, int value
, int WXUNUSED(argFlags
) ) const
234 if ( !wxPGIsVariantType(variant
, long) || variant
.GetLong() != value
)
236 variant
= (long)value
;
242 bool wxIntProperty::DoValidation( const wxPGProperty
* property
, wxLongLong_t
& value
, wxPGValidationInfo
* pValidationInfo
, int mode
)
245 wxLongLong_t min
= wxINT64_MIN
;
246 wxLongLong_t max
= wxINT64_MAX
;
251 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMin
);
252 if ( !variant
.IsNull() )
254 wxPGVariantToLongLong(variant
, &min
);
258 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMax
);
259 if ( !variant
.IsNull() )
261 wxPGVariantToLongLong(variant
, &max
);
269 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
270 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %lld or higher"),min
);
271 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
274 value
= max
- (min
- value
);
283 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
284 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %lld or higher"),min
);
285 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
288 value
= min
+ (value
- max
);
295 bool wxIntProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
298 if ( wxPGVariantToLongLong(value
, &ll
) )
299 return DoValidation(this, ll
, &validationInfo
, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
303 wxValidator
* wxIntProperty::GetClassValidator()
306 WX_PG_DOGETVALIDATOR_ENTRY()
308 // Atleast wxPython 2.6.2.1 required that the string argument is given
310 wxTextValidator
* validator
= new wxTextValidator(wxFILTER_NUMERIC
,&v
);
312 WX_PG_DOGETVALIDATOR_EXIT(validator
)
318 wxValidator
* wxIntProperty::DoGetValidator() const
320 return GetClassValidator();
323 // -----------------------------------------------------------------------
325 // -----------------------------------------------------------------------
328 #define wxPG_UINT_TEMPLATE_MAX 8
330 static const wxChar
* gs_uintTemplates32
[wxPG_UINT_TEMPLATE_MAX
] = {
331 wxT("%x"),wxT("0x%x"),wxT("$%x"),
332 wxT("%X"),wxT("0x%X"),wxT("$%X"),
336 static const wxChar
* gs_uintTemplates64
[wxPG_UINT_TEMPLATE_MAX
] = {
337 wxT("%") wxLongLongFmtSpec
wxT("x"),
338 wxT("0x%") wxLongLongFmtSpec
wxT("x"),
339 wxT("$%") wxLongLongFmtSpec
wxT("x"),
340 wxT("%") wxLongLongFmtSpec
wxT("X"),
341 wxT("0x%") wxLongLongFmtSpec
wxT("X"),
342 wxT("$%") wxLongLongFmtSpec
wxT("X"),
343 wxT("%") wxLongLongFmtSpec
wxT("u"),
344 wxT("%") wxLongLongFmtSpec
wxT("o")
347 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxUIntProperty
,wxPGProperty
,
348 long,unsigned long,TextCtrl
)
350 void wxUIntProperty::Init()
352 m_base
= 6; // This is magic number for dec base (must be same as in setattribute)
354 m_prefix
= wxPG_PREFIX_NONE
;
357 wxUIntProperty::wxUIntProperty( const wxString
& label
, const wxString
& name
,
358 unsigned long value
) : wxPGProperty(label
,name
)
361 SetValue((long)value
);
364 wxUIntProperty::wxUIntProperty( const wxString
& label
, const wxString
& name
,
365 const wxULongLong
& value
) : wxPGProperty(label
,name
)
368 SetValue(wxULongLongToVariant(value
));
371 wxUIntProperty::~wxUIntProperty() { }
373 wxString
wxUIntProperty::GetValueAsString( int ) const
375 size_t index
= m_base
+ m_prefix
;
376 if ( index
>= wxPG_UINT_TEMPLATE_MAX
)
377 index
= wxPG_BASE_DEC
;
379 if ( wxPGIsVariantType(m_value
, long) )
380 return wxString::Format(gs_uintTemplates32
[index
],(unsigned long)m_value
.GetLong());
382 return wxString::Format(gs_uintTemplates64
[index
],wxULongLongFromVariant(m_value
).GetValue());
385 bool wxUIntProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int WXUNUSED(argFlags
) ) const
387 //long unsigned value32 = 0;
388 bool isPrevLong
= wxPGIsVariantType(variant
, long);
390 if ( text
.length() == 0 )
397 if ( text
[0] == wxS('$') )
400 wxULongLong_t value64
= 0;
401 wxString s
= text
.substr(start
, text
.length() - start
);
403 if ( s
.ToULongLong(&value64
, (unsigned int)m_realBase
) )
405 if ( value64
>= LONG_MAX
)
407 wxULongLong
* _m_value64
= &wxULongLongFromVariant(m_value
);
408 if ( isPrevLong
|| !_m_value64
|| _m_value64
->GetValue() != value64
)
410 variant
= wxULongLongToVariant(value64
);
416 unsigned long value32
= wxLongLong(value64
).GetLo();
417 if ( !isPrevLong
|| m_value
.GetLong() != (long)value32
)
419 variant
= (long)value32
;
428 bool wxUIntProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
430 if ( m_value
!= (long)number
)
432 variant
= (long)number
;
439 #define wxUINT64_MAX ULLONG_MAX
440 #define wxUINT64_MIN wxULL(0)
442 #define wxUINT64_MAX wxULL(0xFFFFFFFFFFFFFFFF)
443 #define wxUINT64_MIN wxULL(0)
446 bool wxUIntProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
450 if ( wxPGVariantToULongLong(value
, &ll
) )
452 wxULongLong_t min
= wxUINT64_MIN
;
453 wxULongLong_t max
= wxUINT64_MAX
;
456 variant
= GetAttribute(wxPGGlobalVars
->m_strMin
);
457 if ( !variant
.IsNull() )
459 wxPGVariantToULongLong(variant
, &min
);
462 validationInfo
.m_failureMessage
= wxString::Format(_("Value must be %llu or higher"),min
);
466 variant
= GetAttribute(wxPGGlobalVars
->m_strMax
);
467 if ( !variant
.IsNull() )
469 wxPGVariantToULongLong(variant
, &max
);
472 validationInfo
.m_failureMessage
= wxString::Format(_("Value must be %llu or less"),max
);
480 bool wxUIntProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
482 if ( name
== wxPG_UINT_BASE
)
484 int val
= value
.GetLong();
486 m_realBase
= (wxByte
) val
;
487 if ( m_realBase
> 16 )
491 // Translate logical base to a template array index
493 if ( val
== wxPG_BASE_HEX
)
495 else if ( val
== wxPG_BASE_DEC
)
497 else if ( val
== wxPG_BASE_HEXL
)
501 else if ( name
== wxPG_UINT_PREFIX
)
503 m_prefix
= (wxByte
) value
.GetLong();
509 // -----------------------------------------------------------------------
511 // -----------------------------------------------------------------------
513 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFloatProperty
,wxPGProperty
,
514 double,double,TextCtrl
)
516 wxFloatProperty::wxFloatProperty( const wxString
& label
,
517 const wxString
& name
,
519 : wxPGProperty(label
,name
)
525 wxFloatProperty::~wxFloatProperty() { }
527 // This helper method provides standard way for floating point-using
528 // properties to convert values to string.
529 void wxPropertyGrid::DoubleToString(wxString
& target
,
533 wxString
* precTemplate
)
535 if ( precision
>= 0 )
539 precTemplate
= &text1
;
541 if ( !precTemplate
->length() )
543 *precTemplate
= wxS("%.");
544 *precTemplate
<< wxString::Format( wxS("%i"), precision
);
545 *precTemplate
<< wxS('f');
548 target
.Printf( precTemplate
->c_str(), value
);
552 target
.Printf( wxS("%f"), value
);
555 if ( removeZeroes
&& precision
!= 0 && target
.length() )
557 // Remove excess zeroes (do not remove this code just yet,
558 // since sprintf can't do the same consistently across platforms).
559 wxString::const_iterator i
= target
.end() - 1;
560 size_t new_len
= target
.length() - 1;
562 for ( ; i
!= target
.begin(); i
-- )
564 if ( *i
!= wxS('0') )
569 wxChar cur_char
= *i
;
570 if ( cur_char
!= wxS('.') && cur_char
!= wxS(',') )
573 if ( new_len
!= target
.length() )
574 target
.resize(new_len
);
578 wxString
wxFloatProperty::GetValueAsString( int argFlags
) const
581 if ( !m_value
.IsNull() )
583 wxPropertyGrid::DoubleToString(text
,
586 !(argFlags
& wxPG_FULL_VALUE
),
592 bool wxFloatProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
597 if ( text
.length() == 0 )
603 bool res
= text
.ToDouble(&value
);
606 if ( m_value
!= value
)
612 else if ( argFlags
& wxPG_REPORT_ERROR
)
618 bool wxFloatProperty::DoValidation( const wxPGProperty
* property
, double& value
, wxPGValidationInfo
* pValidationInfo
, int mode
)
621 double min
= (double)wxINT64_MIN
;
622 double max
= (double)wxINT64_MAX
;
627 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMin
);
628 if ( !variant
.IsNull() )
630 wxPGVariantToDouble(variant
, &min
);
634 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMax
);
635 if ( !variant
.IsNull() )
637 wxPGVariantToDouble(variant
, &max
);
645 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
646 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %f or higher"),min
);
647 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
650 value
= max
- (min
- value
);
657 wxPGVariantToDouble(variant
, &max
);
660 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
661 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %f or less"),max
);
662 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
665 value
= min
+ (value
- max
);
672 bool wxFloatProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
675 if ( wxPGVariantToDouble(value
, &fpv
) )
676 return DoValidation(this, fpv
, &validationInfo
, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
680 bool wxFloatProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
682 if ( name
== wxPG_FLOAT_PRECISION
)
684 m_precision
= value
.GetLong();
690 wxValidator
* wxFloatProperty::DoGetValidator() const
692 return wxIntProperty::GetClassValidator();
695 // -----------------------------------------------------------------------
697 // -----------------------------------------------------------------------
699 // We cannot use standard WX_PG_IMPLEMENT_PROPERTY_CLASS macro, since
700 // there is a custom GetEditorClass.
702 IMPLEMENT_DYNAMIC_CLASS(wxBoolProperty
, wxPGProperty
)
704 const wxPGEditor
* wxBoolProperty::DoGetEditorClass() const
706 // Select correct editor control.
707 #if wxPG_INCLUDE_CHECKBOX
708 if ( !(m_flags
& wxPG_PROP_USE_CHECKBOX
) )
709 return wxPG_EDITOR(Choice
);
710 return wxPG_EDITOR(CheckBox
);
712 return wxPG_EDITOR(Choice
);
716 wxBoolProperty::wxBoolProperty( const wxString
& label
, const wxString
& name
, bool value
) :
717 wxPGProperty(label
,name
)
719 SetValue(wxPGVariant_Bool(value
));
721 m_flags
|= wxPG_PROP_USE_DCC
;
724 wxBoolProperty::~wxBoolProperty() { }
726 wxString
wxBoolProperty::GetValueAsString( int argFlags
) const
728 bool value
= m_value
.GetBool();
730 // As a fragment of composite string value,
731 // make it a little more readable.
732 if ( argFlags
& wxPG_COMPOSITE_FRAGMENT
)
740 if ( argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
)
741 return wxEmptyString
;
744 if ( wxPGGlobalVars
->m_autoGetTranslation
)
745 notFmt
= _("Not %s");
747 notFmt
= wxS("Not %s");
749 return wxString::Format(notFmt
.c_str(), m_label
.c_str());
753 if ( !(argFlags
& wxPG_FULL_VALUE
) )
755 return wxPGGlobalVars
->m_boolChoices
[value
?1:0].GetText();
760 if (value
) text
= wxS("true");
761 else text
= wxS("false");
766 int wxBoolProperty::GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
)
768 if ( IsValueUnspecified() )
772 choiceinfo
->m_choices
= &wxPGGlobalVars
->m_boolChoices
;
773 return m_value
.GetBool()?1:0;
776 bool wxBoolProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int WXUNUSED(argFlags
) ) const
779 if ( text
.CmpNoCase(wxPGGlobalVars
->m_boolChoices
[1].GetText()) == 0 ||
780 text
.CmpNoCase(wxS("true")) == 0 ||
781 text
.CmpNoCase(m_label
) == 0 )
784 if ( text
.length() == 0 )
790 bool oldValue
= m_value
.GetBool();
792 if ( (oldValue
&& !value
) || (!oldValue
&& value
) )
794 variant
= wxPGVariant_Bool(value
);
800 bool wxBoolProperty::IntToValue( wxVariant
& variant
, int value
, int ) const
802 bool boolValue
= value
? true : false;
803 bool oldValue
= m_value
.GetBool();
805 if ( oldValue
!= boolValue
)
807 variant
= wxPGVariant_Bool(boolValue
);
813 bool wxBoolProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
815 #if wxPG_INCLUDE_CHECKBOX
816 if ( name
== wxPG_BOOL_USE_CHECKBOX
)
818 int ival
= wxPGVariantToInt(value
);
820 m_flags
|= wxPG_PROP_USE_CHECKBOX
;
822 m_flags
&= ~(wxPG_PROP_USE_CHECKBOX
);
826 if ( name
== wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
)
828 int ival
= wxPGVariantToInt(value
);
830 m_flags
|= wxPG_PROP_USE_DCC
;
832 m_flags
&= ~(wxPG_PROP_USE_DCC
);
838 // -----------------------------------------------------------------------
839 // wxBaseEnumProperty
840 // -----------------------------------------------------------------------
842 int wxBaseEnumProperty::ms_nextIndex
= -2;
844 wxBaseEnumProperty::wxBaseEnumProperty( const wxString
& label
, const wxString
& name
)
845 : wxPGProperty(label
,name
)
847 m_value
= wxPGVariant_Zero
;
850 /** If has values array, then returns number at index with value -
851 otherwise just returns the value.
853 int wxBaseEnumProperty::GetIndexForValue( int value
) const
858 void wxBaseEnumProperty::OnSetValue()
860 if ( wxPGIsVariantType(m_value
, long) )
861 ValueFromInt_( m_value
, m_value
.GetLong(), wxPG_FULL_VALUE
);
862 else if ( wxPGIsVariantType(m_value
, string
) )
863 ValueFromString_( m_value
, m_value
.GetString(), 0 );
867 if ( ms_nextIndex
!= -2 )
869 m_index
= ms_nextIndex
;
874 bool wxBaseEnumProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
876 // Make sure string value is in the list,
877 // unless property has string as preferred value type
878 // To reduce code size, use conversion here as well
879 if ( wxPGIsVariantType(value
, string
) &&
880 !this->IsKindOf(CLASSINFO(wxEditEnumProperty
)) )
881 return ValueFromString_( value
, value
.GetString(), wxPG_PROPERTY_SPECIFIC
);
886 wxString
wxBaseEnumProperty::GetValueAsString( int ) const
888 if ( wxPGIsVariantType(m_value
, string
) )
889 return m_value
.GetString();
894 const wxString
* pstr
= GetEntry( m_index
, &unusedVal
);
899 return wxEmptyString
;
902 bool wxBaseEnumProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
904 return ValueFromString_( variant
, text
, argFlags
);
907 bool wxBaseEnumProperty::IntToValue( wxVariant
& variant
, int intVal
, int argFlags
) const
909 return ValueFromInt_( variant
, intVal
, argFlags
);
912 bool wxBaseEnumProperty::ValueFromString_( wxVariant
& value
, const wxString
& text
, int argFlags
) const
915 const wxString
* entryLabel
;
920 entryLabel
= GetEntry(i
, &entryValue
);
923 if ( text
.CmpNoCase(*entryLabel
) == 0 )
926 useValue
= (long)entryValue
;
931 entryLabel
= GetEntry(i
, &entryValue
);
936 bool isEdit
= this->IsKindOf(CLASSINFO(wxEditEnumProperty
));
938 // If text not any of the choices, store as text instead
939 // (but only if we are wxEditEnumProperty)
940 if ( useIndex
== -1 &&
941 (!wxPGIsVariantType(m_value
, string
) || (m_value
.GetString() != text
)) &&
947 int setAsNextIndex
= -2;
954 else if ( m_index
!= useIndex
)
956 if ( useIndex
!= -1 )
958 setAsNextIndex
= useIndex
;
959 value
= (long)useValue
;
964 value
= wxPGVariant_MinusOne
;
968 if ( setAsNextIndex
!= -2 )
970 // If wxPG_PROPERTY_SPECIFIC is set, then this is done for
971 // validation purposes only, and index must not be changed
972 if ( !(argFlags
& wxPG_PROPERTY_SPECIFIC
) )
973 ms_nextIndex
= setAsNextIndex
;
975 if ( isEdit
|| setAsNextIndex
!= -1 )
983 bool wxBaseEnumProperty::ValueFromInt_( wxVariant
& variant
, int intVal
, int argFlags
) const
985 // If wxPG_FULL_VALUE is *not* in argFlags, then intVal is index from combo box.
989 if ( argFlags
& wxPG_FULL_VALUE
)
991 ms_nextIndex
= GetIndexForValue( intVal
);
995 if ( m_index
!= intVal
)
997 ms_nextIndex
= intVal
;
1001 if ( ms_nextIndex
!= -2 )
1003 if ( !(argFlags
& wxPG_FULL_VALUE
) )
1004 GetEntry(intVal
, &intVal
);
1006 variant
= (long)intVal
;
1014 void wxBaseEnumProperty::SetIndex( int index
)
1020 int wxBaseEnumProperty::GetIndex() const
1022 if ( ms_nextIndex
!= -2 )
1023 return ms_nextIndex
;
1027 // -----------------------------------------------------------------------
1029 // -----------------------------------------------------------------------
1031 IMPLEMENT_DYNAMIC_CLASS(wxEnumProperty
, wxPGProperty
)
1033 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty
,long,Choice
)
1035 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1036 const long* values
, int value
) : wxBaseEnumProperty(label
,name
)
1042 m_choices
.Add(labels
,values
);
1044 if ( GetItemCount() )
1045 SetValue( (long)value
);
1049 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1050 const long* values
, wxPGChoices
* choicesCache
, int value
)
1051 : wxBaseEnumProperty(label
,name
)
1055 wxASSERT( choicesCache
);
1057 if ( choicesCache
->IsOk() )
1059 m_choices
.Assign( *choicesCache
);
1060 m_value
= wxPGVariant_Zero
;
1064 m_choices
.Add(labels
,values
);
1066 if ( GetItemCount() )
1067 SetValue( (long)value
);
1071 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
,
1072 const wxArrayString
& labels
, const wxArrayInt
& values
, int value
) : wxBaseEnumProperty(label
,name
)
1076 if ( &labels
&& labels
.size() )
1078 m_choices
.Set(labels
, values
);
1080 if ( GetItemCount() )
1081 SetValue( (long)value
);
1085 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
,
1086 wxPGChoices
& choices
, int value
)
1087 : wxBaseEnumProperty(label
,name
)
1089 m_choices
.Assign( choices
);
1091 if ( GetItemCount() )
1092 SetValue( (long)value
);
1095 int wxEnumProperty::GetIndexForValue( int value
) const
1097 if ( !m_choices
.IsOk() )
1100 if ( m_choices
.HasValues() )
1102 int intVal
= m_choices
.Index(value
);
1110 wxEnumProperty::~wxEnumProperty ()
1114 const wxString
* wxEnumProperty::GetEntry( size_t index
, int* pvalue
) const
1116 if ( m_choices
.IsOk() && index
< m_choices
.GetCount() )
1118 int value
= (int)index
;
1119 if ( m_choices
.HasValue(index
) )
1120 value
= m_choices
.GetValue(index
);
1125 return &m_choices
.GetLabel(index
);
1127 return (const wxString
*) NULL
;
1130 int wxEnumProperty::GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
)
1133 choiceinfo
->m_choices
= &m_choices
;
1135 if ( !m_choices
.IsOk() )
1141 // -----------------------------------------------------------------------
1142 // wxEditEnumProperty
1143 // -----------------------------------------------------------------------
1145 IMPLEMENT_DYNAMIC_CLASS(wxEditEnumProperty
, wxPGProperty
)
1147 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEditEnumProperty
,wxString
,ComboBox
)
1149 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1150 const long* values
, const wxString
& value
)
1151 : wxEnumProperty(label
,name
,labels
,values
,0)
1156 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1157 const long* values
, wxPGChoices
* choicesCache
, const wxString
& value
)
1158 : wxEnumProperty(label
,name
,labels
,values
,choicesCache
,0)
1163 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
,
1164 const wxArrayString
& labels
, const wxArrayInt
& values
, const wxString
& value
)
1165 : wxEnumProperty(label
,name
,labels
,values
,0)
1170 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
,
1171 wxPGChoices
& choices
, const wxString
& value
)
1172 : wxEnumProperty(label
,name
,choices
,0)
1177 wxEditEnumProperty::~wxEditEnumProperty()
1181 // -----------------------------------------------------------------------
1183 // -----------------------------------------------------------------------
1185 IMPLEMENT_DYNAMIC_CLASS(wxFlagsProperty
,wxPGProperty
)
1187 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxFlagsProperty
,long,TextCtrl
)
1189 void wxFlagsProperty::Init()
1191 SetFlag(wxPG_PROP_AGGREGATE
); // This is must be done here to support flag props
1192 // with inital zero children.
1194 long value
= m_value
;
1197 // Generate children
1201 unsigned int prevChildCount
= m_children
.GetCount();
1204 if ( prevChildCount
)
1206 wxPropertyGridPageState
* state
= GetParentState();
1208 // State safety check (it may be NULL in immediate parent)
1213 wxPGProperty
* selected
= state
->GetSelection();
1216 if ( selected
->GetParent() == this )
1217 oldSel
= selected
->GetArrIndex();
1218 else if ( selected
== this )
1222 state
->DoClearSelection();
1225 // Delete old children
1226 for ( i
=0; i
<prevChildCount
; i
++ )
1227 delete ( (wxPGProperty
*) m_children
[i
] );
1231 if ( m_choices
.IsOk() )
1233 const wxPGChoices
& choices
= m_choices
;
1235 for ( i
=0; i
<GetItemCount(); i
++ )
1238 if ( choices
.HasValue(i
) )
1239 child_val
= ( value
& choices
.GetValue(i
) )?true:false;
1241 child_val
= ( value
& (1<<i
) )?true:false;
1243 wxPGProperty
* boolProp
;
1246 if ( wxPGGlobalVars
->m_autoGetTranslation
)
1248 boolProp
= new wxBoolProperty( ::wxGetTranslation( GetLabel(i
) ), wxEmptyString
, child_val
);
1253 boolProp
= new wxBoolProperty( GetLabel(i
), wxEmptyString
, child_val
);
1258 m_oldChoicesData
= m_choices
.GetDataPtr();
1261 m_oldValue
= m_value
;
1263 if ( prevChildCount
)
1264 SubPropsChanged(oldSel
);
1267 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1268 const wxChar
** labels
, const long* values
, long value
) : wxPGProperty(label
,name
)
1270 m_oldChoicesData
= (wxPGChoicesData
*) NULL
;
1274 m_choices
.Set(labels
,values
);
1276 wxASSERT( GetItemCount() );
1282 m_value
= wxPGVariant_Zero
;
1286 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1287 const wxArrayString
& labels
, const wxArrayInt
& values
, int value
)
1288 : wxPGProperty(label
,name
)
1290 m_oldChoicesData
= (wxPGChoicesData
*) NULL
;
1292 if ( &labels
&& labels
.size() )
1294 m_choices
.Set(labels
,values
);
1296 wxASSERT( GetItemCount() );
1298 SetValue( (long)value
);
1302 m_value
= wxPGVariant_Zero
;
1306 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1307 wxPGChoices
& choices
, long value
)
1308 : wxPGProperty(label
,name
)
1310 m_oldChoicesData
= (wxPGChoicesData
*) NULL
;
1312 if ( choices
.IsOk() )
1314 m_choices
.Assign(choices
);
1316 wxASSERT( GetItemCount() );
1322 m_value
= wxPGVariant_Zero
;
1326 wxFlagsProperty::~wxFlagsProperty()
1330 void wxFlagsProperty::OnSetValue()
1332 if ( !m_choices
.IsOk() || !GetItemCount() )
1334 m_value
= wxPGVariant_Zero
;
1338 long val
= m_value
.GetLong();
1342 // normalize the value (i.e. remove extra flags)
1344 const wxPGChoices
& choices
= m_choices
;
1345 for ( i
= 0; i
< GetItemCount(); i
++ )
1347 if ( choices
.HasValue(i
) )
1348 fullFlags
|= choices
.GetValue(i
);
1350 fullFlags
|= (1<<i
);
1357 // Need to (re)init now?
1358 if ( GetChildCount() != GetItemCount() ||
1359 m_choices
.GetDataPtr() != m_oldChoicesData
)
1365 long newFlags
= m_value
;
1367 if ( newFlags
!= m_oldValue
)
1369 // Set child modified states
1371 const wxPGChoices
& choices
= m_choices
;
1372 for ( i
= 0; i
<GetItemCount(); i
++ )
1376 if ( choices
.HasValue(i
) )
1377 flag
= choices
.GetValue(i
);
1381 if ( (newFlags
& flag
) != (m_oldValue
& flag
) )
1382 Item(i
)->SetFlag( wxPG_PROP_MODIFIED
);
1385 m_oldValue
= newFlags
;
1389 wxString
wxFlagsProperty::GetValueAsString( int ) const
1393 if ( !m_choices
.IsOk() )
1396 long flags
= m_value
;
1398 const wxPGChoices
& choices
= m_choices
;
1400 for ( i
= 0; i
< GetItemCount(); i
++ )
1403 if ( choices
.HasValue(i
) )
1404 doAdd
= ( flags
& choices
.GetValue(i
) );
1406 doAdd
= ( flags
& (1<<i
) );
1410 text
+= choices
.GetLabel(i
);
1415 // remove last comma
1416 if ( text
.Len() > 1 )
1417 text
.Truncate ( text
.Len() - 2 );
1422 // Translate string into flag tokens
1423 bool wxFlagsProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1425 if ( !m_choices
.IsOk() )
1429 long oldValue
= m_value
;
1431 // semicolons are no longer valid delimeters
1432 WX_PG_TOKENIZER1_BEGIN(text
,wxS(','))
1434 if ( token
.length() )
1436 // Determine which one it is
1437 long bit
= IdToBit( token
);
1450 WX_PG_TOKENIZER1_END()
1454 if ( newFlags
!= oldValue
)
1460 // Converts string id to a relevant bit.
1461 long wxFlagsProperty::IdToBit( const wxString
& id
) const
1464 for ( i
= 0; i
< GetItemCount(); i
++ )
1466 if ( id
== GetLabel(i
) )
1468 if ( m_choices
.HasValue(i
) )
1469 return m_choices
.GetValue(i
);
1476 void wxFlagsProperty::RefreshChildren()
1478 if ( !m_choices
.IsOk() || !GetChildCount() ) return;
1480 int flags
= m_value
.GetLong();
1482 const wxPGChoices
& choices
= m_choices
;
1484 for ( i
= 0; i
< GetItemCount(); i
++ )
1488 if ( choices
.HasValue(i
) )
1489 flag
= choices
.GetValue(i
);
1493 long subVal
= flags
& flag
;
1494 wxPGProperty
* p
= Item(i
);
1496 if ( subVal
!= (m_oldValue
& flag
) )
1497 p
->SetFlag( wxPG_PROP_MODIFIED
);
1499 p
->SetValue( subVal
?true:false );
1505 void wxFlagsProperty::ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const
1507 long oldValue
= thisValue
.GetLong();
1508 long val
= childValue
.GetLong();
1509 unsigned long vi
= (1<<childIndex
);
1510 if ( m_choices
.HasValue(childIndex
) ) vi
= m_choices
.GetValue(childIndex
);
1512 thisValue
= (long)(oldValue
| vi
);
1514 thisValue
= (long)(oldValue
& ~(vi
));
1517 int wxFlagsProperty::GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
)
1520 choiceinfo
->m_choices
= &m_choices
;
1524 // -----------------------------------------------------------------------
1526 // -----------------------------------------------------------------------
1528 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxDirProperty
,wxLongStringProperty
,const wxString
&)
1530 wxDirProperty::wxDirProperty( const wxString
& name
, const wxString
& label
, const wxString
& value
)
1531 : wxLongStringProperty(name
,label
,value
)
1533 m_flags
|= wxPG_NO_ESCAPE
;
1535 wxDirProperty::~wxDirProperty() { }
1537 wxValidator
* wxDirProperty::DoGetValidator() const
1539 return wxFileProperty::GetClassValidator();
1542 bool wxDirProperty::OnButtonClick( wxPropertyGrid
* propGrid
, wxString
& value
)
1544 wxSize
dlg_sz(300,400);
1546 wxDirDialog
dlg( propGrid
,
1547 m_dlgMessage
.length() ? m_dlgMessage
: wxString(_("Choose a directory:")),
1550 #if !wxPG_SMALL_SCREEN
1551 propGrid
->GetGoodEditorDialogPosition(this,dlg_sz
),
1558 if ( dlg
.ShowModal() == wxID_OK
)
1560 value
= dlg
.GetPath();
1566 bool wxDirProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1568 if ( name
== wxPG_DIR_DIALOG_MESSAGE
)
1570 m_dlgMessage
= value
.GetString();
1576 // -----------------------------------------------------------------------
1577 // wxPGFileDialogAdapter
1578 // -----------------------------------------------------------------------
1580 bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1582 wxFileProperty
* fileProp
= NULL
;
1586 if ( property
->IsKindOf(CLASSINFO(wxFileProperty
)) )
1588 fileProp
= ((wxFileProperty
*)property
);
1589 path
= fileProp
->m_filename
.GetPath();
1590 indFilter
= fileProp
->m_indFilter
;
1592 if ( !path
.length() && fileProp
->m_basePath
.length() )
1593 path
= fileProp
->m_basePath
;
1597 wxFileName
fn(property
->GetValue().GetString());
1598 path
= fn
.GetPath();
1601 wxFileDialog
dlg( propGrid
->GetPanel(),
1602 property
->GetAttribute(wxS("DialogTitle"), _("Choose a file")),
1603 property
->GetAttribute(wxS("InitialPath"), path
),
1605 property
->GetAttribute(wxPG_FILE_WILDCARD
, _("All files (*.*)|*.*")),
1607 wxDefaultPosition
);
1609 if ( indFilter
>= 0 )
1610 dlg
.SetFilterIndex( indFilter
);
1612 if ( dlg
.ShowModal() == wxID_OK
)
1615 fileProp
->m_indFilter
= dlg
.GetFilterIndex();
1616 SetValue( dlg
.GetPath() );
1622 // -----------------------------------------------------------------------
1624 // -----------------------------------------------------------------------
1626 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFileProperty
,wxPGProperty
,
1627 wxString
,const wxString
&,TextCtrlAndButton
)
1629 wxFileProperty::wxFileProperty( const wxString
& label
, const wxString
& name
,
1630 const wxString
& value
) : wxPGProperty(label
,name
)
1632 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1634 SetAttribute( wxPG_FILE_WILDCARD
, _("All files (*.*)|*.*") );
1639 wxFileProperty::~wxFileProperty() {}
1641 #if wxUSE_VALIDATORS
1643 wxValidator
* wxFileProperty::GetClassValidator()
1645 WX_PG_DOGETVALIDATOR_ENTRY()
1647 // Atleast wxPython 2.6.2.1 required that the string argument is given
1649 wxTextValidator
* validator
= new wxTextValidator(wxFILTER_EXCLUDE_CHAR_LIST
,&v
);
1651 wxArrayString exChars
;
1652 exChars
.Add(wxS("?"));
1653 exChars
.Add(wxS("*"));
1654 exChars
.Add(wxS("|"));
1655 exChars
.Add(wxS("<"));
1656 exChars
.Add(wxS(">"));
1657 exChars
.Add(wxS("\""));
1659 validator
->SetExcludes(exChars
);
1661 WX_PG_DOGETVALIDATOR_EXIT(validator
)
1664 wxValidator
* wxFileProperty::DoGetValidator() const
1666 return GetClassValidator();
1671 void wxFileProperty::OnSetValue()
1673 const wxString
& fnstr
= m_value
.GetString();
1677 if ( !m_filename
.HasName() )
1679 m_value
= wxPGVariant_EmptyString
;
1683 // Find index for extension.
1684 if ( m_indFilter
< 0 && fnstr
.length() )
1686 wxString ext
= m_filename
.GetExt();
1689 size_t len
= m_wildcard
.length();
1691 pos
= m_wildcard
.find(wxS("|"), pos
);
1692 while ( pos
!= wxString::npos
&& pos
< (len
-3) )
1694 size_t ext_begin
= pos
+ 3;
1696 pos
= m_wildcard
.find(wxS("|"), ext_begin
);
1697 if ( pos
== wxString::npos
)
1699 wxString found_ext
= m_wildcard
.substr(ext_begin
, pos
-ext_begin
);
1701 if ( found_ext
.length() > 0 )
1703 if ( found_ext
[0] == wxS('*') )
1705 m_indFilter
= curind
;
1708 if ( ext
.CmpNoCase(found_ext
) == 0 )
1710 m_indFilter
= curind
;
1716 pos
= m_wildcard
.find(wxS("|"), pos
+1);
1723 wxString
wxFileProperty::GetValueAsString( int argFlags
) const
1725 // Always return empty string when name component is empty
1726 wxString fullName
= m_filename
.GetFullName();
1727 if ( !fullName
.length() )
1730 if ( argFlags
& wxPG_FULL_VALUE
)
1732 return m_filename
.GetFullPath();
1734 else if ( m_flags
& wxPG_PROP_SHOW_FULL_FILENAME
)
1736 if ( m_basePath
.Length() )
1738 wxFileName
fn2(m_filename
);
1739 fn2
.MakeRelativeTo(m_basePath
);
1740 return fn2
.GetFullPath();
1742 return m_filename
.GetFullPath();
1745 return m_filename
.GetFullName();
1748 wxPGEditorDialogAdapter
* wxFileProperty::GetEditorDialog() const
1750 return new wxPGFileDialogAdapter();
1753 bool wxFileProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
1755 if ( (m_flags
& wxPG_PROP_SHOW_FULL_FILENAME
) || (argFlags
& wxPG_FULL_VALUE
) )
1757 if ( m_filename
!= text
)
1765 if ( m_filename
.GetFullName() != text
)
1767 wxFileName fn
= m_filename
;
1768 fn
.SetFullName(text
);
1769 variant
= fn
.GetFullPath();
1777 bool wxFileProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1779 // Return false on some occasions to make sure those attribs will get
1780 // stored in m_attributes.
1781 if ( name
== wxPG_FILE_SHOW_FULL_PATH
)
1783 if ( wxPGVariantToInt(value
) )
1784 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1786 m_flags
&= ~(wxPG_PROP_SHOW_FULL_FILENAME
);
1789 else if ( name
== wxPG_FILE_WILDCARD
)
1791 m_wildcard
= value
.GetString();
1793 else if ( name
== wxPG_FILE_SHOW_RELATIVE_PATH
)
1795 m_basePath
= value
.GetString();
1797 // Make sure wxPG_FILE_SHOW_FULL_PATH is also set
1798 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1800 else if ( name
== wxPG_FILE_INITIAL_PATH
)
1802 m_initialPath
= value
.GetString();
1805 else if ( name
== wxPG_FILE_DIALOG_TITLE
)
1807 m_dlgTitle
= value
.GetString();
1813 // -----------------------------------------------------------------------
1814 // wxPGLongStringDialogAdapter
1815 // -----------------------------------------------------------------------
1817 bool wxPGLongStringDialogAdapter::DoShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1819 wxString val1
= property
->GetValueAsString(0);
1820 wxString val_orig
= val1
;
1823 if ( !property
->HasFlag(wxPG_PROP_NO_ESCAPE
) )
1824 wxPropertyGrid::ExpandEscapeSequences(value
, val1
);
1826 value
= wxString(val1
);
1828 // Run editor dialog.
1829 if ( wxLongStringProperty::DisplayEditorDialog(property
, propGrid
, value
) )
1831 if ( !property
->HasFlag(wxPG_PROP_NO_ESCAPE
) )
1832 wxPropertyGrid::CreateEscapeSequences(val1
,value
);
1836 if ( val1
!= val_orig
)
1845 // -----------------------------------------------------------------------
1846 // wxLongStringProperty
1847 // -----------------------------------------------------------------------
1849 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxLongStringProperty
,wxPGProperty
,
1850 wxString
,const wxString
&,TextCtrlAndButton
)
1852 wxLongStringProperty::wxLongStringProperty( const wxString
& label
, const wxString
& name
,
1853 const wxString
& value
) : wxPGProperty(label
,name
)
1858 wxLongStringProperty::~wxLongStringProperty() {}
1860 wxString
wxLongStringProperty::GetValueAsString( int ) const
1865 bool wxLongStringProperty::OnEvent( wxPropertyGrid
* propGrid
, wxWindow
* WXUNUSED(primary
),
1868 if ( propGrid
->IsMainButtonEvent(event
) )
1871 PrepareValueForDialogEditing(propGrid
);
1873 wxString val1
= GetValueAsString(0);
1874 wxString val_orig
= val1
;
1877 if ( !(m_flags
& wxPG_PROP_NO_ESCAPE
) )
1878 wxPropertyGrid::ExpandEscapeSequences(value
,val1
);
1880 value
= wxString(val1
);
1882 // Run editor dialog.
1883 if ( OnButtonClick(propGrid
,value
) )
1885 if ( !(m_flags
& wxPG_PROP_NO_ESCAPE
) )
1886 wxPropertyGrid::CreateEscapeSequences(val1
,value
);
1890 if ( val1
!= val_orig
)
1892 SetValueInEvent( val1
);
1900 bool wxLongStringProperty::OnButtonClick( wxPropertyGrid
* propGrid
, wxString
& value
)
1902 return DisplayEditorDialog(this, propGrid
, value
);
1905 bool wxLongStringProperty::DisplayEditorDialog( wxPGProperty
* prop
, wxPropertyGrid
* propGrid
, wxString
& value
)
1908 // launch editor dialog
1909 wxDialog
* dlg
= new wxDialog(propGrid
,-1,prop
->GetLabel(),wxDefaultPosition
,wxDefaultSize
,
1910 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
|wxCLIP_CHILDREN
);
1912 dlg
->SetFont(propGrid
->GetFont()); // To allow entering chars of the same set as the propGrid
1914 // Multi-line text editor dialog.
1915 #if !wxPG_SMALL_SCREEN
1916 const int spacing
= 8;
1918 const int spacing
= 4;
1920 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
1921 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
1922 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,value
,
1923 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
);
1925 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
1926 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
1927 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
1928 const int but_sz_flags
=
1929 wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
1930 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,_("Ok")),
1931 0, but_sz_flags
, spacing
);
1932 rowsizer
->Add( new wxButton(dlg
,wxID_CANCEL
,_("Cancel")),
1933 0, but_sz_flags
, spacing
);
1934 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
1936 dlg
->SetSizer( topsizer
);
1937 topsizer
->SetSizeHints( dlg
);
1939 #if !wxPG_SMALL_SCREEN
1940 dlg
->SetSize(400,300);
1942 dlg
->Move( propGrid
->GetGoodEditorDialogPosition(prop
,dlg
->GetSize()) );
1945 int res
= dlg
->ShowModal();
1947 if ( res
== wxID_OK
)
1949 value
= ed
->GetValue();
1957 bool wxLongStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1959 if ( m_value
!= text
)
1967 // -----------------------------------------------------------------------
1968 // wxArrayEditorDialog
1969 // -----------------------------------------------------------------------
1971 BEGIN_EVENT_TABLE(wxArrayEditorDialog
, wxDialog
)
1972 EVT_IDLE(wxArrayEditorDialog::OnIdle
)
1973 EVT_LISTBOX(24, wxArrayEditorDialog::OnListBoxClick
)
1974 EVT_TEXT_ENTER(21, wxArrayEditorDialog::OnAddClick
)
1975 EVT_BUTTON(22, wxArrayEditorDialog::OnAddClick
)
1976 EVT_BUTTON(23, wxArrayEditorDialog::OnDeleteClick
)
1977 EVT_BUTTON(25, wxArrayEditorDialog::OnUpClick
)
1978 EVT_BUTTON(26, wxArrayEditorDialog::OnDownClick
)
1979 EVT_BUTTON(27, wxArrayEditorDialog::OnUpdateClick
)
1980 //EVT_BUTTON(28, wxArrayEditorDialog::OnCustomEditClick)
1983 IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog
, wxDialog
)
1985 #include <wx/statline.h>
1987 // -----------------------------------------------------------------------
1989 void wxArrayEditorDialog::OnIdle(wxIdleEvent
& event
)
1992 // Do control focus detection here.
1995 wxWindow
* focused
= FindFocus();
1997 // This strange focus thing is a workaround for wxGTK wxListBox focus
1999 if ( m_curFocus
== 0 && focused
!= m_edValue
&&
2000 focused
!= m_butAdd
&& focused
!= m_butUpdate
&&
2001 m_lbStrings
->GetSelection() >= 0 )
2003 // ListBox was just focused.
2004 m_butAdd
->Enable(false);
2005 m_butUpdate
->Enable(false);
2006 m_butRemove
->Enable(true);
2007 m_butUp
->Enable(true);
2008 m_butDown
->Enable(true);
2011 else if ( (m_curFocus
== 1 && focused
== m_edValue
) /*|| m_curFocus == 2*/ )
2013 // TextCtrl was just focused.
2014 m_butAdd
->Enable(true);
2015 bool upd_enable
= false;
2016 if ( m_lbStrings
->GetCount() && m_lbStrings
->GetSelection() >= 0 )
2018 m_butUpdate
->Enable(upd_enable
);
2019 m_butRemove
->Enable(false);
2020 m_butUp
->Enable(false);
2021 m_butDown
->Enable(false);
2028 // -----------------------------------------------------------------------
2030 wxArrayEditorDialog::wxArrayEditorDialog()
2036 // -----------------------------------------------------------------------
2038 void wxArrayEditorDialog::Init()
2040 m_custBtText
= (const wxChar
*) NULL
;
2043 // -----------------------------------------------------------------------
2045 wxArrayEditorDialog::wxArrayEditorDialog( wxWindow
*parent
,
2046 const wxString
& message
,
2047 const wxString
& caption
,
2054 Create(parent
,message
,caption
,style
,pos
,sz
);
2057 // -----------------------------------------------------------------------
2059 bool wxArrayEditorDialog::Create( wxWindow
*parent
,
2060 const wxString
& message
,
2061 const wxString
& caption
,
2066 // On wxMAC the dialog shows incorrectly if style is not exactly wxCAPTION
2067 // FIXME: This should be only a temporary fix.
2069 int useStyle
= wxCAPTION
;
2071 int useStyle
= style
;
2074 bool res
= wxDialog::Create(parent
, wxID_ANY
, caption
, pos
, sz
, useStyle
);
2076 SetFont(parent
->GetFont()); // To allow entering chars of the same set as the propGrid
2078 #if !wxPG_SMALL_SCREEN
2079 const int spacing
= 4;
2081 const int spacing
= 3;
2088 const int but_sz_flags
=
2089 wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
|wxALL
; //wxBOTTOM|wxLEFT|wxRIGHT;
2091 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
2094 if ( message
.length() )
2095 topsizer
->Add( new wxStaticText(this,-1,message
),
2096 0, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxALL
, spacing
);
2099 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2100 m_edValue
= new wxTextCtrl(this,21,wxEmptyString
,
2101 wxDefaultPosition
,wxDefaultSize
,wxTE_PROCESS_ENTER
);
2102 wxValidator
* validator
= GetTextCtrlValidator();
2105 m_edValue
->SetValidator( *validator
);
2108 rowsizer
->Add( m_edValue
,
2109 1, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxALL
, spacing
);
2112 m_butAdd
= new wxButton(this,22,_("Add"));
2113 rowsizer
->Add( m_butAdd
,
2114 0, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, spacing
);
2115 topsizer
->Add( rowsizer
, 0, wxEXPAND
, spacing
);
2118 topsizer
->Add( new wxStaticLine(this,-1),
2119 0, wxEXPAND
|wxBOTTOM
|wxLEFT
|wxRIGHT
, spacing
);
2121 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2124 m_lbStrings
= new wxListBox(this, 24, wxDefaultPosition
, wxDefaultSize
);
2126 for ( i
=0; i
<ArrayGetCount(); i
++ )
2127 m_lbStrings
->Append( ArrayGet(i
) );
2128 rowsizer
->Add( m_lbStrings
, 1, wxEXPAND
|wxRIGHT
, spacing
);
2130 // Manipulator buttons
2131 wxBoxSizer
* colsizer
= new wxBoxSizer( wxVERTICAL
);
2132 m_butCustom
= (wxButton
*) NULL
;
2135 m_butCustom
= new wxButton(this,28,::wxGetTranslation(m_custBtText
));
2136 colsizer
->Add( m_butCustom
,
2137 0, wxALIGN_CENTER
|wxTOP
/*wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT*/,
2140 m_butUpdate
= new wxButton(this,27,_("Update"));
2141 colsizer
->Add( m_butUpdate
,
2142 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2143 m_butRemove
= new wxButton(this,23,_("Remove"));
2144 colsizer
->Add( m_butRemove
,
2145 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2146 m_butUp
= new wxButton(this,25,_("Up"));
2147 colsizer
->Add( m_butUp
,
2148 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2149 m_butDown
= new wxButton(this,26,_("Down"));
2150 colsizer
->Add( m_butDown
,
2151 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2152 rowsizer
->Add( colsizer
, 0, 0, spacing
);
2154 topsizer
->Add( rowsizer
, 1, wxLEFT
|wxRIGHT
|wxEXPAND
, spacing
);
2157 topsizer
->Add( new wxStaticLine(this,-1),
2158 0, wxEXPAND
|wxTOP
|wxLEFT
|wxRIGHT
, spacing
);
2161 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2163 const int but_sz_flags =
2164 wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT;
2166 rowsizer
->Add( new wxButton(this,wxID_OK
,_("Ok")),
2167 0, but_sz_flags
, spacing
);
2168 rowsizer
->Add( new wxButton(this,wxID_CANCEL
,_("Cancel")),
2169 0, but_sz_flags
, spacing
);
2170 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
2172 m_edValue
->SetFocus();
2174 SetSizer( topsizer
);
2175 topsizer
->SetSizeHints( this );
2177 #if !wxPG_SMALL_SCREEN
2178 if ( sz
.x
== wxDefaultSize
.x
&&
2179 sz
.y
== wxDefaultSize
.y
)
2180 SetSize( wxSize(275,360) );
2188 // -----------------------------------------------------------------------
2190 void wxArrayEditorDialog::OnAddClick(wxCommandEvent
& )
2192 wxString text
= m_edValue
->GetValue();
2193 if ( text
.length() )
2195 if ( ArrayInsert( text
, -1 ) )
2197 m_lbStrings
->Append( text
);
2204 // -----------------------------------------------------------------------
2206 void wxArrayEditorDialog::OnDeleteClick(wxCommandEvent
& )
2208 int index
= m_lbStrings
->GetSelection();
2211 ArrayRemoveAt( index
);
2212 m_lbStrings
->Delete ( index
);
2217 // -----------------------------------------------------------------------
2219 void wxArrayEditorDialog::OnUpClick(wxCommandEvent
& )
2221 int index
= m_lbStrings
->GetSelection();
2224 ArraySwap(index
-1,index
);
2225 /*wxString old_str = m_array[index-1];
2226 wxString new_str = m_array[index];
2227 m_array[index-1] = new_str;
2228 m_array[index] = old_str;*/
2229 m_lbStrings
->SetString ( index
-1, ArrayGet(index
-1) );
2230 m_lbStrings
->SetString ( index
, ArrayGet(index
) );
2231 m_lbStrings
->SetSelection ( index
-1 );
2236 // -----------------------------------------------------------------------
2238 void wxArrayEditorDialog::OnDownClick(wxCommandEvent
& )
2240 int index
= m_lbStrings
->GetSelection();
2241 int lastStringIndex
= ((int) m_lbStrings
->GetCount()) - 1;
2242 if ( index
>= 0 && index
< lastStringIndex
)
2244 ArraySwap(index
,index
+1);
2245 /*wxString old_str = m_array[index+1];
2246 wxString new_str = m_array[index];
2247 m_array[index+1] = new_str;
2248 m_array[index] = old_str;*/
2249 m_lbStrings
->SetString ( index
+1, ArrayGet(index
+1) );
2250 m_lbStrings
->SetString ( index
, ArrayGet(index
) );
2251 m_lbStrings
->SetSelection ( index
+1 );
2256 // -----------------------------------------------------------------------
2258 void wxArrayEditorDialog::OnUpdateClick(wxCommandEvent
& )
2260 int index
= m_lbStrings
->GetSelection();
2263 wxString str
= m_edValue
->GetValue();
2264 if ( ArraySet(index
,str
) )
2266 m_lbStrings
->SetString ( index
, str
);
2267 //m_array[index] = str;
2273 // -----------------------------------------------------------------------
2275 void wxArrayEditorDialog::OnListBoxClick(wxCommandEvent
& )
2277 int index
= m_lbStrings
->GetSelection();
2280 m_edValue
->SetValue( m_lbStrings
->GetString(index
) );
2284 // -----------------------------------------------------------------------
2285 // wxPGArrayStringEditorDialog
2286 // -----------------------------------------------------------------------
2288 IMPLEMENT_DYNAMIC_CLASS(wxPGArrayStringEditorDialog
, wxArrayEditorDialog
)
2290 BEGIN_EVENT_TABLE(wxPGArrayStringEditorDialog
, wxArrayEditorDialog
)
2291 EVT_BUTTON(28, wxPGArrayStringEditorDialog::OnCustomEditClick
)
2294 // -----------------------------------------------------------------------
2296 wxString
wxPGArrayStringEditorDialog::ArrayGet( size_t index
)
2298 return m_array
[index
];
2301 size_t wxPGArrayStringEditorDialog::ArrayGetCount()
2303 return m_array
.size();
2306 bool wxPGArrayStringEditorDialog::ArrayInsert( const wxString
& str
, int index
)
2311 m_array
.Insert(str
,index
);
2315 bool wxPGArrayStringEditorDialog::ArraySet( size_t index
, const wxString
& str
)
2317 m_array
[index
] = str
;
2321 void wxPGArrayStringEditorDialog::ArrayRemoveAt( int index
)
2323 m_array
.RemoveAt(index
);
2326 void wxPGArrayStringEditorDialog::ArraySwap( size_t first
, size_t second
)
2328 wxString old_str
= m_array
[first
];
2329 wxString new_str
= m_array
[second
];
2330 m_array
[first
] = new_str
;
2331 m_array
[second
] = old_str
;
2334 wxPGArrayStringEditorDialog::wxPGArrayStringEditorDialog()
2335 : wxArrayEditorDialog()
2340 void wxPGArrayStringEditorDialog::Init()
2342 m_pCallingClass
= (wxArrayStringProperty
*) NULL
;
2345 void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent
& )
2347 wxASSERT( m_pCallingClass
);
2348 wxString str
= m_edValue
->GetValue();
2349 if ( m_pCallingClass
->OnCustomStringEdit(m_parent
,str
) )
2351 //m_edValue->SetValue ( str );
2352 m_lbStrings
->Append ( str
);
2353 m_array
.Add ( str
);
2358 // -----------------------------------------------------------------------
2359 // wxArrayStringProperty
2360 // -----------------------------------------------------------------------
2362 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxArrayStringProperty
, // Property name
2363 wxPGProperty
, // Property we inherit from
2364 wxArrayString
, // Value type name
2365 const wxArrayString
&, // Value type, as given in constructor
2366 TextCtrlAndButton
) // Initial editor
2368 wxArrayStringProperty::wxArrayStringProperty( const wxString
& label
,
2369 const wxString
& name
,
2370 const wxArrayString
& array
)
2371 : wxPGProperty(label
,name
)
2376 wxArrayStringProperty::~wxArrayStringProperty() { }
2378 void wxArrayStringProperty::OnSetValue()
2380 GenerateValueAsString();
2383 wxString
wxArrayStringProperty::GetValueAsString( int WXUNUSED(argFlags
) ) const
2388 // Converts wxArrayString to a string separated by delimeters and spaces.
2389 // preDelim is useful for "str1" "str2" style. Set flags to 1 to do slash
2391 void wxPropertyGrid::ArrayStringToString( wxString
& dst
, const wxArrayString
& src
,
2392 wxChar preDelim
, wxChar postDelim
,
2398 unsigned int itemCount
= src
.size();
2406 else if ( (flags
& 1) )
2408 preas
[0] = preDelim
;
2415 dst
.append( preas
);
2417 wxASSERT( postDelim
);
2418 wxString
postDelimStr(postDelim
);
2419 //wxString preDelimStr(preDelim);
2421 for ( i
= 0; i
< itemCount
; i
++ )
2423 wxString
str( src
.Item(i
) );
2425 // Do some character conversion.
2426 // Convertes \ to \\ and <preDelim> to \<preDelim>
2427 // Useful when preDelim and postDelim are "\"".
2430 str
.Replace( wxS("\\"), wxS("\\\\"), true );
2432 str
.Replace( preas
, pdr
, true );
2437 if ( i
< (itemCount
-1) )
2439 dst
.append( postDelimStr
);
2440 dst
.append( wxS(" ") );
2441 dst
.append( preas
);
2443 else if ( preDelim
)
2444 dst
.append( postDelimStr
);
2448 #define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \
2449 wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1);
2451 void wxArrayStringProperty::GenerateValueAsString()
2453 wxArrayString arr
= m_value
.GetArrayString();
2454 ARRSTRPROP_ARRAY_TO_STRING(m_display
, arr
)
2457 // Default implementation doesn't do anything.
2458 bool wxArrayStringProperty::OnCustomStringEdit( wxWindow
*, wxString
& )
2463 wxArrayEditorDialog
* wxArrayStringProperty::CreateEditorDialog()
2465 return new wxPGArrayStringEditorDialog();
2468 bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid
* propGrid
,
2469 wxWindow
* WXUNUSED(primaryCtrl
),
2473 PrepareValueForDialogEditing(propGrid
);
2475 if ( !propGrid
->EditorValidate() )
2478 // Create editor dialog.
2479 wxArrayEditorDialog
* dlg
= CreateEditorDialog();
2480 #if wxUSE_VALIDATORS
2481 wxValidator
* validator
= GetValidator();
2482 wxPGInDialogValidator dialogValidator
;
2485 wxPGArrayStringEditorDialog
* strEdDlg
= wxDynamicCast(dlg
, wxPGArrayStringEditorDialog
);
2488 strEdDlg
->SetCustomButton(cbt
, this);
2490 dlg
->SetDialogValue( wxVariant(m_value
) );
2491 dlg
->Create(propGrid
, wxEmptyString
, m_label
);
2493 #if !wxPG_SMALL_SCREEN
2494 dlg
->Move( propGrid
->GetGoodEditorDialogPosition(this,dlg
->GetSize()) );
2503 int res
= dlg
->ShowModal();
2505 if ( res
== wxID_OK
&& dlg
->IsModified() )
2507 wxVariant value
= dlg
->GetDialogValue();
2508 if ( !value
.IsNull() )
2510 wxArrayString actualValue
= value
.GetArrayString();
2512 ARRSTRPROP_ARRAY_TO_STRING(tempStr
, actualValue
)
2513 #if wxUSE_VALIDATORS
2514 if ( dialogValidator
.DoValidate( propGrid
, validator
, tempStr
) )
2517 SetValueInEvent( actualValue
);
2534 bool wxArrayStringProperty::OnEvent( wxPropertyGrid
* propGrid
,
2538 if ( propGrid
->IsMainButtonEvent(event
) )
2539 return OnButtonClick(propGrid
,primary
,(const wxChar
*) NULL
);
2543 bool wxArrayStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2547 WX_PG_TOKENIZER2_BEGIN(text
,wxS('"'))
2549 // Need to replace backslashes with empty characters
2550 // (opposite what is done in GenerateValueString).
2551 token
.Replace ( wxS("\\"), wxEmptyString
, true );
2555 WX_PG_TOKENIZER2_END()
2562 // -----------------------------------------------------------------------
2563 // wxPGInDialogValidator
2564 // -----------------------------------------------------------------------
2566 #if wxUSE_VALIDATORS
2567 bool wxPGInDialogValidator::DoValidate( wxPropertyGrid
* propGrid
,
2568 wxValidator
* validator
,
2569 const wxString
& value
)
2574 wxTextCtrl
* tc
= m_textCtrl
;
2579 tc
= new wxTextCtrl( propGrid
, wxPG_SUBID_TEMP1
, wxEmptyString
,
2580 wxPoint(30000,30000));
2587 tc
->SetValue(value
);
2589 validator
->SetWindow(tc
);
2590 bool res
= validator
->Validate(propGrid
);
2595 bool wxPGInDialogValidator::DoValidate( wxPropertyGrid
* WXUNUSED(propGrid
),
2596 wxValidator
* WXUNUSED(validator
),
2597 const wxString
& WXUNUSED(value
) )
2603 // -----------------------------------------------------------------------