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: vclxaccessibletabpage.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/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>
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
)
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
)
97 // -----------------------------------------------------------------------------
99 bool VCLXAccessibleTabPage::IsSelected()
101 bool bSelected
= false;
103 if ( m_pTabControl
&& m_pTabControl
->GetCurPageId() == m_nPageId
)
109 // -----------------------------------------------------------------------------
111 void VCLXAccessibleTabPage::SetFocused( bool bFocused
)
113 if ( m_bFocused
!= bFocused
)
115 Any aOldValue
, aNewValue
;
117 aOldValue
<<= AccessibleStateType::FOCUSED
;
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
;
133 aOldValue
<<= AccessibleStateType::SELECTED
;
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
;
163 sText
= OutputDevice::GetNonMnemonicString( m_pTabControl
->GetPageText( m_nPageId
) );
168 // -----------------------------------------------------------------------------
170 void VCLXAccessibleTabPage::Update( bool bNew
)
174 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
177 Reference
< XAccessible
> xChild( pTabPage
->GetAccessible( bNew
) );
180 Any aOldValue
, aNewValue
;
182 aNewValue
<<= xChild
;
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
);
201 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
203 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
205 rStateSet
.AddState( AccessibleStateType::SHOWING
);
207 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
210 rStateSet
.AddState( AccessibleStateType::SELECTED
);
213 // -----------------------------------------------------------------------------
214 // OCommonAccessibleComponent
215 // -----------------------------------------------------------------------------
217 awt::Rectangle
VCLXAccessibleTabPage::implGetBounds() throw (RuntimeException
)
219 awt::Rectangle
aBounds( 0, 0, 0, 0 );
222 aBounds
= AWTRectangle( m_pTabControl
->GetTabBounds( m_nPageId
) );
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
)
251 // -----------------------------------------------------------------------------
253 // -----------------------------------------------------------------------------
255 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleTabPage
, AccessibleTextHelper_BASE
, VCLXAccessibleTabPage_BASE
)
257 // -----------------------------------------------------------------------------
259 // -----------------------------------------------------------------------------
261 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleTabPage
, AccessibleTextHelper_BASE
, VCLXAccessibleTabPage_BASE
)
263 // -----------------------------------------------------------------------------
265 // -----------------------------------------------------------------------------
267 void VCLXAccessibleTabPage::disposing()
269 AccessibleTextHelper_BASE::disposing();
271 m_pTabControl
= NULL
;
272 m_sPageText
= ::rtl::OUString();
275 // -----------------------------------------------------------------------------
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" );
306 // -----------------------------------------------------------------------------
308 // -----------------------------------------------------------------------------
310 Reference
< XAccessibleContext
> VCLXAccessibleTabPage::getAccessibleContext( ) throw (RuntimeException
)
312 OExternalLockGuard
aGuard( this );
317 // -----------------------------------------------------------------------------
318 // XAccessibleContext
319 // -----------------------------------------------------------------------------
321 sal_Int32
VCLXAccessibleTabPage::getAccessibleChildCount() throw (RuntimeException
)
323 OExternalLockGuard
aGuard( this );
325 sal_Int32 nCount
= 0;
328 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
329 if ( pTabPage
&& pTabPage
->IsVisible() )
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
;
348 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
349 if ( pTabPage
&& pTabPage
->IsVisible() )
350 xChild
= pTabPage
->GetAccessible();
356 // -----------------------------------------------------------------------------
358 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleParent( ) throw (RuntimeException
)
360 OExternalLockGuard
aGuard( this );
362 Reference
< XAccessible
> xParent
;
364 xParent
= m_pTabControl
->GetAccessible();
369 // -----------------------------------------------------------------------------
371 sal_Int32
VCLXAccessibleTabPage::getAccessibleIndexInParent( ) throw (RuntimeException
)
373 OExternalLockGuard
aGuard( this );
375 sal_Int32 nIndexInParent
= -1;
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
;
399 sDescription
= m_pTabControl
->GetHelpText( m_nPageId
);
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
;
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
);
439 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
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
);
468 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
471 Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
472 Point aPos
= VCLPoint( rPoint
);
473 if ( aRect
.IsInside( aPos
) )
485 // -----------------------------------------------------------------------------
487 void VCLXAccessibleTabPage::grabFocus( ) throw (RuntimeException
)
489 OExternalLockGuard
aGuard( this );
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();
508 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
509 if ( xParentComp
.is() )
510 nColor
= xParentComp
->getForeground();
516 // -----------------------------------------------------------------------------
518 sal_Int32
VCLXAccessibleTabPage::getBackground( ) throw (RuntimeException
)
520 OExternalLockGuard
aGuard( this );
522 sal_Int32 nColor
= 0;
523 Reference
< XAccessible
> xParent
= getAccessibleParent();
526 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
527 if ( xParentComp
.is() )
528 nColor
= xParentComp
->getBackground();
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();
546 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
547 if ( xParentComp
.is() )
548 xFont
= xParentComp
->getFont();
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 // -----------------------------------------------------------------------------
574 // -----------------------------------------------------------------------------
576 sal_Int32
VCLXAccessibleTabPage::getCaretPosition() throw (RuntimeException
)
578 OExternalLockGuard
aGuard( this );
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();
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();
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
);
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 );
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
);
640 // -----------------------------------------------------------------------------
642 sal_Int32
VCLXAccessibleTabPage::getIndexAtPoint( const awt::Point
& aPoint
) throw (RuntimeException
)
644 OExternalLockGuard
aGuard( this );
646 sal_Int32 nIndex
= -1;
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
)
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();
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
;
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
);
705 // -----------------------------------------------------------------------------