/src/libreoffice/toolkit/source/helper/unopropertyarrayhelper.cxx
Line | Count | Source |
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 <helper/property.hxx> |
22 | | #include <map> |
23 | | |
24 | | #include <helper/unopropertyarrayhelper.hxx> |
25 | | |
26 | | |
27 | | |
28 | | UnoPropertyArrayHelper::UnoPropertyArrayHelper( const css::uno::Sequence<sal_Int32>& rIDs ) |
29 | 1 | { |
30 | 1 | for ( const sal_Int32 nID : rIDs ) |
31 | 9 | maIDs.insert( nID ); |
32 | 1 | } |
33 | | |
34 | | UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::vector< sal_uInt16 > &rIDs ) |
35 | 0 | { |
36 | 0 | for (const auto& rId : rIDs) |
37 | 0 | maIDs.insert( rId ); |
38 | 0 | } |
39 | | |
40 | | bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const |
41 | 0 | { |
42 | 0 | if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) |
43 | 0 | nPropId = BASEPROPERTY_FONTDESCRIPTOR; |
44 | |
|
45 | 0 | return maIDs.find( nPropId ) != maIDs.end(); |
46 | 0 | } |
47 | | |
48 | | // ::cppu::IPropertyArrayHelper |
49 | | sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId ) |
50 | 0 | { |
51 | 0 | sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId); |
52 | 0 | bool bValid = ImplHasProperty( id ); |
53 | 0 | if ( bValid ) |
54 | 0 | { |
55 | 0 | if ( pPropName ) |
56 | 0 | *pPropName = GetPropertyName( id ); |
57 | 0 | if ( pAttributes ) |
58 | 0 | *pAttributes = GetPropertyAttribs( id ); |
59 | 0 | } |
60 | 0 | return bValid; |
61 | 0 | } |
62 | | |
63 | | css::uno::Sequence< css::beans::Property > UnoPropertyArrayHelper::getProperties() |
64 | 1 | { |
65 | | // Sort by names ... |
66 | | |
67 | 1 | std::map<OUString, sal_uInt16> aSortedPropsIds; |
68 | 1 | for (const auto& rId : maIDs) |
69 | 9 | { |
70 | 9 | sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >(rId); |
71 | 9 | aSortedPropsIds.emplace(GetPropertyName( nId ), nId); |
72 | | |
73 | 9 | if ( nId == BASEPROPERTY_FONTDESCRIPTOR ) |
74 | 0 | { |
75 | | // single properties ... |
76 | 0 | for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ ) |
77 | 0 | aSortedPropsIds.emplace(GetPropertyName( i ), i); |
78 | 0 | } |
79 | 9 | } |
80 | | |
81 | 1 | sal_uInt32 nProps = aSortedPropsIds.size(); // could be more now |
82 | 1 | css::uno::Sequence< css::beans::Property> aProps( nProps ); |
83 | 1 | css::beans::Property* pProps = aProps.getArray(); |
84 | | |
85 | 1 | sal_uInt32 n = 0; |
86 | 1 | for ( const auto& rPropIds : aSortedPropsIds ) |
87 | 9 | { |
88 | 9 | sal_uInt16 nId = rPropIds.second; |
89 | 9 | pProps[n].Name = rPropIds.first; |
90 | 9 | pProps[n].Handle = nId; |
91 | 9 | pProps[n].Type = *GetPropertyType( nId ); |
92 | 9 | pProps[n].Attributes = GetPropertyAttribs( nId ); |
93 | 9 | ++n; |
94 | 9 | } |
95 | | |
96 | 1 | return aProps; |
97 | 1 | } |
98 | | |
99 | | css::beans::Property UnoPropertyArrayHelper::getPropertyByName(const OUString& rPropertyName) |
100 | 0 | { |
101 | 0 | css::beans::Property aProp; |
102 | 0 | sal_uInt16 nId = GetPropertyId( rPropertyName ); |
103 | 0 | if ( ImplHasProperty( nId ) ) |
104 | 0 | { |
105 | 0 | aProp.Name = rPropertyName; |
106 | 0 | aProp.Handle = -1; |
107 | 0 | aProp.Type = *GetPropertyType( nId ); |
108 | 0 | aProp.Attributes = GetPropertyAttribs( nId ); |
109 | 0 | } |
110 | |
|
111 | 0 | return aProp; |
112 | 0 | } |
113 | | |
114 | | sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const OUString& rPropertyName) |
115 | 0 | { |
116 | 0 | return ImplHasProperty( GetPropertyId( rPropertyName ) ); |
117 | 0 | } |
118 | | |
119 | | sal_Int32 UnoPropertyArrayHelper::getHandleByName( const OUString & rPropertyName ) |
120 | 0 | { |
121 | 0 | sal_Int32 nId = static_cast<sal_Int32>(GetPropertyId( rPropertyName )); |
122 | 0 | return nId ? nId : -1; |
123 | 0 | } |
124 | | |
125 | | sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const css::uno::Sequence< OUString > & rPropNames ) |
126 | 0 | { |
127 | 0 | const OUString* pNames = rPropNames.getConstArray(); |
128 | 0 | sal_Int32 nValues = rPropNames.getLength(); |
129 | 0 | sal_Int32 nValidHandles = 0; |
130 | |
|
131 | 0 | for ( sal_Int32 n = 0; n < nValues; n++ ) |
132 | 0 | { |
133 | 0 | sal_uInt16 nPropId = GetPropertyId( pNames[n] ); |
134 | 0 | if ( nPropId && ImplHasProperty( nPropId ) ) |
135 | 0 | { |
136 | 0 | pHandles[n] = nPropId; |
137 | 0 | nValidHandles++; |
138 | 0 | } |
139 | 0 | else |
140 | 0 | { |
141 | 0 | pHandles[n] = -1; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | return nValidHandles; |
145 | 0 | } |
146 | | |
147 | | |
148 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |