offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/style/XStyleLoader2.idl | 56 +++++++++++++++++++++++ sc/inc/styleuno.hxx | 19 +++++++- sc/source/ui/unoobj/styleuno.cxx | 66 +++++++++++++++++++--------- 4 files changed, 120 insertions(+), 22 deletions(-)
New commits: commit fe6311fce7e7305b2f6c87f57407ea13e2625c53 Author: Laurent Godard <lgodard.li...@laposte.net> Date: Thu Jul 10 10:35:12 2014 +0200 add UNO API loadStylesFromDocument avoid opening again a document that is already available apply to calc - refactoring ScStyleFamiliesObj::loadStylesFromURL Change-Id: I6b26c91265dcafa73b472bc68ee684ba0733b0ac Reviewed-on: https://gerrit.libreoffice.org/10214 Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrh...@googlemail.com> diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 8a07f15..9c56e9f 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -3576,6 +3576,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/style,\ XStyle \ XStyleFamiliesSupplier \ XStyleLoader \ + XStyleLoader2 \ XStyleSupplier \ )) $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/svg,\ diff --git a/offapi/com/sun/star/style/XStyleLoader2.idl b/offapi/com/sun/star/style/XStyleLoader2.idl new file mode 100644 index 0000000..f55760a --- /dev/null +++ b/offapi/com/sun/star/style/XStyleLoader2.idl @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __com_sun_star_style_XStyleLoader2_idl__ +#define __com_sun_star_style_XStyleLoader2_idl__ + +#include <com/sun/star/beans/PropertyValue.idl> +#include <com/sun/star/io/IOException.idl> +#include <com/sun/star/lang/XComponent.idl> + + +module com { module sun { module star { module style { + +/** extends XStyleLoader interface to import styles from an already opened calc or writer component. + + @see com::sun::star::style::XStyleLoader + */ +interface XStyleLoader2: com::sun::star::style::XStyleLoader +{ + /** loads styles from a given document + <p> + @param aSourceComponent + a valid XComponent reference to source doc (calc or writer) + @param aOptions + Specifies which of the Style families the method should load. + The <code>sequence<PropertyValue></code> has the following, optional items: + <ul> + <li> boolean LoadCellStyles </li> + <li> boolean LoadTextStyles </li> + <li> boolean LoadFrameStyles </li> + <li> boolean LoadPageStyles </li> + <li> boolean LoadNumberingStyles </li> + <li> boolean OverwriteStyles</li> + </ul> + If <var>OverwriteStyles</var> is `TRUE`, then all styles + will be loaded. Otherwise, only styles which are not already + defined in this document are loaded.</p> + <p>As the default, all supported style families are loaded and existing styles are overwritten.</p> + */ + void loadStylesFromDocument( [in] com::sun::star::lang::XComponent aSourceComponent, + [in] sequence<com::sun::star::beans::PropertyValue> aOptions ) + raises( com::sun::star::io::IOException ); +}; + + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/styleuno.hxx b/sc/inc/styleuno.hxx index 3f18636..da1e82b 100644 --- a/sc/inc/styleuno.hxx +++ b/sc/inc/styleuno.hxx @@ -25,7 +25,7 @@ #include <rsc/rscsfx.hxx> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/style/XStyle.hpp> -#include <com/sun/star/style/XStyleLoader.hpp> +#include <com/sun/star/style/XStyleLoader2.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XIndexReplace.hpp> @@ -36,9 +36,12 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <cppuhelper/implbase4.hxx> #include <cppuhelper/implbase7.hxx> +#include <com/sun/star/lang/XComponent.hpp> + class SfxStyleSheetBase; class ScDocShell; +class SfxObjectShell; class ScStyleFamilyObj; class ScStyleObj; @@ -46,7 +49,7 @@ class ScStyleObj; class ScStyleFamiliesObj : public ::cppu::WeakImplHelper4< ::com::sun::star::container::XIndexAccess, ::com::sun::star::container::XNameAccess, - ::com::sun::star::style::XStyleLoader, + ::com::sun::star::style::XStyleLoader2, ::com::sun::star::lang::XServiceInfo >, public SfxListener { @@ -94,6 +97,12 @@ public: virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getStyleLoaderOptions() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + //XStyleLoader2 + virtual void SAL_CALL loadStylesFromDocument( const ::com::sun::star::uno::Reference <::com::sun::star::lang::XComponent> & aSourceComponent, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& aOptions ) + throw(::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; @@ -101,6 +110,12 @@ public: throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +private: + void loadStylesFromDocShell( ScDocShell* pSource, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue>& aOptions ) + throw(::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException, std::exception); }; class ScStyleFamilyObj : public ::cppu::WeakImplHelper4< diff --git a/sc/source/ui/unoobj/styleuno.cxx b/sc/source/ui/unoobj/styleuno.cxx index a694d1c..666e145 100644 --- a/sc/source/ui/unoobj/styleuno.cxx +++ b/sc/source/ui/unoobj/styleuno.cxx @@ -535,6 +535,52 @@ void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const OUString& aURL, ScDocumentLoader aLoader( aURL, aFilter, aFiltOpt ); ScDocShell* pSource = aLoader.GetDocShell(); + + loadStylesFromDocShell(pSource, aOptions); +} + +uno::Sequence<beans::PropertyValue> SAL_CALL ScStyleFamiliesObj::getStyleLoaderOptions() + throw(uno::RuntimeException, std::exception) +{ + // return defaults for options (?) + + uno::Sequence<beans::PropertyValue> aSequence(3); + beans::PropertyValue* pArray = aSequence.getArray(); + + pArray[0].Name = OUString(SC_UNONAME_OVERWSTL ); + ScUnoHelpFunctions::SetBoolInAny( pArray[0].Value, true ); + + pArray[1].Name = OUString(SC_UNONAME_LOADCELL ); + ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, true ); + + pArray[2].Name = OUString(SC_UNONAME_LOADPAGE ); + ScUnoHelpFunctions::SetBoolInAny( pArray[2].Value, true ); + + return aSequence; +} + +// style::XStyleLoader2 + +void SAL_CALL ScStyleFamiliesObj::loadStylesFromDocument( const uno::Reference < lang::XComponent > & aSourceComponent, + const uno::Sequence<beans::PropertyValue>& aOptions ) + throw(io::IOException, uno::RuntimeException, std::exception) +{ + // Source document docShell + if ( !aSourceComponent.is() ) + throw uno::RuntimeException(); + + ScDocShell* pDocShellSrc = dynamic_cast<ScDocShell*> (SfxObjectShell::GetShellFromComponent(aSourceComponent)); + + loadStylesFromDocShell(pDocShellSrc, aOptions); +} + +// private + +void ScStyleFamiliesObj::loadStylesFromDocShell( ScDocShell* pSource, + const uno::Sequence<beans::PropertyValue>& aOptions ) + throw(io::IOException, uno::RuntimeException, std::exception) +{ + if ( pSource && pDocShell ) { // collect options @@ -563,26 +609,6 @@ void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const OUString& aURL, } } -uno::Sequence<beans::PropertyValue> SAL_CALL ScStyleFamiliesObj::getStyleLoaderOptions() - throw(uno::RuntimeException, std::exception) -{ - // return defaults for options (?) - - uno::Sequence<beans::PropertyValue> aSequence(3); - beans::PropertyValue* pArray = aSequence.getArray(); - - pArray[0].Name = OUString(SC_UNONAME_OVERWSTL ); - ScUnoHelpFunctions::SetBoolInAny( pArray[0].Value, true ); - - pArray[1].Name = OUString(SC_UNONAME_LOADCELL ); - ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, true ); - - pArray[2].Name = OUString(SC_UNONAME_LOADPAGE ); - ScUnoHelpFunctions::SetBoolInAny( pArray[2].Value, true ); - - return aSequence; -} - ScStyleFamilyObj::ScStyleFamilyObj(ScDocShell* pDocSh, SfxStyleFamily eFam) : pDocShell( pDocSh ), eFamily( eFam ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits