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