15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
105b190011SAndrew Rist  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
195b190011SAndrew Rist  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
225b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
27cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawView.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp>
29cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
30cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
32cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
34cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBLE_ACCESSIBLEEVENTID_HPP_
35cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
38cdf0e10cSrcweir #ifndef	_COM_SUN_STAR_LANG_XMULSTISERVICEFACTORY_HPP_
39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #include <rtl/ustring.h>
42cdf0e10cSrcweir #ifndef _SFXFRAME_HXX
43cdf0e10cSrcweir #include<sfx2/viewfrm.hxx>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <svx/AccessibleShape.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <svx/svdobj.hxx>
49cdf0e10cSrcweir #include <svx/svdmodel.hxx>
50cdf0e10cSrcweir #include <svx/unoapi.hxx>
51cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
52cdf0e10cSrcweir #include <vcl/svapp.hxx>
53cdf0e10cSrcweir #include "Window.hxx"
54cdf0e10cSrcweir #include "ViewShell.hxx"
55cdf0e10cSrcweir #include "OutlineViewShell.hxx"
56cdf0e10cSrcweir #include "View.hxx"
57cdf0e10cSrcweir #include "AccessibleOutlineView.hxx"
58cdf0e10cSrcweir #include "AccessibleOutlineEditSource.hxx"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include <memory>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #include "accessibility.hrc"
63cdf0e10cSrcweir #include "sdresid.hxx"
64cdf0e10cSrcweir #include <vos/mutex.hxx>
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using namespace ::com::sun::star;
67cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir namespace accessibility {
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //=====  internal  ============================================================
73cdf0e10cSrcweir 
AccessibleOutlineView(::sd::Window * pSdWindow,::sd::OutlineViewShell * pViewShell,const uno::Reference<frame::XController> & rxController,const uno::Reference<XAccessible> & rxParent)74cdf0e10cSrcweir AccessibleOutlineView::AccessibleOutlineView (
75cdf0e10cSrcweir     ::sd::Window* pSdWindow,
76cdf0e10cSrcweir     ::sd::OutlineViewShell* pViewShell,
77cdf0e10cSrcweir     const uno::Reference<frame::XController>& rxController,
78cdf0e10cSrcweir     const uno::Reference<XAccessible>& rxParent)
79cdf0e10cSrcweir     : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
80cdf0e10cSrcweir       maTextHelper( ::std::auto_ptr< SvxEditSource >( NULL ) )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     // Beware! Here we leave the paths of the UNO API and descend into the
85cdf0e10cSrcweir     // depths of the core.  Necessary for making the edit engine accessible.
86cdf0e10cSrcweir     if( pViewShell && pSdWindow )
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         ::sd::View* pView = pViewShell->GetView();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         if (pView && pView->ISA(::sd::OutlineView))
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             OutlinerView* pOutlineView = static_cast< ::sd::OutlineView*>(
93cdf0e10cSrcweir                 pView)->GetViewByWindow( pSdWindow );
94cdf0e10cSrcweir             SdrOutliner* pOutliner =
95cdf0e10cSrcweir                 static_cast< ::sd::OutlineView*>(pView)->GetOutliner();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             if( pOutlineView && pOutliner )
98cdf0e10cSrcweir             {
99cdf0e10cSrcweir                 maTextHelper.SetEditSource( ::std::auto_ptr< SvxEditSource >( new AccessibleOutlineEditSource(
100cdf0e10cSrcweir                                                                                   *pOutliner, *pView, *pOutlineView, *pSdWindow ) ) );
101cdf0e10cSrcweir             }
102cdf0e10cSrcweir         }
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
~AccessibleOutlineView(void)107cdf0e10cSrcweir AccessibleOutlineView::~AccessibleOutlineView (void)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     OSL_TRACE ("~AccessibleOutlineView");
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
Init(void)113cdf0e10cSrcweir void AccessibleOutlineView::Init (void)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     // #105479# Set event source _before_ starting to listen
116cdf0e10cSrcweir     maTextHelper.SetEventSource(this);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     AccessibleDocumentViewBase::Init ();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
ViewForwarderChanged(ChangeType aChangeType,const IAccessibleViewForwarder * pViewForwarder)122cdf0e10cSrcweir void AccessibleOutlineView::ViewForwarderChanged (ChangeType aChangeType,
123cdf0e10cSrcweir     const IAccessibleViewForwarder* pViewForwarder)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     AccessibleDocumentViewBase::ViewForwarderChanged (aChangeType, pViewForwarder);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     UpdateChildren();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //=====  XAccessibleContext  ==================================================
132cdf0e10cSrcweir 
133cdf0e10cSrcweir sal_Int32 SAL_CALL
getAccessibleChildCount(void)134cdf0e10cSrcweir     AccessibleOutlineView::getAccessibleChildCount (void)
135cdf0e10cSrcweir     throw (uno::RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     ThrowIfDisposed ();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     // forward
140cdf0e10cSrcweir     return maTextHelper.GetChildCount();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir uno::Reference<XAccessible> SAL_CALL
getAccessibleChild(sal_Int32 nIndex)145cdf0e10cSrcweir     AccessibleOutlineView::getAccessibleChild (sal_Int32 nIndex)
146cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     ThrowIfDisposed ();
149cdf0e10cSrcweir     // Forward request to children manager.
150cdf0e10cSrcweir     return maTextHelper.GetChild(nIndex);
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153*0deba7fbSSteve Yin #include <drawdoc.hxx>
154*0deba7fbSSteve Yin ::rtl::OUString SAL_CALL
getAccessibleName(void)155*0deba7fbSSteve Yin 	AccessibleOutlineView::getAccessibleName(void)
156*0deba7fbSSteve Yin 	throw (::com::sun::star::uno::RuntimeException)
157*0deba7fbSSteve Yin {
158*0deba7fbSSteve Yin 	::rtl::OUString sName = String( SdResId(SID_SD_A11Y_D_PRESENTATION) );
159*0deba7fbSSteve Yin 	::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
160*0deba7fbSSteve Yin 	if ( pSdView )
161*0deba7fbSSteve Yin 	{
162*0deba7fbSSteve Yin 		SdDrawDocument* pDoc = pSdView->GetDoc();
163*0deba7fbSSteve Yin 		if ( pDoc )
164*0deba7fbSSteve Yin 		{
165*0deba7fbSSteve Yin 			rtl::OUString sFileName = pDoc->getDocAccTitle();
166*0deba7fbSSteve Yin 			if ( !sFileName.getLength() )
167*0deba7fbSSteve Yin 			{
168*0deba7fbSSteve Yin 				::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
169*0deba7fbSSteve Yin 				if ( pDocSh )
170*0deba7fbSSteve Yin 				{
171*0deba7fbSSteve Yin 					sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
172*0deba7fbSSteve Yin 				}
173*0deba7fbSSteve Yin 			}
174*0deba7fbSSteve Yin 			if ( sFileName.getLength() )
175*0deba7fbSSteve Yin 			{
176*0deba7fbSSteve Yin 				sName = sFileName + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - ")) + sName;
177*0deba7fbSSteve Yin 			}
178*0deba7fbSSteve Yin 		}
179*0deba7fbSSteve Yin 	}
180*0deba7fbSSteve Yin 	return sName;
181*0deba7fbSSteve Yin }
182cdf0e10cSrcweir //=====  XAccessibleEventBroadcaster  ========================================
183cdf0e10cSrcweir 
addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)184cdf0e10cSrcweir void SAL_CALL AccessibleOutlineView::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     // delegate listener handling to children manager.
187cdf0e10cSrcweir     if ( ! IsDisposed())
188cdf0e10cSrcweir         maTextHelper.AddEventListener(xListener);
189*0deba7fbSSteve Yin 	AccessibleContextBase::addEventListener(xListener);
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)192cdf0e10cSrcweir void SAL_CALL AccessibleOutlineView::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     // forward
195cdf0e10cSrcweir     if ( ! IsDisposed())
196cdf0e10cSrcweir         maTextHelper.RemoveEventListener(xListener);
197*0deba7fbSSteve Yin 	AccessibleContextBase::removeEventListener(xListener);
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //=====  XServiceInfo  ========================================================
201cdf0e10cSrcweir 
202cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getImplementationName(void)203cdf0e10cSrcweir     AccessibleOutlineView::getImplementationName (void)
204cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleOutlineView"));
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //=====  XEventListener  ======================================================
211cdf0e10cSrcweir 
212cdf0e10cSrcweir void SAL_CALL
disposing(const lang::EventObject & rEventObject)213cdf0e10cSrcweir     AccessibleOutlineView::disposing (const lang::EventObject& rEventObject)
214cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     AccessibleDocumentViewBase::disposing (rEventObject);
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir //=====  protected internal  ==================================================
220cdf0e10cSrcweir 
FireEvent(const AccessibleEventObject & aEvent)221cdf0e10cSrcweir void AccessibleOutlineView::FireEvent(const AccessibleEventObject& aEvent )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     // delegate listener handling to children manager.
224cdf0e10cSrcweir     maTextHelper.FireEvent(aEvent);
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
Activated(void)227cdf0e10cSrcweir void AccessibleOutlineView::Activated (void)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     // delegate listener handling to children manager.
232cdf0e10cSrcweir     maTextHelper.SetFocus(sal_True);
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
Deactivated(void)235cdf0e10cSrcweir void AccessibleOutlineView::Deactivated (void)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     // delegate listener handling to children manager.
240cdf0e10cSrcweir     maTextHelper.SetFocus(sal_False);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
disposing(void)243cdf0e10cSrcweir void SAL_CALL AccessibleOutlineView::disposing (void)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     // dispose children
246cdf0e10cSrcweir     maTextHelper.Dispose();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     AccessibleDocumentViewBase::disposing ();
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir //=====  XPropertyChangeListener  =============================================
252cdf0e10cSrcweir 
253cdf0e10cSrcweir void SAL_CALL
propertyChange(const beans::PropertyChangeEvent & rEventObject)254cdf0e10cSrcweir     AccessibleOutlineView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
255cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     ThrowIfDisposed ();
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     AccessibleDocumentViewBase::propertyChange (rEventObject);
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     OSL_TRACE ("AccessibleOutlineView::propertyChange");
262*0deba7fbSSteve Yin 	//add page switch event for slide show mode
263*0deba7fbSSteve Yin     if (rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("CurrentPage")) ||
264*0deba7fbSSteve Yin 		rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("PageChange")) )
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir         OSL_TRACE ("    current page changed");
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         // The current page changed. Update the children accordingly.
269cdf0e10cSrcweir         UpdateChildren();
270*0deba7fbSSteve Yin     	CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir     else if (rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("VisibleArea")))
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         OSL_TRACE ("    visible area changed");
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         // The visible area changed. Update the children accordingly.
277cdf0e10cSrcweir         UpdateChildren();
278cdf0e10cSrcweir     }
279cdf0e10cSrcweir     else
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         OSL_TRACE ("  unhandled");
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir     OSL_TRACE ("  done");
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 
287cdf0e10cSrcweir ///	Create a name for this view.
288cdf0e10cSrcweir ::rtl::OUString
CreateAccessibleName(void)289cdf0e10cSrcweir     AccessibleOutlineView::CreateAccessibleName (void)
290cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     return String( SdResId(SID_SD_A11Y_I_OUTLINEVIEW_N) );
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir /** Create a description for this view.  Use the model's description or URL
299cdf0e10cSrcweir     if a description is not available.
300cdf0e10cSrcweir */
301cdf0e10cSrcweir ::rtl::OUString
CreateAccessibleDescription(void)302cdf0e10cSrcweir     AccessibleOutlineView::CreateAccessibleDescription (void)
303cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     return String( SdResId(SID_SD_A11Y_I_OUTLINEVIEW_D) );
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
UpdateChildren()310cdf0e10cSrcweir void AccessibleOutlineView::UpdateChildren()
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     // Update visible children
315cdf0e10cSrcweir     maTextHelper.UpdateChildren();
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir } // end of namespace accessibility
319