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 .
20 #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
21 #include <toolkit/helper/externallock.hxx>
22 #include <toolkit/helper/convert.hxx>
23 #include <accessibility/helper/characterattributeshelper.hxx>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
29 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <unotools/accessiblerelationsethelper.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/unohelp2.hxx>
35 #include <vcl/status.hxx>
36 #include <vcl/controllayout.hxx>
37 #include <vcl/settings.hxx>
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::beans
;
43 using namespace ::com::sun::star
;
44 using namespace ::comphelper
;
48 // class VCLXAccessibleStatusBarItem
51 VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar
* pStatusBar
, sal_uInt16 nItemId
)
52 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() )
53 ,m_pStatusBar( pStatusBar
)
56 m_pExternalLock
= static_cast< VCLExternalSolarLock
* >( getExternalLock() );
58 m_sItemName
= GetItemName();
59 m_sItemText
= GetItemText();
60 m_bShowing
= IsShowing();
65 VCLXAccessibleStatusBarItem::~VCLXAccessibleStatusBarItem()
67 delete m_pExternalLock
;
68 m_pExternalLock
= NULL
;
73 bool VCLXAccessibleStatusBarItem::IsShowing()
75 bool bShowing
= false;
78 bShowing
= m_pStatusBar
->IsItemVisible( m_nItemId
);
85 void VCLXAccessibleStatusBarItem::SetShowing( bool bShowing
)
87 if ( m_bShowing
!= bShowing
)
89 Any aOldValue
, aNewValue
;
91 aOldValue
<<= AccessibleStateType::SHOWING
;
93 aNewValue
<<= AccessibleStateType::SHOWING
;
94 m_bShowing
= bShowing
;
95 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
101 void VCLXAccessibleStatusBarItem::SetItemName( const OUString
& sItemName
)
103 if ( !m_sItemName
.equals( sItemName
) )
105 Any aOldValue
, aNewValue
;
106 aOldValue
<<= m_sItemName
;
107 aNewValue
<<= sItemName
;
108 m_sItemName
= sItemName
;
109 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
115 OUString
VCLXAccessibleStatusBarItem::GetItemName()
119 sName
= m_pStatusBar
->GetAccessibleName( m_nItemId
);
126 void VCLXAccessibleStatusBarItem::SetItemText( const OUString
& sItemText
)
128 Any aOldValue
, aNewValue
;
129 if ( implInitTextChangedEvent( m_sItemText
, sItemText
, aOldValue
, aNewValue
) )
131 m_sItemText
= sItemText
;
132 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED
, aOldValue
, aNewValue
);
138 OUString
VCLXAccessibleStatusBarItem::GetItemText()
141 vcl::ControlLayoutData aLayoutData
;
144 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
145 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
146 sText
= aLayoutData
.m_aDisplayText
;
154 void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
156 rStateSet
.AddState( AccessibleStateType::ENABLED
);
157 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
159 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
162 rStateSet
.AddState( AccessibleStateType::SHOWING
);
166 // OCommonAccessibleComponent
169 awt::Rectangle
VCLXAccessibleStatusBarItem::implGetBounds() throw (RuntimeException
)
171 awt::Rectangle
aBounds( 0, 0, 0, 0 );
174 aBounds
= AWTRectangle( m_pStatusBar
->GetItemRect( m_nItemId
) );
180 // OCommonAccessibleText
183 OUString
VCLXAccessibleStatusBarItem::implGetText()
185 return GetItemText();
190 lang::Locale
VCLXAccessibleStatusBarItem::implGetLocale()
192 return Application::GetSettings().GetLanguageTag().getLocale();
197 void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
207 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleStatusBarItem
, AccessibleTextHelper_BASE
, VCLXAccessibleStatusBarItem_BASE
)
213 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleStatusBarItem
, AccessibleTextHelper_BASE
, VCLXAccessibleStatusBarItem_BASE
)
219 void VCLXAccessibleStatusBarItem::disposing()
221 AccessibleTextHelper_BASE::disposing();
232 OUString
VCLXAccessibleStatusBarItem::getImplementationName() throw (RuntimeException
, std::exception
)
234 return OUString( "com.sun.star.comp.toolkit.AccessibleStatusBarItem" );
239 sal_Bool
VCLXAccessibleStatusBarItem::supportsService( const OUString
& rServiceName
) throw (RuntimeException
, std::exception
)
241 return cppu::supportsService(this, rServiceName
);
246 Sequence
< OUString
> VCLXAccessibleStatusBarItem::getSupportedServiceNames() throw (RuntimeException
, std::exception
)
248 Sequence
< OUString
> aNames(1);
249 aNames
[0] = "com.sun.star.awt.AccessibleStatusBarItem";
257 Reference
< XAccessibleContext
> VCLXAccessibleStatusBarItem::getAccessibleContext( ) throw (RuntimeException
, std::exception
)
259 OExternalLockGuard
aGuard( this );
265 // XAccessibleContext
268 sal_Int32
VCLXAccessibleStatusBarItem::getAccessibleChildCount() throw (RuntimeException
, std::exception
)
270 OExternalLockGuard
aGuard( this );
277 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
279 OExternalLockGuard
aGuard( this );
281 if ( i
< 0 || i
>= getAccessibleChildCount() )
282 throw IndexOutOfBoundsException();
284 return Reference
< XAccessible
>();
289 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleParent( ) throw (RuntimeException
, std::exception
)
291 OExternalLockGuard
aGuard( this );
293 Reference
< XAccessible
> xParent
;
295 xParent
= m_pStatusBar
->GetAccessible();
302 sal_Int32
VCLXAccessibleStatusBarItem::getAccessibleIndexInParent( ) throw (RuntimeException
, std::exception
)
304 OExternalLockGuard
aGuard( this );
306 sal_Int32 nIndexInParent
= -1;
308 nIndexInParent
= m_pStatusBar
->GetItemPos( m_nItemId
);
310 return nIndexInParent
;
315 sal_Int16
VCLXAccessibleStatusBarItem::getAccessibleRole( ) throw (RuntimeException
, std::exception
)
317 OExternalLockGuard
aGuard( this );
319 return AccessibleRole::LABEL
;
324 OUString
VCLXAccessibleStatusBarItem::getAccessibleDescription( ) throw (RuntimeException
, std::exception
)
326 OExternalLockGuard
aGuard( this );
328 OUString sDescription
;
330 sDescription
= m_pStatusBar
->GetHelpText( m_nItemId
);
337 OUString
VCLXAccessibleStatusBarItem::getAccessibleName( ) throw (RuntimeException
, std::exception
)
339 OExternalLockGuard
aGuard( this );
341 return GetItemName();
346 Reference
< XAccessibleRelationSet
> VCLXAccessibleStatusBarItem::getAccessibleRelationSet( ) throw (RuntimeException
, std::exception
)
348 OExternalLockGuard
aGuard( this );
350 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
351 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
357 Reference
< XAccessibleStateSet
> VCLXAccessibleStatusBarItem::getAccessibleStateSet( ) throw (RuntimeException
, std::exception
)
359 OExternalLockGuard
aGuard( this );
361 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
362 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
364 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
366 FillAccessibleStateSet( *pStateSetHelper
);
370 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
378 Locale
VCLXAccessibleStatusBarItem::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
, std::exception
)
380 OExternalLockGuard
aGuard( this );
382 return Application::GetSettings().GetLanguageTag().getLocale();
386 // XAccessibleComponent
389 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point
& ) throw (RuntimeException
, std::exception
)
391 OExternalLockGuard
aGuard( this );
393 return Reference
< XAccessible
>();
398 void VCLXAccessibleStatusBarItem::grabFocus( ) throw (RuntimeException
, std::exception
)
400 // no focus for status bar items
405 sal_Int32
VCLXAccessibleStatusBarItem::getForeground( ) throw (RuntimeException
, std::exception
)
407 OExternalLockGuard
aGuard( this );
409 sal_Int32 nColor
= 0;
410 Reference
< XAccessible
> xParent
= getAccessibleParent();
413 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
414 if ( xParentComp
.is() )
415 nColor
= xParentComp
->getForeground();
423 sal_Int32
VCLXAccessibleStatusBarItem::getBackground( ) throw (RuntimeException
, std::exception
)
425 OExternalLockGuard
aGuard( this );
427 sal_Int32 nColor
= 0;
428 Reference
< XAccessible
> xParent
= getAccessibleParent();
431 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
432 if ( xParentComp
.is() )
433 nColor
= xParentComp
->getBackground();
440 // XAccessibleExtendedComponent
443 Reference
< awt::XFont
> VCLXAccessibleStatusBarItem::getFont( ) throw (RuntimeException
, std::exception
)
445 OExternalLockGuard
aGuard( this );
447 Reference
< awt::XFont
> xFont
;
448 Reference
< XAccessible
> xParent
= getAccessibleParent();
451 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
452 if ( xParentComp
.is() )
453 xFont
= xParentComp
->getFont();
461 OUString
VCLXAccessibleStatusBarItem::getTitledBorderText( ) throw (RuntimeException
, std::exception
)
463 OExternalLockGuard
aGuard( this );
465 return GetItemText();
470 OUString
VCLXAccessibleStatusBarItem::getToolTipText( ) throw (RuntimeException
, std::exception
)
472 OExternalLockGuard
aGuard( this );
481 sal_Int32
VCLXAccessibleStatusBarItem::getCaretPosition() throw (RuntimeException
, std::exception
)
483 OExternalLockGuard
aGuard( this );
490 sal_Bool
VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
492 OExternalLockGuard
aGuard( this );
494 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
495 throw IndexOutOfBoundsException();
502 Sequence
< PropertyValue
> VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex
, const Sequence
< OUString
>& aRequestedAttributes
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
504 OExternalLockGuard
aGuard( this );
506 Sequence
< PropertyValue
> aValues
;
507 OUString
sText( implGetText() );
509 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
510 throw IndexOutOfBoundsException();
514 vcl::Font aFont
= m_pStatusBar
->GetFont();
515 sal_Int32 nBackColor
= getBackground();
516 sal_Int32 nColor
= getForeground();
517 aValues
= CharacterAttributesHelper( aFont
, nBackColor
, nColor
)
518 .GetCharacterAttributes( aRequestedAttributes
);
526 awt::Rectangle
VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
528 OExternalLockGuard
aGuard( this );
530 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
531 throw IndexOutOfBoundsException();
533 awt::Rectangle
aBounds( 0, 0, 0, 0 );
536 vcl::ControlLayoutData aLayoutData
;
537 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
538 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
539 Rectangle aCharRect
= aLayoutData
.GetCharacterBounds( nIndex
);
540 aCharRect
.Move( -aItemRect
.Left(), -aItemRect
.Top() );
541 aBounds
= AWTRectangle( aCharRect
);
549 sal_Int32
VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point
& aPoint
) throw (RuntimeException
, std::exception
)
551 OExternalLockGuard
aGuard( this );
553 sal_Int32 nIndex
= -1;
556 vcl::ControlLayoutData aLayoutData
;
557 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
558 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
559 Point
aPnt( VCLPoint( aPoint
) );
560 aPnt
+= aItemRect
.TopLeft();
561 nIndex
= aLayoutData
.GetIndexForPoint( aPnt
);
569 sal_Bool
VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
571 OExternalLockGuard
aGuard( this );
573 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
574 throw IndexOutOfBoundsException();
581 sal_Bool
VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
583 OExternalLockGuard
aGuard( this );
585 bool bReturn
= false;
589 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= m_pStatusBar
->GetClipboard();
590 if ( xClipboard
.is() )
592 OUString
sText( getTextRange( nStartIndex
, nEndIndex
) );
594 vcl::unohelper::TextDataObject
* pDataObj
= new vcl::unohelper::TextDataObject( sText
);
596 SolarMutexReleaser aReleaser
;
597 xClipboard
->setContents( pDataObj
, NULL
);
599 Reference
< datatransfer::clipboard::XFlushableClipboard
> xFlushableClipboard( xClipboard
, uno::UNO_QUERY
);
600 if( xFlushableClipboard
.is() )
601 xFlushableClipboard
->flushClipboard();
612 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */