From: Vadim Zeitlin Date: Sun, 4 Mar 2012 00:29:44 +0000 (+0000) Subject: Fix stretchable spaces in wxToolBar after tool removal in wxMSW. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/76c67131022c84eb8c424adea124620da6b0d03e Fix stretchable spaces in wxToolBar after tool removal in wxMSW. The stretchable spaces need to be manually updated after removing a tool from the toolbar. Closes #13577. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70798 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index b6ab33c597..baf5e43add 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -503,7 +503,8 @@ MSW: - Fix coordinates and Z-position for joystick events (Markus Juergens). - Fix size of the font returned by wxTextCtrl::GetStyle() (Igor Korot). - Add wxActiveXContainer::QueryClientSiteInterface and implement it in - wxWebViewIE to improve the default behaviour (Allonii) + wxWebViewIE to improve the default behaviour (Allonii). +- Update stretchable spaces in wxToolBar after tool removal (Catalin Raceanu). OSX: diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 6ad75a3cd1..4866b30c54 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -568,14 +568,18 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) // get the size of the button we're going to delete const RECT r = wxGetTBItemRect(GetHwnd(), pos); - int width = r.right - r.left; + int delta = IsVertical() ? r.bottom - r.top : r.right - r.left; if ( tool->IsControl() ) { nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount(); - width *= nButtonsToDelete; + + if ( !IsVertical() ) + delta *= nButtonsToDelete; } + m_totalFixedSize -= delta; + // do delete all buttons m_nButtons -= nButtonsToDelete; while ( nButtonsToDelete-- > 0 ) @@ -588,14 +592,45 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) } } - // and finally reposition all the controls after this button (the toolbar - // takes care of all normal items) - for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) + // and finally rearrange the tools + + // search for any stretch spacers before the removed tool + bool hasPrecedingStrechables = false; + for ( wxToolBarToolsList::compatibility_iterator nodeStch = m_tools.GetFirst(); + nodeStch != node; nodeStch = nodeStch->GetNext() ) { - wxToolBarTool *tool2 = (wxToolBarTool*)node->GetData(); - if ( tool2->IsControl() ) + if ( ((wxToolBarTool*)nodeStch->GetData())->IsStretchable() ) + { + hasPrecedingStrechables = true; + break; + } + } + + if ( hasPrecedingStrechables ) + { + // if the removed tool is preceded by stretch spacers + // just redistribute the space + UpdateStretchableSpacersSize(); + } + else + { + // reposition all the controls after this button but before any + // stretch spacer (the toolbar takes care of all normal items) + for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) { - tool2->MoveBy(-width); + wxToolBarTool *tool2 = (wxToolBarTool*)node->GetData(); + + if ( tool2->IsControl() ) + { + tool2->MoveBy(-delta); + } + + // if a stretch spacer is found just redistribute the available space + else if ( tool2->IsStretchable() ) + { + UpdateStretchableSpacersSize(); + break; + } } }