Line data Source code
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 "accessibility/extended/AccessibleGridControlTableCell.hxx"
22 : #include <svtools/accessibletable.hxx>
23 : #include "accessibility/extended/AccessibleGridControl.hxx"
24 : #include <tools/gen.hxx>
25 : #include <toolkit/helper/vclunohelper.hxx>
26 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 :
28 : namespace accessibility
29 : {
30 : namespace
31 : {
32 : // FIXME this is a copy'n'paste from
33 : // source/extended/AccessibleBrowseBoxTableCell.cxx, get rid of that...
34 0 : static void checkIndex_Impl( sal_Int32 _nIndex, const OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
35 : {
36 0 : if ( _nIndex >= _sText.getLength() )
37 0 : throw ::com::sun::star::lang::IndexOutOfBoundsException();
38 0 : }
39 : }
40 : using namespace ::com::sun::star::lang;
41 : using namespace utl;
42 : using namespace comphelper;
43 : using ::accessibility::AccessibleGridControl;
44 : using namespace ::com::sun::star::uno;
45 : using ::com::sun::star::accessibility::XAccessible;
46 : using namespace ::com::sun::star::accessibility;
47 : using namespace ::svt;
48 : using namespace ::svt::table;
49 :
50 :
51 :
52 : // = AccessibleGridControlCell
53 :
54 :
55 0 : AccessibleGridControlCell::AccessibleGridControlCell(
56 : const Reference< XAccessible >& _rxParent, IAccessibleTable& _rTable,
57 : sal_Int32 _nRowPos, sal_uInt16 _nColPos, AccessibleTableControlObjType _eType )
58 : :AccessibleGridControlBase( _rxParent, _rTable, _eType )
59 : ,m_nRowPos( _nRowPos )
60 0 : ,m_nColPos( _nColPos )
61 : {
62 : // set accessible name here, because for that we need the position of the cell
63 : // and so the base class isn't capable of doing this
64 0 : OUString aAccName;
65 0 : if(_eType == TCTYPE_TABLECELL)
66 0 : aAccName = _rTable.GetAccessibleObjectName( TCTYPE_TABLECELL, _nRowPos, _nColPos );
67 0 : else if(_eType == TCTYPE_ROWHEADERCELL)
68 0 : aAccName = _rTable.GetAccessibleObjectName( TCTYPE_ROWHEADERCELL, _nRowPos, 0 );
69 0 : else if(_eType == TCTYPE_COLUMNHEADERCELL)
70 0 : aAccName = _rTable.GetAccessibleObjectName( TCTYPE_COLUMNHEADERCELL, 0, _nRowPos );
71 0 : implSetName( aAccName );
72 0 : }
73 :
74 :
75 0 : AccessibleGridControlCell::~AccessibleGridControlCell()
76 : {
77 0 : }
78 :
79 :
80 0 : void SAL_CALL AccessibleGridControlCell::grabFocus() throw ( RuntimeException, std::exception )
81 : {
82 0 : SolarMutexGuard aSolarGuard;
83 :
84 0 : m_aTable.GoToCell( m_nColPos, m_nRowPos );
85 0 : }
86 :
87 : // implementation of a table cell
88 0 : OUString AccessibleGridControlTableCell::implGetText()
89 : {
90 0 : ensureIsAlive();
91 0 : return m_aTable.GetAccessibleCellText( getRowPos(), getColumnPos() );
92 : }
93 :
94 0 : ::com::sun::star::lang::Locale AccessibleGridControlTableCell::implGetLocale()
95 : {
96 0 : ensureIsAlive();
97 0 : return m_aTable.GetAccessible()->getAccessibleContext()->getLocale();
98 : }
99 :
100 0 : void AccessibleGridControlTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
101 : {
102 0 : nStartIndex = 0;
103 0 : nEndIndex = 0;
104 0 : }
105 :
106 0 : AccessibleGridControlTableCell::AccessibleGridControlTableCell(const Reference<XAccessible >& _rxParent,
107 : IAccessibleTable& _rTable,
108 : sal_Int32 _nRowPos,
109 : sal_uInt16 _nColPos,
110 : AccessibleTableControlObjType eObjType)
111 0 : :AccessibleGridControlCell( _rxParent, _rTable, _nRowPos, _nColPos, eObjType )
112 : {
113 0 : }
114 :
115 : // XInterface -------------------------------------------------------------
116 :
117 : /** Queries for a new interface. */
118 0 : ::com::sun::star::uno::Any SAL_CALL AccessibleGridControlTableCell::queryInterface(
119 : const ::com::sun::star::uno::Type& rType )
120 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
121 : {
122 0 : Any aRet = AccessibleGridControlCell::queryInterface(rType);
123 0 : if ( !aRet.hasValue() )
124 0 : aRet = AccessibleTextHelper_BASE::queryInterface(rType);
125 0 : return aRet;
126 : }
127 :
128 : /** Aquires the object (calls acquire() on base class). */
129 0 : void SAL_CALL AccessibleGridControlTableCell::acquire() throw ()
130 : {
131 0 : AccessibleGridControlCell::acquire();
132 0 : }
133 :
134 : /** Releases the object (calls release() on base class). */
135 0 : void SAL_CALL AccessibleGridControlTableCell::release() throw ()
136 : {
137 0 : AccessibleGridControlCell::release();
138 0 : }
139 :
140 0 : ::com::sun::star::awt::Rectangle SAL_CALL AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
141 : {
142 0 : SolarMutexGuard aSolarGuard;
143 :
144 0 : ensureIsAlive();
145 0 : if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
146 0 : throw IndexOutOfBoundsException();
147 :
148 0 : ::com::sun::star::awt::Rectangle aRect;
149 :
150 0 : if ( &m_aTable )
151 0 : aRect = AWTRectangle( m_aTable.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
152 0 : return aRect;
153 : }
154 :
155 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException, std::exception)
156 : {
157 0 : SolarMutexGuard aSolarGuard;
158 :
159 0 : ensureIsAlive();
160 :
161 0 : return m_aTable.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
162 : }
163 :
164 : /** @return
165 : The name of this class.
166 : */
167 0 : OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName()
168 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
169 : {
170 0 : return OUString( "com.sun.star.accessibility.AccessibleGridControlTableCell" );
171 : }
172 :
173 : /** @return The count of visible children. */
174 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount()
175 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
176 : {
177 0 : return 0;
178 : }
179 :
180 : /** @return The XAccessible interface of the specified child. */
181 : ::com::sun::star::uno::Reference<
182 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
183 0 : AccessibleGridControlTableCell::getAccessibleChild( sal_Int32 )
184 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
185 : ::com::sun::star::uno::RuntimeException, std::exception )
186 : {
187 0 : throw ::com::sun::star::lang::IndexOutOfBoundsException();
188 : }
189 :
190 : /** Creates a new AccessibleStateSetHelper and fills it with states of the
191 : current object.
192 : @return
193 : A filled AccessibleStateSetHelper.
194 : */
195 0 : ::utl::AccessibleStateSetHelper* AccessibleGridControlTableCell::implCreateStateSetHelper()
196 : {
197 0 : ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
198 :
199 0 : if( isAlive() )
200 : {
201 : // SHOWING done with mxParent
202 0 : if( implIsShowing() )
203 0 : pStateSetHelper->AddState( AccessibleStateType::SHOWING );
204 :
205 0 : m_aTable.FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
206 : }
207 : else
208 0 : pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
209 :
210 0 : return pStateSetHelper;
211 : }
212 :
213 :
214 : // XAccessible ------------------------------------------------------------
215 :
216 : /** @return The XAccessibleContext interface of this object. */
217 0 : Reference< XAccessibleContext > SAL_CALL AccessibleGridControlTableCell::getAccessibleContext() throw ( RuntimeException, std::exception )
218 : {
219 0 : SolarMutexGuard g;
220 :
221 0 : ensureIsAlive();
222 0 : return this;
223 : }
224 :
225 : // XAccessibleContext -----------------------------------------------------
226 :
227 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent()
228 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
229 : {
230 0 : SolarMutexGuard aSolarGuard;
231 :
232 0 : ensureIsAlive();
233 :
234 0 : return ( getRowPos() * m_aTable.GetColumnCount() ) + getColumnPos();
235 : }
236 :
237 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
238 : {
239 0 : return -1;
240 : }
241 0 : sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
242 : {
243 0 : SolarMutexGuard aSolarGuard;
244 :
245 0 : if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
246 0 : throw IndexOutOfBoundsException();
247 :
248 0 : return sal_False;
249 : }
250 0 : sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
251 : {
252 0 : SolarMutexGuard aSolarGuard;
253 :
254 0 : return OCommonAccessibleText::getCharacter( nIndex );
255 : }
256 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
257 : {
258 0 : SolarMutexGuard aSolarGuard;
259 :
260 0 : OUString sText( implGetText() );
261 :
262 0 : if ( !implIsValidIndex( nIndex, sText.getLength() ) )
263 0 : throw IndexOutOfBoundsException();
264 :
265 0 : return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
266 : }
267 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
268 : {
269 0 : SolarMutexGuard aSolarGuard;
270 :
271 0 : return OCommonAccessibleText::getCharacterCount( );
272 : }
273 :
274 0 : OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
275 : {
276 0 : SolarMutexGuard aSolarGuard;
277 :
278 0 : return OCommonAccessibleText::getSelectedText( );
279 : }
280 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
281 : {
282 0 : SolarMutexGuard aSolarGuard;
283 :
284 0 : return OCommonAccessibleText::getSelectionStart( );
285 : }
286 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
287 : {
288 0 : SolarMutexGuard aSolarGuard;
289 :
290 0 : return OCommonAccessibleText::getSelectionEnd( );
291 : }
292 0 : sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
293 : {
294 0 : SolarMutexGuard aSolarGuard;
295 :
296 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
297 0 : throw IndexOutOfBoundsException();
298 :
299 0 : return sal_False;
300 : }
301 0 : OUString SAL_CALL AccessibleGridControlTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
302 : {
303 0 : SolarMutexGuard aSolarGuard;
304 :
305 0 : return OCommonAccessibleText::getText( );
306 : }
307 0 : OUString SAL_CALL AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
308 : {
309 0 : SolarMutexGuard aSolarGuard;
310 :
311 0 : return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
312 : }
313 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
314 : {
315 0 : SolarMutexGuard aSolarGuard;
316 :
317 0 : return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
318 : }
319 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
320 : {
321 0 : SolarMutexGuard aSolarGuard;
322 :
323 0 : return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
324 : }
325 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
326 : {
327 0 : SolarMutexGuard aSolarGuard;
328 :
329 0 : return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
330 : }
331 0 : sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
332 : {
333 0 : SolarMutexGuard aSolarGuard;
334 :
335 0 : OUString sText = implGetText();
336 0 : checkIndex_Impl( nStartIndex, sText );
337 0 : checkIndex_Impl( nEndIndex, sText );
338 :
339 : //!!! don't know how to put a string into the clipboard
340 0 : return sal_False;
341 : }
342 :
343 0 : Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
344 : {
345 0 : Window* pParent = m_aTable.GetAccessibleParentWindow();
346 : DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
347 0 : Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( pParent );
348 0 : sal_Int32 nIndex = getAccessibleIndexInParent();
349 0 : Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
350 0 : long nX = aGridRect.Left() + aCellRect.Left();
351 0 : long nY = aGridRect.Top() + aCellRect.Top();
352 0 : Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
353 0 : return aCell;
354 : }
355 :
356 0 : Rectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
357 : {
358 0 : Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( NULL );
359 0 : sal_Int32 nIndex = getAccessibleIndexInParent();
360 0 : Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
361 0 : long nX = aGridRect.Left() + aCellRect.Left();
362 0 : long nY = aGridRect.Top() + aCellRect.Top();
363 0 : Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
364 0 : return aCell;
365 : }
366 : }
367 :
368 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|