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 <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>
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() );
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)
99 bool AccessibleDialogControlShape::IsSelected()
101 if ( m_pDialogWindow
)
102 return m_pDialogWindow
->GetView().IsObjMarked(m_pDlgEdObj
);
108 void AccessibleDialogControlShape::SetFocused( bool bFocused
)
110 if ( m_bFocused
!= bFocused
)
112 Any aOldValue
, aNewValue
;
114 aOldValue
<<= AccessibleStateType::FOCUSED
;
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
;
130 aOldValue
<<= AccessibleStateType::SELECTED
;
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 );
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
);
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
)
175 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED
, Any(), Any() );
181 vcl::Window
* AccessibleDialogControlShape::GetWindow() const
183 vcl::Window
* pWindow
= NULL
;
186 Reference
< awt::XControl
> xControl( m_pDlgEdObj
->GetControl(), UNO_QUERY
);
188 pWindow
= VCLUnoHelper::GetWindow( xControl
->getPeer() );
196 OUString
AccessibleDialogControlShape::GetModelStringProperty( const sal_Char
* pPropertyName
)
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!" );
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
);
231 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
233 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
236 rStateSet
.AddState( AccessibleStateType::SELECTED
);
238 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
241 // OCommonAccessibleComponent
242 awt::Rectangle
AccessibleDialogControlShape::implGetBounds() throw (RuntimeException
, std::exception
)
248 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape
, AccessibleExtendedComponentHelper_BASE
, AccessibleDialogControlShape_BASE
)
251 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape
, AccessibleExtendedComponentHelper_BASE
, AccessibleDialogControlShape_BASE
)
254 void AccessibleDialogControlShape::disposing()
256 AccessibleExtendedComponentHelper_BASE::disposing();
258 m_pDialogWindow
= NULL
;
261 if ( m_xControlModel
.is() )
262 m_xControlModel
->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
263 m_xControlModel
.clear();
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() );
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" ;
321 Reference
< XAccessibleContext
> AccessibleDialogControlShape::getAccessibleContext( ) throw (RuntimeException
, std::exception
)
323 OExternalLockGuard
aGuard( this );
328 // XAccessibleContext
329 sal_Int32
AccessibleDialogControlShape::getAccessibleChildCount() throw (RuntimeException
, std::exception
)
331 OExternalLockGuard
aGuard( this );
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();
363 sal_Int32
AccessibleDialogControlShape::getAccessibleIndexInParent( ) throw (RuntimeException
, std::exception
)
365 OExternalLockGuard
aGuard( this );
367 sal_Int32 nIndexInParent
= -1;
368 Reference
< XAccessible
> xParent( getAccessibleParent() );
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
) );
379 Reference
< XAccessibleContext
> xChildContext
= xChild
->getAccessibleContext();
380 if ( xChildContext
== (XAccessibleContext
*)this )
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
;
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
);
446 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
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();
489 if ( pWindow
->IsControlForeground() )
490 nColor
= pWindow
->GetControlForeground().GetColor();
494 if ( pWindow
->IsControlFont() )
495 aFont
= pWindow
->GetControlFont();
497 aFont
= pWindow
->GetFont();
498 nColor
= aFont
.GetColor().GetColor();
507 sal_Int32
AccessibleDialogControlShape::getBackground( ) throw (RuntimeException
, std::exception
)
509 OExternalLockGuard
aGuard( this );
511 sal_Int32 nColor
= 0;
512 vcl::Window
* pWindow
= GetWindow();
515 if ( pWindow
->IsControlBackground() )
516 nColor
= pWindow
->GetControlBackground().GetColor();
518 nColor
= pWindow
->GetBackground().GetColor().GetColor();
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();
536 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
540 if ( pWindow
->IsControlFont() )
541 aFont
= pWindow
->GetControlFont();
543 aFont
= pWindow
->GetFont();
544 VCLXFont
* pVCLXFont
= new VCLXFont
;
545 pVCLXFont
->Init( *xDev
.get(), aFont
);
555 OUString
AccessibleDialogControlShape::getTitledBorderText( ) throw (RuntimeException
, std::exception
)
557 OExternalLockGuard
aGuard( this );
564 OUString
AccessibleDialogControlShape::getToolTipText( ) throw (RuntimeException
, std::exception
)
566 OExternalLockGuard
aGuard( this );
569 vcl::Window
* pWindow
= GetWindow();
571 sText
= pWindow
->GetQuickHelpText();
578 } // namespace basctl
580 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */