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 
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 
107cdf0e10cSrcweir AccessibleOutlineView::~AccessibleOutlineView (void)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     OSL_TRACE ("~AccessibleOutlineView");
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
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 
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
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
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 //IAccessibility2 Implementation 2009-----
154*0deba7fbSSteve Yin #include <drawdoc.hxx>
155*0deba7fbSSteve Yin ::rtl::OUString SAL_CALL
156*0deba7fbSSteve Yin 	AccessibleOutlineView::getAccessibleName(void)
157*0deba7fbSSteve Yin 	throw (::com::sun::star::uno::RuntimeException)
158*0deba7fbSSteve Yin {
159*0deba7fbSSteve Yin 	::rtl::OUString sName = String( SdResId(SID_SD_A11Y_D_PRESENTATION) );
160*0deba7fbSSteve Yin 	::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
161*0deba7fbSSteve Yin 	if ( pSdView )
162*0deba7fbSSteve Yin 	{
163*0deba7fbSSteve Yin 		SdDrawDocument* pDoc = pSdView->GetDoc();
164*0deba7fbSSteve Yin 		if ( pDoc )
165*0deba7fbSSteve Yin 		{
166*0deba7fbSSteve Yin 			rtl::OUString sFileName = pDoc->getDocAccTitle();
167*0deba7fbSSteve Yin 			if ( !sFileName.getLength() )
168*0deba7fbSSteve Yin 			{
169*0deba7fbSSteve Yin 				::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
170*0deba7fbSSteve Yin 				if ( pDocSh )
171*0deba7fbSSteve Yin 				{
172*0deba7fbSSteve Yin 					sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
173*0deba7fbSSteve Yin 				}
174*0deba7fbSSteve Yin 			}
175*0deba7fbSSteve Yin 			if ( sFileName.getLength() )
176*0deba7fbSSteve Yin 			{
177*0deba7fbSSteve Yin 				sName = sFileName + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - ")) + sName;
178*0deba7fbSSteve Yin 			}
179*0deba7fbSSteve Yin 		}
180*0deba7fbSSteve Yin 	}
181*0deba7fbSSteve Yin 	return sName;
182*0deba7fbSSteve Yin }
183*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
184cdf0e10cSrcweir //=====  XAccessibleEventBroadcaster  ========================================
185cdf0e10cSrcweir 
186cdf0e10cSrcweir void SAL_CALL AccessibleOutlineView::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     // delegate listener handling to children manager.
189cdf0e10cSrcweir     if ( ! IsDisposed())
190cdf0e10cSrcweir         maTextHelper.AddEventListener(xListener);
191*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
192*0deba7fbSSteve Yin 	AccessibleContextBase::addEventListener(xListener);
193*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir void SAL_CALL AccessibleOutlineView::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     // forward
199cdf0e10cSrcweir     if ( ! IsDisposed())
200cdf0e10cSrcweir         maTextHelper.RemoveEventListener(xListener);
201*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
202*0deba7fbSSteve Yin 	AccessibleContextBase::removeEventListener(xListener);
203*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir //=====  XServiceInfo  ========================================================
207cdf0e10cSrcweir 
208cdf0e10cSrcweir ::rtl::OUString SAL_CALL
209cdf0e10cSrcweir     AccessibleOutlineView::getImplementationName (void)
210cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleOutlineView"));
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
216cdf0e10cSrcweir //=====  XEventListener  ======================================================
217cdf0e10cSrcweir 
218cdf0e10cSrcweir void SAL_CALL
219cdf0e10cSrcweir     AccessibleOutlineView::disposing (const lang::EventObject& rEventObject)
220cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     AccessibleDocumentViewBase::disposing (rEventObject);
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir //=====  protected internal  ==================================================
226cdf0e10cSrcweir 
227cdf0e10cSrcweir void AccessibleOutlineView::FireEvent(const AccessibleEventObject& aEvent )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     // delegate listener handling to children manager.
230cdf0e10cSrcweir     maTextHelper.FireEvent(aEvent);
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir void AccessibleOutlineView::Activated (void)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     // delegate listener handling to children manager.
238cdf0e10cSrcweir     maTextHelper.SetFocus(sal_True);
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir void AccessibleOutlineView::Deactivated (void)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     // delegate listener handling to children manager.
246cdf0e10cSrcweir     maTextHelper.SetFocus(sal_False);
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir void SAL_CALL AccessibleOutlineView::disposing (void)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     // dispose children
252cdf0e10cSrcweir     maTextHelper.Dispose();
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     AccessibleDocumentViewBase::disposing ();
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir //=====  XPropertyChangeListener  =============================================
258cdf0e10cSrcweir 
259cdf0e10cSrcweir void SAL_CALL
260cdf0e10cSrcweir     AccessibleOutlineView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
261cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     ThrowIfDisposed ();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     AccessibleDocumentViewBase::propertyChange (rEventObject);
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     OSL_TRACE ("AccessibleOutlineView::propertyChange");
268*0deba7fbSSteve Yin 	//add page switch event for slide show mode
269*0deba7fbSSteve Yin     if (rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("CurrentPage")) ||
270*0deba7fbSSteve Yin 		rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("PageChange")) )
271cdf0e10cSrcweir     {
272cdf0e10cSrcweir         OSL_TRACE ("    current page changed");
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         // The current page changed. Update the children accordingly.
275cdf0e10cSrcweir         UpdateChildren();
276*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
277*0deba7fbSSteve Yin     	CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
278*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir     else if (rEventObject.PropertyName == ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("VisibleArea")))
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         OSL_TRACE ("    visible area changed");
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         // The visible area changed. Update the children accordingly.
285cdf0e10cSrcweir         UpdateChildren();
286cdf0e10cSrcweir     }
287cdf0e10cSrcweir     else
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         OSL_TRACE ("  unhandled");
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir     OSL_TRACE ("  done");
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 
295cdf0e10cSrcweir ///	Create a name for this view.
296cdf0e10cSrcweir ::rtl::OUString
297cdf0e10cSrcweir     AccessibleOutlineView::CreateAccessibleName (void)
298cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     return String( SdResId(SID_SD_A11Y_I_OUTLINEVIEW_N) );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 
306cdf0e10cSrcweir /** Create a description for this view.  Use the model's description or URL
307cdf0e10cSrcweir     if a description is not available.
308cdf0e10cSrcweir */
309cdf0e10cSrcweir ::rtl::OUString
310cdf0e10cSrcweir     AccessibleOutlineView::CreateAccessibleDescription (void)
311cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     return String( SdResId(SID_SD_A11Y_I_OUTLINEVIEW_D) );
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir void AccessibleOutlineView::UpdateChildren()
319cdf0e10cSrcweir {
320cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     // Update visible children
323cdf0e10cSrcweir     maTextHelper.UpdateChildren();
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir } // end of namespace accessibility
327