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 <vcl/svapp.hxx>
23 #include <vcl/unohelp.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
, std::u16string_view _sText
)
38 if ( _nIndex
>= static_cast<sal_Int32
>(_sText
.size()) )
39 throw css::lang::IndexOutOfBoundsException();
42 using namespace ::com::sun::star::lang
;
43 using namespace comphelper
;
44 using namespace ::com::sun::star::uno
;
45 using ::com::sun::star::accessibility::XAccessible
;
46 using namespace ::com::sun::star::accessibility
;
47 using namespace ::vcl
;
48 using namespace ::vcl::table
;
51 // = AccessibleGridControlCell
54 AccessibleGridControlCell::AccessibleGridControlCell(
55 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, ::vcl::table::IAccessibleTable
& _rTable
,
56 sal_Int32 _nRowPos
, sal_uInt16 _nColPos
, ::vcl::table::AccessibleTableControlObjType _eType
)
57 :AccessibleGridControlBase( _rxParent
, _rTable
, _eType
)
58 ,m_nRowPos( _nRowPos
)
59 ,m_nColPos( _nColPos
)
61 assert(((m_eObjType
== AccessibleTableControlObjType::TABLECELL
)
62 || ((m_eObjType
== AccessibleTableControlObjType::ROWHEADERCELL
) && _nColPos
== 0)
63 || ((m_eObjType
== AccessibleTableControlObjType::COLUMNHEADERCELL
) && _nRowPos
== 0))
64 && "Unhandled table cell type");
67 void SAL_CALL
AccessibleGridControlCell::grabFocus()
69 SolarMutexGuard aSolarGuard
;
71 m_aTable
.GoToCell( m_nColPos
, m_nRowPos
);
74 OUString SAL_CALL
AccessibleGridControlCell::getAccessibleName()
79 return m_aTable
.GetAccessibleObjectName(m_eObjType
, m_nRowPos
, m_nColPos
);
82 // implementation of a table cell
83 OUString
AccessibleGridControlTableCell::implGetText()
86 return m_aTable
.GetAccessibleCellText( getRowPos(), getColumnPos() );
89 css::lang::Locale
AccessibleGridControlTableCell::implGetLocale()
92 return m_aTable
.GetAccessible()->getAccessibleContext()->getLocale();
95 void AccessibleGridControlTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
101 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const css::uno::Reference
<XAccessible
>& _rxParent
,
102 ::vcl::table::IAccessibleTable
& _rTable
,
105 :AccessibleGridControlCell(_rxParent
, _rTable
, _nRowPos
, _nColPos
, AccessibleTableControlObjType::TABLECELL
)
111 /** Queries for a new interface. */
112 css::uno::Any SAL_CALL
AccessibleGridControlTableCell::queryInterface(
113 const css::uno::Type
& rType
)
115 Any aRet
= AccessibleGridControlCell::queryInterface(rType
);
116 if ( !aRet
.hasValue() )
117 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
121 /** Acquires the object (calls acquire() on base class). */
122 void SAL_CALL
AccessibleGridControlTableCell::acquire() noexcept
124 AccessibleGridControlCell::acquire();
127 /** Releases the object (calls release() on base class). */
128 void SAL_CALL
AccessibleGridControlTableCell::release() noexcept
130 AccessibleGridControlCell::release();
133 css::awt::Rectangle SAL_CALL
AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex
)
135 SolarMutexGuard aSolarGuard
;
138 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
139 throw IndexOutOfBoundsException();
141 return vcl::unohelper::ConvertToAWTRect(
142 m_aTable
.GetFieldCharacterBounds(getRowPos(), getColumnPos(), nIndex
));
145 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getIndexAtPoint( const css::awt::Point
& _aPoint
)
147 SolarMutexGuard aSolarGuard
;
151 return m_aTable
.GetFieldIndexAtPoint(getRowPos(), getColumnPos(),
152 vcl::unohelper::ConvertToVCLPoint(_aPoint
));
156 The name of this class.
158 OUString SAL_CALL
AccessibleGridControlTableCell::getImplementationName()
160 return u
"com.sun.star.accessibility.AccessibleGridControlTableCell"_ustr
;
163 /** @return The count of visible children. */
164 sal_Int64 SAL_CALL
AccessibleGridControlTableCell::getAccessibleChildCount()
169 /** @return The css::accessibility::XAccessible interface of the specified child. */
170 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlTableCell::getAccessibleChild( sal_Int64
)
172 throw css::lang::IndexOutOfBoundsException();
175 /** Return a bitset of states of the current object.
177 sal_Int64
AccessibleGridControlTableCell::implCreateStateSet()
179 sal_Int64 nStateSet
= 0;
183 // SHOWING done with mxParent
184 if( implIsShowing() )
185 nStateSet
|= AccessibleStateType::SHOWING
;
187 m_aTable
.FillAccessibleStateSetForCell( nStateSet
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
190 nStateSet
|= AccessibleStateType::DEFUNC
;
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_Int64 SAL_CALL
AccessibleGridControlTableCell::getAccessibleIndexInParent()
211 SolarMutexGuard aSolarGuard
;
215 return (static_cast<sal_Int64
>(getRowPos()) * static_cast<sal_Int64
>(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( )
259 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionStart( )
263 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionEnd( )
267 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
269 SolarMutexGuard aSolarGuard
;
271 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
272 throw IndexOutOfBoundsException();
276 OUString SAL_CALL
AccessibleGridControlTableCell::getText( )
278 SolarMutexGuard aSolarGuard
;
280 return implGetText( );
282 OUString SAL_CALL
AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
284 SolarMutexGuard aSolarGuard
;
286 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
288 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
290 SolarMutexGuard aSolarGuard
;
292 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
294 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
296 SolarMutexGuard aSolarGuard
;
298 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
300 css::accessibility::TextSegment SAL_CALL
AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
302 SolarMutexGuard aSolarGuard
;
304 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
306 sal_Bool SAL_CALL
AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
308 SolarMutexGuard aSolarGuard
;
310 OUString sText
= implGetText();
311 checkIndex_Impl( nStartIndex
, sText
);
312 checkIndex_Impl( nEndIndex
, sText
);
314 //!!! don't know how to put a string into the clipboard
317 sal_Bool SAL_CALL
AccessibleGridControlTableCell::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
322 tools::Rectangle
AccessibleGridControlTableCell::implGetBoundingBox()
324 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
325 assert(pParent
&& "implGetBoundingBox - missing parent window");
326 tools::Rectangle aGridRect
= m_aTable
.GetWindowExtentsRelative( *pParent
);
327 sal_Int64 nIndex
= getAccessibleIndexInParent();
328 tools::Rectangle aCellRect
= m_aTable
.calcCellRect(nIndex
%m_aTable
.GetColumnCount(), nIndex
/m_aTable
.GetColumnCount());
329 tools::Long nX
= aGridRect
.Left() + aCellRect
.Left();
330 tools::Long nY
= aGridRect
.Top() + aCellRect
.Top();
331 tools::Rectangle
aCell( Point( nX
, nY
), aCellRect
.GetSize());
335 AbsoluteScreenPixelRectangle
AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
337 AbsoluteScreenPixelRectangle aGridRect
= m_aTable
.GetWindowExtentsAbsolute();
338 sal_Int64 nIndex
= getAccessibleIndexInParent();
339 tools::Rectangle aCellRect
= m_aTable
.calcCellRect(nIndex
%m_aTable
.GetColumnCount(), nIndex
/m_aTable
.GetColumnCount());
340 tools::Long nX
= aGridRect
.Left() + aCellRect
.Left();
341 tools::Long nY
= aGridRect
.Top() + aCellRect
.Top();
342 AbsoluteScreenPixelRectangle
aCell( AbsoluteScreenPixelPoint( nX
, nY
), aCellRect
.GetSize());
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */