Make wxArrayStringProperty a parent of wxEditorDialogProperty

wxArrayStringProperty uses TextCtrlAndButton editor so it can be implemented as parent of wxEditorDialogProperty to re-use common functions and data.
This commit is contained in:
Artur Wieczorek
2019-07-04 20:28:55 +02:00
parent a1dac5aa38
commit 9f75d4e909
3 changed files with 56 additions and 61 deletions

View File

@@ -692,7 +692,7 @@ protected:
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Property that manages a list of strings. // Property that manages a list of strings.
class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxEditorDialogProperty
{ {
WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty) WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty)
public: public:
@@ -706,8 +706,6 @@ public:
virtual bool StringToValue( wxVariant& variant, virtual bool StringToValue( wxVariant& variant,
const wxString& text, const wxString& text,
int argFlags = 0 ) const wxOVERRIDE; int argFlags = 0 ) const wxOVERRIDE;
virtual bool OnEvent( wxPropertyGrid* propgrid,
wxWindow* primary, wxEvent& event ) wxOVERRIDE;
virtual bool DoSetAttribute( const wxString& name, wxVariant& value ) wxOVERRIDE; virtual bool DoSetAttribute( const wxString& name, wxVariant& value ) wxOVERRIDE;
// Implement in derived class for custom array-to-string conversion. // Implement in derived class for custom array-to-string conversion.
@@ -720,10 +718,13 @@ public:
// should be returned if that was the case. // should be returned if that was the case.
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value );
#if WXWIN_COMPATIBILITY_3_0
// Helper. // Helper.
wxDEPRECATED_MSG("OnButtonClick() function is no longer used")
virtual bool OnButtonClick( wxPropertyGrid* propgrid, virtual bool OnButtonClick( wxPropertyGrid* propgrid,
wxWindow* primary, wxWindow* primary,
const wxChar* cbt ); const wxChar* cbt );
#endif // WXWIN_COMPATIBILITY_3_0
// Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick. // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
virtual wxPGArrayEditorDialog* CreateEditorDialog(); virtual wxPGArrayEditorDialog* CreateEditorDialog();
@@ -740,6 +741,8 @@ public:
wxUniChar delimiter, int flags ); wxUniChar delimiter, int flags );
protected: protected:
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value) wxOVERRIDE;
// Previously this was to be implemented in derived class for array-to- // Previously this was to be implemented in derived class for array-to-
// string conversion. Now you should implement ConvertValueToString() // string conversion. Now you should implement ConvertValueToString()
// instead. // instead.
@@ -747,6 +750,7 @@ protected:
wxString m_display; // Cache for displayed text. wxString m_display; // Cache for displayed text.
wxUniChar m_delimiter; wxUniChar m_delimiter;
wxString m_customBtnText;
}; };
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -761,8 +765,6 @@ public: \
const wxString& name = wxPG_LABEL, \ const wxString& name = wxPG_LABEL, \
const wxArrayString& value = wxArrayString() ); \ const wxArrayString& value = wxArrayString() ); \
~PROPNAME(); \ ~PROPNAME(); \
virtual bool OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ) wxOVERRIDE; \
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ) wxOVERRIDE; \ virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ) wxOVERRIDE; \
virtual wxValidator* DoGetValidator() const wxOVERRIDE; \ virtual wxValidator* DoGetValidator() const wxOVERRIDE; \
}; };
@@ -782,15 +784,9 @@ PROPNAME::PROPNAME( const wxString& label, \
{ \ { \
PROPNAME::GenerateValueAsString(); \ PROPNAME::GenerateValueAsString(); \
m_delimiter = DELIMCHAR; \ m_delimiter = DELIMCHAR; \
m_customBtnText = CUSTBUTTXT; \
} \ } \
PROPNAME::~PROPNAME() { } \ PROPNAME::~PROPNAME() { }
bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ) \
{ \
if ( event.GetEventType() == wxEVT_BUTTON ) \
return OnButtonClick(propgrid,primary, CUSTBUTTXT); \
return false; \
}
#define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \ #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME) WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)

View File

@@ -708,7 +708,7 @@ protected:
@ingroup classes @ingroup classes
Property that manages a list of strings. Property that manages a list of strings.
*/ */
class wxArrayStringProperty : public wxPGProperty class wxArrayStringProperty : public wxEditorDialogProperty
{ {
public: public:
wxArrayStringProperty( const wxString& label = wxPG_LABEL, wxArrayStringProperty( const wxString& label = wxPG_LABEL,
@@ -721,26 +721,24 @@ public:
virtual bool StringToValue( wxVariant& variant, virtual bool StringToValue( wxVariant& variant,
const wxString& text, const wxString& text,
int argFlags = 0 ) const; int argFlags = 0 ) const;
virtual bool OnEvent( wxPropertyGrid* propgrid,
wxWindow* primary, wxEvent& event );
virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
// Implement in derived class for custom array-to-string conversion. /**
Implement in derived class for custom array-to-string conversion.
*/
virtual void ConvertArrayToString(const wxArrayString& arr, virtual void ConvertArrayToString(const wxArrayString& arr,
wxString* pString, wxString* pString,
const wxUniChar& delimiter) const; 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 Shows string editor dialog to edit the individual item. Value to be edited
// should be returned if that was the case. should be read from @a value, and if dialog is not cancelled, it
should be stored back and @true should be returned if that was the case.
*/
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value );
// Helper. /** Creates wxPGArrayEditorDialog for string editing.
virtual bool OnButtonClick( wxPropertyGrid* propgrid, */
wxWindow* primary,
const wxChar* cbt );
// Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
virtual wxPGArrayEditorDialog* CreateEditorDialog(); virtual wxPGArrayEditorDialog* CreateEditorDialog();
enum ConversionFlags enum ConversionFlags
@@ -750,20 +748,25 @@ public:
}; };
/** /**
Generates contents for string dst based on the contents of Generates contents for string @a dst based on the contents of
wxArrayString src. wxArrayString @a src.
*/ */
static void ArrayStringToString( wxString& dst, const wxArrayString& src, static void ArrayStringToString( wxString& dst, const wxArrayString& src,
wxUniChar delimiter, int flags ); wxUniChar delimiter, int flags );
protected: protected:
// Previously this was to be implemented in derived class for array-to- virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value);
// string conversion. Now you should implement ConvertValueToString()
// instead. /**
Previously this was to be implemented in derived class for array-to-
string conversion. Now you should implement ConvertValueToString()
instead.
*/
virtual void GenerateValueAsString(); virtual void GenerateValueAsString();
wxString m_display; // Cache for displayed text. wxString m_display; // Cache for displayed text.
wxUniChar m_delimiter; wxUniChar m_delimiter;
wxString m_customBtnText;
}; };

View File

@@ -2679,16 +2679,15 @@ wxPGArrayStringEditorDialog::OnCustomNewAction(wxString* resString)
// wxArrayStringProperty // wxArrayStringProperty
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
wxPG_IMPLEMENT_PROPERTY_CLASS(wxArrayStringProperty, // Property name wxPG_IMPLEMENT_PROPERTY_CLASS(wxArrayStringProperty, wxEditorDialogProperty, TextCtrlAndButton)
wxPGProperty, // Property we inherit from
TextCtrlAndButton) // Initial editor
wxArrayStringProperty::wxArrayStringProperty( const wxString& label, wxArrayStringProperty::wxArrayStringProperty( const wxString& label,
const wxString& name, const wxString& name,
const wxArrayString& array ) const wxArrayString& array )
: wxPGProperty(label,name) : wxEditorDialogProperty(label,name)
, m_delimiter(',') , m_delimiter(',')
{ {
m_dlgStyle = wxAEDIALOG_STYLE;
SetValue( array ); SetValue( array );
} }
@@ -2804,19 +2803,24 @@ bool wxArrayStringProperty::OnCustomStringEdit( wxWindow*, wxString& )
return false; return false;
} }
#if WXWIN_COMPATIBILITY_3_0
bool wxArrayStringProperty::OnButtonClick(wxPropertyGrid* WXUNUSED(propgrid),
wxWindow* WXUNUSED(primary),
const wxChar* WXUNUSED(cbt))
{
return false;
}
#endif // WXWIN_COMPATIBILITY_3_0
wxPGArrayEditorDialog* wxArrayStringProperty::CreateEditorDialog() wxPGArrayEditorDialog* wxArrayStringProperty::CreateEditorDialog()
{ {
return new wxPGArrayStringEditorDialog(); return new wxPGArrayStringEditorDialog();
} }
bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid, bool wxArrayStringProperty::DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value)
wxWindow* WXUNUSED(primaryCtrl),
const wxChar* cbt )
{ {
// Update the value wxASSERT_MSG(value.IsType(wxPG_VARIANT_TYPE_ARRSTRING), "Function called for incompatible property");
wxVariant useValue = propGrid->GetUncommittedPropertyValue(); if ( !pg->EditorValidate() )
if ( !propGrid->EditorValidate() )
return false; return false;
// Create editor dialog. // Create editor dialog.
@@ -2829,14 +2833,15 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
wxPGArrayStringEditorDialog* strEdDlg = wxDynamicCast(dlg, wxPGArrayStringEditorDialog); wxPGArrayStringEditorDialog* strEdDlg = wxDynamicCast(dlg, wxPGArrayStringEditorDialog);
if ( strEdDlg ) if ( strEdDlg )
strEdDlg->SetCustomButton(cbt, this); strEdDlg->SetCustomButton(m_customBtnText, this);
dlg->SetDialogValue( useValue ); dlg->SetDialogValue( value );
dlg->Create(propGrid, wxEmptyString, m_label); dlg->Create(pg->GetPanel(), wxEmptyString,
m_dlgTitle.empty() ? GetLabel() : m_dlgTitle, m_dlgStyle);
if ( !wxPropertyGrid::IsSmallScreen() ) if ( !wxPropertyGrid::IsSmallScreen() )
{ {
dlg->Move( propGrid->GetGoodEditorDialogPosition(this,dlg->GetSize()) ); dlg->Move( pg->GetGoodEditorDialogPosition(this,dlg->GetSize()) );
} }
bool retVal; bool retVal;
@@ -2849,18 +2854,18 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
if ( res == wxID_OK && dlg->IsModified() ) if ( res == wxID_OK && dlg->IsModified() )
{ {
wxVariant value = dlg->GetDialogValue(); wxVariant curValue = dlg->GetDialogValue();
if ( !value.IsNull() ) if ( !curValue.IsNull() )
{ {
wxArrayString actualValue = value.GetArrayString(); wxArrayString actualValue = curValue.GetArrayString();
wxString tempStr; wxString tempStr;
ConvertArrayToString(actualValue, &tempStr, m_delimiter); ConvertArrayToString(actualValue, &tempStr, m_delimiter);
#if wxUSE_VALIDATORS #if wxUSE_VALIDATORS
if ( dialogValidator.DoValidate(propGrid, validator, if ( dialogValidator.DoValidate(pg, validator,
tempStr) ) tempStr) )
#endif #endif
{ {
SetValueInEvent( actualValue ); value = actualValue;
retVal = true; retVal = true;
break; break;
} }
@@ -2877,15 +2882,6 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
return retVal; return retVal;
} }
bool wxArrayStringProperty::OnEvent( wxPropertyGrid* propGrid,
wxWindow* primary,
wxEvent& event )
{
if ( propGrid->IsMainButtonEvent(event) )
return OnButtonClick(propGrid,primary,(const wxChar*) NULL);
return false;
}
bool wxArrayStringProperty::StringToValue( wxVariant& variant, bool wxArrayStringProperty::StringToValue( wxVariant& variant,
const wxString& text, int ) const const wxString& text, int ) const
{ {
@@ -2925,7 +2921,7 @@ bool wxArrayStringProperty::DoSetAttribute( const wxString& name, wxVariant& val
GenerateValueAsString(); GenerateValueAsString();
return true; return true;
} }
return wxPGProperty::DoSetAttribute(name, value); return wxEditorDialogProperty::DoSetAttribute(name, value);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------