1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <extended/AccessibleGridControlTableCell.hxx>
21 #include <vcl/accessibletable.hxx>
22 #include <tools/gen.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
25 namespace accessibility
29 // FIXME this is a copy'n'paste from
30 // source/extended/AccessibleBrowseBoxTableCell.cxx, get rid of that...
31 /// @throws css::lang::IndexOutOfBoundsException
32 void checkIndex_Impl( sal_Int32 _nIndex
, const OUString
& _sText
)
34 if ( _nIndex
>= _sText
.getLength() )
35 throw css::lang::IndexOutOfBoundsException();
38 using namespace ::com::sun::star::lang
;
40 using namespace comphelper
;
41 using namespace ::com::sun::star::uno
;
42 using ::com::sun::star::accessibility::XAccessible
;
43 using namespace ::com::sun::star::accessibility
;
44 using namespace ::vcl
;
45 using namespace ::vcl::table
;
48 // = AccessibleGridControlCell
51 AccessibleGridControlCell::AccessibleGridControlCell(
52 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, ::vcl::table::IAccessibleTable
& _rTable
,
53 sal_Int32 _nRowPos
, sal_uInt16 _nColPos
, ::vcl::table::AccessibleTableControlObjType _eType
)
54 :AccessibleGridControlBase( _rxParent
, _rTable
, _eType
)
55 ,m_nRowPos( _nRowPos
)
56 ,m_nColPos( _nColPos
)
58 // set accessible name here, because for that we need the position of the cell
59 // and so the base class isn't capable of doing this
61 if(_eType
== TCTYPE_TABLECELL
)
62 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_TABLECELL
, _nRowPos
, _nColPos
);
63 else if(_eType
== TCTYPE_ROWHEADERCELL
)
64 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_ROWHEADERCELL
, _nRowPos
, 0 );
65 else if(_eType
== TCTYPE_COLUMNHEADERCELL
)
66 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_COLUMNHEADERCELL
, 0, _nRowPos
);
67 implSetName( aAccName
);
70 void SAL_CALL
AccessibleGridControlCell::grabFocus()
72 SolarMutexGuard aSolarGuard
;
74 m_aTable
.GoToCell( m_nColPos
, m_nRowPos
);
77 // implementation of a table cell
78 OUString
AccessibleGridControlTableCell::implGetText()
81 return m_aTable
.GetAccessibleCellText( getRowPos(), getColumnPos() );
84 css::lang::Locale
AccessibleGridControlTableCell::implGetLocale()
87 return m_aTable
.GetAccessible()->getAccessibleContext()->getLocale();
90 void AccessibleGridControlTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
96 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const css::uno::Reference
<XAccessible
>& _rxParent
,
97 ::vcl::table::IAccessibleTable
& _rTable
,
100 :AccessibleGridControlCell( _rxParent
, _rTable
, _nRowPos
, _nColPos
, TCTYPE_TABLECELL
)
106 /** Queries for a new interface. */
107 css::uno::Any SAL_CALL
AccessibleGridControlTableCell::queryInterface(
108 const css::uno::Type
& rType
)
110 Any aRet
= AccessibleGridControlCell::queryInterface(rType
);
111 if ( !aRet
.hasValue() )
112 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
116 /** Acquires the object (calls acquire() on base class). */
117 void SAL_CALL
AccessibleGridControlTableCell::acquire() throw ()
119 AccessibleGridControlCell::acquire();
122 /** Releases the object (calls release() on base class). */
123 void SAL_CALL
AccessibleGridControlTableCell::release() throw ()
125 AccessibleGridControlCell::release();
128 css::awt::Rectangle SAL_CALL
AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex
)
130 SolarMutexGuard aSolarGuard
;
133 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
134 throw IndexOutOfBoundsException();
136 return AWTRectangle( m_aTable
.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex
) );
139 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getIndexAtPoint( const css::awt::Point
& _aPoint
)
141 SolarMutexGuard aSolarGuard
;
145 return m_aTable
.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint
) );
149 The name of this class.
151 OUString SAL_CALL
AccessibleGridControlTableCell::getImplementationName()
153 return OUString( "com.sun.star.accessibility.AccessibleGridControlTableCell" );
156 /** @return The count of visible children. */
157 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getAccessibleChildCount()
162 /** @return The css::accessibility::XAccessible interface of the specified child. */
163 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlTableCell::getAccessibleChild( sal_Int32
)
165 throw css::lang::IndexOutOfBoundsException();
168 /** Creates a new AccessibleStateSetHelper and fills it with states of the
171 A filled AccessibleStateSetHelper.
173 ::utl::AccessibleStateSetHelper
* AccessibleGridControlTableCell::implCreateStateSetHelper()
175 ::utl::AccessibleStateSetHelper
* pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
179 // SHOWING done with mxParent
180 if( implIsShowing() )
181 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
183 m_aTable
.FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
186 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
188 return pStateSetHelper
;
192 // css::accessibility::XAccessible
194 /** @return The css::accessibility::XAccessibleContext interface of this object. */
195 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
AccessibleGridControlTableCell::getAccessibleContext()
203 // css::accessibility::XAccessibleContext
205 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getAccessibleIndexInParent()
207 SolarMutexGuard aSolarGuard
;
211 return ( getRowPos() * m_aTable
.GetColumnCount() ) + getColumnPos();
214 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getCaretPosition( )
218 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex
)
220 SolarMutexGuard aSolarGuard
;
222 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
223 throw IndexOutOfBoundsException();
227 sal_Unicode SAL_CALL
AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex
)
229 SolarMutexGuard aSolarGuard
;
231 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
233 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
235 SolarMutexGuard aSolarGuard
;
237 OUString
sText( implGetText() );
239 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
240 throw IndexOutOfBoundsException();
242 return css::uno::Sequence
< css::beans::PropertyValue
>();
244 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getCharacterCount( )
246 SolarMutexGuard aSolarGuard
;
248 return implGetText().getLength();
251 OUString SAL_CALL
AccessibleGridControlTableCell::getSelectedText( )
253 SolarMutexGuard aSolarGuard
;
257 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionStart( )
259 SolarMutexGuard aSolarGuard
;
263 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionEnd( )
265 SolarMutexGuard aSolarGuard
;
269 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
271 SolarMutexGuard aSolarGuard
;
273 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
274 throw IndexOutOfBoundsException();
278 OUString SAL_CALL
AccessibleGridControlTableCell::getText( )
280 SolarMutexGuard aSolarGuard
;
282 return implGetText( );
284 OUString SAL_CALL
AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
286 SolarMutexGuard aSolarGuard
;
288 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
290 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
292 SolarMutexGuard aSolarGuard
;
294 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
296 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
298 SolarMutexGuard aSolarGuard
;
300 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
302 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
304 SolarMutexGuard aSolarGuard
;
306 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
308 sal_Bool SAL_CALL
AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
310 SolarMutexGuard aSolarGuard
;
312 OUString sText
= implGetText();
313 checkIndex_Impl( nStartIndex
, sText
);
314 checkIndex_Impl( nEndIndex
, sText
);
316 //!!! don't know how to put a string into the clipboard
320 tools::Rectangle
AccessibleGridControlTableCell::implGetBoundingBox()
322 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
323 DBG_ASSERT( pParent
, "implGetBoundingBox - missing parent window" );
324 tools::Rectangle aGridRect
= m_aTable
.GetWindowExtentsRelative( pParent
);
325 sal_Int32 nIndex
= getAccessibleIndexInParent();
326 tools::Rectangle aCellRect
= m_aTable
.calcCellRect(nIndex
%m_aTable
.GetColumnCount(), nIndex
/m_aTable
.GetColumnCount());
327 long nX
= aGridRect
.Left() + aCellRect
.Left();
328 long nY
= aGridRect
.Top() + aCellRect
.Top();
329 tools::Rectangle
aCell( Point( nX
, nY
), aCellRect
.GetSize());
333 tools::Rectangle
AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
335 tools::Rectangle aGridRect
= m_aTable
.GetWindowExtentsRelative( nullptr );
336 sal_Int32 nIndex
= getAccessibleIndexInParent();
337 tools::Rectangle aCellRect
= m_aTable
.calcCellRect(nIndex
%m_aTable
.GetColumnCount(), nIndex
/m_aTable
.GetColumnCount());
338 long nX
= aGridRect
.Left() + aCellRect
.Left();
339 long nY
= aGridRect
.Top() + aCellRect
.Top();
340 tools::Rectangle
aCell( Point( nX
, nY
), aCellRect
.GetSize());
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */