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 <accessibility/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 <cppuhelper/supportsservice.hxx>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <unotools/accessiblerelationsethelper.hxx>
28 #include <vcl/svapp.hxx>
29 #include <toolkit/helper/convert.hxx>
32 //.........................................................................
33 namespace accessibility
35 //.........................................................................
37 using namespace ::com::sun::star::accessibility
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star
;
41 using namespace ::comphelper
;
43 // -----------------------------------------------------------------------------
44 // class AccessibleTabBarPage
45 // -----------------------------------------------------------------------------
47 AccessibleTabBarPage::AccessibleTabBarPage( TabBar
* pTabBar
, sal_uInt16 nPageId
, const Reference
< XAccessible
>& rxParent
)
48 :AccessibleTabBarBase( pTabBar
)
50 ,m_xParent( rxParent
)
52 m_bEnabled
= IsEnabled();
53 m_bShowing
= IsShowing();
54 m_bSelected
= IsSelected();
57 m_sPageText
= m_pTabBar
->GetPageText( m_nPageId
);
60 // -----------------------------------------------------------------------------
62 AccessibleTabBarPage::~AccessibleTabBarPage()
66 // -----------------------------------------------------------------------------
68 sal_Bool
AccessibleTabBarPage::IsEnabled()
70 OExternalLockGuard
aGuard( this );
72 sal_Bool bEnabled
= sal_False
;
74 bEnabled
= m_pTabBar
->IsPageEnabled( m_nPageId
);
79 // -----------------------------------------------------------------------------
81 sal_Bool
AccessibleTabBarPage::IsShowing()
83 sal_Bool bShowing
= sal_False
;
85 if ( m_pTabBar
&& m_pTabBar
->IsVisible() )
91 // -----------------------------------------------------------------------------
93 sal_Bool
AccessibleTabBarPage::IsSelected()
95 sal_Bool bSelected
= sal_False
;
97 if ( m_pTabBar
&& m_pTabBar
->GetCurPageId() == m_nPageId
)
103 // -----------------------------------------------------------------------------
105 void AccessibleTabBarPage::SetEnabled( sal_Bool bEnabled
)
107 if ( m_bEnabled
!= bEnabled
)
109 Any aOldValue
[2], aNewValue
[2];
112 aOldValue
[0] <<= AccessibleStateType::SENSITIVE
;
113 aOldValue
[1] <<= AccessibleStateType::ENABLED
;
118 aNewValue
[0] <<= AccessibleStateType::ENABLED
;
119 aNewValue
[1] <<= AccessibleStateType::SENSITIVE
;
121 m_bEnabled
= bEnabled
;
122 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
[0], aNewValue
[0] );
123 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
[1], aNewValue
[1] );
127 // -----------------------------------------------------------------------------
129 void AccessibleTabBarPage::SetShowing( sal_Bool bShowing
)
131 if ( m_bShowing
!= bShowing
)
133 Any aOldValue
, aNewValue
;
135 aOldValue
<<= AccessibleStateType::SHOWING
;
137 aNewValue
<<= AccessibleStateType::SHOWING
;
138 m_bShowing
= bShowing
;
139 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
143 // -----------------------------------------------------------------------------
145 void AccessibleTabBarPage::SetSelected( sal_Bool bSelected
)
147 if ( m_bSelected
!= bSelected
)
149 Any aOldValue
, aNewValue
;
151 aOldValue
<<= AccessibleStateType::SELECTED
;
153 aNewValue
<<= AccessibleStateType::SELECTED
;
154 m_bSelected
= bSelected
;
155 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
159 // -----------------------------------------------------------------------------
161 void AccessibleTabBarPage::SetPageText( const OUString
& sPageText
)
163 if ( !m_sPageText
.equals( sPageText
) )
165 Any aOldValue
, aNewValue
;
166 aOldValue
<<= m_sPageText
;
167 aNewValue
<<= sPageText
;
168 m_sPageText
= sPageText
;
169 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
173 // -----------------------------------------------------------------------------
175 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
179 rStateSet
.AddState( AccessibleStateType::ENABLED
);
180 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
183 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
186 rStateSet
.AddState( AccessibleStateType::SHOWING
);
188 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
191 rStateSet
.AddState( AccessibleStateType::SELECTED
);
194 // -----------------------------------------------------------------------------
195 // OCommonAccessibleComponent
196 // -----------------------------------------------------------------------------
198 awt::Rectangle
AccessibleTabBarPage::implGetBounds() throw (RuntimeException
)
200 awt::Rectangle aBounds
;
203 // get bounding rectangle relative to the AccessibleTabBar
204 aBounds
= AWTRectangle( m_pTabBar
->GetPageRect( m_nPageId
) );
206 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
207 Reference
< XAccessible
> xParent
= getAccessibleParent();
210 Reference
< XAccessibleComponent
> xParentComponent( xParent
->getAccessibleContext(), UNO_QUERY
);
211 if ( xParentComponent
.is() )
213 awt::Point aParentLoc
= xParentComponent
->getLocation();
215 // calculate bounding rectangle relative to the AccessibleTabBarPageList
216 aBounds
.X
-= aParentLoc
.X
;
217 aBounds
.Y
-= aParentLoc
.Y
;
225 // -----------------------------------------------------------------------------
227 // -----------------------------------------------------------------------------
229 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBarPage_BASE
)
231 // -----------------------------------------------------------------------------
233 // -----------------------------------------------------------------------------
235 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBarPage_BASE
)
237 // -----------------------------------------------------------------------------
239 // -----------------------------------------------------------------------------
241 void AccessibleTabBarPage::disposing()
243 AccessibleTabBarBase::disposing();
244 m_sPageText
= OUString();
247 // -----------------------------------------------------------------------------
249 // -----------------------------------------------------------------------------
251 OUString
AccessibleTabBarPage::getImplementationName() throw (RuntimeException
)
253 return OUString( "com.sun.star.comp.svtools.AccessibleTabBarPage" );
256 // -----------------------------------------------------------------------------
258 sal_Bool
AccessibleTabBarPage::supportsService( const OUString
& rServiceName
) throw (RuntimeException
)
260 return cppu::supportsService(this, rServiceName
);
263 // -----------------------------------------------------------------------------
265 Sequence
< OUString
> AccessibleTabBarPage::getSupportedServiceNames() throw (RuntimeException
)
267 Sequence
< OUString
> aNames(1);
268 aNames
[0] = "com.sun.star.awt.AccessibleTabBarPage";
272 // -----------------------------------------------------------------------------
274 // -----------------------------------------------------------------------------
276 Reference
< XAccessibleContext
> AccessibleTabBarPage::getAccessibleContext( ) throw (RuntimeException
)
278 OExternalLockGuard
aGuard( this );
283 // -----------------------------------------------------------------------------
284 // XAccessibleContext
285 // -----------------------------------------------------------------------------
287 sal_Int32
AccessibleTabBarPage::getAccessibleChildCount() throw (RuntimeException
)
289 OExternalLockGuard
aGuard( this );
294 // -----------------------------------------------------------------------------
296 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
298 OExternalLockGuard
aGuard( this );
300 if ( i
< 0 || i
>= getAccessibleChildCount() )
301 throw IndexOutOfBoundsException();
303 return Reference
< XAccessible
>();
306 // -----------------------------------------------------------------------------
308 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleParent( ) throw (RuntimeException
)
310 OExternalLockGuard
aGuard( this );
315 // -----------------------------------------------------------------------------
317 sal_Int32
AccessibleTabBarPage::getAccessibleIndexInParent( ) throw (RuntimeException
)
319 OExternalLockGuard
aGuard( this );
321 sal_Int32 nIndexInParent
= -1;
323 nIndexInParent
= m_pTabBar
->GetPagePos( m_nPageId
);
325 return nIndexInParent
;
328 // -----------------------------------------------------------------------------
330 sal_Int16
AccessibleTabBarPage::getAccessibleRole( ) throw (RuntimeException
)
332 OExternalLockGuard
aGuard( this );
334 return AccessibleRole::PAGE_TAB
;
337 // -----------------------------------------------------------------------------
339 OUString
AccessibleTabBarPage::getAccessibleDescription( ) throw (RuntimeException
)
341 OExternalLockGuard
aGuard( this );
343 OUString sDescription
;
345 sDescription
= m_pTabBar
->GetHelpText( m_nPageId
);
350 // -----------------------------------------------------------------------------
352 OUString
AccessibleTabBarPage::getAccessibleName( ) throw (RuntimeException
)
354 OExternalLockGuard
aGuard( this );
359 // -----------------------------------------------------------------------------
361 Reference
< XAccessibleRelationSet
> AccessibleTabBarPage::getAccessibleRelationSet( ) throw (RuntimeException
)
363 OExternalLockGuard
aGuard( this );
365 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
366 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
370 // -----------------------------------------------------------------------------
372 Reference
< XAccessibleStateSet
> AccessibleTabBarPage::getAccessibleStateSet( ) throw (RuntimeException
)
374 OExternalLockGuard
aGuard( this );
376 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
377 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
379 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
381 FillAccessibleStateSet( *pStateSetHelper
);
385 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
391 // -----------------------------------------------------------------------------
393 Locale
AccessibleTabBarPage::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
395 OExternalLockGuard
aGuard( this );
397 return Application::GetSettings().GetLanguageTag().getLocale();
400 // -----------------------------------------------------------------------------
401 // XAccessibleComponent
402 // -----------------------------------------------------------------------------
404 Reference
< XAccessible
> AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point
& ) throw (RuntimeException
)
406 OExternalLockGuard
aGuard( this );
408 return Reference
< XAccessible
>();
411 // -----------------------------------------------------------------------------
413 void AccessibleTabBarPage::grabFocus( ) throw (RuntimeException
)
418 // -----------------------------------------------------------------------------
420 sal_Int32
AccessibleTabBarPage::getForeground( ) throw (RuntimeException
)
422 OExternalLockGuard
aGuard( this );
424 sal_Int32 nColor
= 0;
425 Reference
< XAccessible
> xParent
= getAccessibleParent();
428 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
429 if ( xParentComp
.is() )
430 nColor
= xParentComp
->getForeground();
436 // -----------------------------------------------------------------------------
438 sal_Int32
AccessibleTabBarPage::getBackground( ) throw (RuntimeException
)
440 OExternalLockGuard
aGuard( this );
442 sal_Int32 nColor
= 0;
443 Reference
< XAccessible
> xParent
= getAccessibleParent();
446 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
447 if ( xParentComp
.is() )
448 nColor
= xParentComp
->getBackground();
454 // -----------------------------------------------------------------------------
455 // XAccessibleExtendedComponent
456 // -----------------------------------------------------------------------------
458 Reference
< awt::XFont
> AccessibleTabBarPage::getFont( ) throw (RuntimeException
)
460 OExternalLockGuard
aGuard( this );
462 Reference
< awt::XFont
> xFont
;
463 Reference
< XAccessible
> xParent
= getAccessibleParent();
466 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
467 if ( xParentComp
.is() )
468 xFont
= xParentComp
->getFont();
474 // -----------------------------------------------------------------------------
476 OUString
AccessibleTabBarPage::getTitledBorderText( ) throw (RuntimeException
)
478 OExternalLockGuard
aGuard( this );
483 // -----------------------------------------------------------------------------
485 OUString
AccessibleTabBarPage::getToolTipText( ) throw (RuntimeException
)
487 OExternalLockGuard
aGuard( this );
492 // -----------------------------------------------------------------------------
494 //.........................................................................
495 } // namespace accessibility
496 //.........................................................................
498 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */