tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / basctl / source / accessibility / accessibledialogcontrolshape.cxx
blobce65b97f819dae524f310664f729e3226a73b0d5
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 <accessibledialogcontrolshape.hxx>
21 #include <baside3.hxx>
22 #include <dlgeddef.hxx>
23 #include <dlgedview.hxx>
24 #include <dlgedobj.hxx>
25 #include <com/sun/star/awt/XVclWindowPeer.hpp>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <toolkit/awt/vclxfont.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <comphelper/accessiblecontexthelper.hxx>
35 #include <comphelper/diagnose_ex.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/unohelp.hxx>
39 #include <i18nlangtag/languagetag.hxx>
41 namespace basctl
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::accessibility;
49 using namespace ::comphelper;
54 AccessibleDialogControlShape::AccessibleDialogControlShape (DialogWindow* pDialogWindow, DlgEdObj* pDlgEdObj)
55 :m_pDialogWindow( pDialogWindow )
56 ,m_pDlgEdObj( pDlgEdObj )
58 if ( m_pDlgEdObj )
59 m_xControlModel.set( m_pDlgEdObj->GetUnoControlModel(), UNO_QUERY );
61 if ( m_xControlModel.is() )
62 m_xControlModel->addPropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
64 m_bFocused = IsFocused();
65 m_bSelected = IsSelected();
66 m_aBounds = GetBounds();
70 AccessibleDialogControlShape::~AccessibleDialogControlShape()
72 if ( m_xControlModel.is() )
73 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
77 bool AccessibleDialogControlShape::IsFocused() const
79 bool bFocused = false;
80 if ( m_pDialogWindow )
82 SdrView& rView = m_pDialogWindow->GetView();
83 if (rView.IsObjMarked(m_pDlgEdObj) && rView.GetMarkedObjectList().GetMarkCount() == 1)
84 bFocused = true;
87 return bFocused;
91 bool AccessibleDialogControlShape::IsSelected() const
93 if ( m_pDialogWindow )
94 return m_pDialogWindow->GetView().IsObjMarked(m_pDlgEdObj);
95 return false;
99 void AccessibleDialogControlShape::SetFocused( bool bFocused )
101 if ( m_bFocused != bFocused )
103 Any aOldValue, aNewValue;
104 if ( m_bFocused )
105 aOldValue <<= AccessibleStateType::FOCUSED;
106 else
107 aNewValue <<= AccessibleStateType::FOCUSED;
108 m_bFocused = bFocused;
109 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
114 void AccessibleDialogControlShape::SetSelected( bool bSelected )
116 if ( m_bSelected != bSelected )
118 Any aOldValue, aNewValue;
119 if ( m_bSelected )
120 aOldValue <<= AccessibleStateType::SELECTED;
121 else
122 aNewValue <<= AccessibleStateType::SELECTED;
123 m_bSelected = bSelected;
124 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
129 awt::Rectangle AccessibleDialogControlShape::GetBounds() const
131 awt::Rectangle aBounds( 0, 0, 0, 0 );
132 if ( m_pDlgEdObj )
134 // get the bounding box of the shape in logic units
135 tools::Rectangle aRect = m_pDlgEdObj->GetSnapRect();
137 if ( m_pDialogWindow )
139 // transform coordinates relative to the parent
140 MapMode aMap = m_pDialogWindow->GetMapMode();
141 Point aOrg = aMap.GetOrigin();
142 aRect.Move( aOrg.X(), aOrg.Y() );
144 // convert logic units to pixel
145 aRect = m_pDialogWindow->LogicToPixel( aRect, MapMode(MapUnit::Map100thMM) );
147 // clip the shape's bounding box with the bounding box of its parent
148 tools::Rectangle aParentRect( Point( 0, 0 ), m_pDialogWindow->GetSizePixel() );
149 aRect = aRect.GetIntersection( aParentRect );
150 aBounds = vcl::unohelper::ConvertToAWTRect(aRect);
154 return aBounds;
158 void AccessibleDialogControlShape::SetBounds( const awt::Rectangle& aBounds )
160 if ( m_aBounds.X != aBounds.X || m_aBounds.Y != aBounds.Y || m_aBounds.Width != aBounds.Width || m_aBounds.Height != aBounds.Height )
162 m_aBounds = aBounds;
163 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
168 vcl::Window* AccessibleDialogControlShape::GetWindow() const
170 vcl::Window* pWindow = nullptr;
171 if ( m_pDlgEdObj )
173 Reference< awt::XControl > xControl = m_pDlgEdObj->GetControl();
174 if ( xControl.is() )
175 pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
178 return pWindow;
182 OUString AccessibleDialogControlShape::GetModelStringProperty( OUString const & pPropertyName )
184 OUString sReturn;
188 if ( m_xControlModel.is() )
190 Reference< XPropertySetInfo > xInfo = m_xControlModel->getPropertySetInfo();
191 if ( xInfo.is() && xInfo->hasPropertyByName( pPropertyName ) )
192 m_xControlModel->getPropertyValue( pPropertyName ) >>= sReturn;
195 catch ( const Exception& )
197 TOOLS_WARN_EXCEPTION( "basctl", "AccessibleDialogControlShape::GetModelStringProperty" );
200 return sReturn;
204 void AccessibleDialogControlShape::FillAccessibleStateSet( sal_Int64& rStateSet )
206 rStateSet |= AccessibleStateType::ENABLED;
208 rStateSet |= AccessibleStateType::VISIBLE;
210 rStateSet |= AccessibleStateType::SHOWING;
212 rStateSet |= AccessibleStateType::FOCUSABLE;
214 if ( IsFocused() )
215 rStateSet |= AccessibleStateType::FOCUSED;
217 rStateSet |= AccessibleStateType::SELECTABLE;
219 if ( IsSelected() )
220 rStateSet |= AccessibleStateType::SELECTED;
222 rStateSet |= AccessibleStateType::RESIZABLE;
225 // OCommonAccessibleComponent
226 awt::Rectangle AccessibleDialogControlShape::implGetBounds()
228 return GetBounds();
231 // XComponent
232 void AccessibleDialogControlShape::disposing()
234 OAccessibleExtendedComponentHelper::disposing();
236 m_pDialogWindow = nullptr;
237 m_pDlgEdObj = nullptr;
239 if ( m_xControlModel.is() )
240 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
241 m_xControlModel.clear();
245 // XEventListener
248 void AccessibleDialogControlShape::disposing( const lang::EventObject& )
250 if ( m_xControlModel.is() )
251 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
252 m_xControlModel.clear();
256 // XPropertyChangeListener
259 void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent& rEvent )
261 if ( rEvent.PropertyName == DLGED_PROP_NAME )
263 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, rEvent.OldValue, rEvent.NewValue );
265 else if ( rEvent.PropertyName == DLGED_PROP_POSITIONX ||
266 rEvent.PropertyName == DLGED_PROP_POSITIONY ||
267 rEvent.PropertyName == DLGED_PROP_WIDTH ||
268 rEvent.PropertyName == DLGED_PROP_HEIGHT )
270 SetBounds( GetBounds() );
272 else if ( rEvent.PropertyName == DLGED_PROP_BACKGROUNDCOLOR ||
273 rEvent.PropertyName == DLGED_PROP_TEXTCOLOR ||
274 rEvent.PropertyName == DLGED_PROP_TEXTLINECOLOR )
276 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any() );
280 // XServiceInfo
281 OUString AccessibleDialogControlShape::getImplementationName()
283 return u"com.sun.star.comp.basctl.AccessibleShape"_ustr;
286 sal_Bool AccessibleDialogControlShape::supportsService( const OUString& rServiceName )
288 return cppu::supportsService(this, rServiceName);
291 Sequence< OUString > AccessibleDialogControlShape::getSupportedServiceNames()
293 return { u"com.sun.star.drawing.AccessibleShape"_ustr };
296 // XAccessible
297 Reference< XAccessibleContext > AccessibleDialogControlShape::getAccessibleContext( )
299 return this;
302 // XAccessibleContext
303 sal_Int64 AccessibleDialogControlShape::getAccessibleChildCount()
305 return 0;
309 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleChild( sal_Int64 i )
311 OExternalLockGuard aGuard( this );
313 if ( i < 0 || i >= getAccessibleChildCount() )
314 throw IndexOutOfBoundsException();
316 return Reference< XAccessible >();
320 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleParent( )
322 OExternalLockGuard aGuard( this );
324 Reference< XAccessible > xParent;
325 if ( m_pDialogWindow )
326 xParent = m_pDialogWindow->GetAccessible();
328 return xParent;
332 sal_Int64 AccessibleDialogControlShape::getAccessibleIndexInParent( )
334 OExternalLockGuard aGuard( this );
336 sal_Int64 nIndexInParent = -1;
337 Reference< XAccessible > xParent( getAccessibleParent() );
338 if ( xParent.is() )
340 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
341 if ( xParentContext.is() )
343 for ( sal_Int64 i = 0, nCount = xParentContext->getAccessibleChildCount(); i < nCount; ++i )
345 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
346 if ( xChild.is() )
348 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
349 if ( xChildContext == static_cast<XAccessibleContext*>(this) )
351 nIndexInParent = i;
352 break;
359 return nIndexInParent;
363 sal_Int16 AccessibleDialogControlShape::getAccessibleRole( )
365 OExternalLockGuard aGuard( this );
367 return AccessibleRole::SHAPE;
371 OUString AccessibleDialogControlShape::getAccessibleDescription( )
373 OExternalLockGuard aGuard( this );
375 return GetModelStringProperty( u"HelpText"_ustr );
379 OUString AccessibleDialogControlShape::getAccessibleName( )
381 OExternalLockGuard aGuard( this );
383 return GetModelStringProperty( u"Name"_ustr );
387 Reference< XAccessibleRelationSet > AccessibleDialogControlShape::getAccessibleRelationSet( )
389 OExternalLockGuard aGuard( this );
391 return new utl::AccessibleRelationSetHelper;
395 sal_Int64 AccessibleDialogControlShape::getAccessibleStateSet( )
397 OExternalLockGuard aGuard( this );
399 sal_Int64 nStateSet = 0;
401 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
403 FillAccessibleStateSet( nStateSet );
405 else
407 nStateSet |= AccessibleStateType::DEFUNC;
410 return nStateSet;
414 Locale AccessibleDialogControlShape::getLocale( )
416 OExternalLockGuard aGuard( this );
418 return Application::GetSettings().GetLanguageTag().getLocale();
422 // XAccessibleComponent
425 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point& )
427 OExternalLockGuard aGuard( this );
429 return Reference< XAccessible >();
433 void AccessibleDialogControlShape::grabFocus( )
435 // no focus for shapes
439 sal_Int32 AccessibleDialogControlShape::getForeground( )
441 OExternalLockGuard aGuard( this );
443 Color nColor;
444 vcl::Window* pWindow = GetWindow();
445 if ( pWindow )
447 if ( pWindow->IsControlForeground() )
448 nColor = pWindow->GetControlForeground();
449 else
451 vcl::Font aFont;
452 if ( pWindow->IsControlFont() )
453 aFont = pWindow->GetControlFont();
454 else
455 aFont = pWindow->GetFont();
456 nColor = aFont.GetColor();
460 return sal_Int32(nColor);
464 sal_Int32 AccessibleDialogControlShape::getBackground( )
466 OExternalLockGuard aGuard( this );
468 Color nColor;
469 vcl::Window* pWindow = GetWindow();
470 if ( pWindow )
472 if ( pWindow->IsControlBackground() )
473 nColor = pWindow->GetControlBackground();
474 else
475 nColor = pWindow->GetBackground().GetColor();
478 return sal_Int32(nColor);
482 // XAccessibleExtendedComponent
484 OUString AccessibleDialogControlShape::getTitledBorderText( )
486 OExternalLockGuard aGuard( this );
488 return OUString();
492 OUString AccessibleDialogControlShape::getToolTipText( )
494 OExternalLockGuard aGuard( this );
496 OUString sText;
497 vcl::Window* pWindow = GetWindow();
498 if ( pWindow )
499 sText = pWindow->GetQuickHelpText();
501 return sText;
505 } // namespace basctl
507 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */