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 <com/sun/star/drawing/XDrawPage.hpp>
21 : #include <com/sun/star/drawing/XDrawView.hpp>
22 : #include <com/sun/star/drawing/XShapes.hpp>
23 : #include <com/sun/star/container/XChild.hpp>
24 : #include <com/sun/star/frame/XController.hpp>
25 : #include <com/sun/star/frame/XFrame.hpp>
26 : #include <com/sun/star/document/XEventBroadcaster.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 : #include <rtl/ustring.h>
32 : #include <sfx2/viewfrm.hxx>
33 :
34 : #include <svx/AccessibleShape.hxx>
35 :
36 : #include <svx/svdobj.hxx>
37 : #include <svx/svdmodel.hxx>
38 : #include <svx/unoapi.hxx>
39 : #include <toolkit/helper/vclunohelper.hxx>
40 : #include <vcl/svapp.hxx>
41 : #include "Window.hxx"
42 : #include "ViewShell.hxx"
43 : #include "OutlineViewShell.hxx"
44 : #include "View.hxx"
45 : #include "AccessibleOutlineView.hxx"
46 : #include "AccessibleOutlineEditSource.hxx"
47 :
48 : #include <memory>
49 :
50 : #include "accessibility.hrc"
51 : #include "sdresid.hxx"
52 : #include <osl/mutex.hxx>
53 :
54 : using namespace ::com::sun::star;
55 : using namespace ::com::sun::star::accessibility;
56 :
57 : namespace accessibility {
58 :
59 : //===== internal ============================================================
60 :
61 0 : AccessibleOutlineView::AccessibleOutlineView (
62 : ::sd::Window* pSdWindow,
63 : ::sd::OutlineViewShell* pViewShell,
64 : const uno::Reference<frame::XController>& rxController,
65 : const uno::Reference<XAccessible>& rxParent)
66 : : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
67 0 : maTextHelper( ::std::unique_ptr< SvxEditSource >() )
68 : {
69 0 : SolarMutexGuard aGuard;
70 :
71 : // Beware! Here we leave the paths of the UNO API and descend into the
72 : // depths of the core. Necessary for making the edit engine accessible.
73 0 : if (pSdWindow)
74 : {
75 0 : ::sd::View* pView = pViewShell->GetView();
76 :
77 0 : if (pView && pView->ISA(::sd::OutlineView))
78 : {
79 : OutlinerView* pOutlineView = static_cast< ::sd::OutlineView*>(
80 0 : pView)->GetViewByWindow( pSdWindow );
81 : SdrOutliner& rOutliner =
82 0 : static_cast< ::sd::OutlineView*>(pView)->GetOutliner();
83 :
84 0 : if( pOutlineView )
85 : {
86 : maTextHelper.SetEditSource( ::std::unique_ptr< SvxEditSource >( new AccessibleOutlineEditSource(
87 0 : rOutliner, *pView, *pOutlineView, *pSdWindow ) ) );
88 : }
89 : }
90 0 : }
91 0 : }
92 :
93 0 : AccessibleOutlineView::~AccessibleOutlineView()
94 : {
95 : OSL_TRACE ("~AccessibleOutlineView");
96 0 : }
97 :
98 0 : void AccessibleOutlineView::Init()
99 : {
100 : // Set event source _before_ starting to listen
101 0 : maTextHelper.SetEventSource(this);
102 :
103 0 : AccessibleDocumentViewBase::Init ();
104 0 : }
105 :
106 0 : void AccessibleOutlineView::ViewForwarderChanged (ChangeType aChangeType,
107 : const IAccessibleViewForwarder* pViewForwarder)
108 : {
109 0 : AccessibleDocumentViewBase::ViewForwarderChanged (aChangeType, pViewForwarder);
110 :
111 0 : UpdateChildren();
112 0 : }
113 :
114 : //===== XAccessibleContext ==================================================
115 :
116 : sal_Int32 SAL_CALL
117 0 : AccessibleOutlineView::getAccessibleChildCount()
118 : throw (uno::RuntimeException, std::exception)
119 : {
120 0 : ThrowIfDisposed ();
121 :
122 : // forward
123 0 : return maTextHelper.GetChildCount();
124 : }
125 :
126 : uno::Reference<XAccessible> SAL_CALL
127 0 : AccessibleOutlineView::getAccessibleChild (sal_Int32 nIndex)
128 : throw (::com::sun::star::uno::RuntimeException, std::exception)
129 : {
130 0 : ThrowIfDisposed ();
131 : // Forward request to children manager.
132 0 : return maTextHelper.GetChild(nIndex);
133 : }
134 :
135 : #include <drawdoc.hxx>
136 :
137 : OUString SAL_CALL
138 0 : AccessibleOutlineView::getAccessibleName()
139 : throw (::com::sun::star::uno::RuntimeException, std::exception)
140 : {
141 0 : SolarMutexGuard g;
142 :
143 0 : OUString sName = SdResId(SID_SD_A11Y_D_PRESENTATION);
144 0 : ::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
145 0 : if ( pSdView )
146 : {
147 0 : SdDrawDocument& rDoc = pSdView->GetDoc();
148 0 : rtl::OUString sFileName = rDoc.getDocAccTitle();
149 0 : if (sFileName.isEmpty())
150 : {
151 0 : ::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
152 0 : if ( pDocSh )
153 : {
154 0 : sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
155 : }
156 : }
157 0 : if (!sFileName.isEmpty())
158 : {
159 0 : sName = sFileName + " - " + sName;
160 0 : }
161 : }
162 0 : return sName;
163 : }
164 :
165 : //===== XAccessibleEventBroadcaster ========================================
166 :
167 0 : void SAL_CALL AccessibleOutlineView::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException, std::exception)
168 : {
169 : // delegate listener handling to children manager.
170 0 : if ( ! IsDisposed())
171 0 : maTextHelper.AddEventListener(xListener);
172 0 : AccessibleContextBase::addEventListener(xListener);
173 0 : }
174 :
175 0 : void SAL_CALL AccessibleOutlineView::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException, std::exception)
176 : {
177 : // forward
178 0 : if ( ! IsDisposed())
179 0 : maTextHelper.RemoveEventListener(xListener);
180 0 : AccessibleContextBase::removeEventListener(xListener);
181 0 : }
182 :
183 : // XServiceInfo
184 :
185 : OUString SAL_CALL
186 0 : AccessibleOutlineView::getImplementationName()
187 : throw (::com::sun::star::uno::RuntimeException, std::exception)
188 : {
189 0 : return OUString("AccessibleOutlineView");
190 : }
191 :
192 : //===== XEventListener ======================================================
193 :
194 : void SAL_CALL
195 0 : AccessibleOutlineView::disposing (const lang::EventObject& rEventObject)
196 : throw (::com::sun::star::uno::RuntimeException, std::exception)
197 : {
198 0 : AccessibleDocumentViewBase::disposing (rEventObject);
199 0 : }
200 :
201 : //===== protected internal ==================================================
202 :
203 0 : void AccessibleOutlineView::Activated()
204 : {
205 0 : SolarMutexGuard aGuard;
206 :
207 : // delegate listener handling to children manager.
208 0 : maTextHelper.SetFocus(true);
209 0 : }
210 :
211 0 : void AccessibleOutlineView::Deactivated()
212 : {
213 0 : SolarMutexGuard aGuard;
214 :
215 : // delegate listener handling to children manager.
216 0 : maTextHelper.SetFocus(false);
217 0 : }
218 :
219 0 : void SAL_CALL AccessibleOutlineView::disposing()
220 : {
221 : // dispose children
222 0 : maTextHelper.Dispose();
223 :
224 0 : AccessibleDocumentViewBase::disposing ();
225 0 : }
226 :
227 : //===== XPropertyChangeListener =============================================
228 :
229 : void SAL_CALL
230 0 : AccessibleOutlineView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
231 : throw (::com::sun::star::uno::RuntimeException, std::exception)
232 : {
233 0 : ThrowIfDisposed ();
234 :
235 0 : AccessibleDocumentViewBase::propertyChange (rEventObject);
236 :
237 : OSL_TRACE ("AccessibleOutlineView::propertyChange");
238 : //add page switch event for slide show mode
239 0 : if (rEventObject.PropertyName == "CurrentPage" ||
240 0 : rEventObject.PropertyName == "PageChange")
241 : {
242 : OSL_TRACE (" current page changed");
243 :
244 : // The current page changed. Update the children accordingly.
245 0 : UpdateChildren();
246 0 : CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue, rEventObject.OldValue);
247 : }
248 0 : else if ( rEventObject.PropertyName == "VisibleArea" )
249 : {
250 : OSL_TRACE (" visible area changed");
251 :
252 : // The visible area changed. Update the children accordingly.
253 0 : UpdateChildren();
254 : }
255 : else
256 : {
257 : OSL_TRACE (" unhandled");
258 : }
259 : OSL_TRACE (" done");
260 0 : }
261 :
262 : /// Create a name for this view.
263 : OUString
264 0 : AccessibleOutlineView::CreateAccessibleName()
265 : throw (::com::sun::star::uno::RuntimeException)
266 : {
267 0 : SolarMutexGuard aGuard;
268 :
269 0 : return SD_RESSTR(SID_SD_A11Y_I_OUTLINEVIEW_N);
270 : }
271 :
272 : /** Create a description for this view. Use the model's description or URL
273 : if a description is not available.
274 : */
275 : OUString
276 0 : AccessibleOutlineView::CreateAccessibleDescription()
277 : throw (::com::sun::star::uno::RuntimeException)
278 : {
279 0 : SolarMutexGuard aGuard;
280 :
281 0 : return SD_RESSTR(SID_SD_A11Y_I_OUTLINEVIEW_D);
282 : }
283 :
284 0 : void AccessibleOutlineView::UpdateChildren()
285 : {
286 0 : SolarMutexGuard aGuard;
287 :
288 : // Update visible children
289 0 : maTextHelper.UpdateChildren();
290 0 : }
291 :
292 66 : } // end of namespace accessibility
293 :
294 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|