1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessiblestatusbaritem.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
34 #include <toolkit/helper/externallock.hxx>
35 #include <toolkit/helper/convert.hxx>
36 #include <accessibility/helper/characterattributeshelper.hxx>
38 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
39 #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
42 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
44 #include <unotools/accessiblestatesethelper.hxx>
45 #include <unotools/accessiblerelationsethelper.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/unohelp2.hxx>
48 #include <vcl/status.hxx>
49 #include <vcl/controllayout.hxx>
54 using namespace ::com::sun::star::accessibility
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::beans
;
58 using namespace ::com::sun::star
;
59 using namespace ::comphelper
;
62 // -----------------------------------------------------------------------------
63 // class VCLXAccessibleStatusBarItem
64 // -----------------------------------------------------------------------------
66 VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar
* pStatusBar
, sal_uInt16 nItemId
)
67 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() )
68 ,m_pStatusBar( pStatusBar
)
71 m_pExternalLock
= static_cast< VCLExternalSolarLock
* >( getExternalLock() );
73 m_sItemName
= GetItemName();
74 m_sItemText
= GetItemText();
75 m_bShowing
= IsShowing();
78 // -----------------------------------------------------------------------------
80 VCLXAccessibleStatusBarItem::~VCLXAccessibleStatusBarItem()
82 delete m_pExternalLock
;
83 m_pExternalLock
= NULL
;
86 // -----------------------------------------------------------------------------
88 sal_Bool
VCLXAccessibleStatusBarItem::IsShowing()
90 sal_Bool bShowing
= sal_False
;
93 bShowing
= m_pStatusBar
->IsItemVisible( m_nItemId
);
98 // -----------------------------------------------------------------------------
100 void VCLXAccessibleStatusBarItem::SetShowing( sal_Bool bShowing
)
102 if ( m_bShowing
!= bShowing
)
104 Any aOldValue
, aNewValue
;
106 aOldValue
<<= AccessibleStateType::SHOWING
;
108 aNewValue
<<= AccessibleStateType::SHOWING
;
109 m_bShowing
= bShowing
;
110 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
114 // -----------------------------------------------------------------------------
116 void VCLXAccessibleStatusBarItem::SetItemName( const ::rtl::OUString
& sItemName
)
118 if ( !m_sItemName
.equals( sItemName
) )
120 Any aOldValue
, aNewValue
;
121 aOldValue
<<= m_sItemName
;
122 aNewValue
<<= sItemName
;
123 m_sItemName
= sItemName
;
124 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
128 // -----------------------------------------------------------------------------
130 ::rtl::OUString
VCLXAccessibleStatusBarItem::GetItemName()
132 ::rtl::OUString sName
;
134 sName
= m_pStatusBar
->GetAccessibleName( m_nItemId
);
139 // -----------------------------------------------------------------------------
141 void VCLXAccessibleStatusBarItem::SetItemText( const ::rtl::OUString
& sItemText
)
143 Any aOldValue
, aNewValue
;
144 if ( implInitTextChangedEvent( m_sItemText
, sItemText
, aOldValue
, aNewValue
) )
146 m_sItemText
= sItemText
;
147 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED
, aOldValue
, aNewValue
);
151 // -----------------------------------------------------------------------------
153 ::rtl::OUString
VCLXAccessibleStatusBarItem::GetItemText()
155 ::rtl::OUString sText
;
156 ::vcl::ControlLayoutData aLayoutData
;
159 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
160 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
161 sText
= aLayoutData
.m_aDisplayText
;
167 // -----------------------------------------------------------------------------
169 void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
171 rStateSet
.AddState( AccessibleStateType::ENABLED
);
172 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
174 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
177 rStateSet
.AddState( AccessibleStateType::SHOWING
);
180 // -----------------------------------------------------------------------------
181 // OCommonAccessibleComponent
182 // -----------------------------------------------------------------------------
184 awt::Rectangle
VCLXAccessibleStatusBarItem::implGetBounds() throw (RuntimeException
)
186 awt::Rectangle
aBounds( 0, 0, 0, 0 );
189 aBounds
= AWTRectangle( m_pStatusBar
->GetItemRect( m_nItemId
) );
194 // -----------------------------------------------------------------------------
195 // OCommonAccessibleText
196 // -----------------------------------------------------------------------------
198 ::rtl::OUString
VCLXAccessibleStatusBarItem::implGetText()
200 return GetItemText();
203 // -----------------------------------------------------------------------------
205 lang::Locale
VCLXAccessibleStatusBarItem::implGetLocale()
207 return Application::GetSettings().GetLocale();
210 // -----------------------------------------------------------------------------
212 void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
218 // -----------------------------------------------------------------------------
220 // -----------------------------------------------------------------------------
222 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleStatusBarItem
, AccessibleTextHelper_BASE
, VCLXAccessibleStatusBarItem_BASE
)
224 // -----------------------------------------------------------------------------
226 // -----------------------------------------------------------------------------
228 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleStatusBarItem
, AccessibleTextHelper_BASE
, VCLXAccessibleStatusBarItem_BASE
)
230 // -----------------------------------------------------------------------------
232 // -----------------------------------------------------------------------------
234 void VCLXAccessibleStatusBarItem::disposing()
236 AccessibleTextHelper_BASE::disposing();
239 m_sItemName
= ::rtl::OUString();
240 m_sItemText
= ::rtl::OUString();
243 // -----------------------------------------------------------------------------
245 // -----------------------------------------------------------------------------
247 ::rtl::OUString
VCLXAccessibleStatusBarItem::getImplementationName() throw (RuntimeException
)
249 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleStatusBarItem" );
252 // -----------------------------------------------------------------------------
254 sal_Bool
VCLXAccessibleStatusBarItem::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
256 Sequence
< ::rtl::OUString
> aNames( getSupportedServiceNames() );
257 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
258 const ::rtl::OUString
* pEnd
= pNames
+ aNames
.getLength();
259 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
262 return pNames
!= pEnd
;
265 // -----------------------------------------------------------------------------
267 Sequence
< ::rtl::OUString
> VCLXAccessibleStatusBarItem::getSupportedServiceNames() throw (RuntimeException
)
269 Sequence
< ::rtl::OUString
> aNames(1);
270 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleStatusBarItem" );
274 // -----------------------------------------------------------------------------
276 // -----------------------------------------------------------------------------
278 Reference
< XAccessibleContext
> VCLXAccessibleStatusBarItem::getAccessibleContext( ) throw (RuntimeException
)
280 OExternalLockGuard
aGuard( this );
285 // -----------------------------------------------------------------------------
286 // XAccessibleContext
287 // -----------------------------------------------------------------------------
289 sal_Int32
VCLXAccessibleStatusBarItem::getAccessibleChildCount() throw (RuntimeException
)
291 OExternalLockGuard
aGuard( this );
296 // -----------------------------------------------------------------------------
298 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
300 OExternalLockGuard
aGuard( this );
302 if ( i
< 0 || i
>= getAccessibleChildCount() )
303 throw IndexOutOfBoundsException();
305 return Reference
< XAccessible
>();
308 // -----------------------------------------------------------------------------
310 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleParent( ) throw (RuntimeException
)
312 OExternalLockGuard
aGuard( this );
314 Reference
< XAccessible
> xParent
;
316 xParent
= m_pStatusBar
->GetAccessible();
321 // -----------------------------------------------------------------------------
323 sal_Int32
VCLXAccessibleStatusBarItem::getAccessibleIndexInParent( ) throw (RuntimeException
)
325 OExternalLockGuard
aGuard( this );
327 sal_Int32 nIndexInParent
= -1;
329 nIndexInParent
= m_pStatusBar
->GetItemPos( m_nItemId
);
331 return nIndexInParent
;
334 // -----------------------------------------------------------------------------
336 sal_Int16
VCLXAccessibleStatusBarItem::getAccessibleRole( ) throw (RuntimeException
)
338 OExternalLockGuard
aGuard( this );
340 return AccessibleRole::LABEL
;
343 // -----------------------------------------------------------------------------
345 ::rtl::OUString
VCLXAccessibleStatusBarItem::getAccessibleDescription( ) throw (RuntimeException
)
347 OExternalLockGuard
aGuard( this );
349 ::rtl::OUString sDescription
;
351 sDescription
= m_pStatusBar
->GetHelpText( m_nItemId
);
356 // -----------------------------------------------------------------------------
358 ::rtl::OUString
VCLXAccessibleStatusBarItem::getAccessibleName( ) throw (RuntimeException
)
360 OExternalLockGuard
aGuard( this );
362 return GetItemName();
365 // -----------------------------------------------------------------------------
367 Reference
< XAccessibleRelationSet
> VCLXAccessibleStatusBarItem::getAccessibleRelationSet( ) throw (RuntimeException
)
369 OExternalLockGuard
aGuard( this );
371 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
372 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
376 // -----------------------------------------------------------------------------
378 Reference
< XAccessibleStateSet
> VCLXAccessibleStatusBarItem::getAccessibleStateSet( ) throw (RuntimeException
)
380 OExternalLockGuard
aGuard( this );
382 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
383 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
385 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
387 FillAccessibleStateSet( *pStateSetHelper
);
391 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
397 // -----------------------------------------------------------------------------
399 Locale
VCLXAccessibleStatusBarItem::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
401 OExternalLockGuard
aGuard( this );
403 return Application::GetSettings().GetLocale();
406 // -----------------------------------------------------------------------------
407 // XAccessibleComponent
408 // -----------------------------------------------------------------------------
410 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point
& ) throw (RuntimeException
)
412 OExternalLockGuard
aGuard( this );
414 return Reference
< XAccessible
>();
417 // -----------------------------------------------------------------------------
419 void VCLXAccessibleStatusBarItem::grabFocus( ) throw (RuntimeException
)
421 // no focus for status bar items
424 // -----------------------------------------------------------------------------
426 sal_Int32
VCLXAccessibleStatusBarItem::getForeground( ) throw (RuntimeException
)
428 OExternalLockGuard
aGuard( this );
430 sal_Int32 nColor
= 0;
431 Reference
< XAccessible
> xParent
= getAccessibleParent();
434 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
435 if ( xParentComp
.is() )
436 nColor
= xParentComp
->getForeground();
442 // -----------------------------------------------------------------------------
444 sal_Int32
VCLXAccessibleStatusBarItem::getBackground( ) throw (RuntimeException
)
446 OExternalLockGuard
aGuard( this );
448 sal_Int32 nColor
= 0;
449 Reference
< XAccessible
> xParent
= getAccessibleParent();
452 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
453 if ( xParentComp
.is() )
454 nColor
= xParentComp
->getBackground();
460 // -----------------------------------------------------------------------------
461 // XAccessibleExtendedComponent
462 // -----------------------------------------------------------------------------
464 Reference
< awt::XFont
> VCLXAccessibleStatusBarItem::getFont( ) throw (RuntimeException
)
466 OExternalLockGuard
aGuard( this );
468 Reference
< awt::XFont
> xFont
;
469 Reference
< XAccessible
> xParent
= getAccessibleParent();
472 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
473 if ( xParentComp
.is() )
474 xFont
= xParentComp
->getFont();
480 // -----------------------------------------------------------------------------
482 ::rtl::OUString
VCLXAccessibleStatusBarItem::getTitledBorderText( ) throw (RuntimeException
)
484 OExternalLockGuard
aGuard( this );
486 return GetItemText();
489 // -----------------------------------------------------------------------------
491 ::rtl::OUString
VCLXAccessibleStatusBarItem::getToolTipText( ) throw (RuntimeException
)
493 OExternalLockGuard
aGuard( this );
495 return ::rtl::OUString();
498 // -----------------------------------------------------------------------------
500 // -----------------------------------------------------------------------------
502 sal_Int32
VCLXAccessibleStatusBarItem::getCaretPosition() throw (RuntimeException
)
504 OExternalLockGuard
aGuard( this );
509 // -----------------------------------------------------------------------------
511 sal_Bool
VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
513 OExternalLockGuard
aGuard( this );
515 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
516 throw IndexOutOfBoundsException();
521 // -----------------------------------------------------------------------------
523 Sequence
< PropertyValue
> VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex
, const Sequence
< ::rtl::OUString
>& aRequestedAttributes
) throw (IndexOutOfBoundsException
, RuntimeException
)
525 OExternalLockGuard
aGuard( this );
527 Sequence
< PropertyValue
> aValues
;
528 ::rtl::OUString
sText( implGetText() );
530 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
531 throw IndexOutOfBoundsException();
535 Font aFont
= m_pStatusBar
->GetFont();
536 sal_Int32 nBackColor
= getBackground();
537 sal_Int32 nColor
= getForeground();
538 ::std::auto_ptr
< CharacterAttributesHelper
> pHelper( new CharacterAttributesHelper( aFont
, nBackColor
, nColor
) );
539 aValues
= pHelper
->GetCharacterAttributes( aRequestedAttributes
);
545 // -----------------------------------------------------------------------------
547 awt::Rectangle
VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
549 OExternalLockGuard
aGuard( this );
551 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
552 throw IndexOutOfBoundsException();
554 awt::Rectangle
aBounds( 0, 0, 0, 0 );
557 ::vcl::ControlLayoutData aLayoutData
;
558 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
559 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
560 Rectangle aCharRect
= aLayoutData
.GetCharacterBounds( nIndex
);
561 aCharRect
.Move( -aItemRect
.Left(), -aItemRect
.Top() );
562 aBounds
= AWTRectangle( aCharRect
);
568 // -----------------------------------------------------------------------------
570 sal_Int32
VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point
& aPoint
) throw (RuntimeException
)
572 OExternalLockGuard
aGuard( this );
574 sal_Int32 nIndex
= -1;
577 ::vcl::ControlLayoutData aLayoutData
;
578 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
579 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
580 Point
aPnt( VCLPoint( aPoint
) );
581 aPnt
+= aItemRect
.TopLeft();
582 nIndex
= aLayoutData
.GetIndexForPoint( aPnt
);
588 // -----------------------------------------------------------------------------
590 sal_Bool
VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
592 OExternalLockGuard
aGuard( this );
594 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
595 throw IndexOutOfBoundsException();
600 // -----------------------------------------------------------------------------
602 sal_Bool
VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
604 OExternalLockGuard
aGuard( this );
606 sal_Bool bReturn
= sal_False
;
610 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= m_pStatusBar
->GetClipboard();
611 if ( xClipboard
.is() )
613 ::rtl::OUString
sText( getTextRange( nStartIndex
, nEndIndex
) );
615 ::vcl::unohelper::TextDataObject
* pDataObj
= new ::vcl::unohelper::TextDataObject( sText
);
616 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
617 xClipboard
->setContents( pDataObj
, NULL
);
619 Reference
< datatransfer::clipboard::XFlushableClipboard
> xFlushableClipboard( xClipboard
, uno::UNO_QUERY
);
620 if( xFlushableClipboard
.is() )
621 xFlushableClipboard
->flushClipboard();
623 Application::AcquireSolarMutex( nRef
);
632 // -----------------------------------------------------------------------------