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 <toolkit/helper/convert.hxx>
22 #include <vcl/accessibletable.hxx>
23 #include <vcl/svapp.hxx>
24 #include <tools/gen.hxx>
25 #include <tools/debug.hxx>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 namespace accessibility
33 // FIXME this is a copy'n'paste from
34 // source/extended/AccessibleBrowseBoxTableCell.cxx, get rid of that...
35 /// @throws css::lang::IndexOutOfBoundsException
36 void checkIndex_Impl( sal_Int32 _nIndex
, const OUString
& _sText
)
38 if ( _nIndex
>= _sText
.getLength() )
39 throw css::lang::IndexOutOfBoundsException();
42 using namespace ::com::sun::star::lang
;
44 using namespace comphelper
;
45 using namespace ::com::sun::star::uno
;
46 using ::com::sun::star::accessibility::XAccessible
;
47 using namespace ::com::sun::star::accessibility
;
48 using namespace ::vcl
;
49 using namespace ::vcl::table
;
52 // = AccessibleGridControlCell
55 AccessibleGridControlCell::AccessibleGridControlCell(
56 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, ::vcl::table::IAccessibleTable
& _rTable
,
57 sal_Int32 _nRowPos
, sal_uInt16 _nColPos
, ::vcl::table::AccessibleTableControlObjType _eType
)
58 :AccessibleGridControlBase( _rxParent
, _rTable
, _eType
)
59 ,m_nRowPos( _nRowPos
)
60 ,m_nColPos( _nColPos
)
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
65 if(_eType
== TCTYPE_TABLECELL
)
66 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_TABLECELL
, _nRowPos
, _nColPos
);
67 else if(_eType
== TCTYPE_ROWHEADERCELL
)
68 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_ROWHEADERCELL
, _nRowPos
, 0 );
69 else if(_eType
== TCTYPE_COLUMNHEADERCELL
)
70 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_COLUMNHEADERCELL
, 0, _nRowPos
);
71 implSetName( aAccName
);
74 void SAL_CALL
AccessibleGridControlCell::grabFocus()
76 SolarMutexGuard aSolarGuard
;
78 m_aTable
.GoToCell( m_nColPos
, m_nRowPos
);
81 // implementation of a table cell
82 OUString
AccessibleGridControlTableCell::implGetText()
85 return m_aTable
.GetAccessibleCellText( getRowPos(), getColumnPos() );
88 css::lang::Locale
AccessibleGridControlTableCell::implGetLocale()
91 return m_aTable
.GetAccessible()->getAccessibleContext()->getLocale();
94 void AccessibleGridControlTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
100 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const css::uno::Reference
<XAccessible
>& _rxParent
,
101 ::vcl::table::IAccessibleTable
& _rTable
,
104 :AccessibleGridControlCell( _rxParent
, _rTable
, _nRowPos
, _nColPos
, TCTYPE_TABLECELL
)
110 /** Queries for a new interface. */
111 css::uno::Any SAL_CALL
AccessibleGridControlTableCell::queryInterface(
112 const css::uno::Type
& rType
)
114 Any aRet
= AccessibleGridControlCell::queryInterface(rType
);
115 if ( !aRet
.hasValue() )
116 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
120 /** Acquires the object (calls acquire() on base class). */
121 void SAL_CALL
AccessibleGridControlTableCell::acquire() noexcept
123 AccessibleGridControlCell::acquire();
126 /** Releases the object (calls release() on base class). */
127 void SAL_CALL
AccessibleGridControlTableCell::release() noexcept
129 AccessibleGridControlCell::release();
132 css::awt::Rectangle SAL_CALL
AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex
)
134 SolarMutexGuard aSolarGuard
;
137 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
138 throw IndexOutOfBoundsException();
140 return AWTRectangle( m_aTable
.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex
) );
143 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getIndexAtPoint( const css::awt::Point
& _aPoint
)
145 SolarMutexGuard aSolarGuard
;
149 return m_aTable
.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint
) );
153 The name of this class.
155 OUString SAL_CALL
AccessibleGridControlTableCell::getImplementationName()
157 return "com.sun.star.accessibility.AccessibleGridControlTableCell";
160 /** @return The count of visible children. */
161 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getAccessibleChildCount()
166 /** @return The css::accessibility::XAccessible interface of the specified child. */
167 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlTableCell::getAccessibleChild( sal_Int32
)
169 throw css::lang::IndexOutOfBoundsException();
172 /** Creates a new AccessibleStateSetHelper and fills it with states of the
175 A filled AccessibleStateSetHelper.
177 rtl::Reference
<::utl::AccessibleStateSetHelper
> AccessibleGridControlTableCell::implCreateStateSetHelper()
179 rtl::Reference
<::utl::AccessibleStateSetHelper
> pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
183 // SHOWING done with mxParent
184 if( implIsShowing() )
185 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
187 m_aTable
.FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
190 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
192 return pStateSetHelper
;
196 // css::accessibility::XAccessible
198 /** @return The css::accessibility::XAccessibleContext interface of this object. */
199 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
AccessibleGridControlTableCell::getAccessibleContext()
207 // css::accessibility::XAccessibleContext
209 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getAccessibleIndexInParent()
211 SolarMutexGuard aSolarGuard
;
215 return ( getRowPos() * m_aTable
.GetColumnCount() ) + getColumnPos();
218 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getCaretPosition( )
222 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex
)
224 SolarMutexGuard aSolarGuard
;
226 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
227 throw IndexOutOfBoundsException();
231 sal_Unicode SAL_CALL
AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex
)
233 SolarMutexGuard aSolarGuard
;
235 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
237 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
239 SolarMutexGuard aSolarGuard
;
241 OUString
sText( implGetText() );
243 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
244 throw IndexOutOfBoundsException();
246 return css::uno::Sequence
< css::beans::PropertyValue
>();
248 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getCharacterCount( )
250 SolarMutexGuard aSolarGuard
;
252 return implGetText().getLength();
255 OUString SAL_CALL
AccessibleGridControlTableCell::getSelectedText( )
257 SolarMutexGuard aSolarGuard
;
261 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionStart( )
263 SolarMutexGuard aSolarGuard
;
267 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionEnd( )
269 SolarMutexGuard aSolarGuard
;
273 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
275 SolarMutexGuard aSolarGuard
;
277 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
278 throw IndexOutOfBoundsException();
282 OUString SAL_CALL
AccessibleGridControlTableCell::getText( )
284 SolarMutexGuard aSolarGuard
;
286 return implGetText( );
288 OUString SAL_CALL
AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
290 SolarMutexGuard aSolarGuard
;
292 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
294 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
296 SolarMutexGuard aSolarGuard
;
298 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
300 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
302 SolarMutexGuard aSolarGuard
;
304 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
306 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
308 SolarMutexGuard aSolarGuard
;
310 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
312 sal_Bool SAL_CALL
AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
314 SolarMutexGuard aSolarGuard
;
316 OUString sText
= implGetText();
317 checkIndex_Impl( nStartIndex
, sText
);
318 checkIndex_Impl( nEndIndex
, sText
);
320 //!!! don't know how to put a string into the clipboard
323 sal_Bool SAL_CALL
AccessibleGridControlTableCell::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
328 tools::Rectangle
AccessibleGridControlTableCell::implGetBoundingBox()
330 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
331 DBG_ASSERT( pParent
, "implGetBoundingBox - missing parent window" );
332 tools::Rectangle aGridRect
= m_aTable
.GetWindowExtentsRelative( pParent
);
333 sal_Int32 nIndex
= getAccessibleIndexInParent();
334 tools::Rectangle aCellRect
= m_aTable
.calcCellRect(nIndex
%m_aTable
.GetColumnCount(), nIndex
/m_aTable
.GetColumnCount());
335 tools::Long nX
= aGridRect
.Left() + aCellRect
.Left();
336 tools::Long nY
= aGridRect
.Top() + aCellRect
.Top();
337 tools::Rectangle
aCell( Point( nX
, nY
), aCellRect
.GetSize());
341 tools::Rectangle
AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
343 tools::Rectangle aGridRect
= m_aTable
.GetWindowExtentsRelative( nullptr );
344 sal_Int32 nIndex
= getAccessibleIndexInParent();
345 tools::Rectangle aCellRect
= m_aTable
.calcCellRect(nIndex
%m_aTable
.GetColumnCount(), nIndex
/m_aTable
.GetColumnCount());
346 tools::Long nX
= aGridRect
.Left() + aCellRect
.Left();
347 tools::Long nY
= aGridRect
.Top() + aCellRect
.Top();
348 tools::Rectangle
aCell( Point( nX
, nY
), aCellRect
.GetSize());
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */