1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/accessiblestatesethelper.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <toolkit/awt/vclxfont.hxx>
33 #include <toolkit/helper/convert.hxx>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/settings.hxx>
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 :m_pDialogWindow( pDialogWindow
)
54 ,m_pDlgEdObj( pDlgEdObj
)
57 m_xControlModel
.set( m_pDlgEdObj
->GetUnoControlModel(), UNO_QUERY
);
59 if ( m_xControlModel
.is() )
60 m_xControlModel
->addPropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
62 m_bFocused
= IsFocused();
63 m_bSelected
= IsSelected();
64 m_aBounds
= GetBounds();
68 AccessibleDialogControlShape::~AccessibleDialogControlShape()
70 if ( m_xControlModel
.is() )
71 m_xControlModel
->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
75 bool AccessibleDialogControlShape::IsFocused()
77 bool bFocused
= false;
78 if ( m_pDialogWindow
)
80 SdrView
& rView
= m_pDialogWindow
->GetView();
81 if (rView
.IsObjMarked(m_pDlgEdObj
) && rView
.GetMarkedObjectList().GetMarkCount() == 1)
89 bool AccessibleDialogControlShape::IsSelected()
91 if ( m_pDialogWindow
)
92 return m_pDialogWindow
->GetView().IsObjMarked(m_pDlgEdObj
);
97 void AccessibleDialogControlShape::SetFocused( bool bFocused
)
99 if ( m_bFocused
!= bFocused
)
101 Any aOldValue
, aNewValue
;
103 aOldValue
<<= AccessibleStateType::FOCUSED
;
105 aNewValue
<<= AccessibleStateType::FOCUSED
;
106 m_bFocused
= bFocused
;
107 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
112 void AccessibleDialogControlShape::SetSelected( bool bSelected
)
114 if ( m_bSelected
!= bSelected
)
116 Any aOldValue
, aNewValue
;
118 aOldValue
<<= AccessibleStateType::SELECTED
;
120 aNewValue
<<= AccessibleStateType::SELECTED
;
121 m_bSelected
= bSelected
;
122 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
127 awt::Rectangle
AccessibleDialogControlShape::GetBounds()
129 awt::Rectangle
aBounds( 0, 0, 0, 0 );
132 // get the bounding box of the shape in logic units
133 tools::Rectangle aRect
= m_pDlgEdObj
->GetSnapRect();
135 if ( m_pDialogWindow
)
137 // transform coordinates relative to the parent
138 MapMode aMap
= m_pDialogWindow
->GetMapMode();
139 Point aOrg
= aMap
.GetOrigin();
140 aRect
.Move( aOrg
.X(), aOrg
.Y() );
142 // convert logic units to pixel
143 aRect
= m_pDialogWindow
->LogicToPixel( aRect
, MapMode(MapUnit::Map100thMM
) );
145 // clip the shape's bounding box with the bounding box of its parent
146 tools::Rectangle
aParentRect( Point( 0, 0 ), m_pDialogWindow
->GetSizePixel() );
147 aRect
= aRect
.GetIntersection( aParentRect
);
148 aBounds
= AWTRectangle( aRect
);
156 void AccessibleDialogControlShape::SetBounds( const awt::Rectangle
& aBounds
)
158 if ( m_aBounds
.X
!= aBounds
.X
|| m_aBounds
.Y
!= aBounds
.Y
|| m_aBounds
.Width
!= aBounds
.Width
|| m_aBounds
.Height
!= aBounds
.Height
)
161 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED
, Any(), Any() );
166 vcl::Window
* AccessibleDialogControlShape::GetWindow() const
168 vcl::Window
* pWindow
= nullptr;
171 Reference
< awt::XControl
> xControl( m_pDlgEdObj
->GetControl(), UNO_QUERY
);
173 pWindow
= VCLUnoHelper::GetWindow( xControl
->getPeer() ).get();
180 OUString
AccessibleDialogControlShape::GetModelStringProperty( OUString
const & pPropertyName
)
186 if ( m_xControlModel
.is() )
188 Reference
< XPropertySetInfo
> xInfo
= m_xControlModel
->getPropertySetInfo();
189 if ( xInfo
.is() && xInfo
->hasPropertyByName( pPropertyName
) )
190 m_xControlModel
->getPropertyValue( pPropertyName
) >>= sReturn
;
193 catch ( const Exception
& )
195 OSL_FAIL( "AccessibleDialogControlShape::GetModelStringProperty: caught an exception!" );
202 void AccessibleDialogControlShape::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
204 rStateSet
.AddState( AccessibleStateType::ENABLED
);
206 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
208 rStateSet
.AddState( AccessibleStateType::SHOWING
);
210 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
213 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
215 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
218 rStateSet
.AddState( AccessibleStateType::SELECTED
);
220 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
223 // OCommonAccessibleComponent
224 awt::Rectangle
AccessibleDialogControlShape::implGetBounds()
230 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape
, OAccessibleExtendedComponentHelper
, AccessibleDialogControlShape_BASE
)
233 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape
, OAccessibleExtendedComponentHelper
, AccessibleDialogControlShape_BASE
)
236 void AccessibleDialogControlShape::disposing()
238 OAccessibleExtendedComponentHelper::disposing();
240 m_pDialogWindow
= nullptr;
241 m_pDlgEdObj
= nullptr;
243 if ( m_xControlModel
.is() )
244 m_xControlModel
->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
245 m_xControlModel
.clear();
252 void AccessibleDialogControlShape::disposing( const lang::EventObject
& )
254 if ( m_xControlModel
.is() )
255 m_xControlModel
->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
256 m_xControlModel
.clear();
260 // XPropertyChangeListener
263 void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent
& rEvent
)
265 if ( rEvent
.PropertyName
== DLGED_PROP_NAME
)
267 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, rEvent
.OldValue
, rEvent
.NewValue
);
269 else if ( rEvent
.PropertyName
== DLGED_PROP_POSITIONX
||
270 rEvent
.PropertyName
== DLGED_PROP_POSITIONY
||
271 rEvent
.PropertyName
== DLGED_PROP_WIDTH
||
272 rEvent
.PropertyName
== DLGED_PROP_HEIGHT
)
274 SetBounds( GetBounds() );
276 else if ( rEvent
.PropertyName
== DLGED_PROP_BACKGROUNDCOLOR
||
277 rEvent
.PropertyName
== DLGED_PROP_TEXTCOLOR
||
278 rEvent
.PropertyName
== DLGED_PROP_TEXTLINECOLOR
)
280 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED
, Any(), Any() );
285 OUString
AccessibleDialogControlShape::getImplementationName()
287 return OUString( "com.sun.star.comp.basctl.AccessibleShape" );
290 sal_Bool
AccessibleDialogControlShape::supportsService( const OUString
& rServiceName
)
292 return cppu::supportsService(this, rServiceName
);
295 Sequence
< OUString
> AccessibleDialogControlShape::getSupportedServiceNames()
297 return { "com.sun.star.drawing.AccessibleShape" };
301 Reference
< XAccessibleContext
> AccessibleDialogControlShape::getAccessibleContext( )
306 // XAccessibleContext
307 sal_Int32
AccessibleDialogControlShape::getAccessibleChildCount()
313 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleChild( sal_Int32 i
)
315 OExternalLockGuard
aGuard( this );
317 if ( i
< 0 || i
>= getAccessibleChildCount() )
318 throw IndexOutOfBoundsException();
320 return Reference
< XAccessible
>();
324 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleParent( )
326 OExternalLockGuard
aGuard( this );
328 Reference
< XAccessible
> xParent
;
329 if ( m_pDialogWindow
)
330 xParent
= m_pDialogWindow
->GetAccessible();
336 sal_Int32
AccessibleDialogControlShape::getAccessibleIndexInParent( )
338 OExternalLockGuard
aGuard( this );
340 sal_Int32 nIndexInParent
= -1;
341 Reference
< XAccessible
> xParent( getAccessibleParent() );
344 Reference
< XAccessibleContext
> xParentContext( xParent
->getAccessibleContext() );
345 if ( xParentContext
.is() )
347 for ( sal_Int32 i
= 0, nCount
= xParentContext
->getAccessibleChildCount(); i
< nCount
; ++i
)
349 Reference
< XAccessible
> xChild( xParentContext
->getAccessibleChild( i
) );
352 Reference
< XAccessibleContext
> xChildContext
= xChild
->getAccessibleContext();
353 if ( xChildContext
== static_cast<XAccessibleContext
*>(this) )
363 return nIndexInParent
;
367 sal_Int16
AccessibleDialogControlShape::getAccessibleRole( )
369 OExternalLockGuard
aGuard( this );
371 return AccessibleRole::SHAPE
;
375 OUString
AccessibleDialogControlShape::getAccessibleDescription( )
377 OExternalLockGuard
aGuard( this );
379 return GetModelStringProperty( "HelpText" );
383 OUString
AccessibleDialogControlShape::getAccessibleName( )
385 OExternalLockGuard
aGuard( this );
387 return GetModelStringProperty( "Name" );
391 Reference
< XAccessibleRelationSet
> AccessibleDialogControlShape::getAccessibleRelationSet( )
393 OExternalLockGuard
aGuard( this );
395 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
396 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
401 Reference
< XAccessibleStateSet
> AccessibleDialogControlShape::getAccessibleStateSet( )
403 OExternalLockGuard
aGuard( this );
405 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
406 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
408 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
410 FillAccessibleStateSet( *pStateSetHelper
);
414 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
421 Locale
AccessibleDialogControlShape::getLocale( )
423 OExternalLockGuard
aGuard( this );
425 return Application::GetSettings().GetLanguageTag().getLocale();
429 // XAccessibleComponent
432 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point
& )
434 OExternalLockGuard
aGuard( this );
436 return Reference
< XAccessible
>();
440 void AccessibleDialogControlShape::grabFocus( )
442 // no focus for shapes
446 sal_Int32
AccessibleDialogControlShape::getForeground( )
448 OExternalLockGuard
aGuard( this );
451 vcl::Window
* pWindow
= GetWindow();
454 if ( pWindow
->IsControlForeground() )
455 nColor
= pWindow
->GetControlForeground();
459 if ( pWindow
->IsControlFont() )
460 aFont
= pWindow
->GetControlFont();
462 aFont
= pWindow
->GetFont();
463 nColor
= aFont
.GetColor();
467 return sal_Int32(nColor
);
471 sal_Int32
AccessibleDialogControlShape::getBackground( )
473 OExternalLockGuard
aGuard( this );
476 vcl::Window
* pWindow
= GetWindow();
479 if ( pWindow
->IsControlBackground() )
480 nColor
= pWindow
->GetControlBackground();
482 nColor
= pWindow
->GetBackground().GetColor();
485 return sal_Int32(nColor
);
489 // XAccessibleExtendedComponent
492 Reference
< awt::XFont
> AccessibleDialogControlShape::getFont( )
494 OExternalLockGuard
aGuard( this );
496 Reference
< awt::XFont
> xFont
;
497 vcl::Window
* pWindow
= GetWindow();
500 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
504 if ( pWindow
->IsControlFont() )
505 aFont
= pWindow
->GetControlFont();
507 aFont
= pWindow
->GetFont();
508 VCLXFont
* pVCLXFont
= new VCLXFont
;
509 pVCLXFont
->Init( *xDev
.get(), aFont
);
518 OUString
AccessibleDialogControlShape::getTitledBorderText( )
520 OExternalLockGuard
aGuard( this );
526 OUString
AccessibleDialogControlShape::getToolTipText( )
528 OExternalLockGuard
aGuard( this );
531 vcl::Window
* pWindow
= GetWindow();
533 sText
= pWindow
->GetQuickHelpText();
539 } // namespace basctl
541 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */