/src/libreoffice/toolkit/source/controls/table/AccessibleGridControl.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/AccessibleGridControl.hxx> |
21 | | #include <controls/table/AccessibleGridControlTable.hxx> |
22 | | #include <controls/table/AccessibleGridControlHeader.hxx> |
23 | | |
24 | | #include <com/sun/star/accessibility/AccessibleEventId.hpp> |
25 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
26 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
27 | | #include <utility> |
28 | | #include <vcl/svapp.hxx> |
29 | | #include <vcl/unohelp.hxx> |
30 | | |
31 | | namespace accessibility |
32 | | { |
33 | | |
34 | | using namespace ::com::sun::star::uno; |
35 | | using namespace ::com::sun::star; |
36 | | using namespace ::com::sun::star::lang; |
37 | | using namespace ::com::sun::star::accessibility; |
38 | | using namespace ::vcl; |
39 | | |
40 | | AccessibleGridControl::AccessibleGridControl( |
41 | | const css::uno::Reference< css::accessibility::XAccessible >& _rxParent, |
42 | | svt::table::TableControl& _rTable) |
43 | 0 | : AccessibleGridControlBase(_rxParent, _rTable, AccessibleTableControlObjType::GRIDCONTROL) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | |
48 | | void SAL_CALL AccessibleGridControl::disposing() |
49 | 0 | { |
50 | 0 | SolarMutexGuard g; |
51 | |
|
52 | 0 | if ( m_xTable.is() ) |
53 | 0 | { |
54 | 0 | m_xTable->dispose(); |
55 | 0 | m_xTable.clear(); |
56 | 0 | } |
57 | 0 | if ( m_xRowHeaderBar.is() ) |
58 | 0 | { |
59 | 0 | m_xRowHeaderBar->dispose(); |
60 | 0 | m_xRowHeaderBar.clear(); |
61 | 0 | } |
62 | 0 | if ( m_xColumnHeaderBar.is() ) |
63 | 0 | { |
64 | 0 | m_xColumnHeaderBar->dispose(); |
65 | 0 | m_xColumnHeaderBar.clear(); |
66 | 0 | } |
67 | 0 | AccessibleGridControlBase::disposing(); |
68 | 0 | } |
69 | | |
70 | | sal_Int64 AccessibleGridControl::implGetAccessibleChildCount() |
71 | 0 | { |
72 | 0 | return m_aTable.GetAccessibleControlCount(); |
73 | 0 | } |
74 | | |
75 | | // css::accessibility::XAccessibleContext --------------------------------------------------------- |
76 | | |
77 | | |
78 | | sal_Int64 SAL_CALL AccessibleGridControl::getAccessibleChildCount() |
79 | 0 | { |
80 | 0 | SolarMutexGuard aSolarGuard; |
81 | 0 | ensureAlive(); |
82 | 0 | return implGetAccessibleChildCount(); |
83 | 0 | } |
84 | | |
85 | | |
86 | | css::uno::Reference< css::accessibility::XAccessible > SAL_CALL |
87 | | AccessibleGridControl::getAccessibleChild( sal_Int64 nChildIndex ) |
88 | 0 | { |
89 | 0 | SolarMutexGuard aSolarGuard; |
90 | |
|
91 | 0 | if (nChildIndex<0 || nChildIndex>=implGetAccessibleChildCount()) |
92 | 0 | throw IndexOutOfBoundsException(); |
93 | | |
94 | 0 | css::uno::Reference< css::accessibility::XAccessible > xChild; |
95 | 0 | if (isAlive()) |
96 | 0 | { |
97 | 0 | if(nChildIndex == 0 && m_aTable.HasColHeader()) |
98 | 0 | { |
99 | 0 | if(!m_xColumnHeaderBar.is()) |
100 | 0 | { |
101 | 0 | m_xColumnHeaderBar = new AccessibleGridControlHeader( |
102 | 0 | this, m_aTable, AccessibleTableControlObjType::COLUMNHEADERBAR); |
103 | 0 | } |
104 | 0 | xChild = m_xColumnHeaderBar.get(); |
105 | 0 | } |
106 | 0 | else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0)) |
107 | 0 | { |
108 | 0 | if(!m_xRowHeaderBar.is()) |
109 | 0 | { |
110 | 0 | m_xRowHeaderBar = new AccessibleGridControlHeader( |
111 | 0 | this, m_aTable, AccessibleTableControlObjType::ROWHEADERBAR); |
112 | 0 | } |
113 | 0 | xChild = m_xRowHeaderBar.get(); |
114 | 0 | } |
115 | 0 | else |
116 | 0 | { |
117 | 0 | if(!m_xTable.is()) |
118 | 0 | { |
119 | 0 | m_xTable = new AccessibleGridControlTable(this, m_aTable); |
120 | 0 | } |
121 | 0 | xChild = m_xTable.get(); |
122 | 0 | } |
123 | 0 | } |
124 | 0 | return xChild; |
125 | 0 | } |
126 | | |
127 | | |
128 | | sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole() |
129 | 0 | { |
130 | 0 | SolarMutexGuard g; |
131 | |
|
132 | 0 | ensureAlive(); |
133 | 0 | return AccessibleRole::PANEL; |
134 | 0 | } |
135 | | |
136 | | |
137 | | // css::accessibility::XAccessibleComponent ------------------------------------------------------- |
138 | | |
139 | | css::uno::Reference< css::accessibility::XAccessible > SAL_CALL |
140 | | AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint ) |
141 | 0 | { |
142 | 0 | SolarMutexGuard aSolarGuard; |
143 | 0 | ensureAlive(); |
144 | | |
145 | | // try whether point is in one of the fixed children |
146 | | // (table, header bars, corner control) |
147 | 0 | Point aPoint(vcl::unohelper::ConvertToVCLPoint(rPoint)); |
148 | 0 | const sal_Int64 nChildCount = implGetAccessibleChildCount(); |
149 | 0 | for (sal_Int64 nIndex = 0; nIndex < nChildCount; ++nIndex) |
150 | 0 | { |
151 | 0 | css::uno::Reference<css::accessibility::XAccessible> xCurrChild = getAccessibleChild(nIndex); |
152 | 0 | css::uno::Reference<css::accessibility::XAccessibleComponent> xCurrChildComp( |
153 | 0 | xCurrChild, uno::UNO_QUERY); |
154 | |
|
155 | 0 | if (xCurrChildComp.is() |
156 | 0 | && vcl::unohelper::ConvertToVCLRect(xCurrChildComp->getBounds()).Contains(aPoint)) |
157 | 0 | return xCurrChild; |
158 | 0 | } |
159 | 0 | return nullptr; |
160 | 0 | } |
161 | | |
162 | | |
163 | | void SAL_CALL AccessibleGridControl::grabFocus() |
164 | 0 | { |
165 | 0 | SolarMutexGuard aSolarGuard; |
166 | 0 | ensureAlive(); |
167 | 0 | m_aTable.GrabFocus(); |
168 | 0 | } |
169 | | |
170 | | // XServiceInfo --------------------------------------------------------------- |
171 | | OUString SAL_CALL AccessibleGridControl::getImplementationName() |
172 | 0 | { |
173 | 0 | return u"com.sun.star.accessibility.AccessibleGridControl"_ustr; |
174 | 0 | } |
175 | | |
176 | | // internal virtual methods --------------------------------------------------- |
177 | | |
178 | | AbsoluteScreenPixelRectangle AccessibleGridControl::implGetBoundingBoxOnScreen() |
179 | 0 | { |
180 | 0 | return m_aTable.GetWindowExtentsAbsolute(); |
181 | 0 | } |
182 | | |
183 | | // internal helper methods ---------------------------------------------------- |
184 | | |
185 | | void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue) |
186 | 0 | { |
187 | 0 | sal_Int64 nChildCount = implGetAccessibleChildCount(); |
188 | 0 | assert(nChildCount != 0); |
189 | 0 | for (sal_Int64 i = 0; i < nChildCount; i++) |
190 | 0 | { |
191 | 0 | css::uno::Reference<css::accessibility::XAccessible> xAccessible = getAccessibleChild(i); |
192 | 0 | if (css::uno::Reference<css::accessibility::XAccessible>(m_xTable) == xAccessible) |
193 | 0 | { |
194 | 0 | Reference<XAccessible> xCell = m_xTable->getAccessibleCellAt( |
195 | 0 | m_aTable.GetCurrentRow(), m_aTable.GetCurrentColumn()); |
196 | 0 | AccessibleGridControlTableCell* pCell |
197 | 0 | = static_cast<AccessibleGridControlTableCell*>(xCell.get()); |
198 | 0 | pCell->commitEvent(_nEventId, _rNewValue, _rOldValue); |
199 | 0 | } |
200 | 0 | } |
201 | 0 | } |
202 | | |
203 | | void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue) |
204 | 0 | { |
205 | 0 | if ( !m_xTable.is() ) |
206 | 0 | return; |
207 | | |
208 | 0 | if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED) |
209 | 0 | { |
210 | 0 | const sal_Int32 nCurrentRow = m_aTable.GetCurrentRow(); |
211 | 0 | const sal_Int32 nCurrentCol = m_aTable.GetCurrentColumn(); |
212 | 0 | css::uno::Reference< css::accessibility::XAccessible > xChild; |
213 | 0 | if (nCurrentRow > -1 && nCurrentCol > -1) |
214 | 0 | xChild = m_xTable->getAccessibleCellAt(nCurrentRow, nCurrentCol); |
215 | |
|
216 | 0 | m_xTable->commitEvent(_nEventId, Any(xChild),_rOldValue); |
217 | 0 | } |
218 | 0 | else |
219 | 0 | m_xTable->commitEvent(_nEventId,_rNewValue,_rOldValue); |
220 | 0 | } |
221 | | |
222 | | } // namespace accessibility |
223 | | |
224 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |