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>
32 #include <i18nlangtag/languagetag.hxx>
35 namespace accessibility
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star
;
43 using namespace ::comphelper
;
46 // class AccessibleTabBarPage
49 AccessibleTabBarPage::AccessibleTabBarPage( TabBar
* pTabBar
, sal_uInt16 nPageId
, const Reference
< XAccessible
>& rxParent
)
50 :AccessibleTabBarBase( pTabBar
)
52 ,m_xParent( rxParent
)
54 m_bShowing
= IsShowing();
55 m_bSelected
= IsSelected();
58 m_sPageText
= m_pTabBar
->GetPageText( m_nPageId
);
62 bool AccessibleTabBarPage::IsEnabled()
64 OExternalLockGuard
aGuard( this );
66 bool bEnabled
= false;
68 bEnabled
= m_pTabBar
->IsPageEnabled( m_nPageId
);
74 bool AccessibleTabBarPage::IsShowing() const
76 bool bShowing
= false;
78 if ( m_pTabBar
&& m_pTabBar
->IsVisible() )
85 bool AccessibleTabBarPage::IsSelected() const
87 bool bSelected
= false;
89 if ( m_pTabBar
&& m_pTabBar
->GetCurPageId() == m_nPageId
)
96 void AccessibleTabBarPage::SetShowing( bool bShowing
)
98 if ( m_bShowing
!= bShowing
)
100 Any aOldValue
, aNewValue
;
102 aOldValue
<<= AccessibleStateType::SHOWING
;
104 aNewValue
<<= AccessibleStateType::SHOWING
;
105 m_bShowing
= bShowing
;
106 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
111 void AccessibleTabBarPage::SetSelected( bool bSelected
)
113 if ( m_bSelected
!= bSelected
)
115 Any aOldValue
, aNewValue
;
117 aOldValue
<<= AccessibleStateType::SELECTED
;
119 aNewValue
<<= AccessibleStateType::SELECTED
;
120 m_bSelected
= bSelected
;
121 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
126 void AccessibleTabBarPage::SetPageText( const OUString
& sPageText
)
128 if ( m_sPageText
!= sPageText
)
130 Any aOldValue
, aNewValue
;
131 aOldValue
<<= m_sPageText
;
132 aNewValue
<<= sPageText
;
133 m_sPageText
= sPageText
;
134 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
139 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
143 rStateSet
.AddState( AccessibleStateType::ENABLED
);
144 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
147 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
150 rStateSet
.AddState( AccessibleStateType::SHOWING
);
152 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
155 rStateSet
.AddState( AccessibleStateType::SELECTED
);
159 // OCommonAccessibleComponent
162 awt::Rectangle
AccessibleTabBarPage::implGetBounds()
164 awt::Rectangle aBounds
;
167 // get bounding rectangle relative to the AccessibleTabBar
168 aBounds
= AWTRectangle( m_pTabBar
->GetPageRect( m_nPageId
) );
170 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
171 Reference
< XAccessible
> xParent
= getAccessibleParent();
174 Reference
< XAccessibleComponent
> xParentComponent( xParent
->getAccessibleContext(), UNO_QUERY
);
175 if ( xParentComponent
.is() )
177 awt::Point aParentLoc
= xParentComponent
->getLocation();
179 // calculate bounding rectangle relative to the AccessibleTabBarPageList
180 aBounds
.X
-= aParentLoc
.X
;
181 aBounds
.Y
-= aParentLoc
.Y
;
193 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage
, OAccessibleExtendedComponentHelper
, AccessibleTabBarPage_BASE
)
199 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage
, OAccessibleExtendedComponentHelper
, AccessibleTabBarPage_BASE
)
205 void AccessibleTabBarPage::disposing()
207 AccessibleTabBarBase::disposing();
215 OUString
AccessibleTabBarPage::getImplementationName()
217 return "com.sun.star.comp.svtools.AccessibleTabBarPage";
221 sal_Bool
AccessibleTabBarPage::supportsService( const OUString
& rServiceName
)
223 return cppu::supportsService(this, rServiceName
);
227 Sequence
< OUString
> AccessibleTabBarPage::getSupportedServiceNames()
229 return { "com.sun.star.awt.AccessibleTabBarPage" };
236 Reference
< XAccessibleContext
> AccessibleTabBarPage::getAccessibleContext( )
238 OExternalLockGuard
aGuard( this );
244 // XAccessibleContext
247 sal_Int32
AccessibleTabBarPage::getAccessibleChildCount()
253 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleChild( sal_Int32
)
255 OExternalLockGuard
aGuard( this );
257 throw IndexOutOfBoundsException();
261 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleParent( )
263 OExternalLockGuard
aGuard( this );
269 sal_Int32
AccessibleTabBarPage::getAccessibleIndexInParent( )
271 OExternalLockGuard
aGuard( this );
273 sal_Int32 nIndexInParent
= -1;
275 nIndexInParent
= m_pTabBar
->GetPagePos( m_nPageId
);
277 return nIndexInParent
;
281 sal_Int16
AccessibleTabBarPage::getAccessibleRole( )
283 return AccessibleRole::PAGE_TAB
;
287 OUString
AccessibleTabBarPage::getAccessibleDescription( )
289 OExternalLockGuard
aGuard( this );
291 OUString sDescription
;
293 sDescription
= m_pTabBar
->GetHelpText( m_nPageId
);
299 OUString
AccessibleTabBarPage::getAccessibleName( )
301 OExternalLockGuard
aGuard( this );
307 Reference
< XAccessibleRelationSet
> AccessibleTabBarPage::getAccessibleRelationSet( )
309 OExternalLockGuard
aGuard( this );
311 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
312 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
317 Reference
< XAccessibleStateSet
> AccessibleTabBarPage::getAccessibleStateSet( )
319 OExternalLockGuard
aGuard( this );
321 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
322 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
324 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
326 FillAccessibleStateSet( *pStateSetHelper
);
330 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
337 Locale
AccessibleTabBarPage::getLocale( )
339 OExternalLockGuard
aGuard( this );
341 return Application::GetSettings().GetLanguageTag().getLocale();
345 // XAccessibleComponent
348 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point
& )
350 return Reference
< XAccessible
>();
354 void AccessibleTabBarPage::grabFocus( )
360 sal_Int32
AccessibleTabBarPage::getForeground( )
362 OExternalLockGuard
aGuard( this );
364 sal_Int32 nColor
= 0;
365 Reference
< XAccessible
> xParent
= getAccessibleParent();
368 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
369 if ( xParentComp
.is() )
370 nColor
= xParentComp
->getForeground();
377 sal_Int32
AccessibleTabBarPage::getBackground( )
379 OExternalLockGuard
aGuard( this );
381 sal_Int32 nColor
= 0;
382 Reference
< XAccessible
> xParent
= getAccessibleParent();
385 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
386 if ( xParentComp
.is() )
387 nColor
= xParentComp
->getBackground();
394 // XAccessibleExtendedComponent
397 Reference
< awt::XFont
> AccessibleTabBarPage::getFont( )
399 OExternalLockGuard
aGuard( this );
401 Reference
< awt::XFont
> xFont
;
402 Reference
< XAccessible
> xParent
= getAccessibleParent();
405 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
406 if ( xParentComp
.is() )
407 xFont
= xParentComp
->getFont();
414 OUString
AccessibleTabBarPage::getTitledBorderText( )
416 OExternalLockGuard
aGuard( this );
422 OUString
AccessibleTabBarPage::getToolTipText( )
428 } // namespace accessibility
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */