Update ooo320-m1
[ooovba.git] / accessibility / source / standard / vclxaccessibletabpage.cxx
blob7e0e7e0421d47ed20d1e564e3d72edbfaa69f6e7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessibletabpage.cxx,v $
10 * $Revision: 1.3 $
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/vclxaccessibletabpage.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/tabctrl.hxx>
49 #include <vcl/tabpage.hxx>
51 #include <memory>
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 VCLXAccessibleTabPage
64 // -----------------------------------------------------------------------------
66 VCLXAccessibleTabPage::VCLXAccessibleTabPage( TabControl* pTabControl, sal_uInt16 nPageId )
67 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() )
68 ,m_pTabControl( pTabControl )
69 ,m_nPageId( nPageId )
71 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() );
72 m_bFocused = IsFocused();
73 m_bSelected = IsSelected();
74 m_sPageText = GetPageText();
77 // -----------------------------------------------------------------------------
79 VCLXAccessibleTabPage::~VCLXAccessibleTabPage()
81 delete m_pExternalLock;
82 m_pExternalLock = NULL;
85 // -----------------------------------------------------------------------------
87 bool VCLXAccessibleTabPage::IsFocused()
89 bool bFocused = false;
91 if ( m_pTabControl && m_pTabControl->HasFocus() && m_pTabControl->GetCurPageId() == m_nPageId )
92 bFocused = true;
94 return bFocused;
97 // -----------------------------------------------------------------------------
99 bool VCLXAccessibleTabPage::IsSelected()
101 bool bSelected = false;
103 if ( m_pTabControl && m_pTabControl->GetCurPageId() == m_nPageId )
104 bSelected = true;
106 return bSelected;
109 // -----------------------------------------------------------------------------
111 void VCLXAccessibleTabPage::SetFocused( bool bFocused )
113 if ( m_bFocused != bFocused )
115 Any aOldValue, aNewValue;
116 if ( m_bFocused )
117 aOldValue <<= AccessibleStateType::FOCUSED;
118 else
119 aNewValue <<= AccessibleStateType::FOCUSED;
120 m_bFocused = bFocused;
121 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
125 // -----------------------------------------------------------------------------
127 void VCLXAccessibleTabPage::SetSelected( bool bSelected )
129 if ( m_bSelected != bSelected )
131 Any aOldValue, aNewValue;
132 if ( m_bSelected )
133 aOldValue <<= AccessibleStateType::SELECTED;
134 else
135 aNewValue <<= AccessibleStateType::SELECTED;
136 m_bSelected = bSelected;
137 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
141 // -----------------------------------------------------------------------------
143 void VCLXAccessibleTabPage::SetPageText( const ::rtl::OUString& sPageText )
145 Any aOldValue, aNewValue;
146 if ( OCommonAccessibleText::implInitTextChangedEvent( m_sPageText, sPageText, aOldValue, aNewValue ) )
148 Any aOldName, aNewName;
149 aOldName <<= m_sPageText;
150 aNewName <<= sPageText;
151 m_sPageText = sPageText;
152 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldName, aNewName );
153 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
157 // -----------------------------------------------------------------------------
159 ::rtl::OUString VCLXAccessibleTabPage::GetPageText()
161 ::rtl::OUString sText;
162 if ( m_pTabControl )
163 sText = OutputDevice::GetNonMnemonicString( m_pTabControl->GetPageText( m_nPageId ) );
165 return sText;
168 // -----------------------------------------------------------------------------
170 void VCLXAccessibleTabPage::Update( bool bNew )
172 if ( m_pTabControl )
174 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
175 if ( pTabPage )
177 Reference< XAccessible > xChild( pTabPage->GetAccessible( bNew ) );
178 if ( xChild.is() )
180 Any aOldValue, aNewValue;
181 if ( bNew )
182 aNewValue <<= xChild;
183 else
184 aOldValue <<= xChild;
185 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
191 // -----------------------------------------------------------------------------
193 void VCLXAccessibleTabPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
195 rStateSet.AddState( AccessibleStateType::ENABLED );
196 rStateSet.AddState( AccessibleStateType::SENSITIVE );
198 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
200 if ( IsFocused() )
201 rStateSet.AddState( AccessibleStateType::FOCUSED );
203 rStateSet.AddState( AccessibleStateType::VISIBLE );
205 rStateSet.AddState( AccessibleStateType::SHOWING );
207 rStateSet.AddState( AccessibleStateType::SELECTABLE );
209 if ( IsSelected() )
210 rStateSet.AddState( AccessibleStateType::SELECTED );
213 // -----------------------------------------------------------------------------
214 // OCommonAccessibleComponent
215 // -----------------------------------------------------------------------------
217 awt::Rectangle VCLXAccessibleTabPage::implGetBounds() throw (RuntimeException)
219 awt::Rectangle aBounds( 0, 0, 0, 0 );
221 if ( m_pTabControl )
222 aBounds = AWTRectangle( m_pTabControl->GetTabBounds( m_nPageId ) );
224 return aBounds;
227 // -----------------------------------------------------------------------------
228 // OCommonAccessibleText
229 // -----------------------------------------------------------------------------
231 ::rtl::OUString VCLXAccessibleTabPage::implGetText()
233 return GetPageText();
236 // -----------------------------------------------------------------------------
238 lang::Locale VCLXAccessibleTabPage::implGetLocale()
240 return Application::GetSettings().GetLocale();
243 // -----------------------------------------------------------------------------
245 void VCLXAccessibleTabPage::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
247 nStartIndex = 0;
248 nEndIndex = 0;
251 // -----------------------------------------------------------------------------
252 // XInterface
253 // -----------------------------------------------------------------------------
255 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleTabPage, AccessibleTextHelper_BASE, VCLXAccessibleTabPage_BASE )
257 // -----------------------------------------------------------------------------
258 // XTypeProvider
259 // -----------------------------------------------------------------------------
261 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleTabPage, AccessibleTextHelper_BASE, VCLXAccessibleTabPage_BASE )
263 // -----------------------------------------------------------------------------
264 // XComponent
265 // -----------------------------------------------------------------------------
267 void VCLXAccessibleTabPage::disposing()
269 AccessibleTextHelper_BASE::disposing();
271 m_pTabControl = NULL;
272 m_sPageText = ::rtl::OUString();
275 // -----------------------------------------------------------------------------
276 // XServiceInfo
277 // -----------------------------------------------------------------------------
279 ::rtl::OUString VCLXAccessibleTabPage::getImplementationName() throw (RuntimeException)
281 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleTabPage" );
284 // -----------------------------------------------------------------------------
286 sal_Bool VCLXAccessibleTabPage::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
288 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
289 const ::rtl::OUString* pNames = aNames.getConstArray();
290 const ::rtl::OUString* pEnd = pNames + aNames.getLength();
291 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
294 return pNames != pEnd;
297 // -----------------------------------------------------------------------------
299 Sequence< ::rtl::OUString > VCLXAccessibleTabPage::getSupportedServiceNames() throw (RuntimeException)
301 Sequence< ::rtl::OUString > aNames(1);
302 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabPage" );
303 return aNames;
306 // -----------------------------------------------------------------------------
307 // XAccessible
308 // -----------------------------------------------------------------------------
310 Reference< XAccessibleContext > VCLXAccessibleTabPage::getAccessibleContext( ) throw (RuntimeException)
312 OExternalLockGuard aGuard( this );
314 return this;
317 // -----------------------------------------------------------------------------
318 // XAccessibleContext
319 // -----------------------------------------------------------------------------
321 sal_Int32 VCLXAccessibleTabPage::getAccessibleChildCount() throw (RuntimeException)
323 OExternalLockGuard aGuard( this );
325 sal_Int32 nCount = 0;
326 if ( m_pTabControl )
328 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
329 if ( pTabPage && pTabPage->IsVisible() )
330 nCount = 1;
333 return nCount;
336 // -----------------------------------------------------------------------------
338 Reference< XAccessible > VCLXAccessibleTabPage::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
340 OExternalLockGuard aGuard( this );
342 if ( i < 0 || i >= getAccessibleChildCount() )
343 throw IndexOutOfBoundsException();
345 Reference< XAccessible > xChild;
346 if ( m_pTabControl )
348 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
349 if ( pTabPage && pTabPage->IsVisible() )
350 xChild = pTabPage->GetAccessible();
353 return xChild;
356 // -----------------------------------------------------------------------------
358 Reference< XAccessible > VCLXAccessibleTabPage::getAccessibleParent( ) throw (RuntimeException)
360 OExternalLockGuard aGuard( this );
362 Reference< XAccessible > xParent;
363 if ( m_pTabControl )
364 xParent = m_pTabControl->GetAccessible();
366 return xParent;
369 // -----------------------------------------------------------------------------
371 sal_Int32 VCLXAccessibleTabPage::getAccessibleIndexInParent( ) throw (RuntimeException)
373 OExternalLockGuard aGuard( this );
375 sal_Int32 nIndexInParent = -1;
376 if ( m_pTabControl )
377 nIndexInParent = m_pTabControl->GetPagePos( m_nPageId );
379 return nIndexInParent;
382 // -----------------------------------------------------------------------------
384 sal_Int16 VCLXAccessibleTabPage::getAccessibleRole( ) throw (RuntimeException)
386 OExternalLockGuard aGuard( this );
388 return AccessibleRole::PAGE_TAB;
391 // -----------------------------------------------------------------------------
393 ::rtl::OUString VCLXAccessibleTabPage::getAccessibleDescription( ) throw (RuntimeException)
395 OExternalLockGuard aGuard( this );
397 ::rtl::OUString sDescription;
398 if ( m_pTabControl )
399 sDescription = m_pTabControl->GetHelpText( m_nPageId );
401 return sDescription;
404 // -----------------------------------------------------------------------------
406 ::rtl::OUString VCLXAccessibleTabPage::getAccessibleName( ) throw (RuntimeException)
408 OExternalLockGuard aGuard( this );
410 return GetPageText();
413 // -----------------------------------------------------------------------------
415 Reference< XAccessibleRelationSet > VCLXAccessibleTabPage::getAccessibleRelationSet( ) throw (RuntimeException)
417 OExternalLockGuard aGuard( this );
419 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
420 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
421 return xSet;
424 // -----------------------------------------------------------------------------
426 Reference< XAccessibleStateSet > VCLXAccessibleTabPage::getAccessibleStateSet( ) throw (RuntimeException)
428 OExternalLockGuard aGuard( this );
430 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
431 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
433 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
435 FillAccessibleStateSet( *pStateSetHelper );
437 else
439 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
442 return xSet;
445 // -----------------------------------------------------------------------------
447 Locale VCLXAccessibleTabPage::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
449 OExternalLockGuard aGuard( this );
451 return Application::GetSettings().GetLocale();
454 // -----------------------------------------------------------------------------
455 // XAccessibleComponent
456 // -----------------------------------------------------------------------------
458 Reference< XAccessible > VCLXAccessibleTabPage::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
460 OExternalLockGuard aGuard( this );
462 Reference< XAccessible > xChild;
463 for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
465 Reference< XAccessible > xAcc = getAccessibleChild( i );
466 if ( xAcc.is() )
468 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
469 if ( xComp.is() )
471 Rectangle aRect = VCLRectangle( xComp->getBounds() );
472 Point aPos = VCLPoint( rPoint );
473 if ( aRect.IsInside( aPos ) )
475 xChild = xAcc;
476 break;
482 return xChild;
485 // -----------------------------------------------------------------------------
487 void VCLXAccessibleTabPage::grabFocus( ) throw (RuntimeException)
489 OExternalLockGuard aGuard( this );
491 if ( m_pTabControl )
493 m_pTabControl->SelectTabPage( m_nPageId );
494 m_pTabControl->GrabFocus();
498 // -----------------------------------------------------------------------------
500 sal_Int32 VCLXAccessibleTabPage::getForeground( ) throw (RuntimeException)
502 OExternalLockGuard aGuard( this );
504 sal_Int32 nColor = 0;
505 Reference< XAccessible > xParent = getAccessibleParent();
506 if ( xParent.is() )
508 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
509 if ( xParentComp.is() )
510 nColor = xParentComp->getForeground();
513 return nColor;
516 // -----------------------------------------------------------------------------
518 sal_Int32 VCLXAccessibleTabPage::getBackground( ) throw (RuntimeException)
520 OExternalLockGuard aGuard( this );
522 sal_Int32 nColor = 0;
523 Reference< XAccessible > xParent = getAccessibleParent();
524 if ( xParent.is() )
526 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
527 if ( xParentComp.is() )
528 nColor = xParentComp->getBackground();
531 return nColor;
534 // -----------------------------------------------------------------------------
535 // XAccessibleExtendedComponent
536 // -----------------------------------------------------------------------------
538 Reference< awt::XFont > VCLXAccessibleTabPage::getFont( ) throw (RuntimeException)
540 OExternalLockGuard aGuard( this );
542 Reference< awt::XFont > xFont;
543 Reference< XAccessible > xParent = getAccessibleParent();
544 if ( xParent.is() )
546 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
547 if ( xParentComp.is() )
548 xFont = xParentComp->getFont();
551 return xFont;
554 // -----------------------------------------------------------------------------
556 ::rtl::OUString VCLXAccessibleTabPage::getTitledBorderText( ) throw (RuntimeException)
558 OExternalLockGuard aGuard( this );
560 return ::rtl::OUString();
563 // -----------------------------------------------------------------------------
565 ::rtl::OUString VCLXAccessibleTabPage::getToolTipText( ) throw (RuntimeException)
567 OExternalLockGuard aGuard( this );
569 return ::rtl::OUString();
572 // -----------------------------------------------------------------------------
573 // XAccessibleText
574 // -----------------------------------------------------------------------------
576 sal_Int32 VCLXAccessibleTabPage::getCaretPosition() throw (RuntimeException)
578 OExternalLockGuard aGuard( this );
580 return -1;
583 // -----------------------------------------------------------------------------
585 sal_Bool VCLXAccessibleTabPage::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
587 OExternalLockGuard aGuard( this );
589 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
590 throw IndexOutOfBoundsException();
592 return sal_False;
595 // -----------------------------------------------------------------------------
597 Sequence< PropertyValue > VCLXAccessibleTabPage::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException)
599 OExternalLockGuard aGuard( this );
601 Sequence< PropertyValue > aValues;
602 ::rtl::OUString sText( implGetText() );
604 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
605 throw IndexOutOfBoundsException();
607 if ( m_pTabControl )
609 Font aFont = m_pTabControl->GetFont();
610 sal_Int32 nBackColor = getBackground();
611 sal_Int32 nColor = getForeground();
612 ::std::auto_ptr< CharacterAttributesHelper > pHelper( new CharacterAttributesHelper( aFont, nBackColor, nColor ) );
613 aValues = pHelper->GetCharacterAttributes( aRequestedAttributes );
616 return aValues;
619 // -----------------------------------------------------------------------------
621 awt::Rectangle VCLXAccessibleTabPage::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
623 OExternalLockGuard aGuard( this );
625 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
626 throw IndexOutOfBoundsException();
628 awt::Rectangle aBounds( 0, 0, 0, 0 );
629 if ( m_pTabControl )
631 Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
632 Rectangle aCharRect = m_pTabControl->GetCharacterBounds( m_nPageId, nIndex );
633 aCharRect.Move( -aPageRect.Left(), -aPageRect.Top() );
634 aBounds = AWTRectangle( aCharRect );
637 return aBounds;
640 // -----------------------------------------------------------------------------
642 sal_Int32 VCLXAccessibleTabPage::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
644 OExternalLockGuard aGuard( this );
646 sal_Int32 nIndex = -1;
647 if ( m_pTabControl )
649 sal_uInt16 nPageId = 0;
650 Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
651 Point aPnt( VCLPoint( aPoint ) );
652 aPnt += aPageRect.TopLeft();
653 sal_Int32 nI = m_pTabControl->GetIndexForPoint( aPnt, nPageId );
654 if ( nI != -1 && m_nPageId == nPageId )
655 nIndex = nI;
658 return nIndex;
661 // -----------------------------------------------------------------------------
663 sal_Bool VCLXAccessibleTabPage::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
665 OExternalLockGuard aGuard( this );
667 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
668 throw IndexOutOfBoundsException();
670 return sal_False;
673 // -----------------------------------------------------------------------------
675 sal_Bool VCLXAccessibleTabPage::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
677 OExternalLockGuard aGuard( this );
679 sal_Bool bReturn = sal_False;
681 if ( m_pTabControl )
683 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pTabControl->GetClipboard();
684 if ( xClipboard.is() )
686 ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
688 ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
689 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
690 xClipboard->setContents( pDataObj, NULL );
692 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
693 if( xFlushableClipboard.is() )
694 xFlushableClipboard->flushClipboard();
696 Application::AcquireSolarMutex( nRef );
698 bReturn = sal_True;
702 return bReturn;
705 // -----------------------------------------------------------------------------