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 <extended/accessibletabbarpage.hxx>
21 #include <svtools/tabbar.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/lang/IndexOutOfBoundsException.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/settings.hxx>
31 #include <toolkit/helper/convert.hxx>
34 namespace accessibility
38 using namespace ::com::sun::star::accessibility
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star
;
42 using namespace ::comphelper
;
45 // class AccessibleTabBarPage
48 AccessibleTabBarPage::AccessibleTabBarPage( TabBar
* pTabBar
, sal_uInt16 nPageId
, const Reference
< XAccessible
>& rxParent
)
49 :AccessibleTabBarBase( pTabBar
)
51 ,m_xParent( rxParent
)
53 m_bShowing
= IsShowing();
54 m_bSelected
= IsSelected();
57 m_sPageText
= m_pTabBar
->GetPageText( m_nPageId
);
61 bool AccessibleTabBarPage::IsEnabled()
63 OExternalLockGuard
aGuard( this );
65 bool bEnabled
= false;
67 bEnabled
= m_pTabBar
->IsPageEnabled( m_nPageId
);
73 bool AccessibleTabBarPage::IsShowing()
75 bool bShowing
= false;
77 if ( m_pTabBar
&& m_pTabBar
->IsVisible() )
84 bool AccessibleTabBarPage::IsSelected()
86 bool bSelected
= false;
88 if ( m_pTabBar
&& m_pTabBar
->GetCurPageId() == m_nPageId
)
95 void AccessibleTabBarPage::SetShowing( bool bShowing
)
97 if ( m_bShowing
!= bShowing
)
99 Any aOldValue
, aNewValue
;
101 aOldValue
<<= AccessibleStateType::SHOWING
;
103 aNewValue
<<= AccessibleStateType::SHOWING
;
104 m_bShowing
= bShowing
;
105 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
110 void AccessibleTabBarPage::SetSelected( bool bSelected
)
112 if ( m_bSelected
!= bSelected
)
114 Any aOldValue
, aNewValue
;
116 aOldValue
<<= AccessibleStateType::SELECTED
;
118 aNewValue
<<= AccessibleStateType::SELECTED
;
119 m_bSelected
= bSelected
;
120 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
125 void AccessibleTabBarPage::SetPageText( const OUString
& sPageText
)
127 if ( m_sPageText
!= sPageText
)
129 Any aOldValue
, aNewValue
;
130 aOldValue
<<= m_sPageText
;
131 aNewValue
<<= sPageText
;
132 m_sPageText
= sPageText
;
133 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
138 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
142 rStateSet
.AddState( AccessibleStateType::ENABLED
);
143 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
146 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
149 rStateSet
.AddState( AccessibleStateType::SHOWING
);
151 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
154 rStateSet
.AddState( AccessibleStateType::SELECTED
);
158 // OCommonAccessibleComponent
161 awt::Rectangle
AccessibleTabBarPage::implGetBounds()
163 awt::Rectangle aBounds
;
166 // get bounding rectangle relative to the AccessibleTabBar
167 aBounds
= AWTRectangle( m_pTabBar
->GetPageRect( m_nPageId
) );
169 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
170 Reference
< XAccessible
> xParent
= getAccessibleParent();
173 Reference
< XAccessibleComponent
> xParentComponent( xParent
->getAccessibleContext(), UNO_QUERY
);
174 if ( xParentComponent
.is() )
176 awt::Point aParentLoc
= xParentComponent
->getLocation();
178 // calculate bounding rectangle relative to the AccessibleTabBarPageList
179 aBounds
.X
-= aParentLoc
.X
;
180 aBounds
.Y
-= aParentLoc
.Y
;
192 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage
, OAccessibleExtendedComponentHelper
, AccessibleTabBarPage_BASE
)
198 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage
, OAccessibleExtendedComponentHelper
, AccessibleTabBarPage_BASE
)
204 void AccessibleTabBarPage::disposing()
206 AccessibleTabBarBase::disposing();
214 OUString
AccessibleTabBarPage::getImplementationName()
216 return OUString( "com.sun.star.comp.svtools.AccessibleTabBarPage" );
220 sal_Bool
AccessibleTabBarPage::supportsService( const OUString
& rServiceName
)
222 return cppu::supportsService(this, rServiceName
);
226 Sequence
< OUString
> AccessibleTabBarPage::getSupportedServiceNames()
228 return { "com.sun.star.awt.AccessibleTabBarPage" };
235 Reference
< XAccessibleContext
> AccessibleTabBarPage::getAccessibleContext( )
237 OExternalLockGuard
aGuard( this );
243 // XAccessibleContext
246 sal_Int32
AccessibleTabBarPage::getAccessibleChildCount()
252 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleChild( sal_Int32
)
254 OExternalLockGuard
aGuard( this );
256 throw IndexOutOfBoundsException();
260 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleParent( )
262 OExternalLockGuard
aGuard( this );
268 sal_Int32
AccessibleTabBarPage::getAccessibleIndexInParent( )
270 OExternalLockGuard
aGuard( this );
272 sal_Int32 nIndexInParent
= -1;
274 nIndexInParent
= m_pTabBar
->GetPagePos( m_nPageId
);
276 return nIndexInParent
;
280 sal_Int16
AccessibleTabBarPage::getAccessibleRole( )
282 return AccessibleRole::PAGE_TAB
;
286 OUString
AccessibleTabBarPage::getAccessibleDescription( )
288 OExternalLockGuard
aGuard( this );
290 OUString sDescription
;
292 sDescription
= m_pTabBar
->GetHelpText( m_nPageId
);
298 OUString
AccessibleTabBarPage::getAccessibleName( )
300 OExternalLockGuard
aGuard( this );
306 Reference
< XAccessibleRelationSet
> AccessibleTabBarPage::getAccessibleRelationSet( )
308 OExternalLockGuard
aGuard( this );
310 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
311 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
316 Reference
< XAccessibleStateSet
> AccessibleTabBarPage::getAccessibleStateSet( )
318 OExternalLockGuard
aGuard( this );
320 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
321 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
323 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
325 FillAccessibleStateSet( *pStateSetHelper
);
329 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
336 Locale
AccessibleTabBarPage::getLocale( )
338 OExternalLockGuard
aGuard( this );
340 return Application::GetSettings().GetLanguageTag().getLocale();
344 // XAccessibleComponent
347 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point
& )
349 return Reference
< XAccessible
>();
353 void AccessibleTabBarPage::grabFocus( )
359 sal_Int32
AccessibleTabBarPage::getForeground( )
361 OExternalLockGuard
aGuard( this );
363 sal_Int32 nColor
= 0;
364 Reference
< XAccessible
> xParent
= getAccessibleParent();
367 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
368 if ( xParentComp
.is() )
369 nColor
= xParentComp
->getForeground();
376 sal_Int32
AccessibleTabBarPage::getBackground( )
378 OExternalLockGuard
aGuard( this );
380 sal_Int32 nColor
= 0;
381 Reference
< XAccessible
> xParent
= getAccessibleParent();
384 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
385 if ( xParentComp
.is() )
386 nColor
= xParentComp
->getBackground();
393 // XAccessibleExtendedComponent
396 Reference
< awt::XFont
> AccessibleTabBarPage::getFont( )
398 OExternalLockGuard
aGuard( this );
400 Reference
< awt::XFont
> xFont
;
401 Reference
< XAccessible
> xParent
= getAccessibleParent();
404 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
405 if ( xParentComp
.is() )
406 xFont
= xParentComp
->getFont();
413 OUString
AccessibleTabBarPage::getTitledBorderText( )
415 OExternalLockGuard
aGuard( this );
421 OUString
AccessibleTabBarPage::getToolTipText( )
427 } // namespace accessibility
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */