/src/libreoffice/vcl/source/accessibility/AccessibleBrowseBoxTableCell.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 | | |
21 | | #include <rtl/ref.hxx> |
22 | | #include <tools/gen.hxx> |
23 | | #include <vcl/accessibility/AccessibleBrowseBoxTableCell.hxx> |
24 | | |
25 | | #include <vcl/accessibletableprovider.hxx> |
26 | | #include <vcl/unohelp.hxx> |
27 | | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
28 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
29 | | |
30 | | namespace |
31 | | { |
32 | | /// @throws css::lang::IndexOutOfBoundsException |
33 | | void checkIndex_Impl( sal_Int32 _nIndex, std::u16string_view _sText ) |
34 | 0 | { |
35 | 0 | if ( _nIndex >= static_cast<sal_Int32>(_sText.size()) ) |
36 | 0 | throw css::lang::IndexOutOfBoundsException(); |
37 | 0 | } |
38 | | |
39 | | sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount ) |
40 | 0 | { |
41 | 0 | return _nRow * _nColumnCount + _nColumn; |
42 | 0 | } |
43 | | } |
44 | | using namespace ::com::sun::star::lang; |
45 | | using namespace comphelper; |
46 | | using namespace ::com::sun::star::uno; |
47 | | using ::com::sun::star::accessibility::XAccessible; |
48 | | using namespace ::com::sun::star::accessibility; |
49 | | |
50 | | |
51 | | // implementation of a table cell |
52 | | OUString AccessibleBrowseBoxTableCell::implGetText() |
53 | 0 | { |
54 | 0 | return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) ); |
55 | 0 | } |
56 | | |
57 | | css::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale() |
58 | 0 | { |
59 | 0 | return mpBrowseBox->GetAccessible()->getLocale(); |
60 | 0 | } |
61 | | |
62 | | void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) |
63 | 0 | { |
64 | 0 | nStartIndex = 0; |
65 | 0 | nEndIndex = 0; |
66 | 0 | } |
67 | | |
68 | | AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell( |
69 | | const Reference<XAccessible>& _rxParent, vcl::IAccessibleTableProvider& _rBrowseBox, |
70 | | sal_Int32 _nRowPos, sal_uInt16 _nColPos) |
71 | 0 | : ImplInheritanceHelper(_rxParent, _rBrowseBox, nullptr, _nRowPos, _nColPos) |
72 | 0 | { |
73 | 0 | sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() ); |
74 | 0 | setAccessibleName( _rBrowseBox.GetAccessibleObjectName( AccessibleBrowseBoxObjType::TableCell, nIndex ) ); |
75 | 0 | setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( AccessibleBrowseBoxObjType::TableCell, nIndex ) ); |
76 | | // Need to register as event listener |
77 | 0 | Reference< XComponent > xComponent(_rxParent, UNO_QUERY); |
78 | 0 | if( xComponent.is() ) |
79 | 0 | xComponent->addEventListener(static_cast< XEventListener *> (this)); |
80 | 0 | } |
81 | | |
82 | | css::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex ) |
83 | 0 | { |
84 | 0 | SolarMethodGuard aGuard(getMutex()); |
85 | 0 | ensureIsAlive(); |
86 | |
|
87 | 0 | css::awt::Rectangle aRect; |
88 | |
|
89 | 0 | if ( mpBrowseBox ) |
90 | 0 | { |
91 | 0 | if ( !implIsValidIndex( nIndex, implGetText().getLength() ) ) |
92 | 0 | throw IndexOutOfBoundsException(); |
93 | | |
94 | 0 | aRect = vcl::unohelper::ConvertToAWTRect( |
95 | 0 | mpBrowseBox->GetFieldCharacterBounds(getRowPos(), getColumnPos(), nIndex)); |
96 | 0 | } |
97 | | |
98 | 0 | return aRect; |
99 | 0 | } |
100 | | |
101 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point& _aPoint ) |
102 | 0 | { |
103 | | //! TODO CTL bidi |
104 | | // OSL_FAIL("Need to be done by base class!"); |
105 | 0 | SolarMethodGuard aGuard(getMutex()); |
106 | 0 | ensureIsAlive(); |
107 | |
|
108 | 0 | return mpBrowseBox->GetFieldIndexAtPoint(getRowPos(), getColumnPos(), |
109 | 0 | vcl::unohelper::ConvertToVCLPoint(_aPoint)); |
110 | 0 | } |
111 | | |
112 | | /** @return |
113 | | The name of this class. |
114 | | */ |
115 | | OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName() |
116 | 0 | { |
117 | 0 | return u"com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell"_ustr; |
118 | 0 | } |
119 | | |
120 | | /** @return The count of visible children. */ |
121 | | sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount() |
122 | 0 | { |
123 | 0 | return 0; |
124 | 0 | } |
125 | | |
126 | | /** @return The XAccessible interface of the specified child. */ |
127 | | css::uno::Reference< css::accessibility::XAccessible > SAL_CALL |
128 | | AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int64 ) |
129 | 0 | { |
130 | 0 | throw css::lang::IndexOutOfBoundsException(); |
131 | 0 | } |
132 | | |
133 | | /** Return a bitset of states of the current object. |
134 | | */ |
135 | | sal_Int64 AccessibleBrowseBoxTableCell::implCreateStateSet() |
136 | 0 | { |
137 | 0 | SolarMethodGuard aGuard(getMutex()); |
138 | |
|
139 | 0 | sal_Int64 nStateSet = 0; |
140 | |
|
141 | 0 | if( isAlive() ) |
142 | 0 | { |
143 | | // SHOWING done with mxParent |
144 | 0 | if( implIsShowing() ) |
145 | 0 | nStateSet |= AccessibleStateType::SHOWING; |
146 | |
|
147 | 0 | mpBrowseBox->FillAccessibleStateSetForCell( nStateSet, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) ); |
148 | 0 | } |
149 | 0 | else |
150 | 0 | nStateSet |= AccessibleStateType::DEFUNC; |
151 | |
|
152 | 0 | return nStateSet; |
153 | 0 | } |
154 | | |
155 | | // XAccessibleContext ----------------------------------------------------- |
156 | | |
157 | | sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent() |
158 | 0 | { |
159 | 0 | SolarMethodGuard aGuard(getMutex()); |
160 | 0 | ensureIsAlive(); |
161 | |
|
162 | 0 | return (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(mpBrowseBox->GetColumnCount())) + getColumnPos(); |
163 | 0 | } |
164 | | |
165 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( ) |
166 | 0 | { |
167 | 0 | return -1; |
168 | 0 | } |
169 | | |
170 | | sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex ) |
171 | 0 | { |
172 | 0 | SolarMethodGuard aGuard(getMutex()); |
173 | 0 | ensureIsAlive(); |
174 | |
|
175 | 0 | if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) ) |
176 | 0 | throw IndexOutOfBoundsException(); |
177 | | |
178 | 0 | return false; |
179 | 0 | } |
180 | | sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex ) |
181 | 0 | { |
182 | 0 | SolarMethodGuard aGuard(getMutex()); |
183 | 0 | ensureIsAlive(); |
184 | |
|
185 | 0 | return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex ); |
186 | 0 | } |
187 | | css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& ) |
188 | 0 | { |
189 | 0 | SolarMethodGuard aGuard(getMutex()); |
190 | 0 | ensureIsAlive(); |
191 | |
|
192 | 0 | OUString sText( implGetText() ); |
193 | |
|
194 | 0 | if ( !implIsValidIndex( nIndex, sText.getLength() ) ) |
195 | 0 | throw IndexOutOfBoundsException(); |
196 | | |
197 | 0 | return css::uno::Sequence< css::beans::PropertyValue >(); |
198 | 0 | } |
199 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( ) |
200 | 0 | { |
201 | 0 | SolarMethodGuard aGuard(getMutex()); |
202 | 0 | ensureIsAlive(); |
203 | |
|
204 | 0 | return implGetText().getLength(); |
205 | 0 | } |
206 | | |
207 | | OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( ) |
208 | 0 | { |
209 | 0 | SolarMethodGuard aGuard(getMutex()); |
210 | 0 | ensureIsAlive(); |
211 | |
|
212 | 0 | return OCommonAccessibleText::getSelectedText( ); |
213 | 0 | } |
214 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( ) |
215 | 0 | { |
216 | 0 | SolarMethodGuard aGuard(getMutex()); |
217 | 0 | ensureIsAlive(); |
218 | |
|
219 | 0 | return OCommonAccessibleText::getSelectionStart( ); |
220 | 0 | } |
221 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( ) |
222 | 0 | { |
223 | 0 | SolarMethodGuard aGuard(getMutex()); |
224 | 0 | ensureIsAlive(); |
225 | |
|
226 | 0 | return OCommonAccessibleText::getSelectionEnd( ); |
227 | 0 | } |
228 | | sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) |
229 | 0 | { |
230 | 0 | SolarMethodGuard aGuard(getMutex()); |
231 | 0 | ensureIsAlive(); |
232 | |
|
233 | 0 | if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) |
234 | 0 | throw IndexOutOfBoundsException(); |
235 | | |
236 | 0 | return false; |
237 | 0 | } |
238 | | OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( ) |
239 | 0 | { |
240 | 0 | SolarMethodGuard aGuard(getMutex()); |
241 | 0 | ensureIsAlive(); |
242 | |
|
243 | 0 | return implGetText( ); |
244 | 0 | } |
245 | | OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) |
246 | 0 | { |
247 | 0 | SolarMethodGuard aGuard(getMutex()); |
248 | 0 | ensureIsAlive(); |
249 | |
|
250 | 0 | return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex ); |
251 | 0 | } |
252 | | css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) |
253 | 0 | { |
254 | 0 | SolarMethodGuard aGuard(getMutex()); |
255 | 0 | ensureIsAlive(); |
256 | |
|
257 | 0 | return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType); |
258 | 0 | } |
259 | | css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) |
260 | 0 | { |
261 | 0 | SolarMethodGuard aGuard(getMutex()); |
262 | 0 | ensureIsAlive(); |
263 | |
|
264 | 0 | return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType); |
265 | 0 | } |
266 | | css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) |
267 | 0 | { |
268 | 0 | SolarMethodGuard aGuard(getMutex()); |
269 | 0 | ensureIsAlive(); |
270 | |
|
271 | 0 | return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType); |
272 | 0 | } |
273 | | sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) |
274 | 0 | { |
275 | 0 | SolarMethodGuard aGuard(getMutex()); |
276 | 0 | ensureIsAlive(); |
277 | |
|
278 | 0 | OUString sText = implGetText(); |
279 | 0 | checkIndex_Impl( nStartIndex, sText ); |
280 | 0 | checkIndex_Impl( nEndIndex, sText ); |
281 | | |
282 | | //!!! don't know how to put a string into the clipboard |
283 | 0 | return false; |
284 | 0 | } |
285 | | sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType ) |
286 | 0 | { |
287 | 0 | return false; |
288 | 0 | } |
289 | | void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource ) |
290 | 0 | { |
291 | 0 | if ( _rSource.Source == mxParent ) |
292 | 0 | { |
293 | 0 | dispose(); |
294 | 0 | } |
295 | 0 | } |
296 | | |
297 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |