diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 7a804e2617..21f5a79c76 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -241,6 +241,8 @@ protected: virtual wxSize DoGetBestSize() const wxOVERRIDE; virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const wxOVERRIDE; + virtual void DoMoveWindow(int x, int y, int width, int height) wxOVERRIDE; + #if wxUSE_RICHEDIT virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE; diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 6991eb79bb..7156658d38 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2639,6 +2639,30 @@ wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const return wxSize(wText, hText); } +void wxTextCtrl::DoMoveWindow(int x, int y, int width, int height) +{ + // We reset the text of single line controls each time their width changes + // because they don't adjust their horizontal offset on their own and there + // doesn't seem to be any way to convince them to do it other than by just + // setting the text again, see #18268. + const bool resetText = IsSingleLine() && !IsShownOnScreen(); + int oldWidth = -1; + if ( resetText ) + { + oldWidth = GetSize().x; + } + + wxTextCtrlBase::DoMoveWindow(x, y, width, height); + + if ( resetText && GetSize().x != oldWidth ) + { + // We need to use DoWriteText() to avoid our own optimization in + // ChangeValue() which does nothing when the text doesn't really + // change. + DoWriteText(DoGetValue(), 0 /* no flags for no events */); + } +} + // ---------------------------------------------------------------------------- // standard handlers for standard edit menu events // ----------------------------------------------------------------------------