Kaydet (Commit) fe6311fc authored tarafından Laurent Godard's avatar Laurent Godard Kaydeden (comit) Markus Mohrhard

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/10214Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 713735fc
...@@ -3576,6 +3576,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/style,\ ...@@ -3576,6 +3576,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/style,\
XStyle \ XStyle \
XStyleFamiliesSupplier \ XStyleFamiliesSupplier \
XStyleLoader \ XStyleLoader \
XStyleLoader2 \
XStyleSupplier \ XStyleSupplier \
)) ))
$(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/svg,\ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/svg,\
......
/* -*- 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: */
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <rsc/rscsfx.hxx> #include <rsc/rscsfx.hxx>
#include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/style/XStyle.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/lang/XServiceInfo.hpp>
#include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/container/XIndexReplace.hpp> #include <com/sun/star/container/XIndexReplace.hpp>
...@@ -36,9 +36,12 @@ ...@@ -36,9 +36,12 @@
#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp>
#include <cppuhelper/implbase4.hxx> #include <cppuhelper/implbase4.hxx>
#include <cppuhelper/implbase7.hxx> #include <cppuhelper/implbase7.hxx>
#include <com/sun/star/lang/XComponent.hpp>
class SfxStyleSheetBase; class SfxStyleSheetBase;
class ScDocShell; class ScDocShell;
class SfxObjectShell;
class ScStyleFamilyObj; class ScStyleFamilyObj;
class ScStyleObj; class ScStyleObj;
...@@ -46,7 +49,7 @@ class ScStyleObj; ...@@ -46,7 +49,7 @@ class ScStyleObj;
class ScStyleFamiliesObj : public ::cppu::WeakImplHelper4< class ScStyleFamiliesObj : public ::cppu::WeakImplHelper4<
::com::sun::star::container::XIndexAccess, ::com::sun::star::container::XIndexAccess,
::com::sun::star::container::XNameAccess, ::com::sun::star::container::XNameAccess,
::com::sun::star::style::XStyleLoader, ::com::sun::star::style::XStyleLoader2,
::com::sun::star::lang::XServiceInfo >, ::com::sun::star::lang::XServiceInfo >,
public SfxListener public SfxListener
{ {
...@@ -94,6 +97,12 @@ public: ...@@ -94,6 +97,12 @@ public:
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL
getStyleLoaderOptions() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; 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 // XServiceInfo
virtual OUString SAL_CALL getImplementationName() virtual OUString SAL_CALL getImplementationName()
throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
...@@ -101,6 +110,12 @@ public: ...@@ -101,6 +110,12 @@ public:
throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; 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< class ScStyleFamilyObj : public ::cppu::WeakImplHelper4<
......
...@@ -535,6 +535,52 @@ void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const OUString& aURL, ...@@ -535,6 +535,52 @@ void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const OUString& aURL,
ScDocumentLoader aLoader( aURL, aFilter, aFiltOpt ); ScDocumentLoader aLoader( aURL, aFilter, aFiltOpt );
ScDocShell* pSource = aLoader.GetDocShell(); 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 ) if ( pSource && pDocShell )
{ {
// collect options // collect options
...@@ -563,26 +609,6 @@ void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const OUString& aURL, ...@@ -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) : ScStyleFamilyObj::ScStyleFamilyObj(ScDocShell* pDocSh, SfxStyleFamily eFam) :
pDocShell( pDocSh ), pDocShell( pDocSh ),
eFamily( eFam ) eFamily( eFam )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment