Make stretchable spacers work in vertical toolbars too in wxMSW.

Replace the old implementation of stretchable spacers based on changing the
size of the separators used as spacers as the toolbar size itself changed with
a new one, simply replacing the old separator with the new one of the correct
size, as it also works for the vertical toolbars, unlike the old approach.

Closes #13673.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76092 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-03-07 01:19:13 +00:00
parent f2fbc84dcb
commit 74f21995ca
2 changed files with 58 additions and 22 deletions

View File

@ -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:

View File

@ -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<TBBUTTONINFO> 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));
}
}