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 <standard/vclxaccessibletabpage.hxx>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 #include <comphelper/accessiblecontexthelper.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/accessiblerelationsethelper.hxx>
31 #include <vcl/accessibility/characterattributeshelper.hxx>
32 #include <vcl/mnemonic.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/unohelp.hxx>
35 #include <vcl/unohelp2.hxx>
36 #include <vcl/tabctrl.hxx>
37 #include <vcl/tabpage.hxx>
38 #include <vcl/settings.hxx>
39 #include <i18nlangtag/languagetag.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
;
51 VCLXAccessibleTabPage::VCLXAccessibleTabPage( TabControl
* pTabControl
, sal_uInt16 nPageId
)
52 :m_pTabControl( pTabControl
)
55 m_bFocused
= IsFocused();
56 m_bSelected
= IsSelected();
57 m_sPageText
= GetPageText();
61 VCLXAccessibleTabPage::~VCLXAccessibleTabPage()
66 bool VCLXAccessibleTabPage::IsFocused() const
68 bool bFocused
= false;
70 if ( m_pTabControl
&& m_pTabControl
->HasFocus() && m_pTabControl
->GetCurPageId() == m_nPageId
)
77 bool VCLXAccessibleTabPage::IsSelected() const
79 bool bSelected
= false;
81 if ( m_pTabControl
&& m_pTabControl
->GetCurPageId() == m_nPageId
)
88 void VCLXAccessibleTabPage::SetFocused( bool bFocused
)
90 if ( m_bFocused
!= bFocused
)
92 Any aOldValue
, aNewValue
;
94 aOldValue
<<= AccessibleStateType::FOCUSED
;
96 aNewValue
<<= AccessibleStateType::FOCUSED
;
97 m_bFocused
= bFocused
;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
103 void VCLXAccessibleTabPage::SetSelected( bool bSelected
)
105 if ( m_bSelected
!= bSelected
)
107 Any aOldValue
, aNewValue
;
109 aOldValue
<<= AccessibleStateType::SELECTED
;
111 aNewValue
<<= AccessibleStateType::SELECTED
;
112 m_bSelected
= bSelected
;
113 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
118 void VCLXAccessibleTabPage::SetPageText( const OUString
& sPageText
)
120 Any aOldValue
, aNewValue
;
121 if ( OCommonAccessibleText::implInitTextChangedEvent( m_sPageText
, sPageText
, aOldValue
, aNewValue
) )
123 Any aOldName
, aNewName
;
124 aOldName
<<= m_sPageText
;
125 aNewName
<<= sPageText
;
126 m_sPageText
= sPageText
;
127 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldName
, aNewName
);
128 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED
, aOldValue
, aNewValue
);
133 OUString
VCLXAccessibleTabPage::GetPageText()
137 sText
= removeMnemonicFromString( m_pTabControl
->GetPageText( m_nPageId
) );
143 void VCLXAccessibleTabPage::Update( bool bNew
)
145 if ( !m_pTabControl
)
148 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
152 Reference
< XAccessible
> xChild( pTabPage
->GetAccessible( bNew
) );
155 Any aOldValue
, aNewValue
;
157 aNewValue
<<= xChild
;
159 aOldValue
<<= xChild
;
160 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
165 void VCLXAccessibleTabPage::FillAccessibleStateSet( sal_Int64
& rStateSet
)
167 rStateSet
|= AccessibleStateType::ENABLED
;
168 rStateSet
|= AccessibleStateType::SENSITIVE
;
170 rStateSet
|= AccessibleStateType::FOCUSABLE
;
173 rStateSet
|= AccessibleStateType::FOCUSED
;
175 rStateSet
|= AccessibleStateType::VISIBLE
;
177 rStateSet
|= AccessibleStateType::SHOWING
;
179 rStateSet
|= AccessibleStateType::SELECTABLE
;
182 rStateSet
|= AccessibleStateType::SELECTED
;
186 // OCommonAccessibleComponent
189 awt::Rectangle
VCLXAccessibleTabPage::implGetBounds()
191 awt::Rectangle
aBounds( 0, 0, 0, 0 );
194 aBounds
= vcl::unohelper::ConvertToAWTRect(m_pTabControl
->GetTabBounds(m_nPageId
));
200 // OCommonAccessibleText
203 OUString
VCLXAccessibleTabPage::implGetText()
205 return GetPageText();
209 lang::Locale
VCLXAccessibleTabPage::implGetLocale()
211 return Application::GetSettings().GetLanguageTag().getLocale();
215 void VCLXAccessibleTabPage::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
225 void VCLXAccessibleTabPage::disposing()
227 comphelper::OAccessibleTextHelper::disposing();
229 m_pTabControl
= nullptr;
237 OUString
VCLXAccessibleTabPage::getImplementationName()
239 return u
"com.sun.star.comp.toolkit.AccessibleTabPage"_ustr
;
243 sal_Bool
VCLXAccessibleTabPage::supportsService( const OUString
& rServiceName
)
245 return cppu::supportsService(this, rServiceName
);
249 Sequence
< OUString
> VCLXAccessibleTabPage::getSupportedServiceNames()
251 return { u
"com.sun.star.awt.AccessibleTabPage"_ustr
};
258 Reference
< XAccessibleContext
> VCLXAccessibleTabPage::getAccessibleContext( )
260 OExternalLockGuard
aGuard( this );
266 // XAccessibleContext
269 sal_Int64
VCLXAccessibleTabPage::getAccessibleChildCount()
271 OExternalLockGuard
aGuard( this );
272 return implGetAccessibleChildCount();
275 sal_Int64
VCLXAccessibleTabPage::implGetAccessibleChildCount()
277 sal_Int64 nCount
= 0;
280 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
281 if ( pTabPage
&& pTabPage
->IsVisible() )
289 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleChild( sal_Int64 i
)
291 OExternalLockGuard
aGuard( this );
293 if ( i
< 0 || i
>= implGetAccessibleChildCount() )
294 throw IndexOutOfBoundsException();
296 Reference
< XAccessible
> xChild
;
299 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( m_nPageId
);
300 if ( pTabPage
&& pTabPage
->IsVisible() )
301 xChild
= pTabPage
->GetAccessible();
308 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleParent( )
310 OExternalLockGuard
aGuard( this );
312 Reference
< XAccessible
> xParent
;
314 xParent
= m_pTabControl
->GetAccessible();
320 sal_Int64
VCLXAccessibleTabPage::getAccessibleIndexInParent( )
322 OExternalLockGuard
aGuard( this );
324 sal_Int64 nIndexInParent
= -1;
326 nIndexInParent
= m_pTabControl
->GetPagePos( m_nPageId
);
328 return nIndexInParent
;
331 sal_Int16
VCLXAccessibleTabPage::getAccessibleRole()
333 OExternalLockGuard
aGuard( this );
335 return AccessibleRole::PAGE_TAB
;
338 OUString
VCLXAccessibleTabPage::getAccessibleDescription()
340 OExternalLockGuard
aGuard( this );
342 OUString sDescription
;
344 sDescription
= m_pTabControl
->GetAccessibleDescription( m_nPageId
);
349 OUString
VCLXAccessibleTabPage::getAccessibleName()
351 OExternalLockGuard
aGuard( this );
355 sName
= m_pTabControl
->GetAccessibleName( m_nPageId
);
360 Reference
< XAccessibleRelationSet
> VCLXAccessibleTabPage::getAccessibleRelationSet( )
362 OExternalLockGuard
aGuard( this );
364 return new utl::AccessibleRelationSetHelper
;
368 sal_Int64
VCLXAccessibleTabPage::getAccessibleStateSet( )
370 OExternalLockGuard
aGuard( this );
372 sal_Int64 nStateSet
= 0;
374 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
376 FillAccessibleStateSet( nStateSet
);
380 nStateSet
|= AccessibleStateType::DEFUNC
;
387 Locale
VCLXAccessibleTabPage::getLocale( )
389 OExternalLockGuard
aGuard( this );
391 return Application::GetSettings().GetLanguageTag().getLocale();
395 // XAccessibleComponent
398 Reference
< XAccessible
> VCLXAccessibleTabPage::getAccessibleAtPoint( const awt::Point
& rPoint
)
400 OExternalLockGuard
aGuard( this );
402 for ( sal_Int64 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
404 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
407 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
410 tools::Rectangle aRect
= vcl::unohelper::ConvertToVCLRect(xComp
->getBounds());
411 Point aPos
= vcl::unohelper::ConvertToVCLPoint(rPoint
);
412 if ( aRect
.Contains( aPos
) )
424 void VCLXAccessibleTabPage::grabFocus( )
426 OExternalLockGuard
aGuard( this );
430 m_pTabControl
->SelectTabPage( m_nPageId
);
431 m_pTabControl
->GrabFocus();
436 sal_Int32
VCLXAccessibleTabPage::getForeground( )
438 OExternalLockGuard
aGuard( this );
440 sal_Int32 nColor
= 0;
441 Reference
< XAccessible
> xParent
= getAccessibleParent();
444 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
445 if ( xParentComp
.is() )
446 nColor
= xParentComp
->getForeground();
453 sal_Int32
VCLXAccessibleTabPage::getBackground( )
455 OExternalLockGuard
aGuard( this );
457 sal_Int32 nColor
= 0;
458 Reference
< XAccessible
> xParent
= getAccessibleParent();
461 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
462 if ( xParentComp
.is() )
463 nColor
= xParentComp
->getBackground();
470 // XAccessibleExtendedComponent
472 OUString
VCLXAccessibleTabPage::getTitledBorderText( )
474 OExternalLockGuard
aGuard( this );
480 OUString
VCLXAccessibleTabPage::getToolTipText( )
482 OExternalLockGuard
aGuard( this );
490 OUString
VCLXAccessibleTabPage::getText()
492 OExternalLockGuard
aGuard( this );
494 return GetPageText();
497 OUString
VCLXAccessibleTabPage::getTextRange(sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
499 OExternalLockGuard
aGuard( this );
501 return OCommonAccessibleText::implGetTextRange(GetPageText(), nStartIndex
, nEndIndex
);
504 sal_Unicode
VCLXAccessibleTabPage::getCharacter( sal_Int32 nIndex
)
506 OExternalLockGuard
aGuard( this );
508 return OCommonAccessibleText::implGetCharacter( GetPageText(), nIndex
);
511 sal_Int32
VCLXAccessibleTabPage::getCharacterCount()
513 return GetPageText().getLength();
516 sal_Int32
VCLXAccessibleTabPage::getCaretPosition()
518 OExternalLockGuard
aGuard( this );
524 sal_Bool
VCLXAccessibleTabPage::setCaretPosition( sal_Int32 nIndex
)
526 OExternalLockGuard
aGuard( this );
528 if ( !implIsValidRange( nIndex
, nIndex
, GetPageText().getLength() ) )
529 throw IndexOutOfBoundsException();
535 Sequence
< PropertyValue
> VCLXAccessibleTabPage::getCharacterAttributes( sal_Int32 nIndex
, const Sequence
< OUString
>& aRequestedAttributes
)
537 OExternalLockGuard
aGuard( this );
539 Sequence
< PropertyValue
> aValues
;
540 OUString
sText( GetPageText() );
542 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
543 throw IndexOutOfBoundsException();
547 vcl::Font aFont
= m_pTabControl
->GetFont();
548 sal_Int32 nBackColor
= getBackground();
549 sal_Int32 nColor
= getForeground();
550 aValues
= CharacterAttributesHelper( aFont
, nBackColor
, nColor
)
551 .GetCharacterAttributes( aRequestedAttributes
);
558 awt::Rectangle
VCLXAccessibleTabPage::getCharacterBounds( sal_Int32 nIndex
)
560 OExternalLockGuard
aGuard( this );
562 if ( !implIsValidIndex( nIndex
, GetPageText().getLength() ) )
563 throw IndexOutOfBoundsException();
565 awt::Rectangle
aBounds( 0, 0, 0, 0 );
568 tools::Rectangle aPageRect
= m_pTabControl
->GetTabBounds( m_nPageId
);
569 tools::Rectangle aCharRect
; // m_pTabControl->GetCharacterBounds( m_nPageId, nIndex );
570 aCharRect
.Move( -aPageRect
.Left(), -aPageRect
.Top() );
571 aBounds
= vcl::unohelper::ConvertToAWTRect(aCharRect
);
578 sal_Int32
VCLXAccessibleTabPage::getIndexAtPoint( const awt::Point
& /*aPoint*/ )
580 OExternalLockGuard
aGuard( this );
582 sal_Int32 nIndex
= -1;
583 // if ( m_pTabControl )
585 // sal_uInt16 nPageId = 0;
586 // tools::Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
587 // Point aPnt( vcl::unohelper::ConvertToVCLPoint( aPoint ) );
588 // aPnt += aPageRect.TopLeft();
589 // sal_Int32 nI = m_pTabControl->GetIndexForPoint( aPnt, nPageId );
590 // if ( nI != -1 && m_nPageId == nPageId )
598 sal_Bool
VCLXAccessibleTabPage::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
600 OExternalLockGuard
aGuard( this );
602 if ( !implIsValidRange( nStartIndex
, nEndIndex
, GetPageText().getLength() ) )
603 throw IndexOutOfBoundsException();
609 sal_Bool
VCLXAccessibleTabPage::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
611 OExternalLockGuard
aGuard( this );
613 bool bReturn
= false;
617 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= m_pTabControl
->GetClipboard();
618 if ( xClipboard
.is() )
620 OUString
sText( implGetTextRange( GetPageText(), nStartIndex
, nEndIndex
) );
622 rtl::Reference
<vcl::unohelper::TextDataObject
> pDataObj
= new vcl::unohelper::TextDataObject( sText
);
624 SolarMutexReleaser aReleaser
;
625 xClipboard
->setContents( pDataObj
, nullptr );
627 Reference
< datatransfer::clipboard::XFlushableClipboard
> xFlushableClipboard( xClipboard
, uno::UNO_QUERY
);
628 if( xFlushableClipboard
.is() )
629 xFlushableClipboard
->flushClipboard();
638 sal_Bool
VCLXAccessibleTabPage::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
644 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */