Update ooo320-m1
[ooovba.git] / chart2 / source / controller / accessibility / AccessibleChartView.cxx
bloba1900e93ac190dc950e8cd8884856925cad92061
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: AccessibleChartView.cxx,v $
10 * $Revision: 1.4 $
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_chart2.hxx"
34 #include "AccessibleChartView.hxx"
35 #include "chartview/ExplicitValueProvider.hxx"
36 #include "servicenames.hxx"
37 #include "macros.hxx"
38 #include "ObjectHierarchy.hxx"
39 #include "ObjectIdentifier.hxx"
40 #include "ResId.hxx"
41 #include "Strings.hrc"
43 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
44 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
45 #include <com/sun/star/accessibility/AccessibleRole.hpp>
47 #include <tools/string.hxx>
48 #include <vcl/window.hxx>
49 #include <toolkit/helper/vclunohelper.hxx>
50 // for SolarMutex
51 #include <vcl/svapp.hxx>
53 // header for typedef MutexGuard
54 #include <osl/mutex.hxx>
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::accessibility;
59 using ::com::sun::star::uno::Sequence;
60 using ::com::sun::star::uno::Reference;
61 using ::com::sun::star::uno::WeakReference;
62 using ::com::sun::star::uno::Any;
63 using ::rtl::OUString;
64 using osl::MutexGuard;
66 //.............................................................................
67 namespace chart
69 //.............................................................................
71 AccessibleChartView::AccessibleChartView(
72 const Reference<uno::XComponentContext> & xContext ) :
73 impl::AccessibleChartView_Base(
74 AccessibleElementInfo(), // empty for now
75 true, // has children
76 true // always transparent
78 m_xContext( xContext )
80 AddState( AccessibleStateType::OPAQUE );
83 AccessibleChartView::~AccessibleChartView()
88 awt::Rectangle AccessibleChartView::GetWindowPosSize() const
90 Reference< awt::XWindow > xWindow( GetInfo().m_xWindow );
91 if( ! xWindow.is())
92 return awt::Rectangle();
94 // this should do, but it doesn't => HACK
95 // return xWindow->getPosSize();
97 awt::Rectangle aBBox( xWindow->getPosSize() );
99 Window* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow ));
100 if( pWindow )
102 // /-- solar
103 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
104 Point aVCLPoint( pWindow->OutputToAbsoluteScreenPixel( Point( 0, 0 ) ));
105 aBBox.X = aVCLPoint.getX();
106 aBBox.Y = aVCLPoint.getY();
107 // \-- solar
110 return aBBox;
113 awt::Point AccessibleChartView::GetUpperLeftOnScreen() const
115 awt::Point aParentPosition;
117 awt::Rectangle aBBox( GetWindowPosSize() );
118 aParentPosition.X = aBBox.X;
119 aParentPosition.Y = aBBox.Y;
121 return aParentPosition;
124 // ________ XAccessibleContext ________
125 OUString SAL_CALL AccessibleChartView::getAccessibleName()
126 throw (uno::RuntimeException)
128 return OUString( String( SchResId( STR_OBJECT_DIAGRAM )));
131 OUString SAL_CALL AccessibleChartView::getAccessibleDescription()
132 throw (uno::RuntimeException)
134 return getAccessibleName();
137 Reference< XAccessible > SAL_CALL AccessibleChartView::getAccessibleParent()
138 throw (uno::RuntimeException)
140 return Reference< XAccessible >( m_xParent );
143 sal_Int32 SAL_CALL AccessibleChartView::getAccessibleIndexInParent()
144 throw (uno::RuntimeException)
146 // the document is always the only child of the window
147 return 0;
150 sal_Int16 SAL_CALL AccessibleChartView::getAccessibleRole()
151 throw (uno::RuntimeException)
153 return AccessibleRole::DOCUMENT;
156 // ________ XAccessibleComponent ________
157 awt::Rectangle SAL_CALL AccessibleChartView::getBounds()
158 throw (uno::RuntimeException)
160 awt::Rectangle aResult( GetWindowPosSize());
161 Reference< XAccessible > xParent( m_xParent );
162 if( xParent.is())
164 Reference< XAccessibleComponent > xContext( xParent->getAccessibleContext(), uno::UNO_QUERY );
165 if( xContext.is())
167 awt::Point aParentPosition = xContext->getLocationOnScreen();
168 aResult.X -= aParentPosition.X;
169 aResult.Y -= aParentPosition.Y;
172 return aResult;
175 awt::Point SAL_CALL AccessibleChartView::getLocationOnScreen()
176 throw (uno::RuntimeException)
178 awt::Rectangle aBounds( getBounds());
179 awt::Point aResult;
180 Reference< XAccessible > xParent( m_xParent );
181 if( xParent.is())
183 Reference< XAccessibleComponent > xAccComp(
184 xParent->getAccessibleContext(), uno::UNO_QUERY );
185 aResult = xAccComp->getLocationOnScreen();
186 aResult.X += aBounds.X;
187 aResult.Y += aBounds.Y;
189 return aResult;
192 //-----------------------------------------------------------------
193 // lang::XServiceInfo
194 //-----------------------------------------------------------------
196 APPHELPER_XSERVICEINFO_IMPL( AccessibleChartView, CHART2_ACCESSIBLE_SERVICE_IMPLEMENTATION_NAME )
198 uno::Sequence< rtl::OUString > AccessibleChartView::getSupportedServiceNames_Static()
200 uno::Sequence< rtl::OUString > aSNS( 2 );
201 aSNS.getArray()[ 0 ] = C2U("com.sun.star.accessibility.Accessible");
202 aSNS.getArray()[ 1 ] = CHART2_ACCESSIBLE_SERVICE_NAME;
203 return aSNS;
206 //-----------------------------------------------------------------
207 // lang::XInitialization
208 //-----------------------------------------------------------------
210 void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments )
211 throw (uno::Exception, uno::RuntimeException)
213 //0: view::XSelectionSupplier offers notifications for selection changes and access to the selection itself
214 //1: frame::XModel representing the chart model - offers access to object data
215 //2: lang::XInterface representing the normal chart view - offers access to some extra object data
217 //all arguments are only valid until next initialization
218 bool bChanged = false;
219 bool bOldInvalid = false;
220 bool bNewInvalid = false;
222 Reference< view::XSelectionSupplier > xSelectionSupplier;
223 Reference< frame::XModel > xChartModel;
224 Reference< uno::XInterface > xChartView;
225 Reference< XAccessible > xParent;
226 Reference< awt::XWindow > xWindow;
228 MutexGuard aGuard( GetMutex());
229 xSelectionSupplier.set( m_xSelectionSupplier );
230 xChartModel.set( m_xChartModel );
231 xChartView.set( m_xChartView );
232 xParent.set( m_xParent );
233 xWindow.set( m_xWindow );
236 if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
238 bOldInvalid = true;
241 if( rArguments.getLength() > 1 )
243 Reference< frame::XModel > xNewChartModel;
244 rArguments[1] >>= xNewChartModel;
245 if( xNewChartModel != xChartModel )
247 xChartModel = xNewChartModel;
248 bChanged = true;
251 else if( xChartModel.is() )
253 bChanged = true;
254 xChartModel = 0;
257 if( rArguments.getLength() > 2 )
259 Reference< uno::XInterface > xNewChartView;
260 rArguments[2] >>= xNewChartView;
261 if( xNewChartView != xChartView )
263 xChartView = xNewChartView;
264 bChanged = true;
267 else if( xChartView.is() )
269 bChanged = true;
270 xChartView = 0;
273 if( rArguments.getLength() > 3 )
275 Reference< XAccessible > xNewParent;
276 rArguments[3] >>= xNewParent;
277 if( xNewParent != xParent )
279 xParent = xNewParent;
280 bChanged = true;
284 if( rArguments.getLength() > 4 )
286 Reference< awt::XWindow > xNewWindow;
287 rArguments[4] >>= xNewWindow;
288 if( xNewWindow != xWindow )
290 xWindow.set( xNewWindow );
291 bChanged = true;
295 if( rArguments.getLength() > 0 && xChartModel.is() && xChartView.is() )
297 Reference< view::XSelectionSupplier > xNewSelectionSupplier;
298 rArguments[0] >>= xNewSelectionSupplier;
299 if(xSelectionSupplier!=xNewSelectionSupplier)
301 bChanged = true;
302 if(xSelectionSupplier.is())
303 xSelectionSupplier->removeSelectionChangeListener(this);
304 if(xNewSelectionSupplier.is())
305 xNewSelectionSupplier->addSelectionChangeListener(this);
306 xSelectionSupplier = xNewSelectionSupplier;
309 else if( xSelectionSupplier.is() )
311 bChanged = true;
312 xSelectionSupplier->removeSelectionChangeListener(this);
313 xSelectionSupplier = 0;
316 if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
318 if(xSelectionSupplier.is())
319 xSelectionSupplier->removeSelectionChangeListener(this);
320 xSelectionSupplier = 0;
321 xChartModel.clear();
322 xChartView.clear();
323 xParent.clear();
324 xWindow.clear();
326 bNewInvalid = true;
330 MutexGuard aGuard( GetMutex());
331 m_xSelectionSupplier = WeakReference< view::XSelectionSupplier >(xSelectionSupplier);
332 m_xChartModel = WeakReference< frame::XModel >(xChartModel);
333 m_xChartView = WeakReference< uno::XInterface >(xChartView);
334 m_xParent = WeakReference< XAccessible >(xParent);
335 m_xWindow = WeakReference< awt::XWindow >(xWindow);
338 if( bOldInvalid && bNewInvalid )
339 bChanged = false;
341 if( bChanged )
344 //before notification we prepare for creation of new context
345 //the old context will be deleted after notification than
346 MutexGuard aGuard( GetMutex());
347 Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
348 if( xChartDoc.is())
349 m_spObjectHierarchy.reset( new ObjectHierarchy( xChartDoc, getExplicitValueProvider() ));
350 else
351 m_spObjectHierarchy.reset();
355 AccessibleElementInfo aAccInfo;
356 aAccInfo.m_aCID = C2U("ROOT");
357 aAccInfo.m_xChartDocument = uno::WeakReference< chart2::XChartDocument >(
358 uno::Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY ));
359 aAccInfo.m_xSelectionSupplier = m_xSelectionSupplier;
360 aAccInfo.m_xView = m_xChartView;
361 aAccInfo.m_xWindow = m_xWindow;
362 aAccInfo.m_pParent = 0;
363 aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy;
364 // broadcasts an INVALIDATE_ALL_CHILDREN event globally
365 SetInfo( aAccInfo );
370 ExplicitValueProvider* AccessibleChartView::getExplicitValueProvider()
372 return ExplicitValueProvider::getExplicitValueProvider(m_xChartView);
375 //-------------------------------------------------------------------------
376 // view::XSelectionChangeListener
377 //-------------------------------------------------------------------------
379 void SAL_CALL AccessibleChartView::selectionChanged( const lang::EventObject& /*rEvent*/ )
380 throw (uno::RuntimeException)
382 Reference< view::XSelectionSupplier > xSelectionSupplier;
384 MutexGuard aGuard( GetMutex());
385 xSelectionSupplier = Reference< view::XSelectionSupplier >(m_xSelectionSupplier);
388 if( xSelectionSupplier.is() )
390 rtl::OUString aSelectedObjectCID;
391 Any aSelection = xSelectionSupplier->getSelection();
392 if(aSelection>>=aSelectedObjectCID)
394 if( m_aCurrentSelectionCID.getLength())
395 NotifyEvent( LOST_SELECTION, m_aCurrentSelectionCID );
396 if( aSelectedObjectCID.getLength())
397 NotifyEvent( GOT_SELECTION, aSelectedObjectCID );
398 m_aCurrentSelectionCID = aSelectedObjectCID;
403 //-------------------------------------------------------------------------
404 // lang::XComponent::dispose()
405 //-------------------------------------------------------------------------
406 void SAL_CALL AccessibleChartView::disposing()
408 AccessibleBase::disposing();
411 //-------------------------------------------------------------------------
412 // XEventListener
413 //-------------------------------------------------------------------------
414 void SAL_CALL AccessibleChartView::disposing( const lang::EventObject& /*Source*/ )
415 throw (uno::RuntimeException)
419 //.............................................................................
420 } //namespace chart
421 //.............................................................................