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