LibreOffice Module unotools (master) 1
accessiblerelationsethelper.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#include <sal/config.h>
21
22#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23#include <o3tl/safeint.hxx>
26
27using namespace ::utl;
28using namespace ::com::sun::star;
29using namespace ::com::sun::star::accessibility;
30
31namespace
32{
33 AccessibleRelation lcl_getRelationByType( std::vector<AccessibleRelation>& raRelations, sal_Int16 aRelationType )
34 {
35 for (const auto& aRelation: raRelations)
36 {
37 if (aRelation.RelationType == aRelationType)
38 return aRelation;
39 }
40 return AccessibleRelation();
41 }
42}
43//===== internal ============================================================
44
45AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
46{
47}
48
49AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
50 : cppu::WeakImplHelper<XAccessibleRelationSet>(rHelper),
52{
53}
54
56{
57}
58
59//===== XAccessibleRelationSet ==============================================
60
66sal_Int32 SAL_CALL
68{
69 std::scoped_lock aGuard (maMutex);
70
71 return maRelations.size();
72}
73
87 AccessibleRelation SAL_CALL
89{
90 std::scoped_lock aGuard (maMutex);
91
92 if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maRelations.size()))
93 throw lang::IndexOutOfBoundsException();
94
95 return maRelations[nIndex];
96}
97
110sal_Bool SAL_CALL
112{
113 std::scoped_lock aGuard (maMutex);
114
115 AccessibleRelation defaultRelation; // default is INVALID
116 AccessibleRelation relationByType = lcl_getRelationByType(maRelations, aRelationType);
117 return relationByType.RelationType != defaultRelation.RelationType;
118}
119
131AccessibleRelation SAL_CALL
133{
134 std::scoped_lock aGuard (maMutex);
135
136 return lcl_getRelationByType(maRelations, aRelationType);
137}
138
139void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
140{
141 std::scoped_lock aGuard (maMutex);
142
143 for (auto& aRelation: maRelations)
144 {
145 if (aRelation.RelationType == rRelation.RelationType)
146 {
147 aRelation.TargetSet = comphelper::concatSequences(aRelation.TargetSet, rRelation.TargetSet);
148 return;
149 }
150 }
151 maRelations.push_back(rRelation);
152}
153
154//===== XTypeProvider =======================================================
155
156uno::Sequence< css::uno::Type> AccessibleRelationSetHelper::getTypes()
157{
158 static const uno::Sequence< css::uno::Type> aTypes {
161 };
162 return aTypes;
163}
164
165uno::Sequence<sal_Int8> SAL_CALL AccessibleRelationSetHelper::getImplementationId()
166{
167 return css::uno::Sequence<sal_Int8>();
168}
169
170/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::vector< AccessibleRelation > maRelations
css::uno::Type const & get()
@descr This base class provides an implementation of the AccessibleRelationSet service.
std::mutex maMutex
Mutex guarding this object.
virtual sal_Int32 SAL_CALL getRelationCount() override
Returns the number of relations in this relation set.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
virtual sal_Bool SAL_CALL containsRelation(sal_Int16 aRelationType) override
Tests whether the relation set contains a relation matching the specified key.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Returns a sequence of all supported interfaces.
virtual css::accessibility::AccessibleRelation SAL_CALL getRelationByType(sal_Int16 aRelationType) override
Retrieve and return the relation with the given relation type.
void AddRelation(const css::accessibility::AccessibleRelation &rRelation)
std::vector< css::accessibility::AccessibleRelation > maRelations
The implementation of this helper interface.
virtual css::accessibility::AccessibleRelation SAL_CALL getRelation(sal_Int32 nIndex) override
Returns the relation of this relation set that is specified by the given index.
sal_Int32 nIndex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]