bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / style / MultiPropertySetHelper.cxx
blob7636278ebef604e9f46740616f0b9ad832d3198e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <MultiPropertySetHelper.hxx>
22 #include <com/sun/star/beans/XPropertySetInfo.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/XMultiPropertySet.hpp>
26 #include <sal/log.hxx>
28 using ::com::sun::star::beans::XMultiPropertySet;
29 using ::com::sun::star::beans::XPropertySet;
30 using ::com::sun::star::beans::XPropertySetInfo;
31 using ::com::sun::star::uno::Any;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::UNO_QUERY;
36 MultiPropertySetHelper::MultiPropertySetHelper(
37 const char** pNames ) :
38 nLength( 0 ),
39 pValues( nullptr )
41 // first count the elements
42 for( const char** pPtr = pNames; *pPtr != nullptr; pPtr++ )
43 nLength++;
45 // allocate array and create strings
46 pPropertyNames.reset( new OUString[nLength] );
47 for( sal_Int16 i = 0; i < nLength; i++ )
48 pPropertyNames[i] = OUString::createFromAscii( pNames[i] );
52 MultiPropertySetHelper::~MultiPropertySetHelper()
54 pValues = nullptr; // memory 'owned' by aValues
58 void MultiPropertySetHelper::hasProperties(
59 const Reference<XPropertySetInfo> & rInfo )
61 SAL_WARN_IF( !rInfo.is(), "xmloff", "I'd really like an XPropertySetInfo here." );
63 // allocate sequence index
64 if ( !pSequenceIndex )
65 pSequenceIndex.reset( new sal_Int16[nLength] );
67 // construct pSequenceIndex
68 sal_Int16 nNumberOfProperties = 0;
69 sal_Int16 i;
71 for( i = 0; i < nLength; i++ )
73 // ask for property
74 bool bHasProperty =
75 rInfo->hasPropertyByName( pPropertyNames[i] );
77 // set index and increment (if appropriate)
78 pSequenceIndex[i]= bHasProperty ? nNumberOfProperties : -1;
79 if ( bHasProperty )
80 nNumberOfProperties++;
83 // construct property sequence from index array
84 if ( aPropertySequence.getLength() != nNumberOfProperties )
85 aPropertySequence.realloc( nNumberOfProperties );
86 OUString* pPropertySequence = aPropertySequence.getArray();
87 for( i = 0; i < nLength; i ++ )
89 sal_Int16 nIndex = pSequenceIndex[i];
90 if ( nIndex != -1 )
91 pPropertySequence[nIndex] = pPropertyNames[i];
95 bool MultiPropertySetHelper::checkedProperties()
97 return (nullptr != pSequenceIndex);
101 void MultiPropertySetHelper::getValues(
102 const Reference<XMultiPropertySet> & rMultiPropertySet )
104 SAL_WARN_IF( !rMultiPropertySet.is(), "xmloff", "We need an XMultiPropertySet." );
106 aValues = rMultiPropertySet->getPropertyValues( aPropertySequence );
107 pValues = aValues.getConstArray();
110 void MultiPropertySetHelper::getValues(
111 const Reference<XPropertySet> & rPropertySet )
113 SAL_WARN_IF( !rPropertySet.is(), "xmloff", "We need an XPropertySet." );
115 // re-alloc aValues (if necessary) and fill with values from XPropertySet
116 sal_Int16 nSupportedPropertiesCount =
117 static_cast<sal_Int16>(aPropertySequence.getLength());
118 if ( aValues.getLength() != nSupportedPropertiesCount )
119 aValues.realloc( nSupportedPropertiesCount );
120 Any* pMutableArray = aValues.getArray();
121 for( sal_Int16 i = 0; i < nSupportedPropertiesCount; i++ )
123 pMutableArray[i] = rPropertySet->getPropertyValue(
124 pPropertyNames[ pSequenceIndex[ i ] ] );
127 // re-establish pValues pointer
128 pValues = aValues.getConstArray();
132 const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex,
133 const Reference< XPropertySet> & rPropSet,
134 bool bTryMulti )
136 if( !pValues )
138 if( bTryMulti )
140 Reference < XMultiPropertySet > xMultiPropSet( rPropSet,
141 UNO_QUERY );
142 if( xMultiPropSet.is() )
143 getValues( xMultiPropSet );
144 else
145 getValues( rPropSet );
147 else
149 getValues( rPropSet );
153 return getValue( nIndex );
156 const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex,
157 const Reference< XMultiPropertySet> & rMultiPropSet )
159 if( !pValues )
160 getValues( rMultiPropSet );
162 return getValue( nIndex );
165 // inline methods defined in header:
166 // inline Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex )
167 // inline sal_Bool MultiPropertySetHelper::hasProperty( sal_Int16 nValueNo )
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */