Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
29 :
30 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
33 :
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>
39 :
40 : using namespace ::com::sun::star;
41 : using namespace ::com::sun::star::accessibility;
42 :
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;
48 :
49 : namespace chart
50 : {
51 :
52 0 : 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
58 : ),
59 : m_xContext( xContext ),
60 : m_pSdrView( pView ),
61 0 : m_pViewForwarder( NULL )
62 : {
63 0 : AddState( AccessibleStateType::OPAQUE );
64 0 : }
65 :
66 0 : AccessibleChartView::~AccessibleChartView()
67 : {
68 0 : delete m_pViewForwarder;
69 0 : }
70 :
71 0 : awt::Rectangle AccessibleChartView::GetWindowPosSize() const
72 : {
73 0 : Reference< awt::XWindow > xWindow( GetInfo().m_xWindow );
74 0 : if( ! xWindow.is())
75 0 : return awt::Rectangle();
76 :
77 0 : awt::Rectangle aBBox( xWindow->getPosSize() );
78 :
79 0 : vcl::Window* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow ));
80 0 : if( pWindow )
81 : {
82 0 : SolarMutexGuard aSolarGuard;
83 0 : Point aVCLPoint( pWindow->OutputToAbsoluteScreenPixel( Point( 0, 0 ) ));
84 0 : aBBox.X = aVCLPoint.getX();
85 0 : aBBox.Y = aVCLPoint.getY();
86 : }
87 :
88 0 : return aBBox;
89 : }
90 :
91 0 : awt::Point AccessibleChartView::GetUpperLeftOnScreen() const
92 : {
93 0 : awt::Point aParentPosition;
94 :
95 0 : awt::Rectangle aBBox( GetWindowPosSize() );
96 0 : aParentPosition.X = aBBox.X;
97 0 : aParentPosition.Y = aBBox.Y;
98 :
99 0 : return aParentPosition;
100 : }
101 :
102 : // ________ XAccessibleContext ________
103 0 : OUString SAL_CALL AccessibleChartView::getAccessibleName()
104 : throw (uno::RuntimeException, std::exception)
105 : {
106 0 : return SCH_RESSTR(STR_OBJECT_DIAGRAM);
107 : }
108 :
109 0 : OUString SAL_CALL AccessibleChartView::getAccessibleDescription()
110 : throw (uno::RuntimeException, std::exception)
111 : {
112 0 : return getAccessibleName();
113 : }
114 :
115 0 : Reference< XAccessible > SAL_CALL AccessibleChartView::getAccessibleParent()
116 : throw (uno::RuntimeException, std::exception)
117 : {
118 0 : return Reference< XAccessible >( m_xParent );
119 : }
120 :
121 0 : sal_Int32 SAL_CALL AccessibleChartView::getAccessibleIndexInParent()
122 : throw (uno::RuntimeException, std::exception)
123 : {
124 : // the document is always the only child of the window
125 0 : return 0;
126 : }
127 :
128 0 : sal_Int16 SAL_CALL AccessibleChartView::getAccessibleRole()
129 : throw (uno::RuntimeException, std::exception)
130 : {
131 0 : return AccessibleRole::DOCUMENT;
132 : }
133 :
134 : // ________ XAccessibleComponent ________
135 0 : awt::Rectangle SAL_CALL AccessibleChartView::getBounds()
136 : throw (uno::RuntimeException, std::exception)
137 : {
138 0 : awt::Rectangle aResult( GetWindowPosSize());
139 0 : Reference< XAccessible > xParent( m_xParent );
140 0 : if( xParent.is())
141 : {
142 0 : Reference< XAccessibleComponent > xContext( xParent->getAccessibleContext(), uno::UNO_QUERY );
143 0 : if( xContext.is())
144 : {
145 0 : awt::Point aParentPosition = xContext->getLocationOnScreen();
146 0 : aResult.X -= aParentPosition.X;
147 0 : aResult.Y -= aParentPosition.Y;
148 0 : }
149 : }
150 0 : return aResult;
151 : }
152 :
153 0 : awt::Point SAL_CALL AccessibleChartView::getLocationOnScreen()
154 : throw (uno::RuntimeException, std::exception)
155 : {
156 0 : awt::Rectangle aBounds( getBounds());
157 0 : awt::Point aResult;
158 0 : Reference< XAccessible > xParent( m_xParent );
159 0 : if( xParent.is())
160 : {
161 : Reference< XAccessibleComponent > xAccComp(
162 0 : xParent->getAccessibleContext(), uno::UNO_QUERY );
163 0 : aResult = xAccComp->getLocationOnScreen();
164 0 : aResult.X += aBounds.X;
165 0 : aResult.Y += aBounds.Y;
166 : }
167 0 : return aResult;
168 : }
169 :
170 : // lang::XInitialization
171 :
172 0 : void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments )
173 : throw (uno::Exception, uno::RuntimeException, std::exception)
174 : {
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
178 :
179 : //all arguments are only valid until next initialization
180 0 : bool bChanged = false;
181 0 : bool bOldInvalid = false;
182 0 : bool bNewInvalid = false;
183 :
184 0 : Reference< view::XSelectionSupplier > xSelectionSupplier;
185 0 : Reference< frame::XModel > xChartModel;
186 0 : Reference< uno::XInterface > xChartView;
187 0 : Reference< XAccessible > xParent;
188 0 : Reference< awt::XWindow > xWindow;
189 : {
190 0 : MutexGuard aGuard( GetMutex());
191 0 : xSelectionSupplier.set( m_xSelectionSupplier );
192 0 : xChartModel.set( m_xChartModel );
193 0 : xChartView.set( m_xChartView );
194 0 : xParent.set( m_xParent );
195 0 : xWindow.set( m_xWindow );
196 : }
197 :
198 0 : if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
199 : {
200 0 : bOldInvalid = true;
201 : }
202 :
203 0 : if( rArguments.getLength() > 1 )
204 : {
205 0 : Reference< frame::XModel > xNewChartModel;
206 0 : rArguments[1] >>= xNewChartModel;
207 0 : if( xNewChartModel != xChartModel )
208 : {
209 0 : xChartModel = xNewChartModel;
210 0 : bChanged = true;
211 0 : }
212 : }
213 0 : else if( xChartModel.is() )
214 : {
215 0 : bChanged = true;
216 0 : xChartModel = 0;
217 : }
218 :
219 0 : if( rArguments.getLength() > 2 )
220 : {
221 0 : Reference< uno::XInterface > xNewChartView;
222 0 : rArguments[2] >>= xNewChartView;
223 0 : if( xNewChartView != xChartView )
224 : {
225 0 : xChartView = xNewChartView;
226 0 : bChanged = true;
227 0 : }
228 : }
229 0 : else if( xChartView.is() )
230 : {
231 0 : bChanged = true;
232 0 : xChartView = 0;
233 : }
234 :
235 0 : if( rArguments.getLength() > 3 )
236 : {
237 0 : Reference< XAccessible > xNewParent;
238 0 : rArguments[3] >>= xNewParent;
239 0 : if( xNewParent != xParent )
240 : {
241 0 : xParent = xNewParent;
242 0 : bChanged = true;
243 0 : }
244 : }
245 :
246 0 : if( rArguments.getLength() > 4 )
247 : {
248 0 : Reference< awt::XWindow > xNewWindow;
249 0 : rArguments[4] >>= xNewWindow;
250 0 : if( xNewWindow != xWindow )
251 : {
252 0 : xWindow.set( xNewWindow );
253 0 : bChanged = true;
254 0 : }
255 : }
256 :
257 0 : if( rArguments.getLength() > 0 && xChartModel.is() && xChartView.is() )
258 : {
259 0 : Reference< view::XSelectionSupplier > xNewSelectionSupplier;
260 0 : rArguments[0] >>= xNewSelectionSupplier;
261 0 : if(xSelectionSupplier!=xNewSelectionSupplier)
262 : {
263 0 : bChanged = true;
264 0 : if(xSelectionSupplier.is())
265 0 : xSelectionSupplier->removeSelectionChangeListener(this);
266 0 : if(xNewSelectionSupplier.is())
267 0 : xNewSelectionSupplier->addSelectionChangeListener(this);
268 0 : xSelectionSupplier = xNewSelectionSupplier;
269 0 : }
270 : }
271 0 : else if( xSelectionSupplier.is() )
272 : {
273 0 : bChanged = true;
274 0 : xSelectionSupplier->removeSelectionChangeListener(this);
275 0 : xSelectionSupplier = 0;
276 : }
277 :
278 0 : if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
279 : {
280 0 : if(xSelectionSupplier.is())
281 0 : xSelectionSupplier->removeSelectionChangeListener(this);
282 0 : xSelectionSupplier = 0;
283 0 : xChartModel.clear();
284 0 : xChartView.clear();
285 0 : xParent.clear();
286 0 : xWindow.clear();
287 :
288 0 : bNewInvalid = true;
289 : }
290 :
291 : {
292 0 : MutexGuard aGuard( GetMutex());
293 0 : m_xSelectionSupplier = WeakReference< view::XSelectionSupplier >(xSelectionSupplier);
294 0 : m_xChartModel = WeakReference< frame::XModel >(xChartModel);
295 0 : m_xChartView = WeakReference< uno::XInterface >(xChartView);
296 0 : m_xParent = WeakReference< XAccessible >(xParent);
297 0 : m_xWindow = WeakReference< awt::XWindow >(xWindow);
298 : }
299 :
300 0 : if( bOldInvalid && bNewInvalid )
301 0 : bChanged = false;
302 :
303 0 : if( bChanged )
304 : {
305 : {
306 : //before notification we prepare for creation of new context
307 : //the old context will be deleted after notification than
308 0 : MutexGuard aGuard( GetMutex());
309 0 : Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
310 0 : if( xChartDoc.is())
311 0 : m_spObjectHierarchy.reset( new ObjectHierarchy( xChartDoc, getExplicitValueProvider() ));
312 : else
313 0 : m_spObjectHierarchy.reset();
314 : }
315 :
316 : {
317 0 : AccessibleElementInfo aAccInfo;
318 0 : aAccInfo.m_aOID = ObjectIdentifier("ROOT");
319 0 : aAccInfo.m_xChartDocument = uno::WeakReference< chart2::XChartDocument >(
320 0 : uno::Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY ));
321 0 : aAccInfo.m_xSelectionSupplier = m_xSelectionSupplier;
322 0 : aAccInfo.m_xView = m_xChartView;
323 0 : aAccInfo.m_xWindow = m_xWindow;
324 0 : aAccInfo.m_pParent = 0;
325 0 : aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy;
326 0 : aAccInfo.m_pSdrView = m_pSdrView;
327 0 : vcl::Window* pWindow = VCLUnoHelper::GetWindow( m_xWindow );
328 0 : if ( m_pViewForwarder )
329 : {
330 0 : delete m_pViewForwarder;
331 : }
332 0 : m_pViewForwarder = new AccessibleViewForwarder( this, pWindow );
333 0 : aAccInfo.m_pViewForwarder = m_pViewForwarder;
334 : // broadcasts an INVALIDATE_ALL_CHILDREN event globally
335 0 : SetInfo( aAccInfo );
336 : }
337 0 : }
338 0 : }
339 :
340 0 : ExplicitValueProvider* AccessibleChartView::getExplicitValueProvider()
341 : {
342 0 : return ExplicitValueProvider::getExplicitValueProvider(m_xChartView);
343 : }
344 :
345 : // view::XSelectionChangeListener
346 :
347 0 : void SAL_CALL AccessibleChartView::selectionChanged( const lang::EventObject& /*rEvent*/ )
348 : throw (uno::RuntimeException, std::exception)
349 : {
350 0 : Reference< view::XSelectionSupplier > xSelectionSupplier;
351 : {
352 0 : MutexGuard aGuard( GetMutex());
353 0 : xSelectionSupplier = Reference< view::XSelectionSupplier >(m_xSelectionSupplier);
354 : }
355 :
356 0 : if( xSelectionSupplier.is() )
357 : {
358 0 : ObjectIdentifier aSelectedOID( xSelectionSupplier->getSelection() );
359 0 : if ( m_aCurrentSelectionOID.isValid() )
360 : {
361 0 : NotifyEvent( LOST_SELECTION, m_aCurrentSelectionOID );
362 : }
363 0 : if( aSelectedOID.isValid() )
364 : {
365 0 : NotifyEvent( GOT_SELECTION, aSelectedOID );
366 : }
367 0 : m_aCurrentSelectionOID = aSelectedOID;
368 0 : }
369 0 : }
370 :
371 : // lang::XComponent::dispose()
372 0 : void SAL_CALL AccessibleChartView::disposing()
373 : {
374 0 : AccessibleBase::disposing();
375 0 : }
376 :
377 : // XEventListener
378 0 : void SAL_CALL AccessibleChartView::disposing( const lang::EventObject& /*Source*/ )
379 : throw (uno::RuntimeException, std::exception)
380 : {
381 0 : }
382 :
383 102 : } //namespace chart
384 :
385 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|