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/accessibility/AccessibleEventId.hpp>
21 
22 #include <sal/log.hxx>
23 #include <vcl/svapp.hxx>
24 #include <Window.hxx>
25 #include <OutlineViewShell.hxx>
26 #include <DrawDocShell.hxx>
27 #include <OutlineView.hxx>
28 #include <View.hxx>
29 #include <AccessibleOutlineView.hxx>
30 #include <AccessibleOutlineEditSource.hxx>
31 #include <drawdoc.hxx>
32 #include <strings.hrc>
33 #include <sdresid.hxx>
34 
35 #include <memory>
36 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::accessibility;
39 
40 namespace accessibility {
41 
42 //=====  internal  ============================================================
43 
AccessibleOutlineView(::sd::Window * pSdWindow,::sd::OutlineViewShell * pViewShell,const uno::Reference<frame::XController> & rxController,const uno::Reference<XAccessible> & rxParent)44 AccessibleOutlineView::AccessibleOutlineView (
45     ::sd::Window* pSdWindow,
46     ::sd::OutlineViewShell* pViewShell,
47     const uno::Reference<frame::XController>& rxController,
48     const uno::Reference<XAccessible>& rxParent)
49     : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
50       maTextHelper( ::std::unique_ptr< SvxEditSource >() )
51 {
52     SolarMutexGuard aGuard;
53 
54     // Beware! Here we leave the paths of the UNO API and descend into the
55     // depths of the core.  Necessary for making the edit engine accessible.
56     if (!pSdWindow)
57         return;
58 
59     ::sd::View* pView = pViewShell->GetView();
60 
61     if (dynamic_cast<const ::sd::OutlineView* >( pView ) ==  nullptr)
62         return;
63 
64     OutlinerView* pOutlineView = static_cast< ::sd::OutlineView*>(
65         pView)->GetViewByWindow( pSdWindow );
66     SdrOutliner& rOutliner =
67         static_cast< ::sd::OutlineView*>(pView)->GetOutliner();
68 
69     if( pOutlineView )
70     {
71         maTextHelper.SetEditSource( ::std::unique_ptr< SvxEditSource >( new AccessibleOutlineEditSource(
72                                                                           rOutliner, *pView, *pOutlineView, *pSdWindow ) ) );
73     }
74 }
75 
~AccessibleOutlineView()76 AccessibleOutlineView::~AccessibleOutlineView()
77 {
78 }
79 
Init()80 void AccessibleOutlineView::Init()
81 {
82     // Set event source _before_ starting to listen
83     maTextHelper.SetEventSource(this);
84 
85     AccessibleDocumentViewBase::Init ();
86 }
87 
ViewForwarderChanged()88 void AccessibleOutlineView::ViewForwarderChanged()
89 {
90     AccessibleDocumentViewBase::ViewForwarderChanged();
91 
92     UpdateChildren();
93 }
94 
95 //=====  XAccessibleContext  ==================================================
96 
97 sal_Int32 SAL_CALL
getAccessibleChildCount()98     AccessibleOutlineView::getAccessibleChildCount()
99 {
100     ThrowIfDisposed ();
101 
102     // forward
103     return maTextHelper.GetChildCount();
104 }
105 
106 uno::Reference<XAccessible> SAL_CALL
getAccessibleChild(sal_Int32 nIndex)107     AccessibleOutlineView::getAccessibleChild (sal_Int32 nIndex)
108 {
109     ThrowIfDisposed ();
110     // Forward request to children manager.
111     return maTextHelper.GetChild(nIndex);
112 }
113 
114 OUString SAL_CALL
getAccessibleName()115     AccessibleOutlineView::getAccessibleName()
116 {
117     SolarMutexGuard g;
118 
119     OUString sName = SdResId(SID_SD_A11Y_D_PRESENTATION);
120     ::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
121     if ( pSdView )
122     {
123         SdDrawDocument& rDoc = pSdView->GetDoc();
124         OUString sFileName = rDoc.getDocAccTitle();
125         if (sFileName.isEmpty())
126         {
127             ::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
128             if ( pDocSh )
129             {
130                 sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
131             }
132         }
133         if (!sFileName.isEmpty())
134         {
135             sName = sFileName + " - " + sName;
136         }
137     }
138     return sName;
139 }
140 
141 //=====  XAccessibleEventBroadcaster  ========================================
142 
addAccessibleEventListener(const uno::Reference<XAccessibleEventListener> & xListener)143 void SAL_CALL AccessibleOutlineView::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
144 {
145     // delegate listener handling to children manager.
146     if ( ! IsDisposed())
147         maTextHelper.AddEventListener(xListener);
148     AccessibleContextBase::addEventListener(xListener);
149 }
150 
removeAccessibleEventListener(const uno::Reference<XAccessibleEventListener> & xListener)151 void SAL_CALL AccessibleOutlineView::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
152 {
153     // forward
154     if ( ! IsDisposed())
155         maTextHelper.RemoveEventListener(xListener);
156     AccessibleContextBase::removeEventListener(xListener);
157 }
158 
159 // XServiceInfo
160 
161 OUString SAL_CALL
getImplementationName()162     AccessibleOutlineView::getImplementationName()
163 {
164     return "AccessibleOutlineView";
165 }
166 
167 //=====  XEventListener  ======================================================
168 
169 //=====  protected internal  ==================================================
170 
Activated()171 void AccessibleOutlineView::Activated()
172 {
173     SolarMutexGuard aGuard;
174 
175     // delegate listener handling to children manager.
176     maTextHelper.SetFocus();
177 }
178 
Deactivated()179 void AccessibleOutlineView::Deactivated()
180 {
181     SolarMutexGuard aGuard;
182 
183     // delegate listener handling to children manager.
184     maTextHelper.SetFocus(false);
185 }
186 
disposing()187 void SAL_CALL AccessibleOutlineView::disposing()
188 {
189     // dispose children
190     maTextHelper.Dispose();
191 
192     AccessibleDocumentViewBase::disposing ();
193 }
194 
195 //=====  XPropertyChangeListener  =============================================
196 
197 void SAL_CALL
propertyChange(const beans::PropertyChangeEvent & rEventObject)198     AccessibleOutlineView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
199 {
200     ThrowIfDisposed ();
201 
202     AccessibleDocumentViewBase::propertyChange (rEventObject);
203 
204     //add page switch event for slide show mode
205     if (rEventObject.PropertyName == "CurrentPage" ||
206         rEventObject.PropertyName == "PageChange")
207     {
208         // The current page changed. Update the children accordingly.
209         UpdateChildren();
210         CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue, rEventObject.OldValue);
211     }
212     else if ( rEventObject.PropertyName == "VisibleArea" )
213     {
214         // The visible area changed. Update the children accordingly.
215         UpdateChildren();
216     }
217     else
218     {
219         SAL_INFO("sd", "unhandled");
220     }
221 }
222 
223 /// Create a name for this view.
224 OUString
CreateAccessibleName()225     AccessibleOutlineView::CreateAccessibleName()
226 {
227     SolarMutexGuard aGuard;
228 
229     return SdResId(SID_SD_A11Y_I_OUTLINEVIEW_N);
230 }
231 
UpdateChildren()232 void AccessibleOutlineView::UpdateChildren()
233 {
234     SolarMutexGuard aGuard;
235 
236     // Update visible children
237     maTextHelper.UpdateChildren();
238 }
239 
240 } // end of namespace accessibility
241 
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
243