Fix default value of Emscripten --with-main-module
[LibreOffice.git] / svtools / source / control / accessibletabbarpage.cxx
blob5a15d33b6309c40cf5e5b96f195151237216dd33
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 "accessibletabbarpage.hxx"
22 #include <svtools/tabbar.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/lang/IndexOutOfBoundsException.hpp>
27 #include <comphelper/accessiblecontexthelper.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <unotools/accessiblerelationsethelper.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/unohelp.hxx>
33 #include <i18nlangtag/languagetag.hxx>
36 namespace accessibility
40 using namespace ::com::sun::star::accessibility;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star;
44 using namespace ::comphelper;
49 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
50 :ImplInheritanceHelper( pTabBar )
51 ,m_nPageId( nPageId )
52 ,m_xParent( rxParent )
54 m_bShowing = IsShowing();
55 m_bSelected = IsSelected();
57 if ( m_pTabBar )
58 m_sPageText = m_pTabBar->GetPageText( m_nPageId );
62 bool AccessibleTabBarPage::IsEnabled()
64 OExternalLockGuard aGuard( this );
66 bool bEnabled = false;
67 if ( m_pTabBar )
68 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
70 return bEnabled;
74 bool AccessibleTabBarPage::IsShowing() const
76 bool bShowing = false;
78 if ( m_pTabBar && m_pTabBar->IsVisible() )
79 bShowing = true;
81 return bShowing;
85 bool AccessibleTabBarPage::IsSelected() const
87 bool bSelected = false;
89 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
90 bSelected = true;
92 return bSelected;
96 void AccessibleTabBarPage::SetShowing( bool bShowing )
98 if ( m_bShowing != bShowing )
100 Any aOldValue, aNewValue;
101 if ( m_bShowing )
102 aOldValue <<= AccessibleStateType::SHOWING;
103 else
104 aNewValue <<= AccessibleStateType::SHOWING;
105 m_bShowing = bShowing;
106 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
111 void AccessibleTabBarPage::SetSelected( bool bSelected )
113 if ( m_bSelected != bSelected )
115 Any aOldValue, aNewValue;
116 if ( m_bSelected )
117 aOldValue <<= AccessibleStateType::SELECTED;
118 else
119 aNewValue <<= AccessibleStateType::SELECTED;
120 m_bSelected = bSelected;
121 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
126 void AccessibleTabBarPage::SetPageText( const OUString& sPageText )
128 if ( m_sPageText != sPageText )
130 Any aOldValue, aNewValue;
131 aOldValue <<= m_sPageText;
132 aNewValue <<= sPageText;
133 m_sPageText = sPageText;
134 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
139 void AccessibleTabBarPage::FillAccessibleStateSet( sal_Int64& rStateSet )
141 if ( IsEnabled() )
143 rStateSet |= AccessibleStateType::ENABLED;
144 rStateSet |= AccessibleStateType::SENSITIVE;
147 rStateSet |= AccessibleStateType::VISIBLE;
149 if ( IsShowing() )
150 rStateSet |= AccessibleStateType::SHOWING;
152 rStateSet |= AccessibleStateType::SELECTABLE;
154 if ( IsSelected() )
155 rStateSet |= AccessibleStateType::SELECTED;
159 // OCommonAccessibleComponent
162 awt::Rectangle AccessibleTabBarPage::implGetBounds()
164 awt::Rectangle aBounds;
165 if ( m_pTabBar )
167 // get bounding rectangle relative to the AccessibleTabBar
168 aBounds = vcl::unohelper::ConvertToAWTRect(m_pTabBar->GetPageRect(m_nPageId));
170 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
171 Reference< XAccessible > xParent = getAccessibleParent();
172 if ( xParent.is() )
174 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
175 if ( xParentComponent.is() )
177 awt::Point aParentLoc = xParentComponent->getLocation();
179 // calculate bounding rectangle relative to the AccessibleTabBarPageList
180 aBounds.X -= aParentLoc.X;
181 aBounds.Y -= aParentLoc.Y;
186 return aBounds;
190 // XComponent
193 void AccessibleTabBarPage::disposing()
195 AccessibleTabBarBase::disposing();
196 m_sPageText.clear();
200 // XServiceInfo
203 OUString AccessibleTabBarPage::getImplementationName()
205 return u"com.sun.star.comp.svtools.AccessibleTabBarPage"_ustr;
209 sal_Bool AccessibleTabBarPage::supportsService( const OUString& rServiceName )
211 return cppu::supportsService(this, rServiceName);
215 Sequence< OUString > AccessibleTabBarPage::getSupportedServiceNames()
217 return { u"com.sun.star.awt.AccessibleTabBarPage"_ustr };
221 // XAccessible
224 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( )
226 OExternalLockGuard aGuard( this );
228 return this;
232 // XAccessibleContext
235 sal_Int64 AccessibleTabBarPage::getAccessibleChildCount()
237 return 0;
241 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int64 )
243 OExternalLockGuard aGuard( this );
245 throw IndexOutOfBoundsException();
249 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( )
251 OExternalLockGuard aGuard( this );
253 return m_xParent;
257 sal_Int64 AccessibleTabBarPage::getAccessibleIndexInParent( )
259 OExternalLockGuard aGuard( this );
261 sal_Int64 nIndexInParent = -1;
262 if ( m_pTabBar )
263 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
265 return nIndexInParent;
268 sal_Int16 AccessibleTabBarPage::getAccessibleRole( )
270 return AccessibleRole::PAGE_TAB;
273 OUString AccessibleTabBarPage::getAccessibleDescription( )
275 OExternalLockGuard aGuard( this );
277 if (m_pTabBar)
278 return m_pTabBar->GetHelpText(m_nPageId);
280 return OUString();
283 OUString AccessibleTabBarPage::getAccessibleName( )
285 OExternalLockGuard aGuard( this );
287 return m_sPageText;
290 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( )
292 OExternalLockGuard aGuard( this );
294 return new utl::AccessibleRelationSetHelper;
297 sal_Int64 AccessibleTabBarPage::getAccessibleStateSet( )
299 OExternalLockGuard aGuard( this );
301 sal_Int64 nStateSet = 0;
303 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
305 FillAccessibleStateSet( nStateSet );
307 else
309 nStateSet |= AccessibleStateType::DEFUNC;
312 return nStateSet;
316 Locale AccessibleTabBarPage::getLocale( )
318 OExternalLockGuard aGuard( this );
320 return Application::GetSettings().GetLanguageTag().getLocale();
324 // XAccessibleComponent
327 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& )
329 return Reference< XAccessible >();
333 void AccessibleTabBarPage::grabFocus( )
335 // no focus
339 sal_Int32 AccessibleTabBarPage::getForeground( )
341 OExternalLockGuard aGuard( this );
343 sal_Int32 nColor = 0;
344 Reference< XAccessible > xParent = getAccessibleParent();
345 if ( xParent.is() )
347 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
348 if ( xParentComp.is() )
349 nColor = xParentComp->getForeground();
352 return nColor;
356 sal_Int32 AccessibleTabBarPage::getBackground( )
358 OExternalLockGuard aGuard( this );
360 sal_Int32 nColor = 0;
361 Reference< XAccessible > xParent = getAccessibleParent();
362 if ( xParent.is() )
364 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
365 if ( xParentComp.is() )
366 nColor = xParentComp->getBackground();
369 return nColor;
373 // XAccessibleExtendedComponent
375 OUString AccessibleTabBarPage::getTitledBorderText( )
377 OExternalLockGuard aGuard( this );
379 return m_sPageText;
383 OUString AccessibleTabBarPage::getToolTipText( )
385 return OUString();
389 } // namespace accessibility
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */