summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-22 08:50:20 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-22 13:48:25 +0200
commita7ce8404befaf59df5f1a476c8dd414633bbf823 (patch)
treedc617344e2ac5a1b144614421a87d27a17ee0f36
parent5c54b6523f74db4f79540361fc1630aaee06bcd5 (diff)
loplugin:flatten in pyuno..sc
Change-Id: I7ddc0b76532d26910f78642200750459508c2861 Reviewed-on: https://gerrit.libreoffice.org/42617 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/flatten.cxx16
-rw-r--r--pyuno/source/module/pyuno_runtime.cxx40
-rw-r--r--pyuno/source/module/pyuno_type.cxx47
-rw-r--r--reportdesign/source/core/api/ReportDefinition.cxx21
-rw-r--r--sc/source/ui/Accessibility/AccessiblePreviewTable.cxx101
-rw-r--r--sc/source/ui/unoobj/afmtuno.cxx94
-rw-r--r--sc/source/ui/unoobj/appluno.cxx78
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx138
-rw-r--r--sc/source/ui/unoobj/chart2uno.cxx11
-rw-r--r--sc/source/ui/unoobj/chartuno.cxx12
-rw-r--r--sc/source/ui/unoobj/condformatuno.cxx97
-rw-r--r--sc/source/ui/unoobj/dapiuno.cxx24
-rw-r--r--sc/source/ui/unoobj/datauno.cxx66
-rw-r--r--sc/source/ui/unoobj/docuno.cxx151
-rw-r--r--sc/source/ui/unoobj/fielduno.cxx122
15 files changed, 482 insertions, 536 deletions
diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx
index 3ae8b3b7dc45..fd5094940c3c 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -15,10 +15,8 @@
#include "plugin.hxx"
/**
- Look for places where we can flatten the control flow in a method.
-
+ Look for places where we can flatten the control flow in a method by returning early.
*/
-
namespace {
class Flatten:
@@ -295,24 +293,24 @@ SourceRange Flatten::extendOverComments(SourceRange range)
startLoc = startLoc.getLocWithOffset(p1 - SM.getCharacterData( startLoc ));
// look for trailing ";"
- while (*p2 == ';')
+ while (*(p2+1) == ';')
++p2;
// look for trailing " "
- while (*p2 == ' ')
+ while (*(p2+1) == ' ')
++p2;
// look for single line comments attached to the end of the statement
- if (*p2 == '/' && *(p2+1) == '/')
+ if (*(p2+1) == '/' && *(p2+2) == '/')
{
p2 += 2;
- while (*p2 && *p2 != '\n')
+ while (*(p2+1) && *(p2+1) != '\n')
++p2;
- if (*p2 == '\n')
+ if (*(p2+1) == '\n')
++p2;
}
else
{
// make the source code we extract include any trailing "\n"
- if (*p2 == '\n')
+ if (*(p2+1) == '\n')
++p2;
}
endLoc = endLoc.getLocWithOffset(p2 - SM.getCharacterData( endLoc ));
diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx
index 1a47db8999bd..0955326f61fc 100644
--- a/pyuno/source/module/pyuno_runtime.cxx
+++ b/pyuno/source/module/pyuno_runtime.cxx
@@ -764,13 +764,14 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
PyRef struc(PyObject_GetAttrString( o , "value" ),SAL_NO_ACQUIRE);
PyUNO * obj = reinterpret_cast<PyUNO*>(struc.get());
Reference< XMaterialHolder > holder( obj->members->xInvocation, UNO_QUERY );
- if( holder.is( ) )
- a = holder->getMaterial();
- else
+ if( !holder.is( ) )
{
throw RuntimeException(
"struct or exception wrapper does not support XMaterialHolder" );
}
+
+ a = holder->getMaterial();
+
}
else if( PyObject_IsInstance( o, getPyUnoClass().get() ) )
{
@@ -789,28 +790,27 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
}
else if( PyObject_IsInstance( o, getAnyClass( runtime ).get() ) )
{
- if( ACCEPT_UNO_ANY == mode )
- {
- a = pyObject2Any( PyRef( PyObject_GetAttrString( o , "value" ), SAL_NO_ACQUIRE) );
- Type t;
- pyObject2Any( PyRef( PyObject_GetAttrString( o, "type" ), SAL_NO_ACQUIRE ) ) >>= t;
-
- try
- {
- a = getImpl()->cargo->xTypeConverter->convertTo( a, t );
- }
- catch( const css::uno::Exception & e )
- {
- throw WrappedTargetRuntimeException(
- e.Message, e.Context, makeAny(e));
- }
- }
- else
+ if( !(ACCEPT_UNO_ANY == mode) )
{
throw RuntimeException(
"uno.Any instance not accepted during method call, "
"use uno.invoke instead" );
}
+
+ a = pyObject2Any( PyRef( PyObject_GetAttrString( o , "value" ), SAL_NO_ACQUIRE) );
+ Type t;
+ pyObject2Any( PyRef( PyObject_GetAttrString( o, "type" ), SAL_NO_ACQUIRE ) ) >>= t;
+
+ try
+ {
+ a = getImpl()->cargo->xTypeConverter->convertTo( a, t );
+ }
+ catch( const css::uno::Exception & e )
+ {
+ throw WrappedTargetRuntimeException(
+ e.Message, e.Context, makeAny(e));
+ }
+
}
else
{
diff --git a/pyuno/source/module/pyuno_type.cxx b/pyuno/source/module/pyuno_type.cxx
index b09c78de1205..e54400ba6d8d 100644
--- a/pyuno/source/module/pyuno_type.cxx
+++ b/pyuno/source/module/pyuno_type.cxx
@@ -160,38 +160,37 @@ Any PyEnum2Enum( PyObject *obj )
char *stringValue = PyStr_AsString( value.get() );
TypeDescription desc( strTypeName );
- if( desc.is() )
+ if( !desc.is() )
{
- if(desc.get()->eTypeClass != typelib_TypeClass_ENUM )
- {
- throw RuntimeException( "pyuno.checkEnum: " + strTypeName + "is a " +
- OUString::createFromAscii(typeClassToString( (css::uno::TypeClass) desc.get()->eTypeClass)) +
- ", expected ENUM" );
- }
+ throw RuntimeException( "enum " + OUString::createFromAscii( PyStr_AsString(typeName.get()) ) + " is unknown" );
+ }
+
+ if(desc.get()->eTypeClass != typelib_TypeClass_ENUM )
+ {
+ throw RuntimeException( "pyuno.checkEnum: " + strTypeName + "is a " +
+ OUString::createFromAscii(typeClassToString( (css::uno::TypeClass) desc.get()->eTypeClass)) +
+ ", expected ENUM" );
+ }
- desc.makeComplete();
+ desc.makeComplete();
- typelib_EnumTypeDescription *pEnumDesc = reinterpret_cast<typelib_EnumTypeDescription*>(desc.get());
- int i = 0;
- for( i = 0; i < pEnumDesc->nEnumValues ; i ++ )
- {
- if( OUString::unacquired(&pEnumDesc->ppEnumNames[i]).equalsAscii( stringValue ) )
- {
- break;
- }
- }
- if( i == pEnumDesc->nEnumValues )
+ typelib_EnumTypeDescription *pEnumDesc = reinterpret_cast<typelib_EnumTypeDescription*>(desc.get());
+ int i = 0;
+ for( i = 0; i < pEnumDesc->nEnumValues ; i ++ )
+ {
+ if( OUString::unacquired(&pEnumDesc->ppEnumNames[i]).equalsAscii( stringValue ) )
{
- throw RuntimeException( "value " + OUString::createFromAscii( stringValue ) +
- "is unknown in enum " +
- OUString::createFromAscii( PyStr_AsString( typeName.get() ) ) );
+ break;
}
- ret = Any( &pEnumDesc->pEnumValues[i], desc.get()->pWeakRef );
}
- else
+ if( i == pEnumDesc->nEnumValues )
{
- throw RuntimeException( "enum " + OUString::createFromAscii( PyStr_AsString(typeName.get()) ) + " is unknown" );
+ throw RuntimeException( "value " + OUString::createFromAscii( stringValue ) +
+ "is unknown in enum " +
+ OUString::createFromAscii( PyStr_AsString( typeName.get() ) ) );
}
+ ret = Any( &pEnumDesc->pEnumValues[i], desc.get()->pWeakRef );
+
return ret;
}
diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx
index d0c194ab95db..ca6d941dcf50 100644
--- a/reportdesign/source/core/api/ReportDefinition.cxx
+++ b/reportdesign/source/core/api/ReportDefinition.cxx
@@ -2664,21 +2664,20 @@ uno::Reference< document::XDocumentProperties > SAL_CALL OReportDefinition::getD
uno::Any SAL_CALL OReportDefinition::getTransferData( const datatransfer::DataFlavor& aFlavor )
{
uno::Any aResult;
- if( isDataFlavorSupported( aFlavor ) )
+ if( !isDataFlavorSupported( aFlavor ) )
{
- try
- {
- aResult = getPreferredVisualRepresentation(0).Data;
- }
- catch (const uno::Exception &)
- {
- DBG_UNHANDLED_EXCEPTION();
- }
+ throw datatransfer::UnsupportedFlavorException(aFlavor.MimeType, static_cast< ::cppu::OWeakObject* >( this ));
}
- else
+
+ try
{
- throw datatransfer::UnsupportedFlavorException(aFlavor.MimeType, static_cast< ::cppu::OWeakObject* >( this ));
+ aResult = getPreferredVisualRepresentation(0).Data;
}
+ catch (const uno::Exception &)
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
return aResult;
}
diff --git a/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx b/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx
index a8a51dd51091..81d5a0970a96 100644
--- a/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx
+++ b/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx
@@ -181,27 +181,25 @@ sal_Int32 SAL_CALL ScAccessiblePreviewTable::getAccessibleRowExtentAt( sal_Int32
FillTableInfo();
sal_Int32 nRows = 1;
- if ( mpViewShell && mpTableInfo && nColumn >= 0 && nRow >= 0 &&
- nColumn < mpTableInfo->GetCols() && nRow < mpTableInfo->GetRows() )
- {
- const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[nColumn];
- const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[nRow];
+ if ( !mpViewShell || !mpTableInfo || nColumn < 0 || nRow < 0 ||
+ nColumn >= mpTableInfo->GetCols() || nRow >= mpTableInfo->GetRows() )
+ throw lang::IndexOutOfBoundsException();
- if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
- {
- // header cells only span a single cell
- }
- else
- {
- ScDocument& rDoc = mpViewShell->GetDocument();
- const ScMergeAttr* pItem = static_cast<const ScMergeAttr*>(rDoc.GetAttr(
- static_cast<SCCOL>(rColInfo.nDocIndex), static_cast<SCROW>(rRowInfo.nDocIndex), mpTableInfo->GetTab(), ATTR_MERGE ));
- if ( pItem && pItem->GetRowMerge() > 0 )
- nRows = pItem->GetRowMerge();
- }
+ const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[nColumn];
+ const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[nRow];
+
+ if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
+ {
+ // header cells only span a single cell
}
else
- throw lang::IndexOutOfBoundsException();
+ {
+ ScDocument& rDoc = mpViewShell->GetDocument();
+ const ScMergeAttr* pItem = static_cast<const ScMergeAttr*>(rDoc.GetAttr(
+ static_cast<SCCOL>(rColInfo.nDocIndex), static_cast<SCROW>(rRowInfo.nDocIndex), mpTableInfo->GetTab(), ATTR_MERGE ));
+ if ( pItem && pItem->GetRowMerge() > 0 )
+ nRows = pItem->GetRowMerge();
+ }
return nRows;
}
@@ -214,27 +212,25 @@ sal_Int32 SAL_CALL ScAccessiblePreviewTable::getAccessibleColumnExtentAt( sal_In
FillTableInfo();
sal_Int32 nColumns = 1;
- if ( mpViewShell && mpTableInfo && nColumn >= 0 && nRow >= 0 &&
- nColumn < mpTableInfo->GetCols() && nRow < mpTableInfo->GetRows() )
- {
- const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[nColumn];
- const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[nRow];
+ if ( !mpViewShell || !mpTableInfo || nColumn < 0 || nRow < 0 ||
+ nColumn >= mpTableInfo->GetCols() || nRow >= mpTableInfo->GetRows() )
+ throw lang::IndexOutOfBoundsException();
- if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
- {
- // header cells only span a single cell
- }
- else
- {
- ScDocument& rDoc = mpViewShell->GetDocument();
- const ScMergeAttr* pItem = static_cast<const ScMergeAttr*>(rDoc.GetAttr(
- static_cast<SCCOL>(rColInfo.nDocIndex), static_cast<SCROW>(rRowInfo.nDocIndex), mpTableInfo->GetTab(), ATTR_MERGE ));
- if ( pItem && pItem->GetColMerge() > 0 )
- nColumns = pItem->GetColMerge();
- }
+ const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[nColumn];
+ const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[nRow];
+
+ if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
+ {
+ // header cells only span a single cell
}
else
- throw lang::IndexOutOfBoundsException();
+ {
+ ScDocument& rDoc = mpViewShell->GetDocument();
+ const ScMergeAttr* pItem = static_cast<const ScMergeAttr*>(rDoc.GetAttr(
+ static_cast<SCCOL>(rColInfo.nDocIndex), static_cast<SCROW>(rRowInfo.nDocIndex), mpTableInfo->GetTab(), ATTR_MERGE ));
+ if ( pItem && pItem->GetColMerge() > 0 )
+ nColumns = pItem->GetColMerge();
+ }
return nColumns;
}
@@ -347,13 +343,10 @@ sal_Bool SAL_CALL ScAccessiblePreviewTable::isAccessibleSelected( sal_Int32 nRow
FillTableInfo();
- if ( mpTableInfo && nColumn >= 0 && nRow >= 0 && nColumn < mpTableInfo->GetCols() && nRow < mpTableInfo->GetRows() )
- {
- // index iterates horizontally
- }
- else
+ if ( !mpTableInfo || nColumn < 0 || nRow < 0 || nColumn >= mpTableInfo->GetCols() || nRow >= mpTableInfo->GetRows() )
throw lang::IndexOutOfBoundsException();
+ // index iterates horizontally
return false;
}
@@ -364,15 +357,11 @@ sal_Int32 SAL_CALL ScAccessiblePreviewTable::getAccessibleIndex( sal_Int32 nRow,
FillTableInfo();
- sal_Int32 nRet = 0;
- if ( mpTableInfo && nColumn >= 0 && nRow >= 0 && nColumn < mpTableInfo->GetCols() && nRow < mpTableInfo->GetRows() )
- {
- // index iterates horizontally
- nRet = nRow * mpTableInfo->GetCols() + nColumn;
- }
- else
+ if ( !mpTableInfo || nColumn < 0 || nRow < 0 || nColumn >= mpTableInfo->GetCols() || nRow >= mpTableInfo->GetRows() )
throw lang::IndexOutOfBoundsException();
+ // index iterates horizontally
+ sal_Int32 nRet = nRow * mpTableInfo->GetCols() + nColumn;
return nRet;
}
@@ -383,14 +372,10 @@ sal_Int32 SAL_CALL ScAccessiblePreviewTable::getAccessibleRow( sal_Int32 nChildI
FillTableInfo();
- sal_Int32 nRow = 0;
- if ( mpTableInfo && nChildIndex >= 0 && nChildIndex < static_cast<sal_Int32>(mpTableInfo->GetRows()) * mpTableInfo->GetCols() )
- {
- nRow = nChildIndex / mpTableInfo->GetCols();
- }
- else
+ if ( !mpTableInfo || nChildIndex < 0 || nChildIndex >= static_cast<sal_Int32>(mpTableInfo->GetRows()) * mpTableInfo->GetCols() )
throw lang::IndexOutOfBoundsException();
+ sal_Int32 nRow = nChildIndex / mpTableInfo->GetCols();
return nRow;
}
@@ -401,14 +386,10 @@ sal_Int32 SAL_CALL ScAccessiblePreviewTable::getAccessibleColumn( sal_Int32 nChi
FillTableInfo();
- sal_Int32 nCol = 0;
- if ( mpTableInfo && nChildIndex >= 0 && nChildIndex < static_cast<sal_Int32>(mpTableInfo->GetRows()) * mpTableInfo->GetCols() )
- {
- nCol = nChildIndex % static_cast<sal_Int32>(mpTableInfo->GetCols());
- }
- else
+ if ( !mpTableInfo || nChildIndex < 0 || nChildIndex >= static_cast<sal_Int32>(mpTableInfo->GetRows()) * mpTableInfo->GetCols() )
throw lang::IndexOutOfBoundsException();
+ sal_Int32 nCol = nChildIndex % static_cast<sal_Int32>(mpTableInfo->GetCols());
return nCol;
}
diff --git a/sc/source/ui/unoobj/afmtuno.cxx b/sc/source/ui/unoobj/afmtuno.cxx
index 2d492bc6809d..b1349a2222ca 100644
--- a/sc/source/ui/unoobj/afmtuno.cxx
+++ b/sc/source/ui/unoobj/afmtuno.cxx
@@ -215,32 +215,30 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno::
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
sal_uInt16 nDummy;
- if (!lcl_FindAutoFormatIndex( *pFormats, aName, nDummy ))
+ if (lcl_FindAutoFormatIndex( *pFormats, aName, nDummy ))
{
- ScAutoFormatData* pNew = new ScAutoFormatData();
- pNew->SetName( aName );
+ throw container::ElementExistException();
+ }
- if (pFormats->insert(pNew))
- {
- //! notify to other objects
- pFormats->Save();
+ ScAutoFormatData* pNew = new ScAutoFormatData();
+ pNew->SetName( aName );
- sal_uInt16 nNewIndex;
- if (lcl_FindAutoFormatIndex( *pFormats, aName, nNewIndex ))
- {
- pFormatObj->InitFormat( nNewIndex ); // can be used now
- bDone = true;
- }
- }
- else
+ if (pFormats->insert(pNew))
+ {
+ //! notify to other objects
+ pFormats->Save();
+
+ sal_uInt16 nNewIndex;
+ if (lcl_FindAutoFormatIndex( *pFormats, aName, nNewIndex ))
{
- OSL_FAIL("AutoFormat could not be inserted");
- throw uno::RuntimeException();
+ pFormatObj->InitFormat( nNewIndex ); // can be used now
+ bDone = true;
}
}
else
{
- throw container::ElementExistException();
+ OSL_FAIL("AutoFormat could not be inserted");
+ throw uno::RuntimeException();
}
}
}
@@ -266,17 +264,15 @@ void SAL_CALL ScAutoFormatsObj::removeByName( const OUString& aName )
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
ScAutoFormat::iterator it = pFormats->find(aName);
- if (it != pFormats->end())
- {
- pFormats->erase(it);
-
- //! notify to other objects
- pFormats->Save(); // save immediately
- }
- else
+ if (it == pFormats->end())
{
throw container::NoSuchElementException();
}
+ pFormats->erase(it);
+
+ //! notify to other objects
+ pFormats->Save(); // save immediately
+
}
// container::XEnumerationAccess
@@ -480,37 +476,35 @@ void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName )
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
sal_uInt16 nDummy;
- if (IsInserted() && nFormatIndex < pFormats->size() &&
- !lcl_FindAutoFormatIndex( *pFormats, aNewName, nDummy ))
+ if (!IsInserted() || nFormatIndex >= pFormats->size() ||
+ lcl_FindAutoFormatIndex( *pFormats, aNewName, nDummy ))
{
- ScAutoFormat::iterator it = pFormats->begin();
- std::advance(it, nFormatIndex);
- ScAutoFormatData *const pData = it->second.get();
- OSL_ENSURE(pData,"AutoFormat data not available");
+ // not inserted or name exists
+ throw uno::RuntimeException();
+ }
- ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
- pNew->SetName( aNewName );
+ ScAutoFormat::iterator it = pFormats->begin();
+ std::advance(it, nFormatIndex);
+ ScAutoFormatData *const pData = it->second.get();
+ OSL_ENSURE(pData,"AutoFormat data not available");
- pFormats->erase(it);
- if (pFormats->insert(pNew))
- {
- it = pFormats->find(pNew);
- ScAutoFormat::iterator itBeg = pFormats->begin();
- nFormatIndex = std::distance(itBeg, it);
+ ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
+ pNew->SetName( aNewName );
- //! notify to other objects
- pFormats->SetSaveLater(true);
- }
- else
- {
- OSL_FAIL("AutoFormat could not be inserted");
- nFormatIndex = 0; //! old index invalid
- }
+ pFormats->erase(it);
+ if (pFormats->insert(pNew))
+ {
+ it = pFormats->find(pNew);
+ ScAutoFormat::iterator itBeg = pFormats->begin();
+ nFormatIndex = std::distance(itBeg, it);
+
+ //! notify to other objects
+ pFormats->SetSaveLater(true);
}
else
{
- // not inserted or name exists
- throw uno::RuntimeException();
+ OSL_FAIL("AutoFormat could not be inserted");
+ nFormatIndex = 0; //! old index invalid
}
}
diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx
index b641142ccba1..e0ea77cbeab0 100644
--- a/sc/source/ui/unoobj/appluno.cxx
+++ b/sc/source/ui/unoobj/appluno.cxx
@@ -579,24 +579,22 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScFunctionListObj::getById( sal_Int
{
SolarMutexGuard aGuard;
const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
- if ( pFuncList )
+ if ( !pFuncList )
+ throw uno::RuntimeException(); // should not happen
+
+ sal_uInt16 nCount = (sal_uInt16)pFuncList->GetCount();
+ for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
{
- sal_uInt16 nCount = (sal_uInt16)pFuncList->GetCount();
- for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
+ const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
+ if ( pDesc && pDesc->nFIndex == nId )
{
- const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
- if ( pDesc && pDesc->nFIndex == nId )
- {
- uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
- lcl_FillSequence( aSeq, *pDesc );
- return aSeq;
- }
+ uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
+ lcl_FillSequence( aSeq, *pDesc );
+ return aSeq;
}
-
- throw lang::IllegalArgumentException(); // not found
}
- else
- throw uno::RuntimeException(); // should not happen
+
+ throw lang::IllegalArgumentException(); // not found
}
// XNameAccess
@@ -605,25 +603,23 @@ uno::Any SAL_CALL ScFunctionListObj::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
- if ( pFuncList )
+ if ( !pFuncList )
+ throw uno::RuntimeException(); // should not happen
+
+ sal_uInt16 nCount = (sal_uInt16)pFuncList->GetCount();
+ for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
{
- sal_uInt16 nCount = (sal_uInt16)pFuncList->GetCount();
- for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
+ const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
+ //! Case-insensitiv ???
+ if ( pDesc && pDesc->pFuncName && aName == *pDesc->pFuncName )
{
- const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
- //! Case-insensitiv ???
- if ( pDesc && pDesc->pFuncName && aName == *pDesc->pFuncName )
- {
- uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
- lcl_FillSequence( aSeq, *pDesc );
- return uno::makeAny(aSeq);
- }
+ uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
+ lcl_FillSequence( aSeq, *pDesc );
+ return uno::makeAny(aSeq);
}
-
- throw container::NoSuchElementException(); // not found
}
- else
- throw uno::RuntimeException(); // should not happen
+
+ throw container::NoSuchElementException(); // not found
}
// XIndexAccess
@@ -642,23 +638,21 @@ uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
- if ( pFuncList )
+ if ( !pFuncList )
+ throw uno::RuntimeException(); // should not happen
+
+ if ( nIndex >= 0 && nIndex < (sal_Int32)pFuncList->GetCount() )
{
- if ( nIndex >= 0 && nIndex < (sal_Int32)pFuncList->GetCount() )
+ const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
+ if ( pDesc )
{
- const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
- if ( pDesc )
- {
- uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
- lcl_FillSequence( aSeq, *pDesc );
- return uno::makeAny(aSeq);
- }
+ uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
+ lcl_FillSequence( aSeq, *pDesc );
+ return uno::makeAny(aSeq);
}
-
- throw lang::IndexOutOfBoundsException(); // illegal index
}
- else
- throw uno::RuntimeException(); // should not happen
+
+ throw lang::IndexOutOfBoundsException(); // illegal index
}
// XEnumerationAccess
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 1abd589b8297..ba3e602c3609 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -2151,57 +2151,56 @@ static void lcl_SetCellProperty( const SfxItemPropertySimpleEntry& rEntry, const
nOldFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang );
sal_Int32 nIntVal = 0;
- if ( rValue >>= nIntVal )
- {
- sal_uLong nNewFormat = (sal_uLong)nIntVal;
- rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
+ if ( !(rValue >>= nIntVal) )
+ throw lang::IllegalArgumentException();
- const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat );
- LanguageType eNewLang =
- pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
- if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW )
- {
- rSet.Put( SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) );
+ sal_uLong nNewFormat = (sal_uLong)nIntVal;
+ rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
- // if only language is changed,
- // don't touch number format attribute
- sal_uLong nNewMod = nNewFormat % SV_COUNTRY_LANGUAGE_OFFSET;
- if ( nNewMod == ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) &&
- nNewMod <= SV_MAX_COUNT_STANDARD_FORMATS )
- {
- rFirstItemId = 0; // don't use ATTR_VALUE_FORMAT value
- }
+ const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat );
+ LanguageType eNewLang =
+ pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
+ if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW )
+ {
+ rSet.Put( SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) );
- rSecondItemId = ATTR_LANGUAGE_FORMAT;
+ // if only language is changed,
+ // don't touch number format attribute
+ sal_uLong nNewMod = nNewFormat % SV_COUNTRY_LANGUAGE_OFFSET;
+ if ( nNewMod == ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) &&
+ nNewMod <= SV_MAX_COUNT_STANDARD_FORMATS )
+ {
+ rFirstItemId = 0; // don't use ATTR_VALUE_FORMAT value
}
+
+ rSecondItemId = ATTR_LANGUAGE_FORMAT;
}
- else
- throw lang::IllegalArgumentException();
+
}
break;
case ATTR_INDENT:
{
sal_Int16 nIntVal = 0;
- if ( rValue >>= nIntVal )
- rSet.Put( SfxUInt16Item( rEntry.nWID, (sal_uInt16)HMMToTwips(nIntVal) ) );
- else
+ if ( !(rValue >>= nIntVal) )
throw lang::IllegalArgumentException();
+
+ rSet.Put( SfxUInt16Item( rEntry.nWID, (sal_uInt16)HMMToTwips(nIntVal) ) );
+
}
break;
case ATTR_ROTATE_VALUE:
{
sal_Int32 nRotVal = 0;
- if ( rValue >>= nRotVal )
- {
- // stored value is always between 0 and 360 deg.
- nRotVal %= 36000;
- if ( nRotVal < 0 )
- nRotVal += 36000;
-
- rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, nRotVal ) );
- }
- else
+ if ( !(rValue >>= nRotVal) )
throw lang::IllegalArgumentException();
+
+ // stored value is always between 0 and 360 deg.
+ nRotVal %= 36000;
+ if ( nRotVal < 0 )
+ nRotVal += 36000;
+
+ rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, nRotVal ) );
+
}
break;
case ATTR_STACKED:
@@ -4306,13 +4305,12 @@ void SAL_CALL ScCellRangesObj::removeRangeAddress( const table::CellRangeAddress
if (aMarkData.GetTableSelect( aRange.aStart.Tab() ))
{
aMarkData.MarkToMulti();
- if (aMarkData.IsAllMarked( aRange ) )
- {
- aMarkData.SetMultiMarkArea( aRange, false );
- lcl_RemoveNamedEntry(m_pImpl->m_aNamedEntries, aRange);
- }
- else
+ if (!aMarkData.IsAllMarked( aRange ) )
throw container::NoSuchElementException();
+
+ aMarkData.SetMultiMarkArea( aRange, false );
+ lcl_RemoveNamedEntry(m_pImpl->m_aNamedEntries, aRange);
+
}
SetNewRanges(aNotSheetRanges);
ScRangeList aNew;
@@ -4574,18 +4572,17 @@ uno::Any SAL_CALL ScCellRangesObj::getByName( const OUString& aName )
ScDocShell* pDocSh = GetDocShell();
const ScRangeList& rRanges = GetRangeList();
ScRange aRange;
- if (lcl_FindRangeOrEntry(m_pImpl->m_aNamedEntries, rRanges,
+ if (!lcl_FindRangeOrEntry(m_pImpl->m_aNamedEntries, rRanges,
pDocSh, aName, aRange))
- {
- uno::Reference<table::XCellRange> xRange;
- if ( aRange.aStart == aRange.aEnd )
- xRange.set(new ScCellObj( pDocSh, aRange.aStart ));
- else
- xRange.set(new ScCellRangeObj( pDocSh, aRange ));
- aRet <<= xRange;
- }
- else
throw container::NoSuchElementException();
+
+ uno::Reference<table::XCellRange> xRange;
+ if ( aRange.aStart == aRange.aEnd )
+ xRange.set(new ScCellObj( pDocSh, aRange.aStart ));
+ else
+ xRange.set(new ScCellRangeObj( pDocSh, aRange ));
+ aRet <<= xRange;
+
return aRet;
}
@@ -4663,10 +4660,11 @@ uno::Any SAL_CALL ScCellRangesObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<table::XCellRange> xRange(GetObjectByIndex_Impl(nIndex));
- if (xRange.is())
- return uno::makeAny(xRange);
- else
+ if (!xRange.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xRange);
+
}
uno::Type SAL_CALL ScCellRangesObj::getElementType()
@@ -5422,14 +5420,13 @@ void SAL_CALL ScCellRangeObj::autoFormat( const OUString& aName )
{
ScAutoFormat* pAutoFormat = ScGlobal::GetOrCreateAutoFormat();
ScAutoFormat::const_iterator it = pAutoFormat->find(aName);
- if (it != pAutoFormat->end())
- {
- ScAutoFormat::const_iterator itBeg = pAutoFormat->begin();
- size_t nIndex = std::distance(itBeg, it);
- pDocSh->GetDocFunc().AutoFormat(aRange, nullptr, nIndex, true);
- }
- else
+ if (it == pAutoFormat->end())
throw lang::IllegalArgumentException();
+
+ ScAutoFormat::const_iterator itBeg = pAutoFormat->begin();
+ size_t nIndex = std::distance(itBeg, it);
+ pDocSh->GetDocFunc().AutoFormat(aRange, nullptr, nIndex, true);
+
}
}
@@ -6178,10 +6175,11 @@ uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursorByRange(
else
{
ScCellTextCursor* pOther = ScCellTextCursor::getImplementation( aTextPosition );
- if(pOther)
- pCursor->SetSelection( pOther->GetSelection() );
- else
+ if(!pOther)
throw uno::RuntimeException();
+
+ pCursor->SetSelection( pOther->GetSelection() );
+
}
return xCursor;
@@ -9108,10 +9106,11 @@ uno::Any SAL_CALL ScCellFormatsObj::getByIndex( sal_Int32 nIndex )
SolarMutexGuard aGuard;
uno::Reference<table::XCellRange> xRange(GetObjectByIndex_Impl(nIndex));
- if (xRange.is())
- return uno::makeAny(xRange);
- else
+ if (!xRange.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xRange);
+
}
uno::Type SAL_CALL ScCellFormatsObj::getElementType()
@@ -9464,10 +9463,11 @@ uno::Any SAL_CALL ScUniqueCellFormatsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
- if(static_cast<sal_uInt32>(nIndex) < aRangeLists.size())
- return uno::makeAny(uno::Reference<sheet::XSheetCellRangeContainer>(new ScCellRangesObj(pDocShell, aRangeLists[nIndex])));
- else
+ if(static_cast<sal_uInt32>(nIndex) >= aRangeLists.size())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(uno::Reference<sheet::XSheetCellRangeContainer>(new ScCellRangesObj(pDocShell, aRangeLists[nIndex])));
+
}
uno::Type SAL_CALL ScUniqueCellFormatsObj::getElementType()
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index dc0c2dfc498e..089ac69d9708 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -2290,13 +2290,12 @@ ScChart2DataProvider::getPropertySetInfo()
void SAL_CALL ScChart2DataProvider::setPropertyValue(
const OUString& rPropertyName, const uno::Any& rValue)
{
- if ( rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS )
- {
- if ( !(rValue >>= m_bIncludeHiddenCells))
- throw lang::IllegalArgumentException();
- }
- else
+ if ( rPropertyName != SC_UNONAME_INCLUDEHIDDENCELLS )
throw beans::UnknownPropertyException();
+
+ if ( !(rValue >>= m_bIncludeHiddenCells))
+ throw lang::IllegalArgumentException();
+
}
uno::Any SAL_CALL ScChart2DataProvider::getPropertyValue(
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index cc38b7059892..027f38fd7f2e 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -321,10 +321,10 @@ uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
- if (xChart.is())
- return uno::makeAny(xChart);
- else
+ if (!xChart.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xChart);
}
uno::Type SAL_CALL ScChartsObj::getElementType()
@@ -343,10 +343,10 @@ uno::Any SAL_CALL ScChartsObj::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
- if (xChart.is())
- return uno::makeAny(xChart);
- else
+ if (!xChart.is())
throw container::NoSuchElementException();
+
+ return uno::makeAny(xChart);
}
uno::Sequence<OUString> SAL_CALL ScChartsObj::getElementNames()
diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index 99916105bf3e..8b70376336af 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -914,20 +914,19 @@ void SAL_CALL ScColorScaleFormatObj::setPropertyValue(
case ColorScaleEntries:
{
uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries;
- if (aValue >>= aEntries)
- {
- if (aEntries.getLength() < 2)
- throw lang::IllegalArgumentException();
+ if (!(aValue >>= aEntries))
+ throw lang::IllegalArgumentException();
- // TODO: we need to make sure that there are enough entries
- size_t n = size_t(aEntries.getLength());
- for (size_t i = 0; i < n; ++i)
- {
- setColorScaleEntry(getCoreObject()->GetEntry(i), aEntries[i]);
- }
- }
- else
+ if (aEntries.getLength() < 2)
throw lang::IllegalArgumentException();
+
+ // TODO: we need to make sure that there are enough entries
+ size_t n = size_t(aEntries.getLength());
+ for (size_t i = 0; i < n; ++i)
+ {
+ setColorScaleEntry(getCoreObject()->GetEntry(i), aEntries[i]);
+ }
+
}
break;
default:
@@ -1231,49 +1230,45 @@ void SAL_CALL ScDataBarFormatObj::setPropertyValue(
case NegativeColor:
{
sal_Int32 nNegativeColor = COL_AUTO;
- if ((aValue >>= nNegativeColor) && getCoreObject()->GetDataBarData()->mbNeg)
- {
- getCoreObject()->GetDataBarData()->mpNegativeColor->SetColor(nNegativeColor);
- }
- else
+ if (!(aValue >>= nNegativeColor) || !getCoreObject()->GetDataBarData()->mbNeg)
throw lang::IllegalArgumentException();
+
+ getCoreObject()->GetDataBarData()->mpNegativeColor->SetColor(nNegativeColor);
+
}
break;
case DataBarEntries:
{
uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries;
- if (aValue >>= aEntries)
- {
- if (aEntries.getLength() != 2)
- throw lang::IllegalArgumentException();
+ if (!(aValue >>= aEntries))
+ throw lang::IllegalArgumentException();
- setDataBarEntry(getCoreObject()->GetDataBarData()->mpLowerLimit.get(),
- aEntries[0]);
- setDataBarEntry(getCoreObject()->GetDataBarData()->mpUpperLimit.get(),
- aEntries[1]);
- }
- else
+ if (aEntries.getLength() != 2)
throw lang::IllegalArgumentException();
+
+ setDataBarEntry(getCoreObject()->GetDataBarData()->mpLowerLimit.get(),
+ aEntries[0]);
+ setDataBarEntry(getCoreObject()->GetDataBarData()->mpUpperLimit.get(),
+ aEntries[1]);
+
}
break;
case MinimumLength:
{
double nLength = 0;
- if ((aValue >>= nLength) && nLength < 100 && nLength >= 0)
- {
- getCoreObject()->GetDataBarData()->mnMinLength = nLength;
- }
- else throw lang::IllegalArgumentException();
+ if (!(aValue >>= nLength) || nLength >= 100 || nLength < 0)
+ throw lang::IllegalArgumentException();
+ getCoreObject()->GetDataBarData()->mnMinLength = nLength;
+
}
break;
case MaximumLength:
{
double nLength = 0;
- if ((aValue >>= nLength) && nLength <= 100 && nLength > 0)
- {
- getCoreObject()->GetDataBarData()->mnMaxLength = nLength;
- }
- else throw lang::IllegalArgumentException();
+ if (!(aValue >>= nLength) || nLength > 100 || nLength <= 0)
+ throw lang::IllegalArgumentException();
+ getCoreObject()->GetDataBarData()->mnMaxLength = nLength;
+
}
break;
}
@@ -1586,18 +1581,17 @@ void SAL_CALL ScIconSetFormatObj::setPropertyValue(
case IconSetEntries:
{
uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries;
- if (aValue >>= aEntries)
+ if (!(aValue >>= aEntries))
+ throw lang::IllegalArgumentException();
+
+ // TODO: we need to check that the number of entries
+ // corresponds to the icon type
+ sal_Int32 nLength = aEntries.getLength();
+ for (size_t i = 0; i < size_t(nLength); ++i)
{
- // TODO: we need to check that the number of entries
- // corresponds to the icon type
- sal_Int32 nLength = aEntries.getLength();
- for (size_t i = 0; i < size_t(nLength); ++i)
- {
- setIconSetEntry(getCoreObject(), aEntries[i], i);
- }
+ setIconSetEntry(getCoreObject(), aEntries[i], i);
}
- else
- throw lang::IllegalArgumentException();
+
}
break;
default:
@@ -1813,12 +1807,11 @@ void SAL_CALL ScCondDateFormatObj::setPropertyValue(
case Date_StyleName:
{
OUString aStyleName;
- if (aValue >>= aStyleName)
- {
- getCoreObject()->SetStyleName(aStyleName);
- }
- else
+ if (!(aValue >>= aStyleName))
throw lang::IllegalArgumentException();
+
+ getCoreObject()->SetStyleName(aStyleName);
+
}
break;
case DateType:
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index d6eb02a1eb4d..3cf9a3261cd9 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -442,13 +442,12 @@ void SAL_CALL ScDataPilotTablesObj::removeByName( const OUString& aName )
{
SolarMutexGuard aGuard;
ScDPObject* pDPObj = lcl_GetDPObject( pDocShell, nTab, aName );
- if (pDPObj && pDocShell)
- {
- ScDBDocFunc aFunc(*pDocShell);
- aFunc.RemovePivotTable(*pDPObj, true, true); // remove - incl. undo etc.
- }
- else
+ if (!pDPObj || !pDocShell)
throw RuntimeException(); // no other exceptions specified
+
+ ScDBDocFunc aFunc(*pDocShell);
+ aFunc.RemovePivotTable(*pDPObj, true, true); // remove - incl. undo etc.
+
}
// XEnumerationAccess
@@ -3379,14 +3378,13 @@ void SAL_CALL ScDataPilotItemObj::setPropertyValue( const OUString& aPropertyNam
else if ( aPropertyName == SC_UNONAME_POS )
{
sal_Int32 nNewPos = 0;
- if ( ( aValue >>= nNewPos ) && nNewPos >= 0 && nNewPos < nCount )
- {
- pDim->SetMemberPosition( sName, nNewPos );
- // get new effective index (depends on sorting mode, which isn't modified)
- bGetNewIndex = true;
- }
- else
+ if ( !( aValue >>= nNewPos ) || nNewPos < 0 || nNewPos >= nCount )
throw IllegalArgumentException();
+
+ pDim->SetMemberPosition( sName, nNewPos );
+ // get new effective index (depends on sorting mode, which isn't modified)
+ bGetNewIndex = true;
+
}
SetDPObject( pDPObj );
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index d3b765a8b78e..646dd5fae664 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -578,36 +578,35 @@ void SAL_CALL ScSubTotalDescriptorBase::addNew(
sal_uInt32 nColCount = aSubTotalColumns.getLength();
- if ( nPos < MAXSUBTOTAL && nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
- {
- aParam.bGroupActive[nPos] = true;
- aParam.nField[nPos] = static_cast<SCCOL>(nGroupColumn);
+ if ( nPos >= MAXSUBTOTAL || nColCount > sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
+ // too many fields / columns
+ throw uno::RuntimeException(); // no other exceptions specified
- delete aParam.pSubTotals[nPos];
- delete aParam.pFunctions[nPos];
+ aParam.bGroupActive[nPos] = true;
+ aParam.nField[nPos] = static_cast<SCCOL>(nGroupColumn);
- SCCOL nCount = static_cast<SCCOL>(nColCount);
- aParam.nSubTotals[nPos] = nCount;
- if (nCount != 0)
- {
- aParam.pSubTotals[nPos] = new SCCOL[nCount];
- aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
+ delete aParam.pSubTotals[nPos];
+ delete aParam.pFunctions[nPos];
- const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
- for (SCCOL i=0; i<nCount; i++)
- {
- aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
- aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc((ScGeneralFunction)pAry[i].Function);
- }
- }
- else
+ SCCOL nCount = static_cast<SCCOL>(nColCount);
+ aParam.nSubTotals[nPos] = nCount;
+ if (nCount != 0)
+ {
+ aParam.pSubTotals[nPos] = new SCCOL[nCount];
+ aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
+
+ const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
+ for (SCCOL i=0; i<nCount; i++)
{
- aParam.pSubTotals[nPos] = nullptr;
- aParam.pFunctions[nPos] = nullptr;
+ aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
+ aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc((ScGeneralFunction)pAry[i].Function);
}
}
- else // too many fields / columns
- throw uno::RuntimeException(); // no other exceptions specified
+ else
+ {
+ aParam.pSubTotals[nPos] = nullptr;
+ aParam.pFunctions[nPos] = nullptr;
+ }
PutData(aParam);
}
@@ -640,10 +639,10 @@ uno::Any SAL_CALL ScSubTotalDescriptorBase::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XSubTotalField> xField(GetObjectByIndex_Impl((sal_uInt16)nIndex));
- if (xField.is())
- return uno::makeAny(xField);
- else
+ if (!xField.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xField);
}
uno::Type SAL_CALL ScSubTotalDescriptorBase::getElementType()
@@ -2243,10 +2242,10 @@ uno::Any SAL_CALL ScDatabaseRangesObj::getByIndex( sal_Int32 nIndex )
throw lang::IndexOutOfBoundsException();
uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByIndex_Impl(static_cast<size_t>(nIndex)));
- if (xRange.is())
- return uno::makeAny(xRange);
- else
+ if (!xRange.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xRange);
}
uno::Type SAL_CALL ScDatabaseRangesObj::getElementType()
@@ -2267,11 +2266,10 @@ uno::Any SAL_CALL ScDatabaseRangesObj::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByName_Impl(aName));
- if (xRange.is())
- return uno::makeAny(xRange);
- else
+ if (!xRange.is())
throw container::NoSuchElementException();
-// return uno::Any();
+
+ return uno::makeAny(xRange);
}
uno::Sequence<OUString> SAL_CALL ScDatabaseRangesObj::getElementNames()
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index c6445c73d0dd..c985cb5b61aa 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1690,44 +1690,43 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
if ( nRenderer < 0 )
{
- if ( nSelRenderer == 0 )
- {
- // getRenderer(0) is used to query the settings, so it must always return something
-
- awt::Size aPageSize;
- if (lcl_renderSelectionToGraphic( bRenderToGraphic, aStatus))
- {
- assert( aMark.IsMarked());
- ScRange aRange;
- aMark.GetMarkArea( aRange );
- tools::Rectangle aMMRect( pDocShell->GetDocument().GetMMRect(
- aRange.aStart.Col(), aRange.aStart.Row(),
- aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab()));
- aPageSize.Width = aMMRect.GetWidth();
- aPageSize.Height = aMMRect.GetHeight();
- }
- else
- {
- SCTAB const nCurTab = 0; //! use current sheet from view?
- ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
- Size aTwips = aDefaultFunc.GetPageSize();
- aPageSize.Width = TwipsToHMM( aTwips.Width());
- aPageSize.Height = TwipsToHMM( aTwips.Height());
- }
+ if ( nSelRenderer != 0 )
+ throw lang::IllegalArgumentException();
- uno::Sequence<beans::PropertyValue> aSequence( comphelper::InitPropertySequence({
- { SC_UNONAME_PAGESIZE, uno::Any(aPageSize) }
- }));
+ // getRenderer(0) is used to query the settings, so it must always return something
- if( ! pPrinterOptions )
- pPrinterOptions = new ScPrintUIOptions;
- else
- pPrinterOptions->SetDefaults();
- pPrinterOptions->appendPrintUIOptions( aSequence );
- return aSequence;
+ awt::Size aPageSize;
+ if (lcl_renderSelectionToGraphic( bRenderToGraphic, aStatus))
+ {
+ assert( aMark.IsMarked());
+ ScRange aRange;
+ aMark.GetMarkArea( aRange );
+ tools::Rectangle aMMRect( pDocShell->GetDocument().GetMMRect(
+ aRange.aStart.Col(), aRange.aStart.Row(),
+ aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab()));
+ aPageSize.Width = aMMRect.GetWidth();
+ aPageSize.Height = aMMRect.GetHeight();
}
else
- throw lang::IllegalArgumentException();
+ {
+ SCTAB const nCurTab = 0; //! use current sheet from view?
+ ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
+ Size aTwips = aDefaultFunc.GetPageSize();
+ aPageSize.Width = TwipsToHMM( aTwips.Width());
+ aPageSize.Height = TwipsToHMM( aTwips.Height());
+ }
+
+ uno::Sequence<beans::PropertyValue> aSequence( comphelper::InitPropertySequence({
+ { SC_UNONAME_PAGESIZE, uno::Any(aPageSize) }
+ }));
+
+ if( ! pPrinterOptions )
+ pPrinterOptions = new ScPrintUIOptions;
+ else
+ pPrinterOptions->SetDefaults();
+ pPrinterOptions->appendPrintUIOptions( aSequence );
+ return aSequence;
+
}
// printer is used as device (just for page layout), draw view is not needed
@@ -3279,10 +3278,10 @@ uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
- if (xPage.is())
- return uno::makeAny(xPage);
- else
+ if (!xPage.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xPage);
}
uno::Type SAL_CALL ScDrawPagesObj::getElementType()
@@ -3462,21 +3461,20 @@ void SAL_CALL ScTableSheetsObj::replaceByName( const OUString& aName, const uno:
if ( pSheetObj && !pSheetObj->GetDocShell() ) // not inserted yet?
{
SCTAB nPosition;
- if ( pDocShell->GetDocument().GetTable( aName, nPosition ) )
- {
- if ( pDocShell->GetDocFunc().DeleteTable( nPosition, true ) )
- {
- // InsertTable can't really go wrong now
- bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aName, true, true );
- if (bDone)
- pSheetObj->InitInsertSheet( pDocShell, nPosition );
- }
- }
- else
+ if ( !pDocShell->GetDocument().GetTable( aName, nPosition ) )
{
// not found
throw container::NoSuchElementException();
}
+
+ if ( pDocShell->GetDocFunc().DeleteTable( nPosition, true ) )
+ {
+ // InsertTable can't really go wrong now
+ bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aName, true, true );
+ if (bDone)
+ pSheetObj->InitInsertSheet( pDocShell, nPosition );
+ }
+
}
else
bIllArg = true;
@@ -3501,10 +3499,9 @@ void SAL_CALL ScTableSheetsObj::removeByName( const OUString& aName )
if (pDocShell)
{
SCTAB nIndex;
- if ( pDocShell->GetDocument().GetTable( aName, nIndex ) )
- bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, true );
- else // not found
- throw container::NoSuchElementException();
+ if ( !pDocShell->GetDocument().GetTable( aName, nIndex ) )
+ throw container::NoSuchElementException(); // not found
+ bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, true );
}
if (!bDone)
@@ -3614,10 +3611,11 @@ uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
- if (xSheet.is())
- return uno::makeAny(xSheet);
- else
+ if (!xSheet.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xSheet);
+
// return uno::Any();
}
@@ -3639,10 +3637,10 @@ uno::Any SAL_CALL ScTableSheetsObj::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
- if (xSheet.is())
- return uno::makeAny(xSheet);
- else
+ if (!xSheet.is())
throw container::NoSuchElementException();
+
+ return uno::makeAny(xSheet);
}
uno::Sequence<OUString> SAL_CALL ScTableSheetsObj::getElementNames()
@@ -3777,10 +3775,11 @@ uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
- if (xColumn.is())
- return uno::makeAny(xColumn);
- else
+ if (!xColumn.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xColumn);
+
}
uno::Type SAL_CALL ScTableColumnsObj::getElementType()
@@ -3799,10 +3798,10 @@ uno::Any SAL_CALL ScTableColumnsObj::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
- if (xColumn.is())
- return uno::makeAny(xColumn);
- else
+ if (!xColumn.is())
throw container::NoSuchElementException();
+
+ return uno::makeAny(xColumn);
}
uno::Sequence<OUString> SAL_CALL ScTableColumnsObj::getElementNames()
@@ -4015,10 +4014,10 @@ uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
- if (xRow.is())
- return uno::makeAny(xRow);
- else
+ if (!xRow.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xRow);
}
uno::Type SAL_CALL ScTableRowsObj::getElementType()
@@ -4326,10 +4325,10 @@ uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
- if (xAnnotation.is())
- return uno::makeAny(xAnnotation);
- else
+ if (!xAnnotation.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xAnnotation);
}
uno::Type SAL_CALL ScAnnotationsObj::getElementType()
@@ -4487,10 +4486,10 @@ uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
- if (xScen.is())
- return uno::makeAny(xScen);
- else
+ if (!xScen.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xScen);
}
uno::Type SAL_CALL ScScenariosObj::getElementType()
@@ -4509,10 +4508,10 @@ uno::Any SAL_CALL ScScenariosObj::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
- if (xScen.is())
- return uno::makeAny(xScen);
- else
+ if (!xScen.is())
throw container::NoSuchElementException();
+
+ return uno::makeAny(xScen);
}
uno::Sequence<OUString> SAL_CALL ScScenariosObj::getElementNames()
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index d87bd6f1aa8d..cd434056ce6d 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -356,10 +356,10 @@ uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
- if (xField.is())
- return uno::makeAny(xField);
- else
+ if (!xField.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xField);
}
uno::Type SAL_CALL ScCellFieldsObj::getElementType()
@@ -512,10 +512,10 @@ uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
- if (xField.is())
- return uno::makeAny(xField);
- else
+ if (!xField.is())
throw lang::IndexOutOfBoundsException();
+
+ return uno::makeAny(xField);
}
uno::Type SAL_CALL ScHeaderFieldsObj::getElementType()
@@ -752,67 +752,65 @@ uno::Any ScEditFieldObj::getPropertyValueURL(const OUString& rName)
void ScEditFieldObj::setPropertyValueFile(const OUString& rName, const uno::Any& rVal)
{
- if (rName == SC_UNONAME_FILEFORM)
+ if (rName != SC_UNONAME_FILEFORM)
+ throw beans::UnknownPropertyException();
+
+ sal_Int16 nIntVal = 0;
+ if (rVal >>= nIntVal)
{
- sal_Int16 nIntVal = 0;
- if (rVal >>= nIntVal)
+ SvxFileFormat eFormat = lcl_UnoToSvxFileFormat(nIntVal);
+ if (mpEditSource)
{
- SvxFileFormat eFormat = lcl_UnoToSvxFileFormat(nIntVal);
- if (mpEditSource)
- {
- ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
- ScUnoEditEngine aTempEngine(pEditEngine);
- SvxFieldData* pField = aTempEngine.FindByPos(
- aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE);
- OSL_ENSURE(pField, "setPropertyValueFile: Field not found");
- if (pField)
- {
- SvxExtFileField* pExtFile = static_cast<SvxExtFileField*>(pField); // local to the ScUnoEditEngine
- pExtFile->SetFormat(eFormat);
- pEditEngine->QuickInsertField(SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection);
- mpEditSource->UpdateData();
- }
- }
- else
+ ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
+ ScUnoEditEngine aTempEngine(pEditEngine);
+ SvxFieldData* pField = aTempEngine.FindByPos(
+ aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE);
+ OSL_ENSURE(pField, "setPropertyValueFile: Field not found");
+ if (pField)
{
- SvxFieldData* pField = getData();
- SvxExtFileField* pExtFile = static_cast<SvxExtFileField*>(pField);
+ SvxExtFileField* pExtFile = static_cast<SvxExtFileField*>(pField); // local to the ScUnoEditEngine
pExtFile->SetFormat(eFormat);
+ pEditEngine->QuickInsertField(SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection);
+ mpEditSource->UpdateData();
}
}
+ else
+ {
+ SvxFieldData* pField = getData();
+ SvxExtFileField* pExtFile = static_cast<SvxExtFileField*>(pField);
+ pExtFile->SetFormat(eFormat);
+ }
}
- else
- throw beans::UnknownPropertyException();
+
}
uno::Any ScEditFieldObj::getPropertyValueFile(const OUString& rName)
{
uno::Any aRet;
- if (rName == SC_UNONAME_FILEFORM)
- {
- SvxFileFormat eFormat = SvxFileFormat::NameAndExt;
- const SvxFieldData* pField = nullptr;
- if (mpEditSource)
- {
- ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
- ScUnoEditEngine aTempEngine(pEditEngine);
- pField = aTempEngine.FindByPos(
- aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE);
- }
- else
- pField = getData();
-
- OSL_ENSURE(pField, "setPropertyValueFile: Field not found");
- if (!pField)
- throw uno::RuntimeException();
+ if (rName != SC_UNONAME_FILEFORM)
+ throw beans::UnknownPropertyException();
- const SvxExtFileField* pExtFile = static_cast<const SvxExtFileField*>(pField);
- eFormat = pExtFile->GetFormat();
- sal_Int16 nIntVal = lcl_SvxToUnoFileFormat(eFormat);
- aRet <<= nIntVal;
+ SvxFileFormat eFormat = SvxFileFormat::NameAndExt;
+ const SvxFieldData* pField = nullptr;
+ if (mpEditSource)
+ {
+ ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
+ ScUnoEditEngine aTempEngine(pEditEngine);
+ pField = aTempEngine.FindByPos(
+ aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE);
}
else
- throw beans::UnknownPropertyException();
+ pField = getData();
+
+ OSL_ENSURE(pField, "setPropertyValueFile: Field not found");
+ if (!pField)
+ throw uno::RuntimeException();
+
+ const SvxExtFileField* pExtFile = static_cast<const SvxExtFileField*>(pField);
+ eFormat = pExtFile->GetFormat();
+ sal_Int16 nIntVal = lcl_SvxToUnoFileFormat(eFormat);
+ aRet <<= nIntVal;
+
return aRet;
}
@@ -1037,14 +1035,13 @@ void ScEditFieldObj::setPropertyValueSheet(const OUString& rName, const uno::Any
SvxTableField* p = static_cast<SvxTableField*>(pField);
- if (rName == SC_UNONAME_TABLEPOS)
- {
- sal_Int32 nTab = rVal.get<sal_Int32>();
- p->SetTab(nTab);
- }
- else
+ if (rName != SC_UNONAME_TABLEPOS)
throw beans::UnknownPropertyException();
+ sal_Int32 nTab = rVal.get<sal_Int32>();
+ p->SetTab(nTab);
+
+
pEditEngine->QuickInsertField(SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection);
mpEditSource->UpdateData();
return;
@@ -1056,14 +1053,11 @@ void ScEditFieldObj::setPropertyValueSheet(const OUString& rName, const uno::Any
throw uno::RuntimeException();
SvxTableField* p = static_cast<SvxTableField*>(pData);
- if (rName == SC_UNONAME_TABLEPOS)
- {
- sal_Int32 nTab = rVal.get<sal_Int32>();
- p->SetTab(nTab);
- }
- else
+ if (rName != SC_UNONAME_TABLEPOS)
throw beans::UnknownPropertyException();
+ sal_Int32 nTab = rVal.get<sal_Int32>();
+ p->SetTab(nTab);
}
ScEditFieldObj::ScEditFieldObj(