Make wxFontProperty and wxMultiChoiceProperty parents of wxEditorDialogProperty

wxFontProperty and wxMultiChoiceProperty use TextCtrlAndButton editor so they can be implemented as parents of wxEditorDialogProperty to share common functions and data.
This commit is contained in:
Artur Wieczorek
2019-07-02 20:54:25 +02:00
parent 37f9c6f083
commit a3ec84fdd1
3 changed files with 85 additions and 96 deletions

View File

@@ -576,12 +576,12 @@ static const long gs_fp_es_weight_values[] = {
// Class body is in advprops.h
wxPG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty,wxPGProperty,TextCtrlAndButton)
wxPG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty,wxEditorDialogProperty,TextCtrlAndButton)
wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
const wxFont& value )
: wxPGProperty(label,name)
: wxEditorDialogProperty(label,name)
{
SetValue(WXVARIANT(value));
@@ -652,37 +652,32 @@ void wxFontProperty::OnSetValue()
wxString wxFontProperty::ValueToString( wxVariant& value,
int argFlags ) const
{
return wxPGProperty::ValueToString(value, argFlags);
return wxEditorDialogProperty::ValueToString(value, argFlags);
}
bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary),
wxEvent& event )
bool wxFontProperty::DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value)
{
if ( propgrid->IsMainButtonEvent(event) )
wxFont font;
wxASSERT_MSG(value.IsType(wxS("wxFont")), "Function called for incompatible property");
if ( value.IsType(wxS("wxFont")) )
font << value;
wxFontData data;
data.SetInitialFont(font);
data.SetColour(*wxBLACK);
wxFontDialog dlg(pg->GetPanel(), data);
if ( !m_dlgTitle.empty() )
{
// Update value from last minute changes
wxVariant useValue = propgrid->GetUncommittedPropertyValue();
wxFontData data;
wxFont font;
if ( useValue.IsType(wxS("wxFont")) )
font << useValue;
data.SetInitialFont( font );
data.SetColour(*wxBLACK);
wxFontDialog dlg(propgrid, data);
if ( dlg.ShowModal() == wxID_OK )
{
propgrid->EditorsValueWasModified();
wxVariant variant;
variant << dlg.GetFontData().GetChosenFont();
SetValueInEvent( variant );
return true;
}
dlg.SetTitle(m_dlgTitle);
}
if ( dlg.ShowModal() == wxID_OK )
{
value = WXVARIANT(dlg.GetFontData().GetChosenFont());
return true;
}
return false;
}
@@ -1952,15 +1947,16 @@ void wxImageFileProperty::OnCustomPaint( wxDC& dc,
#include "wx/choicdlg.h"
wxPG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxPGProperty,
wxPG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxEditorDialogProperty,
TextCtrlAndButton)
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
const wxString& name,
const wxPGChoices& choices,
const wxArrayString& value)
: wxPGProperty(label,name)
: wxEditorDialogProperty(label,name)
{
m_dlgStyle = wxCHOICEDLG_STYLE;
m_userStringMode = 0;
m_choices.Assign(choices);
SetValue(value);
@@ -1970,8 +1966,9 @@ wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
const wxString& name,
const wxArrayString& strings,
const wxArrayString& value)
: wxPGProperty(label,name)
: wxEditorDialogProperty(label,name)
{
m_dlgStyle = wxCHOICEDLG_STYLE;
m_userStringMode = 0;
m_choices.Set(strings);
SetValue(value);
@@ -1980,8 +1977,9 @@ wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
const wxString& name,
const wxArrayString& value)
: wxPGProperty(label,name)
: wxEditorDialogProperty(label,name)
{
m_dlgStyle = wxCHOICEDLG_STYLE;
m_userStringMode = 0;
wxArrayString strings;
m_choices.Set(strings);
@@ -2062,67 +2060,59 @@ wxArrayInt wxMultiChoiceProperty::GetValueAsIndices() const
return selections;
}
bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
wxWindow* WXUNUSED(primary),
wxEvent& event )
bool wxMultiChoiceProperty::DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value)
{
if ( propgrid->IsMainButtonEvent(event) )
wxASSERT_MSG(value.IsType(wxPG_VARIANT_TYPE_ARRSTRING), "Function called for incompatible property");
if ( !m_choices.IsOk() )
{
// Update the value
wxVariant useValue = propgrid->GetUncommittedPropertyValue();
return false;
}
wxArrayString labels = m_choices.GetLabels();
unsigned int choiceCount;
wxArrayString labels = m_choices.GetLabels();
unsigned int choiceCount = m_choices.GetCount();
if ( m_choices.IsOk() )
choiceCount = m_choices.GetCount();
else
choiceCount = 0;
// launch editor dialog
wxMultiChoiceDialog dlg( pg->GetPanel(),
_("Make a selection:"),
m_dlgTitle.empty() ? GetLabel() : m_dlgTitle,
choiceCount,
choiceCount?&labels[0]:NULL,
m_dlgStyle );
// launch editor dialog
wxMultiChoiceDialog dlg( propgrid,
_("Make a selection:"),
m_label,
choiceCount,
choiceCount?&labels[0]:NULL,
wxCHOICEDLG_STYLE );
dlg.Move( pg->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
wxArrayString strings = value.GetArrayString();
wxArrayString extraStrings;
wxArrayString strings = useValue.GetArrayString();
wxArrayString extraStrings;
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
if ( dlg.ShowModal() == wxID_OK && choiceCount )
{
wxArrayInt arrInt = dlg.GetSelections();
if ( dlg.ShowModal() == wxID_OK && choiceCount )
// Strings that were not in list of choices
wxArrayString newValue;
// Translate string indices to strings
size_t n;
if ( m_userStringMode == 1 )
{
wxArrayInt arrInt = dlg.GetSelections();
// Strings that were not in list of choices
wxArrayString value;
// Translate string indices to strings
unsigned int n;
if ( m_userStringMode == 1 )
{
for (n=0;n<extraStrings.size();n++)
value.push_back(extraStrings[n]);
}
for ( size_t i = 0; i < arrInt.size(); i++ )
value.Add(m_choices.GetLabel(arrInt.Item(i)));
if ( m_userStringMode == 2 )
{
for (n=0;n<extraStrings.size();n++)
value.push_back(extraStrings[n]);
}
SetValueInEvent(wxVariant(value));
return true;
for (n=0;n<extraStrings.size();n++)
newValue.push_back(extraStrings[n]);
}
for ( size_t i = 0; i < arrInt.size(); i++ )
newValue.push_back(m_choices.GetLabel(arrInt[i]));
if ( m_userStringMode == 2 )
{
for (n=0;n<extraStrings.size();n++)
newValue.push_back(extraStrings[n]);
}
value = wxVariant(newValue);
return true;
}
return false;
}
@@ -2149,7 +2139,7 @@ bool wxMultiChoiceProperty::DoSetAttribute( const wxString& name, wxVariant& val
m_userStringMode = (int)value.GetLong();
return true;
}
return wxPGProperty::DoSetAttribute(name, value);
return wxEditorDialogProperty::DoSetAttribute(name, value);
}
#endif // wxUSE_CHOICEDLG