bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / accessibility / accessibledialogcontrolshape.cxx
blob34545917f35a93fa5b0a21260912d361730ab0ef
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;
50 // class AccessibleDialogControlShape
53 AccessibleDialogControlShape::AccessibleDialogControlShape (DialogWindow* pDialogWindow, DlgEdObj* pDlgEdObj)
54 :AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() )
55 ,m_pDialogWindow( pDialogWindow )
56 ,m_pDlgEdObj( pDlgEdObj )
58 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() );
60 if ( m_pDlgEdObj )
61 m_xControlModel = Reference< XPropertySet >( m_pDlgEdObj->GetUnoControlModel(), UNO_QUERY );
63 if ( m_xControlModel.is() )
64 m_xControlModel->addPropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
66 m_bFocused = IsFocused();
67 m_bSelected = IsSelected();
68 m_aBounds = GetBounds();
73 AccessibleDialogControlShape::~AccessibleDialogControlShape()
75 if ( m_xControlModel.is() )
76 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
78 delete m_pExternalLock;
79 m_pExternalLock = NULL;
84 bool AccessibleDialogControlShape::IsFocused()
86 bool bFocused = false;
87 if ( m_pDialogWindow )
89 SdrView& rView = m_pDialogWindow->GetView();
90 if (rView.IsObjMarked(m_pDlgEdObj) && rView.GetMarkedObjectList().GetMarkCount() == 1)
91 bFocused = true;
94 return bFocused;
99 bool AccessibleDialogControlShape::IsSelected()
101 if ( m_pDialogWindow )
102 return m_pDialogWindow->GetView().IsObjMarked(m_pDlgEdObj);
103 return false;
108 void AccessibleDialogControlShape::SetFocused( bool bFocused )
110 if ( m_bFocused != bFocused )
112 Any aOldValue, aNewValue;
113 if ( m_bFocused )
114 aOldValue <<= AccessibleStateType::FOCUSED;
115 else
116 aNewValue <<= AccessibleStateType::FOCUSED;
117 m_bFocused = bFocused;
118 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
124 void AccessibleDialogControlShape::SetSelected( bool bSelected )
126 if ( m_bSelected != bSelected )
128 Any aOldValue, aNewValue;
129 if ( m_bSelected )
130 aOldValue <<= AccessibleStateType::SELECTED;
131 else
132 aNewValue <<= AccessibleStateType::SELECTED;
133 m_bSelected = bSelected;
134 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
140 awt::Rectangle AccessibleDialogControlShape::GetBounds()
142 awt::Rectangle aBounds( 0, 0, 0, 0 );
143 if ( m_pDlgEdObj )
145 // get the bounding box of the shape in logic units
146 Rectangle aRect = m_pDlgEdObj->GetSnapRect();
148 if ( m_pDialogWindow )
150 // transform coordinates relative to the parent
151 MapMode aMap = m_pDialogWindow->GetMapMode();
152 Point aOrg = aMap.GetOrigin();
153 aRect.Move( aOrg.X(), aOrg.Y() );
155 // convert logic units to pixel
156 aRect = m_pDialogWindow->LogicToPixel( aRect, MapMode(MAP_100TH_MM) );
158 // clip the shape's bounding box with the bounding box of its parent
159 Rectangle aParentRect( Point( 0, 0 ), m_pDialogWindow->GetSizePixel() );
160 aRect = aRect.GetIntersection( aParentRect );
161 aBounds = AWTRectangle( aRect );
165 return aBounds;
170 void AccessibleDialogControlShape::SetBounds( const awt::Rectangle& aBounds )
172 if ( m_aBounds.X != aBounds.X || m_aBounds.Y != aBounds.Y || m_aBounds.Width != aBounds.Width || m_aBounds.Height != aBounds.Height )
174 m_aBounds = aBounds;
175 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
181 vcl::Window* AccessibleDialogControlShape::GetWindow() const
183 vcl::Window* pWindow = NULL;
184 if ( m_pDlgEdObj )
186 Reference< awt::XControl > xControl( m_pDlgEdObj->GetControl(), UNO_QUERY );
187 if ( xControl.is() )
188 pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
191 return pWindow;
196 OUString AccessibleDialogControlShape::GetModelStringProperty( const sal_Char* pPropertyName )
198 OUString sReturn;
202 if ( m_xControlModel.is() )
204 OUString sPropertyName( OUString::createFromAscii( pPropertyName ) );
205 Reference< XPropertySetInfo > xInfo = m_xControlModel->getPropertySetInfo();
206 if ( xInfo.is() && xInfo->hasPropertyByName( sPropertyName ) )
207 m_xControlModel->getPropertyValue( sPropertyName ) >>= sReturn;
210 catch ( const Exception& )
212 OSL_FAIL( "AccessibleDialogControlShape::GetModelStringProperty: caught an exception!" );
215 return sReturn;
220 void AccessibleDialogControlShape::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
222 rStateSet.AddState( AccessibleStateType::ENABLED );
224 rStateSet.AddState( AccessibleStateType::VISIBLE );
226 rStateSet.AddState( AccessibleStateType::SHOWING );
228 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
230 if ( IsFocused() )
231 rStateSet.AddState( AccessibleStateType::FOCUSED );
233 rStateSet.AddState( AccessibleStateType::SELECTABLE );
235 if ( IsSelected() )
236 rStateSet.AddState( AccessibleStateType::SELECTED );
238 rStateSet.AddState( AccessibleStateType::RESIZABLE );
241 // OCommonAccessibleComponent
242 awt::Rectangle AccessibleDialogControlShape::implGetBounds() throw (RuntimeException, std::exception)
244 return GetBounds();
247 // XInterface
248 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape, AccessibleExtendedComponentHelper_BASE, AccessibleDialogControlShape_BASE )
250 // XTypeProvider
251 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape, AccessibleExtendedComponentHelper_BASE, AccessibleDialogControlShape_BASE )
253 // XComponent
254 void AccessibleDialogControlShape::disposing()
256 AccessibleExtendedComponentHelper_BASE::disposing();
258 m_pDialogWindow = NULL;
259 m_pDlgEdObj = NULL;
261 if ( m_xControlModel.is() )
262 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
263 m_xControlModel.clear();
267 // XEventListener
270 void AccessibleDialogControlShape::disposing( const lang::EventObject& ) throw (RuntimeException, std::exception)
272 if ( m_xControlModel.is() )
273 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
274 m_xControlModel.clear();
278 // XPropertyChangeListener
281 void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent& rEvent ) throw (RuntimeException, std::exception)
283 if ( rEvent.PropertyName == DLGED_PROP_NAME )
285 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, rEvent.OldValue, rEvent.NewValue );
287 else if ( rEvent.PropertyName == DLGED_PROP_POSITIONX ||
288 rEvent.PropertyName == DLGED_PROP_POSITIONY ||
289 rEvent.PropertyName == DLGED_PROP_WIDTH ||
290 rEvent.PropertyName == DLGED_PROP_HEIGHT )
292 SetBounds( GetBounds() );
294 else if ( rEvent.PropertyName == DLGED_PROP_BACKGROUNDCOLOR ||
295 rEvent.PropertyName == DLGED_PROP_TEXTCOLOR ||
296 rEvent.PropertyName == DLGED_PROP_TEXTLINECOLOR )
298 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any() );
302 // XServiceInfo
303 OUString AccessibleDialogControlShape::getImplementationName() throw (RuntimeException, std::exception)
305 return OUString( "com.sun.star.comp.basctl.AccessibleShape" );
308 sal_Bool AccessibleDialogControlShape::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
310 return cppu::supportsService(this, rServiceName);
313 Sequence< OUString > AccessibleDialogControlShape::getSupportedServiceNames() throw (RuntimeException, std::exception)
315 Sequence< OUString > aNames(1);
316 aNames[0] = "com.sun.star.drawing.AccessibleShape" ;
317 return aNames;
320 // XAccessible
321 Reference< XAccessibleContext > AccessibleDialogControlShape::getAccessibleContext( ) throw (RuntimeException, std::exception)
323 OExternalLockGuard aGuard( this );
325 return this;
328 // XAccessibleContext
329 sal_Int32 AccessibleDialogControlShape::getAccessibleChildCount() throw (RuntimeException, std::exception)
331 OExternalLockGuard aGuard( this );
333 return 0;
338 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
340 OExternalLockGuard aGuard( this );
342 if ( i < 0 || i >= getAccessibleChildCount() )
343 throw IndexOutOfBoundsException();
345 return Reference< XAccessible >();
350 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleParent( ) throw (RuntimeException, std::exception)
352 OExternalLockGuard aGuard( this );
354 Reference< XAccessible > xParent;
355 if ( m_pDialogWindow )
356 xParent = m_pDialogWindow->GetAccessible();
358 return xParent;
363 sal_Int32 AccessibleDialogControlShape::getAccessibleIndexInParent( ) throw (RuntimeException, std::exception)
365 OExternalLockGuard aGuard( this );
367 sal_Int32 nIndexInParent = -1;
368 Reference< XAccessible > xParent( getAccessibleParent() );
369 if ( xParent.is() )
371 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
372 if ( xParentContext.is() )
374 for ( sal_Int32 i = 0, nCount = xParentContext->getAccessibleChildCount(); i < nCount; ++i )
376 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
377 if ( xChild.is() )
379 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
380 if ( xChildContext == (XAccessibleContext*)this )
382 nIndexInParent = i;
383 break;
390 return nIndexInParent;
395 sal_Int16 AccessibleDialogControlShape::getAccessibleRole( ) throw (RuntimeException, std::exception)
397 OExternalLockGuard aGuard( this );
399 return AccessibleRole::SHAPE;
404 OUString AccessibleDialogControlShape::getAccessibleDescription( ) throw (RuntimeException, std::exception)
406 OExternalLockGuard aGuard( this );
408 return GetModelStringProperty( "HelpText" );
413 OUString AccessibleDialogControlShape::getAccessibleName( ) throw (RuntimeException, std::exception)
415 OExternalLockGuard aGuard( this );
417 return GetModelStringProperty( "Name" );
422 Reference< XAccessibleRelationSet > AccessibleDialogControlShape::getAccessibleRelationSet( ) throw (RuntimeException, std::exception)
424 OExternalLockGuard aGuard( this );
426 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
427 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
428 return xSet;
433 Reference< XAccessibleStateSet > AccessibleDialogControlShape::getAccessibleStateSet( ) throw (RuntimeException, std::exception)
435 OExternalLockGuard aGuard( this );
437 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
438 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
440 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
442 FillAccessibleStateSet( *pStateSetHelper );
444 else
446 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
449 return xSet;
454 Locale AccessibleDialogControlShape::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
456 OExternalLockGuard aGuard( this );
458 return Application::GetSettings().GetLanguageTag().getLocale();
462 // XAccessibleComponent
465 Reference< XAccessible > AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException, std::exception)
467 OExternalLockGuard aGuard( this );
469 return Reference< XAccessible >();
474 void AccessibleDialogControlShape::grabFocus( ) throw (RuntimeException, std::exception)
476 // no focus for shapes
481 sal_Int32 AccessibleDialogControlShape::getForeground( ) throw (RuntimeException, std::exception)
483 OExternalLockGuard aGuard( this );
485 sal_Int32 nColor = 0;
486 vcl::Window* pWindow = GetWindow();
487 if ( pWindow )
489 if ( pWindow->IsControlForeground() )
490 nColor = pWindow->GetControlForeground().GetColor();
491 else
493 vcl::Font aFont;
494 if ( pWindow->IsControlFont() )
495 aFont = pWindow->GetControlFont();
496 else
497 aFont = pWindow->GetFont();
498 nColor = aFont.GetColor().GetColor();
502 return nColor;
507 sal_Int32 AccessibleDialogControlShape::getBackground( ) throw (RuntimeException, std::exception)
509 OExternalLockGuard aGuard( this );
511 sal_Int32 nColor = 0;
512 vcl::Window* pWindow = GetWindow();
513 if ( pWindow )
515 if ( pWindow->IsControlBackground() )
516 nColor = pWindow->GetControlBackground().GetColor();
517 else
518 nColor = pWindow->GetBackground().GetColor().GetColor();
521 return nColor;
525 // XAccessibleExtendedComponent
528 Reference< awt::XFont > AccessibleDialogControlShape::getFont( ) throw (RuntimeException, std::exception)
530 OExternalLockGuard aGuard( this );
532 Reference< awt::XFont > xFont;
533 vcl::Window* pWindow = GetWindow();
534 if ( pWindow )
536 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
537 if ( xDev.is() )
539 vcl::Font aFont;
540 if ( pWindow->IsControlFont() )
541 aFont = pWindow->GetControlFont();
542 else
543 aFont = pWindow->GetFont();
544 VCLXFont* pVCLXFont = new VCLXFont;
545 pVCLXFont->Init( *xDev.get(), aFont );
546 xFont = pVCLXFont;
550 return xFont;
555 OUString AccessibleDialogControlShape::getTitledBorderText( ) throw (RuntimeException, std::exception)
557 OExternalLockGuard aGuard( this );
559 return OUString();
564 OUString AccessibleDialogControlShape::getToolTipText( ) throw (RuntimeException, std::exception)
566 OExternalLockGuard aGuard( this );
568 OUString sText;
569 vcl::Window* pWindow = GetWindow();
570 if ( pWindow )
571 sText = pWindow->GetQuickHelpText();
573 return sText;
578 } // namespace basctl
580 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */