X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9e565667d0f29605c948ad6e742310798e3b2d0d..d9106ec5b679d5c9a5eb61b9633e5f3b1437b6a8:/src/msw/spinctrl.cpp diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index ea503b4c41..4610eef008 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin // Modified by: // Created: 22.07.99 -// RCS-ID: $Id$ // Copyright: (c) 1999-2005 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -179,7 +178,7 @@ bool wxSpinCtrl::ProcessTextCommand(WXWORD cmd, WXWORD WXUNUSED(id)) { if ( (cmd == EN_CHANGE) && (!m_blockEvent )) { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); + wxCommandEvent event(wxEVT_TEXT, GetId()); event.SetEventObject(this); wxString val = wxGetWindowText(m_hwndBuddy); event.SetString(val); @@ -197,7 +196,7 @@ void wxSpinCtrl::OnChar(wxKeyEvent& event) { case WXK_RETURN: { - wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); InitCommandEvent(event); wxString val = wxGetWindowText(m_hwndBuddy); event.SetString(val); @@ -321,7 +320,9 @@ bool wxSpinCtrl::Create(wxWindow *parent, sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; if ( sizeText.x <= 0 ) { - wxLogDebug(wxT("not enough space for wxSpinCtrl!")); + wxLogDebug(wxS("wxSpinCtrl \"%s\": initial width %d is too small, ") + wxS("at least %d pixels needed."), + name, size.x, sizeBtn.x + MARGIN_BETWEEN + 1); } wxPoint posBtn(pos); @@ -399,12 +400,11 @@ bool wxSpinCtrl::Create(wxWindow *parent, if ( value.ToLong(&initialFromText) ) initial = initialFromText; - SetValue(initial); - - m_oldValue = initial; - - // Set the range in the native control + // Set the range in the native control: notice that we must do it before + // calling SetValue() to use the correct validity checks for the initial + // value. SetRange(min, max); + SetValue(initial); // Also set the text part of the control if it was specified independently // but don't generate an event for this, it would be unexpected. @@ -670,7 +670,7 @@ void wxSpinCtrl::DoSetToolTip(wxToolTip *tip) void wxSpinCtrl::SendSpinUpdate(int value) { - wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, GetId()); + wxCommandEvent event(wxEVT_SPINCTRL, GetId()); event.SetEventObject(this); event.SetInt(value); @@ -717,42 +717,54 @@ bool wxSpinCtrl::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *re // ---------------------------------------------------------------------------- wxSize wxSpinCtrl::DoGetBestSize() const +{ + return DoGetSizeFromTextSize(DEFAULT_ITEM_WIDTH); +} + +wxSize wxSpinCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const { wxSize sizeBtn = wxSpinButton::DoGetBestSize(); - sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN; int y; wxGetCharSize(GetHWND(), NULL, &y, GetFont()); - y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(y); - // JACS: we should always use the height calculated // from above, because otherwise we'll get a spin control // that's too big. So never use the height calculated // from wxSpinButton::DoGetBestSize(). - // if ( sizeBtn.y < y ) - { - // make the text tall enough - sizeBtn.y = y; - } + wxSize tsize(xlen + sizeBtn.x + MARGIN_BETWEEN + 3*y/10 + 10, + EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); + + // Check if the user requested a non-standard height. + if ( ylen > 0 ) + tsize.IncBy(0, ylen - y); - return sizeBtn; + return tsize; } void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) { int widthBtn = wxSpinButton::DoGetBestSize().x; int widthText = width - widthBtn - MARGIN_BETWEEN; - if ( widthText <= 0 ) + if ( widthText < 0 ) { - wxLogDebug(wxT("not enough space for wxSpinCtrl!")); + // This can happen during the initial window layout when it's total + // size is too small to accommodate all the controls and usually is not + // a problem because the window will be relaid out with enough space + // later. Of course, if it isn't and this is our final size, then we + // have a real problem but as we don't know if this is going to be the + // case or not, just hope for the best -- we used to give a debug + // warning here and this was annoying as it could result in dozens of + // perfectly harmless warnings. + widthText = 0; } // 1) The buddy window DoMoveSibling(m_hwndBuddy, x, y, widthText, height); // 2) The button window - x += widthText + MARGIN_BETWEEN; + if ( widthText > 0 ) + x += widthText + MARGIN_BETWEEN; wxSpinButton::DoMoveWindow(x, y, widthBtn, height); }