📄 propgrid.h
字号:
/** One returned by GetPropertyClassName */
const wxChar* m_name;
/** Classinfo of the base property class. */
const wxPGPropertyClassInfo* m_baseInfo;
/** 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;
wxPGChoices* m_choices;
int m_itemCount;
};
// -----------------------------------------------------------------------
/** \class wxPGPropertyDataExt
\ingroup classes
\brief wxPGPropertyDataExt is data extension class for wxPGProperty.
*/
class WXDLLIMPEXP_PG wxPGPropertyDataExt
{
public:
wxPGPropertyDataExt()
{
#if wxUSE_VALIDATORS
m_validator = (wxValidator*) NULL;
#endif
m_customEditor = (wxPGEditor*) NULL;
m_valueBitmap = (wxBitmap*) NULL;
}
~wxPGPropertyDataExt()
{
// Do not delete m_customEditor
#if wxUSE_VALIDATORS
delete m_validator;
#endif
delete m_valueBitmap;
}
// For conviency, declare all members public.
wxString m_helpString; // Help shown in statusbar or help box.
const wxPGEditor* m_customEditor; // Overrides editor returned by property class
#if wxUSE_VALIDATORS
// NOTE: This is candidate for hash mapping.
wxValidator* m_validator; // Editor is going to get this validator
#endif
wxBitmap* m_valueBitmap; // Show this in front of the value
};
#endif
// -----------------------------------------------------------------------
/** \class wxPGProperty
\ingroup classes
\brief wxPGProperty, alias wxBasePropertyClass, is base class for properties.
Information here is provided primarily for anyone who creates new properties,
since <b>all operations on properties should be done via wxPropertyGrid's or
wxPropertyGridManager's methods</b>.
\remarks
- When changing name of a property, it is essential to use wxPropertyGrid::SetPropertyName
(that's why there is no SetName method).
*/
class WXDLLIMPEXP_PG wxPGProperty
{
#ifndef SWIG
friend class wxPGPropertyWithChildren;
friend class wxPropertyGrid;
friend class wxPropertyContainerMethods;
friend class wxPropertyGridState;
#endif
public:
// PYSWIG is a special symbol used by my custom scripts. Code to remove it
// automatically should be added in future.
#ifndef PYSWIG
/** Basic constructor. Should not be necessary to override.
*/
wxPGProperty();
#endif
/** Constructor.
Real used property classes should have constructor of this style:
\code
// If MyValueType is a class, then it should be a constant reference
// (e.g. const MyValueType& ) instead.
wxMyProperty( const wxString& label, const wxString& name,
MyValueType value ) : wxPGProperty
{
// Only required if MyValueType is not built-in default
// (wxString, long, double, bool, and wxArrayString are;
// wxFont, wxColour, etc. are not).
wxPG_INIT_REQUIRED_TYPE(MyValueType)
DoSetValue(value); // Generally recommended way to set the initial value.
// If has child properties (i.e. wxPGPropertyWithChildren is used
// as the parent class), then create children here. For example:
// AddChild( new wxStringProperty( wxT("Subprop 1"), wxPG_LABEL, value.GetSubProp1() ) );
}
\endcode
Of course, in this example, wxPGProperty could also be wxPGPropertyWithChildren
(if it has sub-properties) or actually any other property class.
*/
wxPGProperty( const wxString& label, const wxString& name );
/** Virtual destructor. It is customary for derived properties to override this. */
virtual ~wxPGProperty();
/** Sets property's internal value.
\param value
Simple container with GetString(), GetLong() etc. methods. Currently recommended
means to extract value is to use wxPGVariantToXXX(value) macro.
\remarks
Example pseudo-implementation with comments:
\code
void wxMyProperty::DoSetValue ( wxPGVariant value )
{
// A) Get value. For example
const wxMyValueType* pvalue = wxPGVariantToWxObjectPtr(value,wxMyValueType);
// or:
const wxString& str = wxPGVariantToString(value);
// or:
long val = wxPGVariantToLong(value);
// B) If value is wxObject or void based with NULL default, then handle that:
if ( pvalue )
m_value = *pvalue;
else
pmyvalue->SetToDefault();
// Otherwise
// m_value = *pvalue;
// is sufficient.
// C) If has children, this should be here (before displaying in control).
RefreshChildren();
}
\endcode
*/
virtual void DoSetValue( wxPGVariant value );
/** Returns properly constructed wxPGVariant.
*/
virtual wxPGVariant DoGetValue() const;
/** Returns text representation of property's value.
\param argFlags
If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable
one (they may be different).
*/
virtual wxString GetValueAsString( int argFlags = 0 ) const;
/** Converts string to a value, and if succesfull, calls DoSetValue() on it.
Default behaviour is to do nothing.
\param text
String to get the value from.
\param report_error
If true, invalid string will be reported (prefer to use wxLogError).
\retval
true if value was changed.
*/
virtual bool SetValueFromString( const wxString& text, int flags = 0 );
/** Converts integer to a value, and if succesfull, calls DoSetValue() on it.
Default behaviour is to do nothing.
\param value
Int to get the value from.
\param flags
If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
\retval
true if value was changed.
*/
virtual bool SetValueFromInt( long value, int flags = 0 );
/** Returns size of the custom painted image in front of property. This method
must be overridden to return non-default value if OnCustomPaint is to be
called.
\remarks
- If flexible image size is desired, return wxPG_FLEXIBLE_SIZE(wid,hei).
OnCustomPaint is then called to measure items as well (see for
wxPGProperty::OnCustomPaint for measure call specs).
- If entire property, including text, is to be custom painted, then
wxPG_FULL_CUSTOM_PAINT_SIZE(hei) or wxPG_FULL_CUSTOM_PAINT_FLEXIBLE_SIZE(hei)
is to be returned.
- Default behaviour is to return wxSize(0,0), which means no image.
- Default image width or height is indicated with dimension -1.
*/
virtual wxSize GetImageSize() const;
/** Events received by editor widgets are processed here. Note that editor class
usually processes most events. Some, such as button press events of
TextCtrlAndButton class, should be handled here. Also, if custom handling
for regular events is desired, then that can also be done (for example,
wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED).
\param event
Associated wxEvent.
\retval
Should return true if any changes in value should be reported. This is case,
for example, when enter is pressed in wxTextCtrl.
*/
virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_primary, wxEvent& event );
#if wxPG_INCLUDE_WXOBJECT
inline wxPG_CONST_WXCHAR_PTR GetClassName() const
{
return GetClassInfo()->GetClassName();
}
#else
/** Returns classname (for example, "wxStringProperty" for wxStringProperty)
of a property class.
*/
virtual wxPG_CONST_WXCHAR_PTR GetClassName() const = 0;
#endif
/** Returns pointer to the object that has methods related to
the value type of this property. Keep atleast this method
abstract so the class is kept abstract.
*/
#ifndef __WXPYTHON__
virtual const wxPGValueType* GetValueType() const = 0;
#else
#ifndef SWIG
virtual const wxPGValueType* GetValueType() const;
#endif
// Implement this in Python
virtual wxString GetType() const;
#endif
#if !wxPG_VALUETYPE_IS_STRING
const wxPGValueType* GetValueTypePtr() const { return GetValueType(); }
#else
const wxPGValueType* GetValueTypePtr() const;
#endif
#ifndef SWIG
/** Returns pointer to an instance of editor class.
*/
virtual const wxPGEditor* DoGetEditorClass() const;
#endif
#ifdef __WXPYTHON__
/** Returns name of editor used. Takes precendence in the wxPython bindings.
*/
virtual wxString GetEditor() const;
#endif
#if wxUSE_VALIDATORS
/** Returns pointer to the wxValidator that should be used
with the editor of this property (NULL for no validator).
Setting validator explicitly via SetPropertyValidator
will override this.
In most situations, code like this should work well
(macros are used to maintain one actual validator instance,
so on the second call the function exits within the first
macro):
\code
wxValidator* wxMyPropertyClass::DoGetValidator () const
{
WX_PG_DOGETVALIDATOR_ENTRY()
wxMyValidator* validator = new wxMyValidator(...);
... prepare validator...
WX_PG_DOGETVALIDATOR_EXIT(validator)
}
\endcode
\remarks
You can get common filename validator by returning
wxFilePropertyClass::GetClassValidator(). wxDirProperty,
for example, uses it.
*/
virtual wxValidator* DoGetValidator () const;
#endif // #if wxUSE_VALIDATORS
/** Returns 0 for normal items. 1 for categories, -1 for other properties with children,
-2 for wxCustomProperty (mostly like -1 ones but with few expections).
\remarks
Should not be overridden by new custom properties. Usually only used internally.
*/
inline signed char GetParentingType() const { return m_parentingType; }
/** Returns current value's index to the choice control. May also return,
through pointer arguments, strings that should be inserted to that control.
Irrelevant to classes which do not employ wxPG_EDITOR(Choice) or similar.
\remarks
- If returns -1 in choiceinfo->m_itemCount, then in that case this
class be derived from wxBaseEnumPropertyClass (see propdev.h) and
GetEntry is used to fill an array (slower, but handier if you don't
store your labels as arrays of strings).
- Must not crash even if property's set of choices is uninitialized
(i.e. it points to wxPGGlobalVars->m_emptyConstants).
*/
virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo );
/** Override to paint an image in front of the property value text or drop-down
list item (but only if wxPGProperty::GetImageSize is overridden as well).
If property's GetImageSize() returns size that has height != 0 but less than
row height ( < 0 has special meanings), wxPropertyGrid calls this method to
draw a custom image in a limited area in front of the editor control or
value text/graphics, and if control has drop-down list, then the image is
drawn there as well (even in the case GetImageSize() returned higher height
than row height).
NOTE: Following applies when GetImageSize() returns a "flexible" height (
using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
If rect.x is < 0, then this is a measure item call, which means that
dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
to the height of the image of item at index paintdata.m_choiceItem. This call
may be done even as often as once every drop-down popup show.
\param dc
wxDC to paint on.
\param rect
Box reserved for custom graphics. Includes surrounding rectangle, if any.
If x is < 0, then this is a measure item call (see above).
\param paintdata
wxPGPaintData structure with much useful data.
\remarks
- You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
must be set to the full width drawn in pixels.
- Due to technical reasons, rect's height will be default even if custom height
was reported during measure call.
- Changing font and text colour affects the text drawn next to the painted image
(which is done immediately after the OnCustomPaint call finishes).
- Brush is guaranteed to be default background colour. It has been already used to
clear the background of area being painted. It can be modified.
- Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
drawing framing rectangle. It can be changed as well.
\sa @link GetValueAsString @endlink
*/
virtual void OnCustomPaint( wxDC& dc,
const wxRect& rect, wxPGPaintData& paintdata );
/** Sets an attribute of this p
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -