X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d61d8cffa928c7b25cfada5618b987be2ec5e052..6cab632f3251ae1117d24544813f47c6597a3b34:/include/wx/propgrid/props.h diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index 6609bdbb3a..a260605ade 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -6,20 +6,29 @@ // Created: 2007-03-28 // RCS-ID: $Id$ // Copyright: (c) Jaakko Salli -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_PROPGRID_PROPS_H_ #define _WX_PROPGRID_PROPS_H_ +#include "wx/defs.h" + #if wxUSE_PROPGRID // ----------------------------------------------------------------------- -class wxArrayEditorDialog; +class wxPGArrayEditorDialog; #include "wx/propgrid/editors.h" +#include "wx/filename.h" +#include "wx/dialog.h" +#include "wx/textctrl.h" +#include "wx/button.h" +#include "wx/listbox.h" +#include "wx/valtext.h" + // ----------------------------------------------------------------------- // @@ -35,7 +44,7 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR) // // These macros help creating DoGetValidator #define WX_PG_DOGETVALIDATOR_ENTRY() \ - static wxValidator* s_ptr = (wxValidator*) NULL; \ + static wxValidator* s_ptr = NULL; \ if ( s_ptr ) return s_ptr; // Common function exit @@ -46,10 +55,6 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR) // ----------------------------------------------------------------------- -#ifndef SWIG - -#include "wx/textctrl.h" - /** @class wxPGInDialogValidator @ingroup classes Creates and manages a temporary wxTextCtrl for validation purposes. @@ -77,8 +82,6 @@ private: wxTextCtrl* m_textCtrl; }; -#endif // SWIG - // ----------------------------------------------------------------------- // Property classes @@ -106,7 +109,7 @@ public: const wxString& value = wxEmptyString ); virtual ~wxStringProperty(); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -122,10 +125,9 @@ protected: // ----------------------------------------------------------------------- -#ifndef SWIG -/** Constants used with DoValidation() methods. +/** Constants used with NumericValidation<>(). */ -enum +enum wxPGNumericValidationConstants { /** Instead of modifying the value, show an error message. */ @@ -139,10 +141,32 @@ enum */ wxPG_PROPERTY_VALIDATION_WRAP = 2 }; -#endif // ----------------------------------------------------------------------- +#if wxUSE_VALIDATORS + +/** + A more comprehensive numeric validator class. +*/ +class WXDLLIMPEXP_PROPGRID wxNumericPropertyValidator : public wxTextValidator +{ +public: + enum NumericType + { + Signed = 0, + Unsigned, + Float + }; + + wxNumericPropertyValidator( NumericType numericType, int base = 10 ); + virtual ~wxNumericPropertyValidator() { } + virtual bool Validate(wxWindow* parent); +}; + +#endif // wxUSE_VALIDATORS + + /** @class wxIntProperty @ingroup classes Basic property with integer value. @@ -196,7 +220,7 @@ public: wxIntProperty( const wxString& label, const wxString& name, const wxLongLong& value ); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -250,13 +274,14 @@ public: wxUIntProperty( const wxString& label, const wxString& name, const wxULongLong& value ); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); virtual bool ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const; + virtual wxValidator* DoGetValidator () const; virtual bool IntToValue( wxVariant& variant, int number, int argFlags = 0 ) const; @@ -287,7 +312,7 @@ public: double value = 0.0 ); virtual ~wxFloatProperty(); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -302,17 +327,15 @@ public: wxPGValidationInfo* pValidationInfo, int mode = wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); + static wxValidator* GetClassValidator(); + virtual wxValidator* DoGetValidator () const; protected: int m_precision; - virtual wxValidator* DoGetValidator () const; }; // ----------------------------------------------------------------------- -// Exclude class from wxPython bindings -#ifndef SWIG - /** @class wxBoolProperty @ingroup classes Basic property with boolean value. @@ -330,7 +353,7 @@ public: bool value = false ); virtual ~wxBoolProperty(); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -339,13 +362,16 @@ public: virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); }; -#endif // !SWIG - // ----------------------------------------------------------------------- -/** @class wxBaseEnumProperty +// If set, then selection of choices is static and should not be +// changed (i.e. returns NULL in GetPropertyChoices). +#define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1 + +/** @class wxEnumProperty @ingroup classes - Derive dynamic custom properties with choices from this class. + You can derive custom properties with choices from this class. See + wxBaseEnumProperty for remarks. @remarks - Updating private index is important. You can do this either by calling @@ -353,14 +379,49 @@ public: be called (by not implementing it, or by calling super class function in it) -OR- you can just call SetIndex in OnSetValue. */ -class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty : public wxPGProperty +class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty { + WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty) public: - wxBaseEnumProperty( const wxString& label = wxPG_LABEL, - const wxString& name = wxPG_LABEL ); + +#ifndef SWIG + wxEnumProperty( const wxString& label = wxPG_LABEL, + const wxString& name = wxPG_LABEL, + const wxChar* const* labels = NULL, + const long* values = NULL, + int value = 0 ); + wxEnumProperty( const wxString& label, + const wxString& name, + wxPGChoices& choices, + int value = 0 ); + + // Special constructor for caching choices (used by derived class) + wxEnumProperty( const wxString& label, + const wxString& name, + const wxChar* const* labels, + const long* values, + wxPGChoices* choicesCache, + int value = 0 ); + + wxEnumProperty( const wxString& label, + const wxString& name, + const wxArrayString& labels, + const wxArrayInt& values = wxArrayInt(), + int value = 0 ); +#else + wxEnumProperty( const wxString& label = wxPG_LABEL, + const wxString& name = wxPG_LABEL, + const wxArrayString& labels = wxArrayString(), + const wxArrayInt& values = wxArrayInt(), + int value = 0 ); +#endif + + virtual ~wxEnumProperty(); + + size_t GetItemCount() const { return m_choices.GetCount(); } virtual void OnSetValue(); - virtual wxString GetValueAsString( int argFlags ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -379,22 +440,12 @@ public: // This must be overridden to have non-index based value virtual int GetIndexForValue( int value ) const; - // This returns string and value for index - // Returns NULL if beyond last item - // pvalue is never NULL - always set it. - virtual const wxString* GetEntry( size_t index, int* pvalue ) const = 0; - // GetChoiceSelection needs to overridden since m_index is // the true index, and various property classes derived from // this take advantage of it. virtual int GetChoiceSelection() const { return m_index; } - int GetValueForIndex( size_t index ) const - { - int v; - GetEntry( index, &v ); - return v; - } + virtual void OnValidationFailure( wxVariant& pendingValue ); protected: @@ -419,63 +470,6 @@ private: // ----------------------------------------------------------------------- -// If set, then selection of choices is static and should not be -// changed (i.e. returns NULL in GetPropertyChoices). -#define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1 - -/** @class wxEnumProperty - @ingroup classes - You can derive custom properties with choices from this class. See - wxBaseEnumProperty for remarks. -*/ -class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxBaseEnumProperty -{ - WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty) -public: - -#ifndef SWIG - wxEnumProperty( const wxString& label = wxPG_LABEL, - const wxString& name = wxPG_LABEL, - const wxChar** labels = NULL, - const long* values = NULL, - int value = 0 ); - wxEnumProperty( const wxString& label, - const wxString& name, - wxPGChoices& choices, - int value = 0 ); - - // Special constructor for caching choices (used by derived class) - wxEnumProperty( const wxString& label, - const wxString& name, - const wxChar** labels, - const long* values, - wxPGChoices* choicesCache, - int value = 0 ); - - wxEnumProperty( const wxString& label, - const wxString& name, - const wxArrayString& labels, - const wxArrayInt& values = wxArrayInt(), - int value = 0 ); -#else - wxEnumProperty( const wxString& label = wxPG_LABEL, - const wxString& name = wxPG_LABEL, - const wxArrayString& labels = wxArrayString(), - const wxArrayInt& values = wxArrayInt(), - int value = 0 ); -#endif - - virtual ~wxEnumProperty(); - - virtual int GetIndexForValue( int value ) const; - virtual const wxString* GetEntry( size_t index, int* pvalue ) const; - - size_t GetItemCount() const { return m_choices.GetCount(); } - const wxPGChoices& GetChoices() const { return m_choices; } -}; - -// ----------------------------------------------------------------------- - /** @class wxEditEnumProperty @ingroup classes wxEnumProperty with wxString value and writable combo box editor. @@ -491,7 +485,7 @@ public: wxEditEnumProperty( const wxString& label, const wxString& name, - const wxChar** labels, + const wxChar* const* labels, const long* values, const wxString& value ); wxEditEnumProperty( const wxString& label = wxPG_LABEL, @@ -507,7 +501,7 @@ public: // Special constructor for caching choices (used by derived class) wxEditEnumProperty( const wxString& label, const wxString& name, - const wxChar** labels, + const wxChar* const* labels, const long* values, wxPGChoices* choicesCache, const wxString& value ); @@ -537,7 +531,7 @@ public: #ifndef SWIG wxFlagsProperty( const wxString& label, const wxString& name, - const wxChar** labels, + const wxChar* const* labels, const long* values = NULL, long value = 0 ); wxFlagsProperty( const wxString& label, @@ -553,14 +547,15 @@ public: virtual ~wxFlagsProperty (); virtual void OnSetValue(); - virtual wxString GetValueAsString( int argFlags ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int flags ) const; - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, - wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); + virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); // GetChoiceSelection needs to overridden since m_choices is // used and value is integer, but it is not index. @@ -600,8 +595,6 @@ public: // ----------------------------------------------------------------------- -#include "wx/filename.h" - // Indicates first bit useable by derived properties. #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1 @@ -631,7 +624,7 @@ public: virtual ~wxFileProperty (); virtual void OnSetValue(); - virtual wxString GetValueAsString( int argFlags ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -641,12 +634,16 @@ public: static wxValidator* GetClassValidator(); virtual wxValidator* DoGetValidator() const; + /** + Returns filename to file represented by current value. + */ + wxFileName GetFileName() const; + protected: wxString m_wildcard; wxString m_basePath; // If set, then show path relative to it wxString m_initialPath; // If set, start the file dialog here wxString m_dlgTitle; // If set, used as title for file dialog - wxFileName m_filename; // used as primary storage int m_indFilter; // index to the selected filter }; @@ -682,7 +679,7 @@ public: const wxString& value = wxEmptyString ); virtual ~wxLongStringProperty(); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; @@ -704,9 +701,6 @@ protected: // ----------------------------------------------------------------------- -// Exclude class from wxPython bindings -#ifndef SWIG - /** @class wxDirProperty @ingroup classes Like wxLongStringProperty, but the button triggers dir selector instead. @@ -716,9 +710,7 @@ protected: */ class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty { -#ifndef SWIG DECLARE_DYNAMIC_CLASS(wxDirProperty) -#endif public: wxDirProperty( const wxString& name = wxPG_LABEL, const wxString& label = wxPG_LABEL, @@ -734,8 +726,6 @@ protected: wxString m_dlgMessage; }; -#endif // !SWIG - // ----------------------------------------------------------------------- // wxBoolProperty specific flags @@ -754,21 +744,24 @@ class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty { WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty) public: - wxArrayStringProperty( const wxString& label = wxPG_LABEL, const wxString& name = wxPG_LABEL, const wxArrayString& value = wxArrayString() ); virtual ~wxArrayStringProperty(); virtual void OnSetValue(); - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event ); + virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); - virtual void GenerateValueAsString(); + // Implement in derived class for custom array-to-string conversion. + virtual void ConvertArrayToString(const wxArrayString& arr, + wxString* pString, + const wxUniChar& delimiter) const; // 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 @@ -780,13 +773,30 @@ public: wxWindow* primary, const wxChar* cbt ); -#ifndef SWIG - // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick. - virtual wxArrayEditorDialog* CreateEditorDialog(); -#endif + // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick. + virtual wxPGArrayEditorDialog* CreateEditorDialog(); + + enum ConversionFlags + { + Escape = 0x01, + QuoteStrings = 0x02 + }; + + /** + Generates contents for string dst based on the contents of + wxArrayString src. + */ + static void ArrayStringToString( wxString& dst, const wxArrayString& src, + wxUniChar delimiter, int flags ); protected: + // Previously this was to be implemented in derived class for array-to- + // string conversion. Now you should implement ConvertValueToString() + // instead. + virtual void GenerateValueAsString(); + wxString m_display; // Cache for displayed text. + wxUniChar m_delimiter; }; // ----------------------------------------------------------------------- @@ -801,9 +811,6 @@ public: \ const wxString& name = wxPG_LABEL, \ const wxArrayString& value = wxArrayString() ); \ ~PROPNAME(); \ - virtual void GenerateValueAsString(); \ - virtual bool StringToValue( wxVariant& value, \ - const wxString& text, int = 0 ) const; \ virtual bool OnEvent( wxPropertyGrid* propgrid, \ wxWindow* primary, wxEvent& event ); \ virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \ @@ -825,32 +832,9 @@ PROPNAME::PROPNAME( const wxString& label, \ : wxArrayStringProperty(label,name,value) \ { \ PROPNAME::GenerateValueAsString(); \ + m_delimiter = DELIMCHAR; \ } \ PROPNAME::~PROPNAME() { } \ -void PROPNAME::GenerateValueAsString() \ -{ \ - wxChar delimChar = DELIMCHAR; \ - if ( delimChar == wxS('"') ) \ - wxArrayStringProperty::GenerateValueAsString(); \ - else \ - wxPropertyGrid::ArrayStringToString(m_display, \ - m_value.GetArrayString(), \ - 0,DELIMCHAR,0); \ -} \ -bool PROPNAME::StringToValue( wxVariant& variant, \ - const wxString& text, int ) const \ -{ \ - wxChar delimChar = DELIMCHAR; \ - if ( delimChar == wxS('"') ) \ - return wxArrayStringProperty::StringToValue(variant, text, 0); \ - \ - wxArrayString arr; \ - WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \ - arr.Add( token ); \ - WX_PG_TOKENIZER1_END() \ - variant = arr; \ - return true; \ -} \ bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \ wxWindow* primary, wxEvent& event ) \ { \ @@ -870,29 +854,30 @@ WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ DELIMCHAR, \ CUSTBUTTXT) \ wxValidator* PROPNAME::DoGetValidator () const \ -{ return (wxValidator*) NULL; } +{ return NULL; } // ----------------------------------------------------------------------- -// wxArrayEditorDialog +// wxPGArrayEditorDialog // ----------------------------------------------------------------------- -#include "wx/button.h" -#include "wx/dialog.h" -#include "wx/listbox.h" +#if wxUSE_EDITABLELISTBOX + +class WXDLLIMPEXP_FWD_ADV wxEditableListBox; +class WXDLLIMPEXP_FWD_CORE wxListEvent; #define wxAEDIALOG_STYLE \ (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) -class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog : public wxDialog +class WXDLLIMPEXP_PROPGRID wxPGArrayEditorDialog : public wxDialog { public: - wxArrayEditorDialog(); - virtual ~wxArrayEditorDialog() { } + wxPGArrayEditorDialog(); + virtual ~wxPGArrayEditorDialog() { } void Init(); - wxArrayEditorDialog( wxWindow *parent, + wxPGArrayEditorDialog( wxWindow *parent, const wxString& message, const wxString& caption, long style = wxAEDIALOG_STYLE, @@ -906,6 +891,11 @@ public: const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize ); + void EnableCustomNewAction() + { + m_hasCustomNewAction = true; + } + /** Set value modified by dialog. */ virtual void SetDialogValue( const wxVariant& WXUNUSED(value) ) @@ -931,43 +921,36 @@ public: */ virtual wxValidator* GetTextCtrlValidator() const { - return (wxValidator*) NULL; + return NULL; } // Returns true if array was actually modified bool IsModified() const { return m_modified; } - //const wxArrayString& GetStrings() const { return m_array; } + // wxEditableListBox utilities + int GetSelection() const; // 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 OnEndLabelEdit(wxListEvent& 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; + wxEditableListBox* m_elb; - //wxArrayString m_array; + // These are used for focus repair + wxWindow* m_elbSubPanel; + wxWindow* m_lastFocused; - const wxChar* m_custBtText; - //wxArrayStringPropertyClass* m_pCallingClass; + // A new item, edited by user, is pending at this index. + // It will be committed once list ctrl item editing is done. + int m_itemPendingAtIndex; bool m_modified; - - unsigned char m_curFocus; + bool m_hasCustomNewAction; // These must be overridden - must return true on success. virtual wxString ArrayGet( size_t index ) = 0; @@ -976,20 +959,24 @@ protected: 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; + virtual bool OnCustomNewAction(wxString* WXUNUSED(resString)) + { + return false; + } private: -#ifndef SWIG - DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog) + DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog) DECLARE_EVENT_TABLE() -#endif }; +#endif // wxUSE_EDITABLELISTBOX + // ----------------------------------------------------------------------- // wxPGArrayStringEditorDialog // ----------------------------------------------------------------------- class WXDLLIMPEXP_PROPGRID - wxPGArrayStringEditorDialog : public wxArrayEditorDialog + wxPGArrayStringEditorDialog : public wxPGArrayEditorDialog { public: wxPGArrayStringEditorDialog(); @@ -1007,13 +994,17 @@ public: return m_array; } - void SetCustomButton( const wxChar* custBtText, wxArrayStringProperty* pcc ) + void SetCustomButton( const wxString& custBtText, + wxArrayStringProperty* pcc ) { - m_custBtText = custBtText; - m_pCallingClass = pcc; + if ( custBtText.length() ) + { + EnableCustomNewAction(); + m_pCallingClass = pcc; + } } - void OnCustomEditClick(wxCommandEvent& event); + virtual bool OnCustomNewAction(wxString* resString); protected: wxArrayString m_array; @@ -1028,10 +1019,8 @@ protected: virtual void ArraySwap( size_t first, size_t second ); private: -#ifndef SWIG DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog) DECLARE_EVENT_TABLE() -#endif }; // -----------------------------------------------------------------------