build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / basctl / source / accessibility / accessibledialogcontrolshape.cxx
blobade2d1b2960df4088432e1c8428385b40a3f51bc
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/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <unotools/accessiblestatesethelper.hxx>
30 #include <unotools/accessiblerelationsethelper.hxx>
31 #include <toolkit/awt/vclxfont.hxx>
32 #include <toolkit/helper/externallock.hxx>
33 #include <toolkit/helper/convert.hxx>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/settings.hxx>
38 namespace basctl
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::accessibility;
46 using namespace ::comphelper;
49 // class AccessibleDialogControlShape
52 AccessibleDialogControlShape::AccessibleDialogControlShape (DialogWindow* pDialogWindow, DlgEdObj* pDlgEdObj)
53 :OAccessibleExtendedComponentHelper( new VCLExternalSolarLock() )
54 ,m_pDialogWindow( pDialogWindow )
55 ,m_pDlgEdObj( pDlgEdObj )
57 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() );
59 if ( m_pDlgEdObj )
60 m_xControlModel.set( m_pDlgEdObj->GetUnoControlModel(), UNO_QUERY );
62 if ( m_xControlModel.is() )
63 m_xControlModel->addPropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
65 m_bFocused = IsFocused();
66 m_bSelected = IsSelected();
67 m_aBounds = GetBounds();
71 AccessibleDialogControlShape::~AccessibleDialogControlShape()
73 if ( m_xControlModel.is() )
74 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
76 delete m_pExternalLock;
77 m_pExternalLock = nullptr;
81 bool AccessibleDialogControlShape::IsFocused()
83 bool bFocused = false;
84 if ( m_pDialogWindow )
86 SdrView& rView = m_pDialogWindow->GetView();
87 if (rView.IsObjMarked(m_pDlgEdObj) && rView.GetMarkedObjectList().GetMarkCount() == 1)
88 bFocused = true;
91 return bFocused;
95 bool AccessibleDialogControlShape::IsSelected()
97 if ( m_pDialogWindow )
98 return m_pDialogWindow->GetView().IsObjMarked(m_pDlgEdObj);
99 return false;
103 void AccessibleDialogControlShape::SetFocused( bool bFocused )
105 if ( m_bFocused != bFocused )
107 Any aOldValue, aNewValue;
108 if ( m_bFocused )
109 aOldValue <<= AccessibleStateType::FOCUSED;
110 else
111 aNewValue <<= AccessibleStateType::FOCUSED;
112 m_bFocused = bFocused;
113 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
118 void AccessibleDialogControlShape::SetSelected( bool bSelected )
120 if ( m_bSelected != bSelected )
122 Any aOldValue, aNewValue;
123 if ( m_bSelected )
124 aOldValue <<= AccessibleStateType::SELECTED;
125 else
126 aNewValue <<= AccessibleStateType::SELECTED;
127 m_bSelected = bSelected;
128 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
133 awt::Rectangle AccessibleDialogControlShape::GetBounds()
135 awt::Rectangle aBounds( 0, 0, 0, 0 );
136 if ( m_pDlgEdObj )
138 // get the bounding box of the shape in logic units
139 Rectangle aRect = m_pDlgEdObj->GetSnapRect();
141 if ( m_pDialogWindow )
143 // transform coordinates relative to the parent
144 MapMode aMap = m_pDialogWindow->GetMapMode();
145 Point aOrg = aMap.GetOrigin();
146 aRect.Move( aOrg.X(), aOrg.Y() );
148 // convert logic units to pixel
149 aRect = m_pDialogWindow->LogicToPixel( aRect, MapMode(MapUnit::Map100thMM) );
151 // clip the shape's bounding box with the bounding box of its parent
152 Rectangle aParentRect( Point( 0, 0 ), m_pDialogWindow->GetSizePixel() );
153 aRect = aRect.GetIntersection( aParentRect );
154 aBounds = AWTRectangle( aRect );
158 return aBounds;
162 void AccessibleDialogControlShape::SetBounds( const awt::Rectangle& aBounds )
164 if ( m_aBounds.X != aBounds.X || m_aBounds.Y != aBounds.Y || m_aBounds.Width != aBounds.Width || m_aBounds.Height != aBounds.Height )
166 m_aBounds = aBounds;
167 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
172 vcl::Window* AccessibleDialogControlShape::GetWindow() const
174 vcl::Window* pWindow = nullptr;
175 if ( m_pDlgEdObj )
177 Reference< awt::XControl > xControl( m_pDlgEdObj->GetControl(), UNO_QUERY );
178 if ( xControl.is() )
179 pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() ).get();
182 return pWindow;
186 OUString AccessibleDialogControlShape::GetModelStringProperty( const sal_Char* pPropertyName )
188 OUString sReturn;
192 if ( m_xControlModel.is() )
194 OUString sPropertyName( OUString::createFromAscii( pPropertyName ) );
195 Reference< XPropertySetInfo > xInfo = m_xControlModel->getPropertySetInfo();
196 if ( xInfo.is() && xInfo->hasPropertyByName( sPropertyName ) )
197 m_xControlModel->getPropertyValue( sPropertyName ) >>= sReturn;
200 catch ( const Exception& )
202 OSL_FAIL( "AccessibleDialogControlShape::GetModelStringProperty: caught an exception!" );
205 return sReturn;
209 void AccessibleDialogControlShape::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
211 rStateSet.AddState( AccessibleStateType::ENABLED );
213 rStateSet.AddState( AccessibleStateType::VISIBLE );
215 rStateSet.AddState( AccessibleStateType::SHOWING );
217 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
219 if ( IsFocused() )
220 rStateSet.AddState( AccessibleStateType::FOCUSED );
222 rStateSet.AddState( AccessibleStateType::SELECTABLE );
224 if ( IsSelected() )
225 rStateSet.AddState( AccessibleStateType::SELECTED );
227 rStateSet.AddState( AccessibleStateType::RESIZABLE );
230 // OCommonAccessibleComponent
231 awt::Rectangle AccessibleDialogControlShape::implGetBounds() throw (RuntimeException, std::exception)
233 return GetBounds();
236 // XInterface
237 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape, OAccessibleExtendedComponentHelper, AccessibleDialogControlShape_BASE )
239 // XTypeProvider
240 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape, OAccessibleExtendedComponentHelper, AccessibleDialogControlShape_BASE )
242 // XComponent
243 void AccessibleDialogControlShape::disposing()
245 OAccessibleExtendedComponentHelper::disposing();
247 m_pDialogWindow = nullptr;
248 m_pDlgEdObj = nullptr;
250 if ( m_xControlModel.is() )
251 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
252 m_xControlModel.clear();
256 // XEventListener
259 void AccessibleDialogControlShape::disposing( const lang::EventObject& ) throw (RuntimeException, std::exception)
261 if ( m_xControlModel.is() )
262 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
263 m_xControlModel.clear();
267 // XPropertyChangeListener
270 void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent& rEvent ) throw (RuntimeException, std::exception)
272 if ( rEvent.PropertyName == DLGED_PROP_NAME )
274 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, rEvent.OldValue, rEvent.NewValue );
276 else if ( rEvent.PropertyName == DLGED_PROP_POSITIONX ||
277 rEvent.PropertyName == DLGED_PROP_POSITIONY ||
278 rEvent.PropertyName == DLGED_PROP_WIDTH ||
279 rEvent.PropertyName == DLGED_PROP_HEIGHT )
281 SetBounds( GetBounds() );
283 else if ( rEvent.PropertyName == DLGED_PROP_BACKGROUNDCOLOR ||
284 rEvent.PropertyName == DLGED_PROP_TEXTCOLOR ||
285 rEvent.PropertyName == DLGED_PROP_TEXTLINECOLOR )
287 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any() );
291 // XServiceInfo
292 OUString AccessibleDialogControlShape::getImplementationName() throw (RuntimeException, std::exception)
294 return OUString( "com.sun.star.comp.basctl.AccessibleShape" );
297 sal_Bool AccessibleDialogControlShape::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
299 return cppu::supportsService(this, rServiceName);
302 Sequence< OUString > AccessibleDialogControlShape::getSupportedServiceNames() throw (RuntimeException, std::exception)
304 return { "com.sun.star.drawing.AccessibleShape" };
307 // XAccessible
308 Reference< XAccessibleContext > AccessibleDialogControlShape::getAccessibleContext( ) throw (RuntimeException, std::exception)
310 OExternalLockGuard aGuard( this );
312 return this;
315 // XAccessibleContext
316 sal_Int32 AccessibleDialogControlShape::getAccessibleChildCount() throw (RuntimeException, std::exception)
318 OExternalLockGuard aGuard( this );
320 return 0;
324 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
326 OExternalLockGuard aGuard( this );
328 if ( i < 0 || i >= getAccessibleChildCount() )
329 throw IndexOutOfBoundsException();
331 return Reference< XAccessible >();
335 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleParent( ) throw (RuntimeException, std::exception)
337 OExternalLockGuard aGuard( this );
339 Reference< XAccessible > xParent;
340 if ( m_pDialogWindow )
341 xParent = m_pDialogWindow->GetAccessible();
343 return xParent;
347 sal_Int32 AccessibleDialogControlShape::getAccessibleIndexInParent( ) throw (RuntimeException, std::exception)
349 OExternalLockGuard aGuard( this );
351 sal_Int32 nIndexInParent = -1;
352 Reference< XAccessible > xParent( getAccessibleParent() );
353 if ( xParent.is() )
355 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
356 if ( xParentContext.is() )
358 for ( sal_Int32 i = 0, nCount = xParentContext->getAccessibleChildCount(); i < nCount; ++i )
360 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
361 if ( xChild.is() )
363 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
364 if ( xChildContext == static_cast<XAccessibleContext*>(this) )
366 nIndexInParent = i;
367 break;
374 return nIndexInParent;
378 sal_Int16 AccessibleDialogControlShape::getAccessibleRole( ) throw (RuntimeException, std::exception)
380 OExternalLockGuard aGuard( this );
382 return AccessibleRole::SHAPE;
386 OUString AccessibleDialogControlShape::getAccessibleDescription( ) throw (RuntimeException, std::exception)
388 OExternalLockGuard aGuard( this );
390 return GetModelStringProperty( "HelpText" );
394 OUString AccessibleDialogControlShape::getAccessibleName( ) throw (RuntimeException, std::exception)
396 OExternalLockGuard aGuard( this );
398 return GetModelStringProperty( "Name" );
402 Reference< XAccessibleRelationSet > AccessibleDialogControlShape::getAccessibleRelationSet( ) throw (RuntimeException, std::exception)
404 OExternalLockGuard aGuard( this );
406 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
407 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
408 return xSet;
412 Reference< XAccessibleStateSet > AccessibleDialogControlShape::getAccessibleStateSet( ) throw (RuntimeException, std::exception)
414 OExternalLockGuard aGuard( this );
416 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
417 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
419 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
421 FillAccessibleStateSet( *pStateSetHelper );
423 else
425 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
428 return xSet;
432 Locale AccessibleDialogControlShape::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
434 OExternalLockGuard aGuard( this );
436 return Application::GetSettings().GetLanguageTag().getLocale();
440 // XAccessibleComponent
443 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException, std::exception)
445 OExternalLockGuard aGuard( this );
447 return Reference< XAccessible >();
451 void AccessibleDialogControlShape::grabFocus( ) throw (RuntimeException, std::exception)
453 // no focus for shapes
457 sal_Int32 AccessibleDialogControlShape::getForeground( ) throw (RuntimeException, std::exception)
459 OExternalLockGuard aGuard( this );
461 sal_Int32 nColor = 0;
462 vcl::Window* pWindow = GetWindow();
463 if ( pWindow )
465 if ( pWindow->IsControlForeground() )
466 nColor = pWindow->GetControlForeground().GetColor();
467 else
469 vcl::Font aFont;
470 if ( pWindow->IsControlFont() )
471 aFont = pWindow->GetControlFont();
472 else
473 aFont = pWindow->GetFont();
474 nColor = aFont.GetColor().GetColor();
478 return nColor;
482 sal_Int32 AccessibleDialogControlShape::getBackground( ) throw (RuntimeException, std::exception)
484 OExternalLockGuard aGuard( this );
486 sal_Int32 nColor = 0;
487 vcl::Window* pWindow = GetWindow();
488 if ( pWindow )
490 if ( pWindow->IsControlBackground() )
491 nColor = pWindow->GetControlBackground().GetColor();
492 else
493 nColor = pWindow->GetBackground().GetColor().GetColor();
496 return nColor;
500 // XAccessibleExtendedComponent
503 Reference< awt::XFont > AccessibleDialogControlShape::getFont( ) throw (RuntimeException, std::exception)
505 OExternalLockGuard aGuard( this );
507 Reference< awt::XFont > xFont;
508 vcl::Window* pWindow = GetWindow();
509 if ( pWindow )
511 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
512 if ( xDev.is() )
514 vcl::Font aFont;
515 if ( pWindow->IsControlFont() )
516 aFont = pWindow->GetControlFont();
517 else
518 aFont = pWindow->GetFont();
519 VCLXFont* pVCLXFont = new VCLXFont;
520 pVCLXFont->Init( *xDev.get(), aFont );
521 xFont = pVCLXFont;
525 return xFont;
529 OUString AccessibleDialogControlShape::getTitledBorderText( ) throw (RuntimeException, std::exception)
531 OExternalLockGuard aGuard( this );
533 return OUString();
537 OUString AccessibleDialogControlShape::getToolTipText( ) throw (RuntimeException, std::exception)
539 OExternalLockGuard aGuard( this );
541 OUString sText;
542 vcl::Window* pWindow = GetWindow();
543 if ( pWindow )
544 sText = pWindow->GetQuickHelpText();
546 return sText;
550 } // namespace basctl
552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */