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.
|
// Property representing wxFont.
|
||||||
class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty
|
class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxEditorDialogProperty
|
||||||
{
|
{
|
||||||
WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
|
WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
|
||||||
public:
|
public:
|
||||||
@@ -148,14 +148,13 @@ public:
|
|||||||
virtual ~wxFontProperty();
|
virtual ~wxFontProperty();
|
||||||
virtual void OnSetValue() wxOVERRIDE;
|
virtual void OnSetValue() wxOVERRIDE;
|
||||||
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const 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,
|
virtual wxVariant ChildChanged( wxVariant& thisValue,
|
||||||
int childIndex,
|
int childIndex,
|
||||||
wxVariant& childValue ) const wxOVERRIDE;
|
wxVariant& childValue ) const wxOVERRIDE;
|
||||||
virtual void RefreshChildren() wxOVERRIDE;
|
virtual void RefreshChildren() wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value) wxOVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -317,7 +316,7 @@ private:
|
|||||||
// Property that manages a value resulting from wxMultiChoiceDialog. Value is
|
// Property that manages a value resulting from wxMultiChoiceDialog. Value is
|
||||||
// array of strings. You can get value as array of choice values/indices by
|
// array of strings. You can get value as array of choice values/indices by
|
||||||
// calling wxMultiChoiceProperty::GetValueAsArrayInt().
|
// calling wxMultiChoiceProperty::GetValueAsArrayInt().
|
||||||
class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxPGProperty
|
class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxEditorDialogProperty
|
||||||
{
|
{
|
||||||
WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
|
WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
|
||||||
public:
|
public:
|
||||||
@@ -342,8 +341,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;
|
||||||
|
|
||||||
wxArrayInt GetValueAsArrayInt() const
|
wxArrayInt GetValueAsArrayInt() const
|
||||||
@@ -352,6 +349,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value) wxOVERRIDE;
|
||||||
|
|
||||||
void GenerateValueAsString( wxVariant& value, wxString* target ) const;
|
void GenerateValueAsString( wxVariant& value, wxString* target ) const;
|
||||||
|
|
||||||
|
@@ -66,22 +66,22 @@ public:
|
|||||||
@ingroup classes
|
@ingroup classes
|
||||||
Property representing wxFont.
|
Property representing wxFont.
|
||||||
*/
|
*/
|
||||||
class wxFontProperty : public wxPGProperty
|
class wxFontProperty : public wxEditorDialogProperty
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
wxFontProperty(const wxString& label = wxPG_LABEL,
|
wxFontProperty(const wxString& label = wxPG_LABEL,
|
||||||
const wxString& name = wxPG_LABEL,
|
const wxString& name = wxPG_LABEL,
|
||||||
const wxFont& value = wxFont());
|
const wxFont& value = wxFont());
|
||||||
virtual ~wxFontProperty();
|
virtual ~wxFontProperty();
|
||||||
virtual void OnSetValue();
|
virtual void OnSetValue();
|
||||||
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
|
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
|
||||||
virtual bool OnEvent( wxPropertyGrid* propgrid,
|
|
||||||
wxWindow* primary, wxEvent& event );
|
|
||||||
virtual wxVariant ChildChanged( wxVariant& thisValue,
|
virtual wxVariant ChildChanged( wxVariant& thisValue,
|
||||||
int childIndex,
|
int childIndex,
|
||||||
wxVariant& childValue ) const;
|
wxVariant& childValue ) const;
|
||||||
virtual void RefreshChildren();
|
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
|
user strings are preferably placed in front of valid choices. If value is
|
||||||
2, then those strings will placed behind valid choices.
|
2, then those strings will placed behind valid choices.
|
||||||
*/
|
*/
|
||||||
class wxMultiChoiceProperty : public wxPGProperty
|
class wxMultiChoiceProperty : public wxEditorDialogProperty
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -278,12 +278,11 @@ 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 );
|
|
||||||
|
|
||||||
wxArrayInt GetValueAsArrayInt() const;
|
wxArrayInt GetValueAsArrayInt() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value);
|
||||||
|
|
||||||
void GenerateValueAsString( wxVariant& value, wxString* target ) const;
|
void GenerateValueAsString( wxVariant& value, wxString* target ) const;
|
||||||
|
|
||||||
@@ -294,6 +293,8 @@ protected:
|
|||||||
|
|
||||||
// Cache displayed text since generating it is relatively complicated.
|
// Cache displayed text since generating it is relatively complicated.
|
||||||
wxString m_display;
|
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
|
// 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,
|
wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
|
||||||
const wxFont& value )
|
const wxFont& value )
|
||||||
: wxPGProperty(label,name)
|
: wxEditorDialogProperty(label,name)
|
||||||
{
|
{
|
||||||
SetValue(WXVARIANT(value));
|
SetValue(WXVARIANT(value));
|
||||||
|
|
||||||
@@ -652,37 +652,32 @@ void wxFontProperty::OnSetValue()
|
|||||||
wxString wxFontProperty::ValueToString( wxVariant& value,
|
wxString wxFontProperty::ValueToString( wxVariant& value,
|
||||||
int argFlags ) const
|
int argFlags ) const
|
||||||
{
|
{
|
||||||
return wxPGProperty::ValueToString(value, argFlags);
|
return wxEditorDialogProperty::ValueToString(value, argFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary),
|
bool wxFontProperty::DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value)
|
||||||
wxEvent& event )
|
|
||||||
{
|
{
|
||||||
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
|
dlg.SetTitle(m_dlgTitle);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ( dlg.ShowModal() == wxID_OK )
|
||||||
|
{
|
||||||
|
value = WXVARIANT(dlg.GetFontData().GetChosenFont());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1952,15 +1947,16 @@ void wxImageFileProperty::OnCustomPaint( wxDC& dc,
|
|||||||
|
|
||||||
#include "wx/choicdlg.h"
|
#include "wx/choicdlg.h"
|
||||||
|
|
||||||
wxPG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxPGProperty,
|
wxPG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxEditorDialogProperty,
|
||||||
TextCtrlAndButton)
|
TextCtrlAndButton)
|
||||||
|
|
||||||
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
|
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
|
||||||
const wxString& name,
|
const wxString& name,
|
||||||
const wxPGChoices& choices,
|
const wxPGChoices& choices,
|
||||||
const wxArrayString& value)
|
const wxArrayString& value)
|
||||||
: wxPGProperty(label,name)
|
: wxEditorDialogProperty(label,name)
|
||||||
{
|
{
|
||||||
|
m_dlgStyle = wxCHOICEDLG_STYLE;
|
||||||
m_userStringMode = 0;
|
m_userStringMode = 0;
|
||||||
m_choices.Assign(choices);
|
m_choices.Assign(choices);
|
||||||
SetValue(value);
|
SetValue(value);
|
||||||
@@ -1970,8 +1966,9 @@ wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
|
|||||||
const wxString& name,
|
const wxString& name,
|
||||||
const wxArrayString& strings,
|
const wxArrayString& strings,
|
||||||
const wxArrayString& value)
|
const wxArrayString& value)
|
||||||
: wxPGProperty(label,name)
|
: wxEditorDialogProperty(label,name)
|
||||||
{
|
{
|
||||||
|
m_dlgStyle = wxCHOICEDLG_STYLE;
|
||||||
m_userStringMode = 0;
|
m_userStringMode = 0;
|
||||||
m_choices.Set(strings);
|
m_choices.Set(strings);
|
||||||
SetValue(value);
|
SetValue(value);
|
||||||
@@ -1980,8 +1977,9 @@ wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
|
|||||||
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
|
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
|
||||||
const wxString& name,
|
const wxString& name,
|
||||||
const wxArrayString& value)
|
const wxArrayString& value)
|
||||||
: wxPGProperty(label,name)
|
: wxEditorDialogProperty(label,name)
|
||||||
{
|
{
|
||||||
|
m_dlgStyle = wxCHOICEDLG_STYLE;
|
||||||
m_userStringMode = 0;
|
m_userStringMode = 0;
|
||||||
wxArrayString strings;
|
wxArrayString strings;
|
||||||
m_choices.Set(strings);
|
m_choices.Set(strings);
|
||||||
@@ -2062,67 +2060,59 @@ wxArrayInt wxMultiChoiceProperty::GetValueAsIndices() const
|
|||||||
return selections;
|
return selections;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
|
bool wxMultiChoiceProperty::DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value)
|
||||||
wxWindow* WXUNUSED(primary),
|
|
||||||
wxEvent& event )
|
|
||||||
{
|
{
|
||||||
if ( propgrid->IsMainButtonEvent(event) )
|
wxASSERT_MSG(value.IsType(wxPG_VARIANT_TYPE_ARRSTRING), "Function called for incompatible property");
|
||||||
|
if ( !m_choices.IsOk() )
|
||||||
{
|
{
|
||||||
// Update the value
|
return false;
|
||||||
wxVariant useValue = propgrid->GetUncommittedPropertyValue();
|
}
|
||||||
|
|
||||||
wxArrayString labels = m_choices.GetLabels();
|
wxArrayString labels = m_choices.GetLabels();
|
||||||
unsigned int choiceCount;
|
unsigned int choiceCount = m_choices.GetCount();
|
||||||
|
|
||||||
if ( m_choices.IsOk() )
|
// launch editor dialog
|
||||||
choiceCount = m_choices.GetCount();
|
wxMultiChoiceDialog dlg( pg->GetPanel(),
|
||||||
else
|
_("Make a selection:"),
|
||||||
choiceCount = 0;
|
m_dlgTitle.empty() ? GetLabel() : m_dlgTitle,
|
||||||
|
choiceCount,
|
||||||
|
choiceCount?&labels[0]:NULL,
|
||||||
|
m_dlgStyle );
|
||||||
|
|
||||||
// launch editor dialog
|
dlg.Move( pg->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
||||||
wxMultiChoiceDialog dlg( propgrid,
|
|
||||||
_("Make a selection:"),
|
|
||||||
m_label,
|
|
||||||
choiceCount,
|
|
||||||
choiceCount?&labels[0]:NULL,
|
|
||||||
wxCHOICEDLG_STYLE );
|
|
||||||
|
|
||||||
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
wxArrayString strings = value.GetArrayString();
|
||||||
|
wxArrayString extraStrings;
|
||||||
|
|
||||||
wxArrayString strings = useValue.GetArrayString();
|
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
|
||||||
wxArrayString 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();
|
for (n=0;n<extraStrings.size();n++)
|
||||||
|
newValue.push_back(extraStrings[n]);
|
||||||
// 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 ( 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;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2149,7 +2139,7 @@ bool wxMultiChoiceProperty::DoSetAttribute( const wxString& name, wxVariant& val
|
|||||||
m_userStringMode = (int)value.GetLong();
|
m_userStringMode = (int)value.GetLong();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return wxPGProperty::DoSetAttribute(name, value);
|
return wxEditorDialogProperty::DoSetAttribute(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_CHOICEDLG
|
#endif // wxUSE_CHOICEDLG
|
||||||
|
Reference in New Issue
Block a user