/src/libreoffice/toolkit/source/controls/table/AccessibleGridControlBase.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 <controls/table/AccessibleGridControlBase.hxx> |
21 | | |
22 | | #include <utility> |
23 | | #include <vcl/svapp.hxx> |
24 | | #include <vcl/unohelp.hxx> |
25 | | #include <vcl/window.hxx> |
26 | | #include <cppuhelper/supportsservice.hxx> |
27 | | #include <sal/types.h> |
28 | | |
29 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
30 | | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
31 | | #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp> |
32 | | #include <unotools/accessiblerelationsethelper.hxx> |
33 | | #include <sal/log.hxx> |
34 | | |
35 | | using ::com::sun::star::uno::Sequence; |
36 | | using ::com::sun::star::uno::Any; |
37 | | |
38 | | using namespace ::com::sun::star; |
39 | | using namespace ::com::sun::star::accessibility; |
40 | | using namespace ::comphelper; |
41 | | using namespace ::vcl; |
42 | | |
43 | | |
44 | | namespace accessibility { |
45 | | |
46 | | using namespace com::sun::star::accessibility::AccessibleStateType; |
47 | | |
48 | | AccessibleGridControlBase::AccessibleGridControlBase( |
49 | | css::uno::Reference<css::accessibility::XAccessible> xParent, svt::table::TableControl& rTable, |
50 | | AccessibleTableControlObjType eObjType) |
51 | 0 | : m_xParent(std::move(xParent)) |
52 | 0 | , m_aTable(rTable) |
53 | 0 | , m_eObjType(eObjType) |
54 | 0 | { |
55 | 0 | } |
56 | | |
57 | | void SAL_CALL AccessibleGridControlBase::disposing() |
58 | 0 | { |
59 | 0 | SolarMutexGuard g; |
60 | |
|
61 | 0 | OAccessible::disposing(); |
62 | |
|
63 | 0 | m_xParent = nullptr; |
64 | | //m_aTable = NULL; |
65 | 0 | } |
66 | | |
67 | | // css::accessibility::XAccessibleContext |
68 | | |
69 | | css::uno::Reference< css::accessibility::XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleParent() |
70 | 0 | { |
71 | 0 | SolarMutexGuard g; |
72 | |
|
73 | 0 | ensureAlive(); |
74 | 0 | return m_xParent; |
75 | 0 | } |
76 | | |
77 | | OUString SAL_CALL AccessibleGridControlBase::getAccessibleDescription() |
78 | 0 | { |
79 | 0 | SolarMutexGuard g; |
80 | |
|
81 | 0 | ensureAlive(); |
82 | 0 | return m_aTable.GetAccessibleObjectDescription(m_eObjType); |
83 | 0 | } |
84 | | |
85 | | OUString SAL_CALL AccessibleGridControlBase::getAccessibleName() |
86 | 0 | { |
87 | 0 | SolarMutexGuard g; |
88 | |
|
89 | 0 | ensureAlive(); |
90 | 0 | return m_aTable.GetAccessibleObjectName(m_eObjType, 0, 0); |
91 | 0 | } |
92 | | |
93 | | css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL |
94 | | AccessibleGridControlBase::getAccessibleRelationSet() |
95 | 0 | { |
96 | 0 | SolarMutexGuard g; |
97 | |
|
98 | 0 | ensureAlive(); |
99 | | // GridControl does not have relations. |
100 | 0 | return new utl::AccessibleRelationSetHelper; |
101 | 0 | } |
102 | | |
103 | | sal_Int64 SAL_CALL |
104 | | AccessibleGridControlBase::getAccessibleStateSet() |
105 | 0 | { |
106 | 0 | SolarMutexGuard aSolarGuard; |
107 | | |
108 | | // don't check whether alive -> StateSet may contain DEFUNC |
109 | 0 | return implCreateStateSet(); |
110 | 0 | } |
111 | | |
112 | | lang::Locale SAL_CALL AccessibleGridControlBase::getLocale() |
113 | 0 | { |
114 | 0 | SolarMutexGuard g; |
115 | |
|
116 | 0 | ensureAlive(); |
117 | 0 | if( m_xParent.is() ) |
118 | 0 | { |
119 | 0 | css::uno::Reference< css::accessibility::XAccessibleContext > |
120 | 0 | xParentContext( m_xParent->getAccessibleContext() ); |
121 | 0 | if( xParentContext.is() ) |
122 | 0 | return xParentContext->getLocale(); |
123 | 0 | } |
124 | 0 | throw IllegalAccessibleComponentStateException(); |
125 | 0 | } |
126 | | |
127 | | // XServiceInfo |
128 | | |
129 | | sal_Bool SAL_CALL AccessibleGridControlBase::supportsService( |
130 | | const OUString& rServiceName ) |
131 | 0 | { |
132 | 0 | return cppu::supportsService(this, rServiceName); |
133 | 0 | } |
134 | | |
135 | | Sequence< OUString > SAL_CALL AccessibleGridControlBase::getSupportedServiceNames() |
136 | 0 | { |
137 | 0 | return { u"com.sun.star.accessibility.AccessibleContext"_ustr }; |
138 | 0 | } |
139 | | // internal virtual methods |
140 | | |
141 | | bool AccessibleGridControlBase::implIsShowing() |
142 | 0 | { |
143 | 0 | bool bShowing = false; |
144 | 0 | if( m_xParent.is() ) |
145 | 0 | { |
146 | 0 | css::uno::Reference< css::accessibility::XAccessibleComponent > |
147 | 0 | xParentComp( m_xParent->getAccessibleContext(), uno::UNO_QUERY ); |
148 | 0 | if( xParentComp.is() ) |
149 | 0 | bShowing = implGetBoundingBox().Overlaps( |
150 | 0 | vcl::unohelper::ConvertToVCLRect(xParentComp->getBounds())); |
151 | 0 | } |
152 | 0 | return bShowing; |
153 | 0 | } |
154 | | |
155 | | tools::Rectangle AccessibleGridControlBase::implGetBoundingBox() |
156 | 0 | { |
157 | | // calculate parent-relative position from own and parent's absolute position |
158 | 0 | tools::Rectangle aBound(implGetBoundingBoxOnScreen()); |
159 | 0 | if (!m_xParent.is()) |
160 | 0 | return aBound; |
161 | | |
162 | 0 | uno::Reference<css::accessibility::XAccessibleComponent> xParentComponent(m_xParent->getAccessibleContext(), uno::UNO_QUERY); |
163 | 0 | if (!xParentComponent.is()) |
164 | 0 | return aBound; |
165 | | |
166 | 0 | awt::Point aParentPos = xParentComponent->getLocationOnScreen(); |
167 | 0 | aBound.Move(-aParentPos.X, -aParentPos.Y); |
168 | 0 | return aBound; |
169 | 0 | } |
170 | | |
171 | | sal_Int64 AccessibleGridControlBase::implCreateStateSet() |
172 | 0 | { |
173 | 0 | sal_Int64 nStateSet = 0; |
174 | |
|
175 | 0 | if( isAlive() ) |
176 | 0 | { |
177 | | // SHOWING done with m_xParent |
178 | 0 | if( implIsShowing() ) |
179 | 0 | nStateSet |= AccessibleStateType::SHOWING; |
180 | | // GridControl fills StateSet with states depending on object type |
181 | 0 | m_aTable.FillAccessibleStateSet( nStateSet, getType() ); |
182 | 0 | } |
183 | 0 | else |
184 | 0 | nStateSet |= AccessibleStateType::DEFUNC; |
185 | 0 | return nStateSet; |
186 | 0 | } |
187 | | |
188 | | css::awt::Rectangle AccessibleGridControlBase::implGetBounds() |
189 | 0 | { |
190 | 0 | return vcl::unohelper::ConvertToAWTRect(implGetBoundingBox()); |
191 | 0 | } |
192 | | |
193 | | void AccessibleGridControlBase::commitEvent( |
194 | | sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue ) |
195 | 0 | { |
196 | 0 | NotifyAccessibleEvent(_nEventId, _rOldValue, _rNewValue); |
197 | 0 | } |
198 | | |
199 | | sal_Int16 SAL_CALL AccessibleGridControlBase::getAccessibleRole() |
200 | 0 | { |
201 | 0 | ensureAlive(); |
202 | 0 | sal_Int16 nRole = AccessibleRole::UNKNOWN; |
203 | 0 | switch ( m_eObjType ) |
204 | 0 | { |
205 | 0 | case AccessibleTableControlObjType::ROWHEADERCELL: |
206 | 0 | nRole = AccessibleRole::ROW_HEADER; |
207 | 0 | break; |
208 | 0 | case AccessibleTableControlObjType::COLUMNHEADERCELL: |
209 | 0 | nRole = AccessibleRole::COLUMN_HEADER; |
210 | 0 | break; |
211 | 0 | case AccessibleTableControlObjType::COLUMNHEADERBAR: |
212 | 0 | case AccessibleTableControlObjType::ROWHEADERBAR: |
213 | 0 | case AccessibleTableControlObjType::TABLE: |
214 | 0 | nRole = AccessibleRole::TABLE; |
215 | 0 | break; |
216 | 0 | case AccessibleTableControlObjType::TABLECELL: |
217 | 0 | nRole = AccessibleRole::TABLE_CELL; |
218 | 0 | break; |
219 | 0 | case AccessibleTableControlObjType::GRIDCONTROL: |
220 | 0 | nRole = AccessibleRole::PANEL; |
221 | 0 | break; |
222 | 0 | } |
223 | 0 | return nRole; |
224 | 0 | } |
225 | | |
226 | | css::uno::Reference<css::accessibility::XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleAtPoint( const css::awt::Point& ) |
227 | 0 | { |
228 | 0 | return nullptr; |
229 | 0 | } |
230 | | |
231 | | sal_Int32 SAL_CALL AccessibleGridControlBase::getForeground( ) |
232 | 0 | { |
233 | 0 | SolarMutexGuard aSolarGuard; |
234 | |
|
235 | 0 | ensureAlive(); |
236 | |
|
237 | 0 | Color nColor; |
238 | 0 | if (m_aTable.IsControlForeground()) |
239 | 0 | nColor = m_aTable.GetControlForeground(); |
240 | 0 | else |
241 | 0 | { |
242 | 0 | vcl::Font aFont; |
243 | 0 | if (m_aTable.IsControlFont() ) |
244 | 0 | aFont = m_aTable.GetControlFont(); |
245 | 0 | else |
246 | 0 | aFont = m_aTable.GetFont(); |
247 | 0 | nColor = aFont.GetColor(); |
248 | 0 | } |
249 | 0 | return sal_Int32(nColor); |
250 | 0 | } |
251 | | |
252 | | sal_Int32 SAL_CALL AccessibleGridControlBase::getBackground( ) |
253 | 0 | { |
254 | 0 | SolarMutexGuard aSolarGuard; |
255 | |
|
256 | 0 | ensureAlive(); |
257 | 0 | Color nColor; |
258 | 0 | if (m_aTable.IsControlBackground()) |
259 | 0 | nColor = m_aTable.GetControlBackground(); |
260 | 0 | else |
261 | 0 | nColor = m_aTable.GetBackground().GetColor(); |
262 | 0 | return sal_Int32(nColor); |
263 | 0 | } |
264 | | |
265 | | } // namespace accessibility |
266 | | |
267 | | |
268 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |