Debian Codegraph @

toolkit/source/controls/table/AccessibleGridControlBase.cxx

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