/src/libreoffice/vcl/source/accessibility/vclxaccessibleheaderbar.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 | | #include <accessibility/vclxaccessibleheaderbar.hxx> |
21 | | #include <accessibility/vclxaccessibleheaderbaritem.hxx> |
22 | | |
23 | | #include <comphelper/accessiblecontexthelper.hxx> |
24 | | #include <o3tl/safeint.hxx> |
25 | | #include <vcl/headbar.hxx> |
26 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
27 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
28 | | #include <vcl/svapp.hxx> |
29 | | |
30 | | using namespace ::com::sun::star; |
31 | | using namespace ::com::sun::star::uno; |
32 | | using namespace ::com::sun::star::lang; |
33 | | using namespace ::com::sun::star::accessibility; |
34 | | |
35 | | VCLXAccessibleHeaderBar::VCLXAccessibleHeaderBar(HeaderBar* pHeaderBar) |
36 | 0 | : VCLXAccessibleComponent(pHeaderBar) |
37 | 0 | { |
38 | 0 | m_pHeadBar = pHeaderBar; |
39 | 0 | } |
40 | | |
41 | 0 | VCLXAccessibleHeaderBar::~VCLXAccessibleHeaderBar() {} |
42 | | |
43 | | // XServiceInfo |
44 | | |
45 | | OUString VCLXAccessibleHeaderBar::getImplementationName() |
46 | 0 | { |
47 | 0 | return u"com.sun.star.comp.toolkit.AccessibleHeaderBar"_ustr; |
48 | 0 | } |
49 | | |
50 | | Sequence<OUString> VCLXAccessibleHeaderBar::getSupportedServiceNames() |
51 | 0 | { |
52 | 0 | return { u"com.sun.star.awt.AccessibleHeaderBar"_ustr }; |
53 | 0 | } |
54 | | |
55 | | // =======XAccessibleContext======= |
56 | | |
57 | | sal_Int64 SAL_CALL VCLXAccessibleHeaderBar::getAccessibleChildCount() |
58 | 0 | { |
59 | 0 | SolarMutexGuard g; |
60 | |
|
61 | 0 | sal_Int64 nCount = 0; |
62 | 0 | if (m_pHeadBar) |
63 | 0 | nCount = m_pHeadBar->GetItemCount(); |
64 | |
|
65 | 0 | return nCount; |
66 | 0 | } |
67 | | css::uno::Reference<css::accessibility::XAccessible> |
68 | | SAL_CALL VCLXAccessibleHeaderBar::getAccessibleChild(sal_Int64 i) |
69 | 0 | { |
70 | 0 | SolarMutexGuard g; |
71 | |
|
72 | 0 | if (i < 0 || i >= getAccessibleChildCount()) |
73 | 0 | throw IndexOutOfBoundsException(); |
74 | | |
75 | 0 | rtl::Reference<VCLXAccessibleHeaderBarItem> xChild; |
76 | | // search for the child |
77 | 0 | if (o3tl::make_unsigned(i) >= m_aAccessibleChildren.size()) |
78 | 0 | xChild = CreateChild(i); |
79 | 0 | else |
80 | 0 | { |
81 | 0 | xChild = m_aAccessibleChildren[i]; |
82 | 0 | if (!xChild.is()) |
83 | 0 | xChild = CreateChild(i); |
84 | 0 | } |
85 | 0 | return xChild; |
86 | 0 | } |
87 | | |
88 | | sal_Int16 SAL_CALL VCLXAccessibleHeaderBar::getAccessibleRole() |
89 | 0 | { |
90 | 0 | return css::accessibility::AccessibleRole::LIST; |
91 | 0 | } |
92 | | |
93 | | void SAL_CALL VCLXAccessibleHeaderBar::disposing() |
94 | 0 | { |
95 | 0 | SolarMutexGuard g; |
96 | |
|
97 | 0 | ListItems().swap(m_aAccessibleChildren); |
98 | 0 | VCLXAccessibleComponent::disposing(); |
99 | 0 | } |
100 | | |
101 | | rtl::Reference<VCLXAccessibleHeaderBarItem> VCLXAccessibleHeaderBar::CreateChild(sal_Int32 i) |
102 | 0 | { |
103 | 0 | rtl::Reference<VCLXAccessibleHeaderBarItem> xChild; |
104 | |
|
105 | 0 | sal_uInt16 nPos = static_cast<sal_uInt16>(i); |
106 | 0 | if (nPos >= m_aAccessibleChildren.size()) |
107 | 0 | { |
108 | 0 | m_aAccessibleChildren.resize(nPos + 1); |
109 | | |
110 | | // insert into the container |
111 | 0 | xChild = new VCLXAccessibleHeaderBarItem(m_pHeadBar, i); |
112 | 0 | m_aAccessibleChildren[nPos] = xChild.get(); |
113 | 0 | } |
114 | 0 | else |
115 | 0 | { |
116 | 0 | xChild = m_aAccessibleChildren[nPos]; |
117 | | // check if position is empty and can be used else we have to adjust all entries behind this |
118 | 0 | if (!xChild.is()) |
119 | 0 | { |
120 | 0 | xChild = new VCLXAccessibleHeaderBarItem(m_pHeadBar, i); |
121 | 0 | m_aAccessibleChildren[nPos] = xChild.get(); |
122 | 0 | } |
123 | 0 | } |
124 | 0 | return xChild; |
125 | 0 | } |
126 | | |
127 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |