LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / accessibility / source / extended / accessibletabbar.cxx
blobe983c1e4747178fbb2d86145b9488a203418a191
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 <extended/accessibletabbar.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <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 <com/sun/star/awt/XDevice.hpp>
27 #include <com/sun/star/awt/XWindowPeer.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/accessiblestatesethelper.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/settings.hxx>
35 #include <toolkit/awt/vclxfont.hxx>
36 #include <toolkit/helper/convert.hxx>
39 namespace accessibility
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::accessibility;
47 using namespace ::comphelper;
52 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
53 :AccessibleTabBarBase( pTabBar )
55 if ( m_pTabBar )
56 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
60 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
62 Any aOldValue, aNewValue;
64 switch ( rVclWindowEvent.GetId() )
66 case VclEventId::WindowEnabled:
68 aNewValue <<= AccessibleStateType::SENSITIVE;
69 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
70 aNewValue <<= AccessibleStateType::ENABLED;
71 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
73 break;
74 case VclEventId::WindowDisabled:
76 aOldValue <<= AccessibleStateType::ENABLED;
77 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
78 aOldValue <<= AccessibleStateType::SENSITIVE;
79 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
81 break;
82 case VclEventId::WindowGetFocus:
84 aNewValue <<= AccessibleStateType::FOCUSED;
85 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
87 break;
88 case VclEventId::WindowLoseFocus:
90 aOldValue <<= AccessibleStateType::FOCUSED;
91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
93 break;
94 case VclEventId::WindowShow:
96 aNewValue <<= AccessibleStateType::SHOWING;
97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
99 break;
100 case VclEventId::WindowHide:
102 aOldValue <<= AccessibleStateType::SHOWING;
103 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
105 break;
106 default:
108 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
110 break;
115 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
117 if ( !m_pTabBar )
118 return;
120 if ( m_pTabBar->IsEnabled() )
122 rStateSet.AddState( AccessibleStateType::ENABLED );
123 rStateSet.AddState( AccessibleStateType::SENSITIVE );
126 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
128 if ( m_pTabBar->HasFocus() )
129 rStateSet.AddState( AccessibleStateType::FOCUSED );
131 rStateSet.AddState( AccessibleStateType::VISIBLE );
133 if ( m_pTabBar->IsVisible() )
134 rStateSet.AddState( AccessibleStateType::SHOWING );
136 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
137 rStateSet.AddState( AccessibleStateType::RESIZABLE );
141 // OCommonAccessibleComponent
144 awt::Rectangle AccessibleTabBar::implGetBounds()
146 awt::Rectangle aBounds;
147 if ( m_pTabBar )
148 aBounds = AWTRectangle( tools::Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
150 return aBounds;
154 // XInterface
157 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, OAccessibleExtendedComponentHelper, AccessibleTabBar_BASE )
160 // XTypeProvider
163 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, OAccessibleExtendedComponentHelper, AccessibleTabBar_BASE )
166 // XComponent
169 void AccessibleTabBar::disposing()
171 AccessibleTabBarBase::disposing();
173 // dispose all children
174 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
176 Reference< XComponent > xComponent( i, UNO_QUERY );
177 if ( xComponent.is() )
178 xComponent->dispose();
180 m_aAccessibleChildren.clear();
184 // XServiceInfo
187 OUString AccessibleTabBar::getImplementationName()
189 return "com.sun.star.comp.svtools.AccessibleTabBar";
193 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName )
195 return cppu::supportsService(this, rServiceName);
199 Sequence< OUString > AccessibleTabBar::getSupportedServiceNames()
201 return { "com.sun.star.awt.AccessibleTabBar" };
205 // XAccessible
208 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( )
210 OExternalLockGuard aGuard( this );
212 return this;
216 // XAccessibleContext
219 sal_Int32 AccessibleTabBar::getAccessibleChildCount()
221 OExternalLockGuard aGuard( this );
223 return m_aAccessibleChildren.size();
227 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i )
229 OExternalLockGuard aGuard( this );
231 if ( i < 0 || i >= static_cast<sal_Int32>(m_aAccessibleChildren.size()) )
232 throw IndexOutOfBoundsException();
234 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
235 if ( !xChild.is() )
237 if ( m_pTabBar )
239 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
241 if ( i < nCount )
243 vcl::Window* pChild = m_pTabBar->GetAccessibleChildWindow( static_cast<sal_uInt16>(i) );
244 if ( pChild )
245 xChild = pChild->GetAccessible();
247 else if ( i == nCount )
249 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
252 // insert into child list
253 m_aAccessibleChildren[i] = xChild;
257 return xChild;
261 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( )
263 OExternalLockGuard aGuard( this );
265 Reference< XAccessible > xParent;
266 if ( m_pTabBar )
268 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
269 if ( pParent )
270 xParent = pParent->GetAccessible();
273 return xParent;
277 sal_Int32 AccessibleTabBar::getAccessibleIndexInParent( )
279 OExternalLockGuard aGuard( this );
281 sal_Int32 nIndexInParent = -1;
282 if ( m_pTabBar )
284 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
285 if ( pParent )
287 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
289 vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
290 if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
292 nIndexInParent = i;
293 break;
299 return nIndexInParent;
303 sal_Int16 AccessibleTabBar::getAccessibleRole( )
305 OExternalLockGuard aGuard( this );
307 return AccessibleRole::PANEL;
311 OUString AccessibleTabBar::getAccessibleDescription( )
313 OExternalLockGuard aGuard( this );
315 OUString sDescription;
316 if ( m_pTabBar )
317 sDescription = m_pTabBar->GetAccessibleDescription();
319 return sDescription;
323 OUString AccessibleTabBar::getAccessibleName( )
325 OExternalLockGuard aGuard( this );
327 OUString sName;
328 if ( m_pTabBar )
329 sName = m_pTabBar->GetAccessibleName();
331 return sName;
335 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( )
337 OExternalLockGuard aGuard( this );
339 return new utl::AccessibleRelationSetHelper;
343 Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet( )
345 OExternalLockGuard aGuard( this );
347 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
349 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
351 FillAccessibleStateSet( *pStateSetHelper );
353 else
355 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
358 return pStateSetHelper;
362 Locale AccessibleTabBar::getLocale( )
364 OExternalLockGuard aGuard( this );
366 return Application::GetSettings().GetLanguageTag().getLocale();
370 // XAccessibleComponent
373 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint )
375 OExternalLockGuard aGuard( this );
377 Reference< XAccessible > xChild;
378 for ( size_t i = 0; i < m_aAccessibleChildren.size(); ++i )
380 Reference< XAccessible > xAcc = getAccessibleChild( i );
381 if ( xAcc.is() )
383 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
384 if ( xComp.is() )
386 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
387 Point aPos = VCLPoint( rPoint );
388 if ( aRect.Contains( aPos ) )
390 xChild = xAcc;
391 break;
397 return xChild;
401 void AccessibleTabBar::grabFocus( )
403 OExternalLockGuard aGuard( this );
405 if ( m_pTabBar )
406 m_pTabBar->GrabFocus();
410 sal_Int32 AccessibleTabBar::getForeground( )
412 OExternalLockGuard aGuard( this );
414 Color nColor;
415 if ( m_pTabBar )
417 if ( m_pTabBar->IsControlForeground() )
418 nColor = m_pTabBar->GetControlForeground();
419 else
421 vcl::Font aFont;
422 if ( m_pTabBar->IsControlFont() )
423 aFont = m_pTabBar->GetControlFont();
424 else
425 aFont = m_pTabBar->GetFont();
426 nColor = aFont.GetColor();
430 return sal_Int32(nColor);
434 sal_Int32 AccessibleTabBar::getBackground( )
436 OExternalLockGuard aGuard( this );
438 Color nColor;
439 if ( m_pTabBar )
441 if ( m_pTabBar->IsControlBackground() )
442 nColor = m_pTabBar->GetControlBackground();
443 else
444 nColor = m_pTabBar->GetBackground().GetColor();
447 return sal_Int32(nColor);
451 // XAccessibleExtendedComponent
454 Reference< awt::XFont > AccessibleTabBar::getFont( )
456 OExternalLockGuard aGuard( this );
458 Reference< awt::XFont > xFont;
459 if ( m_pTabBar )
461 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
462 if ( xDev.is() )
464 vcl::Font aFont;
465 if ( m_pTabBar->IsControlFont() )
466 aFont = m_pTabBar->GetControlFont();
467 else
468 aFont = m_pTabBar->GetFont();
469 rtl::Reference<VCLXFont> pVCLXFont = new VCLXFont;
470 pVCLXFont->Init( *xDev, aFont );
471 xFont = pVCLXFont;
475 return xFont;
479 OUString AccessibleTabBar::getTitledBorderText( )
481 OExternalLockGuard aGuard( this );
483 OUString sText;
484 if ( m_pTabBar )
485 sText = m_pTabBar->GetText();
487 return sText;
491 OUString AccessibleTabBar::getToolTipText( )
493 OExternalLockGuard aGuard( this );
495 OUString sText;
496 if ( m_pTabBar )
497 sText = m_pTabBar->GetQuickHelpText();
499 return sText;
503 } // namespace accessibility
506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */