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 .
21 #include <extended/AccessibleBrowseBoxTableCell.hxx>
23 #include <vcl/accessibletableprovider.hxx>
24 #include <vcl/unohelp.hxx>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 namespace accessibility
32 /// @throws css::lang::IndexOutOfBoundsException
33 void checkIndex_Impl( sal_Int32 _nIndex
, std::u16string_view _sText
)
35 if ( _nIndex
>= static_cast<sal_Int32
>(_sText
.size()) )
36 throw css::lang::IndexOutOfBoundsException();
39 sal_Int32
getIndex_Impl( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_uInt16 _nColumnCount
)
41 return _nRow
* _nColumnCount
+ _nColumn
;
44 using namespace ::com::sun::star::lang
;
45 using namespace comphelper
;
46 using namespace ::com::sun::star::uno
;
47 using ::com::sun::star::accessibility::XAccessible
;
48 using namespace ::com::sun::star::accessibility
;
51 // implementation of a table cell
52 OUString
AccessibleBrowseBoxTableCell::implGetText()
54 return mpBrowseBox
->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
57 css::lang::Locale
AccessibleBrowseBoxTableCell::implGetLocale()
59 return mpBrowseBox
->GetAccessible()->getAccessibleContext()->getLocale();
62 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
68 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference
<XAccessible
>& _rxParent
,
69 vcl::IAccessibleTableProvider
& _rBrowseBox
,
73 :AccessibleBrowseBoxCell(_rxParent
, _rBrowseBox
, nullptr, _nRowPos
, _nColPos
)
75 m_nOffset
= ( _nOffset
== OFFSET_DEFAULT
) ? sal_Int32(vcl::BBINDEX_FIRSTCONTROL
) : _nOffset
;
76 sal_Int32 nIndex
= getIndex_Impl( _nRowPos
, _nColPos
, _rBrowseBox
.GetColumnCount() );
77 setAccessibleName( _rBrowseBox
.GetAccessibleObjectName( AccessibleBrowseBoxObjType::TableCell
, nIndex
) );
78 setAccessibleDescription( _rBrowseBox
.GetAccessibleObjectDescription( AccessibleBrowseBoxObjType::TableCell
, nIndex
) );
79 // Need to register as event listener
80 Reference
< XComponent
> xComponent(_rxParent
, UNO_QUERY
);
82 xComponent
->addEventListener(static_cast< XEventListener
*> (this));
85 // XInterface -------------------------------------------------------------
87 /** Queries for a new interface. */
88 css::uno::Any SAL_CALL
AccessibleBrowseBoxTableCell::queryInterface( const css::uno::Type
& rType
)
90 Any aRet
= AccessibleBrowseBoxCell::queryInterface(rType
);
91 if ( !aRet
.hasValue() )
92 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
96 /** Acquires the object (calls acquire() on base class). */
97 void SAL_CALL
AccessibleBrowseBoxTableCell::acquire() noexcept
99 AccessibleBrowseBoxCell::acquire();
102 /** Releases the object (calls release() on base class). */
103 void SAL_CALL
AccessibleBrowseBoxTableCell::release() noexcept
105 AccessibleBrowseBoxCell::release();
108 css::awt::Rectangle SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex
)
110 SolarMethodGuard
aGuard(getMutex());
113 css::awt::Rectangle aRect
;
117 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
118 throw IndexOutOfBoundsException();
120 aRect
= vcl::unohelper::ConvertToAWTRect(
121 mpBrowseBox
->GetFieldCharacterBounds(getRowPos(), getColumnPos(), nIndex
));
127 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point
& _aPoint
)
130 // OSL_FAIL("Need to be done by base class!");
131 SolarMethodGuard
aGuard(getMutex());
134 return mpBrowseBox
->GetFieldIndexAtPoint(getRowPos(), getColumnPos(),
135 vcl::unohelper::ConvertToVCLPoint(_aPoint
));
139 The name of this class.
141 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getImplementationName()
143 return u
"com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell"_ustr
;
146 /** @return The count of visible children. */
147 sal_Int64 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleChildCount()
152 /** @return The XAccessible interface of the specified child. */
153 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
154 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int64
)
156 throw css::lang::IndexOutOfBoundsException();
159 /** Return a bitset of states of the current object.
161 sal_Int64
AccessibleBrowseBoxTableCell::implCreateStateSet()
163 SolarMethodGuard
aGuard(getMutex());
165 sal_Int64 nStateSet
= 0;
169 // SHOWING done with mxParent
170 if( implIsShowing() )
171 nStateSet
|= AccessibleStateType::SHOWING
;
173 mpBrowseBox
->FillAccessibleStateSetForCell( nStateSet
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
176 nStateSet
|= AccessibleStateType::DEFUNC
;
182 // XAccessible ------------------------------------------------------------
184 /** @return The XAccessibleContext interface of this object. */
185 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleContext()
187 osl::MutexGuard
aGuard( getMutex() );
192 // XAccessibleContext -----------------------------------------------------
194 sal_Int64 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
196 SolarMethodGuard
aGuard(getMutex());
199 return /*vcl::BBINDEX_FIRSTCONTROL*/ m_nOffset
+ (static_cast<sal_Int64
>(getRowPos()) * static_cast<sal_Int64
>(mpBrowseBox
->GetColumnCount())) + getColumnPos();
202 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCaretPosition( )
207 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex
)
209 SolarMethodGuard
aGuard(getMutex());
212 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
213 throw IndexOutOfBoundsException();
217 sal_Unicode SAL_CALL
AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex
)
219 SolarMethodGuard
aGuard(getMutex());
222 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
224 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
226 SolarMethodGuard
aGuard(getMutex());
229 OUString
sText( implGetText() );
231 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
232 throw IndexOutOfBoundsException();
234 return css::uno::Sequence
< css::beans::PropertyValue
>();
236 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterCount( )
238 SolarMethodGuard
aGuard(getMutex());
241 return implGetText().getLength();
244 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getSelectedText( )
246 SolarMethodGuard
aGuard(getMutex());
249 return OCommonAccessibleText::getSelectedText( );
251 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionStart( )
253 SolarMethodGuard
aGuard(getMutex());
256 return OCommonAccessibleText::getSelectionStart( );
258 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionEnd( )
260 SolarMethodGuard
aGuard(getMutex());
263 return OCommonAccessibleText::getSelectionEnd( );
265 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
267 SolarMethodGuard
aGuard(getMutex());
270 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
271 throw IndexOutOfBoundsException();
275 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getText( )
277 SolarMethodGuard
aGuard(getMutex());
280 return implGetText( );
282 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
284 SolarMethodGuard
aGuard(getMutex());
287 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
289 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
291 SolarMethodGuard
aGuard(getMutex());
294 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
296 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
298 SolarMethodGuard
aGuard(getMutex());
301 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
303 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
305 SolarMethodGuard
aGuard(getMutex());
308 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
310 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
312 SolarMethodGuard
aGuard(getMutex());
315 OUString sText
= implGetText();
316 checkIndex_Impl( nStartIndex
, sText
);
317 checkIndex_Impl( nEndIndex
, sText
);
319 //!!! don't know how to put a string into the clipboard
322 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
326 void AccessibleBrowseBoxTableCell::disposing( const EventObject
& _rSource
)
328 if ( _rSource
.Source
== mxParent
)
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */