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/AccessibleEventId.hpp>
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
, const OUString
& _sText
)
35 if ( _nIndex
>= _sText
.getLength() )
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
;
46 using namespace comphelper
;
47 using namespace ::com::sun::star::uno
;
48 using ::com::sun::star::accessibility::XAccessible
;
49 using namespace ::com::sun::star::accessibility
;
52 // implementation of a table cell
53 OUString
AccessibleBrowseBoxTableCell::implGetText()
55 return mpBrowseBox
->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
58 css::lang::Locale
AccessibleBrowseBoxTableCell::implGetLocale()
60 return mpBrowseBox
->GetAccessible()->getAccessibleContext()->getLocale();
63 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
69 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference
<XAccessible
>& _rxParent
,
70 vcl::IAccessibleTableProvider
& _rBrowseBox
,
71 const css::uno::Reference
< css::awt::XWindow
>& _xFocusWindow
,
75 :AccessibleBrowseBoxCell( _rxParent
, _rBrowseBox
, _xFocusWindow
, _nRowPos
, _nColPos
)
77 m_nOffset
= ( _nOffset
== OFFSET_DEFAULT
) ? sal_Int32(vcl::BBINDEX_FIRSTCONTROL
) : _nOffset
;
78 sal_Int32 nIndex
= getIndex_Impl( _nRowPos
, _nColPos
, _rBrowseBox
.GetColumnCount() );
79 setAccessibleName( _rBrowseBox
.GetAccessibleObjectName( vcl::BBTYPE_TABLECELL
, nIndex
) );
80 setAccessibleDescription( _rBrowseBox
.GetAccessibleObjectDescription( vcl::BBTYPE_TABLECELL
, nIndex
) );
81 // Need to register as event listener
82 Reference
< XComponent
> xComponent(_rxParent
, UNO_QUERY
);
84 xComponent
->addEventListener(static_cast< XEventListener
*> (this));
87 void AccessibleBrowseBoxTableCell::nameChanged( const OUString
& rNewName
, const OUString
& rOldName
)
89 implSetName( rNewName
);
90 Any aOldValue
, aNewValue
;
91 aOldValue
<<= rOldName
;
92 aNewValue
<<= rNewName
;
93 commitEvent( AccessibleEventId::NAME_CHANGED
, aNewValue
, aOldValue
);
96 // XInterface -------------------------------------------------------------
98 /** Queries for a new interface. */
99 css::uno::Any SAL_CALL
AccessibleBrowseBoxTableCell::queryInterface( const css::uno::Type
& rType
)
101 Any aRet
= AccessibleBrowseBoxCell::queryInterface(rType
);
102 if ( !aRet
.hasValue() )
103 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
107 /** Acquires the object (calls acquire() on base class). */
108 void SAL_CALL
AccessibleBrowseBoxTableCell::acquire() throw ()
110 AccessibleBrowseBoxCell::acquire();
113 /** Releases the object (calls release() on base class). */
114 void SAL_CALL
AccessibleBrowseBoxTableCell::release() throw ()
116 AccessibleBrowseBoxCell::release();
119 css::awt::Rectangle SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex
)
121 SolarMethodGuard
aGuard(getMutex());
124 css::awt::Rectangle aRect
;
128 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
129 throw IndexOutOfBoundsException();
131 aRect
= AWTRectangle( mpBrowseBox
->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex
) );
137 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point
& _aPoint
)
140 // OSL_FAIL("Need to be done by base class!");
141 SolarMethodGuard
aGuard(getMutex());
144 return mpBrowseBox
->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint
) );
148 The name of this class.
150 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getImplementationName()
152 return "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell";
155 /** @return The count of visible children. */
156 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleChildCount()
161 /** @return The XAccessible interface of the specified child. */
162 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
163 AccessibleBrowseBoxTableCell::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
* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
175 SolarMethodGuard
aGuard(getMutex());
177 ::utl::AccessibleStateSetHelper
* pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
181 // SHOWING done with mxParent
182 if( implIsShowing() )
183 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
185 mpBrowseBox
->FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
188 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
190 return pStateSetHelper
;
194 // XAccessible ------------------------------------------------------------
196 /** @return The XAccessibleContext interface of this object. */
197 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleContext()
199 osl::MutexGuard
aGuard( getMutex() );
204 // XAccessibleContext -----------------------------------------------------
206 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
208 SolarMethodGuard
aGuard(getMutex());
211 return /*vcl::BBINDEX_FIRSTCONTROL*/ m_nOffset
+ ( getRowPos() * mpBrowseBox
->GetColumnCount() ) + getColumnPos();
214 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCaretPosition( )
219 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex
)
221 SolarMethodGuard
aGuard(getMutex());
224 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
225 throw IndexOutOfBoundsException();
229 sal_Unicode SAL_CALL
AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex
)
231 SolarMethodGuard
aGuard(getMutex());
234 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
236 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
238 SolarMethodGuard
aGuard(getMutex());
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
AccessibleBrowseBoxTableCell::getCharacterCount( )
250 SolarMethodGuard
aGuard(getMutex());
253 return implGetText().getLength();
256 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getSelectedText( )
258 SolarMethodGuard
aGuard(getMutex());
261 return OCommonAccessibleText::getSelectedText( );
263 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionStart( )
265 SolarMethodGuard
aGuard(getMutex());
268 return OCommonAccessibleText::getSelectionStart( );
270 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionEnd( )
272 SolarMethodGuard
aGuard(getMutex());
275 return OCommonAccessibleText::getSelectionEnd( );
277 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
279 SolarMethodGuard
aGuard(getMutex());
282 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
283 throw IndexOutOfBoundsException();
287 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getText( )
289 SolarMethodGuard
aGuard(getMutex());
292 return implGetText( );
294 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
296 SolarMethodGuard
aGuard(getMutex());
299 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
301 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
303 SolarMethodGuard
aGuard(getMutex());
306 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
308 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
310 SolarMethodGuard
aGuard(getMutex());
313 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
315 css::accessibility::TextSegment SAL_CALL
AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
317 SolarMethodGuard
aGuard(getMutex());
320 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
322 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
324 SolarMethodGuard
aGuard(getMutex());
327 OUString sText
= implGetText();
328 checkIndex_Impl( nStartIndex
, sText
);
329 checkIndex_Impl( nEndIndex
, sText
);
331 //!!! don't know how to put a string into the clipboard
334 void AccessibleBrowseBoxTableCell::disposing( const EventObject
& _rSource
)
336 if ( _rSource
.Source
== mxParent
)
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */