From: Vadim Zeitlin Date: Thu, 4 Apr 2013 00:11:00 +0000 (+0000) Subject: Fix wxTextEntryDialog::GetValue() when using SetTextValidator(). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/42fe16e58be724a33c50fcf3911a7ae0fb753cb9?hp=45c363c5eb600988ada161e5c5ee211d8876b713 Fix wxTextEntryDialog::GetValue() when using SetTextValidator(). Associating a validator with the text control in wxTextEntryDialog resulted in GetValue() always returning an empty string which was completely unexpected. Fix this by setting the value string manually to avoid interfering with any possibly used validators. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73774 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/textdlgg.h b/include/wx/generic/textdlgg.h index 4d37d24251..2b78b8d9d7 100644 --- a/include/wx/generic/textdlgg.h +++ b/include/wx/generic/textdlgg.h @@ -69,8 +69,10 @@ public: #endif void SetTextValidator( wxTextValidatorStyle style = wxFILTER_NONE ); wxTextValidator* GetTextValidator() { return (wxTextValidator*)m_textctrl->GetValidator(); } -#endif - // wxUSE_VALIDATORS +#endif // wxUSE_VALIDATORS + + virtual bool TransferDataToWindow(); + virtual bool TransferDataFromWindow(); // implementation only void OnOK(wxCommandEvent& event); diff --git a/src/generic/textdlgg.cpp b/src/generic/textdlgg.cpp index b00d192f7b..7d52947e51 100644 --- a/src/generic/textdlgg.cpp +++ b/src/generic/textdlgg.cpp @@ -105,11 +105,6 @@ bool wxTextEntryDialog::Create(wxWindow *parent, Expand(). TripleBorder(wxLEFT | wxRIGHT)); -#if wxUSE_VALIDATORS - wxTextValidator validator( wxFILTER_NONE, &m_value ); - m_textctrl->SetValidator( validator ); -#endif // wxUSE_VALIDATORS - // 3) buttons if any wxSizer *buttonSizer = CreateSeparatedButtonSizer(style & (wxOK | wxCANCEL)); if ( buttonSizer ) @@ -134,19 +129,26 @@ bool wxTextEntryDialog::Create(wxWindow *parent, return true; } +bool wxTextEntryDialog::TransferDataToWindow() +{ + m_textctrl->SetValue(m_value); + + return wxDialog::TransferDataToWindow(); +} + +bool wxTextEntryDialog::TransferDataFromWindow() +{ + m_value = m_textctrl->GetValue(); + + return wxDialog::TransferDataFromWindow(); +} + void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) { -#if wxUSE_VALIDATORS - if( Validate() && TransferDataFromWindow() ) + if ( Validate() && TransferDataFromWindow() ) { EndModal( wxID_OK ); } -#else - m_value = m_textctrl->GetValue(); - - EndModal(wxID_OK); -#endif - // wxUSE_VALIDATORS } void wxTextEntryDialog::SetValue(const wxString& val) @@ -167,8 +169,7 @@ void wxTextEntryDialog::SetTextValidator( long style ) void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style ) { - wxTextValidator validator( style, &m_value ); - m_textctrl->SetValidator( validator ); + SetTextValidator(wxTextValidator(style)); } void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator ) @@ -176,8 +177,7 @@ void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator ) m_textctrl->SetValidator( validator ); } -#endif - // wxUSE_VALIDATORS +#endif // wxUSE_VALIDATORS // ---------------------------------------------------------------------------- // wxPasswordEntryDialog