From 8870e068cc7368ffa14a6938836b370d2a188b64 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Sat, 20 Dec 2014 20:47:39 +0100 Subject: fdo#39440 sc: reduce scope of local variables This addresses some cppcheck warnings. Change-Id: Icd031be4aeec07ba60804923e3506d64cf876dd8 --- sc/source/ui/vba/vbachart.cxx | 4 ++-- sc/source/ui/vba/vbarange.cxx | 15 +++++++-------- sc/source/ui/view/cellsh1.cxx | 7 ++++--- sc/source/ui/view/drawvie3.cxx | 9 +++------ sc/source/ui/view/output.cxx | 9 +++------ sc/source/ui/view/output2.cxx | 4 ++-- sc/source/ui/view/viewfun3.cxx | 6 ++---- sc/source/ui/xmlsource/xmlsourcedlg.cxx | 9 +++------ 8 files changed, 26 insertions(+), 37 deletions(-) (limited to 'sc/source') diff --git a/sc/source/ui/vba/vbachart.cxx b/sc/source/ui/vba/vbachart.cxx index f9f8db7e93d4..dd89baa4a861 100644 --- a/sc/source/ui/vba/vbachart.cxx +++ b/sc/source/ui/vba/vbachart.cxx @@ -923,9 +923,9 @@ ScVbaChart::is100PercentStacked() throw ( uno::RuntimeException ) sal_Int32 ScVbaChart::getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked) throw ( script::BasicErrorException ) { - bool bIsVertical = true; try { + bool bIsVertical = true; mxDiagramPropertySet->getPropertyValue(VERTICAL) >>= bIsVertical; bool bIsDeep = false; mxDiagramPropertySet->getPropertyValue(DEEP) >>= bIsDeep; @@ -955,9 +955,9 @@ ScVbaChart::getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _ sal_Int32 ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown) throw (script::BasicErrorException) { - bool bUpDown = false; try { + bool bUpDown = false; mxDiagramPropertySet->getPropertyValue(UPDOWN) >>= bUpDown; if (bUpDown) { diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 642ddec429a6..610222625aab 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -1190,7 +1190,6 @@ bool getScRangeListForAddress( const OUString& sName, ScDocShell* pDocSh, ScRang OUString sAddress = (*it).trim(); // if a local name ( on the active sheet ) exists this will // take precedence over a global with the same name - bool bLocalName = false; if ( !xNameAccess->hasByName( sAddress ) ) { // try a local name @@ -1199,7 +1198,7 @@ bool getScRangeListForAddress( const OUString& sName, ScDocShell* pDocSh, ScRang ScRangeName* pRangeName = rDoc.GetRangeName(nCurTab); if (pRangeName) { - bLocalName = pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(sAddress)) != NULL; + bool bLocalName = pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(sAddress)) != NULL; // TODO: Handle local names correctly. (void)bLocalName; } @@ -2094,9 +2093,9 @@ ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolut if ( !bVal ) nFlags &= ~COL_ABSOLUTE; } - bool bLocal = false; if ( External.hasValue() ) { + bool bLocal = false; External >>= bLocal; if ( bLocal ) nFlags |= SCA_TAB_3D | SCA_FORCE_DOC; @@ -3045,7 +3044,6 @@ ScVbaRange::Replace( const OUString& What, const OUString& Replacement, const un sal_Int16 nLook = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole; sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns; - bool bMatchCase = false; uno::Reference< util::XReplaceable > xReplace( mxRange, uno::UNO_QUERY ); if ( xReplace.is() ) { @@ -3088,6 +3086,8 @@ ScVbaRange::Replace( const OUString& What, const OUString& Replacement, const un } if ( MatchCase.hasValue() ) { + bool bMatchCase = false; + // SearchCaseSensitive MatchCase >>= bMatchCase; xDescriptor->setPropertyValue( SC_UNO_SRCHCASE, uno::makeAny( bMatchCase ) ); @@ -4470,7 +4470,6 @@ ScVbaRange::AutoFilter( const uno::Any& aField, const uno::Any& Criteria1, const if ( !aField.hasValue() && ( Criteria1.hasValue() || Operator.hasValue() || Criteria2.hasValue() ) ) throw uno::RuntimeException(); - bool bAll = false; uno::Any Field( aField ); if ( !( Field >>= nField ) ) { @@ -4488,6 +4487,8 @@ ScVbaRange::AutoFilter( const uno::Any& aField, const uno::Any& Criteria1, const // in this case we just call the core calc functionality - if ( ( Field >>= nField ) ) { + bool bAll = false; + uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY ); if ( xDesc.is() ) @@ -4836,8 +4837,6 @@ uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException, std::ex if( m_Areas->getCount() > 1 ) throw uno::RuntimeException("Can not get Range.ShowDetail attribute " ); - bool bShowDetail = false; - RangeHelper helper( mxRange ); uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor(); xSheetCellCursor->collapseToCurrentRegion(); @@ -4857,7 +4856,7 @@ uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException, std::ex const ScOutlineEntry* pEntry = rOutlineArray.GetEntryByPos( 0, nPos ); if( pEntry ) { - bShowDetail = !pEntry->IsHidden(); + const bool bShowDetail = !pEntry->IsHidden(); return uno::makeAny( bShowDetail ); } } diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 331a76556ebe..72d072e39265 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -1304,9 +1304,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) { InsertDeleteFlags nFlags = IDF_NONE; sal_uInt16 nFunction = PASTE_NOFUNC; - bool bSkipEmpty = false; - bool bTranspose = false; - bool bAsLink = false; InsCellCmd eMoveMode = INS_NONE; vcl::Window* pWin = GetViewData()->GetActiveWin(); @@ -1315,6 +1312,10 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin ); if ( pOwnClip ) { + bool bSkipEmpty = false; + bool bTranspose = false; + bool bAsLink = false; + // keep a reference in case the clipboard is changed during dialog or PasteFromClip uno::Reference aOwnClipRef( pOwnClip ); if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() ) diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx index d4bc93a1d29b..4300413ea514 100644 --- a/sc/source/ui/view/drawvie3.cxx +++ b/sc/source/ui/view/drawvie3.cxx @@ -57,12 +57,11 @@ void ScDrawView::SetPageAnchored() { if( AreObjectsMarked() ) { - SdrObject* pObj = NULL; const SdrMarkList* pMark = &GetMarkedObjectList(); const size_t nCount = pMark->GetMarkCount(); for( size_t i=0; iGetMark(i)->GetMarkedSdrObj(); + SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); ScDrawLayer::SetPageAnchored( *pObj ); } @@ -82,12 +81,11 @@ void ScDrawView::SetCellAnchored() if( AreObjectsMarked() ) { - SdrObject* pObj = NULL; const SdrMarkList* pMark = &GetMarkedObjectList(); const size_t nCount = pMark->GetMarkCount(); for( size_t i=0; iGetMark(i)->GetMarkedSdrObj(); + SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab); } @@ -107,10 +105,9 @@ ScAnchorType ScDrawView::GetAnchorType() const { const SdrMarkList* pMark = &GetMarkedObjectList(); const size_t nCount = pMark->GetMarkCount(); - const SdrObject* pObj = NULL; for( size_t i=0; iGetMark(i)->GetMarkedSdrObj(); + const SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); if( ScDrawLayer::GetAnchorType( *pObj ) == SCA_CELL ) bCell =true; else diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx index 6fc29bb75369..36dd56d1d374 100644 --- a/sc/source/ui/view/output.cxx +++ b/sc/source/ui/view/output.cxx @@ -414,11 +414,10 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage ) ++nVisX; nPosY = nScrY; - long nNextY; for (nArrY=1; nArrY+1nHeight; + const long nNextY = nPosY + pThisRowInfo->nHeight; bool bHOver = pThisRowInfo->pCellInfo[nXplus1].bHideGrid; if (!bHOver) @@ -516,10 +515,9 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage ) if ( bLayoutRTL ) nPosX += nMirrorW - nOneX; - long nNextX; for (SCCOL i=nX1; i<=nX2; i++) { - nNextX = nPosX + pRowInfo[0].pCellInfo[i+1].nWidth * nLayoutSign; + const long nNextX = nPosX + pRowInfo[0].pCellInfo[i+1].nWidth * nLayoutSign; if (nNextX != nPosX) // visible { bool bVOver; @@ -1000,7 +998,6 @@ void ScOutputData::DrawBackground() const SvxBrushItem* pOldBackground = NULL; const SvxBrushItem* pBackground; const Color* pOldColor = NULL; - const Color* pColor = NULL; const ScDataBarInfo* pOldDataBarInfo = NULL; const ScIconSetInfo* pOldIconSetInfo = NULL; for (SCCOL nX=nX1; nX<=nX2; nX++) @@ -1041,7 +1038,7 @@ void ScOutputData::DrawBackground() pBackground = lcl_FindBackground( mpDoc, nX, nY, nTab ); } - pColor = pInfo->pColorScale.get(); + const Color* pColor = pInfo->pColorScale.get(); const ScDataBarInfo* pDataBarInfo = pInfo->pDataBar.get(); const ScIconSetInfo* pIconSetInfo = pInfo->pIconSet.get(); drawCells( pColor, pBackground, pOldColor, pOldBackground, aRect, nPosX, nSignedOneX, mpDev, pDataBarInfo, pOldDataBarInfo, pIconSetInfo, pOldIconSetInfo ); diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index e6d745eb6e08..47f28c219e22 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -1858,12 +1858,12 @@ void ScOutputData::DrawStrings( bool bPixelToLogic ) bVClip = true; } - // horizontalen Platz testen + // check horizontal space - bool bRightAdjusted = false; // to correct text width calculation later bool bNeedEditEngine = false; if ( !bNeedEditEngine && !bOutside ) { + bool bRightAdjusted = false; // to correct text width calculation later switch (eOutHorJust) { case SVX_HOR_JUSTIFY_LEFT: diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index 562135a0d5e0..ee1d23a4fe5e 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -1151,15 +1151,13 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc, { // "Cell merge not possible if cells already merged" ScDocAttrIterator aIter( pDoc, nStartTab, nStartCol, nStartRow, nUndoEndCol, nUndoEndRow ); const ScPatternAttr* pPattern = NULL; - const ScMergeAttr* pMergeFlag = NULL; - const ScMergeFlagAttr* pMergeFlagAttr = NULL; SCCOL nCol = -1; SCROW nRow1 = -1; SCROW nRow2 = -1; while ( ( pPattern = aIter.GetNext( nCol, nRow1, nRow2 ) ) != NULL ) { - pMergeFlag = static_cast( &pPattern->GetItem(ATTR_MERGE) ); - pMergeFlagAttr = static_cast( &pPattern->GetItem(ATTR_MERGE_FLAG) ); + const ScMergeAttr* pMergeFlag = static_cast( &pPattern->GetItem(ATTR_MERGE) ); + const ScMergeFlagAttr* pMergeFlagAttr = static_cast( &pPattern->GetItem(ATTR_MERGE_FLAG) ); if( ( pMergeFlag && pMergeFlag->IsMerged() ) || ( pMergeFlagAttr && pMergeFlagAttr->IsOverlapped() ) ) { ScRange aRange(nCol, nRow1, nStartTab); diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx index 6a81c2248d09..39331ac79083 100644 --- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx +++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx @@ -326,10 +326,9 @@ void ScXMLSourceDlg::DefaultElementSelected(SvTreeListEntry& rEntry) { // Only an element with no child elements (leaf element) can be linked. bool bHasChild = false; - ScOrcusXMLTreeParam::EntryData* pUserData = NULL; for (SvTreeListEntry* pChild = mpLbTree->FirstChild(&rEntry); pChild; pChild = mpLbTree->NextSibling(pChild)) { - pUserData = ScOrcusXMLTreeParam::getUserData(*pChild); + ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pChild); OSL_ASSERT(pUserData); if (pUserData->meType != ScOrcusXMLTreeParam::Attribute) { @@ -451,11 +450,10 @@ void ScXMLSourceDlg::SelectAllChildEntries(SvTreeListEntry& rEntry) bool ScXMLSourceDlg::IsParentDirty(SvTreeListEntry* pEntry) const { - ScOrcusXMLTreeParam::EntryData* pUserData = NULL; SvTreeListEntry* pParent = mpLbTree->GetParent(pEntry); while (pParent) { - pUserData = ScOrcusXMLTreeParam::getUserData(*pParent); + ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pParent); assert(pUserData); if (pUserData->maLinkedPos.IsValid()) { @@ -474,10 +472,9 @@ bool ScXMLSourceDlg::IsParentDirty(SvTreeListEntry* pEntry) const bool ScXMLSourceDlg::IsChildrenDirty(SvTreeListEntry* pEntry) const { - ScOrcusXMLTreeParam::EntryData* pUserData = NULL; for (SvTreeListEntry* pChild = mpLbTree->FirstChild(pEntry); pChild; pChild = mpLbTree->NextSibling(pChild)) { - pUserData = ScOrcusXMLTreeParam::getUserData(*pChild); + ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pChild); OSL_ASSERT(pUserData); if (pUserData->maLinkedPos.IsValid()) // Already linked. -- cgit