diff --git a/docs/changes.txt b/docs/changes.txt index f8e072900a..b9ae88a031 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -73,6 +73,11 @@ Changes in behaviour not resulting in compilation errors - wxDC::DrawCheckMark() draws the same shape under all platforms now, use the new wxRendererNative::DrawCheckMark() to draw MSW-specific themed check mark. +- wxTE_PROCESS_ENTER must be used to receive wxEVT_TEXT_ENTER events from even + multiline wxTextCtrl, conforming to the documentation, but contrary to the + previous behaviour in wxMSW, when these events were always generated in this + case. Please add wxTE_PROCESS_ENTER style if you relied on the old behaviour. + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 82c346a85b..6ee2ff9c0b 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2075,14 +2075,18 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) switch ( event.GetKeyCode() ) { case WXK_RETURN: + // Single line controls only get this key code if they have + // wxTE_PROCESS_ENTER style, but multiline ones always get it + // because they need it for themselves. However we shouldn't + // generate wxEVT_TEXT_ENTER for the controls without this style, + // so test for it explicitly. + if ( HasFlag(wxTE_PROCESS_ENTER) ) { wxCommandEvent evt(wxEVT_TEXT_ENTER, m_windowId); InitCommandEvent(evt); evt.SetString(GetValue()); if ( HandleWindowEvent(evt) ) - if ( !HasFlag(wxTE_MULTILINE) ) - return; - //else: multiline controls need Enter for themselves + return; } break; diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 74726bd63e..2d25ebd674 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -1274,7 +1274,8 @@ TEST_CASE("wxTextCtrl::ProcessEnter", "[wxTextCtrl][enter]") class TextCtrlCreator : public TextLikeControlCreator { public: - explicit TextCtrlCreator() + explicit TextCtrlCreator(int styleToAdd = 0) + : m_styleToAdd(styleToAdd) { } @@ -1282,8 +1283,16 @@ TEST_CASE("wxTextCtrl::ProcessEnter", "[wxTextCtrl][enter]") { return new wxTextCtrl(parent, wxID_ANY, wxString(), wxDefaultPosition, wxDefaultSize, - style); + style | m_styleToAdd); } + + virtual TextLikeControlCreator* CloneAsMultiLine() const wxOVERRIDE + { + return new TextCtrlCreator(wxTE_MULTILINE); + } + + private: + int m_styleToAdd; }; TestProcessEnter(TextCtrlCreator()); diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index 4d1178a555..ab65a7c622 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -21,6 +21,8 @@ #include "textentrytest.h" #include "testableframe.h" + +#include "wx/scopedptr.h" #include "wx/uiaction.h" void TextEntryTestCase::SetValue() @@ -434,6 +436,23 @@ private: } } + void OnText(wxCommandEvent& WXUNUSED(e)) + { + // This should only happen for the multiline text controls. + switch ( m_processEnter ) + { + case ProcessEnter_No: + case ProcessEnter_ButSkip: + // We consider that the text succeeded. + EndModal(wxID_OK); + break; + + case ProcessEnter_WithoutSkipping: + FAIL("Shouldn't be getting wxEVT_TEXT if handled"); + break; + } + } + void OnTimeOut(wxTimerEvent&) { EndModal(wxID_CANCEL); @@ -459,6 +478,7 @@ private: // style would fail with an assertion failure, due to wx helpfully complaining // about it. wxBEGIN_EVENT_TABLE(TestDialog, wxDialog) + EVT_TEXT(wxID_ANY, TestDialog::OnText) EVT_TEXT_ENTER(wxID_ANY, TestDialog::OnTextEnter) wxEND_EVENT_TABLE() @@ -492,6 +512,42 @@ void TestProcessEnter(const TextLikeControlCreator& controlCreator) REQUIRE( dlgProcessEnter.ShowModal() == wxID_APPLY ); CHECK( dlgProcessEnter.GotEnter() ); } + + SECTION("Without wxTE_PROCESS_ENTER but with wxTE_MULTILINE") + { + wxScopedPtr + multiLineCreator(controlCreator.CloneAsMultiLine()); + if ( !multiLineCreator ) + return; + + TestDialog dlg(*multiLineCreator, ProcessEnter_No); + REQUIRE( dlg.ShowModal() == wxID_OK ); + CHECK( !dlg.GotEnter() ); + } + + SECTION("With wxTE_PROCESS_ENTER and wxTE_MULTILINE but skipping") + { + wxScopedPtr + multiLineCreator(controlCreator.CloneAsMultiLine()); + if ( !multiLineCreator ) + return; + + TestDialog dlg(*multiLineCreator, ProcessEnter_ButSkip); + REQUIRE( dlg.ShowModal() == wxID_OK ); + CHECK( dlg.GotEnter() ); + } + + SECTION("With wxTE_PROCESS_ENTER and wxTE_MULTILINE without skipping") + { + wxScopedPtr + multiLineCreator(controlCreator.CloneAsMultiLine()); + if ( !multiLineCreator ) + return; + + TestDialog dlg(*multiLineCreator, ProcessEnter_WithoutSkipping); + REQUIRE( dlg.ShowModal() == wxID_APPLY ); + CHECK( dlg.GotEnter() ); + } } #else // !wxUSE_UIACTIONSIMULATOR diff --git a/tests/controls/textentrytest.h b/tests/controls/textentrytest.h index 5545d00aed..c5b2c31592 100644 --- a/tests/controls/textentrytest.h +++ b/tests/controls/textentrytest.h @@ -85,6 +85,11 @@ public: // Create the control of the right type using the given parent and style. virtual wxControl* Create(wxWindow* parent, int style) const = 0; + // Return another creator similar to this one, but creating multiline + // version of the control. If the returned pointer is non-null, it must be + // deleted by the caller. + virtual TextLikeControlCreator* CloneAsMultiLine() const { return NULL; } + // Give it a virtual dtor to avoid warnings even though this class is not // supposed to be used polymorphically. virtual ~TextLikeControlCreator() {}