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 206 : UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs )
30 : {
31 206 : sal_Int32 nIDs = rIDs.getLength();
32 206 : const sal_Int32* pIDs = rIDs.getConstArray();
33 4448 : for ( sal_Int32 n = 0; n < nIDs; n++ )
34 4242 : maIDs.insert( pIDs[n] );
35 206 : }
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 166436 : bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const
45 : {
46 166436 : if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
47 42591 : nPropId = BASEPROPERTY_FONTDESCRIPTOR;
48 :
49 166436 : return maIDs.find( nPropId ) != maIDs.end();
50 : }
51 :
52 : // ::cppu::IPropertyArrayHelper
53 99247 : sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId )
54 : {
55 99247 : sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId);
56 99247 : bool bValid = ImplHasProperty( id );
57 99247 : if ( bValid )
58 : {
59 99247 : if ( pPropName )
60 16320 : *pPropName = GetPropertyName( id );
61 99247 : if ( pAttributes )
62 49254 : *pAttributes = GetPropertyAttribs( id );
63 : }
64 99247 : return bValid;
65 : }
66 :
67 198 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties()
68 : {
69 : // Sortiert nach Namen...
70 :
71 198 : std::map<sal_Int32, sal_uInt16> aSortedPropsIds;
72 4246 : for( std::set<sal_Int32>::const_iterator it = maIDs.begin(); it != maIDs.end(); ++it)
73 : {
74 4048 : sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >(*it);
75 4048 : aSortedPropsIds[ 1+GetPropertyOrderNr( nId ) ] = nId;
76 :
77 4048 : if ( nId == BASEPROPERTY_FONTDESCRIPTOR )
78 : {
79 : // Einzelproperties...
80 1887 : for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ )
81 1776 : aSortedPropsIds[ 1+GetPropertyOrderNr( i ) ] = i;
82 : }
83 : }
84 :
85 198 : sal_uInt32 nProps = aSortedPropsIds.size(); // koennen jetzt mehr sein
86 198 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps );
87 198 : ::com::sun::star::beans::Property* pProps = aProps.getArray();
88 :
89 198 : std::map<sal_Int32, sal_uInt16>::const_iterator it = aSortedPropsIds.begin();
90 6022 : for ( sal_uInt32 n = 0; n < nProps; n++, ++it )
91 : {
92 5824 : sal_uInt16 nId = it->second;
93 5824 : pProps[n].Name = GetPropertyName( nId );
94 5824 : pProps[n].Handle = nId;
95 5824 : pProps[n].Type = *GetPropertyType( nId );
96 5824 : pProps[n].Attributes = GetPropertyAttribs( nId );
97 : }
98 :
99 198 : 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 7348 : sal_Int32 UnoPropertyArrayHelper::getHandleByName( const OUString & rPropertyName )
123 : {
124 7348 : sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName );
125 7348 : return nId ? nId : (-1);
126 : }
127 :
128 2838 : sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< OUString > & rPropNames )
129 : {
130 2838 : const OUString* pNames = rPropNames.getConstArray();
131 2838 : sal_Int32 nValues = rPropNames.getLength();
132 2838 : sal_Int32 nValidHandles = 0;
133 :
134 70027 : for ( sal_Int32 n = 0; n < nValues; n++ )
135 : {
136 67189 : sal_uInt16 nPropId = GetPropertyId( pNames[n] );
137 67189 : if ( nPropId && ImplHasProperty( nPropId ) )
138 : {
139 67189 : pHandles[n] = nPropId;
140 67189 : nValidHandles++;
141 : }
142 : else
143 : {
144 0 : pHandles[n] = -1;
145 : }
146 : }
147 2838 : return nValidHandles;
148 : }
149 :
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|