Added 'Delimiter' attribute for wxArrayStringProperty. Moved static ArrayStringToString() to wxArrayStringProperty.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64894 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2010-07-11 17:04:23 +00:00
parent 895e26a04b
commit 525b29124a
7 changed files with 118 additions and 72 deletions

View File

@@ -500,6 +500,7 @@ All (GUI):
new flags: wxPG_VFB_SHOW_MESSAGEBOX and wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR.
- wxPropertyGrid: Added wxPropertyGrid::DedicateKey().
- wxPropertyGrid: wxArrayStringProperty now uses wxEditableListBox.
- wxPropertyGrid: Added "Delimiter" attribute for wxArrayStringProperty.
- wxPropertyGridManager: added wxPG_NO_INTERNAL_BORDER,
wxPG_EX_NO_TOOLBAR_DIVIDER and wxPG_EX_TOOLBAR_SEPARATOR styles for finer
control over borders. Borders around property grid are now native for

View File

@@ -644,6 +644,15 @@ wxPG_PROP_BEING_DELETED = 0x00200000
*/
#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
/**
wxArrayStringProperty's string delimiter character. If this is aquotation
mark or hyphen, then strings will be quoted instead (with given
character).
Default delimiter is quotation mark.
*/
#define wxPG_ARRAY_DELIMITER wxS("Delimiter")
/** Sets displayed date format for wxDateProperty.
*/
#define wxPG_DATE_FORMAT wxS("DateFormat")

View File

@@ -1520,18 +1520,6 @@ public:
// Events from editor controls are forward to this function
void HandleCustomEditorEvent( wxEvent &event );
/**
Generates contents for string dst based on the contents of
wxArrayString src.
Format will be "(preDelim)str1(postDelim) (preDelim)str2(postDelim) and
so on. Set flags to 1 inorder to convert backslashes to double-back-
slashes and "(preDelims)"'s to "(preDelims)".
*/
static void ArrayStringToString( wxString& dst, const wxArrayString& src,
wxChar preDelim, wxChar postDelim,
int flags );
// Mostly useful for page switching.
void SwitchState( wxPropertyGridPageState* pNewState );

View File

@@ -716,7 +716,6 @@ class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty
{
WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty)
public:
wxArrayStringProperty( const wxString& label = wxPG_LABEL,
const wxString& name = wxPG_LABEL,
const wxArrayString& value = wxArrayString() );
@@ -729,8 +728,12 @@ public:
int argFlags = 0 ) const;
virtual bool OnEvent( wxPropertyGrid* propgrid,
wxWindow* primary, wxEvent& event );
virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
virtual void GenerateValueAsString();
// Implement in derived class for custom array-to-string conversion.
virtual void ConvertArrayToString(const wxArrayString& arr,
wxString* pString,
const wxUniChar& delimiter) const;
// Shows string editor dialog. Value to be edited should be read from
// value, and if dialog is not cancelled, it should be stored back and true
@@ -745,8 +748,27 @@ public:
// Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
virtual wxPGArrayEditorDialog* CreateEditorDialog();
enum ConversionFlags
{
Escape = 0x01,
QuoteStrings = 0x02
};
/**
Generates contents for string dst based on the contents of
wxArrayString src.
*/
static void ArrayStringToString( wxString& dst, const wxArrayString& src,
wxUniChar delimiter, int flags );
protected:
// Previously this was to be implemented in derived class for array-to-
// string conversion. Now you should implement ConvertValueToString()
// instead.
virtual void GenerateValueAsString();
wxString m_display; // Cache for displayed text.
wxUniChar m_delimiter;
};
// -----------------------------------------------------------------------
@@ -761,9 +783,6 @@ public: \
const wxString& name = wxPG_LABEL, \
const wxArrayString& value = wxArrayString() ); \
~PROPNAME(); \
virtual void GenerateValueAsString(); \
virtual bool StringToValue( wxVariant& value, \
const wxString& text, int = 0 ) const; \
virtual bool OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ); \
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
@@ -785,32 +804,9 @@ PROPNAME::PROPNAME( const wxString& label, \
: wxArrayStringProperty(label,name,value) \
{ \
PROPNAME::GenerateValueAsString(); \
m_delimiter = DELIMCHAR; \
} \
PROPNAME::~PROPNAME() { } \
void PROPNAME::GenerateValueAsString() \
{ \
wxChar delimChar = DELIMCHAR; \
if ( delimChar == wxS('"') ) \
wxArrayStringProperty::GenerateValueAsString(); \
else \
wxPropertyGrid::ArrayStringToString(m_display, \
m_value.GetArrayString(), \
0,DELIMCHAR,0); \
} \
bool PROPNAME::StringToValue( wxVariant& variant, \
const wxString& text, int ) const \
{ \
wxChar delimChar = DELIMCHAR; \
if ( delimChar == wxS('"') ) \
return wxArrayStringProperty::StringToValue(variant, text, 0); \
\
wxArrayString arr; \
WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
arr.Add( token ); \
WX_PG_TOKENIZER1_END() \
variant = arr; \
return true; \
} \
bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ) \
{ \

View File

@@ -130,6 +130,15 @@
*/
#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
/**
wxArrayStringProperty's string delimiter character. If this is aquotation
mark or hyphen, then strings will be quoted instead (with given
character).
Default delimiter is quotation mark.
*/
#define wxPG_ARRAY_DELIMITER wxS("Delimiter")
/** Sets displayed date format for wxDateProperty.
*/
#define wxPG_DATE_FORMAT wxS("DateFormat")

View File

@@ -277,7 +277,8 @@ wxVariant wxPointProperty::ChildChanged( wxVariant& thisValue,
// Dirs Property
// -----------------------------------------------------------------------
WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(wxDirsProperty,wxT(','),wxT("Browse"))
WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(wxDirsProperty, ',',
"Browse")
#if wxUSE_VALIDATORS

View File

@@ -2397,8 +2397,28 @@ void wxArrayStringProperty::OnSetValue()
GenerateValueAsString();
}
#define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \
wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1)
void
wxArrayStringProperty::ConvertArrayToString(const wxArrayString& arr,
wxString* pString,
const wxUniChar& delimiter) const
{
if ( delimiter == '"' || delimiter == '\'' )
{
// Quoted strings
ArrayStringToString(*pString,
arr,
delimiter,
Escape | QuoteStrings);
}
else
{
// Regular delimiter
ArrayStringToString(*pString,
arr,
delimiter,
0);
}
}
wxString wxArrayStringProperty::ValueToString( wxVariant& WXUNUSED(value),
int argFlags ) const
@@ -2412,48 +2432,46 @@ wxString wxArrayStringProperty::ValueToString( wxVariant& WXUNUSED(value),
wxArrayString arr = m_value.GetArrayString();
wxString s;
ARRSTRPROP_ARRAY_TO_STRING(s, arr);
ConvertArrayToString(arr, &s, m_delimiter);
return s;
}
// Converts wxArrayString to a string separated by delimeters and spaces.
// preDelim is useful for "str1" "str2" style. Set flags to 1 to do slash
// conversion.
void wxPropertyGrid::ArrayStringToString( wxString& dst, const wxArrayString& src,
wxChar preDelim, wxChar postDelim,
int flags )
void
wxArrayStringProperty::ArrayStringToString( wxString& dst,
const wxArrayString& src,
wxUniChar delimiter, int flags )
{
wxString pdr;
wxString preas;
unsigned int i;
unsigned int itemCount = src.size();
wxChar preas[2] = { 0, 0 };
dst.Empty();
if ( flags & 1 )
if ( flags & Escape )
{
preas[0] = preDelim;
preas[0] = delimiter;
pdr = wxS("\\");
pdr += preDelim;
pdr += delimiter;
}
if ( itemCount )
dst.append( preas );
wxASSERT( postDelim );
wxString postDelimStr(postDelim);
//wxString preDelimStr(preDelim);
wxString delimStr(delimiter);
for ( i = 0; i < itemCount; i++ )
{
wxString str( src.Item(i) );
// Do some character conversion.
// Convertes \ to \\ and <preDelim> to \<preDelim>
// Useful when preDelim and postDelim are "\"".
if ( flags & 1 )
// Converts \ to \\ and $delimiter to \$delimiter
// Useful when quoting.
if ( flags & Escape )
{
str.Replace( wxS("\\"), wxS("\\\\"), true );
if ( pdr.length() )
@@ -2464,19 +2482,19 @@ void wxPropertyGrid::ArrayStringToString( wxString& dst, const wxArrayString& sr
if ( i < (itemCount-1) )
{
dst.append( postDelimStr );
dst.append( delimStr );
dst.append( wxS(" ") );
dst.append( preas );
}
else if ( preDelim )
dst.append( postDelimStr );
else if ( flags & QuoteStrings )
dst.append( delimStr );
}
}
void wxArrayStringProperty::GenerateValueAsString()
{
wxArrayString arr = m_value.GetArrayString();
ARRSTRPROP_ARRAY_TO_STRING(m_display, arr);
ConvertArrayToString(arr, &m_display, m_delimiter);
}
// Default implementation doesn't do anything.
@@ -2534,9 +2552,10 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
{
wxArrayString actualValue = value.GetArrayString();
wxString tempStr;
ARRSTRPROP_ARRAY_TO_STRING(tempStr, actualValue);
ConvertArrayToString(actualValue, &tempStr, m_delimiter);
#if wxUSE_VALIDATORS
if ( dialogValidator.DoValidate( propGrid, validator, tempStr ) )
if ( dialogValidator.DoValidate(propGrid, validator,
tempStr) )
#endif
{
SetValueInEvent( actualValue );
@@ -2565,25 +2584,48 @@ bool wxArrayStringProperty::OnEvent( wxPropertyGrid* propGrid,
return false;
}
bool wxArrayStringProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
bool wxArrayStringProperty::StringToValue( wxVariant& variant,
const wxString& text, int ) const
{
wxArrayString arr;
WX_PG_TOKENIZER2_BEGIN(text,wxS('"'))
if ( m_delimiter == '"' || m_delimiter == '\'' )
{
// Quoted strings
WX_PG_TOKENIZER2_BEGIN(text, m_delimiter)
// Need to replace backslashes with empty characters
// (opposite what is done in GenerateValueString).
token.Replace ( wxS("\\\\"), wxS("\\"), true );
// Need to replace backslashes with empty characters
// (opposite what is done in ConvertArrayToString()).
token.Replace ( wxS("\\\\"), wxS("\\"), true );
arr.Add( token );
arr.Add( token );
WX_PG_TOKENIZER2_END()
WX_PG_TOKENIZER2_END()
}
else
{
// Regular delimiter
WX_PG_TOKENIZER1_BEGIN(text, m_delimiter)
arr.Add( token );
WX_PG_TOKENIZER1_END()
}
variant = arr;
return true;
}
bool wxArrayStringProperty::DoSetAttribute( const wxString& name, wxVariant& value )
{
if ( name == wxPG_ARRAY_DELIMITER )
{
m_delimiter = value.GetChar();
GenerateValueAsString();
return false;
}
return true;
}
// -----------------------------------------------------------------------
// wxPGInDialogValidator
// -----------------------------------------------------------------------