1*b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0724fc6SAndrew Rist * distributed with this work for additional information 6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17*b0724fc6SAndrew Rist * specific language governing permissions and limitations 18*b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b0724fc6SAndrew Rist *************************************************************/ 21*b0724fc6SAndrew Rist 22*b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx> 28cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir // ---------------------------------------------------- 31cdf0e10cSrcweir // class UnoPropertyArrayHelper 32cdf0e10cSrcweir // ---------------------------------------------------- 33cdf0e10cSrcweir 34cdf0e10cSrcweir UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs ) 35cdf0e10cSrcweir { 36cdf0e10cSrcweir sal_Int32 nIDs = rIDs.getLength(); 37cdf0e10cSrcweir const sal_Int32* pIDs = rIDs.getConstArray(); 38cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nIDs; n++ ) 39cdf0e10cSrcweir maIDs.Insert( pIDs[n], (void*)1L ); 40cdf0e10cSrcweir } 41cdf0e10cSrcweir 42cdf0e10cSrcweir UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list< sal_uInt16 > &rIDs ) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir std::list< sal_uInt16 >::const_iterator iter; 45cdf0e10cSrcweir for( iter = rIDs.begin(); iter != rIDs.end(); iter++) 46cdf0e10cSrcweir maIDs.Insert( *iter, (void*)1L); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir sal_Bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const 50cdf0e10cSrcweir { 51cdf0e10cSrcweir if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) 52cdf0e10cSrcweir nPropId = BASEPROPERTY_FONTDESCRIPTOR; 53cdf0e10cSrcweir 54cdf0e10cSrcweir return maIDs.Get( nPropId ) ? sal_True : sal_False; 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir // ::cppu::IPropertyArrayHelper 58cdf0e10cSrcweir sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( ::rtl::OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId); 61cdf0e10cSrcweir sal_Bool bValid = ImplHasProperty( id ); 62cdf0e10cSrcweir if ( bValid ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir if ( pPropName ) 65cdf0e10cSrcweir *pPropName = GetPropertyName( id ); 66cdf0e10cSrcweir if ( pAttributes ) 67cdf0e10cSrcweir *pAttributes = GetPropertyAttribs( id ); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir return bValid; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties() 73cdf0e10cSrcweir { 74cdf0e10cSrcweir // Sortiert nach Namen... 75cdf0e10cSrcweir 76cdf0e10cSrcweir Table aSortedPropsIds; 77cdf0e10cSrcweir sal_uInt32 nProps = maIDs.Count(); 78cdf0e10cSrcweir for ( sal_uInt32 s = 0; s < nProps; s++ ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >( 81cdf0e10cSrcweir maIDs.GetObjectKey( s )); 82cdf0e10cSrcweir aSortedPropsIds.Insert( 1+GetPropertyOrderNr( nId ), (void*)(sal_uInt32)nId ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir if ( nId == BASEPROPERTY_FONTDESCRIPTOR ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir // Einzelproperties... 87cdf0e10cSrcweir for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ ) 88cdf0e10cSrcweir aSortedPropsIds.Insert( 1+GetPropertyOrderNr( i ), (void*)(sal_uInt32)i ); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir nProps = aSortedPropsIds.Count(); // koennen jetzt mehr sein 93cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps ); 94cdf0e10cSrcweir ::com::sun::star::beans::Property* pProps = aProps.getArray(); 95cdf0e10cSrcweir 96cdf0e10cSrcweir for ( sal_uInt32 n = 0; n < nProps; n++ ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir sal_uInt16 nId = (sal_uInt16)(sal_uLong)aSortedPropsIds.GetObject( n ); 99cdf0e10cSrcweir pProps[n].Name = GetPropertyName( nId ); 100cdf0e10cSrcweir pProps[n].Handle = nId; 101cdf0e10cSrcweir pProps[n].Type = *GetPropertyType( nId ); 102cdf0e10cSrcweir pProps[n].Attributes = GetPropertyAttribs( nId ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir return aProps; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir ::com::sun::star::beans::Property UnoPropertyArrayHelper::getPropertyByName(const ::rtl::OUString& rPropertyName) throw (::com::sun::star::beans::UnknownPropertyException) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ::com::sun::star::beans::Property aProp; 111cdf0e10cSrcweir sal_uInt16 nId = GetPropertyId( rPropertyName ); 112cdf0e10cSrcweir if ( ImplHasProperty( nId ) ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir aProp.Name = rPropertyName; 115cdf0e10cSrcweir aProp.Handle = -1; 116cdf0e10cSrcweir aProp.Type = *GetPropertyType( nId ); 117cdf0e10cSrcweir aProp.Attributes = GetPropertyAttribs( nId ); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir return aProp; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const ::rtl::OUString& rPropertyName) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir return ImplHasProperty( GetPropertyId( rPropertyName ) ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir sal_Int32 UnoPropertyArrayHelper::getHandleByName( const ::rtl::OUString & rPropertyName ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName ); 131cdf0e10cSrcweir return nId ? nId : (-1); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rPropNames ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir const ::rtl::OUString* pNames = rPropNames.getConstArray(); 137cdf0e10cSrcweir sal_Int32 nValues = rPropNames.getLength(); 138cdf0e10cSrcweir sal_Int32 nValidHandles = 0; 139cdf0e10cSrcweir 140cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nValues; n++ ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir sal_uInt16 nPropId = GetPropertyId( pNames[n] ); 143cdf0e10cSrcweir if ( nPropId && ImplHasProperty( nPropId ) ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir pHandles[n] = nPropId; 146cdf0e10cSrcweir nValidHandles++; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir else 149cdf0e10cSrcweir { 150cdf0e10cSrcweir pHandles[n] = -1; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir return nValidHandles; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir 157