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 )
81 : {
82 0 : SolarMutexGuard aSolarGuard;
83 0 : ::osl::MutexGuard aGuard( getOslMutex() );
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 )
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)
141 : {
142 0 : SolarMutexGuard aSolarGuard;
143 0 : ::osl::MutexGuard aGuard( getOslMutex() );
144 :
145 0 : ensureIsAlive();
146 0 : if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
147 0 : throw IndexOutOfBoundsException();
148 :
149 0 : ::com::sun::star::awt::Rectangle aRect;
150 :
151 0 : if ( &m_aTable )
152 0 : aRect = AWTRectangle( m_aTable.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
153 0 : return aRect;
154 : }
155 :
156 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException)
157 : {
158 0 : SolarMutexGuard aSolarGuard;
159 0 : ::osl::MutexGuard aGuard( getOslMutex() );
160 0 : ensureIsAlive();
161 :
162 0 : return m_aTable.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
163 : }
164 :
165 : /** @return
166 : The name of this class.
167 : */
168 0 : OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName()
169 : throw ( ::com::sun::star::uno::RuntimeException )
170 : {
171 0 : return OUString( "com.sun.star.accessibility.AccessibleGridControlTableCell" );
172 : }
173 :
174 : /** @return The count of visible children. */
175 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount()
176 : throw ( ::com::sun::star::uno::RuntimeException )
177 : {
178 0 : return 0;
179 : }
180 :
181 : /** @return The XAccessible interface of the specified child. */
182 : ::com::sun::star::uno::Reference<
183 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
184 0 : AccessibleGridControlTableCell::getAccessibleChild( sal_Int32 )
185 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
186 : ::com::sun::star::uno::RuntimeException )
187 : {
188 0 : throw ::com::sun::star::lang::IndexOutOfBoundsException();
189 : }
190 :
191 : /** Creates a new AccessibleStateSetHelper and fills it with states of the
192 : current object.
193 : @return
194 : A filled AccessibleStateSetHelper.
195 : */
196 0 : ::utl::AccessibleStateSetHelper* AccessibleGridControlTableCell::implCreateStateSetHelper()
197 : {
198 0 : SolarMutexGuard aSolarGuard;
199 0 : ::osl::MutexGuard aGuard( getOslMutex() );
200 :
201 0 : ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
202 :
203 0 : if( isAlive() )
204 : {
205 : // SHOWING done with mxParent
206 0 : if( implIsShowing() )
207 0 : pStateSetHelper->AddState( AccessibleStateType::SHOWING );
208 :
209 0 : m_aTable.FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
210 : }
211 : else
212 0 : pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
213 :
214 0 : return pStateSetHelper;
215 : }
216 :
217 :
218 : // XAccessible ------------------------------------------------------------
219 :
220 : /** @return The XAccessibleContext interface of this object. */
221 0 : Reference< XAccessibleContext > SAL_CALL AccessibleGridControlTableCell::getAccessibleContext() throw ( RuntimeException )
222 : {
223 0 : ensureIsAlive();
224 0 : return this;
225 : }
226 :
227 : // XAccessibleContext -----------------------------------------------------
228 :
229 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent()
230 : throw ( ::com::sun::star::uno::RuntimeException )
231 : {
232 0 : SolarMutexGuard aSolarGuard;
233 0 : ::osl::MutexGuard aGuard( getOslMutex() );
234 0 : ensureIsAlive();
235 :
236 0 : return ( getRowPos() * m_aTable.GetColumnCount() ) + getColumnPos();
237 : }
238 :
239 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException)
240 : {
241 0 : return -1;
242 : }
243 0 : sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
244 : {
245 0 : SolarMutexGuard aSolarGuard;
246 0 : ::osl::MutexGuard aGuard( getOslMutex() );
247 :
248 0 : if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
249 0 : throw IndexOutOfBoundsException();
250 :
251 0 : return sal_False;
252 : }
253 0 : sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
254 : {
255 0 : SolarMutexGuard aSolarGuard;
256 0 : ::osl::MutexGuard aGuard( getOslMutex() );
257 0 : return OCommonAccessibleText::getCharacter( nIndex );
258 : }
259 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)
260 : {
261 0 : SolarMutexGuard aSolarGuard;
262 0 : ::osl::MutexGuard aGuard( getOslMutex() );
263 :
264 0 : OUString sText( implGetText() );
265 :
266 0 : if ( !implIsValidIndex( nIndex, sText.getLength() ) )
267 0 : throw IndexOutOfBoundsException();
268 :
269 0 : return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
270 : }
271 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException)
272 : {
273 0 : SolarMutexGuard aSolarGuard;
274 0 : ::osl::MutexGuard aGuard( getOslMutex() );
275 0 : return OCommonAccessibleText::getCharacterCount( );
276 : }
277 :
278 0 : OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException)
279 : {
280 0 : SolarMutexGuard aSolarGuard;
281 0 : ::osl::MutexGuard aGuard( getOslMutex() );
282 0 : return OCommonAccessibleText::getSelectedText( );
283 : }
284 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException)
285 : {
286 0 : SolarMutexGuard aSolarGuard;
287 0 : ::osl::MutexGuard aGuard( getOslMutex() );
288 0 : return OCommonAccessibleText::getSelectionStart( );
289 : }
290 0 : sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException)
291 : {
292 0 : SolarMutexGuard aSolarGuard;
293 0 : ::osl::MutexGuard aGuard( getOslMutex() );
294 0 : return OCommonAccessibleText::getSelectionEnd( );
295 : }
296 0 : sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
297 : {
298 0 : SolarMutexGuard aSolarGuard;
299 0 : ::osl::MutexGuard aGuard( getOslMutex() );
300 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
301 0 : throw IndexOutOfBoundsException();
302 :
303 0 : return sal_False;
304 : }
305 0 : OUString SAL_CALL AccessibleGridControlTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException)
306 : {
307 0 : SolarMutexGuard aSolarGuard;
308 0 : ::osl::MutexGuard aGuard( getOslMutex() );
309 0 : return OCommonAccessibleText::getText( );
310 : }
311 0 : OUString SAL_CALL AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
312 : {
313 0 : SolarMutexGuard aSolarGuard;
314 0 : ::osl::MutexGuard aGuard( getOslMutex() );
315 0 : return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
316 : }
317 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)
318 : {
319 0 : SolarMutexGuard aSolarGuard;
320 0 : ::osl::MutexGuard aGuard( getOslMutex() );
321 0 : return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
322 : }
323 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)
324 : {
325 0 : SolarMutexGuard aSolarGuard;
326 0 : ::osl::MutexGuard aGuard( getOslMutex() );
327 0 : return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
328 : }
329 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)
330 : {
331 0 : SolarMutexGuard aSolarGuard;
332 0 : ::osl::MutexGuard aGuard( getOslMutex() );
333 0 : return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
334 : }
335 0 : sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
336 : {
337 0 : SolarMutexGuard aSolarGuard;
338 0 : ::osl::MutexGuard aGuard( getOslMutex() );
339 0 : OUString sText = implGetText();
340 0 : checkIndex_Impl( nStartIndex, sText );
341 0 : checkIndex_Impl( nEndIndex, sText );
342 :
343 : //!!! don't know how to put a string into the clipboard
344 0 : return sal_False;
345 : }
346 :
347 0 : Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
348 : {
349 0 : Window* pParent = m_aTable.GetAccessibleParentWindow();
350 : DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
351 0 : Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( pParent );
352 0 : sal_Int32 nIndex = getAccessibleIndexInParent();
353 0 : Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
354 0 : long nX = aGridRect.Left() + aCellRect.Left();
355 0 : long nY = aGridRect.Top() + aCellRect.Top();
356 0 : Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
357 0 : return aCell;
358 : }
359 : // -----------------------------------------------------------------------------
360 0 : Rectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
361 : {
362 0 : Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( NULL );
363 0 : sal_Int32 nIndex = getAccessibleIndexInParent();
364 0 : Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
365 0 : long nX = aGridRect.Left() + aCellRect.Left();
366 0 : long nY = aGridRect.Top() + aCellRect.Top();
367 0 : Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
368 0 : return aCell;
369 : }
370 : }
371 :
372 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|