Eliminated last property generation macros from props.h (colour property gen ones, now use subclassing facilities present in wx(System)ColourProperty)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli 2008-10-07 17:28:05 +00:00
parent cf490c4df9
commit d61d8cffa9
5 changed files with 116 additions and 186 deletions

View File

@ -282,14 +282,29 @@ protected:
// -----------------------------------------------------------------------
WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
wxColourProperty, class WXDLLIMPEXP_PROPGRID)
class WXDLLIMPEXP_PROPGRID wxColourProperty : public wxSystemColourProperty
{
WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty)
public:
wxColourProperty( const wxString& label = wxPG_LABEL,
const wxString& name = wxPG_LABEL,
const wxColour& value = *wxWHITE );
virtual ~wxColourProperty();
protected:
virtual wxString GetValueAsString( int argFlags ) const;
virtual wxColour GetColour( int index ) const;
virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
private:
void Init( wxColour colour );
};
// -----------------------------------------------------------------------
// Exclude classes from wxPython bindings
#ifndef SWIG
// -----------------------------------------------------------------------
/** @class wxCursorProperty
@ingroup classes
Property representing wxCursor.

View File

@ -26,144 +26,9 @@ class wxArrayEditorDialog;
// Property class implementation helper macros.
//
// Adds constructor function as well.
#define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\
UPCLASS,T,T_AS_ARG,EDITOR) \
#define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME, UPCLASS, T, T_AS_ARG, EDITOR) \
IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR)
// A regular property
#define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \
WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR)
// -----------------------------------------------------------------------
#define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
DECL CLASSNAME : public wxSystemColourProperty \
{ \
DECLARE_DYNAMIC_CLASS(CLASSNAME) \
public: \
CLASSNAME( const wxString& label = wxPG_LABEL, \
const wxString& name = wxPG_LABEL, \
const wxColourPropertyValue& value = wxColourPropertyValue() ); \
virtual ~CLASSNAME(); \
virtual wxColour GetColour( int index ) const; \
};
#define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
#define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
LABELS,VALUES,COLOURS) \
static wxPGChoices gs_##CLASSNAME##_choicesCache; \
IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, wxSystemColourProperty) \
CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
const wxColourPropertyValue& value ) \
: wxSystemColourProperty(label, name, LABELS, VALUES, \
&gs_##CLASSNAME##_choicesCache, value ) \
{ \
m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
} \
CLASSNAME::~CLASSNAME () { } \
wxColour CLASSNAME::GetColour ( int index ) const \
{ \
if ( !m_choices.HasValue(index) ) \
{ \
wxASSERT( index < (int)m_choices.GetCount() ); \
return COLOURS[index]; \
} \
return COLOURS[m_choices.GetValue(index)]; \
}
// -----------------------------------------------------------------------
#define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
DECL) \
DECL CLASSNAME : public wxSystemColourProperty \
{ \
WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
public: \
CLASSNAME( const wxString& label = wxPG_LABEL, \
const wxString& name = wxPG_LABEL, \
const wxColour& value = wxColour() ); \
virtual ~CLASSNAME(); \
virtual wxString GetValueAsString( int argFlags ) const; \
virtual wxColour GetColour( int index ) const; \
virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
void Init( wxColour colour ); \
};
#define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
#define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
LABELS, \
VALUES, \
COLOURS, \
EDITOR) \
static wxPGChoices gs_##CLASSNAME##_choicesCache; \
WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
wxColour, const wxColour&,EDITOR) \
CLASSNAME::CLASSNAME( const wxString& label, \
const wxString& name, \
const wxColour& value ) \
: wxSystemColourProperty(label, name, LABELS, VALUES, \
&gs_##CLASSNAME##_choicesCache, value ) \
{ \
if ( &value ) \
Init( value ); \
else \
Init( *wxWHITE ); \
m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
} \
CLASSNAME::~CLASSNAME() { } \
void CLASSNAME::Init( wxColour colour ) \
{ \
if ( !colour.Ok() ) \
colour = *wxWHITE; \
wxVariant variant; \
variant << colour; \
m_value = variant; \
int ind = ColToInd(colour); \
if ( ind < 0 ) \
ind = m_choices.GetCount() - 1; \
SetIndex( ind ); \
} \
wxString CLASSNAME::GetValueAsString( int argFlags ) const \
{ \
const wxPGEditor* editor = GetEditorClass(); \
if ( editor != wxPGEditor_Choice && \
editor != wxPGEditor_ChoiceAndButton && \
editor != wxPGEditor_ComboBox ) \
argFlags |= wxPG_PROPERTY_SPECIFIC; \
return wxSystemColourProperty::GetValueAsString(argFlags); \
} \
wxColour CLASSNAME::GetColour( int index ) const \
{ \
if ( !m_choices.HasValue(index) ) \
{ \
wxASSERT( index < (int)GetItemCount() ); \
return COLOURS[index]; \
} \
return COLOURS[m_choices.GetValue(index)]; \
} \
wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
{ \
wxVariant variant; \
variant << v.m_colour; \
return variant; \
}
#define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
LABELS, \
VALUES, \
COLOURS) \
WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
LABELS, \
VALUES, \
COLOURS, \
Choice)
WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR)
// -----------------------------------------------------------------------

View File

@ -329,6 +329,8 @@
<b>Useful alternate editor:</b> Choice.
Represents wxColour. wxButton is used to trigger a colour picker dialog.
There are various sub-classing opportunities with this class. See
below in wxSystemColourProperty section for details.
@subsection wxFontProperty
@ -339,7 +341,9 @@
Represents wxColour and a system colour index. wxChoice is used to edit
the value. Drop-down list has color images. Note that value type
is wxColourPropertyValue instead of wxColour.
is wxColourPropertyValue instead of wxColour (which wxColourProperty
uses).
@code
class wxColourPropertyValue : public wxObject
{
@ -357,6 +361,27 @@
};
@endcode
in wxSystemColourProperty, and its derived class wxColourProperty, there
are various sub-classing features. To set basic list list of colour
names, call wxPGProperty::SetChoices().
@code
// Override in derived class to customize how colours are translated
// to strings.
virtual wxString ColourToString( const wxColour& col, int index ) const;
// Returns index of entry that triggers colour picker dialog
// (default is last).
virtual int GetCustomColourIndex() const;
// Helper function to show the colour dialog
bool QueryColourFromUser( wxVariant& variant ) const;
// Returns colour for given choice.
// Default function returns wxSystemSettings::GetColour(index).
virtual wxColour GetColour( int index ) const;
@endcode
@subsection wxCursorProperty
Represents a wxCursor. wxChoice is used to edit the value.

View File

@ -81,23 +81,6 @@ static unsigned long mycolprop_colours[] = {
wxPG_COLOUR(0,0,0)
};
// Implement property class. Third argument is optional values array,
// but in this example we are only interested in creating a shortcut
// for user to access the colour values. Last arg is itemcount, but
// it will be deprecated in the future.
WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty)
WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty,
mycolprop_labels,
(long*)NULL,
mycolprop_colours)
WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property)
WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property,
mycolprop_labels,
(long*)NULL,
mycolprop_colours)
// -----------------------------------------------------------------------
//
@ -106,10 +89,10 @@ WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property,
// * Includes custom colour entry.
// * Includes extra custom entry.
//
class MyColourProperty3 : public wxColourProperty
class MyColourProperty : public wxColourProperty
{
public:
MyColourProperty3( const wxString& label = wxPG_LABEL,
MyColourProperty( const wxString& label = wxPG_LABEL,
const wxString& name = wxPG_LABEL,
const wxColour& value = *wxWHITE )
: wxColourProperty(label, name, value)
@ -129,7 +112,7 @@ public:
SetValue(variant);
}
virtual ~MyColourProperty3()
virtual ~MyColourProperty()
{
}
@ -174,26 +157,12 @@ public:
void FormMain::AddTestProperties( wxPropertyGridPage* pg )
{
pg->Append( new wxMyColourProperty(wxT("CustomColourProperty1")) );
pg->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL, *wxGREEN) );
pg->GetProperty(wxT("CustomColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED);
pg->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox );
pg->SetPropertyHelpString(wxT("CustomColourProperty1"),
wxT("This is a wxMyColourProperty from the sample app. ")
wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR macro ")
wxT("and has wxColour as its data type"));
pg->Append( new wxMyColour2Property(wxT("CustomColourProperty2")) );
pg->SetPropertyHelpString(wxT("CustomColourProperty2"),
wxT("This is a wxMyColour2Property from the sample app. ")
wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY macro ")
wxT("and has wxColourPropertyValue as its data type"));
pg->Append( new MyColourProperty3(wxT("CustomColourProperty3"), wxPG_LABEL, *wxGREEN) );
pg->GetProperty(wxT("CustomColourProperty3"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED);
pg->SetPropertyEditor( wxT("CustomColourProperty3"), wxPGEditor_ComboBox );
pg->SetPropertyHelpString(wxT("CustomColourProperty3"),
wxT("This is a MyColourProperty3 from the sample app. ")
pg->SetPropertyHelpString(wxT("CustomColourProperty"),
wxT("This is a MyColourProperty from the sample app. ")
wxT("It is built by subclassing wxColourProperty."));
}

View File

@ -1356,11 +1356,67 @@ static unsigned long gs_cp_es_normcolour_colours[] = {
wxPG_COLOUR(0,0,0)
};
WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(wxColourProperty,
gs_cp_es_normcolour_labels,
(const long*)NULL,
gs_cp_es_normcolour_colours,
TextCtrlAndButton)
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty, wxSystemColourProperty,
wxColour, const wxColour&, TextCtrlAndButton)
static wxPGChoices gs_wxColourProperty_choicesCache;
wxColourProperty::wxColourProperty( const wxString& label,
const wxString& name,
const wxColour& value )
: wxSystemColourProperty(label, name, gs_cp_es_normcolour_labels,
NULL,
&gs_wxColourProperty_choicesCache, value )
{
Init( value );
m_flags |= wxPG_PROP_TRANSLATE_CUSTOM;
}
wxColourProperty::~wxColourProperty()
{
}
void wxColourProperty::Init( wxColour colour )
{
if ( !colour.Ok() )
colour = *wxWHITE;
wxVariant variant;
variant << colour;
m_value = variant;
int ind = ColToInd(colour);
if ( ind < 0 )
ind = m_choices.GetCount() - 1;
SetIndex( ind );
}
wxString wxColourProperty::GetValueAsString( int argFlags ) const
{
const wxPGEditor* editor = GetEditorClass();
if ( editor != wxPGEditor_Choice &&
editor != wxPGEditor_ChoiceAndButton &&
editor != wxPGEditor_ComboBox )
argFlags |= wxPG_PROPERTY_SPECIFIC;
return wxSystemColourProperty::GetValueAsString(argFlags);
}
wxColour wxColourProperty::GetColour( int index ) const
{
if ( !m_choices.HasValue(index) )
{
wxASSERT( index < (int)GetItemCount() );
return gs_cp_es_normcolour_colours[index];
}
return gs_cp_es_normcolour_colours[m_choices.GetValue(index)];
}
wxVariant wxColourProperty::DoTranslateVal( wxColourPropertyValue& v ) const
{
wxVariant variant;
variant << v.m_colour;
return variant;
}
// -----------------------------------------------------------------------
// wxCursorProperty