merged tag ooo/DEV300_m102
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblestatusbaritem.cxx
blobc3badc50bdbf880040958a8327cfd1724655eaf6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
31 #include <toolkit/helper/externallock.hxx>
32 #include <toolkit/helper/convert.hxx>
33 #include <accessibility/helper/characterattributeshelper.hxx>
35 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36 #include <com/sun/star/accessibility/AccessibleRole.hpp>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
39 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
41 #include <unotools/accessiblestatesethelper.hxx>
42 #include <unotools/accessiblerelationsethelper.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/unohelp2.hxx>
45 #include <vcl/status.hxx>
46 #include <vcl/controllayout.hxx>
48 #include <memory>
51 using namespace ::com::sun::star::accessibility;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star;
56 using namespace ::comphelper;
59 // -----------------------------------------------------------------------------
60 // class VCLXAccessibleStatusBarItem
61 // -----------------------------------------------------------------------------
63 VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar* pStatusBar, sal_uInt16 nItemId )
64 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() )
65 ,m_pStatusBar( pStatusBar )
66 ,m_nItemId( nItemId )
68 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() );
70 m_sItemName = GetItemName();
71 m_sItemText = GetItemText();
72 m_bShowing = IsShowing();
75 // -----------------------------------------------------------------------------
77 VCLXAccessibleStatusBarItem::~VCLXAccessibleStatusBarItem()
79 delete m_pExternalLock;
80 m_pExternalLock = NULL;
83 // -----------------------------------------------------------------------------
85 sal_Bool VCLXAccessibleStatusBarItem::IsShowing()
87 sal_Bool bShowing = sal_False;
89 if ( m_pStatusBar )
90 bShowing = m_pStatusBar->IsItemVisible( m_nItemId );
92 return bShowing;
95 // -----------------------------------------------------------------------------
97 void VCLXAccessibleStatusBarItem::SetShowing( sal_Bool bShowing )
99 if ( m_bShowing != bShowing )
101 Any aOldValue, aNewValue;
102 if ( m_bShowing )
103 aOldValue <<= AccessibleStateType::SHOWING;
104 else
105 aNewValue <<= AccessibleStateType::SHOWING;
106 m_bShowing = bShowing;
107 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
111 // -----------------------------------------------------------------------------
113 void VCLXAccessibleStatusBarItem::SetItemName( const ::rtl::OUString& sItemName )
115 if ( !m_sItemName.equals( sItemName ) )
117 Any aOldValue, aNewValue;
118 aOldValue <<= m_sItemName;
119 aNewValue <<= sItemName;
120 m_sItemName = sItemName;
121 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
125 // -----------------------------------------------------------------------------
127 ::rtl::OUString VCLXAccessibleStatusBarItem::GetItemName()
129 ::rtl::OUString sName;
130 if ( m_pStatusBar )
131 sName = m_pStatusBar->GetAccessibleName( m_nItemId );
133 return sName;
136 // -----------------------------------------------------------------------------
138 void VCLXAccessibleStatusBarItem::SetItemText( const ::rtl::OUString& sItemText )
140 Any aOldValue, aNewValue;
141 if ( implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) )
143 m_sItemText = sItemText;
144 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
148 // -----------------------------------------------------------------------------
150 ::rtl::OUString VCLXAccessibleStatusBarItem::GetItemText()
152 ::rtl::OUString sText;
153 ::vcl::ControlLayoutData aLayoutData;
154 if ( m_pStatusBar )
156 Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
157 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
158 sText = aLayoutData.m_aDisplayText;
161 return sText;
164 // -----------------------------------------------------------------------------
166 void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
168 rStateSet.AddState( AccessibleStateType::ENABLED );
169 rStateSet.AddState( AccessibleStateType::SENSITIVE );
171 rStateSet.AddState( AccessibleStateType::VISIBLE );
173 if ( IsShowing() )
174 rStateSet.AddState( AccessibleStateType::SHOWING );
177 // -----------------------------------------------------------------------------
178 // OCommonAccessibleComponent
179 // -----------------------------------------------------------------------------
181 awt::Rectangle VCLXAccessibleStatusBarItem::implGetBounds() throw (RuntimeException)
183 awt::Rectangle aBounds( 0, 0, 0, 0 );
185 if ( m_pStatusBar )
186 aBounds = AWTRectangle( m_pStatusBar->GetItemRect( m_nItemId ) );
188 return aBounds;
191 // -----------------------------------------------------------------------------
192 // OCommonAccessibleText
193 // -----------------------------------------------------------------------------
195 ::rtl::OUString VCLXAccessibleStatusBarItem::implGetText()
197 return GetItemText();
200 // -----------------------------------------------------------------------------
202 lang::Locale VCLXAccessibleStatusBarItem::implGetLocale()
204 return Application::GetSettings().GetLocale();
207 // -----------------------------------------------------------------------------
209 void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
211 nStartIndex = 0;
212 nEndIndex = 0;
215 // -----------------------------------------------------------------------------
216 // XInterface
217 // -----------------------------------------------------------------------------
219 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleStatusBarItem, AccessibleTextHelper_BASE, VCLXAccessibleStatusBarItem_BASE )
221 // -----------------------------------------------------------------------------
222 // XTypeProvider
223 // -----------------------------------------------------------------------------
225 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleStatusBarItem, AccessibleTextHelper_BASE, VCLXAccessibleStatusBarItem_BASE )
227 // -----------------------------------------------------------------------------
228 // XComponent
229 // -----------------------------------------------------------------------------
231 void VCLXAccessibleStatusBarItem::disposing()
233 AccessibleTextHelper_BASE::disposing();
235 m_pStatusBar = NULL;
236 m_sItemName = ::rtl::OUString();
237 m_sItemText = ::rtl::OUString();
240 // -----------------------------------------------------------------------------
241 // XServiceInfo
242 // -----------------------------------------------------------------------------
244 ::rtl::OUString VCLXAccessibleStatusBarItem::getImplementationName() throw (RuntimeException)
246 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleStatusBarItem" );
249 // -----------------------------------------------------------------------------
251 sal_Bool VCLXAccessibleStatusBarItem::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
253 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
254 const ::rtl::OUString* pNames = aNames.getConstArray();
255 const ::rtl::OUString* pEnd = pNames + aNames.getLength();
256 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
259 return pNames != pEnd;
262 // -----------------------------------------------------------------------------
264 Sequence< ::rtl::OUString > VCLXAccessibleStatusBarItem::getSupportedServiceNames() throw (RuntimeException)
266 Sequence< ::rtl::OUString > aNames(1);
267 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleStatusBarItem" );
268 return aNames;
271 // -----------------------------------------------------------------------------
272 // XAccessible
273 // -----------------------------------------------------------------------------
275 Reference< XAccessibleContext > VCLXAccessibleStatusBarItem::getAccessibleContext( ) throw (RuntimeException)
277 OExternalLockGuard aGuard( this );
279 return this;
282 // -----------------------------------------------------------------------------
283 // XAccessibleContext
284 // -----------------------------------------------------------------------------
286 sal_Int32 VCLXAccessibleStatusBarItem::getAccessibleChildCount() throw (RuntimeException)
288 OExternalLockGuard aGuard( this );
290 return 0;
293 // -----------------------------------------------------------------------------
295 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
297 OExternalLockGuard aGuard( this );
299 if ( i < 0 || i >= getAccessibleChildCount() )
300 throw IndexOutOfBoundsException();
302 return Reference< XAccessible >();
305 // -----------------------------------------------------------------------------
307 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleParent( ) throw (RuntimeException)
309 OExternalLockGuard aGuard( this );
311 Reference< XAccessible > xParent;
312 if ( m_pStatusBar )
313 xParent = m_pStatusBar->GetAccessible();
315 return xParent;
318 // -----------------------------------------------------------------------------
320 sal_Int32 VCLXAccessibleStatusBarItem::getAccessibleIndexInParent( ) throw (RuntimeException)
322 OExternalLockGuard aGuard( this );
324 sal_Int32 nIndexInParent = -1;
325 if ( m_pStatusBar )
326 nIndexInParent = m_pStatusBar->GetItemPos( m_nItemId );
328 return nIndexInParent;
331 // -----------------------------------------------------------------------------
333 sal_Int16 VCLXAccessibleStatusBarItem::getAccessibleRole( ) throw (RuntimeException)
335 OExternalLockGuard aGuard( this );
337 return AccessibleRole::LABEL;
340 // -----------------------------------------------------------------------------
342 ::rtl::OUString VCLXAccessibleStatusBarItem::getAccessibleDescription( ) throw (RuntimeException)
344 OExternalLockGuard aGuard( this );
346 ::rtl::OUString sDescription;
347 if ( m_pStatusBar )
348 sDescription = m_pStatusBar->GetHelpText( m_nItemId );
350 return sDescription;
353 // -----------------------------------------------------------------------------
355 ::rtl::OUString VCLXAccessibleStatusBarItem::getAccessibleName( ) throw (RuntimeException)
357 OExternalLockGuard aGuard( this );
359 return GetItemName();
362 // -----------------------------------------------------------------------------
364 Reference< XAccessibleRelationSet > VCLXAccessibleStatusBarItem::getAccessibleRelationSet( ) throw (RuntimeException)
366 OExternalLockGuard aGuard( this );
368 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
369 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
370 return xSet;
373 // -----------------------------------------------------------------------------
375 Reference< XAccessibleStateSet > VCLXAccessibleStatusBarItem::getAccessibleStateSet( ) throw (RuntimeException)
377 OExternalLockGuard aGuard( this );
379 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
380 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
382 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
384 FillAccessibleStateSet( *pStateSetHelper );
386 else
388 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
391 return xSet;
394 // -----------------------------------------------------------------------------
396 Locale VCLXAccessibleStatusBarItem::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
398 OExternalLockGuard aGuard( this );
400 return Application::GetSettings().GetLocale();
403 // -----------------------------------------------------------------------------
404 // XAccessibleComponent
405 // -----------------------------------------------------------------------------
407 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
409 OExternalLockGuard aGuard( this );
411 return Reference< XAccessible >();
414 // -----------------------------------------------------------------------------
416 void VCLXAccessibleStatusBarItem::grabFocus( ) throw (RuntimeException)
418 // no focus for status bar items
421 // -----------------------------------------------------------------------------
423 sal_Int32 VCLXAccessibleStatusBarItem::getForeground( ) throw (RuntimeException)
425 OExternalLockGuard aGuard( this );
427 sal_Int32 nColor = 0;
428 Reference< XAccessible > xParent = getAccessibleParent();
429 if ( xParent.is() )
431 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
432 if ( xParentComp.is() )
433 nColor = xParentComp->getForeground();
436 return nColor;
439 // -----------------------------------------------------------------------------
441 sal_Int32 VCLXAccessibleStatusBarItem::getBackground( ) throw (RuntimeException)
443 OExternalLockGuard aGuard( this );
445 sal_Int32 nColor = 0;
446 Reference< XAccessible > xParent = getAccessibleParent();
447 if ( xParent.is() )
449 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
450 if ( xParentComp.is() )
451 nColor = xParentComp->getBackground();
454 return nColor;
457 // -----------------------------------------------------------------------------
458 // XAccessibleExtendedComponent
459 // -----------------------------------------------------------------------------
461 Reference< awt::XFont > VCLXAccessibleStatusBarItem::getFont( ) throw (RuntimeException)
463 OExternalLockGuard aGuard( this );
465 Reference< awt::XFont > xFont;
466 Reference< XAccessible > xParent = getAccessibleParent();
467 if ( xParent.is() )
469 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
470 if ( xParentComp.is() )
471 xFont = xParentComp->getFont();
474 return xFont;
477 // -----------------------------------------------------------------------------
479 ::rtl::OUString VCLXAccessibleStatusBarItem::getTitledBorderText( ) throw (RuntimeException)
481 OExternalLockGuard aGuard( this );
483 return GetItemText();
486 // -----------------------------------------------------------------------------
488 ::rtl::OUString VCLXAccessibleStatusBarItem::getToolTipText( ) throw (RuntimeException)
490 OExternalLockGuard aGuard( this );
492 return ::rtl::OUString();
495 // -----------------------------------------------------------------------------
496 // XAccessibleText
497 // -----------------------------------------------------------------------------
499 sal_Int32 VCLXAccessibleStatusBarItem::getCaretPosition() throw (RuntimeException)
501 OExternalLockGuard aGuard( this );
503 return -1;
506 // -----------------------------------------------------------------------------
508 sal_Bool VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
510 OExternalLockGuard aGuard( this );
512 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
513 throw IndexOutOfBoundsException();
515 return sal_False;
518 // -----------------------------------------------------------------------------
520 Sequence< PropertyValue > VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException)
522 OExternalLockGuard aGuard( this );
524 Sequence< PropertyValue > aValues;
525 ::rtl::OUString sText( implGetText() );
527 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
528 throw IndexOutOfBoundsException();
530 if ( m_pStatusBar )
532 Font aFont = m_pStatusBar->GetFont();
533 sal_Int32 nBackColor = getBackground();
534 sal_Int32 nColor = getForeground();
535 ::std::auto_ptr< CharacterAttributesHelper > pHelper( new CharacterAttributesHelper( aFont, nBackColor, nColor ) );
536 aValues = pHelper->GetCharacterAttributes( aRequestedAttributes );
539 return aValues;
542 // -----------------------------------------------------------------------------
544 awt::Rectangle VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
546 OExternalLockGuard aGuard( this );
548 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
549 throw IndexOutOfBoundsException();
551 awt::Rectangle aBounds( 0, 0, 0, 0 );
552 if ( m_pStatusBar )
554 ::vcl::ControlLayoutData aLayoutData;
555 Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
556 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
557 Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
558 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
559 aBounds = AWTRectangle( aCharRect );
562 return aBounds;
565 // -----------------------------------------------------------------------------
567 sal_Int32 VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
569 OExternalLockGuard aGuard( this );
571 sal_Int32 nIndex = -1;
572 if ( m_pStatusBar )
574 ::vcl::ControlLayoutData aLayoutData;
575 Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
576 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
577 Point aPnt( VCLPoint( aPoint ) );
578 aPnt += aItemRect.TopLeft();
579 nIndex = aLayoutData.GetIndexForPoint( aPnt );
582 return nIndex;
585 // -----------------------------------------------------------------------------
587 sal_Bool VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
589 OExternalLockGuard aGuard( this );
591 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
592 throw IndexOutOfBoundsException();
594 return sal_False;
597 // -----------------------------------------------------------------------------
599 sal_Bool VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
601 OExternalLockGuard aGuard( this );
603 sal_Bool bReturn = sal_False;
605 if ( m_pStatusBar )
607 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pStatusBar->GetClipboard();
608 if ( xClipboard.is() )
610 ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
612 ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
613 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
614 xClipboard->setContents( pDataObj, NULL );
616 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
617 if( xFlushableClipboard.is() )
618 xFlushableClipboard->flushClipboard();
620 Application::AcquireSolarMutex( nRef );
622 bReturn = sal_True;
626 return bReturn;
629 // -----------------------------------------------------------------------------