Update ooo320-m1
[ooovba.git] / toolkit / source / helper / unopropertyarrayhelper.cxx
blob638117f172dcbbd15c16ee64e77c65fc8a0a3ff7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unopropertyarrayhelper.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
34 #include <toolkit/helper/unopropertyarrayhelper.hxx>
35 #include <toolkit/helper/property.hxx>
37 // ----------------------------------------------------
38 // class UnoPropertyArrayHelper
39 // ----------------------------------------------------
41 UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs )
43 sal_Int32 nIDs = rIDs.getLength();
44 const sal_Int32* pIDs = rIDs.getConstArray();
45 for ( sal_Int32 n = 0; n < nIDs; n++ )
46 maIDs.Insert( pIDs[n], (void*)1L );
49 UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list< sal_uInt16 > &rIDs )
51 std::list< sal_uInt16 >::const_iterator iter;
52 for( iter = rIDs.begin(); iter != rIDs.end(); iter++)
53 maIDs.Insert( *iter, (void*)1L);
56 sal_Bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const
58 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
59 nPropId = BASEPROPERTY_FONTDESCRIPTOR;
61 return maIDs.Get( nPropId ) ? sal_True : sal_False;
64 // ::cppu::IPropertyArrayHelper
65 sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( ::rtl::OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId )
67 sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId);
68 sal_Bool bValid = ImplHasProperty( id );
69 if ( bValid )
71 if ( pPropName )
72 *pPropName = GetPropertyName( id );
73 if ( pAttributes )
74 *pAttributes = GetPropertyAttribs( id );
76 return bValid;
79 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties()
81 // Sortiert nach Namen...
83 Table aSortedPropsIds;
84 sal_uInt32 nProps = maIDs.Count();
85 for ( sal_uInt32 s = 0; s < nProps; s++ )
87 sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >(
88 maIDs.GetObjectKey( s ));
89 aSortedPropsIds.Insert( 1+GetPropertyOrderNr( nId ), (void*)(sal_uInt32)nId );
91 if ( nId == BASEPROPERTY_FONTDESCRIPTOR )
93 // Einzelproperties...
94 for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ )
95 aSortedPropsIds.Insert( 1+GetPropertyOrderNr( i ), (void*)(sal_uInt32)i );
99 nProps = aSortedPropsIds.Count(); // koennen jetzt mehr sein
100 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps );
101 ::com::sun::star::beans::Property* pProps = aProps.getArray();
103 for ( sal_uInt32 n = 0; n < nProps; n++ )
105 sal_uInt16 nId = (sal_uInt16)(sal_uIntPtr)aSortedPropsIds.GetObject( n );
106 pProps[n].Name = GetPropertyName( nId );
107 pProps[n].Handle = nId;
108 pProps[n].Type = *GetPropertyType( nId );
109 pProps[n].Attributes = GetPropertyAttribs( nId );
112 return aProps;
115 ::com::sun::star::beans::Property UnoPropertyArrayHelper::getPropertyByName(const ::rtl::OUString& rPropertyName) throw (::com::sun::star::beans::UnknownPropertyException)
117 ::com::sun::star::beans::Property aProp;
118 sal_uInt16 nId = GetPropertyId( rPropertyName );
119 if ( ImplHasProperty( nId ) )
121 aProp.Name = rPropertyName;
122 aProp.Handle = -1;
123 aProp.Type = *GetPropertyType( nId );
124 aProp.Attributes = GetPropertyAttribs( nId );
127 return aProp;
130 sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const ::rtl::OUString& rPropertyName)
132 return ImplHasProperty( GetPropertyId( rPropertyName ) );
135 sal_Int32 UnoPropertyArrayHelper::getHandleByName( const ::rtl::OUString & rPropertyName )
137 sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName );
138 return nId ? nId : (-1);
141 sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rPropNames )
143 const ::rtl::OUString* pNames = rPropNames.getConstArray();
144 sal_Int32 nValues = rPropNames.getLength();
145 sal_Int32 nValidHandles = 0;
147 for ( sal_Int32 n = 0; n < nValues; n++ )
149 sal_uInt16 nPropId = GetPropertyId( pNames[n] );
150 if ( nPropId && ImplHasProperty( nPropId ) )
152 pHandles[n] = nPropId;
153 nValidHandles++;
155 else
157 pHandles[n] = -1;
160 return nValidHandles;