+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;
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
+ {
+ wxToolBarTool * const tool = (wxToolBarTool*)node->GetData();
+ if ( tool->IsStretchableSpace() )
+ numSpaces++;
+ }
+
+ if ( !numSpaces )
+ return;
+
+ // we do, adjust their size: either distribute the extra size among them or
+ // reduce their size if there is not enough place for all tools
+ const int totalSize = IsVertical() ? GetClientSize().y : GetClientSize().x;
+ const int extraSize = totalSize - m_totalFixedSize;
+ const int sizeSpacer = extraSize > 0 ? extraSize / numSpaces : 1;
+
+ // the last spacer should consume all remaining space if we have too much
+ // of it (which can be greater than sizeSpacer because of the rounding)
+ const int sizeLastSpacer = extraSize > 0
+ ? extraSize - (numSpaces - 1)*sizeSpacer
+ : 1;
+
+ // cumulated offset by which we need to move all the following controls to
+ // the right: while the toolbar takes care of the normal items, we must
+ // move the controls manually ourselves to ensure they remain at the
+ // correct place
+ int offset = 0;
+ int toolIndex = 0;
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext(), toolIndex++ )
+ {
+ wxToolBarTool * const tool = (wxToolBarTool*)node->GetData();
+
+ if ( tool->IsControl() && offset )
+ {
+ tool->MoveBy(offset);
+
+ continue;
+ }
+
+ if ( !tool->IsStretchableSpace() )
+ continue;
+
+ const RECT rcOld = wxGetTBItemRect(GetHwnd(), toolIndex);
+
+ WinStruct<TBBUTTONINFO> tbbi;
+ tbbi.dwMask = TBIF_SIZE;
+ tbbi.cx = --numSpaces ? sizeSpacer : sizeLastSpacer;
+
+ 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);
+ }
+ }
+#endif // TB_SETBUTTONINFO
+}
+