sfx2/source/appl/workwin.cxx | 135 ++++++++----------------------------------- 1 file changed, 28 insertions(+), 107 deletions(-)
New commits: commit c5574385303a86b6f65002d6bc4ff074f9e84d49 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Oct 2 19:36:41 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Oct 2 22:06:12 2023 +0200 Deduplicate and simplify some SfxWorkWindow methods Change-Id: Ibd7153454f1efd1d311ac99b9c2529958f4ca3e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157500 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sfx2/source/appl/workwin.cxx b/sfx2/source/appl/workwin.cxx index 60d900ccb026..9a4de102bb88 100644 --- a/sfx2/source/appl/workwin.cxx +++ b/sfx2/source/appl/workwin.cxx @@ -1748,24 +1748,26 @@ void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild, } } +namespace +{ +template <sal_uInt16 SfxChildWin_Impl::*Member> +SfxChildWin_Impl* Get_Impl(const std::vector<std::unique_ptr<SfxChildWin_Impl>>& rChildWins, + sal_uInt16 nId) +{ + for (auto& pChildWin : rChildWins) + if (pChildWin.get()->*Member == nId) + return pChildWin.get(); + return nullptr; +} +auto Get_ById = Get_Impl<&SfxChildWin_Impl::nId>; +auto Get_BySaveId = Get_Impl<&SfxChildWin_Impl::nSaveId>; +} void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, bool bEnabled, SfxVisibilityFlags nMode ) { sal_uInt16 nId = static_cast<sal_uInt16>( lId & 0xFFFF ); - SfxChildWin_Impl *pCW=nullptr; - - if ( !pCW ) - { - // If no Parent or the Parent us still unknown, then search here - sal_uInt16 nCount = aChildWins.size(); - for (sal_uInt16 n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - { - pCW = aChildWins[n].get(); - break; - } - } + SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId); if ( !pCW ) { @@ -1787,16 +1789,9 @@ void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, bool bEnabled, S void SfxWorkWindow::ToggleChildWindow_Impl(sal_uInt16 nId, bool bSetFocus) { - sal_uInt16 nCount = aChildWins.size(); - sal_uInt16 n; - for (n=0; n<nCount; n++) - if (aChildWins[n]->nId == nId) - break; - - if ( n<nCount ) + if (SfxChildWin_Impl* pCW = Get_ById(aChildWins, nId)) { // The Window is already known - SfxChildWin_Impl *pCW = aChildWins[n].get(); SfxChildWindow *pChild = pCW->pWin; bool bCreationAllowed( true ); @@ -1863,12 +1858,7 @@ void SfxWorkWindow::ToggleChildWindow_Impl(sal_uInt16 nId, bool bSetFocus) } #ifdef DBG_UTIL - nCount = aChildWins.size(); - for (n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - break; - - if ( n < nCount ) + if (SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId)) { OSL_FAIL("The ChildWindow is not in context!"); } @@ -1882,37 +1872,15 @@ void SfxWorkWindow::ToggleChildWindow_Impl(sal_uInt16 nId, bool bSetFocus) bool SfxWorkWindow::HasChildWindow_Impl(sal_uInt16 nId) { - sal_uInt16 nCount = aChildWins.size(); - sal_uInt16 n; - for (n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - break; - - if (n<nCount) - { - SfxChildWin_Impl *pCW = aChildWins[n].get(); - SfxChildWindow *pChild = pCW->pWin; - return ( pChild && pCW->bCreate ); - } + if (const SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId)) + return ( pCW->pWin && pCW->bCreate ); return false; } bool SfxWorkWindow::IsFloating( sal_uInt16 nId ) { - SfxChildWin_Impl *pCW=nullptr; - - if ( !pCW ) - { - // If no Parent or the Parent us still unknown, then search here - sal_uInt16 nCount = aChildWins.size(); - for (sal_uInt16 n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - { - pCW = aChildWins[n].get(); - break; - } - } + SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId); if ( !pCW ) { @@ -1936,17 +1904,7 @@ bool SfxWorkWindow::IsFloating( sal_uInt16 nId ) bool SfxWorkWindow::KnowsChildWindow_Impl(sal_uInt16 nId) { - SfxChildWin_Impl *pCW=nullptr; - sal_uInt16 nCount = aChildWins.size(); - sal_uInt16 n; - for (n=0; n<nCount; n++) - { - pCW = aChildWins[n].get(); - if ( pCW->nSaveId == nId) - break; - } - - if (n<nCount) + if (SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId)) { if ( !(pCW->aInfo.nFlags & SfxChildWindowFlags::ALWAYSAVAILABLE) && !IsVisible_Impl( pCW->nVisibility ) ) return false; @@ -1959,21 +1917,7 @@ bool SfxWorkWindow::KnowsChildWindow_Impl(sal_uInt16 nId) void SfxWorkWindow::SetChildWindow_Impl(sal_uInt16 nId, bool bOn, bool bSetFocus) { - SfxChildWin_Impl *pCW=nullptr; - SfxWorkWindow *pWork = nullptr; - - if ( !pCW ) - { - // If no Parent or the Parent us still unknown, then search here - sal_uInt16 nCount = aChildWins.size(); - for (sal_uInt16 n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - { - pCW = aChildWins[n].get(); - pWork = this; - break; - } - } + SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId); if ( !pCW ) { @@ -1981,29 +1925,17 @@ void SfxWorkWindow::SetChildWindow_Impl(sal_uInt16 nId, bool bOn, bool bSetFocus // the Parent pCW = new SfxChildWin_Impl( nId ); InitializeChild_Impl( pCW ); - if ( !pWork || pCW->aInfo.nFlags & SfxChildWindowFlags::TASK ) - pWork = this; - pWork->aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); + aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); } if ( pCW->bCreate != bOn ) - pWork->ToggleChildWindow_Impl(nId,bSetFocus); + ToggleChildWindow_Impl(nId,bSetFocus); } void SfxWorkWindow::ShowChildWindow_Impl(sal_uInt16 nId, bool bVisible, bool bSetFocus) { - sal_uInt16 nCount = aChildWins.size(); - SfxChildWin_Impl* pCW=nullptr; - sal_uInt16 n; - for (n=0; n<nCount; n++) - { - pCW = aChildWins[n].get(); - if (pCW->nId == nId) - break; - } - - if ( n<nCount ) + if (SfxChildWin_Impl* pCW = Get_ById(aChildWins, nId)) { SfxChildWindow *pChildWin = pCW->pWin; if ( pChildWin ) @@ -2055,12 +1987,7 @@ void SfxWorkWindow::ShowChildWindow_Impl(sal_uInt16 nId, bool bVisible, bool bSe } #ifdef DBG_UTIL - nCount = aChildWins.size(); - for (n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - break; - - if ( n<nCount ) + if (SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId)) { OSL_FAIL("The ChildWindow is not in context!"); } @@ -2074,14 +2001,8 @@ void SfxWorkWindow::ShowChildWindow_Impl(sal_uInt16 nId, bool bVisible, bool bSe SfxChildWindow* SfxWorkWindow::GetChildWindow_Impl(sal_uInt16 nId) { - sal_uInt16 nCount = aChildWins.size(); - sal_uInt16 n; - for (n=0; n<nCount; n++) - if (aChildWins[n]->nSaveId == nId) - break; - - if (n<nCount) - return aChildWins[n]->pWin; + if (SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId)) + return pCW->pWin; return nullptr; }