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/vclxaccessibletabpage.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/tabctrl.hxx>
36 #include <vcl/tabpage.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 VCLXAccessibleTabPage
51 // -----------------------------------------------------------------------------
53 VCLXAccessibleTabPage::VCLXAccessibleTabPage( TabControl
* pTabControl
, sal_uInt16 nPageId
)
54 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() )
55 ,m_pTabControl( pTabControl
)
58 m_pExternalLock
= static_cast< VCLExternalSolarLock
* >( getExternalLock() );
59 m_bFocused
= IsFocused();
60 m_bSelected
= IsSelected();
61 m_sPageText
= GetPageText();
64 // -----------------------------------------------------------------------------
66 VCLXAccessibleTabPage::~VCLXAccessibleTabPage()
68 delete m_pExternalLock
;
69 m_pExternalLock
= NULL
;
72 // -----------------------------------------------------------------------------
74 bool VCLXAccessibleTabPage::IsFocused()
76 bool bFocused
= false;
78 if ( m_pTabControl
&& m_pTabControl
->HasFocus() && m_pTabControl
->GetCurPageId() == m_nPageId
)
84 // -----------------------------------------------------------------------------
86 bool VCLXAccessibleTabPage::IsSelected()
88 bool bSelected
= false;
90 if ( m_pTabControl
&& m_pTabControl
->GetCurPageId() == m_nPageId
)
96 // -----------------------------------------------------------------------------
98 void VCLXAccessibleTabPage::SetFocused( bool bFocused
)
100 if ( m_bFocused
!= bFocused
)
102 Any aOldValue
, aNewValue
;
104 aOldValue
<<= AccessibleStateType::FOCUSED
;
106 aNewValue
<<= AccessibleStateType::FOCUSED
;
107 m_bFocused
= bFocused
;
108 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
112 // -----------------------------------------------------------------------------
114 void VCLXAccessibleTabPage::SetSelected( bool bSelected
)
116 if ( m_bSelected
!= bSelected
)
118 Any aOldValue
, aNewValue
;
120 aOldValue
<<= AccessibleStateType::SELECTED
;
122 aNewValue
<<= AccessibleStateType::SELECTED
;
123 m_bSelected
= bSelected
;
124 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
128 // -----------------------------------------------------------------------------
130 void VCLXAccessibleTabPage::SetPageText( const OUString
& sPageText
)
132 Any aOldValue
, aNewValue
;
133 if ( OCommonAccessibleText::implInitTextChangedEvent( m_sPageText
, sPageText
, aOldValue
, aNewValue
) )
135 Any aOldName
, aNewName
;
136 aOldName
<<= m_sPageText
;
137 aNewName
<<= sPageText
;
138 m_sPageText
= sPageText
;
139 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldName
, aNewName
);
140 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED
, aOldValue
, aNewValue
);
144 // -----------------------------------------------------------------------------
146 OUString
VCLXAccessibleTabPage::GetPageText()
150 sText
= OutputDevice::GetNonMnemonicString( m_pTabControl
->GetPageText( m_nPageId
) );
155 // -----------------------------------------------------------------------------
157 void VCLXAccessibleTabPage::Update( bool bNew
)
161 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
164 Reference
< XAccessible
> xChild( pTabPage
->GetAccessible( bNew
) );
167 Any aOldValue
, aNewValue
;
169 aNewValue
<<= xChild
;
171 aOldValue
<<= xChild
;
172 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
178 // -----------------------------------------------------------------------------
180 void VCLXAccessibleTabPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
182 rStateSet
.AddState( AccessibleStateType::ENABLED
);
183 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
185 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
188 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
190 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
192 rStateSet
.AddState( AccessibleStateType::SHOWING
);
194 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
197 rStateSet
.AddState( AccessibleStateType::SELECTED
);
200 // -----------------------------------------------------------------------------
201 // OCommonAccessibleComponent
202 // -----------------------------------------------------------------------------
204 awt::Rectangle
VCLXAccessibleTabPage::implGetBounds() throw (RuntimeException
)
206 awt::Rectangle
aBounds( 0, 0, 0, 0 );
209 aBounds
= AWTRectangle( m_pTabControl
->GetTabBounds( m_nPageId
) );
214 // -----------------------------------------------------------------------------
215 // OCommonAccessibleText
216 // -----------------------------------------------------------------------------
218 OUString
VCLXAccessibleTabPage::implGetText()
220 return GetPageText();
223 // -----------------------------------------------------------------------------
225 lang::Locale
VCLXAccessibleTabPage::implGetLocale()
227 return Application::GetSettings().GetLanguageTag().getLocale();
230 // -----------------------------------------------------------------------------
232 void VCLXAccessibleTabPage::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
238 // -----------------------------------------------------------------------------
240 // -----------------------------------------------------------------------------
242 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleTabPage
, AccessibleTextHelper_BASE
, VCLXAccessibleTabPage_BASE
)
244 // -----------------------------------------------------------------------------
246 // -----------------------------------------------------------------------------
248 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleTabPage
, AccessibleTextHelper_BASE
, VCLXAccessibleTabPage_BASE
)
250 // -----------------------------------------------------------------------------
252 // -----------------------------------------------------------------------------
254 void VCLXAccessibleTabPage::disposing()
256 AccessibleTextHelper_BASE::disposing();
258 m_pTabControl
= NULL
;
259 m_sPageText
= OUString();
262 // -----------------------------------------------------------------------------
264 // -----------------------------------------------------------------------------
266 OUString
VCLXAccessibleTabPage::getImplementationName() throw (RuntimeException
)
268 return OUString( "com.sun.star.comp.toolkit.AccessibleTabPage" );
271 // -----------------------------------------------------------------------------
273 sal_Bool
VCLXAccessibleTabPage::supportsService( const OUString
& rServiceName
) throw (RuntimeException
)
275 return cppu::supportsService(this, rServiceName
);
278 // -----------------------------------------------------------------------------
280 Sequence
< OUString
> VCLXAccessibleTabPage::getSupportedServiceNames() throw (RuntimeException
)
282 Sequence
< OUString
> aNames(1);
283 aNames
[0] = "com.sun.star.awt.AccessibleTabPage";
287 // -----------------------------------------------------------------------------
289 // -----------------------------------------------------------------------------
291 Reference
< XAccessibleContext
> VCLXAccessibleTabPage::getAccessibleContext( ) throw (RuntimeException
)
293 OExternalLockGuard
aGuard( this );
298 // -----------------------------------------------------------------------------
299 // XAccessibleContext
300 // -----------------------------------------------------------------------------
302 sal_Int32
VCLXAccessibleTabPage::getAccessibleChildCount() throw (RuntimeException
)
304 OExternalLockGuard
aGuard( this );
306 sal_Int32 nCount
= 0;
309 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
310 if ( pTabPage
&& pTabPage
->IsVisible() )
317 // -----------------------------------------------------------------------------
319 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
321 OExternalLockGuard
aGuard( this );
323 if ( i
< 0 || i
>= getAccessibleChildCount() )
324 throw IndexOutOfBoundsException();
326 Reference
< XAccessible
> xChild
;
329 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
330 if ( pTabPage
&& pTabPage
->IsVisible() )
331 xChild
= pTabPage
->GetAccessible();
337 // -----------------------------------------------------------------------------
339 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleParent( ) throw (RuntimeException
)
341 OExternalLockGuard
aGuard( this );
343 Reference
< XAccessible
> xParent
;
345 xParent
= m_pTabControl
->GetAccessible();
350 // -----------------------------------------------------------------------------
352 sal_Int32
VCLXAccessibleTabPage::getAccessibleIndexInParent( ) throw (RuntimeException
)
354 OExternalLockGuard
aGuard( this );
356 sal_Int32 nIndexInParent
= -1;
358 nIndexInParent
= m_pTabControl
->GetPagePos( m_nPageId
);
360 return nIndexInParent
;
363 // -----------------------------------------------------------------------------
365 sal_Int16
VCLXAccessibleTabPage::getAccessibleRole( ) throw (RuntimeException
)
367 OExternalLockGuard
aGuard( this );
369 return AccessibleRole::PAGE_TAB
;
372 // -----------------------------------------------------------------------------
374 OUString
VCLXAccessibleTabPage::getAccessibleDescription( ) throw (RuntimeException
)
376 OExternalLockGuard
aGuard( this );
378 OUString sDescription
;
380 sDescription
= m_pTabControl
->GetHelpText( m_nPageId
);
385 // -----------------------------------------------------------------------------
387 OUString
VCLXAccessibleTabPage::getAccessibleName( ) throw (RuntimeException
)
389 OExternalLockGuard
aGuard( this );
391 return GetPageText();
394 // -----------------------------------------------------------------------------
396 Reference
< XAccessibleRelationSet
> VCLXAccessibleTabPage::getAccessibleRelationSet( ) throw (RuntimeException
)
398 OExternalLockGuard
aGuard( this );
400 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
401 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
405 // -----------------------------------------------------------------------------
407 Reference
< XAccessibleStateSet
> VCLXAccessibleTabPage::getAccessibleStateSet( ) throw (RuntimeException
)
409 OExternalLockGuard
aGuard( this );
411 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
412 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
414 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
416 FillAccessibleStateSet( *pStateSetHelper
);
420 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
426 // -----------------------------------------------------------------------------
428 Locale
VCLXAccessibleTabPage::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
430 OExternalLockGuard
aGuard( this );
432 return Application::GetSettings().GetLanguageTag().getLocale();
435 // -----------------------------------------------------------------------------
436 // XAccessibleComponent
437 // -----------------------------------------------------------------------------
439 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
441 OExternalLockGuard
aGuard( this );
443 Reference
< XAccessible
> xChild
;
444 for ( sal_uInt32 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
446 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
449 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
452 Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
453 Point aPos
= VCLPoint( rPoint
);
454 if ( aRect
.IsInside( aPos
) )
466 // -----------------------------------------------------------------------------
468 void VCLXAccessibleTabPage::grabFocus( ) throw (RuntimeException
)
470 OExternalLockGuard
aGuard( this );
474 m_pTabControl
->SelectTabPage( m_nPageId
);
475 m_pTabControl
->GrabFocus();
479 // -----------------------------------------------------------------------------
481 sal_Int32
VCLXAccessibleTabPage::getForeground( ) throw (RuntimeException
)
483 OExternalLockGuard
aGuard( this );
485 sal_Int32 nColor
= 0;
486 Reference
< XAccessible
> xParent
= getAccessibleParent();
489 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
490 if ( xParentComp
.is() )
491 nColor
= xParentComp
->getForeground();
497 // -----------------------------------------------------------------------------
499 sal_Int32
VCLXAccessibleTabPage::getBackground( ) throw (RuntimeException
)
501 OExternalLockGuard
aGuard( this );
503 sal_Int32 nColor
= 0;
504 Reference
< XAccessible
> xParent
= getAccessibleParent();
507 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
508 if ( xParentComp
.is() )
509 nColor
= xParentComp
->getBackground();
515 // -----------------------------------------------------------------------------
516 // XAccessibleExtendedComponent
517 // -----------------------------------------------------------------------------
519 Reference
< awt::XFont
> VCLXAccessibleTabPage::getFont( ) throw (RuntimeException
)
521 OExternalLockGuard
aGuard( this );
523 Reference
< awt::XFont
> xFont
;
524 Reference
< XAccessible
> xParent
= getAccessibleParent();
527 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
528 if ( xParentComp
.is() )
529 xFont
= xParentComp
->getFont();
535 // -----------------------------------------------------------------------------
537 OUString
VCLXAccessibleTabPage::getTitledBorderText( ) throw (RuntimeException
)
539 OExternalLockGuard
aGuard( this );
544 // -----------------------------------------------------------------------------
546 OUString
VCLXAccessibleTabPage::getToolTipText( ) throw (RuntimeException
)
548 OExternalLockGuard
aGuard( this );
553 // -----------------------------------------------------------------------------
555 // -----------------------------------------------------------------------------
557 sal_Int32
VCLXAccessibleTabPage::getCaretPosition() throw (RuntimeException
)
559 OExternalLockGuard
aGuard( this );
564 // -----------------------------------------------------------------------------
566 sal_Bool
VCLXAccessibleTabPage::setCaretPosition( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
568 OExternalLockGuard
aGuard( this );
570 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
571 throw IndexOutOfBoundsException();
576 // -----------------------------------------------------------------------------
578 Sequence
< PropertyValue
> VCLXAccessibleTabPage::getCharacterAttributes( sal_Int32 nIndex
, const Sequence
< OUString
>& aRequestedAttributes
) throw (IndexOutOfBoundsException
, RuntimeException
)
580 OExternalLockGuard
aGuard( this );
582 Sequence
< PropertyValue
> aValues
;
583 OUString
sText( implGetText() );
585 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
586 throw IndexOutOfBoundsException();
590 Font aFont
= m_pTabControl
->GetFont();
591 sal_Int32 nBackColor
= getBackground();
592 sal_Int32 nColor
= getForeground();
593 ::std::auto_ptr
< CharacterAttributesHelper
> pHelper( new CharacterAttributesHelper( aFont
, nBackColor
, nColor
) );
594 aValues
= pHelper
->GetCharacterAttributes( aRequestedAttributes
);
600 // -----------------------------------------------------------------------------
602 awt::Rectangle
VCLXAccessibleTabPage::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
604 OExternalLockGuard
aGuard( this );
606 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
607 throw IndexOutOfBoundsException();
609 awt::Rectangle
aBounds( 0, 0, 0, 0 );
612 Rectangle aPageRect
= m_pTabControl
->GetTabBounds( m_nPageId
);
613 Rectangle aCharRect
= m_pTabControl
->GetCharacterBounds( m_nPageId
, nIndex
);
614 aCharRect
.Move( -aPageRect
.Left(), -aPageRect
.Top() );
615 aBounds
= AWTRectangle( aCharRect
);
621 // -----------------------------------------------------------------------------
623 sal_Int32
VCLXAccessibleTabPage::getIndexAtPoint( const awt::Point
& aPoint
) throw (RuntimeException
)
625 OExternalLockGuard
aGuard( this );
627 sal_Int32 nIndex
= -1;
630 sal_uInt16 nPageId
= 0;
631 Rectangle aPageRect
= m_pTabControl
->GetTabBounds( m_nPageId
);
632 Point
aPnt( VCLPoint( aPoint
) );
633 aPnt
+= aPageRect
.TopLeft();
634 sal_Int32 nI
= m_pTabControl
->GetIndexForPoint( aPnt
, nPageId
);
635 if ( nI
!= -1 && m_nPageId
== nPageId
)
642 // -----------------------------------------------------------------------------
644 sal_Bool
VCLXAccessibleTabPage::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
646 OExternalLockGuard
aGuard( this );
648 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
649 throw IndexOutOfBoundsException();
654 // -----------------------------------------------------------------------------
656 sal_Bool
VCLXAccessibleTabPage::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
658 OExternalLockGuard
aGuard( this );
660 sal_Bool bReturn
= sal_False
;
664 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= m_pTabControl
->GetClipboard();
665 if ( xClipboard
.is() )
667 OUString
sText( getTextRange( nStartIndex
, nEndIndex
) );
669 ::vcl::unohelper::TextDataObject
* pDataObj
= new ::vcl::unohelper::TextDataObject( sText
);
670 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
671 xClipboard
->setContents( pDataObj
, NULL
);
673 Reference
< datatransfer::clipboard::XFlushableClipboard
> xFlushableClipboard( xClipboard
, uno::UNO_QUERY
);
674 if( xFlushableClipboard
.is() )
675 xFlushableClipboard
->flushClipboard();
677 Application::AcquireSolarMutex( nRef
);
686 // -----------------------------------------------------------------------------
688 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */