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>
22 #include <toolkit/helper/convert.hxx>
23 #include <vcl/accessibletableprovider.hxx>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 namespace accessibility
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 sal_Int32
getIndex_Impl( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_uInt16 _nColumnCount
)
40 return _nRow
* _nColumnCount
+ _nColumn
;
43 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
,
70 const css::uno::Reference
< css::awt::XWindow
>& _xFocusWindow
,
74 :AccessibleBrowseBoxCell( _rxParent
, _rBrowseBox
, _xFocusWindow
, _nRowPos
, _nColPos
)
76 m_nOffset
= ( _nOffset
== OFFSET_DEFAULT
) ? sal_Int32(vcl::BBINDEX_FIRSTCONTROL
) : _nOffset
;
77 sal_Int32 nIndex
= getIndex_Impl( _nRowPos
, _nColPos
, _rBrowseBox
.GetColumnCount() );
78 setAccessibleName( _rBrowseBox
.GetAccessibleObjectName( AccessibleBrowseBoxObjType::TableCell
, nIndex
) );
79 setAccessibleDescription( _rBrowseBox
.GetAccessibleObjectDescription( AccessibleBrowseBoxObjType::TableCell
, nIndex
) );
80 // Need to register as event listener
81 Reference
< XComponent
> xComponent(_rxParent
, UNO_QUERY
);
83 xComponent
->addEventListener(static_cast< XEventListener
*> (this));
86 // XInterface -------------------------------------------------------------
88 /** Queries for a new interface. */
89 css::uno::Any SAL_CALL
AccessibleBrowseBoxTableCell::queryInterface( const css::uno::Type
& rType
)
91 Any aRet
= AccessibleBrowseBoxCell::queryInterface(rType
);
92 if ( !aRet
.hasValue() )
93 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
97 /** Acquires the object (calls acquire() on base class). */
98 void SAL_CALL
AccessibleBrowseBoxTableCell::acquire() noexcept
100 AccessibleBrowseBoxCell::acquire();
103 /** Releases the object (calls release() on base class). */
104 void SAL_CALL
AccessibleBrowseBoxTableCell::release() noexcept
106 AccessibleBrowseBoxCell::release();
109 css::awt::Rectangle SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex
)
111 SolarMethodGuard
aGuard(getMutex());
114 css::awt::Rectangle aRect
;
118 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
119 throw IndexOutOfBoundsException();
121 aRect
= AWTRectangle( 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(), VCLPoint( _aPoint
) );
138 The name of this class.
140 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getImplementationName()
142 return "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell";
145 /** @return The count of visible children. */
146 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleChildCount()
151 /** @return The XAccessible interface of the specified child. */
152 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
153 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32
)
155 throw css::lang::IndexOutOfBoundsException();
158 /** Creates a new AccessibleStateSetHelper and fills it with states of the
161 A filled AccessibleStateSetHelper.
163 rtl::Reference
<::utl::AccessibleStateSetHelper
> AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
165 SolarMethodGuard
aGuard(getMutex());
167 rtl::Reference
<::utl::AccessibleStateSetHelper
> pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
171 // SHOWING done with mxParent
172 if( implIsShowing() )
173 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
175 mpBrowseBox
->FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
178 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
180 return pStateSetHelper
;
184 // XAccessible ------------------------------------------------------------
186 /** @return The XAccessibleContext interface of this object. */
187 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleContext()
189 osl::MutexGuard
aGuard( getMutex() );
194 // XAccessibleContext -----------------------------------------------------
196 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
198 SolarMethodGuard
aGuard(getMutex());
201 return /*vcl::BBINDEX_FIRSTCONTROL*/ m_nOffset
+ ( getRowPos() * mpBrowseBox
->GetColumnCount() ) + getColumnPos();
204 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCaretPosition( )
209 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex
)
211 SolarMethodGuard
aGuard(getMutex());
214 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
215 throw IndexOutOfBoundsException();
219 sal_Unicode SAL_CALL
AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex
)
221 SolarMethodGuard
aGuard(getMutex());
224 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
226 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
228 SolarMethodGuard
aGuard(getMutex());
231 OUString
sText( implGetText() );
233 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
234 throw IndexOutOfBoundsException();
236 return css::uno::Sequence
< css::beans::PropertyValue
>();
238 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterCount( )
240 SolarMethodGuard
aGuard(getMutex());
243 return implGetText().getLength();
246 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getSelectedText( )
248 SolarMethodGuard
aGuard(getMutex());
251 return OCommonAccessibleText::getSelectedText( );
253 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionStart( )
255 SolarMethodGuard
aGuard(getMutex());
258 return OCommonAccessibleText::getSelectionStart( );
260 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionEnd( )
262 SolarMethodGuard
aGuard(getMutex());
265 return OCommonAccessibleText::getSelectionEnd( );
267 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
269 SolarMethodGuard
aGuard(getMutex());
272 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
273 throw IndexOutOfBoundsException();
277 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getText( )
279 SolarMethodGuard
aGuard(getMutex());
282 return implGetText( );
284 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
286 SolarMethodGuard
aGuard(getMutex());
289 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
291 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
293 SolarMethodGuard
aGuard(getMutex());
296 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
298 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
300 SolarMethodGuard
aGuard(getMutex());
303 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
305 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
307 SolarMethodGuard
aGuard(getMutex());
310 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
312 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
314 SolarMethodGuard
aGuard(getMutex());
317 OUString sText
= implGetText();
318 checkIndex_Impl( nStartIndex
, sText
);
319 checkIndex_Impl( nEndIndex
, sText
);
321 //!!! don't know how to put a string into the clipboard
324 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
328 void AccessibleBrowseBoxTableCell::disposing( const EventObject
& _rSource
)
330 if ( _rSource
.Source
== mxParent
)
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */