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