Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / accessibility / source / extended / accessibletabbarpage.cxx
blob3fe24269436cc8144c98d33656cbaabfaea39af6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 )
49 ,m_nPageId( nPageId )
50 ,m_xParent( rxParent )
52 m_bEnabled = IsEnabled();
53 m_bShowing = IsShowing();
54 m_bSelected = IsSelected();
56 if ( m_pTabBar )
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;
73 if ( m_pTabBar )
74 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
76 return bEnabled;
79 // -----------------------------------------------------------------------------
81 sal_Bool AccessibleTabBarPage::IsShowing()
83 sal_Bool bShowing = sal_False;
85 if ( m_pTabBar && m_pTabBar->IsVisible() )
86 bShowing = sal_True;
88 return bShowing;
91 // -----------------------------------------------------------------------------
93 sal_Bool AccessibleTabBarPage::IsSelected()
95 sal_Bool bSelected = sal_False;
97 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
98 bSelected = sal_True;
100 return bSelected;
103 // -----------------------------------------------------------------------------
105 void AccessibleTabBarPage::SetEnabled( sal_Bool bEnabled )
107 if ( m_bEnabled != bEnabled )
109 Any aOldValue[2], aNewValue[2];
110 if ( m_bEnabled )
112 aOldValue[0] <<= AccessibleStateType::SENSITIVE;
113 aOldValue[1] <<= AccessibleStateType::ENABLED;
115 else
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;
134 if ( m_bShowing )
135 aOldValue <<= AccessibleStateType::SHOWING;
136 else
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;
150 if ( m_bSelected )
151 aOldValue <<= AccessibleStateType::SELECTED;
152 else
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 )
177 if ( IsEnabled() )
179 rStateSet.AddState( AccessibleStateType::ENABLED );
180 rStateSet.AddState( AccessibleStateType::SENSITIVE );
183 rStateSet.AddState( AccessibleStateType::VISIBLE );
185 if ( IsShowing() )
186 rStateSet.AddState( AccessibleStateType::SHOWING );
188 rStateSet.AddState( AccessibleStateType::SELECTABLE );
190 if ( IsSelected() )
191 rStateSet.AddState( AccessibleStateType::SELECTED );
194 // -----------------------------------------------------------------------------
195 // OCommonAccessibleComponent
196 // -----------------------------------------------------------------------------
198 awt::Rectangle AccessibleTabBarPage::implGetBounds() throw (RuntimeException)
200 awt::Rectangle aBounds;
201 if ( m_pTabBar )
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();
208 if ( xParent.is() )
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;
222 return aBounds;
225 // -----------------------------------------------------------------------------
226 // XInterface
227 // -----------------------------------------------------------------------------
229 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
231 // -----------------------------------------------------------------------------
232 // XTypeProvider
233 // -----------------------------------------------------------------------------
235 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
237 // -----------------------------------------------------------------------------
238 // XComponent
239 // -----------------------------------------------------------------------------
241 void AccessibleTabBarPage::disposing()
243 AccessibleTabBarBase::disposing();
244 m_sPageText = OUString();
247 // -----------------------------------------------------------------------------
248 // XServiceInfo
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";
269 return aNames;
272 // -----------------------------------------------------------------------------
273 // XAccessible
274 // -----------------------------------------------------------------------------
276 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( ) throw (RuntimeException)
278 OExternalLockGuard aGuard( this );
280 return this;
283 // -----------------------------------------------------------------------------
284 // XAccessibleContext
285 // -----------------------------------------------------------------------------
287 sal_Int32 AccessibleTabBarPage::getAccessibleChildCount() throw (RuntimeException)
289 OExternalLockGuard aGuard( this );
291 return 0;
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 );
312 return m_xParent;
315 // -----------------------------------------------------------------------------
317 sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent( ) throw (RuntimeException)
319 OExternalLockGuard aGuard( this );
321 sal_Int32 nIndexInParent = -1;
322 if ( m_pTabBar )
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;
344 if ( m_pTabBar )
345 sDescription = m_pTabBar->GetHelpText( m_nPageId );
347 return sDescription;
350 // -----------------------------------------------------------------------------
352 OUString AccessibleTabBarPage::getAccessibleName( ) throw (RuntimeException)
354 OExternalLockGuard aGuard( this );
356 return m_sPageText;
359 // -----------------------------------------------------------------------------
361 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( ) throw (RuntimeException)
363 OExternalLockGuard aGuard( this );
365 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
366 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
367 return xSet;
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 );
383 else
385 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
388 return xSet;
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)
415 // no focus
418 // -----------------------------------------------------------------------------
420 sal_Int32 AccessibleTabBarPage::getForeground( ) throw (RuntimeException)
422 OExternalLockGuard aGuard( this );
424 sal_Int32 nColor = 0;
425 Reference< XAccessible > xParent = getAccessibleParent();
426 if ( xParent.is() )
428 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
429 if ( xParentComp.is() )
430 nColor = xParentComp->getForeground();
433 return nColor;
436 // -----------------------------------------------------------------------------
438 sal_Int32 AccessibleTabBarPage::getBackground( ) throw (RuntimeException)
440 OExternalLockGuard aGuard( this );
442 sal_Int32 nColor = 0;
443 Reference< XAccessible > xParent = getAccessibleParent();
444 if ( xParent.is() )
446 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
447 if ( xParentComp.is() )
448 nColor = xParentComp->getBackground();
451 return nColor;
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();
464 if ( xParent.is() )
466 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
467 if ( xParentComp.is() )
468 xFont = xParentComp->getFont();
471 return xFont;
474 // -----------------------------------------------------------------------------
476 OUString AccessibleTabBarPage::getTitledBorderText( ) throw (RuntimeException)
478 OExternalLockGuard aGuard( this );
480 return m_sPageText;
483 // -----------------------------------------------------------------------------
485 OUString AccessibleTabBarPage::getToolTipText( ) throw (RuntimeException)
487 OExternalLockGuard aGuard( this );
489 return OUString();
492 // -----------------------------------------------------------------------------
494 //.........................................................................
495 } // namespace accessibility
496 //.........................................................................
498 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */