fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / accessibility / AccessibleChartView.cxx
blob4b742f17a54c30e3d47350b09607140fbb4b29dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "AccessibleChartView.hxx"
21 #include "chartview/ExplicitValueProvider.hxx"
22 #include "servicenames.hxx"
23 #include "macros.hxx"
24 #include "ObjectHierarchy.hxx"
25 #include "ObjectIdentifier.hxx"
26 #include "ResId.hxx"
27 #include "Strings.hrc"
28 #include "AccessibleViewForwarder.hxx"
30 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #include <rtl/ustring.hxx>
35 #include <vcl/window.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <vcl/svapp.hxx>
38 #include <osl/mutex.hxx>
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::accessibility;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::WeakReference;
46 using ::com::sun::star::uno::Any;
47 using osl::MutexGuard;
49 namespace chart
52 AccessibleChartView::AccessibleChartView(
53 const Reference< uno::XComponentContext >& xContext, SdrView* pView ) :
54 impl::AccessibleChartView_Base(
55 AccessibleElementInfo(), // empty for now
56 true, // has children
57 true // always transparent
59 m_xContext( xContext ),
60 m_pSdrView( pView ),
61 m_pViewForwarder( NULL )
63 AddState( AccessibleStateType::OPAQUE );
66 AccessibleChartView::~AccessibleChartView()
68 delete m_pViewForwarder;
71 awt::Rectangle AccessibleChartView::GetWindowPosSize() const
73 Reference< awt::XWindow > xWindow( GetInfo().m_xWindow );
74 if( ! xWindow.is())
75 return awt::Rectangle();
77 awt::Rectangle aBBox( xWindow->getPosSize() );
79 vcl::Window* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow ));
80 if( pWindow )
82 SolarMutexGuard aSolarGuard;
83 Point aVCLPoint( pWindow->OutputToAbsoluteScreenPixel( Point( 0, 0 ) ));
84 aBBox.X = aVCLPoint.getX();
85 aBBox.Y = aVCLPoint.getY();
88 return aBBox;
91 awt::Point AccessibleChartView::GetUpperLeftOnScreen() const
93 awt::Point aParentPosition;
95 awt::Rectangle aBBox( GetWindowPosSize() );
96 aParentPosition.X = aBBox.X;
97 aParentPosition.Y = aBBox.Y;
99 return aParentPosition;
102 // ________ XAccessibleContext ________
103 OUString SAL_CALL AccessibleChartView::getAccessibleName()
104 throw (uno::RuntimeException, std::exception)
106 return SCH_RESSTR(STR_OBJECT_DIAGRAM);
109 OUString SAL_CALL AccessibleChartView::getAccessibleDescription()
110 throw (uno::RuntimeException, std::exception)
112 return getAccessibleName();
115 Reference< XAccessible > SAL_CALL AccessibleChartView::getAccessibleParent()
116 throw (uno::RuntimeException, std::exception)
118 return Reference< XAccessible >( m_xParent );
121 sal_Int32 SAL_CALL AccessibleChartView::getAccessibleIndexInParent()
122 throw (uno::RuntimeException, std::exception)
124 // the document is always the only child of the window
125 return 0;
128 sal_Int16 SAL_CALL AccessibleChartView::getAccessibleRole()
129 throw (uno::RuntimeException, std::exception)
131 return AccessibleRole::DOCUMENT;
134 // ________ XAccessibleComponent ________
135 awt::Rectangle SAL_CALL AccessibleChartView::getBounds()
136 throw (uno::RuntimeException, std::exception)
138 awt::Rectangle aResult( GetWindowPosSize());
139 Reference< XAccessible > xParent( m_xParent );
140 if( xParent.is())
142 Reference< XAccessibleComponent > xContext( xParent->getAccessibleContext(), uno::UNO_QUERY );
143 if( xContext.is())
145 awt::Point aParentPosition = xContext->getLocationOnScreen();
146 aResult.X -= aParentPosition.X;
147 aResult.Y -= aParentPosition.Y;
150 return aResult;
153 awt::Point SAL_CALL AccessibleChartView::getLocationOnScreen()
154 throw (uno::RuntimeException, std::exception)
156 awt::Rectangle aBounds( getBounds());
157 awt::Point aResult;
158 Reference< XAccessible > xParent( m_xParent );
159 if( xParent.is())
161 Reference< XAccessibleComponent > xAccComp(
162 xParent->getAccessibleContext(), uno::UNO_QUERY );
163 aResult = xAccComp->getLocationOnScreen();
164 aResult.X += aBounds.X;
165 aResult.Y += aBounds.Y;
167 return aResult;
170 // lang::XInitialization
172 void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments )
173 throw (uno::Exception, uno::RuntimeException, std::exception)
175 //0: view::XSelectionSupplier offers notifications for selection changes and access to the selection itself
176 //1: frame::XModel representing the chart model - offers access to object data
177 //2: lang::XInterface representing the normal chart view - offers access to some extra object data
179 //all arguments are only valid until next initialization
180 bool bChanged = false;
181 bool bOldInvalid = false;
182 bool bNewInvalid = false;
184 Reference< view::XSelectionSupplier > xSelectionSupplier;
185 Reference< frame::XModel > xChartModel;
186 Reference< uno::XInterface > xChartView;
187 Reference< XAccessible > xParent;
188 Reference< awt::XWindow > xWindow;
190 MutexGuard aGuard( GetMutex());
191 xSelectionSupplier.set( m_xSelectionSupplier );
192 xChartModel.set( m_xChartModel );
193 xChartView.set( m_xChartView );
194 xParent.set( m_xParent );
195 xWindow.set( m_xWindow );
198 if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
200 bOldInvalid = true;
203 if( rArguments.getLength() > 1 )
205 Reference< frame::XModel > xNewChartModel;
206 rArguments[1] >>= xNewChartModel;
207 if( xNewChartModel != xChartModel )
209 xChartModel = xNewChartModel;
210 bChanged = true;
213 else if( xChartModel.is() )
215 bChanged = true;
216 xChartModel = 0;
219 if( rArguments.getLength() > 2 )
221 Reference< uno::XInterface > xNewChartView;
222 rArguments[2] >>= xNewChartView;
223 if( xNewChartView != xChartView )
225 xChartView = xNewChartView;
226 bChanged = true;
229 else if( xChartView.is() )
231 bChanged = true;
232 xChartView = 0;
235 if( rArguments.getLength() > 3 )
237 Reference< XAccessible > xNewParent;
238 rArguments[3] >>= xNewParent;
239 if( xNewParent != xParent )
241 xParent = xNewParent;
242 bChanged = true;
246 if( rArguments.getLength() > 4 )
248 Reference< awt::XWindow > xNewWindow;
249 rArguments[4] >>= xNewWindow;
250 if( xNewWindow != xWindow )
252 xWindow.set( xNewWindow );
253 bChanged = true;
257 if( rArguments.getLength() > 0 && xChartModel.is() && xChartView.is() )
259 Reference< view::XSelectionSupplier > xNewSelectionSupplier;
260 rArguments[0] >>= xNewSelectionSupplier;
261 if(xSelectionSupplier!=xNewSelectionSupplier)
263 bChanged = true;
264 if(xSelectionSupplier.is())
265 xSelectionSupplier->removeSelectionChangeListener(this);
266 if(xNewSelectionSupplier.is())
267 xNewSelectionSupplier->addSelectionChangeListener(this);
268 xSelectionSupplier = xNewSelectionSupplier;
271 else if( xSelectionSupplier.is() )
273 bChanged = true;
274 xSelectionSupplier->removeSelectionChangeListener(this);
275 xSelectionSupplier = 0;
278 if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
280 if(xSelectionSupplier.is())
281 xSelectionSupplier->removeSelectionChangeListener(this);
282 xSelectionSupplier = 0;
283 xChartModel.clear();
284 xChartView.clear();
285 xParent.clear();
286 xWindow.clear();
288 bNewInvalid = true;
292 MutexGuard aGuard( GetMutex());
293 m_xSelectionSupplier = WeakReference< view::XSelectionSupplier >(xSelectionSupplier);
294 m_xChartModel = WeakReference< frame::XModel >(xChartModel);
295 m_xChartView = WeakReference< uno::XInterface >(xChartView);
296 m_xParent = WeakReference< XAccessible >(xParent);
297 m_xWindow = WeakReference< awt::XWindow >(xWindow);
300 if( bOldInvalid && bNewInvalid )
301 bChanged = false;
303 if( bChanged )
306 //before notification we prepare for creation of new context
307 //the old context will be deleted after notification than
308 MutexGuard aGuard( GetMutex());
309 Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
310 if( xChartDoc.is())
311 m_spObjectHierarchy.reset( new ObjectHierarchy( xChartDoc, getExplicitValueProvider() ));
312 else
313 m_spObjectHierarchy.reset();
317 AccessibleElementInfo aAccInfo;
318 aAccInfo.m_aOID = ObjectIdentifier("ROOT");
319 aAccInfo.m_xChartDocument = uno::WeakReference< chart2::XChartDocument >(
320 uno::Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY ));
321 aAccInfo.m_xSelectionSupplier = m_xSelectionSupplier;
322 aAccInfo.m_xView = m_xChartView;
323 aAccInfo.m_xWindow = m_xWindow;
324 aAccInfo.m_pParent = 0;
325 aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy;
326 aAccInfo.m_pSdrView = m_pSdrView;
327 vcl::Window* pWindow = VCLUnoHelper::GetWindow( m_xWindow );
328 if ( m_pViewForwarder )
330 delete m_pViewForwarder;
332 m_pViewForwarder = new AccessibleViewForwarder( this, pWindow );
333 aAccInfo.m_pViewForwarder = m_pViewForwarder;
334 // broadcasts an INVALIDATE_ALL_CHILDREN event globally
335 SetInfo( aAccInfo );
340 ExplicitValueProvider* AccessibleChartView::getExplicitValueProvider()
342 return ExplicitValueProvider::getExplicitValueProvider(m_xChartView);
345 // view::XSelectionChangeListener
347 void SAL_CALL AccessibleChartView::selectionChanged( const lang::EventObject& /*rEvent*/ )
348 throw (uno::RuntimeException, std::exception)
350 Reference< view::XSelectionSupplier > xSelectionSupplier;
352 MutexGuard aGuard( GetMutex());
353 xSelectionSupplier = Reference< view::XSelectionSupplier >(m_xSelectionSupplier);
356 if( xSelectionSupplier.is() )
358 ObjectIdentifier aSelectedOID( xSelectionSupplier->getSelection() );
359 if ( m_aCurrentSelectionOID.isValid() )
361 NotifyEvent( LOST_SELECTION, m_aCurrentSelectionOID );
363 if( aSelectedOID.isValid() )
365 NotifyEvent( GOT_SELECTION, aSelectedOID );
367 m_aCurrentSelectionOID = aSelectedOID;
371 // lang::XComponent::dispose()
372 void SAL_CALL AccessibleChartView::disposing()
374 AccessibleBase::disposing();
377 // XEventListener
378 void SAL_CALL AccessibleChartView::disposing( const lang::EventObject& /*Source*/ )
379 throw (uno::RuntimeException, std::exception)
383 } //namespace chart
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */