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 <unotools/accessiblestatesethelper.hxx>
29 #include <unotools/accessiblerelationsethelper.hxx>
30 #include <toolkit/awt/vclxfont.hxx>
31 #include <toolkit/helper/externallock.hxx>
32 #include <toolkit/helper/convert.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <vcl/svapp.hxx>
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::beans
;
43 using namespace ::com::sun::star::accessibility
;
44 using namespace ::comphelper
;
47 // -----------------------------------------------------------------------------
48 // class AccessibleDialogControlShape
49 // -----------------------------------------------------------------------------
51 AccessibleDialogControlShape::AccessibleDialogControlShape (DialogWindow
* pDialogWindow
, DlgEdObj
* pDlgEdObj
)
52 :AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() )
53 ,m_pDialogWindow( pDialogWindow
)
54 ,m_pDlgEdObj( pDlgEdObj
)
56 m_pExternalLock
= static_cast< VCLExternalSolarLock
* >( getExternalLock() );
59 m_xControlModel
= Reference
< XPropertySet
>( 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();
69 // -----------------------------------------------------------------------------
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
= NULL
;
80 // -----------------------------------------------------------------------------
82 bool AccessibleDialogControlShape::IsFocused()
84 bool bFocused
= false;
85 if ( m_pDialogWindow
)
87 SdrView
& rView
= m_pDialogWindow
->GetView();
88 if (rView
.IsObjMarked(m_pDlgEdObj
) && rView
.GetMarkedObjectList().GetMarkCount() == 1)
95 // -----------------------------------------------------------------------------
97 bool AccessibleDialogControlShape::IsSelected()
99 if ( m_pDialogWindow
)
100 return m_pDialogWindow
->GetView().IsObjMarked(m_pDlgEdObj
);
104 // -----------------------------------------------------------------------------
106 void AccessibleDialogControlShape::SetFocused( bool bFocused
)
108 if ( m_bFocused
!= bFocused
)
110 Any aOldValue
, aNewValue
;
112 aOldValue
<<= AccessibleStateType::FOCUSED
;
114 aNewValue
<<= AccessibleStateType::FOCUSED
;
115 m_bFocused
= bFocused
;
116 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
120 // -----------------------------------------------------------------------------
122 void AccessibleDialogControlShape::SetSelected( bool bSelected
)
124 if ( m_bSelected
!= bSelected
)
126 Any aOldValue
, aNewValue
;
128 aOldValue
<<= AccessibleStateType::SELECTED
;
130 aNewValue
<<= AccessibleStateType::SELECTED
;
131 m_bSelected
= bSelected
;
132 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
136 // -----------------------------------------------------------------------------
138 awt::Rectangle
AccessibleDialogControlShape::GetBounds()
140 awt::Rectangle
aBounds( 0, 0, 0, 0 );
143 // get the bounding box of the shape in logic units
144 Rectangle aRect
= m_pDlgEdObj
->GetSnapRect();
146 if ( m_pDialogWindow
)
148 // transform coordinates relative to the parent
149 MapMode aMap
= m_pDialogWindow
->GetMapMode();
150 Point aOrg
= aMap
.GetOrigin();
151 aRect
.Move( aOrg
.X(), aOrg
.Y() );
153 // convert logic units to pixel
154 aRect
= m_pDialogWindow
->LogicToPixel( aRect
, MapMode(MAP_100TH_MM
) );
156 // clip the shape's bounding box with the bounding box of its parent
157 Rectangle
aParentRect( Point( 0, 0 ), m_pDialogWindow
->GetSizePixel() );
158 aRect
= aRect
.GetIntersection( aParentRect
);
159 aBounds
= AWTRectangle( aRect
);
166 // -----------------------------------------------------------------------------
168 void AccessibleDialogControlShape::SetBounds( const awt::Rectangle
& aBounds
)
170 if ( m_aBounds
.X
!= aBounds
.X
|| m_aBounds
.Y
!= aBounds
.Y
|| m_aBounds
.Width
!= aBounds
.Width
|| m_aBounds
.Height
!= aBounds
.Height
)
173 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED
, Any(), Any() );
177 // -----------------------------------------------------------------------------
179 Window
* AccessibleDialogControlShape::GetWindow() const
181 Window
* pWindow
= NULL
;
184 Reference
< awt::XControl
> xControl( m_pDlgEdObj
->GetControl(), UNO_QUERY
);
186 pWindow
= VCLUnoHelper::GetWindow( xControl
->getPeer() );
192 // -----------------------------------------------------------------------------
194 OUString
AccessibleDialogControlShape::GetModelStringProperty( const sal_Char
* pPropertyName
)
200 if ( m_xControlModel
.is() )
202 OUString
sPropertyName( OUString::createFromAscii( pPropertyName
) );
203 Reference
< XPropertySetInfo
> xInfo
= m_xControlModel
->getPropertySetInfo();
204 if ( xInfo
.is() && xInfo
->hasPropertyByName( sPropertyName
) )
205 m_xControlModel
->getPropertyValue( sPropertyName
) >>= sReturn
;
208 catch ( const Exception
& )
210 OSL_FAIL( "AccessibleDialogControlShape::GetModelStringProperty: caught an exception!" );
216 // -----------------------------------------------------------------------------
218 void AccessibleDialogControlShape::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
220 rStateSet
.AddState( AccessibleStateType::ENABLED
);
222 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
224 rStateSet
.AddState( AccessibleStateType::SHOWING
);
226 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
229 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
231 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
234 rStateSet
.AddState( AccessibleStateType::SELECTED
);
236 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
239 // -----------------------------------------------------------------------------
240 // OCommonAccessibleComponent
241 // -----------------------------------------------------------------------------
243 awt::Rectangle
AccessibleDialogControlShape::implGetBounds() throw (RuntimeException
)
248 // -----------------------------------------------------------------------------
250 // -----------------------------------------------------------------------------
252 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape
, AccessibleExtendedComponentHelper_BASE
, AccessibleDialogControlShape_BASE
)
254 // -----------------------------------------------------------------------------
256 // -----------------------------------------------------------------------------
258 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape
, AccessibleExtendedComponentHelper_BASE
, AccessibleDialogControlShape_BASE
)
260 // -----------------------------------------------------------------------------
262 // -----------------------------------------------------------------------------
264 void AccessibleDialogControlShape::disposing()
266 AccessibleExtendedComponentHelper_BASE::disposing();
268 m_pDialogWindow
= NULL
;
271 if ( m_xControlModel
.is() )
272 m_xControlModel
->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
273 m_xControlModel
.clear();
276 // -----------------------------------------------------------------------------
278 // -----------------------------------------------------------------------------
280 void AccessibleDialogControlShape::disposing( const lang::EventObject
& ) throw (RuntimeException
)
282 if ( m_xControlModel
.is() )
283 m_xControlModel
->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
284 m_xControlModel
.clear();
287 // -----------------------------------------------------------------------------
288 // XPropertyChangeListener
289 // -----------------------------------------------------------------------------
291 void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent
& rEvent
) throw (RuntimeException
)
293 if ( rEvent
.PropertyName
== DLGED_PROP_NAME
)
295 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, rEvent
.OldValue
, rEvent
.NewValue
);
297 else if ( rEvent
.PropertyName
== DLGED_PROP_POSITIONX
||
298 rEvent
.PropertyName
== DLGED_PROP_POSITIONY
||
299 rEvent
.PropertyName
== DLGED_PROP_WIDTH
||
300 rEvent
.PropertyName
== DLGED_PROP_HEIGHT
)
302 SetBounds( GetBounds() );
304 else if ( rEvent
.PropertyName
== DLGED_PROP_BACKGROUNDCOLOR
||
305 rEvent
.PropertyName
== DLGED_PROP_TEXTCOLOR
||
306 rEvent
.PropertyName
== DLGED_PROP_TEXTLINECOLOR
)
308 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED
, Any(), Any() );
312 // -----------------------------------------------------------------------------
314 // -----------------------------------------------------------------------------
316 OUString
AccessibleDialogControlShape::getImplementationName() throw (RuntimeException
)
318 return OUString( "com.sun.star.comp.basctl.AccessibleShape" );
321 // -----------------------------------------------------------------------------
323 sal_Bool
AccessibleDialogControlShape::supportsService( const OUString
& rServiceName
) throw (RuntimeException
)
325 Sequence
< OUString
> aNames( getSupportedServiceNames() );
326 const OUString
* pNames
= aNames
.getConstArray();
327 const OUString
* pEnd
= pNames
+ aNames
.getLength();
328 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
331 return pNames
!= pEnd
;
334 // -----------------------------------------------------------------------------
336 Sequence
< OUString
> AccessibleDialogControlShape::getSupportedServiceNames() throw (RuntimeException
)
338 Sequence
< OUString
> aNames(1);
339 aNames
[0] = "com.sun.star.drawing.AccessibleShape" ;
343 // -----------------------------------------------------------------------------
345 // -----------------------------------------------------------------------------
347 Reference
< XAccessibleContext
> AccessibleDialogControlShape::getAccessibleContext( ) throw (RuntimeException
)
349 OExternalLockGuard
aGuard( this );
354 // -----------------------------------------------------------------------------
355 // XAccessibleContext
356 // -----------------------------------------------------------------------------
358 sal_Int32
AccessibleDialogControlShape::getAccessibleChildCount() throw (RuntimeException
)
360 OExternalLockGuard
aGuard( this );
365 // -----------------------------------------------------------------------------
367 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
369 OExternalLockGuard
aGuard( this );
371 if ( i
< 0 || i
>= getAccessibleChildCount() )
372 throw IndexOutOfBoundsException();
374 return Reference
< XAccessible
>();
377 // -----------------------------------------------------------------------------
379 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleParent( ) throw (RuntimeException
)
381 OExternalLockGuard
aGuard( this );
383 Reference
< XAccessible
> xParent
;
384 if ( m_pDialogWindow
)
385 xParent
= m_pDialogWindow
->GetAccessible();
390 // -----------------------------------------------------------------------------
392 sal_Int32
AccessibleDialogControlShape::getAccessibleIndexInParent( ) throw (RuntimeException
)
394 OExternalLockGuard
aGuard( this );
396 sal_Int32 nIndexInParent
= -1;
397 Reference
< XAccessible
> xParent( getAccessibleParent() );
400 Reference
< XAccessibleContext
> xParentContext( xParent
->getAccessibleContext() );
401 if ( xParentContext
.is() )
403 for ( sal_Int32 i
= 0, nCount
= xParentContext
->getAccessibleChildCount(); i
< nCount
; ++i
)
405 Reference
< XAccessible
> xChild( xParentContext
->getAccessibleChild( i
) );
408 Reference
< XAccessibleContext
> xChildContext
= xChild
->getAccessibleContext();
409 if ( xChildContext
== (XAccessibleContext
*)this )
419 return nIndexInParent
;
422 // -----------------------------------------------------------------------------
424 sal_Int16
AccessibleDialogControlShape::getAccessibleRole( ) throw (RuntimeException
)
426 OExternalLockGuard
aGuard( this );
428 return AccessibleRole::SHAPE
;
431 // -----------------------------------------------------------------------------
433 OUString
AccessibleDialogControlShape::getAccessibleDescription( ) throw (RuntimeException
)
435 OExternalLockGuard
aGuard( this );
437 return GetModelStringProperty( "HelpText" );
440 // -----------------------------------------------------------------------------
442 OUString
AccessibleDialogControlShape::getAccessibleName( ) throw (RuntimeException
)
444 OExternalLockGuard
aGuard( this );
446 return GetModelStringProperty( "Name" );
449 // -----------------------------------------------------------------------------
451 Reference
< XAccessibleRelationSet
> AccessibleDialogControlShape::getAccessibleRelationSet( ) throw (RuntimeException
)
453 OExternalLockGuard
aGuard( this );
455 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
456 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
460 // -----------------------------------------------------------------------------
462 Reference
< XAccessibleStateSet
> AccessibleDialogControlShape::getAccessibleStateSet( ) throw (RuntimeException
)
464 OExternalLockGuard
aGuard( this );
466 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
467 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
469 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
471 FillAccessibleStateSet( *pStateSetHelper
);
475 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
481 // -----------------------------------------------------------------------------
483 Locale
AccessibleDialogControlShape::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
485 OExternalLockGuard
aGuard( this );
487 return Application::GetSettings().GetLanguageTag().getLocale();
490 // -----------------------------------------------------------------------------
491 // XAccessibleComponent
492 // -----------------------------------------------------------------------------
494 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point
& ) throw (RuntimeException
)
496 OExternalLockGuard
aGuard( this );
498 return Reference
< XAccessible
>();
501 // -----------------------------------------------------------------------------
503 void AccessibleDialogControlShape::grabFocus( ) throw (RuntimeException
)
505 // no focus for shapes
508 // -----------------------------------------------------------------------------
510 sal_Int32
AccessibleDialogControlShape::getForeground( ) throw (RuntimeException
)
512 OExternalLockGuard
aGuard( this );
514 sal_Int32 nColor
= 0;
515 Window
* pWindow
= GetWindow();
518 if ( pWindow
->IsControlForeground() )
519 nColor
= pWindow
->GetControlForeground().GetColor();
523 if ( pWindow
->IsControlFont() )
524 aFont
= pWindow
->GetControlFont();
526 aFont
= pWindow
->GetFont();
527 nColor
= aFont
.GetColor().GetColor();
534 // -----------------------------------------------------------------------------
536 sal_Int32
AccessibleDialogControlShape::getBackground( ) throw (RuntimeException
)
538 OExternalLockGuard
aGuard( this );
540 sal_Int32 nColor
= 0;
541 Window
* pWindow
= GetWindow();
544 if ( pWindow
->IsControlBackground() )
545 nColor
= pWindow
->GetControlBackground().GetColor();
547 nColor
= pWindow
->GetBackground().GetColor().GetColor();
553 // -----------------------------------------------------------------------------
554 // XAccessibleExtendedComponent
555 // -----------------------------------------------------------------------------
557 Reference
< awt::XFont
> AccessibleDialogControlShape::getFont( ) throw (RuntimeException
)
559 OExternalLockGuard
aGuard( this );
561 Reference
< awt::XFont
> xFont
;
562 Window
* pWindow
= GetWindow();
565 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
569 if ( pWindow
->IsControlFont() )
570 aFont
= pWindow
->GetControlFont();
572 aFont
= pWindow
->GetFont();
573 VCLXFont
* pVCLXFont
= new VCLXFont
;
574 pVCLXFont
->Init( *xDev
.get(), aFont
);
582 // -----------------------------------------------------------------------------
584 OUString
AccessibleDialogControlShape::getTitledBorderText( ) throw (RuntimeException
)
586 OExternalLockGuard
aGuard( this );
591 // -----------------------------------------------------------------------------
593 OUString
AccessibleDialogControlShape::getToolTipText( ) throw (RuntimeException
)
595 OExternalLockGuard
aGuard( this );
598 Window
* pWindow
= GetWindow();
600 sText
= pWindow
->GetQuickHelpText();
605 // -----------------------------------------------------------------------------
607 } // namespace basctl
609 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */