update dev300-m58
[ooovba.git] / basctl / source / accessibility / accessibledialogcontrolshape.cxx
blobf19a38dd53b6ce383c1f60ee0b429dc08561f10e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessibledialogcontrolshape.cxx,v $
10 * $Revision: 1.11 $
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() );
68 if ( m_pDlgEdObj )
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 )
99 bFocused = sal_True;
102 return bFocused;
105 // -----------------------------------------------------------------------------
107 sal_Bool AccessibleDialogControlShape::IsSelected()
109 sal_Bool bSelected = sal_False;
110 if ( m_pDialogWindow )
112 SdrView* pSdrView = m_pDialogWindow->GetView();
113 if ( pSdrView )
114 bSelected = pSdrView->IsObjMarked( m_pDlgEdObj );
117 return bSelected;
120 // -----------------------------------------------------------------------------
122 void AccessibleDialogControlShape::SetFocused( sal_Bool bFocused )
124 if ( m_bFocused != bFocused )
126 Any aOldValue, aNewValue;
127 if ( m_bFocused )
128 aOldValue <<= AccessibleStateType::FOCUSED;
129 else
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;
143 if ( m_bSelected )
144 aOldValue <<= AccessibleStateType::SELECTED;
145 else
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 );
157 if ( m_pDlgEdObj )
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 );
179 return aBounds;
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 )
188 m_aBounds = aBounds;
189 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
193 // -----------------------------------------------------------------------------
195 Window* AccessibleDialogControlShape::GetWindow() const
197 Window* pWindow = NULL;
198 if ( m_pDlgEdObj )
200 Reference< awt::XControl > xControl( m_pDlgEdObj->GetControl(), UNO_QUERY );
201 if ( xControl.is() )
202 pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
205 return pWindow;
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!" );
229 return sReturn;
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 );
244 if ( IsFocused() )
245 rStateSet.AddState( AccessibleStateType::FOCUSED );
247 rStateSet.AddState( AccessibleStateType::SELECTABLE );
249 if ( IsSelected() )
250 rStateSet.AddState( AccessibleStateType::SELECTED );
252 rStateSet.AddState( AccessibleStateType::RESIZABLE );
255 // -----------------------------------------------------------------------------
256 // OCommonAccessibleComponent
257 // -----------------------------------------------------------------------------
259 awt::Rectangle AccessibleDialogControlShape::implGetBounds() throw (RuntimeException)
261 return GetBounds();
264 // -----------------------------------------------------------------------------
265 // XInterface
266 // -----------------------------------------------------------------------------
268 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape, AccessibleExtendedComponentHelper_BASE, AccessibleDialogControlShape_BASE )
270 // -----------------------------------------------------------------------------
271 // XTypeProvider
272 // -----------------------------------------------------------------------------
274 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape, AccessibleExtendedComponentHelper_BASE, AccessibleDialogControlShape_BASE )
276 // -----------------------------------------------------------------------------
277 // XComponent
278 // -----------------------------------------------------------------------------
280 void AccessibleDialogControlShape::disposing()
282 AccessibleExtendedComponentHelper_BASE::disposing();
284 m_pDialogWindow = NULL;
285 m_pDlgEdObj = NULL;
287 if ( m_xControlModel.is() )
288 m_xControlModel->removePropertyChangeListener( ::rtl::OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
289 m_xControlModel.clear();
292 // -----------------------------------------------------------------------------
293 // XEventListener
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 // -----------------------------------------------------------------------------
329 // XServiceInfo
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" );
356 return aNames;
359 // -----------------------------------------------------------------------------
360 // XAccessible
361 // -----------------------------------------------------------------------------
363 Reference< XAccessibleContext > AccessibleDialogControlShape::getAccessibleContext( ) throw (RuntimeException)
365 OExternalLockGuard aGuard( this );
367 return this;
370 // -----------------------------------------------------------------------------
371 // XAccessibleContext
372 // -----------------------------------------------------------------------------
374 sal_Int32 AccessibleDialogControlShape::getAccessibleChildCount() throw (RuntimeException)
376 OExternalLockGuard aGuard( this );
378 return 0;
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();
403 return xParent;
406 // -----------------------------------------------------------------------------
408 sal_Int32 AccessibleDialogControlShape::getAccessibleIndexInParent( ) throw (RuntimeException)
410 OExternalLockGuard aGuard( this );
412 sal_Int32 nIndexInParent = -1;
413 Reference< XAccessible > xParent( getAccessibleParent() );
414 if ( xParent.is() )
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 ) );
422 if ( xChild.is() )
424 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
425 if ( xChildContext == (XAccessibleContext*)this )
427 nIndexInParent = i;
428 break;
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;
473 return xSet;
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 );
489 else
491 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
494 return xSet;
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();
532 if ( pWindow )
534 if ( pWindow->IsControlForeground() )
535 nColor = pWindow->GetControlForeground().GetColor();
536 else
538 Font aFont;
539 if ( pWindow->IsControlFont() )
540 aFont = pWindow->GetControlFont();
541 else
542 aFont = pWindow->GetFont();
543 nColor = aFont.GetColor().GetColor();
547 return nColor;
550 // -----------------------------------------------------------------------------
552 sal_Int32 AccessibleDialogControlShape::getBackground( ) throw (RuntimeException)
554 OExternalLockGuard aGuard( this );
556 sal_Int32 nColor = 0;
557 Window* pWindow = GetWindow();
558 if ( pWindow )
560 if ( pWindow->IsControlBackground() )
561 nColor = pWindow->GetControlBackground().GetColor();
562 else
563 nColor = pWindow->GetBackground().GetColor().GetColor();
566 return nColor;
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();
579 if ( pWindow )
581 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
582 if ( xDev.is() )
584 Font aFont;
585 if ( pWindow->IsControlFont() )
586 aFont = pWindow->GetControlFont();
587 else
588 aFont = pWindow->GetFont();
589 VCLXFont* pVCLXFont = new VCLXFont;
590 pVCLXFont->Init( *xDev.get(), aFont );
591 xFont = pVCLXFont;
595 return xFont;
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();
615 if ( pWindow )
616 sText = pWindow->GetQuickHelpText();
618 return sText;
621 // -----------------------------------------------------------------------------