tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblestatusbar.cxx
blob862eb0033d469f3a0cd99f8109c5b847dc3c37e1
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 <standard/vclxaccessiblestatusbar.hxx>
21 #include <standard/vclxaccessiblestatusbaritem.hxx>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include <comphelper/accessiblecontexthelper.hxx>
25 #include <o3tl/safeint.hxx>
26 #include <vcl/status.hxx>
27 #include <vcl/unohelp.hxx>
28 #include <vcl/vclevent.hxx>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::accessibility;
35 using namespace ::comphelper;
40 VCLXAccessibleStatusBar::VCLXAccessibleStatusBar(vcl::Window* pWindow)
41 : VCLXAccessibleComponent(pWindow)
43 m_pStatusBar = GetAs<StatusBar>();
45 if ( m_pStatusBar )
46 m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), rtl::Reference< VCLXAccessibleStatusBarItem >() );
50 void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, bool bShowing )
52 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
54 rtl::Reference< VCLXAccessibleStatusBarItem > pVCLXAccessibleStatusBarItem( m_aAccessibleChildren[i] );
55 if ( pVCLXAccessibleStatusBarItem )
56 pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
61 void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
63 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
64 return;
66 rtl::Reference< VCLXAccessibleStatusBarItem > pVCLXAccessibleStatusBarItem( m_aAccessibleChildren[i] );
67 if ( pVCLXAccessibleStatusBarItem.is() )
69 OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
70 pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
75 void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
77 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
78 return;
80 rtl::Reference< VCLXAccessibleStatusBarItem > pVCLXAccessibleStatusBarItem( m_aAccessibleChildren[i] );
81 if ( pVCLXAccessibleStatusBarItem.is() )
83 OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
84 pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
89 void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
91 if ( i < 0 || o3tl::make_unsigned(i) > m_aAccessibleChildren.size() )
92 return;
94 // insert entry in child list
95 m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, rtl::Reference< VCLXAccessibleStatusBarItem >() );
97 // send accessible child event
98 Reference< XAccessible > xChild( getAccessibleChild( i ) );
99 if ( xChild.is() )
101 Any aOldValue, aNewValue;
102 aNewValue <<= xChild;
103 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
108 void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
110 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
111 return;
113 // get the accessible of the removed page
114 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
116 // remove entry in child list
117 m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
119 // send accessible child event
120 if ( xChild.is() )
122 Any aOldValue, aNewValue;
123 aOldValue <<= xChild;
124 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
126 Reference< XComponent > xComponent( xChild, UNO_QUERY );
127 if ( xComponent.is() )
128 xComponent->dispose();
133 void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
135 switch ( rVclWindowEvent.GetId() )
137 case VclEventId::StatusbarItemAdded:
139 if ( m_pStatusBar )
141 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
142 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
143 InsertChild( nItemPos );
146 break;
147 case VclEventId::StatusbarItemRemoved:
149 if ( m_pStatusBar )
151 OExternalLockGuard aGuard( this );
153 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
154 for ( sal_Int64 i = 0, nCount = m_aAccessibleChildren.size(); i < nCount; ++i )
156 sal_uInt16 nChildItemId = m_pStatusBar->GetItemId( static_cast<sal_uInt16>(i) );
157 if ( nChildItemId == nItemId )
159 RemoveChild( i );
160 break;
165 break;
166 case VclEventId::StatusbarAllItemsRemoved:
168 for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
169 RemoveChild( i );
171 break;
172 case VclEventId::StatusbarShowItem:
173 case VclEventId::StatusbarHideItem:
175 if ( m_pStatusBar )
177 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
178 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
179 UpdateShowing( nItemPos, rVclWindowEvent.GetId() == VclEventId::StatusbarShowItem );
182 break;
183 case VclEventId::StatusbarNameChanged:
185 if ( m_pStatusBar )
187 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
188 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
189 UpdateItemName( nItemPos );
192 break;
193 case VclEventId::StatusbarDrawItem:
195 if ( m_pStatusBar )
197 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
198 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
199 UpdateItemText( nItemPos );
202 break;
203 case VclEventId::ObjectDying:
205 if ( m_pStatusBar )
207 m_pStatusBar = nullptr;
209 // dispose all children
210 for (const rtl::Reference<VCLXAccessibleStatusBarItem>& xComponent : m_aAccessibleChildren)
212 if ( xComponent.is() )
213 xComponent->dispose();
215 m_aAccessibleChildren.clear();
218 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
220 break;
221 default:
222 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
227 // XComponent
230 void VCLXAccessibleStatusBar::disposing()
232 VCLXAccessibleComponent::disposing();
234 if ( !m_pStatusBar )
235 return;
237 m_pStatusBar = nullptr;
239 // dispose all children
240 for (const rtl::Reference<VCLXAccessibleStatusBarItem>& xComponent : m_aAccessibleChildren)
242 if ( xComponent.is() )
243 xComponent->dispose();
245 m_aAccessibleChildren.clear();
249 // XServiceInfo
252 OUString VCLXAccessibleStatusBar::getImplementationName()
254 return u"com.sun.star.comp.toolkit.AccessibleStatusBar"_ustr;
258 Sequence< OUString > VCLXAccessibleStatusBar::getSupportedServiceNames()
260 return { u"com.sun.star.awt.AccessibleStatusBar"_ustr };
264 // XAccessibleContext
267 sal_Int64 VCLXAccessibleStatusBar::getAccessibleChildCount()
269 OExternalLockGuard aGuard( this );
271 return m_aAccessibleChildren.size();
275 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int64 i )
277 OExternalLockGuard aGuard( this );
279 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
280 throw IndexOutOfBoundsException();
282 rtl::Reference< VCLXAccessibleStatusBarItem > xChild = m_aAccessibleChildren[i];
283 if ( !xChild.is() )
285 if ( m_pStatusBar )
287 sal_uInt16 nItemId = m_pStatusBar->GetItemId( static_cast<sal_uInt16>(i) );
289 xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
291 // insert into status bar item list
292 m_aAccessibleChildren[i] = xChild;
296 return xChild;
300 // XAccessibleComponent
303 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint )
305 OExternalLockGuard aGuard( this );
307 Reference< XAccessible > xChild;
308 if ( m_pStatusBar )
310 sal_uInt16 nItemId = m_pStatusBar->GetItemId(vcl::unohelper::ConvertToVCLPoint(rPoint));
311 sal_Int32 nItemPos = m_pStatusBar->GetItemPos( nItemId );
312 if ( nItemPos >= 0 && o3tl::make_unsigned(nItemPos) < m_aAccessibleChildren.size() )
313 xChild = getAccessibleChild( nItemPos );
316 return xChild;
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */