1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include <com/sun/star/drawing/XDrawPage.hpp>
31 #include <com/sun/star/drawing/XDrawView.hpp>
32 #include <com/sun/star/drawing/XShapes.hpp>
33 #include <com/sun/star/container/XChild.hpp>
34 #include <com/sun/star/frame/XController.hpp>
35 #include <com/sun/star/frame/XFrame.hpp>
36 #include <com/sun/star/document/XEventBroadcaster.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #ifndef _COM_SUN_STAR_ACCESSIBLE_ACCESSIBLEEVENTID_HPP_
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 #endif
41 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
42 #ifndef	_COM_SUN_STAR_LANG_XMULSTISERVICEFACTORY_HPP_
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #endif
45 #include <rtl/ustring.h>
46 #ifndef _SFXFRAME_HXX
47 #include<sfx2/viewfrm.hxx>
48 #endif
49 
50 #include <svx/AccessibleShape.hxx>
51 
52 #include <svx/svdobj.hxx>
53 #include <svx/svdmodel.hxx>
54 #include <svx/unoapi.hxx>
55 #include <toolkit/helper/vclunohelper.hxx>
56 #include <vcl/svapp.hxx>
57 #include "Window.hxx"
58 #include "ViewShell.hxx"
59 #include "OutlineViewShell.hxx"
60 #include "View.hxx"
61 #include "AccessibleOutlineView.hxx"
62 #include "AccessibleOutlineEditSource.hxx"
63 
64 #include <memory>
65 
66 #include "accessibility.hrc"
67 #include "sdresid.hxx"
68 #include <vos/mutex.hxx>
69 
70 using namespace ::com::sun::star;
71 using namespace	::com::sun::star::accessibility;
72 
73 namespace accessibility {
74 
75 
76 //=====  internal  ============================================================
77 
78 AccessibleOutlineView::AccessibleOutlineView (
79     ::sd::Window* pSdWindow,
80     ::sd::OutlineViewShell* pViewShell,
81     const uno::Reference<frame::XController>& rxController,
82     const uno::Reference<XAccessible>& rxParent)
83     : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
84       maTextHelper( ::std::auto_ptr< SvxEditSource >( NULL ) )
85 {
86     ::vos::OGuard aGuard( Application::GetSolarMutex() );
87 
88     // Beware! Here we leave the paths of the UNO API and descend into the
89     // depths of the core.  Necessary for making the edit engine accessible.
90     if( pViewShell && pSdWindow )
91     {
92         ::sd::View* pView = pViewShell->GetView();
93 
94         if (pView && pView->ISA(::sd::OutlineView))
95         {
96             OutlinerView* pOutlineView = static_cast< ::sd::OutlineView*>(
97                 pView)->GetViewByWindow( pSdWindow );
98             SdrOutliner* pOutliner =
99                 static_cast< ::sd::OutlineView*>(pView)->GetOutliner();
100 
101             if( pOutlineView && pOutliner )
102             {
103                 maTextHelper.SetEditSource( ::std::auto_ptr< SvxEditSource >( new AccessibleOutlineEditSource(
104                                                                                   *pOutliner, *pView, *pOutlineView, *pSdWindow ) ) );
105             }
106         }
107     }
108 }
109 
110 
111 AccessibleOutlineView::~AccessibleOutlineView (void)
112 {
113     OSL_TRACE ("~AccessibleOutlineView");
114 }
115 
116 
117 void AccessibleOutlineView::Init (void)
118 {
119     // #105479# Set event source _before_ starting to listen
120     maTextHelper.SetEventSource(this);
121 
122     AccessibleDocumentViewBase::Init ();
123 }
124 
125 
126 void AccessibleOutlineView::ViewForwarderChanged (ChangeType aChangeType,
127     const IAccessibleViewForwarder* pViewForwarder)
128 {
129     AccessibleDocumentViewBase::ViewForwarderChanged (aChangeType, pViewForwarder);
130 
131     UpdateChildren();
132 }
133 
134 
135 //=====  XAccessibleContext  ==================================================
136 
137 sal_Int32 SAL_CALL
138     AccessibleOutlineView::getAccessibleChildCount (void)
139     throw (uno::RuntimeException)
140 {
141     ThrowIfDisposed ();
142 
143     // forward
144     return maTextHelper.GetChildCount();
145 }
146 
147 
148 uno::Reference<XAccessible> SAL_CALL
149     AccessibleOutlineView::getAccessibleChild (sal_Int32 nIndex)
150     throw (::com::sun::star::uno::RuntimeException)
151 {
152     ThrowIfDisposed ();
153     // Forward request to children manager.
154     return maTextHelper.GetChild(nIndex);
155 }
156 
157 //=====  XAccessibleEventBroadcaster  ========================================
158 
159 void SAL_CALL AccessibleOutlineView::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
160 {
161     // delegate listener handling to children manager.
162     if ( ! IsDisposed())
163         maTextHelper.AddEventListener(xListener);
164 }
165 
166 void SAL_CALL AccessibleOutlineView::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
167 {
168     // forward
169     if ( ! IsDisposed())
170         maTextHelper.RemoveEventListener(xListener);
171 }
172 
173 //=====  XServiceInfo  ========================================================
174 
175 ::rtl::OUString SAL_CALL
176     AccessibleOutlineView::getImplementationName (void)
177     throw (::com::sun::star::uno::RuntimeException)
178 {
179 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleOutlineView"));
180 }
181 
182 
183 //=====  XEventListener  ======================================================
184 
185 void SAL_CALL
186     AccessibleOutlineView::disposing (const lang::EventObject& rEventObject)
187     throw (::com::sun::star::uno::RuntimeException)
188 {
189     AccessibleDocumentViewBase::disposing (rEventObject);
190 }
191 
192 //=====  protected internal  ==================================================
193 
194 void AccessibleOutlineView::FireEvent(const AccessibleEventObject& aEvent )
195 {
196     // delegate listener handling to children manager.
197     maTextHelper.FireEvent(aEvent);
198 }
199 
200 void AccessibleOutlineView::Activated (void)
201 {
202     ::vos::OGuard aGuard( Application::GetSolarMutex() );
203 
204     // delegate listener handling to children manager.
205     maTextHelper.SetFocus(sal_True);
206 }
207 
208 void AccessibleOutlineView::Deactivated (void)
209 {
210     ::vos::OGuard aGuard( Application::GetSolarMutex() );
211 
212     // delegate listener handling to children manager.
213     maTextHelper.SetFocus(sal_False);
214 }
215 
216 void SAL_CALL AccessibleOutlineView::disposing (void)
217 {
218     // dispose children
219     maTextHelper.Dispose();
220 
221     AccessibleDocumentViewBase::disposing ();
222 }
223 
224 //=====  XPropertyChangeListener  =============================================
225 
226 void SAL_CALL
227     AccessibleOutlineView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
228     throw (::com::sun::star::uno::RuntimeException)
229 {
230     ThrowIfDisposed ();
231 
232     AccessibleDocumentViewBase::propertyChange (rEventObject);
233 
234     OSL_TRACE ("AccessibleOutlineView::propertyChange");
235     if (rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("CurrentPage")))
236     {
237         OSL_TRACE ("    current page changed");
238 
239         // The current page changed. Update the children accordingly.
240         UpdateChildren();
241     }
242     else if (rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("VisibleArea")))
243     {
244         OSL_TRACE ("    visible area changed");
245 
246         // The visible area changed. Update the children accordingly.
247         UpdateChildren();
248     }
249     else
250     {
251         OSL_TRACE ("  unhandled");
252     }
253     OSL_TRACE ("  done");
254 }
255 
256 
257 ///	Create a name for this view.
258 ::rtl::OUString
259     AccessibleOutlineView::CreateAccessibleName (void)
260     throw (::com::sun::star::uno::RuntimeException)
261 {
262     ::vos::OGuard aGuard( Application::GetSolarMutex() );
263 
264     return String( SdResId(SID_SD_A11Y_I_OUTLINEVIEW_N) );
265 }
266 
267 
268 /** Create a description for this view.  Use the model's description or URL
269     if a description is not available.
270 */
271 ::rtl::OUString
272     AccessibleOutlineView::CreateAccessibleDescription (void)
273     throw (::com::sun::star::uno::RuntimeException)
274 {
275     ::vos::OGuard aGuard( Application::GetSolarMutex() );
276 
277     return String( SdResId(SID_SD_A11Y_I_OUTLINEVIEW_D) );
278 }
279 
280 void AccessibleOutlineView::UpdateChildren()
281 {
282     ::vos::OGuard aGuard( Application::GetSolarMutex() );
283 
284     // Update visible children
285     maTextHelper.UpdateChildren();
286 }
287 
288 } // end of namespace accessibility
289