Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <toolkit/helper/property.hxx>
22 : #include <map>
23 :
24 : #include "helper/unopropertyarrayhelper.hxx"
25 :
26 : // class UnoPropertyArrayHelper
27 :
28 :
29 290 : UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs )
30 : {
31 290 : sal_Int32 nIDs = rIDs.getLength();
32 290 : const sal_Int32* pIDs = rIDs.getConstArray();
33 6360 : for ( sal_Int32 n = 0; n < nIDs; n++ )
34 6070 : maIDs.insert( pIDs[n] );
35 290 : }
36 :
37 0 : UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list< sal_uInt16 > &rIDs )
38 : {
39 0 : std::list< sal_uInt16 >::const_iterator iter;
40 0 : for( iter = rIDs.begin(); iter != rIDs.end(); ++iter)
41 0 : maIDs.insert( *iter );
42 0 : }
43 :
44 332982 : bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const
45 : {
46 332982 : if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
47 87317 : nPropId = BASEPROPERTY_FONTDESCRIPTOR;
48 :
49 332982 : return maIDs.find( nPropId ) != maIDs.end() ? sal_True : sal_False;
50 : }
51 :
52 : // ::cppu::IPropertyArrayHelper
53 196764 : sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId )
54 : {
55 196764 : sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId);
56 196764 : bool bValid = ImplHasProperty( id );
57 196764 : if ( bValid )
58 : {
59 196764 : if ( pPropName )
60 33049 : *pPropName = GetPropertyName( id );
61 196764 : if ( pAttributes )
62 99670 : *pAttributes = GetPropertyAttribs( id );
63 : }
64 196764 : return bValid;
65 : }
66 :
67 282 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties()
68 : {
69 : // Sortiert nach Namen...
70 :
71 282 : std::map<sal_Int32, sal_uInt16> aSortedPropsIds;
72 6158 : for( std::set<sal_Int32>::const_iterator it = maIDs.begin(); it != maIDs.end(); ++it)
73 : {
74 5876 : sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >(*it);
75 5876 : aSortedPropsIds[ 1+GetPropertyOrderNr( nId ) ] = nId;
76 :
77 5876 : if ( nId == BASEPROPERTY_FONTDESCRIPTOR )
78 : {
79 : // Einzelproperties...
80 2754 : for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ )
81 2592 : aSortedPropsIds[ 1+GetPropertyOrderNr( i ) ] = i;
82 : }
83 : }
84 :
85 282 : sal_uInt32 nProps = aSortedPropsIds.size(); // koennen jetzt mehr sein
86 282 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps );
87 282 : ::com::sun::star::beans::Property* pProps = aProps.getArray();
88 :
89 282 : std::map<sal_Int32, sal_uInt16>::const_iterator it = aSortedPropsIds.begin();
90 8750 : for ( sal_uInt32 n = 0; n < nProps; n++, ++it )
91 : {
92 8468 : sal_uInt16 nId = it->second;
93 8468 : pProps[n].Name = GetPropertyName( nId );
94 8468 : pProps[n].Handle = nId;
95 8468 : pProps[n].Type = *GetPropertyType( nId );
96 8468 : pProps[n].Attributes = GetPropertyAttribs( nId );
97 : }
98 :
99 282 : return aProps;
100 : }
101 :
102 0 : ::com::sun::star::beans::Property UnoPropertyArrayHelper::getPropertyByName(const OUString& rPropertyName) throw (::com::sun::star::beans::UnknownPropertyException)
103 : {
104 0 : ::com::sun::star::beans::Property aProp;
105 0 : sal_uInt16 nId = GetPropertyId( rPropertyName );
106 0 : if ( ImplHasProperty( nId ) )
107 : {
108 0 : aProp.Name = rPropertyName;
109 0 : aProp.Handle = -1;
110 0 : aProp.Type = *GetPropertyType( nId );
111 0 : aProp.Attributes = GetPropertyAttribs( nId );
112 : }
113 :
114 0 : return aProp;
115 : }
116 :
117 0 : sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const OUString& rPropertyName)
118 : {
119 0 : return ImplHasProperty( GetPropertyId( rPropertyName ) );
120 : }
121 :
122 14534 : sal_Int32 UnoPropertyArrayHelper::getHandleByName( const OUString & rPropertyName )
123 : {
124 14534 : sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName );
125 14534 : return nId ? nId : (-1);
126 : }
127 :
128 5726 : sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< OUString > & rPropNames )
129 : {
130 5726 : const OUString* pNames = rPropNames.getConstArray();
131 5726 : sal_Int32 nValues = rPropNames.getLength();
132 5726 : sal_Int32 nValidHandles = 0;
133 :
134 141944 : for ( sal_Int32 n = 0; n < nValues; n++ )
135 : {
136 136218 : sal_uInt16 nPropId = GetPropertyId( pNames[n] );
137 136218 : if ( nPropId && ImplHasProperty( nPropId ) )
138 : {
139 136218 : pHandles[n] = nPropId;
140 136218 : nValidHandles++;
141 : }
142 : else
143 : {
144 0 : pHandles[n] = -1;
145 : }
146 : }
147 5726 : return nValidHandles;
148 : }
149 :
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|