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>
41 using namespace ::com::sun::star::accessibility
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star
;
46 using namespace ::comphelper
;
49 // -----------------------------------------------------------------------------
50 // class VCLXAccessibleStatusBarItem
51 // -----------------------------------------------------------------------------
53 VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar
* pStatusBar
, sal_uInt16 nItemId
)
54 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() )
55 ,m_pStatusBar( pStatusBar
)
58 m_pExternalLock
= static_cast< VCLExternalSolarLock
* >( getExternalLock() );
60 m_sItemName
= GetItemName();
61 m_sItemText
= GetItemText();
62 m_bShowing
= IsShowing();
65 // -----------------------------------------------------------------------------
67 VCLXAccessibleStatusBarItem::~VCLXAccessibleStatusBarItem()
69 delete m_pExternalLock
;
70 m_pExternalLock
= NULL
;
73 // -----------------------------------------------------------------------------
75 sal_Bool
VCLXAccessibleStatusBarItem::IsShowing()
77 sal_Bool bShowing
= sal_False
;
80 bShowing
= m_pStatusBar
->IsItemVisible( m_nItemId
);
85 // -----------------------------------------------------------------------------
87 void VCLXAccessibleStatusBarItem::SetShowing( sal_Bool bShowing
)
89 if ( m_bShowing
!= bShowing
)
91 Any aOldValue
, aNewValue
;
93 aOldValue
<<= AccessibleStateType::SHOWING
;
95 aNewValue
<<= AccessibleStateType::SHOWING
;
96 m_bShowing
= bShowing
;
97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
101 // -----------------------------------------------------------------------------
103 void VCLXAccessibleStatusBarItem::SetItemName( const OUString
& sItemName
)
105 if ( !m_sItemName
.equals( sItemName
) )
107 Any aOldValue
, aNewValue
;
108 aOldValue
<<= m_sItemName
;
109 aNewValue
<<= sItemName
;
110 m_sItemName
= sItemName
;
111 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
115 // -----------------------------------------------------------------------------
117 OUString
VCLXAccessibleStatusBarItem::GetItemName()
121 sName
= m_pStatusBar
->GetAccessibleName( m_nItemId
);
126 // -----------------------------------------------------------------------------
128 void VCLXAccessibleStatusBarItem::SetItemText( const OUString
& sItemText
)
130 Any aOldValue
, aNewValue
;
131 if ( implInitTextChangedEvent( m_sItemText
, sItemText
, aOldValue
, aNewValue
) )
133 m_sItemText
= sItemText
;
134 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED
, aOldValue
, aNewValue
);
138 // -----------------------------------------------------------------------------
140 OUString
VCLXAccessibleStatusBarItem::GetItemText()
143 ::vcl::ControlLayoutData aLayoutData
;
146 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
147 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
148 sText
= aLayoutData
.m_aDisplayText
;
154 // -----------------------------------------------------------------------------
156 void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
158 rStateSet
.AddState( AccessibleStateType::ENABLED
);
159 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
161 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
164 rStateSet
.AddState( AccessibleStateType::SHOWING
);
167 // -----------------------------------------------------------------------------
168 // OCommonAccessibleComponent
169 // -----------------------------------------------------------------------------
171 awt::Rectangle
VCLXAccessibleStatusBarItem::implGetBounds() throw (RuntimeException
)
173 awt::Rectangle
aBounds( 0, 0, 0, 0 );
176 aBounds
= AWTRectangle( m_pStatusBar
->GetItemRect( m_nItemId
) );
181 // -----------------------------------------------------------------------------
182 // OCommonAccessibleText
183 // -----------------------------------------------------------------------------
185 OUString
VCLXAccessibleStatusBarItem::implGetText()
187 return GetItemText();
190 // -----------------------------------------------------------------------------
192 lang::Locale
VCLXAccessibleStatusBarItem::implGetLocale()
194 return Application::GetSettings().GetLanguageTag().getLocale();
197 // -----------------------------------------------------------------------------
199 void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
205 // -----------------------------------------------------------------------------
207 // -----------------------------------------------------------------------------
209 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleStatusBarItem
, AccessibleTextHelper_BASE
, VCLXAccessibleStatusBarItem_BASE
)
211 // -----------------------------------------------------------------------------
213 // -----------------------------------------------------------------------------
215 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleStatusBarItem
, AccessibleTextHelper_BASE
, VCLXAccessibleStatusBarItem_BASE
)
217 // -----------------------------------------------------------------------------
219 // -----------------------------------------------------------------------------
221 void VCLXAccessibleStatusBarItem::disposing()
223 AccessibleTextHelper_BASE::disposing();
226 m_sItemName
= OUString();
227 m_sItemText
= OUString();
230 // -----------------------------------------------------------------------------
232 // -----------------------------------------------------------------------------
234 OUString
VCLXAccessibleStatusBarItem::getImplementationName() throw (RuntimeException
)
236 return OUString( "com.sun.star.comp.toolkit.AccessibleStatusBarItem" );
239 // -----------------------------------------------------------------------------
241 sal_Bool
VCLXAccessibleStatusBarItem::supportsService( const OUString
& rServiceName
) throw (RuntimeException
)
243 return cppu::supportsService(this, rServiceName
);
246 // -----------------------------------------------------------------------------
248 Sequence
< OUString
> VCLXAccessibleStatusBarItem::getSupportedServiceNames() throw (RuntimeException
)
250 Sequence
< OUString
> aNames(1);
251 aNames
[0] = "com.sun.star.awt.AccessibleStatusBarItem";
255 // -----------------------------------------------------------------------------
257 // -----------------------------------------------------------------------------
259 Reference
< XAccessibleContext
> VCLXAccessibleStatusBarItem::getAccessibleContext( ) throw (RuntimeException
)
261 OExternalLockGuard
aGuard( this );
266 // -----------------------------------------------------------------------------
267 // XAccessibleContext
268 // -----------------------------------------------------------------------------
270 sal_Int32
VCLXAccessibleStatusBarItem::getAccessibleChildCount() throw (RuntimeException
)
272 OExternalLockGuard
aGuard( this );
277 // -----------------------------------------------------------------------------
279 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
281 OExternalLockGuard
aGuard( this );
283 if ( i
< 0 || i
>= getAccessibleChildCount() )
284 throw IndexOutOfBoundsException();
286 return Reference
< XAccessible
>();
289 // -----------------------------------------------------------------------------
291 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleParent( ) throw (RuntimeException
)
293 OExternalLockGuard
aGuard( this );
295 Reference
< XAccessible
> xParent
;
297 xParent
= m_pStatusBar
->GetAccessible();
302 // -----------------------------------------------------------------------------
304 sal_Int32
VCLXAccessibleStatusBarItem::getAccessibleIndexInParent( ) throw (RuntimeException
)
306 OExternalLockGuard
aGuard( this );
308 sal_Int32 nIndexInParent
= -1;
310 nIndexInParent
= m_pStatusBar
->GetItemPos( m_nItemId
);
312 return nIndexInParent
;
315 // -----------------------------------------------------------------------------
317 sal_Int16
VCLXAccessibleStatusBarItem::getAccessibleRole( ) throw (RuntimeException
)
319 OExternalLockGuard
aGuard( this );
321 return AccessibleRole::LABEL
;
324 // -----------------------------------------------------------------------------
326 OUString
VCLXAccessibleStatusBarItem::getAccessibleDescription( ) throw (RuntimeException
)
328 OExternalLockGuard
aGuard( this );
330 OUString sDescription
;
332 sDescription
= m_pStatusBar
->GetHelpText( m_nItemId
);
337 // -----------------------------------------------------------------------------
339 OUString
VCLXAccessibleStatusBarItem::getAccessibleName( ) throw (RuntimeException
)
341 OExternalLockGuard
aGuard( this );
343 return GetItemName();
346 // -----------------------------------------------------------------------------
348 Reference
< XAccessibleRelationSet
> VCLXAccessibleStatusBarItem::getAccessibleRelationSet( ) throw (RuntimeException
)
350 OExternalLockGuard
aGuard( this );
352 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
353 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
357 // -----------------------------------------------------------------------------
359 Reference
< XAccessibleStateSet
> VCLXAccessibleStatusBarItem::getAccessibleStateSet( ) throw (RuntimeException
)
361 OExternalLockGuard
aGuard( this );
363 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
364 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
366 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
368 FillAccessibleStateSet( *pStateSetHelper
);
372 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
378 // -----------------------------------------------------------------------------
380 Locale
VCLXAccessibleStatusBarItem::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
382 OExternalLockGuard
aGuard( this );
384 return Application::GetSettings().GetLanguageTag().getLocale();
387 // -----------------------------------------------------------------------------
388 // XAccessibleComponent
389 // -----------------------------------------------------------------------------
391 Reference
< XAccessible
> VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point
& ) throw (RuntimeException
)
393 OExternalLockGuard
aGuard( this );
395 return Reference
< XAccessible
>();
398 // -----------------------------------------------------------------------------
400 void VCLXAccessibleStatusBarItem::grabFocus( ) throw (RuntimeException
)
402 // no focus for status bar items
405 // -----------------------------------------------------------------------------
407 sal_Int32
VCLXAccessibleStatusBarItem::getForeground( ) throw (RuntimeException
)
409 OExternalLockGuard
aGuard( this );
411 sal_Int32 nColor
= 0;
412 Reference
< XAccessible
> xParent
= getAccessibleParent();
415 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
416 if ( xParentComp
.is() )
417 nColor
= xParentComp
->getForeground();
423 // -----------------------------------------------------------------------------
425 sal_Int32
VCLXAccessibleStatusBarItem::getBackground( ) throw (RuntimeException
)
427 OExternalLockGuard
aGuard( this );
429 sal_Int32 nColor
= 0;
430 Reference
< XAccessible
> xParent
= getAccessibleParent();
433 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
434 if ( xParentComp
.is() )
435 nColor
= xParentComp
->getBackground();
441 // -----------------------------------------------------------------------------
442 // XAccessibleExtendedComponent
443 // -----------------------------------------------------------------------------
445 Reference
< awt::XFont
> VCLXAccessibleStatusBarItem::getFont( ) throw (RuntimeException
)
447 OExternalLockGuard
aGuard( this );
449 Reference
< awt::XFont
> xFont
;
450 Reference
< XAccessible
> xParent
= getAccessibleParent();
453 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
454 if ( xParentComp
.is() )
455 xFont
= xParentComp
->getFont();
461 // -----------------------------------------------------------------------------
463 OUString
VCLXAccessibleStatusBarItem::getTitledBorderText( ) throw (RuntimeException
)
465 OExternalLockGuard
aGuard( this );
467 return GetItemText();
470 // -----------------------------------------------------------------------------
472 OUString
VCLXAccessibleStatusBarItem::getToolTipText( ) throw (RuntimeException
)
474 OExternalLockGuard
aGuard( this );
479 // -----------------------------------------------------------------------------
481 // -----------------------------------------------------------------------------
483 sal_Int32
VCLXAccessibleStatusBarItem::getCaretPosition() throw (RuntimeException
)
485 OExternalLockGuard
aGuard( this );
490 // -----------------------------------------------------------------------------
492 sal_Bool
VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
494 OExternalLockGuard
aGuard( this );
496 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
497 throw IndexOutOfBoundsException();
502 // -----------------------------------------------------------------------------
504 Sequence
< PropertyValue
> VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex
, const Sequence
< OUString
>& aRequestedAttributes
) throw (IndexOutOfBoundsException
, RuntimeException
)
506 OExternalLockGuard
aGuard( this );
508 Sequence
< PropertyValue
> aValues
;
509 OUString
sText( implGetText() );
511 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
512 throw IndexOutOfBoundsException();
516 Font aFont
= m_pStatusBar
->GetFont();
517 sal_Int32 nBackColor
= getBackground();
518 sal_Int32 nColor
= getForeground();
519 ::std::auto_ptr
< CharacterAttributesHelper
> pHelper( new CharacterAttributesHelper( aFont
, nBackColor
, nColor
) );
520 aValues
= pHelper
->GetCharacterAttributes( aRequestedAttributes
);
526 // -----------------------------------------------------------------------------
528 awt::Rectangle
VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
530 OExternalLockGuard
aGuard( this );
532 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
533 throw IndexOutOfBoundsException();
535 awt::Rectangle
aBounds( 0, 0, 0, 0 );
538 ::vcl::ControlLayoutData aLayoutData
;
539 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
540 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
541 Rectangle aCharRect
= aLayoutData
.GetCharacterBounds( nIndex
);
542 aCharRect
.Move( -aItemRect
.Left(), -aItemRect
.Top() );
543 aBounds
= AWTRectangle( aCharRect
);
549 // -----------------------------------------------------------------------------
551 sal_Int32
VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point
& aPoint
) throw (RuntimeException
)
553 OExternalLockGuard
aGuard( this );
555 sal_Int32 nIndex
= -1;
558 ::vcl::ControlLayoutData aLayoutData
;
559 Rectangle aItemRect
= m_pStatusBar
->GetItemRect( m_nItemId
);
560 m_pStatusBar
->RecordLayoutData( &aLayoutData
, aItemRect
);
561 Point
aPnt( VCLPoint( aPoint
) );
562 aPnt
+= aItemRect
.TopLeft();
563 nIndex
= aLayoutData
.GetIndexForPoint( aPnt
);
569 // -----------------------------------------------------------------------------
571 sal_Bool
VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
573 OExternalLockGuard
aGuard( this );
575 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
576 throw IndexOutOfBoundsException();
581 // -----------------------------------------------------------------------------
583 sal_Bool
VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
585 OExternalLockGuard
aGuard( this );
587 sal_Bool bReturn
= sal_False
;
591 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= m_pStatusBar
->GetClipboard();
592 if ( xClipboard
.is() )
594 OUString
sText( getTextRange( nStartIndex
, nEndIndex
) );
596 ::vcl::unohelper::TextDataObject
* pDataObj
= new ::vcl::unohelper::TextDataObject( sText
);
597 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
598 xClipboard
->setContents( pDataObj
, NULL
);
600 Reference
< datatransfer::clipboard::XFlushableClipboard
> xFlushableClipboard( xClipboard
, uno::UNO_QUERY
);
601 if( xFlushableClipboard
.is() )
602 xFlushableClipboard
->flushClipboard();
604 Application::AcquireSolarMutex( nRef
);
613 // -----------------------------------------------------------------------------
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */