diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-09 11:59:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-09 19:05:34 +0200 |
commit | 8c505204f25b509daa586c2d308fb870325c59b9 (patch) | |
tree | 3c5840215f37f8f37c39703de767a4fe7b3b6d87 /sc/source/ui/navipi | |
parent | 966b156cbd8b786c88ade5d322177e16fd408732 (diff) |
loplugin:flatten in sc
Change-Id: Iedb6ca37d1b006131d1fc77eca3303a12ccb60c9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100401
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/ui/navipi')
-rw-r--r-- | sc/source/ui/navipi/content.cxx | 254 | ||||
-rw-r--r-- | sc/source/ui/navipi/navipi.cxx | 110 |
2 files changed, 182 insertions, 182 deletions
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx index eaeb767cafaa..918880c03572 100644 --- a/sc/source/ui/navipi/content.cxx +++ b/sc/source/ui/navipi/content.cxx @@ -661,47 +661,47 @@ void ScContentTree::ObjectFresh(ScContentId nType, const weld::TreeIter* pEntry) if (bHiddenDoc && !pHiddenDocument) return; // other document displayed - if (nType == ScContentId::GRAPHIC || nType == ScContentId::OLEOBJECT || nType == ScContentId::DRAWING) - { - auto nOldChildren = m_aRootNodes[nType] ? m_xTreeView->iter_n_children(*m_aRootNodes[nType]) : 0; - auto nOldPos = m_xTreeView->vadjustment_get_value(); + if (!(nType == ScContentId::GRAPHIC || nType == ScContentId::OLEOBJECT || nType == ScContentId::DRAWING)) + return; - freeze(); - ClearType( nType ); - GetDrawNames( nType/*, nId*/ ); - thaw(); + auto nOldChildren = m_aRootNodes[nType] ? m_xTreeView->iter_n_children(*m_aRootNodes[nType]) : 0; + auto nOldPos = m_xTreeView->vadjustment_get_value(); - auto nNewChildren = m_aRootNodes[nType] ? m_xTreeView->iter_n_children(*m_aRootNodes[nType]) : 0; - bool bRestorePos = nOldChildren == nNewChildren; + freeze(); + ClearType( nType ); + GetDrawNames( nType/*, nId*/ ); + thaw(); - if (!pEntry) - ApplyNavigatorSettings(bRestorePos, nOldPos); - if (pEntry) + auto nNewChildren = m_aRootNodes[nType] ? m_xTreeView->iter_n_children(*m_aRootNodes[nType]) : 0; + bool bRestorePos = nOldChildren == nNewChildren; + + if (!pEntry) + ApplyNavigatorSettings(bRestorePos, nOldPos); + if (!pEntry) + return; + + weld::TreeIter* pParent = m_aRootNodes[nType].get(); + std::unique_ptr<weld::TreeIter> xOldEntry; + std::unique_ptr<weld::TreeIter> xBeginEntry(m_xTreeView->make_iterator(pParent)); + bool bBeginEntry = false; + if( pParent ) + bBeginEntry = m_xTreeView->iter_children(*xBeginEntry); + while (bBeginEntry) + { + OUString aTempText(m_xTreeView->get_text(*xBeginEntry)); + if (aTempText == sKeyString) { - weld::TreeIter* pParent = m_aRootNodes[nType].get(); - std::unique_ptr<weld::TreeIter> xOldEntry; - std::unique_ptr<weld::TreeIter> xBeginEntry(m_xTreeView->make_iterator(pParent)); - bool bBeginEntry = false; - if( pParent ) - bBeginEntry = m_xTreeView->iter_children(*xBeginEntry); - while (bBeginEntry) - { - OUString aTempText(m_xTreeView->get_text(*xBeginEntry)); - if (aTempText == sKeyString) - { - xOldEntry = m_xTreeView->make_iterator(xBeginEntry.get()); - break; - } - bBeginEntry = m_xTreeView->iter_next(*xBeginEntry); - } - if (xOldEntry) - { - m_xTreeView->expand_row(*pParent); - m_xTreeView->select(*xOldEntry); - m_xTreeView->set_cursor(*xOldEntry); - StoreNavigatorSettings(); - } + xOldEntry = m_xTreeView->make_iterator(xBeginEntry.get()); + break; } + bBeginEntry = m_xTreeView->iter_next(*xBeginEntry); + } + if (xOldEntry) + { + m_xTreeView->expand_row(*pParent); + m_xTreeView->select(*xOldEntry); + m_xTreeView->set_cursor(*xOldEntry); + StoreNavigatorSettings(); } } @@ -867,41 +867,41 @@ void ScContentTree::GetDrawNames( ScContentId nType ) ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); SfxObjectShell* pShell = pDoc->GetDocumentShell(); - if (pDrawLayer && pShell) + if (!(pDrawLayer && pShell)) + return; + + SCTAB nTabCount = pDoc->GetTableCount(); + for (SCTAB nTab=0; nTab<nTabCount; nTab++) { - SCTAB nTabCount = pDoc->GetTableCount(); - for (SCTAB nTab=0; nTab<nTabCount; nTab++) + SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); + OSL_ENSURE(pPage,"Page ?"); + if (pPage) { - SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); - OSL_ENSURE(pPage,"Page ?"); - if (pPage) + SdrObjListIter aIter( pPage, eIter ); + SdrObject* pObject = aIter.Next(); + while (pObject) { - SdrObjListIter aIter( pPage, eIter ); - SdrObject* pObject = aIter.Next(); - while (pObject) + if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) { - if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) + OUString aName = ScDrawLayer::GetVisibleName( pObject ); + if (!aName.isEmpty()) { - OUString aName = ScDrawLayer::GetVisibleName( pObject ); - if (!aName.isEmpty()) + if( bisInNavigatoeDlg ) { - if( bisInNavigatoeDlg ) + weld::TreeIter* pParent = m_aRootNodes[nType].get(); + if (pParent) { - weld::TreeIter* pParent = m_aRootNodes[nType].get(); - if (pParent) - { - m_xTreeView->insert(pParent, -1, &aName, nullptr, nullptr, nullptr, false, m_xScratchIter.get()); - m_xTreeView->set_sensitive(*m_xScratchIter, true); - }//end if parent - else - SAL_WARN("sc", "InsertContent without parent"); - } + m_xTreeView->insert(pParent, -1, &aName, nullptr, nullptr, nullptr, false, m_xScratchIter.get()); + m_xTreeView->set_sensitive(*m_xScratchIter, true); + }//end if parent + else + SAL_WARN("sc", "InsertContent without parent"); } - } - pObject = aIter.Next(); } + + pObject = aIter.Next(); } } } @@ -1391,19 +1391,19 @@ void ScContentTree::LoadFile( const OUString& rUrl ) OUString aURL = aDocName; OUString aFilter, aOptions; ScDocumentLoader aLoader( aURL, aFilter, aOptions ); - if ( !aLoader.IsError() ) - { - bHiddenDoc = true; - aHiddenName = aDocName; - aHiddenTitle = aLoader.GetTitle(); - pHiddenDocument = aLoader.GetDocument(); + if ( aLoader.IsError() ) + return; - Refresh(); // get content from loaded document + bHiddenDoc = true; + aHiddenName = aDocName; + aHiddenTitle = aLoader.GetTitle(); + pHiddenDocument = aLoader.GetDocument(); - pHiddenDocument = nullptr; + Refresh(); // get content from loaded document - pParentWindow->GetDocNames( &aHiddenTitle ); // fill list - } + pHiddenDocument = nullptr; + + pParentWindow->GetDocNames( &aHiddenTitle ); // fill list // document is closed again by ScDocumentLoader in dtor } @@ -1574,56 +1574,56 @@ void ScContentTree::SelectEntryByName(const ScContentId nRoot, const OUString& r void ScContentTree::ApplyNavigatorSettings(bool bRestorePos, int nScrollPos) { const ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings(); - if( pSettings ) - { - ScContentId nRootSel = pSettings->GetRootSelected(); - auto nChildSel = pSettings->GetChildSelected(); + if( !pSettings ) + return; - // tdf#133079 ensure Sheet root is selected if nothing - // else would be - if (nRootSel == ScContentId::ROOT) - { - nRootSel = ScContentId::TABLE; - nChildSel = SC_CONTENT_NOCHILD; - } + ScContentId nRootSel = pSettings->GetRootSelected(); + auto nChildSel = pSettings->GetChildSelected(); - for( int i = 1; i <= int(ScContentId::LAST); ++i ) + // tdf#133079 ensure Sheet root is selected if nothing + // else would be + if (nRootSel == ScContentId::ROOT) + { + nRootSel = ScContentId::TABLE; + nChildSel = SC_CONTENT_NOCHILD; + } + + for( int i = 1; i <= int(ScContentId::LAST); ++i ) + { + ScContentId nEntry = static_cast<ScContentId>(i); + if( m_aRootNodes[ nEntry ] ) { - ScContentId nEntry = static_cast<ScContentId>(i); - if( m_aRootNodes[ nEntry ] ) + // gray or ungray + if (!m_xTreeView->iter_has_child(*m_aRootNodes[nEntry])) + m_xTreeView->set_sensitive(*m_aRootNodes[nEntry], false); + else + m_xTreeView->set_sensitive(*m_aRootNodes[nEntry], true); + + // expand + bool bExp = pSettings->IsExpanded( nEntry ); + if (bExp != m_xTreeView->get_row_expanded(*m_aRootNodes[nEntry])) { - // gray or ungray - if (!m_xTreeView->iter_has_child(*m_aRootNodes[nEntry])) - m_xTreeView->set_sensitive(*m_aRootNodes[nEntry], false); + if( bExp ) + m_xTreeView->expand_row(*m_aRootNodes[nEntry]); else - m_xTreeView->set_sensitive(*m_aRootNodes[nEntry], true); + m_xTreeView->collapse_row(*m_aRootNodes[nEntry]); + } - // expand - bool bExp = pSettings->IsExpanded( nEntry ); - if (bExp != m_xTreeView->get_row_expanded(*m_aRootNodes[nEntry])) - { - if( bExp ) - m_xTreeView->expand_row(*m_aRootNodes[nEntry]); - else - m_xTreeView->collapse_row(*m_aRootNodes[nEntry]); - } + // select + if( nRootSel == nEntry ) + { + if (bRestorePos) + m_xTreeView->vadjustment_set_value(nScrollPos); - // select - if( nRootSel == nEntry ) + std::unique_ptr<weld::TreeIter> xEntry; + if (bExp && (nChildSel != SC_CONTENT_NOCHILD)) { - if (bRestorePos) - m_xTreeView->vadjustment_set_value(nScrollPos); - - std::unique_ptr<weld::TreeIter> xEntry; - if (bExp && (nChildSel != SC_CONTENT_NOCHILD)) - { - xEntry = m_xTreeView->make_iterator(m_aRootNodes[nEntry].get()); - if (!m_xTreeView->iter_children(*xEntry) || !m_xTreeView->iter_nth_sibling(*xEntry, nChildSel)) - xEntry.reset(); - } - m_xTreeView->select(xEntry ? *xEntry : *m_aRootNodes[nEntry]); - m_xTreeView->set_cursor(xEntry ? *xEntry : *m_aRootNodes[nEntry]); + xEntry = m_xTreeView->make_iterator(m_aRootNodes[nEntry].get()); + if (!m_xTreeView->iter_children(*xEntry) || !m_xTreeView->iter_nth_sibling(*xEntry, nChildSel)) + xEntry.reset(); } + m_xTreeView->select(xEntry ? *xEntry : *m_aRootNodes[nEntry]); + m_xTreeView->set_cursor(xEntry ? *xEntry : *m_aRootNodes[nEntry]); } } } @@ -1632,26 +1632,26 @@ void ScContentTree::ApplyNavigatorSettings(bool bRestorePos, int nScrollPos) void ScContentTree::StoreNavigatorSettings() const { ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings(); - if( pSettings ) + if( !pSettings ) + return; + + for( int i = 1; i <= int(ScContentId::LAST); ++i ) { - for( int i = 1; i <= int(ScContentId::LAST); ++i ) - { - ScContentId nEntry = static_cast<ScContentId>(i); - bool bExp = m_aRootNodes[nEntry] && m_xTreeView->get_row_expanded(*m_aRootNodes[nEntry]); - pSettings->SetExpanded( nEntry, bExp ); - } + ScContentId nEntry = static_cast<ScContentId>(i); + bool bExp = m_aRootNodes[nEntry] && m_xTreeView->get_row_expanded(*m_aRootNodes[nEntry]); + pSettings->SetExpanded( nEntry, bExp ); + } - std::unique_ptr<weld::TreeIter> xCurEntry(m_xTreeView->make_iterator()); - if (!m_xTreeView->get_cursor(xCurEntry.get())) - xCurEntry.reset(); + std::unique_ptr<weld::TreeIter> xCurEntry(m_xTreeView->make_iterator()); + if (!m_xTreeView->get_cursor(xCurEntry.get())) + xCurEntry.reset(); - ScContentId nRoot; - sal_uLong nChild; - GetEntryIndexes(nRoot, nChild, xCurEntry.get()); + ScContentId nRoot; + sal_uLong nChild; + GetEntryIndexes(nRoot, nChild, xCurEntry.get()); - pSettings->SetRootSelected( nRoot ); - pSettings->SetChildSelected( nChild ); - } + pSettings->SetRootSelected( nRoot ); + pSettings->SetChildSelected( nChild ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx index f970ef9c8683..c7edef768b2e 100644 --- a/sc/source/ui/navipi/navipi.cxx +++ b/sc/source/ui/navipi/navipi.cxx @@ -233,20 +233,20 @@ IMPL_LINK(ScNavigatorDlg, ToolBoxDropdownClickHdl, const OString&, rCommand, voi // the popup menu of the drop mode has to be called in the // click (button down) and not in the select (button up) - if (rCommand == "dragmode") + if (rCommand != "dragmode") + return; + + switch (GetDropMode()) { - switch (GetDropMode()) - { - case 0: - m_xDragModeMenu->set_active("hyperlink", true); - break; - case 1: - m_xDragModeMenu->set_active("link", true); - break; - case 2: - m_xDragModeMenu->set_active("copy", true); - break; - } + case 0: + m_xDragModeMenu->set_active("hyperlink", true); + break; + case 1: + m_xDragModeMenu->set_active("link", true); + break; + case 2: + m_xDragModeMenu->set_active("copy", true); + break; } } @@ -550,26 +550,26 @@ void ScNavigatorDlg::SetDropMode(sal_uInt16 nNew) void ScNavigatorDlg::SetCurrentCell( SCCOL nColNo, SCROW nRowNo ) { - if ( (nColNo+1 != nCurCol) || (nRowNo+1 != nCurRow) ) - { - // SID_CURRENTCELL == Item #0 clear cache, so it's possible - // setting the current cell even in combined areas - mvBoundItems[0]->ClearCache(); + if ((nColNo+1 == nCurCol) && (nRowNo+1 == nCurRow)) + return; - ScAddress aScAddress( nColNo, nRowNo, 0 ); - OUString aAddr(aScAddress.Format(ScRefFlags::ADDR_ABS)); + // SID_CURRENTCELL == Item #0 clear cache, so it's possible + // setting the current cell even in combined areas + mvBoundItems[0]->ClearCache(); - bool bUnmark = false; - if ( GetViewData() ) - bUnmark = !pViewData->GetMarkData().IsCellMarked( nColNo, nRowNo ); + ScAddress aScAddress( nColNo, nRowNo, 0 ); + OUString aAddr(aScAddress.Format(ScRefFlags::ADDR_ABS)); - SfxStringItem aPosItem( SID_CURRENTCELL, aAddr ); - SfxBoolItem aUnmarkItem( FN_PARAM_1, bUnmark ); // cancel selection + bool bUnmark = false; + if ( GetViewData() ) + bUnmark = !pViewData->GetMarkData().IsCellMarked( nColNo, nRowNo ); - rBindings.GetDispatcher()->ExecuteList(SID_CURRENTCELL, - SfxCallMode::SYNCHRON | SfxCallMode::RECORD, - { &aPosItem, &aUnmarkItem }); - } + SfxStringItem aPosItem( SID_CURRENTCELL, aAddr ); + SfxBoolItem aUnmarkItem( FN_PARAM_1, bUnmark ); // cancel selection + + rBindings.GetDispatcher()->ExecuteList(SID_CURRENTCELL, + SfxCallMode::SYNCHRON | SfxCallMode::RECORD, + { &aPosItem, &aUnmarkItem }); } void ScNavigatorDlg::SetCurrentCellStr( const OUString& rName ) @@ -652,21 +652,21 @@ void ScNavigatorDlg::UpdateSelection() return; uno::Reference< drawing::XShapes > xShapes = pViewSh->getSelectedXShapes(); - if( xShapes ) + if( !xShapes ) + return; + + uno::Reference< container::XIndexAccess > xIndexAccess( + xShapes, uno::UNO_QUERY_THROW ); + if( xIndexAccess->getCount() > 1 ) + return; + uno::Reference< drawing::XShape > xShape; + if( xIndexAccess->getByIndex(0) >>= xShape ) { - uno::Reference< container::XIndexAccess > xIndexAccess( - xShapes, uno::UNO_QUERY_THROW ); - if( xIndexAccess->getCount() > 1 ) - return; - uno::Reference< drawing::XShape > xShape; - if( xIndexAccess->getByIndex(0) >>= xShape ) + uno::Reference< container::XNamed > xNamed( xShape, uno::UNO_QUERY_THROW ); + OUString sName = xNamed->getName(); + if (!sName.isEmpty()) { - uno::Reference< container::XNamed > xNamed( xShape, uno::UNO_QUERY_THROW ); - OUString sName = xNamed->getName(); - if (!sName.isEmpty()) - { - m_xLbEntries->SelectEntryByName( ScContentId::DRAWING, sName ); - } + m_xLbEntries->SelectEntryByName( ScContentId::DRAWING, sName ); } } } @@ -863,20 +863,20 @@ void ScNavigatorDlg::MarkDataArea() { ScTabViewShell* pViewSh = GetTabViewShell(); - if ( pViewSh ) - { - if ( !pMarkArea ) - pMarkArea.reset( new ScArea ); + if ( !pViewSh ) + return; - pViewSh->MarkDataArea(); - ScRange aMarkRange; - pViewSh->GetViewData().GetMarkData().GetMarkArea(aMarkRange); - pMarkArea->nColStart = aMarkRange.aStart.Col(); - pMarkArea->nRowStart = aMarkRange.aStart.Row(); - pMarkArea->nColEnd = aMarkRange.aEnd.Col(); - pMarkArea->nRowEnd = aMarkRange.aEnd.Row(); - pMarkArea->nTab = aMarkRange.aStart.Tab(); - } + if ( !pMarkArea ) + pMarkArea.reset( new ScArea ); + + pViewSh->MarkDataArea(); + ScRange aMarkRange; + pViewSh->GetViewData().GetMarkData().GetMarkArea(aMarkRange); + pMarkArea->nColStart = aMarkRange.aStart.Col(); + pMarkArea->nRowStart = aMarkRange.aStart.Row(); + pMarkArea->nColEnd = aMarkRange.aEnd.Col(); + pMarkArea->nRowEnd = aMarkRange.aEnd.Row(); + pMarkArea->nTab = aMarkRange.aStart.Tab(); } void ScNavigatorDlg::UnmarkDataArea() |