Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / accessibility / source / extended / accessibletabbar.cxx
blob8e1730bcf5d5da89b8a1166d715e269ca13cce0b
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/accessibletabbar.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <accessibility/extended/accessibletabbarpagelist.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <toolkit/awt/vclxfont.hxx>
31 #include <toolkit/helper/convert.hxx>
33 #include <vector>
36 //.........................................................................
37 namespace accessibility
39 //.........................................................................
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::accessibility;
45 using namespace ::comphelper;
47 // ----------------------------------------------------
48 // class AccessibleTabBar
49 // ----------------------------------------------------
51 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
52 :AccessibleTabBarBase( pTabBar )
54 if ( m_pTabBar )
55 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
58 // -----------------------------------------------------------------------------
60 AccessibleTabBar::~AccessibleTabBar()
64 // -----------------------------------------------------------------------------
66 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
68 Any aOldValue, aNewValue;
70 switch ( rVclWindowEvent.GetId() )
72 case VCLEVENT_WINDOW_ENABLED:
74 aNewValue <<= AccessibleStateType::SENSITIVE;
75 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
76 aNewValue <<= AccessibleStateType::ENABLED;
77 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
79 break;
80 case VCLEVENT_WINDOW_DISABLED:
82 aOldValue <<= AccessibleStateType::ENABLED;
83 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
84 aOldValue <<= AccessibleStateType::SENSITIVE;
85 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
87 break;
88 case VCLEVENT_WINDOW_GETFOCUS:
90 aNewValue <<= AccessibleStateType::FOCUSED;
91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
93 break;
94 case VCLEVENT_WINDOW_LOSEFOCUS:
96 aOldValue <<= AccessibleStateType::FOCUSED;
97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
99 break;
100 case VCLEVENT_WINDOW_SHOW:
102 aNewValue <<= AccessibleStateType::SHOWING;
103 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
105 break;
106 case VCLEVENT_WINDOW_HIDE:
108 aOldValue <<= AccessibleStateType::SHOWING;
109 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
111 break;
112 default:
114 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
116 break;
120 // -----------------------------------------------------------------------------
122 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
124 if ( m_pTabBar )
126 if ( m_pTabBar->IsEnabled() )
128 rStateSet.AddState( AccessibleStateType::ENABLED );
129 rStateSet.AddState( AccessibleStateType::SENSITIVE );
132 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
134 if ( m_pTabBar->HasFocus() )
135 rStateSet.AddState( AccessibleStateType::FOCUSED );
137 rStateSet.AddState( AccessibleStateType::VISIBLE );
139 if ( m_pTabBar->IsVisible() )
140 rStateSet.AddState( AccessibleStateType::SHOWING );
142 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
143 rStateSet.AddState( AccessibleStateType::RESIZABLE );
147 // -----------------------------------------------------------------------------
148 // OCommonAccessibleComponent
149 // -----------------------------------------------------------------------------
151 awt::Rectangle AccessibleTabBar::implGetBounds() throw (RuntimeException)
153 awt::Rectangle aBounds;
154 if ( m_pTabBar )
155 aBounds = AWTRectangle( Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
157 return aBounds;
160 // -----------------------------------------------------------------------------
161 // XInterface
162 // -----------------------------------------------------------------------------
164 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
166 // -----------------------------------------------------------------------------
167 // XTypeProvider
168 // -----------------------------------------------------------------------------
170 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
172 // -----------------------------------------------------------------------------
173 // XComponent
174 // -----------------------------------------------------------------------------
176 void AccessibleTabBar::disposing()
178 AccessibleTabBarBase::disposing();
180 // dispose all children
181 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
183 Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
184 if ( xComponent.is() )
185 xComponent->dispose();
187 m_aAccessibleChildren.clear();
190 // -----------------------------------------------------------------------------
191 // XServiceInfo
192 // -----------------------------------------------------------------------------
194 OUString AccessibleTabBar::getImplementationName() throw (RuntimeException)
196 return OUString( "com.sun.star.comp.svtools.AccessibleTabBar" );
199 // -----------------------------------------------------------------------------
201 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName ) throw (RuntimeException)
203 return cppu::supportsService(this, rServiceName);
206 // -----------------------------------------------------------------------------
208 Sequence< OUString > AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException)
210 Sequence< OUString > aNames(1);
211 aNames[0] = "com.sun.star.awt.AccessibleTabBar";
212 return aNames;
215 // -----------------------------------------------------------------------------
216 // XAccessible
217 // -----------------------------------------------------------------------------
219 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException)
221 OExternalLockGuard aGuard( this );
223 return this;
226 // -----------------------------------------------------------------------------
227 // XAccessibleContext
228 // -----------------------------------------------------------------------------
230 sal_Int32 AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException)
232 OExternalLockGuard aGuard( this );
234 return m_aAccessibleChildren.size();
237 // -----------------------------------------------------------------------------
239 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
241 OExternalLockGuard aGuard( this );
243 if ( i < 0 || i >= getAccessibleChildCount() )
244 throw IndexOutOfBoundsException();
246 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
247 if ( !xChild.is() )
249 if ( m_pTabBar )
251 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
253 if ( i < nCount )
255 Window* pChild = m_pTabBar->GetAccessibleChildWindow( (sal_uInt16)i );
256 if ( pChild )
257 xChild = pChild->GetAccessible();
259 else if ( i == nCount )
261 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
264 // insert into child list
265 m_aAccessibleChildren[i] = xChild;
269 return xChild;
272 // -----------------------------------------------------------------------------
274 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException)
276 OExternalLockGuard aGuard( this );
278 Reference< XAccessible > xParent;
279 if ( m_pTabBar )
281 Window* pParent = m_pTabBar->GetAccessibleParentWindow();
282 if ( pParent )
283 xParent = pParent->GetAccessible();
286 return xParent;
289 // -----------------------------------------------------------------------------
291 sal_Int32 AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException)
293 OExternalLockGuard aGuard( this );
295 sal_Int32 nIndexInParent = -1;
296 if ( m_pTabBar )
298 Window* pParent = m_pTabBar->GetAccessibleParentWindow();
299 if ( pParent )
301 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
303 Window* pChild = pParent->GetAccessibleChildWindow( i );
304 if ( pChild == static_cast< Window* >( m_pTabBar ) )
306 nIndexInParent = i;
307 break;
313 return nIndexInParent;
316 // -----------------------------------------------------------------------------
318 sal_Int16 AccessibleTabBar::getAccessibleRole( ) throw (RuntimeException)
320 OExternalLockGuard aGuard( this );
322 return AccessibleRole::PANEL;
325 // -----------------------------------------------------------------------------
327 OUString AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException)
329 OExternalLockGuard aGuard( this );
331 OUString sDescription;
332 if ( m_pTabBar )
333 sDescription = m_pTabBar->GetAccessibleDescription();
335 return sDescription;
338 // -----------------------------------------------------------------------------
340 OUString AccessibleTabBar::getAccessibleName( ) throw (RuntimeException)
342 OExternalLockGuard aGuard( this );
344 OUString sName;
345 if ( m_pTabBar )
346 sName = m_pTabBar->GetAccessibleName();
348 return sName;
351 // -----------------------------------------------------------------------------
353 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( ) throw (RuntimeException)
355 OExternalLockGuard aGuard( this );
357 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
358 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
359 return xSet;
362 // -----------------------------------------------------------------------------
364 Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet( ) throw (RuntimeException)
366 OExternalLockGuard aGuard( this );
368 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
369 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
371 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
373 FillAccessibleStateSet( *pStateSetHelper );
375 else
377 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
380 return xSet;
383 // -----------------------------------------------------------------------------
385 Locale AccessibleTabBar::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
387 OExternalLockGuard aGuard( this );
389 return Application::GetSettings().GetLanguageTag().getLocale();
392 // -----------------------------------------------------------------------------
393 // XAccessibleComponent
394 // -----------------------------------------------------------------------------
396 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
398 OExternalLockGuard aGuard( this );
400 Reference< XAccessible > xChild;
401 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
403 Reference< XAccessible > xAcc = getAccessibleChild( i );
404 if ( xAcc.is() )
406 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
407 if ( xComp.is() )
409 Rectangle aRect = VCLRectangle( xComp->getBounds() );
410 Point aPos = VCLPoint( rPoint );
411 if ( aRect.IsInside( aPos ) )
413 xChild = xAcc;
414 break;
420 return xChild;
423 // -----------------------------------------------------------------------------
425 void AccessibleTabBar::grabFocus( ) throw (RuntimeException)
427 OExternalLockGuard aGuard( this );
429 if ( m_pTabBar )
430 m_pTabBar->GrabFocus();
433 // -----------------------------------------------------------------------------
435 sal_Int32 AccessibleTabBar::getForeground( ) throw (RuntimeException)
437 OExternalLockGuard aGuard( this );
439 sal_Int32 nColor = 0;
440 if ( m_pTabBar )
442 if ( m_pTabBar->IsControlForeground() )
443 nColor = m_pTabBar->GetControlForeground().GetColor();
444 else
446 Font aFont;
447 if ( m_pTabBar->IsControlFont() )
448 aFont = m_pTabBar->GetControlFont();
449 else
450 aFont = m_pTabBar->GetFont();
451 nColor = aFont.GetColor().GetColor();
455 return nColor;
458 // -----------------------------------------------------------------------------
460 sal_Int32 AccessibleTabBar::getBackground( ) throw (RuntimeException)
462 OExternalLockGuard aGuard( this );
464 sal_Int32 nColor = 0;
465 if ( m_pTabBar )
467 if ( m_pTabBar->IsControlBackground() )
468 nColor = m_pTabBar->GetControlBackground().GetColor();
469 else
470 nColor = m_pTabBar->GetBackground().GetColor().GetColor();
473 return nColor;
476 // -----------------------------------------------------------------------------
477 // XAccessibleExtendedComponent
478 // -----------------------------------------------------------------------------
480 Reference< awt::XFont > AccessibleTabBar::getFont( ) throw (RuntimeException)
482 OExternalLockGuard aGuard( this );
484 Reference< awt::XFont > xFont;
485 if ( m_pTabBar )
487 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
488 if ( xDev.is() )
490 Font aFont;
491 if ( m_pTabBar->IsControlFont() )
492 aFont = m_pTabBar->GetControlFont();
493 else
494 aFont = m_pTabBar->GetFont();
495 VCLXFont* pVCLXFont = new VCLXFont;
496 pVCLXFont->Init( *xDev.get(), aFont );
497 xFont = pVCLXFont;
501 return xFont;
504 // -----------------------------------------------------------------------------
506 OUString AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException)
508 OExternalLockGuard aGuard( this );
510 OUString sText;
511 if ( m_pTabBar )
512 sText = m_pTabBar->GetText();
514 return sText;
517 // -----------------------------------------------------------------------------
519 OUString AccessibleTabBar::getToolTipText( ) throw (RuntimeException)
521 OExternalLockGuard aGuard( this );
523 OUString sText;
524 if ( m_pTabBar )
525 sText = m_pTabBar->GetQuickHelpText();
527 return sText;
530 // -----------------------------------------------------------------------------
532 //.........................................................................
533 } // namespace accessibility
534 //.........................................................................
536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */