Debian Codegraph @

chart2/source/controller/accessibility/AccessibleChartView.cxx

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