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 <comphelper/accessiblecontexthelper.hxx>
27 #include <cppuhelper/supportsservice.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
;
48 AccessibleTabBarPage::AccessibleTabBarPage( TabBar
* pTabBar
, sal_uInt16 nPageId
, const Reference
< XAccessible
>& rxParent
)
49 :ImplInheritanceHelper( 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() const
75 bool bShowing
= false;
77 if ( m_pTabBar
&& m_pTabBar
->IsVisible() )
84 bool AccessibleTabBarPage::IsSelected() const
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( sal_Int64
& rStateSet
)
142 rStateSet
|= AccessibleStateType::ENABLED
;
143 rStateSet
|= AccessibleStateType::SENSITIVE
;
146 rStateSet
|= AccessibleStateType::VISIBLE
;
149 rStateSet
|= AccessibleStateType::SHOWING
;
151 rStateSet
|= AccessibleStateType::SELECTABLE
;
154 rStateSet
|= 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 void AccessibleTabBarPage::disposing()
194 AccessibleTabBarBase::disposing();
202 OUString
AccessibleTabBarPage::getImplementationName()
204 return "com.sun.star.comp.svtools.AccessibleTabBarPage";
208 sal_Bool
AccessibleTabBarPage::supportsService( const OUString
& rServiceName
)
210 return cppu::supportsService(this, rServiceName
);
214 Sequence
< OUString
> AccessibleTabBarPage::getSupportedServiceNames()
216 return { "com.sun.star.awt.AccessibleTabBarPage" };
223 Reference
< XAccessibleContext
> AccessibleTabBarPage::getAccessibleContext( )
225 OExternalLockGuard
aGuard( this );
231 // XAccessibleContext
234 sal_Int64
AccessibleTabBarPage::getAccessibleChildCount()
240 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleChild( sal_Int64
)
242 OExternalLockGuard
aGuard( this );
244 throw IndexOutOfBoundsException();
248 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleParent( )
250 OExternalLockGuard
aGuard( this );
256 sal_Int64
AccessibleTabBarPage::getAccessibleIndexInParent( )
258 OExternalLockGuard
aGuard( this );
260 sal_Int64 nIndexInParent
= -1;
262 nIndexInParent
= m_pTabBar
->GetPagePos( m_nPageId
);
264 return nIndexInParent
;
268 sal_Int16
AccessibleTabBarPage::getAccessibleRole( )
270 return AccessibleRole::PAGE_TAB
;
274 OUString
AccessibleTabBarPage::getAccessibleDescription( )
276 OExternalLockGuard
aGuard( this );
278 OUString sDescription
;
280 sDescription
= m_pTabBar
->GetHelpText( m_nPageId
);
286 OUString
AccessibleTabBarPage::getAccessibleName( )
288 OExternalLockGuard
aGuard( this );
294 Reference
< XAccessibleRelationSet
> AccessibleTabBarPage::getAccessibleRelationSet( )
296 OExternalLockGuard
aGuard( this );
298 return new utl::AccessibleRelationSetHelper
;
302 sal_Int64
AccessibleTabBarPage::getAccessibleStateSet( )
304 OExternalLockGuard
aGuard( this );
306 sal_Int64 nStateSet
= 0;
308 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
310 FillAccessibleStateSet( nStateSet
);
314 nStateSet
|= AccessibleStateType::DEFUNC
;
321 Locale
AccessibleTabBarPage::getLocale( )
323 OExternalLockGuard
aGuard( this );
325 return Application::GetSettings().GetLanguageTag().getLocale();
329 // XAccessibleComponent
332 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point
& )
334 return Reference
< XAccessible
>();
338 void AccessibleTabBarPage::grabFocus( )
344 sal_Int32
AccessibleTabBarPage::getForeground( )
346 OExternalLockGuard
aGuard( this );
348 sal_Int32 nColor
= 0;
349 Reference
< XAccessible
> xParent
= getAccessibleParent();
352 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
353 if ( xParentComp
.is() )
354 nColor
= xParentComp
->getForeground();
361 sal_Int32
AccessibleTabBarPage::getBackground( )
363 OExternalLockGuard
aGuard( this );
365 sal_Int32 nColor
= 0;
366 Reference
< XAccessible
> xParent
= getAccessibleParent();
369 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
370 if ( xParentComp
.is() )
371 nColor
= xParentComp
->getBackground();
378 // XAccessibleExtendedComponent
381 Reference
< awt::XFont
> AccessibleTabBarPage::getFont( )
383 OExternalLockGuard
aGuard( this );
385 Reference
< awt::XFont
> xFont
;
386 Reference
< XAccessible
> xParent
= getAccessibleParent();
389 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
390 if ( xParentComp
.is() )
391 xFont
= xParentComp
->getFont();
398 OUString
AccessibleTabBarPage::getTitledBorderText( )
400 OExternalLockGuard
aGuard( this );
406 OUString
AccessibleTabBarPage::getToolTipText( )
412 } // namespace accessibility
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */