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. new flags: wxPG_VFB_SHOW_MESSAGEBOX and wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR.
- wxPropertyGrid: Added wxPropertyGrid::DedicateKey(). - wxPropertyGrid: Added wxPropertyGrid::DedicateKey().
- wxPropertyGrid: wxArrayStringProperty now uses wxEditableListBox. - wxPropertyGrid: wxArrayStringProperty now uses wxEditableListBox.
- wxPropertyGrid: Added "Delimiter" attribute for wxArrayStringProperty.
- wxPropertyGridManager: added wxPG_NO_INTERNAL_BORDER, - wxPropertyGridManager: added wxPG_NO_INTERNAL_BORDER,
wxPG_EX_NO_TOOLBAR_DIVIDER and wxPG_EX_TOOLBAR_SEPARATOR styles for finer wxPG_EX_NO_TOOLBAR_DIVIDER and wxPG_EX_TOOLBAR_SEPARATOR styles for finer
control over borders. Borders around property grid are now native for 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") #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. /** Sets displayed date format for wxDateProperty.
*/ */
#define wxPG_DATE_FORMAT wxS("DateFormat") #define wxPG_DATE_FORMAT wxS("DateFormat")

View File

@@ -1520,18 +1520,6 @@ public:
// Events from editor controls are forward to this function // Events from editor controls are forward to this function
void HandleCustomEditorEvent( wxEvent &event ); 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. // Mostly useful for page switching.
void SwitchState( wxPropertyGridPageState* pNewState ); void SwitchState( wxPropertyGridPageState* pNewState );

View File

@@ -716,7 +716,6 @@ class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty
{ {
WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty) WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty)
public: public:
wxArrayStringProperty( const wxString& label = wxPG_LABEL, wxArrayStringProperty( const wxString& label = wxPG_LABEL,
const wxString& name = wxPG_LABEL, const wxString& name = wxPG_LABEL,
const wxArrayString& value = wxArrayString() ); const wxArrayString& value = wxArrayString() );
@@ -729,8 +728,12 @@ public:
int argFlags = 0 ) const; int argFlags = 0 ) const;
virtual bool OnEvent( wxPropertyGrid* propgrid, virtual bool OnEvent( wxPropertyGrid* propgrid,
wxWindow* primary, wxEvent& event ); 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 // 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 // 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. // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
virtual wxPGArrayEditorDialog* CreateEditorDialog(); 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: 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. wxString m_display; // Cache for displayed text.
wxUniChar m_delimiter;
}; };
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -761,9 +783,6 @@ public: \
const wxString& name = wxPG_LABEL, \ const wxString& name = wxPG_LABEL, \
const wxArrayString& value = wxArrayString() ); \ const wxArrayString& value = wxArrayString() ); \
~PROPNAME(); \ ~PROPNAME(); \
virtual void GenerateValueAsString(); \
virtual bool StringToValue( wxVariant& value, \
const wxString& text, int = 0 ) const; \
virtual bool OnEvent( wxPropertyGrid* propgrid, \ virtual bool OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ); \ wxWindow* primary, wxEvent& event ); \
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \ virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
@@ -785,32 +804,9 @@ PROPNAME::PROPNAME( const wxString& label, \
: wxArrayStringProperty(label,name,value) \ : wxArrayStringProperty(label,name,value) \
{ \ { \
PROPNAME::GenerateValueAsString(); \ PROPNAME::GenerateValueAsString(); \
m_delimiter = DELIMCHAR; \
} \ } \
PROPNAME::~PROPNAME() { } \ 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, \ bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ) \ wxWindow* primary, wxEvent& event ) \
{ \ { \

View File

@@ -130,6 +130,15 @@
*/ */
#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage") #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. /** Sets displayed date format for wxDateProperty.
*/ */
#define wxPG_DATE_FORMAT wxS("DateFormat") #define wxPG_DATE_FORMAT wxS("DateFormat")

View File

@@ -277,7 +277,8 @@ wxVariant wxPointProperty::ChildChanged( wxVariant& thisValue,
// Dirs Property // 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 #if wxUSE_VALIDATORS

View File

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