From 9b99c1e36a5481f2c24bee87414c68269baae4c7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Dec 2006 13:38:25 +0000 Subject: [PATCH] changing ES_LEFT/CENTER/RIGHT styles only works for plain (not rich) controls and only under XP, recreate the control in SetWindowStyleFlag() if it's a richedit one or if the system is earlier than XP git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44021 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/textctrl.h | 9 +++++ src/msw/textctrl.cpp | 69 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index ec1a9e0b4f..8cfbb0306e 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -207,6 +207,15 @@ protected: // common part of all ctors void Init(); + // creates the control of appropriate class (plain or rich edit) with the + // styles corresponding to m_windowStyle + // + // this is used by ctor/Create() and when we need to recreate the control + // later + bool MSWCreateText(const wxString& value, + const wxPoint& pos, + const wxSize& size); + virtual void DoSetValue(const wxString &value, int flags = 0); // return true if this control has a user-set limit on amount of text (i.e. diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 01006a404a..02f25eabc3 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -291,7 +291,8 @@ wxTextCtrl::~wxTextCtrl() delete m_privateContextMenu; } -bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, +bool wxTextCtrl::Create(wxWindow *parent, + wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, @@ -308,6 +309,16 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; + if ( !MSWCreateText(value, pos, size) ) + return false; + + return true; +} + +bool wxTextCtrl::MSWCreateText(const wxString& value, + const wxPoint& pos, + const wxSize& size) +{ // translate wxWin style flags to MSW ones WXDWORD msStyle = MSWGetCreateWindowFlags(); @@ -316,7 +327,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, #if defined(__POCKETPC__) || defined(__SMARTPHONE__) // A control that capitalizes the first letter - if (style & wxTE_CAPITALIZE) + if ( HasFlag(wxTE_CAPITALIZE) ) windowClass = wxT("CAPEDIT"); #endif @@ -597,6 +608,60 @@ WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const void wxTextCtrl::SetWindowStyleFlag(long style) { + // changing the alignment of the control dynamically only works under XP + // (but not older Windows version) and only for plain EDIT controls (not + // RICH ones) and we have to recreate the control to make it always work + if ( IsRich() || wxGetWinVersion() < wxWinVersion_XP ) + { + const long alignMask = wxTE_LEFT | wxTE_CENTRE | wxTE_RIGHT; + if ( (style & alignMask) != (GetWindowStyle() & alignMask) ) + { + const wxString value = GetValue(); + const wxPoint pos = GetPosition(); + const wxSize size = GetSize(); + + // delete the old window + HWND hwnd = GetHwnd(); + DissociateHandle(); + ::DestroyWindow(hwnd); + + // create the new one with the updated flags + m_windowStyle = style; + MSWCreateText(value, pos, size); + + // and make sure it has the same attributes as before + if ( m_hasFont ) + { + // calling SetFont(m_font) would do nothing as the code would + // notice that the font didn't change, so force it to believe + // that it did + wxFont font = m_font; + m_font = wxNullFont; + SetFont(font); + } + + if ( m_hasFgCol ) + { + wxColour colFg = m_foregroundColour; + m_foregroundColour = wxNullColour; + SetForegroundColour(colFg); + } + + if ( m_hasBgCol ) + { + wxColour colBg = m_backgroundColour; + m_backgroundColour = wxNullColour; + SetBackgroundColour(colBg); + } + + // note that text styles are lost but this is probably not a big + // problem: if you use styles, you probably don't use nor change + // alignment flags anyhow + + return; + } + } + #if wxUSE_RICHEDIT // we have to deal with some styles separately because they can't be // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed -- 2.45.2