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