📄 propdev.h
字号:
virtual void DoSetValue( wxPGVariant value );
virtual wxPGVariant DoGetValue() const;
virtual wxString GetValueAsString( int argFlags = 0 ) const;
virtual bool SetValueFromString( const wxString& text, int flags );
WX_PG_DECLARE_EVENT_METHODS()
// Shows string editor dialog. Value to be edited should be read from value, and
// if dialog is not cancelled, it should be stored back and true should be returned
// if that was the case.
virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value );
protected:
wxString m_value;
};
// -----------------------------------------------------------------------
// wxBoolProperty specific flags
#define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
// DCC = Double Click Cycles
#define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
// -----------------------------------------------------------------------
class WXDLLIMPEXP_PG wxArrayStringPropertyClass : public wxPGProperty
{
WX_PG_DECLARE_PROPERTY_CLASS()
public:
wxArrayStringPropertyClass( const wxString& label,
const wxString& name,
const wxArrayString& value );
virtual ~wxArrayStringPropertyClass();
WX_PG_DECLARE_BASIC_TYPE_METHODS()
WX_PG_DECLARE_EVENT_METHODS()
virtual void GenerateValueAsString();
// Shows string editor dialog. Value to be edited should be read from value, and
// if dialog is not cancelled, it should be stored back and true should be returned
// if that was the case.
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value );
// Helper.
virtual bool OnButtonClick( wxPropertyGrid* propgrid,
wxWindow* primary,
const wxChar* cbt );
// Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
virtual wxArrayEditorDialog* CreateEditorDialog();
protected:
wxArrayString m_value;
wxString m_display; // Cache for displayed text.
};
#define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
class wxPG_PROPCLASS(PROPNAME) : public wxPG_PROPCLASS(wxArrayStringProperty) \
{ \
WX_PG_DECLARE_PROPERTY_CLASS() \
public: \
wxPG_PROPCLASS(PROPNAME)( const wxString& label, const wxString& name, const wxArrayString& value ); \
~wxPG_PROPCLASS(PROPNAME)(); \
virtual void GenerateValueAsString(); \
virtual bool SetValueFromString( const wxString& text, int ); \
virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event ); \
virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
WX_PG_DECLARE_VALIDATOR_METHODS() \
}; \
WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME,wxArrayStringProperty,wxArrayString,const wxArrayString&,TextCtrlAndButton) \
wxPG_PROPCLASS(PROPNAME)::wxPG_PROPCLASS(PROPNAME) ( const wxString& label, const wxString& name, const wxArrayString& value ) \
: wxPG_PROPCLASS(wxArrayStringProperty)(label,name,value) \
{ \
wxPG_PROPCLASS(PROPNAME)::GenerateValueAsString(); \
} \
wxPG_PROPCLASS(PROPNAME)::~wxPG_PROPCLASS(PROPNAME)() { } \
void wxPG_PROPCLASS(PROPNAME)::GenerateValueAsString() \
{ \
wxChar delimChar = DELIMCHAR; \
if ( delimChar == wxT('"') ) \
wxPG_PROPCLASS(wxArrayStringProperty)::GenerateValueAsString(); \
else \
wxPropertyGrid::ArrayStringToString(m_display,m_value,0,DELIMCHAR,0); \
} \
bool wxPG_PROPCLASS(PROPNAME)::SetValueFromString( const wxString& text, int ) \
{ \
wxChar delimChar = DELIMCHAR; \
if ( delimChar == wxT('"') ) \
return wxPG_PROPCLASS(wxArrayStringProperty)::SetValueFromString(text,0); \
\
m_value.Empty(); \
WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
m_value.Add( token ); \
WX_PG_TOKENIZER1_END() \
GenerateValueAsString(); \
return true; \
} \
bool wxPG_PROPCLASS(PROPNAME)::OnEvent( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event ) \
{ \
if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
return false; \
}
#if wxUSE_VALIDATORS
#define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
wxValidator* wxPG_PROPCLASS(PROPNAME)::DoGetValidator () const \
{ return (wxValidator*) NULL; }
#else
#define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY
#endif
// -----------------------------------------------------------------------
// wxPGEditorDialog
// TODO: To be enabled for 1.3.
// -----------------------------------------------------------------------
#if 0
class wxPGEditorDialog : public wxDialog
{
public:
wxPGEditorDialog() : wxDialog()
{
m_modified = false;
}
/** Called instead non-virtual Create. Must call wxDialog::Create internally.
Note that wxPropertyGrid is always dialog's parent.
\params
custBtText: Allow setting single custom button action. Text is
button title. Event must be intercepted in property's OnEvent()
member function. Not all dialogs are expected to support this.
*/
virtual bool VCreate( wxPropertyGrid* pg,
wxPGProperty* p,
const wxString& caption,
const wxString& message,
wxVariant value,
const wxChar* custBtText = NULL ) = 0;
virtual wxVariant GetValue() const = 0;
// Returns true if value was actually modified
inline bool IsModified() const { return m_modified; }
protected:
bool m_modified;
private:
};
#endif
// -----------------------------------------------------------------------
// wxArrayEditorDialog
// -----------------------------------------------------------------------
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/listbox.h>
#define wxAEDIALOG_STYLE \
(wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
class WXDLLIMPEXP_PG wxArrayEditorDialog : public wxDialog
{
public:
wxArrayEditorDialog();
void Init();
wxArrayEditorDialog( wxWindow *parent,
const wxString& message,
const wxString& caption,
long style = wxAEDIALOG_STYLE,
const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize );
bool Create( wxWindow *parent,
const wxString& message,
const wxString& caption,
long style = wxAEDIALOG_STYLE,
const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize );
/** Set value modified by dialog.
*/
virtual void SetDialogValue( const wxVariant& WXUNUSED(value) )
{
wxFAIL_MSG(wxT("re-implement this member function in derived class"));
}
/** Return value modified by dialog.
*/
virtual wxVariant GetDialogValue() const
{
wxFAIL_MSG(wxT("re-implement this member function in derived class"));
return wxVariant();
}
/** Override to return wxValidator to be used with the wxTextCtrl
in dialog. Note that the validator is used in the standard
wx way, ie. it immediately prevents user from entering invalid
input.
\remarks
Dialog frees the validator.
*/
virtual wxValidator* GetTextCtrlValidator() const
{
return (wxValidator*) NULL;
}
// Returns true if array was actually modified
bool IsModified() const { return m_modified; }
//const wxArrayString& GetStrings() const { return m_array; }
// implementation from now on
void OnUpdateClick(wxCommandEvent& event);
void OnAddClick(wxCommandEvent& event);
void OnDeleteClick(wxCommandEvent& event);
void OnListBoxClick(wxCommandEvent& event);
void OnUpClick(wxCommandEvent& event);
void OnDownClick(wxCommandEvent& event);
//void OnCustomEditClick(wxCommandEvent& event);
void OnIdle(wxIdleEvent& event);
protected:
wxTextCtrl* m_edValue;
wxListBox* m_lbStrings;
wxButton* m_butAdd; // Button pointers
wxButton* m_butCustom; // required for disabling/enabling changing.
wxButton* m_butUpdate;
wxButton* m_butRemove;
wxButton* m_butUp;
wxButton* m_butDown;
//wxArrayString m_array;
const wxChar* m_custBtText;
//wxArrayStringPropertyClass* m_pCallingClass;
bool m_modified;
unsigned char m_curFocus;
// These must be overridden - must return true on success.
virtual wxString ArrayGet( size_t index ) = 0;
virtual size_t ArrayGetCount() = 0;
virtual bool ArrayInsert( const wxString& str, int index ) = 0;
virtual bool ArraySet( size_t index, const wxString& str ) = 0;
virtual void ArrayRemoveAt( int index ) = 0;
virtual void ArraySwap( size_t first, size_t second ) = 0;
private:
#ifndef SWIG
DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog)
DECLARE_EVENT_TABLE()
#endif
};
// -----------------------------------------------------------------------
/** This is a simple property which holds sub-properties. Has default editing
textctrl based editing capability. In essence, it is a category that has
look and feel of a property, and which children can be edited via the textctrl.
*/
class WXDLLIMPEXP_PG wxParentPropertyClass : public wxPGPropertyWithChildren
{
WX_PG_DECLARE_PROPERTY_CLASS()
public:
wxParentPropertyClass( const wxString& label, const wxString& name = wxPG_LABEL );
virtual ~wxParentPropertyClass();
virtual void DoSetValue( wxPGVariant value );
virtual wxPGVariant DoGetValue() const;
virtual void ChildChanged( wxPGProperty* p );
virtual wxString GetValueAsString( int argFlags = 0 ) const;
protected:
wxString m_string;
};
// -----------------------------------------------------------------------
#endif // #ifndef SWIG
/** \class wxCustomPropertyClass
\ingroup classes
\brief This is a rather inefficient but very versatile property class.
Base class offers the following:
- Add any properties as children (i.e. like wxParentProperty)
- Editor control can be set at run-time.
- By default has string value type.
- Has capacity to have choices.
- Can have custom-paint bitmap.
Also note:
- Has m_parentingType of -2 (technical detail).
*/
class WXDLLIMPEXP_PG wxCustomPropertyClass : public wxPGPropertyWithChildren
{
#ifndef SWIG
WX_PG_DECLARE_PROPERTY_CLASS()
#endif
public:
wxCustomPropertyClass( const wxString& label, const wxString& name = wxPG_LABEL );
virtual ~wxCustomPropertyClass();
virtual void DoSetValue( wxPGVariant value );
virtual wxPGVariant DoGetValue() const;
virtual bool SetValueFromString( const wxString& text, int flags );
virtual wxString GetValueAsString( int argFlags ) const;
#ifdef wxPG_COMPATIBILITY_1_0_0
virtual bool OnEvent ( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event );
#endif
WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
virtual bool SetValueFromInt ( long value, int arg_flags );
virtual int GetChoiceInfo ( wxPGChoiceInfo* choiceinfo );
virtual void SetAttribute ( int id, wxVariant& value );
protected:
//wxPGChoicesData* m_choices;
wxPGChoices m_choices;
#ifdef wxPG_COMPATIBILITY_1_0_0
wxPropertyGridCallback m_callback;
#endif
wxPGPaintCallback m_paintCallback;
wxString m_value;
};
// -----------------------------------------------------------------------
#ifndef SWIG
//
// Tokenizer macros.
// NOTE: I have made two versions - worse ones (performance and consistency
// wise) use wxStringTokenizer and better ones (may have unfound bugs)
// use custom code.
//
#include <wx/tokenzr.h>
// TOKENIZER1 can be done with wxStringTokenizer
#define WX_PG_TOKENIZER1_BEGIN(WXSTRING,DELIMITER) \
wxStringTokenizer tkz(WXSTRING,DELIMITER,wxTOKEN_RET_EMPTY); \
while ( tkz.HasMoreTokens() ) \
{ \
wxString token = tkz.GetNextToken(); \
token.Trim(true); \
token.Trim(false);
#define WX_PG_TOKENIZER1_END() \
}
//
// 2nd version: tokens are surrounded by DELIMITERs (for example, C-style strings).
// TOKENIZER2 must use custom code (a class) for full compliancy
// with " surrounded strings with \" inside.
//
// class implementation is in propgrid.cpp
//
class WXDLLIMPEXP_PG wxPGStringTokenizer
{
public:
wxPGStringTokenizer( const wxString& str, wxChar delimeter );
~wxPGStringTokenizer();
bool HasMoreTokens(); // not const so we can do some stuff in it
wxString GetNextToken();
protected:
#ifndef SWIG
const wxString* m_str;
wxString::const_iterator m_curPos;
wxString m_readyToken;
wxUniChar m_delimeter;
#endif
};
#define WX_PG_TOKENIZER2_BEGIN(WXSTRING,DELIMITER) \
wxPGStringTokenizer tkz(WXSTRING,DELIMITER); \
while ( tkz.HasMoreTokens() ) \
{ \
wxString token = tkz.GetNextToken();
#define WX_PG_TOKENIZER2_END() \
}
#endif
// -----------------------------------------------------------------------
#endif // !DOXYGEN
#endif // _WX_PROPGRID_PROPDEV_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -