diff --git a/docs/changes.txt b/docs/changes.txt index eaa1f2a749..04c318080a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -47,6 +47,7 @@ wxMSW: - Fix handling of selected images in wxBitmapButton (Artur Wieczorek). - Fix loading of bitmap with non-pre-multiplied alpha (Artur Wieczorek). - Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek). +- Fix stretchable spacers in vertical toolbars (Artur Wieczorek). wxOSX/Cocoa: diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 959672519b..9a94aed819 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1254,19 +1254,34 @@ bool wxToolBar::Realize() InvalidateBestSize(); UpdateSize(); + if ( IsVertical() ) + { + // For vertical toolbar heights of buttons are incorrect + // unless TB_AUTOSIZE in invoked. + // We need to recalculate fixed elements size again. + m_totalFixedSize = 0; + toolIndex = 0; + for ( node = m_tools.GetFirst(); node; node = node->GetNext(), toolIndex++ ) + { + wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); + if ( !tool->IsStretchableSpace() ) + { + const RECT r = wxGetTBItemRect(GetHwnd(), toolIndex); + if ( !IsVertical() ) + m_totalFixedSize += r.right - r.left; + else if ( !tool->IsControl() ) + m_totalFixedSize += r.bottom - r.top; + } + } + // Enforce invoking UpdateStretchableSpacersSize() with correct value of fixed elements size. + UpdateSize(); + } + return true; } void wxToolBar::UpdateStretchableSpacersSize() { -#ifdef TB_SETBUTTONINFO - // we can't resize the spacers if TB_SETBUTTONINFO is not supported (we - // could try to do it with multiple separators as for the controls but this - // is too painful and it just doesn't seem to be worth doing for the - // ancient systems) - if ( wxApp::GetComCtl32Version() < 471 ) - return; - // check if we have any stretchable spacers in the first place unsigned numSpaces = 0; wxToolBarToolsList::compatibility_iterator node; @@ -1314,23 +1329,38 @@ void wxToolBar::UpdateStretchableSpacersSize() const RECT rcOld = wxGetTBItemRect(GetHwnd(), toolIndex); - WinStruct tbbi; - tbbi.dwMask = TBIF_SIZE; - tbbi.cx = --numSpaces ? sizeSpacer : sizeLastSpacer; + const int oldSize = IsVertical()? (rcOld.bottom - rcOld.top): (rcOld.right - rcOld.left); + const int newSize = --numSpaces ? sizeSpacer : sizeLastSpacer; + if ( newSize != oldSize) + { + if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, toolIndex, 0) ) + { + wxLogLastError(wxT("TB_DELETEBUTTON (separator)")); + } + else + { + TBBUTTON button; + wxZeroMemory(button); - if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO, - tool->GetId(), (LPARAM)&tbbi) ) - { - wxLogLastError(wxT("TB_SETBUTTONINFO")); - } - else - { - // we successfully resized this one, move all the controls after it - // by the corresponding amount (may be positive or negative) - offset += tbbi.cx - (rcOld.right - rcOld.left); + button.idCommand = tool->GetId(); + button.iBitmap = newSize; // set separator width/height + button.fsState = TBSTATE_ENABLED; + button.fsStyle = TBSTYLE_SEP; + if ( IsVertical() ) + button.fsState |= TBSTATE_WRAP; + if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON, toolIndex, (LPARAM)&button) ) + { + wxLogLastError(wxT("TB_INSERTBUTTON (separator)")); + } + else + { + // We successfully replaced this seprator, move all the controls after it + // by the corresponding amount (may be positive or negative) + offset += newSize - oldSize; + } + } } } -#endif // TB_SETBUTTONINFO } // ---------------------------------------------------------------------------- @@ -1843,6 +1873,11 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) rcItem.bottom = rectTotal.height; } + // Apparently, regions of height < 3 are not taken into account + // in clipping so we need to extend them for this purpose. + if ( rcItem.bottom - rcItem.top > 0 && rcItem.bottom - rcItem.top < 3 ) + rcItem.bottom = rcItem.top + 3; + rgnDummySeps.Union(wxRectFromRECT(rcItem)); } }