📄 propgrid.h
字号:
/** Returns default value.
*/
virtual wxPGVariant GetDefaultValue () const = 0;
/** Creates wxVariant with supplied value and name.
*/
virtual wxVariant GenerateVariant ( wxPGVariant value, const wxString& name ) const = 0;
/** Creates new property instance with "proper" class. Initial value is set
to default.
*/
virtual wxPGProperty* GenerateProperty ( const wxString& label, const wxString& name ) const = 0;
/** Sets property value from wxVariant.
*/
virtual void SetValueFromVariant ( wxPGProperty* property, wxVariant& value ) const = 0;
/** Returns type that can be passed to CreatePropertyByType.
*/
inline const wxChar* GetType() const
{
return GetCustomTypeName();
}
protected:
};
// -----------------------------------------------------------------------
#if wxPG_USE_VALIDATORS
/** \class wxPropertyValidator
\ingroup Classes
\brief Classes derived from this one can be used to validate values
edited for a property.
wxIntPropertyValidator and wxFloatPropertyValidator are built-in for
setting minimum and maximum values for a property that has matching
value type.
Example of use:
\code
// Limit value to -100,100 range.
wxIntPropertyValidator int_validator(-100,100);
wxPGId pid = pg->Append ( wxIntProperty( wxT("Value (-100 - 100)"), wxPG_LABEL ) );
pg->SetPropertyValidator ( pid, int_validator );
\endcode
Also, if property is of array type, it can use validator if type of
all its entries match type handled by a validator (so, for example,
sample wxArrayDoubleProperty can use wxFloatPropertyValidator to
validate on per-item basis).
Note that validators can only check if value is bad - they cannot
change it. Also, if you do a custom property class take note that
properties do not use validators automatically. See following
source code (in propgrid.cpp and propgridsample.cpp) for example
of implementation:
wxStringPropertyClass::SetValueFromString:
wxIntPropertyClass::SetValueFromString:
wxFloatPropertyClass::SetValueFromString:
wxArrayDoublePropertyClass::SetValueFromString
As can be noted from the method location of validation (i.e.
not in DoSetValue), value is not checked when set programmatically
(if you really need this, then make a feature request).
*/
class WXDLLIMPEXP_PG wxPropertyValidator
{
public:
wxPropertyValidator();
virtual ~wxPropertyValidator();
/** Must be implemented to create clone of this object.
*/
virtual wxPropertyValidator* Clone() const = 0;
/** Validates value. If not valid, will be modified to best
possible value.
\param value
Value to be validated.
Beware, this is not typesafe nor persistent variant, but should do
since custom properties that need to use this are not common.
\param showmsg
Fill this if you want to show a custom error message (shown usually
as a tooltip or statusbar text).
\retval
Returns TRUE if validation was succesfull (i.e. value is ok).
*/
virtual bool Validate ( wxPGVariant& value, wxString& showmsg ) const = 0;
#ifdef __WXDEBUG__
virtual void AssertDataType ( const wxChar* typestr ) const;
#else
/** Not necessary to override. Virtual out-of-inline method in debug mode only
(__WXDEBUG__ defined). Does not do anything in release mode. When implemented,
must cause assertion failure if type given as argument is not supported.
*/
inline void AssertDataType ( const wxChar* ) { }
#endif
/** For reference counting (no need to call in user code).
*/
wxPropertyValidator* Ref();
/** For reference counting (no need to call in user code).
*/
bool UnRef();
private:
wxPropertyValidator* m_refObject;
int m_refCount;
};
/** \class wxStringPropertyValidator
\ingroup Classes
\brief Use as validator for wxStringProperty (and maybe some others,
such as wxArrayStringProperty).
Implements character exclusion.
*/
class WXDLLIMPEXP_PG wxStringPropertyValidator : public wxPropertyValidator
{
public:
/** \param excludeList
List of characters that are not allowed.
*/
wxStringPropertyValidator( const wxString& excludeList );
virtual ~wxStringPropertyValidator();
virtual wxPropertyValidator* Clone() const;
virtual bool Validate ( wxPGVariant& value, wxString& showmsg ) const;
#ifdef __WXDEBUG__
virtual void AssertDataType ( const wxChar* typestr ) const;
#endif
protected:
wxString m_excludeList;
};
/** \class wxIntPropertyValidator
\ingroup Classes
\brief Use as validator for wxIntProperty (and maybe some others).
Implements minimum and maximum value checking.
*/
class WXDLLIMPEXP_PG wxIntPropertyValidator : public wxPropertyValidator
{
public:
wxIntPropertyValidator( long min, long max );
virtual ~wxIntPropertyValidator();
virtual wxPropertyValidator* Clone() const;
virtual bool Validate ( wxPGVariant& value, wxString& showmsg ) const;
#ifdef __WXDEBUG__
virtual void AssertDataType ( const wxChar* typestr ) const;
#endif
protected:
long m_min, m_max;
};
/** \class wxFloatPropertyValidator
\ingroup Classes
\brief Use as validator for wxFloatProperty (and maybe some others).
Implements minimum and maximum value checking.
*/
class WXDLLIMPEXP_PG wxFloatPropertyValidator : public wxPropertyValidator
{
public:
wxFloatPropertyValidator( double min, double max );
virtual ~wxFloatPropertyValidator();
virtual wxPropertyValidator* Clone() const;
virtual bool Validate ( wxPGVariant& value, wxString& showmsg ) const;
#ifdef __WXDEBUG__
virtual void AssertDataType ( const wxChar* typestr ) const;
#endif
protected:
double m_min, m_max;
};
#endif
// -----------------------------------------------------------------------
union wxPGVariantUnion
{
long m_long;
void* m_ptr;
bool m_bool;
};
// Very simple value wrapper.
class wxPGVariant
{
public:
/** Constructor for none. */
wxPGVariant ()
{
m_v.m_ptr = (void*)NULL;
}
#ifndef SWIG
/** Constructor for long integer. */
wxPGVariant ( long v_long )
{
m_v.m_long = v_long;
}
/** Constructor for integer. */
wxPGVariant ( int v_long )
{
m_v.m_long = v_long;
}
/** Constructor for bool. */
wxPGVariant ( bool value )
{
m_v.m_bool = value;
}
/** Constructor for float. */
wxPGVariant ( const double& v_ptr )
{
m_v.m_ptr = (void*)&v_ptr;
}
/** Constructor for wxString*. */
wxPGVariant ( const wxString& v_ptr )
{
m_v.m_ptr = (void*)&v_ptr;
}
/** Constructor for wxArrayString*. */
wxPGVariant ( const wxArrayString& v_ptr )
{
m_v.m_ptr = (void*)&v_ptr;
}
/** Constructor for wxObject&. */
wxPGVariant ( const wxObject& v_ptr )
{
m_v.m_ptr = (void*)&v_ptr;
}
/** Constructor for wxObject*. */
wxPGVariant ( const wxObject* v_ptr )
{
m_v.m_ptr = (void*)v_ptr;
}
/** Constructor for void*. */
wxPGVariant ( void* v_ptr )
{
m_v.m_ptr = v_ptr;
}
/** Returns value as long integer. */
inline long GetLong () const
{
return m_v.m_long;
}
/** Returns value as boolean integer. */
inline bool GetBool () const
{
return m_v.m_bool;
}
/** Returns value as floating point number. */
inline double GetDouble () const
{
return *((double*)m_v.m_ptr);
}
/** Returns value as floating point number ptr. */
inline double* GetDoublePtr () const
{
return (double*) m_v.m_ptr;
}
/** Returns value as a wxString. */
inline const wxString& GetString () const
{
return *((const wxString*)m_v.m_ptr);
}
/** Returns value as a reference to a wxArrayString. */
inline wxArrayString& GetArrayString () const
{
wxArrayString* temp = (wxArrayString*)m_v.m_ptr;
return *temp;
}
inline const wxObject& GetWxObject() const
{
return *((const wxObject*)m_v.m_ptr);
}
inline wxObject* GetWxObjectPtr() const
{
return (wxObject*)m_v.m_ptr;
}
/** Returns value as void*. */
inline void* GetVoidPtr () const
{
return m_v.m_ptr;
}
#endif
/** Returns value as long integer without type checking. */
inline long GetRawLong () const { return m_v.m_long; }
/** Returns value as void* without type checking. */
inline void* GetRawPtr () const { return m_v.m_ptr; }
#undef wxPG_ASSERT_VARIANT_GET
/** Value in portable format. */
wxPGVariantUnion m_v;
};
#define wxPGVariantToString(A) A.GetString()
#define wxPGVariantToLong(A) A.GetLong()
#define wxPGVariantToBool(A) A.GetBool()
#define wxPGVariantToDouble(A) A.GetDouble()
#define wxPGVariantToArrayString(A) A.GetArrayString()
#define wxPGVariantToWxObject(A) A.GetWxObject()
#define wxPGVariantToWxObjectPtr(A,B) wxDynamicCast((wxObject*)A.GetRawPtr(),B);
#define wxPGVariantToVoidPtr(A) A.GetVoidPtr()
#define wxPGVariantFromString(A) A
#define wxPGVariantFromLong(A) A
#define wxPGVariantFromDouble(A) A
#define wxPGVariantFromArrayString(A) A
#define wxPGVariantFromBool(A) A
#define wxPGVariantFromWxObject(A) *((const wxObject*)A)
// -----------------------------------------------------------------------
//
// Property class declaration helper macros
// (wxPGRootPropertyClass and wxPropertyCategory require this).
//
#define WX_PG_DECLARE_PROPERTY_CLASS() \
public: \
virtual const wxPGValueType* GetValueType () const; \
virtual const wxPGEditor* GetEditorClass () const; \
WX_PG_DECLARE_GETCLASSNAME() \
private:
// -----------------------------------------------------------------------
// wxPGPropertyClassInfo
typedef wxPGProperty* (*wxPGPropertyConstructor) (const wxString&,const wxString&);
/** \class wxPGPropertyClassInfo
\ingroup classes
\brief Class info structure for wxPGProperty derivatives (may be deprecated
in a future release).
*/
struct wxPGPropertyClassInfo
{
// One returned by GetPropertyClassName
const wxChar* m_name;
// Simple property constructor function.
wxPGPropertyConstructor m_constructor;
};
// Use this macro to register your custom property classes.
#define wxPGRegisterPropertyClass(NAME) \
wxPropertyGrid::RegisterPropertyClass(wxT(#NAME),&NAME##ClassInfo)
// -----------------------------------------------------------------------
// Structure for relaying choice/list info.
struct wxPGChoiceInfo
{
const wxChar** m_arrWxChars;
wxString* m_arrWxString;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -