1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessibledialogcontrolshape.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
33 #include <accessibledialogcontrolshape.hxx>
34 #include <baside3.hxx>
35 #include <dlgeddef.hxx>
36 #include <dlgedview.hxx>
37 #include <dlgedobj.hxx>
38 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
39 #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 #include <unotools/accessiblestatesethelper.hxx>
42 #include <unotools/accessiblerelationsethelper.hxx>
43 #include <toolkit/awt/vclxfont.hxx>
44 #include <toolkit/helper/externallock.hxx>
45 #include <toolkit/helper/convert.hxx>
46 #include <toolkit/helper/vclunohelper.hxx>
47 #include <vcl/svapp.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::accessibility
;
54 using namespace ::comphelper
;
57 // -----------------------------------------------------------------------------
58 // class AccessibleDialogControlShape
59 // -----------------------------------------------------------------------------
61 AccessibleDialogControlShape::AccessibleDialogControlShape( DialogWindow
* pDialogWindow
, DlgEdObj
* pDlgEdObj
)
62 :AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() )
63 ,m_pDialogWindow( pDialogWindow
)
64 ,m_pDlgEdObj( pDlgEdObj
)
66 m_pExternalLock
= static_cast< VCLExternalSolarLock
* >( getExternalLock() );
69 m_xControlModel
= Reference
< XPropertySet
>( m_pDlgEdObj
->GetUnoControlModel(), UNO_QUERY
);
71 if ( m_xControlModel
.is() )
72 m_xControlModel
->addPropertyChangeListener( ::rtl::OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
74 m_bFocused
= IsFocused();
75 m_bSelected
= IsSelected();
76 m_aBounds
= GetBounds();
79 // -----------------------------------------------------------------------------
81 AccessibleDialogControlShape::~AccessibleDialogControlShape()
83 if ( m_xControlModel
.is() )
84 m_xControlModel
->removePropertyChangeListener( ::rtl::OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
86 delete m_pExternalLock
;
87 m_pExternalLock
= NULL
;
90 // -----------------------------------------------------------------------------
92 sal_Bool
AccessibleDialogControlShape::IsFocused()
94 sal_Bool bFocused
= sal_False
;
95 if ( m_pDialogWindow
)
97 SdrView
* pSdrView
= m_pDialogWindow
->GetView();
98 if ( pSdrView
&& pSdrView
->IsObjMarked( m_pDlgEdObj
) && pSdrView
->GetMarkedObjectList().GetMarkCount() == 1 )
105 // -----------------------------------------------------------------------------
107 sal_Bool
AccessibleDialogControlShape::IsSelected()
109 sal_Bool bSelected
= sal_False
;
110 if ( m_pDialogWindow
)
112 SdrView
* pSdrView
= m_pDialogWindow
->GetView();
114 bSelected
= pSdrView
->IsObjMarked( m_pDlgEdObj
);
120 // -----------------------------------------------------------------------------
122 void AccessibleDialogControlShape::SetFocused( sal_Bool bFocused
)
124 if ( m_bFocused
!= bFocused
)
126 Any aOldValue
, aNewValue
;
128 aOldValue
<<= AccessibleStateType::FOCUSED
;
130 aNewValue
<<= AccessibleStateType::FOCUSED
;
131 m_bFocused
= bFocused
;
132 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
136 // -----------------------------------------------------------------------------
138 void AccessibleDialogControlShape::SetSelected( sal_Bool bSelected
)
140 if ( m_bSelected
!= bSelected
)
142 Any aOldValue
, aNewValue
;
144 aOldValue
<<= AccessibleStateType::SELECTED
;
146 aNewValue
<<= AccessibleStateType::SELECTED
;
147 m_bSelected
= bSelected
;
148 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
152 // -----------------------------------------------------------------------------
154 awt::Rectangle
AccessibleDialogControlShape::GetBounds()
156 awt::Rectangle
aBounds( 0, 0, 0, 0 );
159 // get the bounding box of the shape in logic units
160 Rectangle aRect
= m_pDlgEdObj
->GetSnapRect();
162 if ( m_pDialogWindow
)
164 // transform coordinates relative to the parent
165 MapMode aMap
= m_pDialogWindow
->GetMapMode();
166 Point aOrg
= aMap
.GetOrigin();
167 aRect
.Move( aOrg
.X(), aOrg
.Y() );
169 // convert logic units to pixel
170 aRect
= m_pDialogWindow
->LogicToPixel( aRect
, MapMode(MAP_100TH_MM
) );
172 // clip the shape's bounding box with the bounding box of its parent
173 Rectangle
aParentRect( Point( 0, 0 ), m_pDialogWindow
->GetSizePixel() );
174 aRect
= aRect
.GetIntersection( aParentRect
);
175 aBounds
= AWTRectangle( aRect
);
182 // -----------------------------------------------------------------------------
184 void AccessibleDialogControlShape::SetBounds( const awt::Rectangle
& aBounds
)
186 if ( m_aBounds
.X
!= aBounds
.X
|| m_aBounds
.Y
!= aBounds
.Y
|| m_aBounds
.Width
!= aBounds
.Width
|| m_aBounds
.Height
!= aBounds
.Height
)
189 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED
, Any(), Any() );
193 // -----------------------------------------------------------------------------
195 Window
* AccessibleDialogControlShape::GetWindow() const
197 Window
* pWindow
= NULL
;
200 Reference
< awt::XControl
> xControl( m_pDlgEdObj
->GetControl(), UNO_QUERY
);
202 pWindow
= VCLUnoHelper::GetWindow( xControl
->getPeer() );
208 // -----------------------------------------------------------------------------
210 ::rtl::OUString
AccessibleDialogControlShape::GetModelStringProperty( const sal_Char
* pPropertyName
)
212 ::rtl::OUString sReturn
;
216 if ( m_xControlModel
.is() )
218 ::rtl::OUString
sPropertyName( ::rtl::OUString::createFromAscii( pPropertyName
) );
219 Reference
< XPropertySetInfo
> xInfo
= m_xControlModel
->getPropertySetInfo();
220 if ( xInfo
.is() && xInfo
->hasPropertyByName( sPropertyName
) )
221 m_xControlModel
->getPropertyValue( sPropertyName
) >>= sReturn
;
224 catch ( const Exception
& )
226 OSL_ENSURE( sal_False
, "AccessibleDialogControlShape::GetModelStringProperty: caught an exception!" );
232 // -----------------------------------------------------------------------------
234 void AccessibleDialogControlShape::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
236 rStateSet
.AddState( AccessibleStateType::ENABLED
);
238 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
240 rStateSet
.AddState( AccessibleStateType::SHOWING
);
242 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
245 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
247 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
250 rStateSet
.AddState( AccessibleStateType::SELECTED
);
252 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
255 // -----------------------------------------------------------------------------
256 // OCommonAccessibleComponent
257 // -----------------------------------------------------------------------------
259 awt::Rectangle
AccessibleDialogControlShape::implGetBounds() throw (RuntimeException
)
264 // -----------------------------------------------------------------------------
266 // -----------------------------------------------------------------------------
268 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape
, AccessibleExtendedComponentHelper_BASE
, AccessibleDialogControlShape_BASE
)
270 // -----------------------------------------------------------------------------
272 // -----------------------------------------------------------------------------
274 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape
, AccessibleExtendedComponentHelper_BASE
, AccessibleDialogControlShape_BASE
)
276 // -----------------------------------------------------------------------------
278 // -----------------------------------------------------------------------------
280 void AccessibleDialogControlShape::disposing()
282 AccessibleExtendedComponentHelper_BASE::disposing();
284 m_pDialogWindow
= NULL
;
287 if ( m_xControlModel
.is() )
288 m_xControlModel
->removePropertyChangeListener( ::rtl::OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
289 m_xControlModel
.clear();
292 // -----------------------------------------------------------------------------
294 // -----------------------------------------------------------------------------
296 void AccessibleDialogControlShape::disposing( const lang::EventObject
& ) throw (RuntimeException
)
298 if ( m_xControlModel
.is() )
299 m_xControlModel
->removePropertyChangeListener( ::rtl::OUString(), static_cast< beans::XPropertyChangeListener
* >( this ) );
300 m_xControlModel
.clear();
303 // -----------------------------------------------------------------------------
304 // XPropertyChangeListener
305 // -----------------------------------------------------------------------------
307 void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent
& rEvent
) throw (RuntimeException
)
309 if ( rEvent
.PropertyName
== DLGED_PROP_NAME
)
311 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED
, rEvent
.OldValue
, rEvent
.NewValue
);
313 else if ( rEvent
.PropertyName
== DLGED_PROP_POSITIONX
||
314 rEvent
.PropertyName
== DLGED_PROP_POSITIONY
||
315 rEvent
.PropertyName
== DLGED_PROP_WIDTH
||
316 rEvent
.PropertyName
== DLGED_PROP_HEIGHT
)
318 SetBounds( GetBounds() );
320 else if ( rEvent
.PropertyName
== DLGED_PROP_BACKGROUNDCOLOR
||
321 rEvent
.PropertyName
== DLGED_PROP_TEXTCOLOR
||
322 rEvent
.PropertyName
== DLGED_PROP_TEXTLINECOLOR
)
324 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED
, Any(), Any() );
328 // -----------------------------------------------------------------------------
330 // -----------------------------------------------------------------------------
332 ::rtl::OUString
AccessibleDialogControlShape::getImplementationName() throw (RuntimeException
)
334 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.basctl.AccessibleShape" );
337 // -----------------------------------------------------------------------------
339 sal_Bool
AccessibleDialogControlShape::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
341 Sequence
< ::rtl::OUString
> aNames( getSupportedServiceNames() );
342 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
343 const ::rtl::OUString
* pEnd
= pNames
+ aNames
.getLength();
344 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
347 return pNames
!= pEnd
;
350 // -----------------------------------------------------------------------------
352 Sequence
< ::rtl::OUString
> AccessibleDialogControlShape::getSupportedServiceNames() throw (RuntimeException
)
354 Sequence
< ::rtl::OUString
> aNames(1);
355 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.AccessibleShape" );
359 // -----------------------------------------------------------------------------
361 // -----------------------------------------------------------------------------
363 Reference
< XAccessibleContext
> AccessibleDialogControlShape::getAccessibleContext( ) throw (RuntimeException
)
365 OExternalLockGuard
aGuard( this );
370 // -----------------------------------------------------------------------------
371 // XAccessibleContext
372 // -----------------------------------------------------------------------------
374 sal_Int32
AccessibleDialogControlShape::getAccessibleChildCount() throw (RuntimeException
)
376 OExternalLockGuard
aGuard( this );
381 // -----------------------------------------------------------------------------
383 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
385 OExternalLockGuard
aGuard( this );
387 if ( i
< 0 || i
>= getAccessibleChildCount() )
388 throw IndexOutOfBoundsException();
390 return Reference
< XAccessible
>();
393 // -----------------------------------------------------------------------------
395 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleParent( ) throw (RuntimeException
)
397 OExternalLockGuard
aGuard( this );
399 Reference
< XAccessible
> xParent
;
400 if ( m_pDialogWindow
)
401 xParent
= m_pDialogWindow
->GetAccessible();
406 // -----------------------------------------------------------------------------
408 sal_Int32
AccessibleDialogControlShape::getAccessibleIndexInParent( ) throw (RuntimeException
)
410 OExternalLockGuard
aGuard( this );
412 sal_Int32 nIndexInParent
= -1;
413 Reference
< XAccessible
> xParent( getAccessibleParent() );
416 Reference
< XAccessibleContext
> xParentContext( xParent
->getAccessibleContext() );
417 if ( xParentContext
.is() )
419 for ( sal_Int32 i
= 0, nCount
= xParentContext
->getAccessibleChildCount(); i
< nCount
; ++i
)
421 Reference
< XAccessible
> xChild( xParentContext
->getAccessibleChild( i
) );
424 Reference
< XAccessibleContext
> xChildContext
= xChild
->getAccessibleContext();
425 if ( xChildContext
== (XAccessibleContext
*)this )
435 return nIndexInParent
;
438 // -----------------------------------------------------------------------------
440 sal_Int16
AccessibleDialogControlShape::getAccessibleRole( ) throw (RuntimeException
)
442 OExternalLockGuard
aGuard( this );
444 return AccessibleRole::SHAPE
;
447 // -----------------------------------------------------------------------------
449 ::rtl::OUString
AccessibleDialogControlShape::getAccessibleDescription( ) throw (RuntimeException
)
451 OExternalLockGuard
aGuard( this );
453 return GetModelStringProperty( "HelpText" );
456 // -----------------------------------------------------------------------------
458 ::rtl::OUString
AccessibleDialogControlShape::getAccessibleName( ) throw (RuntimeException
)
460 OExternalLockGuard
aGuard( this );
462 return GetModelStringProperty( "Name" );
465 // -----------------------------------------------------------------------------
467 Reference
< XAccessibleRelationSet
> AccessibleDialogControlShape::getAccessibleRelationSet( ) throw (RuntimeException
)
469 OExternalLockGuard
aGuard( this );
471 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
472 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
476 // -----------------------------------------------------------------------------
478 Reference
< XAccessibleStateSet
> AccessibleDialogControlShape::getAccessibleStateSet( ) throw (RuntimeException
)
480 OExternalLockGuard
aGuard( this );
482 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
483 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
485 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
487 FillAccessibleStateSet( *pStateSetHelper
);
491 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
497 // -----------------------------------------------------------------------------
499 Locale
AccessibleDialogControlShape::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
501 OExternalLockGuard
aGuard( this );
503 return Application::GetSettings().GetLocale();
506 // -----------------------------------------------------------------------------
507 // XAccessibleComponent
508 // -----------------------------------------------------------------------------
510 Reference
< XAccessible
> AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point
& ) throw (RuntimeException
)
512 OExternalLockGuard
aGuard( this );
514 return Reference
< XAccessible
>();
517 // -----------------------------------------------------------------------------
519 void AccessibleDialogControlShape::grabFocus( ) throw (RuntimeException
)
521 // no focus for shapes
524 // -----------------------------------------------------------------------------
526 sal_Int32
AccessibleDialogControlShape::getForeground( ) throw (RuntimeException
)
528 OExternalLockGuard
aGuard( this );
530 sal_Int32 nColor
= 0;
531 Window
* pWindow
= GetWindow();
534 if ( pWindow
->IsControlForeground() )
535 nColor
= pWindow
->GetControlForeground().GetColor();
539 if ( pWindow
->IsControlFont() )
540 aFont
= pWindow
->GetControlFont();
542 aFont
= pWindow
->GetFont();
543 nColor
= aFont
.GetColor().GetColor();
550 // -----------------------------------------------------------------------------
552 sal_Int32
AccessibleDialogControlShape::getBackground( ) throw (RuntimeException
)
554 OExternalLockGuard
aGuard( this );
556 sal_Int32 nColor
= 0;
557 Window
* pWindow
= GetWindow();
560 if ( pWindow
->IsControlBackground() )
561 nColor
= pWindow
->GetControlBackground().GetColor();
563 nColor
= pWindow
->GetBackground().GetColor().GetColor();
569 // -----------------------------------------------------------------------------
570 // XAccessibleExtendedComponent
571 // -----------------------------------------------------------------------------
573 Reference
< awt::XFont
> AccessibleDialogControlShape::getFont( ) throw (RuntimeException
)
575 OExternalLockGuard
aGuard( this );
577 Reference
< awt::XFont
> xFont
;
578 Window
* pWindow
= GetWindow();
581 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
585 if ( pWindow
->IsControlFont() )
586 aFont
= pWindow
->GetControlFont();
588 aFont
= pWindow
->GetFont();
589 VCLXFont
* pVCLXFont
= new VCLXFont
;
590 pVCLXFont
->Init( *xDev
.get(), aFont
);
598 // -----------------------------------------------------------------------------
600 ::rtl::OUString
AccessibleDialogControlShape::getTitledBorderText( ) throw (RuntimeException
)
602 OExternalLockGuard
aGuard( this );
604 return ::rtl::OUString();
607 // -----------------------------------------------------------------------------
609 ::rtl::OUString
AccessibleDialogControlShape::getToolTipText( ) throw (RuntimeException
)
611 OExternalLockGuard
aGuard( this );
613 ::rtl::OUString sText
;
614 Window
* pWindow
= GetWindow();
616 sText
= pWindow
->GetQuickHelpText();
621 // -----------------------------------------------------------------------------