From c27181d1a10a2bd6b87f998ec65f7d4380d52b3c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 15 Oct 2009 14:44:22 +0000 Subject: [PATCH] Replace wxValidator::SetBellOnError() with SuppressBellOnError(). SetBellOnError() erroneously inversed the value of its parameter. Fixing it to behave correctly could silently break the existing code which might work around this bug already because it always behaved like this (ever since it was added 10.5 years ago). So instead simply deprecate this function and add a new SuppressBellOnError() one which behaves as expected. Closes #11318. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62414 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 +++ include/wx/validate.h | 19 ++++++++++++++++--- interface/wx/validate.h | 8 +++++++- samples/validate/validate.cpp | 4 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7128686cf0..d79c1041c9 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -343,6 +343,9 @@ Deprecated methods and their replacements - wxFont::SetNoAntiAliasing() was deprecated, it never really worked in most ports and was always marked as "experimental" API. It will be replaced with wxDC-level anti-aliasing control in the future. +- wxValidator::SetBellOnError() incorrectly interpreted its argument (it + disabled the bell when it was true) and was replaced by SuppressBellOnError() + with more expected semantics. Major new features in this release diff --git a/include/wx/validate.h b/include/wx/validate.h index 3cd0fdc435..f6832d16d1 100644 --- a/include/wx/validate.h +++ b/include/wx/validate.h @@ -62,10 +62,23 @@ public: wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; } void SetWindow(wxWindowBase *win) { m_validatorWindow = win; } - // validators beep by default if invalid key is pressed, these functions - // allow to change it + // validators beep by default if invalid key is pressed, this function + // allows to change this + static void SuppressBellOnError(bool suppress = true) + { ms_isSilent = suppress; } + + // test if beep is currently disabled static bool IsSilent() { return ms_isSilent; } - static void SetBellOnError(bool doIt = true) { ms_isSilent = doIt; } + + // this function is deprecated because it handled its parameter + // unnaturally: it disabled the bell when it was true, not false as could + // be expected; use SuppressBellOnError() instead +#if WXWIN_COMPATIBILITY_2_8 + wxDEPRECATED_INLINE( + static void SetBellOnError(bool doIt = true), + ms_isSilent = doIt; + ) +#endif protected: wxWindowBase *m_validatorWindow; diff --git a/interface/wx/validate.h b/interface/wx/validate.h index bb2077bcaa..0121382602 100644 --- a/interface/wx/validate.h +++ b/interface/wx/validate.h @@ -74,8 +74,14 @@ public: /** This functions switches on or turns off the error sound produced by the validators if an invalid key is pressed. + + @since 2.9.1 + + @param suppress + If @true, error sound is not played when a validator detects an + error. If @false, error sound is enabled. */ - static void SetBellOnError(bool doIt = true); + static void SuppressBellOnError(bool suppress = true); /** Associates a window with the validator. diff --git a/samples/validate/validate.cpp b/samples/validate/validate.cpp index 4840a7d6a3..dc03e879b7 100644 --- a/samples/validate/validate.cpp +++ b/samples/validate/validate.cpp @@ -173,7 +173,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString&title, int x, int y, int w, int // All validators share a common (static) flag that controls // whether they beep on error. Here we turn it off: - wxValidator::SetBellOnError(m_silent); + wxValidator::SuppressBellOnError(m_silent); file_menu->Check(VALIDATE_TOGGLE_BELL, !wxValidator::IsSilent()); #if wxUSE_STATUSBAR @@ -221,7 +221,7 @@ void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToggleBell(wxCommandEvent& event) { m_silent = !m_silent; - wxValidator::SetBellOnError(m_silent); + wxValidator::SuppressBellOnError(m_silent); event.Skip(); } -- 2.45.2