offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/sheet/XSpreadsheets2.idl | 75 +++++++++++++++++++++++++++ sc/inc/docuno.hxx | 13 ++++ sc/source/ui/unoobj/docuno.cxx | 59 +++++++++++++++++---- sc/xml/ScTableSheetsObj.xml | 1 5 files changed, 137 insertions(+), 12 deletions(-)
New commits: commit ba897375db27a2b74ead5251516824572260b029 Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Wed Nov 23 15:27:51 2011 -0500 Let's throw out-of-bound exception on out-of-bound destination position. diff --git a/offapi/com/sun/star/sheet/XSpreadsheets2.idl b/offapi/com/sun/star/sheet/XSpreadsheets2.idl index c4f8af1..c3635b9 100644 --- a/offapi/com/sun/star/sheet/XSpreadsheets2.idl +++ b/offapi/com/sun/star/sheet/XSpreadsheets2.idl @@ -27,7 +27,7 @@ #include <com/sun/star/sheet/XSpreadsheets.idl> #include <com/sun/star/sheet/XSpreadsheetDocument.idl> #include <com/sun/star/lang/IllegalArgumentException.idl> -#include <com/sun/star/uno/RuntimeException.idl> +#include <com/sun/star/lang/IndexOutOfBoundsException.idl> //============================================================================= @@ -64,7 +64,7 @@ interface XSpreadsheets2: com::sun::star::sheet::XSpreadsheets [in] string srcName, [in] long nDestPosition) raises (com::sun::star::lang::IllegalArgumentException, - com::sun::star::uno::RuntimeException); + com::sun::star::lang::IndexOutOfBoundsException); }; //============================================================================= diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index 1ca0d71..35296da 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -406,7 +406,9 @@ public: ::com::sun::star::sheet::XSpreadsheetDocument > & xDocSrc, const rtl::OUString& srcName, const sal_Int32 nDestPosition) - throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::uno::RuntimeException); // XCellRangesAccess diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 95632e6..3bc1018 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -2632,7 +2632,7 @@ void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName ) sal_Int32 ScTableSheetsObj::importSheet( const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc, const rtl::OUString& srcName, const sal_Int32 nDestPosition ) - throw( lang::IllegalArgumentException, uno::RuntimeException ) + throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException ) { //pDocShell is the destination ScDocument* pDocDest = pDocShell->GetDocument(); @@ -2655,11 +2655,11 @@ sal_Int32 ScTableSheetsObj::importSheet( SCTAB nCount = pDocDest->GetTableCount(); nIndexDest = static_cast<SCTAB>(nDestPosition); if ( nIndexDest > nCount ) - nIndexDest = nCount; + throw lang::IndexOutOfBoundsException(); // control nDestPosition > 0 - if ( nIndexDest < 0) - nIndexDest = 0; + if (nIndexDest < 0) + throw lang::IndexOutOfBoundsException(); // Transfert Tab bool bInsertNew = true; commit 2ee55872ebc5aeb71041c3267d9b3baa9607b85b Author: Laurent Godard <lgodard.li...@laposte.net> Date: Mon Nov 21 17:32:13 2011 +0100 importSheet from an external provided document define a new interface XSpreadsheets2 clean some String in docuno.cxx while i'm at it. diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 4328206..f63ddd3 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -3458,6 +3458,7 @@ $(eval $(call gb_UnoApiTarget_add_idlfiles,offapi,offapi/com/sun/star/sheet,\ XSpreadsheetDocument \ XSpreadsheetView \ XSpreadsheets \ + XSpreadsheets2 \ XSubTotalCalculatable \ XSubTotalDescriptor \ XSubTotalField \ diff --git a/offapi/com/sun/star/sheet/XSpreadsheets2.idl b/offapi/com/sun/star/sheet/XSpreadsheets2.idl new file mode 100644 index 0000000..c4f8af1 --- /dev/null +++ b/offapi/com/sun/star/sheet/XSpreadsheets2.idl @@ -0,0 +1,75 @@ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * + * Author(s): Laurent Godard <lgodard.li...@laposte.net> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef __com_sun_star_table_XSpreadsheets2_idl__ +#define __com_sun_star_table_XSpreadsheets2_idl__ + +#include <com/sun/star/sheet/XSpreadsheets.idl> +#include <com/sun/star/sheet/XSpreadsheetDocument.idl> +#include <com/sun/star/lang/IllegalArgumentException.idl> +#include <com/sun/star/uno/RuntimeException.idl> + +//============================================================================= + +module com { module sun { module star { module sheet { + +//============================================================================= + +/** extends XSpreadsheets interface to import external sheets. + + @see com::sun::star::sheet::Spreadsheets + */ +interface XSpreadsheets2: com::sun::star::sheet::XSpreadsheets +{ + /** copies a sheet from a source document. + + @param srcDoc + a valid XSpreadsheetDocument reference to source doc + + @param srcName + the source sheet name. + + @param nDestPosition + the destination sheet position. + + @returns the position of the imported sheet or -1 if not imported + + @throws ::com::sun::star::lang::IllegalArgumentException + @throws ::com::sun::star::uno::RuntimeException + + @since LibreOffice 3.5 + */ + long importSheet( + [in] com::sun::star::sheet::XSpreadsheetDocument srcDoc, + [in] string srcName, + [in] long nDestPosition) + raises (com::sun::star::lang::IllegalArgumentException, + com::sun::star::uno::RuntimeException); +}; + +//============================================================================= + +}; }; }; }; + +#endif + diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index 5c5ad86..1ca0d71 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -44,6 +44,7 @@ #include <com/sun/star/sheet/XScenarios.hpp> #include <com/sun/star/sheet/XConsolidatable.hpp> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets2.hpp> #include <com/sun/star/sheet/XDocumentAuditing.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/util/XProtectable.hpp> @@ -371,7 +372,7 @@ public: class ScTableSheetsObj : public cppu::WeakImplHelper5< - com::sun::star::sheet::XSpreadsheets, + com::sun::star::sheet::XSpreadsheets2, com::sun::star::sheet::XCellRangesAccess, com::sun::star::container::XEnumerationAccess, com::sun::star::container::XIndexAccess, @@ -399,6 +400,14 @@ public: const ::rtl::OUString& aCopy, sal_Int16 nDestination ) throw(::com::sun::star::uno::RuntimeException); + // XSpreadsheets2 + virtual sal_Int32 SAL_CALL importSheet( + const ::com::sun::star::uno::Reference < + ::com::sun::star::sheet::XSpreadsheetDocument > & xDocSrc, + const rtl::OUString& srcName, + const sal_Int32 nDestPosition) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + // XCellRangesAccess virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 46f94f8..95632e6 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -2433,8 +2433,7 @@ ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const rtl::OUString& aNa if (pDocShell) { SCTAB nIndex; - String aString(aName); - if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) ) return new ScTableSheetObj( pDocShell, nIndex ); } return NULL; @@ -2462,9 +2461,8 @@ void SAL_CALL ScTableSheetsObj::moveByName( const rtl::OUString& aName, sal_Int1 sal_Bool bDone = false; if (pDocShell) { - String aNamStr(aName); SCTAB nSource; - if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nSource ) ) bDone = pDocShell->MoveTable( nSource, nDestination, false, sal_True ); } if (!bDone) @@ -2479,10 +2477,9 @@ void SAL_CALL ScTableSheetsObj::copyByName( const rtl::OUString& aName, sal_Bool bDone = false; if (pDocShell) { - String aNamStr(aName); String aNewStr(aCopy); SCTAB nSource; - if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nSource ) ) { bDone = pDocShell->MoveTable( nSource, nDestination, sal_True, sal_True ); if (bDone) @@ -2572,14 +2569,14 @@ void SAL_CALL ScTableSheetsObj::replaceByName( const rtl::OUString& aName, const ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface ); if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt? { - String aNamStr(aName); SCTAB nPosition; - if ( pDocShell->GetDocument()->GetTable( aNamStr, nPosition ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nPosition ) ) { ScDocFunc aFunc(*pDocShell); if ( aFunc.DeleteTable( nPosition, sal_True, sal_True ) ) { // InsertTable kann jetzt eigentlich nicht schiefgehen... + String aNamStr(aName); bDone = aFunc.InsertTable( nPosition, aNamStr, sal_True, sal_True ); if (bDone) pSheetObj->InitInsertSheet( pDocShell, nPosition ); @@ -2616,8 +2613,7 @@ void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName ) if (pDocShell) { SCTAB nIndex; - String aString(aName); - if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) ) { ScDocFunc aFunc(*pDocShell); bDone = aFunc.DeleteTable( nIndex, sal_True, sal_True ); @@ -2633,6 +2629,47 @@ void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName ) throw uno::RuntimeException(); // NoSuchElementException is handled above } +sal_Int32 ScTableSheetsObj::importSheet( + const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc, + const rtl::OUString& srcName, const sal_Int32 nDestPosition ) + throw( lang::IllegalArgumentException, uno::RuntimeException ) +{ + //pDocShell is the destination + ScDocument* pDocDest = pDocShell->GetDocument(); + + // Source document docShell + if ( !xDocSrc.is() ) + throw uno::RuntimeException(); + ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc); + ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject()); + + SCTAB nIndexDest; + nIndexDest = -1; + + // SourceSheet Position and does srcName exists ? + SCTAB nIndexSrc; + if ( !pDocShellSrc->GetDocument()->GetTable( srcName, nIndexSrc ) ) + throw lang::IllegalArgumentException(); + + // control nDestPosition < maxtab + SCTAB nCount = pDocDest->GetTableCount(); + nIndexDest = static_cast<SCTAB>(nDestPosition); + if ( nIndexDest > nCount ) + nIndexDest = nCount; + + // control nDestPosition > 0 + if ( nIndexDest < 0) + nIndexDest = 0; + + // Transfert Tab + bool bInsertNew = true; + bool bNotifyAndPaint = true; + pDocShell->TransferTab( + *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint ); + + return nIndexDest; +} + // XCellRangesAccess uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet ) @@ -2772,7 +2809,7 @@ sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const rtl::OUString& aName ) if (pDocShell) { SCTAB nIndex; - if ( pDocShell->GetDocument()->GetTable( String(aName), nIndex ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) ) return sal_True; } return false; diff --git a/sc/xml/ScTableSheetsObj.xml b/sc/xml/ScTableSheetsObj.xml index e17cbb0..2a7d8dd 100644 --- a/sc/xml/ScTableSheetsObj.xml +++ b/sc/xml/ScTableSheetsObj.xml @@ -216,6 +216,7 @@ <type>com.sun.star.sheet.XSpreadsheet</type> <type>com.sun.star.sheet.XSpreadsheetDocument</type> <type>com.sun.star.sheet.XSpreadsheets</type> + <type>com.sun.star.sheet.XSpreadsheets2</type> <type>com.sun.star.sheet.XSubTotalCalculatable</type> <type>com.sun.star.sheet.XSubTotalDescriptor</type> <type>com.sun.star.sheet.XSubTotalField</type> _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits