update dev300-m58
[ooovba.git] / accessibility / source / extended / accessibletabbarpage.cxx
blobe9caf58ad9bf083f65ed73ccb02d7d01cd04ab51
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessibletabbarpage.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/extended/accessibletabbarpage.hxx>
34 #include <svtools/tabbar.hxx>
35 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36 #include <com/sun/star/accessibility/AccessibleRole.hpp>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 #include <unotools/accessiblestatesethelper.hxx>
39 #include <unotools/accessiblerelationsethelper.hxx>
40 #include <vcl/svapp.hxx>
41 #include <toolkit/helper/convert.hxx>
44 //.........................................................................
45 namespace accessibility
47 //.........................................................................
49 using namespace ::com::sun::star::accessibility;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star;
53 using namespace ::comphelper;
55 // -----------------------------------------------------------------------------
56 // class AccessibleTabBarPage
57 // -----------------------------------------------------------------------------
59 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
60 :AccessibleTabBarBase( pTabBar )
61 ,m_nPageId( nPageId )
62 ,m_xParent( rxParent )
64 m_bEnabled = IsEnabled();
65 m_bShowing = IsShowing();
66 m_bSelected = IsSelected();
68 if ( m_pTabBar )
69 m_sPageText = m_pTabBar->GetPageText( m_nPageId );
72 // -----------------------------------------------------------------------------
74 AccessibleTabBarPage::~AccessibleTabBarPage()
78 // -----------------------------------------------------------------------------
80 sal_Bool AccessibleTabBarPage::IsEnabled()
82 OExternalLockGuard aGuard( this );
84 sal_Bool bEnabled = sal_False;
85 if ( m_pTabBar )
86 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
88 return bEnabled;
91 // -----------------------------------------------------------------------------
93 sal_Bool AccessibleTabBarPage::IsShowing()
95 sal_Bool bShowing = sal_False;
97 if ( m_pTabBar && m_pTabBar->IsVisible() )
98 bShowing = sal_True;
100 return bShowing;
103 // -----------------------------------------------------------------------------
105 sal_Bool AccessibleTabBarPage::IsSelected()
107 sal_Bool bSelected = sal_False;
109 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
110 bSelected = sal_True;
112 return bSelected;
115 // -----------------------------------------------------------------------------
117 void AccessibleTabBarPage::SetEnabled( sal_Bool bEnabled )
119 if ( m_bEnabled != bEnabled )
121 Any aOldValue[2], aNewValue[2];
122 if ( m_bEnabled )
124 aOldValue[0] <<= AccessibleStateType::SENSITIVE;
125 aOldValue[1] <<= AccessibleStateType::ENABLED;
127 else
130 aNewValue[0] <<= AccessibleStateType::ENABLED;
131 aNewValue[1] <<= AccessibleStateType::SENSITIVE;
133 m_bEnabled = bEnabled;
134 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
135 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
139 // -----------------------------------------------------------------------------
141 void AccessibleTabBarPage::SetShowing( sal_Bool bShowing )
143 if ( m_bShowing != bShowing )
145 Any aOldValue, aNewValue;
146 if ( m_bShowing )
147 aOldValue <<= AccessibleStateType::SHOWING;
148 else
149 aNewValue <<= AccessibleStateType::SHOWING;
150 m_bShowing = bShowing;
151 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
155 // -----------------------------------------------------------------------------
157 void AccessibleTabBarPage::SetSelected( sal_Bool bSelected )
159 if ( m_bSelected != bSelected )
161 Any aOldValue, aNewValue;
162 if ( m_bSelected )
163 aOldValue <<= AccessibleStateType::SELECTED;
164 else
165 aNewValue <<= AccessibleStateType::SELECTED;
166 m_bSelected = bSelected;
167 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
171 // -----------------------------------------------------------------------------
173 void AccessibleTabBarPage::SetPageText( const ::rtl::OUString& sPageText )
175 if ( !m_sPageText.equals( sPageText ) )
177 Any aOldValue, aNewValue;
178 aOldValue <<= m_sPageText;
179 aNewValue <<= sPageText;
180 m_sPageText = sPageText;
181 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
185 // -----------------------------------------------------------------------------
187 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
189 if ( IsEnabled() )
191 rStateSet.AddState( AccessibleStateType::ENABLED );
192 rStateSet.AddState( AccessibleStateType::SENSITIVE );
195 rStateSet.AddState( AccessibleStateType::VISIBLE );
197 if ( IsShowing() )
198 rStateSet.AddState( AccessibleStateType::SHOWING );
200 rStateSet.AddState( AccessibleStateType::SELECTABLE );
202 if ( IsSelected() )
203 rStateSet.AddState( AccessibleStateType::SELECTED );
206 // -----------------------------------------------------------------------------
207 // OCommonAccessibleComponent
208 // -----------------------------------------------------------------------------
210 awt::Rectangle AccessibleTabBarPage::implGetBounds() throw (RuntimeException)
212 awt::Rectangle aBounds;
213 if ( m_pTabBar )
215 // get bounding rectangle relative to the AccessibleTabBar
216 aBounds = AWTRectangle( m_pTabBar->GetPageRect( m_nPageId ) );
218 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
219 Reference< XAccessible > xParent = getAccessibleParent();
220 if ( xParent.is() )
222 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
223 if ( xParentComponent.is() )
225 awt::Point aParentLoc = xParentComponent->getLocation();
227 // calculate bounding rectangle relative to the AccessibleTabBarPageList
228 aBounds.X -= aParentLoc.X;
229 aBounds.Y -= aParentLoc.Y;
234 return aBounds;
237 // -----------------------------------------------------------------------------
238 // XInterface
239 // -----------------------------------------------------------------------------
241 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
243 // -----------------------------------------------------------------------------
244 // XTypeProvider
245 // -----------------------------------------------------------------------------
247 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
249 // -----------------------------------------------------------------------------
250 // XComponent
251 // -----------------------------------------------------------------------------
253 void AccessibleTabBarPage::disposing()
255 AccessibleTabBarBase::disposing();
256 m_sPageText = ::rtl::OUString();
259 // -----------------------------------------------------------------------------
260 // XServiceInfo
261 // -----------------------------------------------------------------------------
263 ::rtl::OUString AccessibleTabBarPage::getImplementationName() throw (RuntimeException)
265 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBarPage" );
268 // -----------------------------------------------------------------------------
270 sal_Bool AccessibleTabBarPage::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
272 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
273 const ::rtl::OUString* pNames = aNames.getConstArray();
274 const ::rtl::OUString* pEnd = pNames + aNames.getLength();
275 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
278 return pNames != pEnd;
281 // -----------------------------------------------------------------------------
283 Sequence< ::rtl::OUString > AccessibleTabBarPage::getSupportedServiceNames() throw (RuntimeException)
285 Sequence< ::rtl::OUString > aNames(1);
286 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBarPage" );
287 return aNames;
290 // -----------------------------------------------------------------------------
291 // XAccessible
292 // -----------------------------------------------------------------------------
294 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( ) throw (RuntimeException)
296 OExternalLockGuard aGuard( this );
298 return this;
301 // -----------------------------------------------------------------------------
302 // XAccessibleContext
303 // -----------------------------------------------------------------------------
305 sal_Int32 AccessibleTabBarPage::getAccessibleChildCount() throw (RuntimeException)
307 OExternalLockGuard aGuard( this );
309 return 0;
312 // -----------------------------------------------------------------------------
314 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
316 OExternalLockGuard aGuard( this );
318 if ( i < 0 || i >= getAccessibleChildCount() )
319 throw IndexOutOfBoundsException();
321 return Reference< XAccessible >();
324 // -----------------------------------------------------------------------------
326 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( ) throw (RuntimeException)
328 OExternalLockGuard aGuard( this );
330 return m_xParent;
333 // -----------------------------------------------------------------------------
335 sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent( ) throw (RuntimeException)
337 OExternalLockGuard aGuard( this );
339 sal_Int32 nIndexInParent = -1;
340 if ( m_pTabBar )
341 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
343 return nIndexInParent;
346 // -----------------------------------------------------------------------------
348 sal_Int16 AccessibleTabBarPage::getAccessibleRole( ) throw (RuntimeException)
350 OExternalLockGuard aGuard( this );
352 return AccessibleRole::PAGE_TAB;
355 // -----------------------------------------------------------------------------
357 ::rtl::OUString AccessibleTabBarPage::getAccessibleDescription( ) throw (RuntimeException)
359 OExternalLockGuard aGuard( this );
361 ::rtl::OUString sDescription;
362 if ( m_pTabBar )
363 sDescription = m_pTabBar->GetHelpText( m_nPageId );
365 return sDescription;
368 // -----------------------------------------------------------------------------
370 ::rtl::OUString AccessibleTabBarPage::getAccessibleName( ) throw (RuntimeException)
372 OExternalLockGuard aGuard( this );
374 return m_sPageText;
377 // -----------------------------------------------------------------------------
379 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( ) throw (RuntimeException)
381 OExternalLockGuard aGuard( this );
383 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
384 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
385 return xSet;
388 // -----------------------------------------------------------------------------
390 Reference< XAccessibleStateSet > AccessibleTabBarPage::getAccessibleStateSet( ) throw (RuntimeException)
392 OExternalLockGuard aGuard( this );
394 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
395 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
397 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
399 FillAccessibleStateSet( *pStateSetHelper );
401 else
403 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
406 return xSet;
409 // -----------------------------------------------------------------------------
411 Locale AccessibleTabBarPage::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
413 OExternalLockGuard aGuard( this );
415 return Application::GetSettings().GetLocale();
418 // -----------------------------------------------------------------------------
419 // XAccessibleComponent
420 // -----------------------------------------------------------------------------
422 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
424 OExternalLockGuard aGuard( this );
426 return Reference< XAccessible >();
429 // -----------------------------------------------------------------------------
431 void AccessibleTabBarPage::grabFocus( ) throw (RuntimeException)
433 // no focus
436 // -----------------------------------------------------------------------------
438 sal_Int32 AccessibleTabBarPage::getForeground( ) 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->getForeground();
451 return nColor;
454 // -----------------------------------------------------------------------------
456 sal_Int32 AccessibleTabBarPage::getBackground( ) throw (RuntimeException)
458 OExternalLockGuard aGuard( this );
460 sal_Int32 nColor = 0;
461 Reference< XAccessible > xParent = getAccessibleParent();
462 if ( xParent.is() )
464 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
465 if ( xParentComp.is() )
466 nColor = xParentComp->getBackground();
469 return nColor;
472 // -----------------------------------------------------------------------------
473 // XAccessibleExtendedComponent
474 // -----------------------------------------------------------------------------
476 Reference< awt::XFont > AccessibleTabBarPage::getFont( ) throw (RuntimeException)
478 OExternalLockGuard aGuard( this );
480 Reference< awt::XFont > xFont;
481 Reference< XAccessible > xParent = getAccessibleParent();
482 if ( xParent.is() )
484 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
485 if ( xParentComp.is() )
486 xFont = xParentComp->getFont();
489 return xFont;
492 // -----------------------------------------------------------------------------
494 ::rtl::OUString AccessibleTabBarPage::getTitledBorderText( ) throw (RuntimeException)
496 OExternalLockGuard aGuard( this );
498 return m_sPageText;
501 // -----------------------------------------------------------------------------
503 ::rtl::OUString AccessibleTabBarPage::getToolTipText( ) throw (RuntimeException)
505 OExternalLockGuard aGuard( this );
507 return ::rtl::OUString();
510 // -----------------------------------------------------------------------------
512 //.........................................................................
513 } // namespace accessibility
514 //.........................................................................