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:
@@ -137,7 +137,7 @@ DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
// Property representing wxFont.
|
||||
class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty
|
||||
class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxEditorDialogProperty
|
||||
{
|
||||
WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
|
||||
public:
|
||||
@@ -148,14 +148,13 @@ public:
|
||||
virtual ~wxFontProperty();
|
||||
virtual void OnSetValue() wxOVERRIDE;
|
||||
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const wxOVERRIDE;
|
||||
virtual bool OnEvent( wxPropertyGrid* propgrid,
|
||||
wxWindow* primary, wxEvent& event ) wxOVERRIDE;
|
||||
virtual wxVariant ChildChanged( wxVariant& thisValue,
|
||||
int childIndex,
|
||||
wxVariant& childValue ) const wxOVERRIDE;
|
||||
virtual void RefreshChildren() wxOVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value) wxOVERRIDE;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -317,7 +316,7 @@ private:
|
||||
// Property that manages a value resulting from wxMultiChoiceDialog. Value is
|
||||
// array of strings. You can get value as array of choice values/indices by
|
||||
// calling wxMultiChoiceProperty::GetValueAsArrayInt().
|
||||
class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxPGProperty
|
||||
class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxEditorDialogProperty
|
||||
{
|
||||
WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
|
||||
public:
|
||||
@@ -342,8 +341,6 @@ public:
|
||||
virtual bool StringToValue(wxVariant& variant,
|
||||
const wxString& text,
|
||||
int argFlags = 0) const wxOVERRIDE;
|
||||
virtual bool OnEvent( wxPropertyGrid* propgrid,
|
||||
wxWindow* primary, wxEvent& event ) wxOVERRIDE;
|
||||
virtual bool DoSetAttribute( const wxString& name, wxVariant& value ) wxOVERRIDE;
|
||||
|
||||
wxArrayInt GetValueAsArrayInt() const
|
||||
@@ -352,6 +349,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value) wxOVERRIDE;
|
||||
|
||||
void GenerateValueAsString( wxVariant& value, wxString* target ) const;
|
||||
|
||||
|
@@ -66,22 +66,22 @@ public:
|
||||
@ingroup classes
|
||||
Property representing wxFont.
|
||||
*/
|
||||
class wxFontProperty : public wxPGProperty
|
||||
class wxFontProperty : public wxEditorDialogProperty
|
||||
{
|
||||
public:
|
||||
|
||||
wxFontProperty(const wxString& label = wxPG_LABEL,
|
||||
const wxString& name = wxPG_LABEL,
|
||||
const wxFont& value = wxFont());
|
||||
virtual ~wxFontProperty();
|
||||
virtual void OnSetValue();
|
||||
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
|
||||
virtual bool OnEvent( wxPropertyGrid* propgrid,
|
||||
wxWindow* primary, wxEvent& event );
|
||||
virtual wxVariant ChildChanged( wxVariant& thisValue,
|
||||
int childIndex,
|
||||
wxVariant& childValue ) const;
|
||||
virtual void RefreshChildren();
|
||||
|
||||
protected:
|
||||
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value);
|
||||
};
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ protected:
|
||||
user strings are preferably placed in front of valid choices. If value is
|
||||
2, then those strings will placed behind valid choices.
|
||||
*/
|
||||
class wxMultiChoiceProperty : public wxPGProperty
|
||||
class wxMultiChoiceProperty : public wxEditorDialogProperty
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -278,12 +278,11 @@ public:
|
||||
virtual bool StringToValue(wxVariant& variant,
|
||||
const wxString& text,
|
||||
int argFlags = 0) const;
|
||||
virtual bool OnEvent( wxPropertyGrid* propgrid,
|
||||
wxWindow* primary, wxEvent& event );
|
||||
|
||||
wxArrayInt GetValueAsArrayInt() const;
|
||||
|
||||
protected:
|
||||
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value);
|
||||
|
||||
void GenerateValueAsString( wxVariant& value, wxString* target ) const;
|
||||
|
||||
@@ -294,6 +293,8 @@ protected:
|
||||
|
||||
// Cache displayed text since generating it is relatively complicated.
|
||||
wxString m_display;
|
||||
// How to handle user strings
|
||||
int m_userStringMode;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user