bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleOutlineView.cxx
blobdbe9323c0137d9b6267cb53c6f1120337025c0e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 #include <svx/AccessibleShape.hxx>
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"
48 #include <memory>
50 #include "accessibility.hrc"
51 #include "sdresid.hxx"
52 #include <osl/mutex.hxx>
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::accessibility;
57 namespace accessibility {
59 //===== internal ============================================================
61 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 maTextHelper( ::std::unique_ptr< SvxEditSource >() )
69 SolarMutexGuard aGuard;
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 if (pSdWindow)
75 ::sd::View* pView = pViewShell->GetView();
77 if (pView && pView->ISA(::sd::OutlineView))
79 OutlinerView* pOutlineView = static_cast< ::sd::OutlineView*>(
80 pView)->GetViewByWindow( pSdWindow );
81 SdrOutliner& rOutliner =
82 static_cast< ::sd::OutlineView*>(pView)->GetOutliner();
84 if( pOutlineView )
86 maTextHelper.SetEditSource( ::std::unique_ptr< SvxEditSource >( new AccessibleOutlineEditSource(
87 rOutliner, *pView, *pOutlineView, *pSdWindow ) ) );
93 AccessibleOutlineView::~AccessibleOutlineView()
95 OSL_TRACE ("~AccessibleOutlineView");
98 void AccessibleOutlineView::Init()
100 // Set event source _before_ starting to listen
101 maTextHelper.SetEventSource(this);
103 AccessibleDocumentViewBase::Init ();
106 void AccessibleOutlineView::ViewForwarderChanged (ChangeType aChangeType,
107 const IAccessibleViewForwarder* pViewForwarder)
109 AccessibleDocumentViewBase::ViewForwarderChanged (aChangeType, pViewForwarder);
111 UpdateChildren();
114 //===== XAccessibleContext ==================================================
116 sal_Int32 SAL_CALL
117 AccessibleOutlineView::getAccessibleChildCount()
118 throw (uno::RuntimeException, std::exception)
120 ThrowIfDisposed ();
122 // forward
123 return maTextHelper.GetChildCount();
126 uno::Reference<XAccessible> SAL_CALL
127 AccessibleOutlineView::getAccessibleChild (sal_Int32 nIndex)
128 throw (::com::sun::star::uno::RuntimeException, std::exception)
130 ThrowIfDisposed ();
131 // Forward request to children manager.
132 return maTextHelper.GetChild(nIndex);
135 #include <drawdoc.hxx>
137 OUString SAL_CALL
138 AccessibleOutlineView::getAccessibleName()
139 throw (::com::sun::star::uno::RuntimeException, std::exception)
141 SolarMutexGuard g;
143 OUString sName = SdResId(SID_SD_A11Y_D_PRESENTATION);
144 ::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
145 if ( pSdView )
147 SdDrawDocument& rDoc = pSdView->GetDoc();
148 rtl::OUString sFileName = rDoc.getDocAccTitle();
149 if (sFileName.isEmpty())
151 ::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
152 if ( pDocSh )
154 sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
157 if (!sFileName.isEmpty())
159 sName = sFileName + " - " + sName;
162 return sName;
165 //===== XAccessibleEventBroadcaster ========================================
167 void SAL_CALL AccessibleOutlineView::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException, std::exception)
169 // delegate listener handling to children manager.
170 if ( ! IsDisposed())
171 maTextHelper.AddEventListener(xListener);
172 AccessibleContextBase::addEventListener(xListener);
175 void SAL_CALL AccessibleOutlineView::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException, std::exception)
177 // forward
178 if ( ! IsDisposed())
179 maTextHelper.RemoveEventListener(xListener);
180 AccessibleContextBase::removeEventListener(xListener);
183 // XServiceInfo
185 OUString SAL_CALL
186 AccessibleOutlineView::getImplementationName()
187 throw (::com::sun::star::uno::RuntimeException, std::exception)
189 return OUString("AccessibleOutlineView");
192 //===== XEventListener ======================================================
194 void SAL_CALL
195 AccessibleOutlineView::disposing (const lang::EventObject& rEventObject)
196 throw (::com::sun::star::uno::RuntimeException, std::exception)
198 AccessibleDocumentViewBase::disposing (rEventObject);
201 //===== protected internal ==================================================
203 void AccessibleOutlineView::Activated()
205 SolarMutexGuard aGuard;
207 // delegate listener handling to children manager.
208 maTextHelper.SetFocus(true);
211 void AccessibleOutlineView::Deactivated()
213 SolarMutexGuard aGuard;
215 // delegate listener handling to children manager.
216 maTextHelper.SetFocus(false);
219 void SAL_CALL AccessibleOutlineView::disposing()
221 // dispose children
222 maTextHelper.Dispose();
224 AccessibleDocumentViewBase::disposing ();
227 //===== XPropertyChangeListener =============================================
229 void SAL_CALL
230 AccessibleOutlineView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
231 throw (::com::sun::star::uno::RuntimeException, std::exception)
233 ThrowIfDisposed ();
235 AccessibleDocumentViewBase::propertyChange (rEventObject);
237 OSL_TRACE ("AccessibleOutlineView::propertyChange");
238 //add page switch event for slide show mode
239 if (rEventObject.PropertyName == "CurrentPage" ||
240 rEventObject.PropertyName == "PageChange")
242 OSL_TRACE (" current page changed");
244 // The current page changed. Update the children accordingly.
245 UpdateChildren();
246 CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue, rEventObject.OldValue);
248 else if ( rEventObject.PropertyName == "VisibleArea" )
250 OSL_TRACE (" visible area changed");
252 // The visible area changed. Update the children accordingly.
253 UpdateChildren();
255 else
257 OSL_TRACE (" unhandled");
259 OSL_TRACE (" done");
262 /// Create a name for this view.
263 OUString
264 AccessibleOutlineView::CreateAccessibleName()
265 throw (::com::sun::star::uno::RuntimeException)
267 SolarMutexGuard aGuard;
269 return SD_RESSTR(SID_SD_A11Y_I_OUTLINEVIEW_N);
272 /** Create a description for this view. Use the model's description or URL
273 if a description is not available.
275 OUString
276 AccessibleOutlineView::CreateAccessibleDescription()
277 throw (::com::sun::star::uno::RuntimeException)
279 SolarMutexGuard aGuard;
281 return SD_RESSTR(SID_SD_A11Y_I_OUTLINEVIEW_D);
284 void AccessibleOutlineView::UpdateChildren()
286 SolarMutexGuard aGuard;
288 // Update visible children
289 maTextHelper.UpdateChildren();
292 } // end of namespace accessibility
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */