23#include <com/sun/star/frame/XModel.hpp>
24#include <com/sun/star/lang/XServiceName.hpp>
25#include <com/sun/star/lang/XMultiServiceFactory.hpp>
26#include <com/sun/star/beans/NamedValue.hpp>
27#include <com/sun/star/beans/XPropertyState.hpp>
28#include <com/sun/star/beans/XPropertySetOption.hpp>
29#include <com/sun/star/beans/XMultiPropertySet.hpp>
36#include <sfx2/sfxsids.hrc>
41using ::com::sun::star::uno::Any;
42using ::com::sun::star::uno::Reference;
43using ::com::sun::star::uno::Sequence;
44using ::com::sun::star::uno::Exception;
45using ::com::sun::star::uno::UNO_QUERY;
46using ::com::sun::star::uno::UNO_QUERY_THROW;
47using ::com::sun::star::uno::XInterface;
48using ::com::sun::star::beans::XPropertySet;
49using ::com::sun::star::beans::XPropertyState;
50using ::com::sun::star::lang::XServiceName;
51using ::com::sun::star::lang::XMultiServiceFactory;
60 Reference< XServiceName > xServiceName( xInt, UNO_QUERY );
61 if( xServiceName.is() )
62 aService = xServiceName->getServiceName();
68 Reference< XMultiServiceFactory >
xFactory;
75 const Reference< XMultiServiceFactory >& xFactory,
const OUString& rServiceName )
77 Reference< XInterface > xInt;
82 xInt =
xFactory->createInstance( rServiceName );
86 OSL_FAIL(
"ScfApiHelper::CreateInstance - cannot create instance" );
99 return CreateInstance( ::comphelper::getProcessServiceFactory(), rServiceName );
105 uno::Sequence< beans::NamedValue > aEncryptionData;
107 if ( pEncryptionDataItem )
108 pEncryptionDataItem->
GetValue() >>= aEncryptionData;
113 aPassword = pPasswordItem->
GetValue();
115 bool bIsDefaultPassword =
false;
118 ::comphelper::DocPasswordRequestType::MS, pDefaultPasswords, &bIsDefaultPassword );
123 if( !bIsDefaultPassword && aEncryptionData.hasElements() )
126 return aEncryptionData;
133 Reference<beans::XPropertySetOption> xPropSetOpt(
mxPropSet, UNO_QUERY);
134 if (xPropSetOpt.is())
136 xPropSetOpt->enableChangeListenerNotification(
true);
143 Reference<beans::XPropertySetOption> xPropSetOpt(
mxPropSet, UNO_QUERY);
144 if (xPropSetOpt.is())
147 xPropSetOpt->enableChangeListenerNotification(
false);
159 bool bHasProp =
false;
162 Reference< XPropertyState > xPropState(
mxPropSet, UNO_QUERY_THROW );
163 bHasProp = xPropState->getPropertyState( rPropName ) == css::beans::PropertyState_DIRECT_VALUE;
173 bool bHasValue =
false;
178 rValue =
mxPropSet->getPropertyValue( rPropName );
203 sal_Int32 nApiColor = 0;
213 OSL_ENSURE(
mxMultiPropSet.is(),
"ScfPropertySet::GetProperties - multi property set not available" );
220 sal_Int32 nLen = rPropNames.getLength();
221 rValues.realloc( nLen );
222 std::transform(rPropNames.begin(), rPropNames.end(), rValues.getArray(),
223 [
this](
const OUString& rPropName) ->
Any { return mxPropSet->getPropertyValue(rPropName); });
238 mxPropSet->setPropertyValue( rPropName, rValue );
242 SAL_WARN(
"sc",
"ScfPropertySet::SetAnyProperty - cannot set property \"" + rPropName +
"\"");
248 OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
"ScfPropertySet::SetProperties - length of sequences different" );
257 OSL_FAIL(
"ScfPropertySet::SetProperties - multi property set not available" );
258 const OUString* pPropName = rPropNames.getConstArray();
259 const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
260 const Any* pValue = rValues.getConstArray();
261 for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
262 mxPropSet->setPropertyValue( *pPropName, *pValue );
267 OSL_FAIL(
"ScfPropertySet::SetAnyProperty - cannot set multiple properties" );
274 OSL_ENSURE( ppcPropNames,
"ScfPropSetHelper::ScfPropSetHelper - no strings found" );
277 typedef ::std::pair< OUString, size_t > IndexedOUString;
278 std::vector<IndexedOUString> aPropNameVec;
279 for(
size_t nVecIdx = 0; *ppcPropNames; ++ppcPropNames, ++nVecIdx )
281 OUString
aPropName = OUString::createFromAscii( *ppcPropNames );
282 aPropNameVec.emplace_back(
aPropName, nVecIdx );
286 ::std::sort( aPropNameVec.begin(), aPropNameVec.end() );
289 size_t nSize = aPropNameVec.size();
290 maNameSeq.realloc(
static_cast< sal_Int32
>( nSize ) );
292 maValueSeq.realloc(
static_cast< sal_Int32
>( nSize ) );
296 sal_Int32 nSeqIdx = 0;
322 sal_Int32 nApiColor(0);
362 OSL_ENSURE(
mnNextIdx <
maNameOrder.size(),
"ScfPropSetHelper::GetNextAny - sequence overflow" );
const OUString & GetValue() const
static bool GetBoolFromAny(const css::uno::Any &aAny)
static OUString GetServiceName(const css::uno::Reference< css::uno::XInterface > &xInt)
Returns the service name provided via the XServiceName interface, or an empty string on error.
static css::uno::Reference< css::lang::XMultiServiceFactory > GetServiceFactory(const SfxObjectShell *pShell)
Returns the multi service factory from a document shell.
static css::uno::Sequence< css::beans::NamedValue > QueryEncryptionDataForMedium(SfxMedium &rMedium, ::comphelper::IDocPasswordVerifier &rVerifier, const ::std::vector< OUString > *pDefaultPasswords)
Opens a password dialog and returns the encryption data.
static css::uno::Reference< css::uno::XInterface > CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory > &xFactory, const OUString &rServiceName)
Creates an instance from the passed service name, using the passed service factory.
css::uno::Sequence< css::uno::Any > maValueSeq
Sequence of property names.
css::uno::Sequence< OUString > maNameSeq
size_t mnNextIdx
Maps initial order to alphabetical order.
void WriteValue(const Type &rValue)
Writes the next value to the value sequence.
ScfPropSetHelper(const char *const *ppcPropNames)
void ReadValue(Type &rValue)
Reads the next value from the value sequence.
ScfInt32Vec maNameOrder
Sequence of property values.
void ReadFromPropertySet(const ScfPropertySet &rPropSet)
Reads all values from the passed property set.
void WriteToPropertySet(ScfPropertySet &rPropSet) const
Writes all values to the passed property set.
void InitializeWrite()
Must be called before reading or storing property values in the helper.
css::uno::Any * GetNextAny()
Returns a pointer to the next Any to be written to.
A wrapper for a UNO property set.
css::uno::Reference< css::beans::XPropertySet > mxPropSet
void GetProperties(css::uno::Sequence< css::uno::Any > &rValues, const css::uno::Sequence< OUString > &rPropNames) const
Gets the specified properties from the property set.
void Set(css::uno::Reference< css::beans::XPropertySet > const &xPropSet)
Sets the passed UNO property set and releases the old UNO property set.
bool GetBoolProperty(const OUString &rPropName) const
Gets the specified Boolean property from the property set.
bool GetProperty(Type &rValue, const OUString &rPropName) const
Gets the specified property from the property set.
css::uno::Reference< css::beans::XMultiPropertySet > mxMultiPropSet
The mandatory property set interface.
OUString GetServiceName() const
Returns the service name provided via the XServiceName interface, or an empty string on error.
bool GetAnyProperty(css::uno::Any &rValue, const OUString &rPropName) const
Gets the specified property from the property set.
OUString GetStringProperty(const OUString &rPropName) const
Gets the specified Boolean property from the property set.
bool GetColorProperty(Color &rColor, const OUString &rPropName) const
Gets the specified color property from the property set.
bool HasProperty(const OUString &rPropName) const
Returns true, if the property set contains the specified property.
void SetProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
void SetAnyProperty(const OUString &rPropName, const css::uno::Any &rValue)
Puts the passed Any into the property set.
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemSet & GetItemSet() const
const OUString & GetOrigURL() const
css::uno::Reference< css::task::XInteractionHandler > GetInteractionHandler(bool bGetAlways=false)
css::uno::Reference< css::frame::XModel3 > GetModel() const
const css::uno::Any & GetValue() const
static css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(IDocPasswordVerifier &rVerifier, const css::uno::Sequence< css::beans::NamedValue > &rMediaEncData, const OUString &rMediaPassword, const css::uno::Reference< css::task::XInteractionHandler > &rxInteractHandler, const OUString &rDocumentUrl, DocPasswordRequestType eRequestType, const ::std::vector< OUString > *pDefaultPasswords=nullptr, bool *pbIsDefaultPassword=nullptr)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)