lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / accessibletabbarpage.cxx
blob631eb794300d7f8352832446d8a312619ef0099b
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/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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/settings.hxx>
31 #include <toolkit/helper/convert.hxx>
34 namespace accessibility
38 using namespace ::com::sun::star::accessibility;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star;
42 using namespace ::comphelper;
45 // class AccessibleTabBarPage
48 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
49 :AccessibleTabBarBase( pTabBar )
50 ,m_nPageId( nPageId )
51 ,m_xParent( rxParent )
53 m_bShowing = IsShowing();
54 m_bSelected = IsSelected();
56 if ( m_pTabBar )
57 m_sPageText = m_pTabBar->GetPageText( m_nPageId );
61 bool AccessibleTabBarPage::IsEnabled()
63 OExternalLockGuard aGuard( this );
65 bool bEnabled = false;
66 if ( m_pTabBar )
67 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
69 return bEnabled;
73 bool AccessibleTabBarPage::IsShowing()
75 bool bShowing = false;
77 if ( m_pTabBar && m_pTabBar->IsVisible() )
78 bShowing = true;
80 return bShowing;
84 bool AccessibleTabBarPage::IsSelected()
86 bool bSelected = false;
88 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
89 bSelected = true;
91 return bSelected;
95 void AccessibleTabBarPage::SetShowing( bool bShowing )
97 if ( m_bShowing != bShowing )
99 Any aOldValue, aNewValue;
100 if ( m_bShowing )
101 aOldValue <<= AccessibleStateType::SHOWING;
102 else
103 aNewValue <<= AccessibleStateType::SHOWING;
104 m_bShowing = bShowing;
105 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
110 void AccessibleTabBarPage::SetSelected( bool bSelected )
112 if ( m_bSelected != bSelected )
114 Any aOldValue, aNewValue;
115 if ( m_bSelected )
116 aOldValue <<= AccessibleStateType::SELECTED;
117 else
118 aNewValue <<= AccessibleStateType::SELECTED;
119 m_bSelected = bSelected;
120 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
125 void AccessibleTabBarPage::SetPageText( const OUString& sPageText )
127 if ( m_sPageText != sPageText )
129 Any aOldValue, aNewValue;
130 aOldValue <<= m_sPageText;
131 aNewValue <<= sPageText;
132 m_sPageText = sPageText;
133 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
138 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
140 if ( IsEnabled() )
142 rStateSet.AddState( AccessibleStateType::ENABLED );
143 rStateSet.AddState( AccessibleStateType::SENSITIVE );
146 rStateSet.AddState( AccessibleStateType::VISIBLE );
148 if ( IsShowing() )
149 rStateSet.AddState( AccessibleStateType::SHOWING );
151 rStateSet.AddState( AccessibleStateType::SELECTABLE );
153 if ( IsSelected() )
154 rStateSet.AddState( AccessibleStateType::SELECTED );
158 // OCommonAccessibleComponent
161 awt::Rectangle AccessibleTabBarPage::implGetBounds()
163 awt::Rectangle aBounds;
164 if ( m_pTabBar )
166 // get bounding rectangle relative to the AccessibleTabBar
167 aBounds = AWTRectangle( m_pTabBar->GetPageRect( m_nPageId ) );
169 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
170 Reference< XAccessible > xParent = getAccessibleParent();
171 if ( xParent.is() )
173 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
174 if ( xParentComponent.is() )
176 awt::Point aParentLoc = xParentComponent->getLocation();
178 // calculate bounding rectangle relative to the AccessibleTabBarPageList
179 aBounds.X -= aParentLoc.X;
180 aBounds.Y -= aParentLoc.Y;
185 return aBounds;
189 // XInterface
192 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, OAccessibleExtendedComponentHelper, AccessibleTabBarPage_BASE )
195 // XTypeProvider
198 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, OAccessibleExtendedComponentHelper, AccessibleTabBarPage_BASE )
201 // XComponent
204 void AccessibleTabBarPage::disposing()
206 AccessibleTabBarBase::disposing();
207 m_sPageText.clear();
211 // XServiceInfo
214 OUString AccessibleTabBarPage::getImplementationName()
216 return OUString( "com.sun.star.comp.svtools.AccessibleTabBarPage" );
220 sal_Bool AccessibleTabBarPage::supportsService( const OUString& rServiceName )
222 return cppu::supportsService(this, rServiceName);
226 Sequence< OUString > AccessibleTabBarPage::getSupportedServiceNames()
228 return { "com.sun.star.awt.AccessibleTabBarPage" };
232 // XAccessible
235 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( )
237 OExternalLockGuard aGuard( this );
239 return this;
243 // XAccessibleContext
246 sal_Int32 AccessibleTabBarPage::getAccessibleChildCount()
248 return 0;
252 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int32 )
254 OExternalLockGuard aGuard( this );
256 throw IndexOutOfBoundsException();
260 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( )
262 OExternalLockGuard aGuard( this );
264 return m_xParent;
268 sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent( )
270 OExternalLockGuard aGuard( this );
272 sal_Int32 nIndexInParent = -1;
273 if ( m_pTabBar )
274 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
276 return nIndexInParent;
280 sal_Int16 AccessibleTabBarPage::getAccessibleRole( )
282 return AccessibleRole::PAGE_TAB;
286 OUString AccessibleTabBarPage::getAccessibleDescription( )
288 OExternalLockGuard aGuard( this );
290 OUString sDescription;
291 if ( m_pTabBar )
292 sDescription = m_pTabBar->GetHelpText( m_nPageId );
294 return sDescription;
298 OUString AccessibleTabBarPage::getAccessibleName( )
300 OExternalLockGuard aGuard( this );
302 return m_sPageText;
306 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( )
308 OExternalLockGuard aGuard( this );
310 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
311 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
312 return xSet;
316 Reference< XAccessibleStateSet > AccessibleTabBarPage::getAccessibleStateSet( )
318 OExternalLockGuard aGuard( this );
320 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
321 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
323 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
325 FillAccessibleStateSet( *pStateSetHelper );
327 else
329 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
332 return xSet;
336 Locale AccessibleTabBarPage::getLocale( )
338 OExternalLockGuard aGuard( this );
340 return Application::GetSettings().GetLanguageTag().getLocale();
344 // XAccessibleComponent
347 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& )
349 return Reference< XAccessible >();
353 void AccessibleTabBarPage::grabFocus( )
355 // no focus
359 sal_Int32 AccessibleTabBarPage::getForeground( )
361 OExternalLockGuard aGuard( this );
363 sal_Int32 nColor = 0;
364 Reference< XAccessible > xParent = getAccessibleParent();
365 if ( xParent.is() )
367 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
368 if ( xParentComp.is() )
369 nColor = xParentComp->getForeground();
372 return nColor;
376 sal_Int32 AccessibleTabBarPage::getBackground( )
378 OExternalLockGuard aGuard( this );
380 sal_Int32 nColor = 0;
381 Reference< XAccessible > xParent = getAccessibleParent();
382 if ( xParent.is() )
384 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
385 if ( xParentComp.is() )
386 nColor = xParentComp->getBackground();
389 return nColor;
393 // XAccessibleExtendedComponent
396 Reference< awt::XFont > AccessibleTabBarPage::getFont( )
398 OExternalLockGuard aGuard( this );
400 Reference< awt::XFont > xFont;
401 Reference< XAccessible > xParent = getAccessibleParent();
402 if ( xParent.is() )
404 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
405 if ( xParentComp.is() )
406 xFont = xParentComp->getFont();
409 return xFont;
413 OUString AccessibleTabBarPage::getTitledBorderText( )
415 OExternalLockGuard aGuard( this );
417 return m_sPageText;
421 OUString AccessibleTabBarPage::getToolTipText( )
423 return OUString();
427 } // namespace accessibility
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */