Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
22 : #include <svtools/accessibletableprovider.hxx>
23 : #include "accessibility/extended/AccessibleBrowseBox.hxx"
24 : #include <toolkit/helper/vclunohelper.hxx>
25 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 :
27 : namespace accessibility
28 : {
29 : namespace
30 : {
31 0 : static void checkIndex_Impl( sal_Int32 _nIndex, const OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
32 : {
33 0 : if ( _nIndex >= _sText.getLength() )
34 0 : throw ::com::sun::star::lang::IndexOutOfBoundsException();
35 0 : }
36 :
37 0 : static sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
38 : {
39 0 : return _nRow * _nColumnCount + _nColumn;
40 : }
41 : }
42 : using namespace ::com::sun::star::lang;
43 : using namespace utl;
44 : using namespace comphelper;
45 : using ::accessibility::AccessibleBrowseBox;
46 : using namespace ::com::sun::star::uno;
47 : using ::com::sun::star::accessibility::XAccessible;
48 : using namespace ::com::sun::star::accessibility;
49 : using namespace ::svt;
50 :
51 :
52 : // implementation of a table cell
53 0 : OUString AccessibleBrowseBoxTableCell::implGetText()
54 : {
55 0 : ensureIsAlive();
56 0 : return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
57 : }
58 :
59 0 : ::com::sun::star::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale()
60 : {
61 0 : ensureIsAlive();
62 0 : return mpBrowseBox->GetAccessible()->getAccessibleContext()->getLocale();
63 : }
64 :
65 0 : void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
66 : {
67 0 : nStartIndex = 0;
68 0 : nEndIndex = 0;
69 0 : }
70 :
71 0 : AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference<XAccessible >& _rxParent,
72 : IAccessibleTableProvider& _rBrowseBox,
73 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
74 : sal_Int32 _nRowPos,
75 : sal_uInt16 _nColPos,
76 : sal_Int32 _nOffset )
77 0 : :AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos )
78 : {
79 0 : m_nOffset = ( OFFSET_DEFAULT == _nOffset ) ? (sal_Int32)BBINDEX_FIRSTCONTROL : _nOffset;
80 0 : sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() );
81 0 : setAccessibleName( _rBrowseBox.GetAccessibleObjectName( BBTYPE_TABLECELL, nIndex ) );
82 0 : setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( BBTYPE_TABLECELL, nIndex ) );
83 : // Need to register as event listener
84 0 : Reference< XComponent > xComponent(_rxParent, UNO_QUERY);
85 0 : if( xComponent.is() )
86 0 : xComponent->addEventListener(static_cast< XEventListener *> (this));
87 0 : }
88 :
89 0 : void AccessibleBrowseBoxTableCell::nameChanged( const OUString& rNewName, const OUString& rOldName )
90 : {
91 0 : implSetName( rNewName );
92 0 : Any aOldValue, aNewValue;
93 0 : aOldValue <<= rOldName;
94 0 : aNewValue <<= rNewName;
95 0 : commitEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
96 0 : }
97 :
98 : // XInterface -------------------------------------------------------------
99 :
100 : /** Queries for a new interface. */
101 0 : ::com::sun::star::uno::Any SAL_CALL AccessibleBrowseBoxTableCell::queryInterface(
102 : const ::com::sun::star::uno::Type& rType )
103 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
104 : {
105 0 : Any aRet = AccessibleBrowseBoxCell::queryInterface(rType);
106 0 : if ( !aRet.hasValue() )
107 0 : aRet = AccessibleTextHelper_BASE::queryInterface(rType);
108 0 : return aRet;
109 : }
110 :
111 : /** Aquires the object (calls acquire() on base class). */
112 0 : void SAL_CALL AccessibleBrowseBoxTableCell::acquire() throw ()
113 : {
114 0 : AccessibleBrowseBoxCell::acquire();
115 0 : }
116 :
117 : /** Releases the object (calls release() on base class). */
118 0 : void SAL_CALL AccessibleBrowseBoxTableCell::release() throw ()
119 : {
120 0 : AccessibleBrowseBoxCell::release();
121 0 : }
122 :
123 0 : ::com::sun::star::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
124 : {
125 0 : SolarMutexGuard aSolarGuard;
126 0 : ::osl::MutexGuard aGuard( getOslMutex() );
127 :
128 0 : ensureIsAlive();
129 0 : if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
130 0 : throw IndexOutOfBoundsException();
131 :
132 0 : ::com::sun::star::awt::Rectangle aRect;
133 :
134 0 : if ( mpBrowseBox )
135 : {
136 0 : aRect = AWTRectangle( mpBrowseBox->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
137 : }
138 :
139 0 : return aRect;
140 : }
141 :
142 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException, std::exception)
143 : {
144 : //! TODO CTL bidi
145 : // OSL_FAIL("Need to be done by base class!");
146 0 : SolarMutexGuard aSolarGuard;
147 0 : ::osl::MutexGuard aGuard( getOslMutex() );
148 0 : ensureIsAlive();
149 :
150 0 : return mpBrowseBox->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
151 : }
152 :
153 : /** @return
154 : The name of this class.
155 : */
156 0 : OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
157 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
158 : {
159 0 : return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" );
160 : }
161 :
162 : /** @return The count of visible children. */
163 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
164 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
165 : {
166 0 : return 0;
167 : }
168 :
169 : /** @return The XAccessible interface of the specified child. */
170 : ::com::sun::star::uno::Reference<
171 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
172 0 : AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32 )
173 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
174 : ::com::sun::star::uno::RuntimeException, std::exception )
175 : {
176 0 : throw ::com::sun::star::lang::IndexOutOfBoundsException();
177 : }
178 :
179 : /** Creates a new AccessibleStateSetHelper and fills it with states of the
180 : current object.
181 : @return
182 : A filled AccessibleStateSetHelper.
183 : */
184 0 : ::utl::AccessibleStateSetHelper* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
185 : {
186 0 : SolarMutexGuard aSolarGuard;
187 0 : ::osl::MutexGuard aGuard( getOslMutex() );
188 :
189 0 : ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
190 :
191 0 : if( isAlive() )
192 : {
193 : // SHOWING done with mxParent
194 0 : if( implIsShowing() )
195 0 : pStateSetHelper->AddState( AccessibleStateType::SHOWING );
196 :
197 0 : mpBrowseBox->FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
198 : }
199 : else
200 0 : pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
201 :
202 0 : return pStateSetHelper;
203 : }
204 :
205 :
206 : // XAccessible ------------------------------------------------------------
207 :
208 : /** @return The XAccessibleContext interface of this object. */
209 0 : Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext() throw ( RuntimeException, std::exception )
210 : {
211 0 : ensureIsAlive();
212 0 : return this;
213 : }
214 :
215 : // XAccessibleContext -----------------------------------------------------
216 :
217 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
218 : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
219 : {
220 0 : SolarMutexGuard aSolarGuard;
221 0 : ::osl::MutexGuard aGuard( getOslMutex() );
222 0 : ensureIsAlive();
223 :
224 0 : return /*BBINDEX_FIRSTCONTROL*/ m_nOffset + ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
225 : }
226 :
227 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
228 : {
229 0 : return -1;
230 : }
231 0 : sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
232 : {
233 0 : SolarMutexGuard aSolarGuard;
234 0 : ::osl::MutexGuard aGuard( getOslMutex() );
235 :
236 0 : if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
237 0 : throw IndexOutOfBoundsException();
238 :
239 0 : return sal_False;
240 : }
241 0 : sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
242 : {
243 0 : SolarMutexGuard aSolarGuard;
244 0 : ::osl::MutexGuard aGuard( getOslMutex() );
245 0 : return OCommonAccessibleText::getCharacter( nIndex );
246 : }
247 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
248 : {
249 0 : SolarMutexGuard aSolarGuard;
250 0 : ::osl::MutexGuard aGuard( getOslMutex() );
251 :
252 0 : OUString sText( implGetText() );
253 :
254 0 : if ( !implIsValidIndex( nIndex, sText.getLength() ) )
255 0 : throw IndexOutOfBoundsException();
256 :
257 0 : return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
258 : }
259 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
260 : {
261 0 : SolarMutexGuard aSolarGuard;
262 0 : ::osl::MutexGuard aGuard( getOslMutex() );
263 0 : return OCommonAccessibleText::getCharacterCount( );
264 : }
265 :
266 0 : OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
267 : {
268 0 : SolarMutexGuard aSolarGuard;
269 0 : ::osl::MutexGuard aGuard( getOslMutex() );
270 0 : return OCommonAccessibleText::getSelectedText( );
271 : }
272 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
273 : {
274 0 : SolarMutexGuard aSolarGuard;
275 0 : ::osl::MutexGuard aGuard( getOslMutex() );
276 0 : return OCommonAccessibleText::getSelectionStart( );
277 : }
278 0 : sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
279 : {
280 0 : SolarMutexGuard aSolarGuard;
281 0 : ::osl::MutexGuard aGuard( getOslMutex() );
282 0 : return OCommonAccessibleText::getSelectionEnd( );
283 : }
284 0 : sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
285 : {
286 0 : SolarMutexGuard aSolarGuard;
287 0 : ::osl::MutexGuard aGuard( getOslMutex() );
288 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
289 0 : throw IndexOutOfBoundsException();
290 :
291 0 : return sal_False;
292 : }
293 0 : OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
294 : {
295 0 : SolarMutexGuard aSolarGuard;
296 0 : ::osl::MutexGuard aGuard( getOslMutex() );
297 0 : return OCommonAccessibleText::getText( );
298 : }
299 0 : OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
300 : {
301 0 : SolarMutexGuard aSolarGuard;
302 0 : ::osl::MutexGuard aGuard( getOslMutex() );
303 0 : return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
304 : }
305 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
306 : {
307 0 : SolarMutexGuard aSolarGuard;
308 0 : ::osl::MutexGuard aGuard( getOslMutex() );
309 0 : return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
310 : }
311 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
312 : {
313 0 : SolarMutexGuard aSolarGuard;
314 0 : ::osl::MutexGuard aGuard( getOslMutex() );
315 0 : return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
316 : }
317 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
318 : {
319 0 : SolarMutexGuard aSolarGuard;
320 0 : ::osl::MutexGuard aGuard( getOslMutex() );
321 0 : return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
322 : }
323 0 : sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
324 : {
325 0 : SolarMutexGuard aSolarGuard;
326 0 : ::osl::MutexGuard aGuard( getOslMutex() );
327 0 : OUString sText = implGetText();
328 0 : checkIndex_Impl( nStartIndex, sText );
329 0 : checkIndex_Impl( nEndIndex, sText );
330 :
331 : //!!! don't know how to put a string into the clipboard
332 0 : return sal_False;
333 : }
334 0 : void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException, std::exception)
335 : {
336 0 : if ( _rSource.Source == mxParent )
337 : {
338 0 : dispose();
339 : }
340 0 : }
341 :
342 : }
343 :
344 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|