merge the formfield patch from ooo-build
[ooovba.git] / accessibility / source / extended / accessibletabbar.cxx
blob104aad95dc042e99a2ed42fb5fbbc314797dafa4
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: accessibletabbar.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/accessibletabbar.hxx>
34 #include <svtools/tabbar.hxx>
35 #include <accessibility/extended/accessibletabbarpagelist.hxx>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <unotools/accessiblerelationsethelper.hxx>
41 #include <vcl/svapp.hxx>
42 #include <toolkit/awt/vclxfont.hxx>
43 #include <toolkit/helper/convert.hxx>
45 #include <vector>
48 //.........................................................................
49 namespace accessibility
51 //.........................................................................
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::lang;
56 using namespace ::com::sun::star::accessibility;
57 using namespace ::comphelper;
59 DBG_NAME( AccessibleTabBar )
61 // ----------------------------------------------------
62 // class AccessibleTabBar
63 // ----------------------------------------------------
65 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
66 :AccessibleTabBarBase( pTabBar )
68 DBG_CTOR( AccessibleTabBar, NULL );
70 if ( m_pTabBar )
71 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
74 // -----------------------------------------------------------------------------
76 AccessibleTabBar::~AccessibleTabBar()
78 DBG_DTOR( AccessibleTabBar, NULL );
81 // -----------------------------------------------------------------------------
83 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
85 Any aOldValue, aNewValue;
87 switch ( rVclWindowEvent.GetId() )
89 case VCLEVENT_WINDOW_ENABLED:
91 aNewValue <<= AccessibleStateType::SENSITIVE;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
93 aNewValue <<= AccessibleStateType::ENABLED;
94 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
96 break;
97 case VCLEVENT_WINDOW_DISABLED:
99 aOldValue <<= AccessibleStateType::ENABLED;
100 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
101 aOldValue <<= AccessibleStateType::SENSITIVE;
102 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
104 break;
105 case VCLEVENT_WINDOW_GETFOCUS:
107 aNewValue <<= AccessibleStateType::FOCUSED;
108 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
110 break;
111 case VCLEVENT_WINDOW_LOSEFOCUS:
113 aOldValue <<= AccessibleStateType::FOCUSED;
114 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
116 break;
117 case VCLEVENT_WINDOW_SHOW:
119 aNewValue <<= AccessibleStateType::SHOWING;
120 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
122 break;
123 case VCLEVENT_WINDOW_HIDE:
125 aOldValue <<= AccessibleStateType::SHOWING;
126 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
128 break;
129 default:
131 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
133 break;
137 // -----------------------------------------------------------------------------
139 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
141 if ( m_pTabBar )
143 if ( m_pTabBar->IsEnabled() )
145 rStateSet.AddState( AccessibleStateType::ENABLED );
146 rStateSet.AddState( AccessibleStateType::SENSITIVE );
149 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
151 if ( m_pTabBar->HasFocus() )
152 rStateSet.AddState( AccessibleStateType::FOCUSED );
154 rStateSet.AddState( AccessibleStateType::VISIBLE );
156 if ( m_pTabBar->IsVisible() )
157 rStateSet.AddState( AccessibleStateType::SHOWING );
159 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
160 rStateSet.AddState( AccessibleStateType::RESIZABLE );
164 // -----------------------------------------------------------------------------
165 // OCommonAccessibleComponent
166 // -----------------------------------------------------------------------------
168 awt::Rectangle AccessibleTabBar::implGetBounds() throw (RuntimeException)
170 awt::Rectangle aBounds;
171 if ( m_pTabBar )
172 aBounds = AWTRectangle( Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
174 return aBounds;
177 // -----------------------------------------------------------------------------
178 // XInterface
179 // -----------------------------------------------------------------------------
181 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
183 // -----------------------------------------------------------------------------
184 // XTypeProvider
185 // -----------------------------------------------------------------------------
187 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
189 // -----------------------------------------------------------------------------
190 // XComponent
191 // -----------------------------------------------------------------------------
193 void AccessibleTabBar::disposing()
195 AccessibleTabBarBase::disposing();
197 // dispose all children
198 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
200 Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
201 if ( xComponent.is() )
202 xComponent->dispose();
204 m_aAccessibleChildren.clear();
207 // -----------------------------------------------------------------------------
208 // XServiceInfo
209 // -----------------------------------------------------------------------------
211 ::rtl::OUString AccessibleTabBar::getImplementationName() throw (RuntimeException)
213 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBar" );
216 // -----------------------------------------------------------------------------
218 sal_Bool AccessibleTabBar::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
220 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
221 const ::rtl::OUString* pNames = aNames.getConstArray();
222 const ::rtl::OUString* pEnd = pNames + aNames.getLength();
223 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
226 return pNames != pEnd;
229 // -----------------------------------------------------------------------------
231 Sequence< ::rtl::OUString > AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException)
233 Sequence< ::rtl::OUString > aNames(1);
234 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBar" );
235 return aNames;
238 // -----------------------------------------------------------------------------
239 // XAccessible
240 // -----------------------------------------------------------------------------
242 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException)
244 OExternalLockGuard aGuard( this );
246 return this;
249 // -----------------------------------------------------------------------------
250 // XAccessibleContext
251 // -----------------------------------------------------------------------------
253 sal_Int32 AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException)
255 OExternalLockGuard aGuard( this );
257 return m_aAccessibleChildren.size();
260 // -----------------------------------------------------------------------------
262 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
264 OExternalLockGuard aGuard( this );
266 if ( i < 0 || i >= getAccessibleChildCount() )
267 throw IndexOutOfBoundsException();
269 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
270 if ( !xChild.is() )
272 if ( m_pTabBar )
274 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
276 if ( i < nCount )
278 Window* pChild = m_pTabBar->GetAccessibleChildWindow( (USHORT)i );
279 if ( pChild )
280 xChild = pChild->GetAccessible();
282 else if ( i == nCount )
284 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
287 // insert into child list
288 m_aAccessibleChildren[i] = xChild;
292 return xChild;
295 // -----------------------------------------------------------------------------
297 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException)
299 OExternalLockGuard aGuard( this );
301 Reference< XAccessible > xParent;
302 if ( m_pTabBar )
304 Window* pParent = m_pTabBar->GetAccessibleParentWindow();
305 if ( pParent )
306 xParent = pParent->GetAccessible();
309 return xParent;
312 // -----------------------------------------------------------------------------
314 sal_Int32 AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException)
316 OExternalLockGuard aGuard( this );
318 sal_Int32 nIndexInParent = -1;
319 if ( m_pTabBar )
321 Window* pParent = m_pTabBar->GetAccessibleParentWindow();
322 if ( pParent )
324 for ( USHORT i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
326 Window* pChild = pParent->GetAccessibleChildWindow( i );
327 if ( pChild == static_cast< Window* >( m_pTabBar ) )
329 nIndexInParent = i;
330 break;
336 return nIndexInParent;
339 // -----------------------------------------------------------------------------
341 sal_Int16 AccessibleTabBar::getAccessibleRole( ) throw (RuntimeException)
343 OExternalLockGuard aGuard( this );
345 return AccessibleRole::PANEL;
348 // -----------------------------------------------------------------------------
350 ::rtl::OUString AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException)
352 OExternalLockGuard aGuard( this );
354 ::rtl::OUString sDescription;
355 if ( m_pTabBar )
356 sDescription = m_pTabBar->GetAccessibleDescription();
358 return sDescription;
361 // -----------------------------------------------------------------------------
363 ::rtl::OUString AccessibleTabBar::getAccessibleName( ) throw (RuntimeException)
365 OExternalLockGuard aGuard( this );
367 ::rtl::OUString sName;
368 if ( m_pTabBar )
369 sName = m_pTabBar->GetAccessibleName();
371 return sName;
374 // -----------------------------------------------------------------------------
376 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( ) throw (RuntimeException)
378 OExternalLockGuard aGuard( this );
380 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
381 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
382 return xSet;
385 // -----------------------------------------------------------------------------
387 Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet( ) throw (RuntimeException)
389 OExternalLockGuard aGuard( this );
391 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
392 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
394 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
396 FillAccessibleStateSet( *pStateSetHelper );
398 else
400 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
403 return xSet;
406 // -----------------------------------------------------------------------------
408 Locale AccessibleTabBar::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
410 OExternalLockGuard aGuard( this );
412 return Application::GetSettings().GetLocale();
415 // -----------------------------------------------------------------------------
416 // XAccessibleComponent
417 // -----------------------------------------------------------------------------
419 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
421 OExternalLockGuard aGuard( this );
423 Reference< XAccessible > xChild;
424 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
426 Reference< XAccessible > xAcc = getAccessibleChild( i );
427 if ( xAcc.is() )
429 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
430 if ( xComp.is() )
432 Rectangle aRect = VCLRectangle( xComp->getBounds() );
433 Point aPos = VCLPoint( rPoint );
434 if ( aRect.IsInside( aPos ) )
436 xChild = xAcc;
437 break;
443 return xChild;
446 // -----------------------------------------------------------------------------
448 void AccessibleTabBar::grabFocus( ) throw (RuntimeException)
450 OExternalLockGuard aGuard( this );
452 if ( m_pTabBar )
453 m_pTabBar->GrabFocus();
456 // -----------------------------------------------------------------------------
458 sal_Int32 AccessibleTabBar::getForeground( ) throw (RuntimeException)
460 OExternalLockGuard aGuard( this );
462 sal_Int32 nColor = 0;
463 if ( m_pTabBar )
465 if ( m_pTabBar->IsControlForeground() )
466 nColor = m_pTabBar->GetControlForeground().GetColor();
467 else
469 Font aFont;
470 if ( m_pTabBar->IsControlFont() )
471 aFont = m_pTabBar->GetControlFont();
472 else
473 aFont = m_pTabBar->GetFont();
474 nColor = aFont.GetColor().GetColor();
478 return nColor;
481 // -----------------------------------------------------------------------------
483 sal_Int32 AccessibleTabBar::getBackground( ) throw (RuntimeException)
485 OExternalLockGuard aGuard( this );
487 sal_Int32 nColor = 0;
488 if ( m_pTabBar )
490 if ( m_pTabBar->IsControlBackground() )
491 nColor = m_pTabBar->GetControlBackground().GetColor();
492 else
493 nColor = m_pTabBar->GetBackground().GetColor().GetColor();
496 return nColor;
499 // -----------------------------------------------------------------------------
500 // XAccessibleExtendedComponent
501 // -----------------------------------------------------------------------------
503 Reference< awt::XFont > AccessibleTabBar::getFont( ) throw (RuntimeException)
505 OExternalLockGuard aGuard( this );
507 Reference< awt::XFont > xFont;
508 if ( m_pTabBar )
510 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
511 if ( xDev.is() )
513 Font aFont;
514 if ( m_pTabBar->IsControlFont() )
515 aFont = m_pTabBar->GetControlFont();
516 else
517 aFont = m_pTabBar->GetFont();
518 VCLXFont* pVCLXFont = new VCLXFont;
519 pVCLXFont->Init( *xDev.get(), aFont );
520 xFont = pVCLXFont;
524 return xFont;
527 // -----------------------------------------------------------------------------
529 ::rtl::OUString AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException)
531 OExternalLockGuard aGuard( this );
533 ::rtl::OUString sText;
534 if ( m_pTabBar )
535 sText = m_pTabBar->GetText();
537 return sText;
540 // -----------------------------------------------------------------------------
542 ::rtl::OUString AccessibleTabBar::getToolTipText( ) throw (RuntimeException)
544 OExternalLockGuard aGuard( this );
546 ::rtl::OUString sText;
547 if ( m_pTabBar )
548 sText = m_pTabBar->GetQuickHelpText();
550 return sText;
553 // -----------------------------------------------------------------------------
555 //.........................................................................
556 } // namespace accessibility
557 //.........................................................................