22#include <com/sun/star/beans/NamedValue.hpp>
23#include <com/sun/star/lang/XInitialization.hpp>
27#include <osl/diagnose.h>
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::XInterface;
38 using ::com::sun::star::uno::UNO_QUERY;
39 using ::com::sun::star::uno::Any;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::beans::NamedValue;
42 using ::com::sun::star::beans::PropertyValue;
43 using ::com::sun::star::lang::XInitialization;
49 struct IsSpecialArgument
51 static bool isSpecialArgumentName( std::u16string_view _rValueName )
53 return _rValueName ==
u"EmbeddedObject" || _rValueName ==
u"EmbeddedScriptSupport" || _rValueName ==
u"DocumentRecoverySupport";
56 bool operator()(
const Any& _rArgument )
const
58 NamedValue aNamedValue;
59 if ( ( _rArgument >>= aNamedValue ) && isSpecialArgumentName( aNamedValue.Name ) )
61 PropertyValue aPropertyValue;
62 return ( _rArgument >>= aPropertyValue ) && isSpecialArgumentName( aPropertyValue.Name );
69 const css::uno::Sequence<css::uno::Any> & _rArguments,
70 std::function<css::uno::Reference<css::uno::XInterface>(
SfxModelFlags)> creationFunc)
73 const bool bEmbeddedObject = aArgs.
getOrDefault(
"EmbeddedObject",
false );
74 const bool bScriptSupport = aArgs.
getOrDefault(
"EmbeddedScriptSupport",
true );
75 const bool bDocRecoverySupport = aArgs.
getOrDefault(
"DocumentRecoverySupport",
true );
82 Reference< XInterface > xInstance( creationFunc(nCreationFlags ) );
86 Sequence< Any > aStrippedArguments( _rArguments.getLength() );
87 Any* pStrippedArgs = aStrippedArguments.getArray();
88 Any* pStrippedArgsEnd = ::std::remove_copy_if(
94 aStrippedArguments.realloc( pStrippedArgsEnd - pStrippedArgs );
96 if ( aStrippedArguments.hasElements() )
98 Reference< XInitialization > xModelInit( xInstance, UNO_QUERY );
99 OSL_ENSURE( xModelInit.is(),
"SfxModelFactory::createInstanceWithArguments: no XInitialization!" );
100 if ( xModelInit.is() )
101 xModelInit->initialize( aStrippedArguments );
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
css::uno::Reference< css::uno::XInterface > createSfxModelInstance(const css::uno::Sequence< css::uno::Any > &_rArguments, std::function< css::uno::Reference< css::uno::XInterface >(SfxModelFlags)> creationFunc)
Intended to be called from UNO constructor functions This evaluates certain creation arguments (passe...
@ DISABLE_DOCUMENT_RECOVERY
@ DISABLE_EMBEDDED_SCRIPTS