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 : #include "accessibility/extended/accessiblelistboxentry.hxx"
21 : #include <svtools/treelistbox.hxx>
22 : #include <svtools/stringtransfer.hxx>
23 : #include <com/sun/star/awt/Point.hpp>
24 : #include <com/sun/star/awt/Rectangle.hpp>
25 : #include <com/sun/star/awt/Size.hpp>
26 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
28 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
29 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 : #include <vcl/svapp.hxx>
31 : #include <vcl/controllayout.hxx>
32 : #include <toolkit/awt/vclxwindow.hxx>
33 : #include <toolkit/helper/convert.hxx>
34 : #include <unotools/accessiblestatesethelper.hxx>
35 : #include <unotools/accessiblerelationsethelper.hxx>
36 : #include <cppuhelper/supportsservice.hxx>
37 : #include <cppuhelper/typeprovider.hxx>
38 : #include <comphelper/sequence.hxx>
39 : #include <comphelper/accessibleeventnotifier.hxx>
40 : #include <toolkit/helper/vclunohelper.hxx>
41 :
42 : #define ACCESSIBLE_ACTION_COUNT 1
43 :
44 : namespace
45 : {
46 0 : void checkActionIndex_Impl( sal_Int32 _nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
47 : {
48 0 : if ( _nIndex < 0 || _nIndex >= ACCESSIBLE_ACTION_COUNT )
49 : // only three actions
50 0 : throw ::com::sun::star::lang::IndexOutOfBoundsException();
51 0 : }
52 : }
53 :
54 : //........................................................................
55 : namespace accessibility
56 : {
57 : // class AccessibleListBoxEntry -----------------------------------------------------
58 :
59 : using namespace ::com::sun::star::accessibility;
60 : using namespace ::com::sun::star::uno;
61 : using namespace ::com::sun::star::lang;
62 : using namespace ::com::sun::star;
63 :
64 : // -----------------------------------------------------------------------------
65 : // Ctor() and Dtor()
66 : // -----------------------------------------------------------------------------
67 0 : AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox& _rListBox,
68 : SvTreeListEntry* _pEntry,
69 : const Reference< XAccessible >& _xParent ) :
70 :
71 : AccessibleListBoxEntry_BASE ( m_aMutex ),
72 : ListBoxAccessibleBase( _rListBox ),
73 :
74 : m_nClientId ( 0 ),
75 0 : m_aParent ( _xParent )
76 :
77 : {
78 0 : _rListBox.FillEntryPath( _pEntry, m_aEntryPath );
79 0 : }
80 : // -----------------------------------------------------------------------------
81 0 : AccessibleListBoxEntry::~AccessibleListBoxEntry()
82 : {
83 0 : if ( IsAlive_Impl() )
84 : {
85 : // increment ref count to prevent double call of Dtor
86 0 : osl_atomic_increment( &m_refCount );
87 0 : dispose();
88 : }
89 0 : }
90 :
91 : // -----------------------------------------------------------------------------
92 0 : Rectangle AccessibleListBoxEntry::GetBoundingBox_Impl() const
93 : {
94 0 : Rectangle aRect;
95 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
96 0 : if ( pEntry )
97 : {
98 0 : aRect = getListBox()->GetBoundingRect( pEntry );
99 0 : SvTreeListEntry* pParent = getListBox()->GetParent( pEntry );
100 0 : if ( pParent )
101 : {
102 : // position relative to parent entry
103 0 : Point aTopLeft = aRect.TopLeft();
104 0 : aTopLeft -= getListBox()->GetBoundingRect( pParent ).TopLeft();
105 0 : aRect = Rectangle( aTopLeft, aRect.GetSize() );
106 : }
107 : }
108 :
109 0 : return aRect;
110 : }
111 : // -----------------------------------------------------------------------------
112 0 : Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
113 : {
114 0 : Rectangle aRect;
115 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
116 0 : if ( pEntry )
117 : {
118 0 : aRect = getListBox()->GetBoundingRect( pEntry );
119 0 : Point aTopLeft = aRect.TopLeft();
120 0 : aTopLeft += getListBox()->GetWindowExtentsRelative( NULL ).TopLeft();
121 0 : aRect = Rectangle( aTopLeft, aRect.GetSize() );
122 : }
123 :
124 0 : return aRect;
125 : }
126 : // -----------------------------------------------------------------------------
127 0 : sal_Bool AccessibleListBoxEntry::IsAlive_Impl() const
128 : {
129 0 : return ( !rBHelper.bDisposed && !rBHelper.bInDispose && isAlive() );
130 : }
131 : // -----------------------------------------------------------------------------
132 0 : sal_Bool AccessibleListBoxEntry::IsShowing_Impl() const
133 : {
134 0 : Reference< XAccessible > xParent = implGetParentAccessible( );
135 :
136 0 : sal_Bool bShowing = sal_False;
137 : Reference< XAccessibleContext > m_xParentContext =
138 0 : xParent.is() ? xParent->getAccessibleContext() : Reference< XAccessibleContext >();
139 0 : if( m_xParentContext.is() )
140 : {
141 0 : Reference< XAccessibleComponent > xParentComp( m_xParentContext, uno::UNO_QUERY );
142 0 : if( xParentComp.is() )
143 0 : bShowing = GetBoundingBox_Impl().IsOver( VCLRectangle( xParentComp->getBounds() ) );
144 : }
145 :
146 0 : return bShowing;
147 : }
148 : // -----------------------------------------------------------------------------
149 0 : Rectangle AccessibleListBoxEntry::GetBoundingBox() throw ( lang::DisposedException )
150 : {
151 0 : SolarMutexGuard aSolarGuard;
152 0 : ::osl::MutexGuard aGuard( m_aMutex );
153 :
154 0 : EnsureIsAlive();
155 0 : return GetBoundingBox_Impl();
156 : }
157 : // -----------------------------------------------------------------------------
158 0 : Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen() throw ( lang::DisposedException )
159 : {
160 0 : SolarMutexGuard aSolarGuard;
161 0 : ::osl::MutexGuard aGuard( m_aMutex );
162 :
163 0 : EnsureIsAlive();
164 0 : return GetBoundingBoxOnScreen_Impl();
165 : }
166 : // -----------------------------------------------------------------------------
167 0 : void AccessibleListBoxEntry::EnsureIsAlive() const throw ( lang::DisposedException )
168 : {
169 0 : if ( !IsAlive_Impl() )
170 0 : throw lang::DisposedException();
171 0 : }
172 : // -----------------------------------------------------------------------------
173 0 : OUString AccessibleListBoxEntry::implGetText()
174 : {
175 0 : OUString sRet;
176 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
177 0 : if ( pEntry )
178 0 : sRet = getListBox()->SearchEntryText( pEntry );
179 0 : return sRet;
180 : }
181 : // -----------------------------------------------------------------------------
182 0 : Locale AccessibleListBoxEntry::implGetLocale()
183 : {
184 0 : Locale aLocale;
185 0 : aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
186 :
187 0 : return aLocale;
188 : }
189 0 : void AccessibleListBoxEntry::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
190 : {
191 0 : nStartIndex = 0;
192 0 : nEndIndex = 0;
193 0 : }
194 : // -----------------------------------------------------------------------------
195 : // XTypeProvider
196 : // -----------------------------------------------------------------------------
197 : // -----------------------------------------------------------------------------
198 0 : Sequence< sal_Int8 > AccessibleListBoxEntry::getImplementationId() throw (RuntimeException)
199 : {
200 : static ::cppu::OImplementationId* pId = NULL;
201 :
202 0 : if ( !pId )
203 : {
204 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
205 :
206 0 : if ( !pId )
207 : {
208 0 : static ::cppu::OImplementationId aId;
209 0 : pId = &aId;
210 0 : }
211 : }
212 0 : return pId->getImplementationId();
213 : }
214 :
215 : // -----------------------------------------------------------------------------
216 : // XComponent/ListBoxAccessibleBase
217 : // -----------------------------------------------------------------------------
218 0 : void SAL_CALL AccessibleListBoxEntry::dispose() throw ( uno::RuntimeException )
219 : {
220 0 : AccessibleListBoxEntry_BASE::dispose();
221 0 : }
222 :
223 : // -----------------------------------------------------------------------------
224 : // XComponent
225 : // -----------------------------------------------------------------------------
226 0 : void SAL_CALL AccessibleListBoxEntry::disposing()
227 : {
228 0 : SolarMutexGuard();
229 0 : ::osl::MutexGuard aGuard( m_aMutex );
230 :
231 0 : Reference< XAccessible > xKeepAlive( this );
232 :
233 : // Send a disposing to all listeners.
234 0 : if ( m_nClientId )
235 : {
236 0 : ::comphelper::AccessibleEventNotifier::TClientId nId = m_nClientId;
237 0 : m_nClientId = 0;
238 0 : ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
239 : }
240 :
241 : // clean up
242 : {
243 :
244 0 : ListBoxAccessibleBase::disposing();
245 : }
246 0 : m_aParent = WeakReference< XAccessible >();
247 0 : }
248 : // -----------------------------------------------------------------------------
249 : // XServiceInfo
250 : // -----------------------------------------------------------------------------
251 0 : OUString SAL_CALL AccessibleListBoxEntry::getImplementationName() throw(RuntimeException)
252 : {
253 0 : return getImplementationName_Static();
254 : }
255 : // -----------------------------------------------------------------------------
256 0 : Sequence< OUString > SAL_CALL AccessibleListBoxEntry::getSupportedServiceNames() throw(RuntimeException)
257 : {
258 0 : return getSupportedServiceNames_Static();
259 : }
260 : // -----------------------------------------------------------------------------
261 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::supportsService( const OUString& _rServiceName ) throw (RuntimeException)
262 : {
263 0 : return cppu::supportsService(this, _rServiceName);
264 : }
265 : // -----------------------------------------------------------------------------
266 : // XServiceInfo - static methods
267 : // -----------------------------------------------------------------------------
268 0 : Sequence< OUString > AccessibleListBoxEntry::getSupportedServiceNames_Static(void) throw( RuntimeException )
269 : {
270 0 : Sequence< OUString > aSupported(3);
271 0 : aSupported[0] = "com.sun.star.accessibility.AccessibleContext";
272 0 : aSupported[1] = "com.sun.star.accessibility.AccessibleComponent";
273 0 : aSupported[2] = "com.sun.star.awt.AccessibleTreeListBoxEntry";
274 0 : return aSupported;
275 : }
276 : // -----------------------------------------------------------------------------
277 0 : OUString AccessibleListBoxEntry::getImplementationName_Static(void) throw( RuntimeException )
278 : {
279 0 : return OUString( "com.sun.star.comp.svtools.AccessibleTreeListBoxEntry" );
280 : }
281 : // -----------------------------------------------------------------------------
282 : // XAccessible
283 : // -----------------------------------------------------------------------------
284 0 : Reference< XAccessibleContext > SAL_CALL AccessibleListBoxEntry::getAccessibleContext( ) throw (RuntimeException)
285 : {
286 0 : EnsureIsAlive();
287 0 : return this;
288 : }
289 : // -----------------------------------------------------------------------------
290 : // XAccessibleContext
291 : // -----------------------------------------------------------------------------
292 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleChildCount( ) throw (RuntimeException)
293 : {
294 0 : SolarMutexGuard aSolarGuard;
295 0 : ::osl::MutexGuard aGuard( m_aMutex );
296 :
297 0 : EnsureIsAlive();
298 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
299 0 : sal_Int32 nCount = 0;
300 0 : if ( pEntry )
301 0 : nCount = getListBox()->GetLevelChildCount( pEntry );
302 :
303 0 : return nCount;
304 : }
305 : // -----------------------------------------------------------------------------
306 0 : Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
307 : {
308 0 : SolarMutexGuard aSolarGuard;
309 0 : ::osl::MutexGuard aGuard( m_aMutex );
310 0 : EnsureIsAlive();
311 :
312 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
313 0 : SvTreeListEntry* pEntry = pParent ? getListBox()->GetEntry( pParent, i ) : NULL;
314 0 : if ( !pEntry )
315 0 : throw IndexOutOfBoundsException();
316 :
317 0 : return new AccessibleListBoxEntry( *getListBox(), pEntry, this );
318 : }
319 :
320 : // -----------------------------------------------------------------------------
321 0 : Reference< XAccessible > AccessibleListBoxEntry::implGetParentAccessible( ) const
322 : {
323 0 : Reference< XAccessible > xParent = (Reference< XAccessible >)m_aParent;
324 0 : if ( !xParent.is() )
325 : {
326 : OSL_ENSURE( m_aEntryPath.size(), "AccessibleListBoxEntry::getAccessibleParent: invalid path!" );
327 0 : if ( 1 == m_aEntryPath.size() )
328 : { // we're a top level entry
329 : // -> our parent is the tree listbox itself
330 0 : if ( getListBox() )
331 0 : xParent = getListBox()->GetAccessible( );
332 : }
333 : else
334 : { // we have a entry as parent -> get it's accessible
335 :
336 : // shorten our access path by one
337 0 : ::std::deque< sal_Int32 > aParentPath( m_aEntryPath );
338 0 : aParentPath.pop_back();
339 :
340 : // get the entry for this shortened access path
341 0 : SvTreeListEntry* pParentEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
342 : OSL_ENSURE( pParentEntry, "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!" );
343 :
344 0 : if ( pParentEntry )
345 0 : xParent = new AccessibleListBoxEntry( *getListBox(), pParentEntry, NULL );
346 : // note that we pass NULL here as parent-accessible:
347 : // this is allowed, as the AccessibleListBoxEntry class will create it's parent
348 : // when needed
349 : }
350 : }
351 :
352 0 : return xParent;
353 : }
354 :
355 : // -----------------------------------------------------------------------------
356 0 : Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleParent( ) throw (RuntimeException)
357 : {
358 0 : SolarMutexGuard aSolarGuard;
359 0 : ::osl::MutexGuard aGuard( m_aMutex );
360 0 : EnsureIsAlive();
361 :
362 0 : return implGetParentAccessible( );
363 : }
364 : // -----------------------------------------------------------------------------
365 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleIndexInParent( ) throw (RuntimeException)
366 : {
367 0 : ::osl::MutexGuard aGuard( m_aMutex );
368 :
369 : OSL_ENSURE( !m_aEntryPath.empty(), "empty path" );
370 0 : return m_aEntryPath.empty() ? -1 : m_aEntryPath.back();
371 : }
372 : // -----------------------------------------------------------------------------
373 0 : sal_Int16 SAL_CALL AccessibleListBoxEntry::getAccessibleRole( ) throw (RuntimeException)
374 : {
375 0 : return AccessibleRole::LABEL;
376 : }
377 : // -----------------------------------------------------------------------------
378 0 : OUString SAL_CALL AccessibleListBoxEntry::getAccessibleDescription( ) throw (RuntimeException)
379 : {
380 : // no description for every item
381 0 : return OUString();
382 : }
383 : // -----------------------------------------------------------------------------
384 0 : OUString SAL_CALL AccessibleListBoxEntry::getAccessibleName( ) throw (RuntimeException)
385 : {
386 0 : ::osl::MutexGuard aGuard( m_aMutex );
387 :
388 0 : EnsureIsAlive();
389 0 : return implGetText();
390 : }
391 : // -----------------------------------------------------------------------------
392 0 : Reference< XAccessibleRelationSet > SAL_CALL AccessibleListBoxEntry::getAccessibleRelationSet( ) throw (RuntimeException)
393 : {
394 0 : Reference< XAccessibleRelationSet > xRelSet;
395 0 : Reference< XAccessible > xParent;
396 0 : if ( m_aEntryPath.size() > 1 ) // not a root entry
397 0 : xParent = implGetParentAccessible();
398 0 : if ( xParent.is() )
399 : {
400 0 : utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
401 0 : Sequence< Reference< XInterface > > aSequence(1);
402 0 : aSequence[0] = xParent;
403 : pRelationSetHelper->AddRelation(
404 0 : AccessibleRelation( AccessibleRelationType::NODE_CHILD_OF, aSequence ) );
405 0 : xRelSet = pRelationSetHelper;
406 : }
407 0 : return xRelSet;
408 : }
409 : // -----------------------------------------------------------------------------
410 0 : Reference< XAccessibleStateSet > SAL_CALL AccessibleListBoxEntry::getAccessibleStateSet( ) throw (RuntimeException)
411 : {
412 0 : ::osl::MutexGuard aGuard( m_aMutex );
413 :
414 0 : utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
415 0 : Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
416 :
417 0 : if ( IsAlive_Impl() )
418 : {
419 0 : pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
420 0 : pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
421 0 : pStateSetHelper->AddState( AccessibleStateType::ENABLED );
422 0 : pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
423 0 : if ( getListBox()->IsInplaceEditingEnabled() )
424 0 : pStateSetHelper->AddState( AccessibleStateType::EDITABLE );
425 0 : if ( IsShowing_Impl() )
426 0 : pStateSetHelper->AddState( AccessibleStateType::SHOWING );
427 0 : getListBox()->FillAccessibleEntryStateSet(
428 0 : getListBox()->GetEntryFromPath( m_aEntryPath ), *pStateSetHelper );
429 : }
430 : else
431 0 : pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
432 :
433 0 : return xStateSet;
434 : }
435 : // -----------------------------------------------------------------------------
436 0 : Locale SAL_CALL AccessibleListBoxEntry::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
437 : {
438 0 : SolarMutexGuard aSolarGuard;
439 0 : ::osl::MutexGuard aGuard( m_aMutex );
440 :
441 0 : return implGetLocale();
442 : }
443 : // -----------------------------------------------------------------------------
444 : // XAccessibleComponent
445 : // -----------------------------------------------------------------------------
446 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::containsPoint( const awt::Point& rPoint ) throw (RuntimeException)
447 : {
448 0 : return Rectangle( Point(), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
449 : }
450 : // -----------------------------------------------------------------------------
451 0 : Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
452 : {
453 0 : SolarMutexGuard aSolarGuard;
454 0 : ::osl::MutexGuard aGuard( m_aMutex );
455 :
456 0 : EnsureIsAlive();
457 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( VCLPoint( _aPoint ) );
458 0 : if ( !pEntry )
459 0 : throw RuntimeException();
460 :
461 0 : Reference< XAccessible > xAcc;
462 0 : AccessibleListBoxEntry* pAccEntry = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
463 0 : Rectangle aRect = pAccEntry->GetBoundingBox_Impl();
464 0 : if ( aRect.IsInside( VCLPoint( _aPoint ) ) )
465 0 : xAcc = pAccEntry;
466 0 : return xAcc;
467 : }
468 : // -----------------------------------------------------------------------------
469 0 : awt::Rectangle SAL_CALL AccessibleListBoxEntry::getBounds( ) throw (RuntimeException)
470 : {
471 0 : return AWTRectangle( GetBoundingBox() );
472 : }
473 : // -----------------------------------------------------------------------------
474 0 : awt::Point SAL_CALL AccessibleListBoxEntry::getLocation( ) throw (RuntimeException)
475 : {
476 0 : return AWTPoint( GetBoundingBox().TopLeft() );
477 : }
478 : // -----------------------------------------------------------------------------
479 0 : awt::Point SAL_CALL AccessibleListBoxEntry::getLocationOnScreen( ) throw (RuntimeException)
480 : {
481 0 : return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
482 : }
483 : // -----------------------------------------------------------------------------
484 0 : awt::Size SAL_CALL AccessibleListBoxEntry::getSize( ) throw (RuntimeException)
485 : {
486 0 : return AWTSize( GetBoundingBox().GetSize() );
487 : }
488 : // -----------------------------------------------------------------------------
489 0 : void SAL_CALL AccessibleListBoxEntry::grabFocus( ) throw (RuntimeException)
490 : {
491 : // do nothing, because no focus for each item
492 0 : }
493 : // -----------------------------------------------------------------------------
494 0 : sal_Int32 AccessibleListBoxEntry::getForeground( ) throw (RuntimeException)
495 : {
496 0 : SolarMutexGuard aSolarGuard;
497 0 : ::osl::MutexGuard aGuard( m_aMutex );
498 :
499 0 : sal_Int32 nColor = 0;
500 0 : Reference< XAccessible > xParent = getAccessibleParent();
501 0 : if ( xParent.is() )
502 : {
503 0 : Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
504 0 : if ( xParentComp.is() )
505 0 : nColor = xParentComp->getForeground();
506 : }
507 :
508 0 : return nColor;
509 : }
510 : // -----------------------------------------------------------------------------
511 0 : sal_Int32 AccessibleListBoxEntry::getBackground( ) throw (RuntimeException)
512 : {
513 0 : SolarMutexGuard aSolarGuard;
514 0 : ::osl::MutexGuard aGuard( m_aMutex );
515 :
516 0 : sal_Int32 nColor = 0;
517 0 : Reference< XAccessible > xParent = getAccessibleParent();
518 0 : if ( xParent.is() )
519 : {
520 0 : Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
521 0 : if ( xParentComp.is() )
522 0 : nColor = xParentComp->getBackground();
523 : }
524 :
525 0 : return nColor;
526 : }
527 : // -----------------------------------------------------------------------------
528 : // XAccessibleText
529 : // -----------------------------------------------------------------------------
530 : // -----------------------------------------------------------------------------
531 0 : awt::Rectangle SAL_CALL AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
532 : {
533 0 : SolarMutexGuard aSolarGuard;
534 0 : ::osl::MutexGuard aGuard( m_aMutex );
535 :
536 0 : EnsureIsAlive();
537 :
538 0 : if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
539 0 : throw IndexOutOfBoundsException();
540 :
541 0 : awt::Rectangle aBounds( 0, 0, 0, 0 );
542 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
543 0 : if ( pEntry )
544 : {
545 0 : ::vcl::ControlLayoutData aLayoutData;
546 0 : Rectangle aItemRect = GetBoundingBox();
547 0 : getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
548 0 : Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
549 0 : aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
550 0 : aBounds = AWTRectangle( aCharRect );
551 : }
552 :
553 0 : return aBounds;
554 : }
555 : // -----------------------------------------------------------------------------
556 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
557 : {
558 0 : SolarMutexGuard aSolarGuard;
559 0 : ::osl::MutexGuard aGuard( m_aMutex );
560 0 : EnsureIsAlive();
561 :
562 0 : sal_Int32 nIndex = -1;
563 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
564 0 : if ( pEntry )
565 : {
566 0 : ::vcl::ControlLayoutData aLayoutData;
567 0 : Rectangle aItemRect = GetBoundingBox();
568 0 : getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
569 0 : Point aPnt( VCLPoint( aPoint ) );
570 0 : aPnt += aItemRect.TopLeft();
571 0 : nIndex = aLayoutData.GetIndexForPoint( aPnt );
572 : }
573 :
574 0 : return nIndex;
575 : }
576 : // -----------------------------------------------------------------------------
577 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
578 : {
579 0 : SolarMutexGuard aSolarGuard;
580 0 : ::osl::MutexGuard aGuard( m_aMutex );
581 0 : EnsureIsAlive();
582 :
583 0 : String sText = getText();
584 0 : if ( ( 0 > nStartIndex ) || ( sText.Len() <= nStartIndex )
585 0 : || ( 0 > nEndIndex ) || ( sText.Len() <= nEndIndex ) )
586 0 : throw IndexOutOfBoundsException();
587 :
588 0 : sal_Int32 nLen = nEndIndex - nStartIndex + 1;
589 0 : ::svt::OStringTransfer::CopyString( sText.Copy( (sal_uInt16)nStartIndex, (sal_uInt16)nLen ), getListBox() );
590 :
591 0 : return sal_True;
592 : }
593 : // -----------------------------------------------------------------------------
594 : // XAccessibleEventBroadcaster
595 : // -----------------------------------------------------------------------------
596 0 : void SAL_CALL AccessibleListBoxEntry::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
597 : {
598 0 : if (xListener.is())
599 : {
600 0 : ::osl::MutexGuard aGuard( m_aMutex );
601 0 : if (!m_nClientId)
602 0 : m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
603 0 : comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
604 : }
605 0 : }
606 : // -----------------------------------------------------------------------------
607 0 : void SAL_CALL AccessibleListBoxEntry::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
608 : {
609 0 : if (xListener.is())
610 : {
611 0 : ::osl::MutexGuard aGuard( m_aMutex );
612 :
613 0 : sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
614 0 : if ( !nListenerCount )
615 : {
616 : // no listeners anymore
617 : // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
618 : // and at least to us not firing any events anymore, in case somebody calls
619 : // NotifyAccessibleEvent, again
620 0 : sal_Int32 nId = m_nClientId;
621 0 : m_nClientId = 0;
622 0 : comphelper::AccessibleEventNotifier::revokeClient( nId );
623 :
624 0 : }
625 : }
626 0 : }
627 : // -----------------------------------------------------------------------------
628 : // XAccessibleAction
629 : // -----------------------------------------------------------------------------
630 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleActionCount( ) throw (RuntimeException)
631 : {
632 0 : ::osl::MutexGuard aGuard( m_aMutex );
633 :
634 : // three actions supported
635 0 : return ACCESSIBLE_ACTION_COUNT;
636 : }
637 : // -----------------------------------------------------------------------------
638 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
639 : {
640 0 : SolarMutexGuard aSolarGuard;
641 0 : ::osl::MutexGuard aGuard( m_aMutex );
642 :
643 0 : sal_Bool bRet = sal_False;
644 0 : checkActionIndex_Impl( nIndex );
645 0 : EnsureIsAlive();
646 :
647 0 : SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
648 0 : if ( pEntry )
649 : {
650 0 : if ( getListBox()->IsExpanded( pEntry ) )
651 0 : getListBox()->Collapse( pEntry );
652 : else
653 0 : getListBox()->Expand( pEntry );
654 0 : bRet = sal_True;
655 : }
656 :
657 0 : return bRet;
658 : }
659 : // -----------------------------------------------------------------------------
660 0 : OUString SAL_CALL AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
661 : {
662 0 : SolarMutexGuard aSolarGuard;
663 0 : ::osl::MutexGuard aGuard( m_aMutex );
664 :
665 0 : checkActionIndex_Impl( nIndex );
666 0 : EnsureIsAlive();
667 :
668 0 : static const OUString sActionDesc( "toggleExpand" );
669 0 : return sActionDesc;
670 : }
671 : // -----------------------------------------------------------------------------
672 0 : Reference< XAccessibleKeyBinding > AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
673 : {
674 0 : ::osl::MutexGuard aGuard( m_aMutex );
675 :
676 0 : Reference< XAccessibleKeyBinding > xRet;
677 0 : checkActionIndex_Impl( nIndex );
678 : // ... which key?
679 0 : return xRet;
680 : }
681 : // -----------------------------------------------------------------------------
682 : // XAccessibleSelection
683 : // -----------------------------------------------------------------------------
684 0 : void SAL_CALL AccessibleListBoxEntry::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
685 : {
686 0 : SolarMutexGuard aSolarGuard;
687 0 : ::osl::MutexGuard aGuard( m_aMutex );
688 :
689 0 : EnsureIsAlive();
690 :
691 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
692 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
693 0 : if ( !pEntry )
694 0 : throw IndexOutOfBoundsException();
695 :
696 0 : getListBox()->Select( pEntry, sal_True );
697 0 : }
698 : // -----------------------------------------------------------------------------
699 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
700 : {
701 0 : SolarMutexGuard aSolarGuard;
702 0 : ::osl::MutexGuard aGuard( m_aMutex );
703 :
704 0 : EnsureIsAlive();
705 :
706 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
707 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
708 0 : if ( !pEntry )
709 0 : throw IndexOutOfBoundsException();
710 :
711 0 : return getListBox()->IsSelected( pEntry );
712 : }
713 : // -----------------------------------------------------------------------------
714 0 : void SAL_CALL AccessibleListBoxEntry::clearAccessibleSelection( ) throw (RuntimeException)
715 : {
716 0 : SolarMutexGuard aSolarGuard;
717 0 : ::osl::MutexGuard aGuard( m_aMutex );
718 :
719 0 : EnsureIsAlive();
720 :
721 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
722 0 : if ( !pParent )
723 0 : throw RuntimeException();
724 0 : sal_Int32 nCount = getListBox()->GetLevelChildCount( pParent );
725 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
726 : {
727 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
728 0 : if ( getListBox()->IsSelected( pEntry ) )
729 0 : getListBox()->Select( pEntry, sal_False );
730 0 : }
731 0 : }
732 : // -----------------------------------------------------------------------------
733 0 : void SAL_CALL AccessibleListBoxEntry::selectAllAccessibleChildren( ) throw (RuntimeException)
734 : {
735 0 : SolarMutexGuard aSolarGuard;
736 0 : ::osl::MutexGuard aGuard( m_aMutex );
737 :
738 0 : EnsureIsAlive();
739 :
740 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
741 0 : if ( !pParent )
742 0 : throw RuntimeException();
743 0 : sal_Int32 nCount = getListBox()->GetLevelChildCount( pParent );
744 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
745 : {
746 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
747 0 : if ( !getListBox()->IsSelected( pEntry ) )
748 0 : getListBox()->Select( pEntry, sal_True );
749 0 : }
750 0 : }
751 : // -----------------------------------------------------------------------------
752 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChildCount( ) throw (RuntimeException)
753 : {
754 0 : SolarMutexGuard aSolarGuard;
755 0 : ::osl::MutexGuard aGuard( m_aMutex );
756 :
757 0 : EnsureIsAlive();
758 :
759 0 : sal_Int32 i, nSelCount = 0, nCount = 0;
760 :
761 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
762 0 : if ( !pParent )
763 0 : throw RuntimeException();
764 0 : nCount = getListBox()->GetLevelChildCount( pParent );
765 0 : for ( i = 0; i < nCount; ++i )
766 : {
767 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
768 0 : if ( getListBox()->IsSelected( pEntry ) )
769 0 : ++nSelCount;
770 : }
771 :
772 0 : return nSelCount;
773 : }
774 : // -----------------------------------------------------------------------------
775 0 : Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
776 : {
777 0 : SolarMutexGuard aSolarGuard;
778 0 : ::osl::MutexGuard aGuard( m_aMutex );
779 :
780 0 : EnsureIsAlive();
781 :
782 0 : if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
783 0 : throw IndexOutOfBoundsException();
784 :
785 0 : Reference< XAccessible > xChild;
786 0 : sal_Int32 i, nSelCount = 0, nCount = 0;
787 :
788 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
789 0 : if ( !pParent )
790 0 : throw RuntimeException();
791 0 : nCount = getListBox()->GetLevelChildCount( pParent );
792 0 : for ( i = 0; i < nCount; ++i )
793 : {
794 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
795 0 : if ( getListBox()->IsSelected( pEntry ) )
796 0 : ++nSelCount;
797 :
798 0 : if ( nSelCount == ( nSelectedChildIndex + 1 ) )
799 : {
800 0 : xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
801 0 : break;
802 : }
803 : }
804 :
805 0 : return xChild;
806 : }
807 : // -----------------------------------------------------------------------------
808 0 : void SAL_CALL AccessibleListBoxEntry::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
809 : {
810 0 : SolarMutexGuard aSolarGuard;
811 0 : ::osl::MutexGuard aGuard( m_aMutex );
812 :
813 0 : EnsureIsAlive();
814 :
815 0 : SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
816 0 : SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, nSelectedChildIndex );
817 0 : if ( !pEntry )
818 0 : throw IndexOutOfBoundsException();
819 :
820 0 : getListBox()->Select( pEntry, sal_False );
821 0 : }
822 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException)
823 : {
824 0 : return -1;
825 : }
826 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
827 : {
828 0 : SolarMutexGuard aSolarGuard;
829 0 : ::osl::MutexGuard aGuard( m_aMutex );
830 0 : EnsureIsAlive();
831 :
832 0 : if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
833 0 : throw IndexOutOfBoundsException();
834 :
835 0 : return sal_False;
836 : }
837 0 : sal_Unicode SAL_CALL AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
838 : {
839 0 : SolarMutexGuard aSolarGuard;
840 0 : ::osl::MutexGuard aGuard( m_aMutex );
841 0 : EnsureIsAlive();
842 0 : return OCommonAccessibleText::getCharacter( nIndex );
843 : }
844 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
845 : {
846 0 : SolarMutexGuard aSolarGuard;
847 0 : ::osl::MutexGuard aGuard( m_aMutex );
848 0 : EnsureIsAlive();
849 :
850 0 : OUString sText( implGetText() );
851 :
852 0 : if ( !implIsValidIndex( nIndex, sText.getLength() ) )
853 0 : throw IndexOutOfBoundsException();
854 :
855 0 : return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
856 : }
857 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException)
858 : {
859 0 : SolarMutexGuard aSolarGuard;
860 0 : ::osl::MutexGuard aGuard( m_aMutex );
861 0 : EnsureIsAlive();
862 0 : return OCommonAccessibleText::getCharacterCount( );
863 : }
864 :
865 0 : OUString SAL_CALL AccessibleListBoxEntry::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException)
866 : {
867 0 : SolarMutexGuard aSolarGuard;
868 0 : ::osl::MutexGuard aGuard( m_aMutex );
869 0 : EnsureIsAlive();
870 0 : return OCommonAccessibleText::getSelectedText( );
871 : }
872 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException)
873 : {
874 0 : SolarMutexGuard aSolarGuard;
875 0 : ::osl::MutexGuard aGuard( m_aMutex );
876 0 : EnsureIsAlive();
877 0 : return OCommonAccessibleText::getSelectionStart( );
878 : }
879 0 : sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException)
880 : {
881 0 : SolarMutexGuard aSolarGuard;
882 0 : ::osl::MutexGuard aGuard( m_aMutex );
883 0 : EnsureIsAlive();
884 0 : return OCommonAccessibleText::getSelectionEnd( );
885 : }
886 0 : sal_Bool SAL_CALL AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
887 : {
888 0 : SolarMutexGuard aSolarGuard;
889 0 : ::osl::MutexGuard aGuard( m_aMutex );
890 0 : EnsureIsAlive();
891 :
892 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
893 0 : throw IndexOutOfBoundsException();
894 :
895 0 : return sal_False;
896 : }
897 0 : OUString SAL_CALL AccessibleListBoxEntry::getText( ) throw (::com::sun::star::uno::RuntimeException)
898 : {
899 0 : SolarMutexGuard aSolarGuard;
900 0 : ::osl::MutexGuard aGuard( m_aMutex );
901 0 : EnsureIsAlive();
902 0 : return OCommonAccessibleText::getText( );
903 : }
904 0 : OUString SAL_CALL AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
905 : {
906 0 : SolarMutexGuard aSolarGuard;
907 0 : ::osl::MutexGuard aGuard( m_aMutex );
908 0 : EnsureIsAlive();
909 0 : return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
910 : }
911 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
912 : {
913 0 : SolarMutexGuard aSolarGuard;
914 0 : ::osl::MutexGuard aGuard( m_aMutex );
915 0 : EnsureIsAlive();
916 0 : return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
917 : }
918 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
919 : {
920 0 : SolarMutexGuard aSolarGuard;
921 0 : ::osl::MutexGuard aGuard( m_aMutex );
922 0 : EnsureIsAlive();
923 0 : return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
924 : }
925 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
926 : {
927 0 : SolarMutexGuard aSolarGuard;
928 0 : ::osl::MutexGuard aGuard( m_aMutex );
929 0 : EnsureIsAlive();
930 :
931 0 : return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
932 : }
933 : //........................................................................
934 : }// namespace accessibility
935 : //........................................................................
936 :
937 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|