1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_toolkit.hxx" 30 31 #include <toolkit/helper/unopropertyarrayhelper.hxx> 32 #include <toolkit/helper/property.hxx> 33 34 // ---------------------------------------------------- 35 // class UnoPropertyArrayHelper 36 // ---------------------------------------------------- 37 38 UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs ) 39 { 40 sal_Int32 nIDs = rIDs.getLength(); 41 const sal_Int32* pIDs = rIDs.getConstArray(); 42 for ( sal_Int32 n = 0; n < nIDs; n++ ) 43 maIDs.Insert( pIDs[n], (void*)1L ); 44 } 45 46 UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list< sal_uInt16 > &rIDs ) 47 { 48 std::list< sal_uInt16 >::const_iterator iter; 49 for( iter = rIDs.begin(); iter != rIDs.end(); iter++) 50 maIDs.Insert( *iter, (void*)1L); 51 } 52 53 sal_Bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const 54 { 55 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) 56 nPropId = BASEPROPERTY_FONTDESCRIPTOR; 57 58 return maIDs.Get( nPropId ) ? sal_True : sal_False; 59 } 60 61 // ::cppu::IPropertyArrayHelper 62 sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( ::rtl::OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId ) 63 { 64 sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId); 65 sal_Bool bValid = ImplHasProperty( id ); 66 if ( bValid ) 67 { 68 if ( pPropName ) 69 *pPropName = GetPropertyName( id ); 70 if ( pAttributes ) 71 *pAttributes = GetPropertyAttribs( id ); 72 } 73 return bValid; 74 } 75 76 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties() 77 { 78 // Sortiert nach Namen... 79 80 Table aSortedPropsIds; 81 sal_uInt32 nProps = maIDs.Count(); 82 for ( sal_uInt32 s = 0; s < nProps; s++ ) 83 { 84 sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >( 85 maIDs.GetObjectKey( s )); 86 aSortedPropsIds.Insert( 1+GetPropertyOrderNr( nId ), (void*)(sal_uInt32)nId ); 87 88 if ( nId == BASEPROPERTY_FONTDESCRIPTOR ) 89 { 90 // Einzelproperties... 91 for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ ) 92 aSortedPropsIds.Insert( 1+GetPropertyOrderNr( i ), (void*)(sal_uInt32)i ); 93 } 94 } 95 96 nProps = aSortedPropsIds.Count(); // koennen jetzt mehr sein 97 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps ); 98 ::com::sun::star::beans::Property* pProps = aProps.getArray(); 99 100 for ( sal_uInt32 n = 0; n < nProps; n++ ) 101 { 102 sal_uInt16 nId = (sal_uInt16)(sal_uLong)aSortedPropsIds.GetObject( n ); 103 pProps[n].Name = GetPropertyName( nId ); 104 pProps[n].Handle = nId; 105 pProps[n].Type = *GetPropertyType( nId ); 106 pProps[n].Attributes = GetPropertyAttribs( nId ); 107 } 108 109 return aProps; 110 } 111 112 ::com::sun::star::beans::Property UnoPropertyArrayHelper::getPropertyByName(const ::rtl::OUString& rPropertyName) throw (::com::sun::star::beans::UnknownPropertyException) 113 { 114 ::com::sun::star::beans::Property aProp; 115 sal_uInt16 nId = GetPropertyId( rPropertyName ); 116 if ( ImplHasProperty( nId ) ) 117 { 118 aProp.Name = rPropertyName; 119 aProp.Handle = -1; 120 aProp.Type = *GetPropertyType( nId ); 121 aProp.Attributes = GetPropertyAttribs( nId ); 122 } 123 124 return aProp; 125 } 126 127 sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const ::rtl::OUString& rPropertyName) 128 { 129 return ImplHasProperty( GetPropertyId( rPropertyName ) ); 130 } 131 132 sal_Int32 UnoPropertyArrayHelper::getHandleByName( const ::rtl::OUString & rPropertyName ) 133 { 134 sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName ); 135 return nId ? nId : (-1); 136 } 137 138 sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rPropNames ) 139 { 140 const ::rtl::OUString* pNames = rPropNames.getConstArray(); 141 sal_Int32 nValues = rPropNames.getLength(); 142 sal_Int32 nValidHandles = 0; 143 144 for ( sal_Int32 n = 0; n < nValues; n++ ) 145 { 146 sal_uInt16 nPropId = GetPropertyId( pNames[n] ); 147 if ( nPropId && ImplHasProperty( nPropId ) ) 148 { 149 pHandles[n] = nPropId; 150 nValidHandles++; 151 } 152 else 153 { 154 pHandles[n] = -1; 155 } 156 } 157 return nValidHandles; 158 } 159 160 161