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