bump product version to 4.1.6.2
[LibreOffice.git] / accessibility / source / standard / vclxaccessibletabpage.cxx
blob67a4c876415cb30dd644ef47b6b3c8b8e7706171
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
38 #include <memory>
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 )
56 ,m_nPageId( nPageId )
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 )
79 bFocused = true;
81 return bFocused;
84 // -----------------------------------------------------------------------------
86 bool VCLXAccessibleTabPage::IsSelected()
88 bool bSelected = false;
90 if ( m_pTabControl && m_pTabControl->GetCurPageId() == m_nPageId )
91 bSelected = true;
93 return bSelected;
96 // -----------------------------------------------------------------------------
98 void VCLXAccessibleTabPage::SetFocused( bool bFocused )
100 if ( m_bFocused != bFocused )
102 Any aOldValue, aNewValue;
103 if ( m_bFocused )
104 aOldValue <<= AccessibleStateType::FOCUSED;
105 else
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;
119 if ( m_bSelected )
120 aOldValue <<= AccessibleStateType::SELECTED;
121 else
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()
148 OUString sText;
149 if ( m_pTabControl )
150 sText = OutputDevice::GetNonMnemonicString( m_pTabControl->GetPageText( m_nPageId ) );
152 return sText;
155 // -----------------------------------------------------------------------------
157 void VCLXAccessibleTabPage::Update( bool bNew )
159 if ( m_pTabControl )
161 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
162 if ( pTabPage )
164 Reference< XAccessible > xChild( pTabPage->GetAccessible( bNew ) );
165 if ( xChild.is() )
167 Any aOldValue, aNewValue;
168 if ( bNew )
169 aNewValue <<= xChild;
170 else
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 );
187 if ( IsFocused() )
188 rStateSet.AddState( AccessibleStateType::FOCUSED );
190 rStateSet.AddState( AccessibleStateType::VISIBLE );
192 rStateSet.AddState( AccessibleStateType::SHOWING );
194 rStateSet.AddState( AccessibleStateType::SELECTABLE );
196 if ( IsSelected() )
197 rStateSet.AddState( AccessibleStateType::SELECTED );
200 // -----------------------------------------------------------------------------
201 // OCommonAccessibleComponent
202 // -----------------------------------------------------------------------------
204 awt::Rectangle VCLXAccessibleTabPage::implGetBounds() throw (RuntimeException)
206 awt::Rectangle aBounds( 0, 0, 0, 0 );
208 if ( m_pTabControl )
209 aBounds = AWTRectangle( m_pTabControl->GetTabBounds( m_nPageId ) );
211 return aBounds;
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 )
234 nStartIndex = 0;
235 nEndIndex = 0;
238 // -----------------------------------------------------------------------------
239 // XInterface
240 // -----------------------------------------------------------------------------
242 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleTabPage, AccessibleTextHelper_BASE, VCLXAccessibleTabPage_BASE )
244 // -----------------------------------------------------------------------------
245 // XTypeProvider
246 // -----------------------------------------------------------------------------
248 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleTabPage, AccessibleTextHelper_BASE, VCLXAccessibleTabPage_BASE )
250 // -----------------------------------------------------------------------------
251 // XComponent
252 // -----------------------------------------------------------------------------
254 void VCLXAccessibleTabPage::disposing()
256 AccessibleTextHelper_BASE::disposing();
258 m_pTabControl = NULL;
259 m_sPageText = OUString();
262 // -----------------------------------------------------------------------------
263 // XServiceInfo
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";
284 return aNames;
287 // -----------------------------------------------------------------------------
288 // XAccessible
289 // -----------------------------------------------------------------------------
291 Reference< XAccessibleContext > VCLXAccessibleTabPage::getAccessibleContext( ) throw (RuntimeException)
293 OExternalLockGuard aGuard( this );
295 return this;
298 // -----------------------------------------------------------------------------
299 // XAccessibleContext
300 // -----------------------------------------------------------------------------
302 sal_Int32 VCLXAccessibleTabPage::getAccessibleChildCount() throw (RuntimeException)
304 OExternalLockGuard aGuard( this );
306 sal_Int32 nCount = 0;
307 if ( m_pTabControl )
309 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
310 if ( pTabPage && pTabPage->IsVisible() )
311 nCount = 1;
314 return nCount;
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;
327 if ( m_pTabControl )
329 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
330 if ( pTabPage && pTabPage->IsVisible() )
331 xChild = pTabPage->GetAccessible();
334 return xChild;
337 // -----------------------------------------------------------------------------
339 Reference< XAccessible > VCLXAccessibleTabPage::getAccessibleParent( ) throw (RuntimeException)
341 OExternalLockGuard aGuard( this );
343 Reference< XAccessible > xParent;
344 if ( m_pTabControl )
345 xParent = m_pTabControl->GetAccessible();
347 return xParent;
350 // -----------------------------------------------------------------------------
352 sal_Int32 VCLXAccessibleTabPage::getAccessibleIndexInParent( ) throw (RuntimeException)
354 OExternalLockGuard aGuard( this );
356 sal_Int32 nIndexInParent = -1;
357 if ( m_pTabControl )
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;
379 if ( m_pTabControl )
380 sDescription = m_pTabControl->GetHelpText( m_nPageId );
382 return sDescription;
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;
402 return xSet;
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 );
418 else
420 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
423 return xSet;
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 );
447 if ( xAcc.is() )
449 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
450 if ( xComp.is() )
452 Rectangle aRect = VCLRectangle( xComp->getBounds() );
453 Point aPos = VCLPoint( rPoint );
454 if ( aRect.IsInside( aPos ) )
456 xChild = xAcc;
457 break;
463 return xChild;
466 // -----------------------------------------------------------------------------
468 void VCLXAccessibleTabPage::grabFocus( ) throw (RuntimeException)
470 OExternalLockGuard aGuard( this );
472 if ( m_pTabControl )
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();
487 if ( xParent.is() )
489 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
490 if ( xParentComp.is() )
491 nColor = xParentComp->getForeground();
494 return nColor;
497 // -----------------------------------------------------------------------------
499 sal_Int32 VCLXAccessibleTabPage::getBackground( ) throw (RuntimeException)
501 OExternalLockGuard aGuard( this );
503 sal_Int32 nColor = 0;
504 Reference< XAccessible > xParent = getAccessibleParent();
505 if ( xParent.is() )
507 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
508 if ( xParentComp.is() )
509 nColor = xParentComp->getBackground();
512 return nColor;
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();
525 if ( xParent.is() )
527 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
528 if ( xParentComp.is() )
529 xFont = xParentComp->getFont();
532 return xFont;
535 // -----------------------------------------------------------------------------
537 OUString VCLXAccessibleTabPage::getTitledBorderText( ) throw (RuntimeException)
539 OExternalLockGuard aGuard( this );
541 return OUString();
544 // -----------------------------------------------------------------------------
546 OUString VCLXAccessibleTabPage::getToolTipText( ) throw (RuntimeException)
548 OExternalLockGuard aGuard( this );
550 return OUString();
553 // -----------------------------------------------------------------------------
554 // XAccessibleText
555 // -----------------------------------------------------------------------------
557 sal_Int32 VCLXAccessibleTabPage::getCaretPosition() throw (RuntimeException)
559 OExternalLockGuard aGuard( this );
561 return -1;
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();
573 return sal_False;
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();
588 if ( m_pTabControl )
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 );
597 return aValues;
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 );
610 if ( m_pTabControl )
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 );
618 return aBounds;
621 // -----------------------------------------------------------------------------
623 sal_Int32 VCLXAccessibleTabPage::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
625 OExternalLockGuard aGuard( this );
627 sal_Int32 nIndex = -1;
628 if ( m_pTabControl )
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 )
636 nIndex = nI;
639 return nIndex;
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();
651 return sal_False;
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;
662 if ( m_pTabControl )
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 );
679 bReturn = sal_True;
683 return bReturn;
686 // -----------------------------------------------------------------------------
688 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */