From 85666cd22f0a40861f13208c04e7d4a6a33b9de7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Feb 2019 15:10:27 +0100 Subject: [PATCH] Demonstrate vetoing wxEVT_SPIN_XXX events in widgets sample Show that these events can be vetoed, which prevents the control value from changing, and also that veto doesn't apply if the event handler skips the event. See https://github.com/wxWidgets/wxWidgets/pull/1232 --- samples/widgets/spinbtn.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp index 067a3af999..2d371e8103 100644 --- a/samples/widgets/spinbtn.cpp +++ b/samples/widgets/spinbtn.cpp @@ -557,12 +557,31 @@ void SpinBtnWidgetsPage::OnSpinBtn(wxSpinEvent& event) void SpinBtnWidgetsPage::OnSpinBtnUp(wxSpinEvent& event) { + // Demonstrate that these events can be vetoed to prevent the control value + // from changing. + if ( event.GetInt() == 11 ) + { + wxLogMessage("Spin button prevented from going up to 11 (still %d)", + m_spinbtn->GetValue()); + event.Veto(); + return; + } + wxLogMessage( "Spin button value incremented, will be %d (was %d)", event.GetInt(), m_spinbtn->GetValue() ); } void SpinBtnWidgetsPage::OnSpinBtnDown(wxSpinEvent& event) { + // Also demonstrate that vetoing the event but then skipping the handler + // doesn't actually apply the veto. + if ( event.GetInt() == 0 ) + { + wxLogMessage("Spin button change not effectively vetoed, will become 0"); + event.Veto(); + event.Skip(); + } + wxLogMessage( "Spin button value decremented, will be %d (was %d)", event.GetInt(), m_spinbtn->GetValue() ); }