1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <toolkit/helper/property.hxx>
24 #include "helper/unopropertyarrayhelper.hxx"
26 // class UnoPropertyArrayHelper
29 UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence
<sal_Int32
>& rIDs
)
31 sal_Int32 nIDs
= rIDs
.getLength();
32 const sal_Int32
* pIDs
= rIDs
.getConstArray();
33 for ( sal_Int32 n
= 0; n
< nIDs
; n
++ )
34 maIDs
.insert( pIDs
[n
] );
37 UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list
< sal_uInt16
> &rIDs
)
39 std::list
< sal_uInt16
>::const_iterator iter
;
40 for( iter
= rIDs
.begin(); iter
!= rIDs
.end(); ++iter
)
41 maIDs
.insert( *iter
);
44 bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId
) const
46 if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
47 nPropId
= BASEPROPERTY_FONTDESCRIPTOR
;
49 return maIDs
.find( nPropId
) != maIDs
.end();
52 // ::cppu::IPropertyArrayHelper
53 sal_Bool
UnoPropertyArrayHelper::fillPropertyMembersByHandle( OUString
* pPropName
, sal_Int16
* pAttributes
, sal_Int32 nPropId
)
55 sal_uInt16 id
= sal::static_int_cast
< sal_uInt16
>(nPropId
);
56 bool bValid
= ImplHasProperty( id
);
60 *pPropName
= GetPropertyName( id
);
62 *pAttributes
= GetPropertyAttribs( id
);
67 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
> UnoPropertyArrayHelper::getProperties()
69 // Sortiert nach Namen...
71 std::map
<sal_Int32
, sal_uInt16
> aSortedPropsIds
;
72 for( std::set
<sal_Int32
>::const_iterator it
= maIDs
.begin(); it
!= maIDs
.end(); ++it
)
74 sal_uInt16 nId
= sal::static_int_cast
< sal_uInt16
>(*it
);
75 aSortedPropsIds
[ 1+GetPropertyOrderNr( nId
) ] = nId
;
77 if ( nId
== BASEPROPERTY_FONTDESCRIPTOR
)
79 // Einzelproperties...
80 for ( sal_uInt16 i
= BASEPROPERTY_FONTDESCRIPTORPART_START
; i
<= BASEPROPERTY_FONTDESCRIPTORPART_END
; i
++ )
81 aSortedPropsIds
[ 1+GetPropertyOrderNr( i
) ] = i
;
85 sal_uInt32 nProps
= aSortedPropsIds
.size(); // koennen jetzt mehr sein
86 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
> aProps( nProps
);
87 ::com::sun::star::beans::Property
* pProps
= aProps
.getArray();
89 std::map
<sal_Int32
, sal_uInt16
>::const_iterator it
= aSortedPropsIds
.begin();
90 for ( sal_uInt32 n
= 0; n
< nProps
; n
++, ++it
)
92 sal_uInt16 nId
= it
->second
;
93 pProps
[n
].Name
= GetPropertyName( nId
);
94 pProps
[n
].Handle
= nId
;
95 pProps
[n
].Type
= *GetPropertyType( nId
);
96 pProps
[n
].Attributes
= GetPropertyAttribs( nId
);
102 ::com::sun::star::beans::Property
UnoPropertyArrayHelper::getPropertyByName(const OUString
& rPropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
)
104 ::com::sun::star::beans::Property aProp
;
105 sal_uInt16 nId
= GetPropertyId( rPropertyName
);
106 if ( ImplHasProperty( nId
) )
108 aProp
.Name
= rPropertyName
;
110 aProp
.Type
= *GetPropertyType( nId
);
111 aProp
.Attributes
= GetPropertyAttribs( nId
);
117 sal_Bool
UnoPropertyArrayHelper::hasPropertyByName(const OUString
& rPropertyName
)
119 return ImplHasProperty( GetPropertyId( rPropertyName
) );
122 sal_Int32
UnoPropertyArrayHelper::getHandleByName( const OUString
& rPropertyName
)
124 sal_Int32 nId
= (sal_Int32
) GetPropertyId( rPropertyName
);
125 return nId
? nId
: (-1);
128 sal_Int32
UnoPropertyArrayHelper::fillHandles( sal_Int32
* pHandles
, const ::com::sun::star::uno::Sequence
< OUString
> & rPropNames
)
130 const OUString
* pNames
= rPropNames
.getConstArray();
131 sal_Int32 nValues
= rPropNames
.getLength();
132 sal_Int32 nValidHandles
= 0;
134 for ( sal_Int32 n
= 0; n
< nValues
; n
++ )
136 sal_uInt16 nPropId
= GetPropertyId( pNames
[n
] );
137 if ( nPropId
&& ImplHasProperty( nPropId
) )
139 pHandles
[n
] = nPropId
;
147 return nValidHandles
;
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */