X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/242ec2f7e9e964025400a72581dfa9762850e98b..53ba4eb40a7107a83393597c41b146971233179d:/src/msw/spinctrl.cpp diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 05965d0c3d..bb867d36a8 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -207,7 +207,7 @@ wxSpinCtrl *wxSpinCtrl::GetSpinForTextCtrl(WXHWND hwndBuddy) // sanity check wxASSERT_MSG( spin->m_hwndBuddy == hwndBuddy, - _T("wxSpinCtrl has incorrect buddy HWND!") ); + wxT("wxSpinCtrl has incorrect buddy HWND!") ); return spin; } @@ -335,10 +335,11 @@ bool wxSpinCtrl::Create(wxWindow *parent, WXDWORD exStyle = 0; WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; - // this control is used for numeric entry so normally using these flags by - // default shouldn't be a problem, if it is we can always add a style such - // as wxSP_NON_NUMERIC later - msStyle |= ES_RIGHT | ES_NUMBER; + // propagate text alignment style to text ctrl + if ( style & wxALIGN_RIGHT ) + msStyle |= ES_RIGHT; + else if ( style & wxALIGN_CENTER ) + msStyle |= ES_CENTER; // calculate the sizes: the size given is the total size for both controls // and we need to fit them both in the given width (height is the same) @@ -353,7 +354,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; if ( sizeText.x <= 0 ) { - wxLogDebug(_T("not enough space for wxSpinCtrl!")); + wxLogDebug(wxT("not enough space for wxSpinCtrl!")); } wxPoint posBtn(pos); @@ -370,7 +371,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, m_hwndBuddy = (WXHWND)::CreateWindowEx ( exStyle, // sunken border - _T("EDIT"), // window class + wxT("EDIT"), // window class NULL, // no window title msStyle, // style (will be shown later) pos.x, pos.y, // position @@ -475,7 +476,7 @@ void wxSpinCtrl::SetValue(const wxString& text) void wxSpinCtrl::SetValue(int val) { m_blockEvent = true; - + wxSpinButton::SetValue(val); // normally setting the value of the spin button is enough as it updates @@ -487,11 +488,11 @@ void wxSpinCtrl::SetValue(int val) // to leave it like this, while we really want to always show the // current value in the control, so do it manually ::SetWindowText(GetBuddyHwnd(), - wxString::Format(_T("%d"), val).wx_str()); + wxString::Format(wxT("%d"), val).wx_str()); } m_oldValue = GetValue(); - + m_blockEvent = false; } @@ -523,6 +524,28 @@ void wxSpinCtrl::SetSelection(long from, long to) ::SendMessage(GetBuddyHwnd(), EM_SETSEL, (WPARAM)from, (LPARAM)to); } +// ---------------------------------------------------------------------------- +// wxSpinButton methods +// ---------------------------------------------------------------------------- + +void wxSpinCtrl::SetRange(int minVal, int maxVal) +{ + wxSpinButton::SetRange(minVal, maxVal); + + // this control is used for numeric entry so restrict the input to numeric + // keys only -- but only if we don't need to be able to enter "-" in it as + // otherwise this would become impossible + const DWORD styleOld = ::GetWindowLong(GetBuddyHwnd(), GWL_STYLE); + DWORD styleNew; + if ( minVal < 0 ) + styleNew = styleOld & ~ES_NUMBER; + else + styleNew = styleOld | ES_NUMBER; + + if ( styleNew != styleOld ) + ::SetWindowLong(GetBuddyHwnd(), GWL_STYLE, styleNew); +} + // ---------------------------------------------------------------------------- // forward some methods to subcontrols // ---------------------------------------------------------------------------- @@ -574,7 +597,9 @@ bool wxSpinCtrl::Reparent(wxWindowBase *newParent) // destroy the old spin button UnsubclassWin(); if ( !::DestroyWindow(GetHwnd()) ) + { wxLogLastError(wxT("DestroyWindow")); + } // create and initialize the new one if ( !wxSpinButton::Create(GetParent(), GetId(), @@ -600,7 +625,7 @@ bool wxSpinCtrl::Enable(bool enable) return false; } - ::EnableWindow(GetBuddyHwnd(), enable); + MSWEnableHWND(GetBuddyHwnd(), enable); return true; } @@ -701,7 +726,7 @@ void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) int widthText = width - widthBtn - MARGIN_BETWEEN; if ( widthText <= 0 ) { - wxLogDebug(_T("not enough space for wxSpinCtrl!")); + wxLogDebug(wxT("not enough space for wxSpinCtrl!")); } // 1) The buddy window