From 3a89adc1f01554f2da86f6f357eafb524c45f191 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Tue, 7 Oct 2008 16:56:43 +0000 Subject: [PATCH] Removed wxLongStringProperty derived property creator macros (just subclass and implement OnButtonClick()); Partially fixed wxPGProperty::PrepareValueForDialogEditing() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56147 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/props.h | 37 ----------------------- interface/wx/propgrid/property.h | 34 ++++++++++++++++++++++ samples/propgrid/tests.cpp | 50 -------------------------------- src/propgrid/property.cpp | 2 +- src/propgrid/props.cpp | 6 +++- 5 files changed, 40 insertions(+), 89 deletions(-) diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index 903d831329..edda643d04 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -38,43 +38,6 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR) // ----------------------------------------------------------------------- -#define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences -#define wxPG_ESCAPE 0 // Escape sequences - -#define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \ -DECL NAME : public wxLongStringProperty \ -{ \ - DECLARE_DYNAMIC_CLASS(NAME) \ -public: \ - NAME( const wxString& name = wxPG_LABEL, \ - const wxString& label = wxPG_LABEL, \ - const wxString& value = wxEmptyString); \ - virtual ~NAME(); \ - virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \ - virtual wxValidator* DoGetValidator() const; \ -}; - -#define WX_PG_DECLARE_STRING_PROPERTY(NAME) \ -WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \ - -#define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \ -IMPLEMENT_DYNAMIC_CLASS(NAME,wxLongStringProperty) \ -NAME::NAME( const wxString& name, \ - const wxString& label, \ - const wxString& value ) \ - : wxLongStringProperty(name,label,value) \ -{ \ - m_flags |= FLAGS; \ -} \ -NAME::~NAME() { } - -#define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \ -WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \ -wxValidator* NAME::DoGetValidator () const \ -{ return (wxValidator*) NULL; } - -// ----------------------------------------------------------------------- - #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \ DECL CLASSNAME : public wxSystemColourProperty \ { \ diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index a0639cb8dd..6795ed0a18 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -234,6 +234,40 @@ dialog. Note that in long string values, tabs are represented by "\t" and line break by "\n". + To display custom dialog on button press, you can subclass + wxLongStringProperty and implement OnButtonClick, like this: + + @code + virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value ) + { + // Update property value from editor, if necessary + PrepareValueForDialogEditing(propGrid); + + wxSize dialogSize(...size of your dialog...); + + wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this, + dialogSize) + + // Create dialog dlg at dlgPos. Use value as initial string + // value. + ... + + if ( dlg.ShowModal() == wxID_OK ) + { + value = dlg.GetStringValue); + return true; + } + return false; + } + @endcode + + Also, if you wish not to have line breaks and tabs translated to + escape sequences, then do following in constructor of your subclass: + + @code + m_flags |= wxPG_PROP_NO_ESCAPE; + @endcode + @subsection wxDirProperty Like wxLongStringProperty, but the button triggers dir selector instead. diff --git a/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index f8d146f76a..a237687684 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -98,54 +98,6 @@ WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property, (long*)NULL, mycolprop_colours) - - -// Just testing the macros -WX_PG_DECLARE_STRING_PROPERTY(wxTestStringProperty) -WX_PG_IMPLEMENT_STRING_PROPERTY(wxTestStringProperty,wxPG_NO_ESCAPE) -bool wxTestStringProperty::OnButtonClick( wxPropertyGrid*, - wxString& ) -{ - ::wxMessageBox(wxT("Button Clicked")); - return true; -} - -WX_PG_DECLARE_STRING_PROPERTY(wxTextStringPropertyWithValidator) -WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(wxTextStringPropertyWithValidator, - wxPG_NO_ESCAPE) - -bool wxTextStringPropertyWithValidator::OnButtonClick( wxPropertyGrid* WXUNUSED(propgrid), - wxString& WXUNUSED(value) ) -{ - ::wxMessageBox(wxT("Button Clicked")); - return true; -} - -wxValidator* wxTextStringPropertyWithValidator::DoGetValidator() const -{ -#if wxUSE_VALIDATORS - WX_PG_DOGETVALIDATOR_ENTRY() - wxTextValidator* validator = new - wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST); - wxArrayString oValid; - oValid.Add(wxT("0")); - oValid.Add(wxT("1")); - oValid.Add(wxT("2")); - oValid.Add(wxT("3")); - oValid.Add(wxT("4")); - oValid.Add(wxT("5")); - oValid.Add(wxT("6")); - oValid.Add(wxT("7")); - oValid.Add(wxT("8")); - oValid.Add(wxT("9")); - oValid.Add(wxT("$")); - validator->SetIncludes(oValid); - WX_PG_DOGETVALIDATOR_EXIT(validator) -#else - return NULL; -#endif -} - // ----------------------------------------------------------------------- // @@ -243,8 +195,6 @@ void FormMain::AddTestProperties( wxPropertyGridPage* pg ) pg->SetPropertyHelpString(wxT("CustomColourProperty3"), wxT("This is a MyColourProperty3 from the sample app. ") wxT("It is built by subclassing wxColourProperty.")); - - pg->Append( new wxTextStringPropertyWithValidator(wxT("TestProp1"), wxPG_LABEL) ); } // ----------------------------------------------------------------------- diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 1022055d36..cc14b53a9f 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -1414,7 +1414,7 @@ bool wxPGProperty::HasVisibleChildren() const bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid* propGrid ) { - return propGrid->EditorValidate(); + return propGrid->CommitChangesFromEditor(); } diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index ba0c468b1a..d4e078bd2d 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -1545,8 +1545,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxDirProperty, wxLongStringProperty) wxDirProperty::wxDirProperty( const wxString& name, const wxString& label, const wxString& value ) : wxLongStringProperty(name,label,value) { - m_flags |= wxPG_NO_ESCAPE; + m_flags |= wxPG_PROP_NO_ESCAPE; } + wxDirProperty::~wxDirProperty() { } wxValidator* wxDirProperty::DoGetValidator() const @@ -1556,6 +1557,9 @@ wxValidator* wxDirProperty::DoGetValidator() const bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value ) { + // Update property value from editor, if necessary + PrepareValueForDialogEditing(propGrid); + wxSize dlg_sz(300,400); wxDirDialog dlg( propGrid, -- 2.45.2