xref: /trunk/main/sd/source/ui/accessibility/AccessibleDrawDocumentView.cxx (revision 46c69c84579d1f1df536015e7d54c9965db90b69)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 #include "AccessibleDrawDocumentView.hxx"
27 #include <com/sun/star/drawing/XDrawPage.hpp>
28 #include <com/sun/star/drawing/XDrawView.hpp>
29 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
30 #include <com/sun/star/drawing/XShapes.hpp>
31 #include <com/sun/star/container/XChild.hpp>
32 #include <com/sun/star/frame/XController.hpp>
33 #include <com/sun/star/frame/XFrame.hpp>
34 #include <com/sun/star/document/XEventBroadcaster.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <rtl/ustring.h>
40 #include<sfx2/viewfrm.hxx>
41 
42 #include <svx/AccessibleShape.hxx>
43 
44 #include <svx/svdobj.hxx>
45 #include <svx/svdmodel.hxx>
46 #include <svx/unoapi.hxx>
47 #include <svx/unoshcol.hxx>
48 #include <toolkit/helper/vclunohelper.hxx>
49 #include "Window.hxx"
50 #include <vcl/svapp.hxx>
51 
52 
53 #include "ViewShell.hxx"
54 #include "View.hxx"
55 #include "DrawDocShell.hxx"
56 #include <drawdoc.hxx>
57 #include <algorithm>
58 #include "sdpage.hxx"
59 #include "slideshow.hxx"
60 #include "anminfo.hxx"
61 #include <memory>
62 
63 #include "accessibility.hrc"
64 #include "sdresid.hxx"
65 #include <vos/mutex.hxx>
66 
67 using ::rtl::OUString;
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::accessibility;
71 
72 class SfxViewFrame;
73 
74 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
75 
76 namespace accessibility {
77 
78 
79 struct XShapePosCompareHelper
80 {
operator ()accessibility::XShapePosCompareHelper81     bool operator() ( const uno::Reference<drawing::XShape>& xshape1,
82         const uno::Reference<drawing::XShape>& xshape2 ) const
83     {
84         // modify the compare method to return the Z-Order, not layout order
85         SdrObject* pObj1 = GetSdrObjectFromXShape(xshape1);
86         SdrObject* pObj2 = GetSdrObjectFromXShape(xshape2);
87         if(pObj1 && pObj2)
88             return pObj1->GetOrdNum() < pObj2->GetOrdNum();
89         else
90             return 0;
91     }
92 };
93 //=====  internal  ============================================================
94 
AccessibleDrawDocumentView(::sd::Window * pSdWindow,::sd::ViewShell * pViewShell,const uno::Reference<frame::XController> & rxController,const uno::Reference<XAccessible> & rxParent)95 AccessibleDrawDocumentView::AccessibleDrawDocumentView (
96     ::sd::Window* pSdWindow,
97     ::sd::ViewShell* pViewShell,
98     const uno::Reference<frame::XController>& rxController,
99     const uno::Reference<XAccessible>& rxParent)
100     : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
101       mpSdViewSh( pViewShell ),
102       mpChildrenManager (NULL)
103 {
104     OSL_TRACE ("AccessibleDrawDocumentView");
105     UpdateAccessibleName();
106 }
107 
108 
109 
110 
~AccessibleDrawDocumentView(void)111 AccessibleDrawDocumentView::~AccessibleDrawDocumentView (void)
112 {
113     OSL_TRACE ("~AccessibleDrawDocumentView");
114     DBG_ASSERT (rBHelper.bDisposed || rBHelper.bInDispose,
115         "~AccessibleDrawDocumentView: object has not been disposed");
116 }
117 
118 
119 
120 
Init(void)121 void AccessibleDrawDocumentView::Init (void)
122 {
123     AccessibleDocumentViewBase::Init ();
124 
125     // Determine the list of shapes on the current page.
126     uno::Reference<drawing::XShapes> xShapeList;
127     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
128     if (xView.is())
129         xShapeList = uno::Reference<drawing::XShapes> (
130             xView->getCurrentPage(), uno::UNO_QUERY);
131 
132     // Create the children manager.
133     mpChildrenManager = new ChildrenManager(this, xShapeList, maShapeTreeInfo, *this);
134     if (mpChildrenManager != NULL)
135     {
136         // Create the page shape and initialize it.  The shape is acquired
137         // before initialization and released after transferring ownership
138         // to the children manager to prevent premature disposing of the
139         // shape.
140         AccessiblePageShape* pPage = CreateDrawPageShape();
141         if (pPage != NULL)
142         {
143             pPage->acquire();
144             pPage->Init();
145             mpChildrenManager->AddAccessibleShape (
146                 std::unique_ptr<AccessibleShape>(pPage));
147             pPage->release();
148             mpChildrenManager->Update ();
149         }
150         mpChildrenManager->UpdateSelection ();
151     }
152 }
153 
154 
155 
156 
ViewForwarderChanged(ChangeType aChangeType,const IAccessibleViewForwarder * pViewForwarder)157 void AccessibleDrawDocumentView::ViewForwarderChanged (ChangeType aChangeType,
158     const IAccessibleViewForwarder* pViewForwarder)
159 {
160     AccessibleDocumentViewBase::ViewForwarderChanged (aChangeType, pViewForwarder);
161     if (mpChildrenManager != NULL)
162         mpChildrenManager->ViewForwarderChanged (aChangeType, pViewForwarder);
163 }
164 
165 
166 
167 
168 /**  The page shape is created on every call at the moment (provided that
169      every thing goes well).
170 */
CreateDrawPageShape(void)171 AccessiblePageShape* AccessibleDrawDocumentView::CreateDrawPageShape (void)
172 {
173     AccessiblePageShape* pShape = NULL;
174 
175     // Create a shape that represents the actual draw page.
176     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
177     if (xView.is())
178     {
179         uno::Reference<beans::XPropertySet> xSet (
180             uno::Reference<beans::XPropertySet> (xView->getCurrentPage(), uno::UNO_QUERY));
181         if (xSet.is())
182         {
183             // Create a rectangle shape that will represent the draw page.
184             uno::Reference<lang::XMultiServiceFactory> xFactory (mxModel, uno::UNO_QUERY);
185             uno::Reference<drawing::XShape> xRectangle;
186             if (xFactory.is())
187                 xRectangle = uno::Reference<drawing::XShape>(xFactory->createInstance (
188                     OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.RectangleShape"))),
189                     uno::UNO_QUERY);
190 
191             // Set the shape's size and position.
192             if (xRectangle.is())
193             {
194                 uno::Any aValue;
195                 awt::Point aPosition;
196                 awt::Size aSize;
197 
198                 // Set size and position of the shape to those of the draw
199                 // page.
200                 aValue = xSet->getPropertyValue (
201                     OUString (RTL_CONSTASCII_USTRINGPARAM("BorderLeft")));
202                 aValue >>= aPosition.X;
203                 aValue = xSet->getPropertyValue (
204                     OUString (RTL_CONSTASCII_USTRINGPARAM("BorderTop")));
205                 aValue >>= aPosition.Y;
206                 xRectangle->setPosition (aPosition);
207 
208                 aValue = xSet->getPropertyValue (
209                     OUString (RTL_CONSTASCII_USTRINGPARAM("Width")));
210                 aValue >>= aSize.Width;
211                 aValue = xSet->getPropertyValue (
212                     OUString (RTL_CONSTASCII_USTRINGPARAM("Height")));
213                 aValue >>= aSize.Height;
214                 xRectangle->setSize (aSize);
215 
216                 // Create the accessible object for the shape and
217                 // initialize it.
218                 pShape = new AccessiblePageShape (
219                     xView->getCurrentPage(), this, maShapeTreeInfo);
220             }
221         }
222     }
223     return pShape;
224 }
225 
226 
227 
228 
229 //=====  XAccessibleContext  ==================================================
230 
231 sal_Int32 SAL_CALL
getAccessibleChildCount(void)232     AccessibleDrawDocumentView::getAccessibleChildCount (void)
233 {
234     ThrowIfDisposed ();
235 
236     long mpChildCount = AccessibleDocumentViewBase::getAccessibleChildCount();
237 
238     // Forward request to children manager.
239     if (mpChildrenManager != NULL)
240         mpChildCount += mpChildrenManager->GetChildCount ();
241 
242     return mpChildCount;
243 }
244 
245 
246 
247 
248 uno::Reference<XAccessible> SAL_CALL
getAccessibleChild(sal_Int32 nIndex)249     AccessibleDrawDocumentView::getAccessibleChild (sal_Int32 nIndex)
250 {
251     ThrowIfDisposed ();
252 
253     ::osl::ClearableMutexGuard aGuard (maMutex);
254 
255     // Take care of children of the base class.
256     sal_Int32 nCount = AccessibleDocumentViewBase::getAccessibleChildCount();
257     if (nCount > 0)
258     {
259         if (nIndex < nCount)
260             return AccessibleDocumentViewBase::getAccessibleChild(nIndex);
261         else
262             nIndex -= nCount;
263     }
264 
265     // Create a copy of the pointer to the children manager and release the
266     // mutex before calling any of its methods.
267     ChildrenManager* pChildrenManager = mpChildrenManager;
268     aGuard.clear();
269 
270     // Forward request to children manager.
271     if (pChildrenManager != NULL)
272     {
273         return pChildrenManager->GetChild (nIndex);
274     }
275     else
276         throw lang::IndexOutOfBoundsException (
277             ::rtl::OUString::createFromAscii ("no accessible child with index ")
278             + rtl::OUString::valueOf(nIndex),
279             static_cast<uno::XWeak*>(this));
280 }
281 
282 OUString SAL_CALL
getAccessibleName(void)283     AccessibleDrawDocumentView::getAccessibleName(void)
284 {
285     OUString sName = String( SdResId(SID_SD_A11Y_D_PRESENTATION) );
286     ::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
287     if ( pSdView )
288     {
289         SdDrawDocument* pDoc = pSdView->GetDoc();
290         if ( pDoc )
291         {
292             rtl::OUString sFileName = pDoc->getDocAccTitle();
293             if ( !sFileName.getLength() )
294             {
295                 ::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
296                 if ( pDocSh )
297                 {
298                     sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
299                 }
300             }
301 
302             OUString sReadOnly;
303             if(pDoc->getDocReadOnly())
304             {
305                 sReadOnly = String(SdResId(SID_SD_A11Y_D_PRESENTATION_READONLY));
306             }
307 
308             if ( sFileName.getLength() )
309             {
310                 sName = sFileName + sReadOnly + OUString(RTL_CONSTASCII_USTRINGPARAM(" - ")) + sName;
311             }
312         }
313     }
314 
315     return sName;
316 }
317 //=====  XEventListener  ======================================================
318 
319 void SAL_CALL
disposing(const lang::EventObject & rEventObject)320     AccessibleDrawDocumentView::disposing (const lang::EventObject& rEventObject)
321 {
322     ThrowIfDisposed ();
323 
324     AccessibleDocumentViewBase::disposing (rEventObject);
325     if (rEventObject.Source == mxModel)
326     {
327         ::osl::Guard< ::osl::Mutex> aGuard (::osl::Mutex::getGlobalMutex());
328         // maShapeTreeInfo has been modified in base class.
329         if (mpChildrenManager != NULL)
330             mpChildrenManager->SetInfo (maShapeTreeInfo);
331     }
332 }
333 
334 
335 
336 
337 //=====  XPropertyChangeListener  =============================================
338 
339 void SAL_CALL
propertyChange(const beans::PropertyChangeEvent & rEventObject)340     AccessibleDrawDocumentView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
341 {
342     ThrowIfDisposed ();
343 
344     AccessibleDocumentViewBase::propertyChange (rEventObject);
345 
346     OSL_TRACE ("AccessibleDrawDocumentView::propertyChange");
347     // add page switch event for slide show mode
348     if (rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("CurrentPage")) ||
349         rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("PageChange")) )
350     {
351         OSL_TRACE ("    current page changed");
352 
353         // Update the accessible name to reflect the current slide.
354         UpdateAccessibleName();
355 
356         // The current page changed.  Update the children manager accordingly.
357         uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
358         if (xView.is() && mpChildrenManager!=NULL)
359         {
360             // Inform the children manager to forget all children and give
361             // him the new ones.
362             mpChildrenManager->ClearAccessibleShapeList ();
363             mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
364                 xView->getCurrentPage(), uno::UNO_QUERY));
365 
366             // Create the page shape and initialize it.  The shape is
367             // acquired before initialization and released after
368             // transferring ownership to the children manager to prevent
369             // premature disposing of the shape.
370             AccessiblePageShape* pPage = CreateDrawPageShape ();
371             if (pPage != NULL)
372             {
373                 pPage->acquire();
374                 pPage->Init();
375                 mpChildrenManager->AddAccessibleShape (
376                     std::unique_ptr<AccessibleShape>(pPage));
377                 mpChildrenManager->Update (false);
378                 pPage->release();
379             }
380         }
381         else
382             OSL_TRACE ("View invalid");
383         CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
384     }
385     else if (rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("VisibleArea")))
386     {
387         OSL_TRACE ("    visible area changed");
388         if (mpChildrenManager != NULL)
389             mpChildrenManager->ViewForwarderChanged (
390                 IAccessibleViewForwarderListener::VISIBLE_AREA,
391                 &maViewForwarder);
392     }
393     else if (rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("ActiveLayer")))
394     {
395         CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
396     }
397     else if (rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("UpdateAcc")))
398     {
399         OSL_TRACE ("    acc on current page should be updated");
400 
401         // The current page changed.  Update the children manager accordingly.
402         uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
403         if (xView.is() && mpChildrenManager!=NULL)
404         {
405             // Inform the children manager to forget all children and give
406             // him the new ones.
407             mpChildrenManager->ClearAccessibleShapeList ();
408             // update the slide show page's accessible info
409             //mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
410             //    xView->getCurrentPage(), uno::UNO_QUERY));
411         rtl::Reference< sd::SlideShow > xSlideshow( sd::SlideShow::GetSlideShow( mpSdViewSh->GetViewShellBase() ) );
412         if( xSlideshow.is() && xSlideshow->isRunning() && xSlideshow->isFullScreen() )
413         {
414             ::com::sun::star::uno::Reference< drawing::XDrawPage > xSlide;
415             // MT IA2: Not used...
416             // sal_Int32 currentPageIndex = xSlideshow->getCurrentPageIndex();
417             ::com::sun::star::uno::Reference< ::com::sun::star::presentation::XSlideShowController > mpSlideController = xSlideshow->getController();
418             if( mpSlideController.is() )
419             {
420                 xSlide = mpSlideController->getCurrentSlide();
421                 if (xSlide.is())
422                 {
423                     mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
424                                 xSlide, uno::UNO_QUERY));
425                 }
426             }
427         }
428             // Create the page shape and initialize it.  The shape is
429             // acquired before initialization and released after
430             // transferring ownership to the children manager to prevent
431             // premature disposing of the shape.
432             AccessiblePageShape* pPage = CreateDrawPageShape ();
433             if (pPage != NULL)
434             {
435                 pPage->acquire();
436                 pPage->Init();
437                 mpChildrenManager->AddAccessibleShape (
438                     std::unique_ptr<AccessibleShape>(pPage));
439                 mpChildrenManager->Update (false);
440                 pPage->release();
441             }
442     }
443     }
444     else
445     {
446         OSL_TRACE ("  unhandled");
447     }
448     OSL_TRACE ("  done");
449 }
450 
451 
452 
453 //=====  XServiceInfo  ========================================================
454 
455 ::rtl::OUString SAL_CALL
getImplementationName(void)456     AccessibleDrawDocumentView::getImplementationName (void)
457 {
458     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
459         "AccessibleDrawDocumentView"));
460 }
461 
462 
463 
464 
465 ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
getSupportedServiceNames(void)466     AccessibleDrawDocumentView::getSupportedServiceNames (void)
467 {
468     ThrowIfDisposed();
469     // Get list of supported service names from base class...
470     uno::Sequence<OUString> aServiceNames =
471         AccessibleDocumentViewBase::getSupportedServiceNames();
472     sal_Int32 nCount (aServiceNames.getLength());
473 
474     // ...and add additional names.
475     aServiceNames.realloc (nCount + 1);
476     static const OUString sAdditionalServiceName (RTL_CONSTASCII_USTRINGPARAM(
477         "com.sun.star.drawing.AccessibleDrawDocumentView"));
478     aServiceNames[nCount] = sAdditionalServiceName;
479 
480     return aServiceNames;
481 }
482 
483 //=====  XInterface  ==========================================================
484 
485 uno::Any SAL_CALL
queryInterface(const uno::Type & rType)486     AccessibleDrawDocumentView::queryInterface (const uno::Type & rType)
487 {
488     uno::Any aReturn = AccessibleDocumentViewBase::queryInterface (rType);
489     if ( ! aReturn.hasValue())
490         aReturn = ::cppu::queryInterface (rType,
491             static_cast<XAccessibleGroupPosition*>(this)
492             );
493     return aReturn;
494 }
495 
496 void SAL_CALL
acquire(void)497     AccessibleDrawDocumentView::acquire (void)
498     throw ()
499 {
500     AccessibleDocumentViewBase::acquire ();
501 }
502 void SAL_CALL
release(void)503     AccessibleDrawDocumentView::release (void)
504     throw ()
505 {
506     AccessibleDocumentViewBase::release ();
507 }
508 //=====  XAccessibleGroupPosition  =========================================
509 uno::Sequence< sal_Int32 > SAL_CALL
getGroupPosition(const uno::Any & rAny)510     AccessibleDrawDocumentView::getGroupPosition( const uno::Any& rAny )
511 {
512     // we will return the:
513     // [0] group level(always be 0 now)
514     // [1] similar items counts in the group
515     // [2] the position of the object in the group
516     uno::Sequence< sal_Int32 > aRet( 3 );
517     //get the xShape of the current selected drawing object
518     uno::Reference<XAccessibleContext> xAccContent;
519     rAny >>= xAccContent;
520     if ( !xAccContent.is() )
521     {
522         return aRet;
523     }
524     AccessibleShape* pAcc = AccessibleShape::getImplementation( xAccContent );
525     if ( !pAcc )
526     {
527         return aRet;
528     }
529     uno::Reference< drawing::XShape > xCurShape = pAcc->GetXShape();
530     if ( !xCurShape.is() )
531     {
532         return aRet;
533     }
534     //find all the child in the page, insert them into a vector and sort
535     if ( mpChildrenManager == NULL )
536     {
537         return aRet;
538     }
539     std::vector< uno::Reference<drawing::XShape> > vXShapes;
540     sal_Int32 nCount = mpChildrenManager->GetChildCount();
541     //get pointer of SdView & SdrPageView for further use.
542     SdrPageView* pPV = NULL;
543     ::sd::View* pSdView = NULL;
544     if ( mpSdViewSh )
545     {
546         pSdView = mpSdViewSh->GetView();
547         pPV = pSdView->GetSdrPageView();
548     }
549     for ( sal_Int32 i = 0; i < nCount; i++ )
550     {
551         uno::Reference< drawing::XShape > xShape = mpChildrenManager->GetChildShape(i);
552         if ( xShape.is() )
553         {
554             //if the object is visible in the page, we add it into the group list.
555             SdrObject* pObj = GetSdrObjectFromXShape(xShape);
556             if ( pObj && pPV && pSdView && pSdView->IsObjMarkable( pObj, pPV ) )
557             {
558                 vXShapes.push_back( xShape );
559             }
560         }
561     }
562     std::sort( vXShapes.begin(), vXShapes.end(), XShapePosCompareHelper() );
563     //get the index of the selected object in the group
564     std::vector< uno::Reference<drawing::XShape> >::iterator aIter;
565     //we start counting position from 1
566     sal_Int32 nPos = 1;
567     for ( aIter = vXShapes.begin(); aIter != vXShapes.end(); aIter++, nPos++ )
568     {
569         if ( (*aIter).get() == xCurShape.get() )
570         {
571             sal_Int32* pArray = aRet.getArray();
572             pArray[0] = 1; //it should be 1 based, not 0 based.
573             pArray[1] = vXShapes.size();
574             pArray[2] = nPos;
575             break;
576         }
577     }
578     return aRet;
579 }
getObjectLink(const uno::Any & rAny)580 ::rtl::OUString AccessibleDrawDocumentView::getObjectLink( const uno::Any& rAny )
581 {
582     ::rtl::OUString aRet;
583     //get the xShape of the current selected drawing object
584     uno::Reference<XAccessibleContext> xAccContent;
585     rAny >>= xAccContent;
586     if ( !xAccContent.is() )
587     {
588         return aRet;
589     }
590     AccessibleShape* pAcc = AccessibleShape::getImplementation( xAccContent );
591     if ( !pAcc )
592     {
593         return aRet;
594     }
595     uno::Reference< drawing::XShape > xCurShape = pAcc->GetXShape();
596     if ( !xCurShape.is() )
597     {
598         return aRet;
599     }
600     SdrObject* pObj = GetSdrObjectFromXShape(xCurShape);
601     if (pObj)
602     {
603         SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
604         if( pInfo && (pInfo->meClickAction == presentation::ClickAction_DOCUMENT) )
605             aRet = (::rtl::OUString)pInfo->GetBookmark();
606     }
607     return aRet;
608 }
609 /// Create a name for this view.
610 ::rtl::OUString
CreateAccessibleName(void)611     AccessibleDrawDocumentView::CreateAccessibleName (void)
612 {
613     rtl::OUString sName;
614 
615     uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
616     if (xInfo.is())
617     {
618         uno::Sequence< ::rtl::OUString > aServices( xInfo->getSupportedServiceNames() );
619         OUString sFirstService = aServices[0];
620         if (sFirstService == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocumentDrawView")))
621         {
622             if( aServices.getLength() >= 2 &&
623                 aServices[1] == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationView")))
624             {
625                 ::vos::OGuard aGuard( Application::GetSolarMutex() );
626 
627                 sName = String( SdResId(SID_SD_A11Y_I_DRAWVIEW_N) );
628             }
629             else
630             {
631                 ::vos::OGuard aGuard( Application::GetSolarMutex() );
632 
633                 sName = String( SdResId(SID_SD_A11Y_D_DRAWVIEW_N) );
634             }
635         }
636         else if (sFirstService == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.NotesView")))
637         {
638             ::vos::OGuard aGuard( Application::GetSolarMutex() );
639 
640             sName = String( SdResId(SID_SD_A11Y_I_NOTESVIEW_N) );
641         }
642         else if (sFirstService == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HandoutView")))
643         {
644             ::vos::OGuard aGuard( Application::GetSolarMutex() );
645 
646             sName = String( SdResId(SID_SD_A11Y_I_HANDOUTVIEW_N) );
647         }
648         else
649         {
650             sName = sFirstService;
651         }
652     }
653     else
654     {
655         sName = OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleDrawDocumentView"));
656     }
657     return sName;
658 }
659 
660 
661 
662 
663 /** Create a description for this view.  Use the model's description or URL
664     if a description is not available.
665 */
666 ::rtl::OUString
CreateAccessibleDescription(void)667     AccessibleDrawDocumentView::CreateAccessibleDescription (void)
668 {
669     rtl::OUString sDescription;
670 
671     uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
672     if (xInfo.is())
673     {
674         uno::Sequence< ::rtl::OUString > aServices( xInfo->getSupportedServiceNames() );
675         OUString sFirstService = aServices[0];
676         if (sFirstService == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocumentDrawView")))
677         {
678             if( aServices.getLength() >= 2 &&
679                 aServices[1] == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationView")))
680             {
681                 ::vos::OGuard aGuard( Application::GetSolarMutex() );
682 
683                 sDescription = String( SdResId(SID_SD_A11Y_I_DRAWVIEW_D) );
684             }
685             else
686             {
687                 ::vos::OGuard aGuard( Application::GetSolarMutex() );
688 
689                 sDescription = String( SdResId(SID_SD_A11Y_D_DRAWVIEW_D) );
690             }
691         }
692         else if (sFirstService == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.NotesView")))
693         {
694             ::vos::OGuard aGuard( Application::GetSolarMutex() );
695 
696             sDescription = String( SdResId(SID_SD_A11Y_I_NOTESVIEW_D) );
697         }
698         else if (sFirstService == OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HandoutView")))
699         {
700             ::vos::OGuard aGuard( Application::GetSolarMutex() );
701 
702             sDescription = String( SdResId(SID_SD_A11Y_I_HANDOUTVIEW_D) );
703         }
704         else
705         {
706             sDescription = sFirstService;
707         }
708     }
709     else
710     {
711         sDescription = OUString(RTL_CONSTASCII_USTRINGPARAM("Accessible Draw Document"));
712     }
713     return sDescription;
714 }
715 
716 
717 
718 
719 /** Return selection state of specified child
720 */
721 sal_Bool
implIsSelected(sal_Int32 nAccessibleChildIndex)722     AccessibleDrawDocumentView::implIsSelected( sal_Int32 nAccessibleChildIndex )
723 {
724     const vos::OGuard                           aSolarGuard( Application::GetSolarMutex() );
725     uno::Reference< view::XSelectionSupplier >  xSel( mxController, uno::UNO_QUERY );
726     sal_Bool                                    bRet = sal_False;
727 
728     OSL_ENSURE( 0 <= nAccessibleChildIndex, "AccessibleDrawDocumentView::implIsSelected: invalid index!" );
729 
730     if( xSel.is() && ( 0 <= nAccessibleChildIndex ) )
731     {
732         uno::Any                            aAny( xSel->getSelection() );
733         uno::Reference< drawing::XShapes >  xShapes;
734 
735         aAny >>= xShapes;
736 
737         if( xShapes.is() )
738         {
739             AccessibleShape* pAcc = AccessibleShape::getImplementation( getAccessibleChild( nAccessibleChildIndex ) );
740 
741             if( pAcc )
742             {
743                 uno::Reference< drawing::XShape > xShape( pAcc->GetXShape() );
744 
745                 if( xShape.is() )
746                 {
747                     for( sal_Int32 i = 0, nCount = xShapes->getCount(); ( i < nCount ) && !bRet; ++i )
748                         if( xShapes->getByIndex( i ) == xShape )
749                             bRet = sal_True;
750                 }
751             }
752         }
753     }
754 
755     return( bRet );
756 }
757 
758 
759 
760 
761 /** Select or delselect the specified shapes.  The corresponding accessible
762     shapes are notified over the selection change listeners registered with
763     the XSelectionSupplier of the controller.
764 */
765 void
implSelect(sal_Int32 nAccessibleChildIndex,sal_Bool bSelect)766     AccessibleDrawDocumentView::implSelect( sal_Int32 nAccessibleChildIndex, sal_Bool bSelect )
767 {
768     const vos::OGuard                           aSolarGuard( Application::GetSolarMutex() );
769     uno::Reference< view::XSelectionSupplier >  xSel( mxController, uno::UNO_QUERY );
770     AccessibleShape* pAccessibleChild;
771 
772     if( xSel.is() )
773     {
774         uno::Any aAny;
775 
776         if( ACCESSIBLE_SELECTION_CHILD_ALL == nAccessibleChildIndex )
777         {
778             // Select or deselect all children.
779 
780             if( !bSelect )
781                 xSel->select( aAny );
782             else
783             {
784                 uno::Reference< drawing::XShapes > xShapes( new SvxShapeCollection() );
785 
786                 for(sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
787                 {
788                     AccessibleShape* pAcc = AccessibleShape::getImplementation( getAccessibleChild( i ) );
789 
790                     if( pAcc && pAcc->GetXShape().is() )
791                     {
792                         xShapes->add( pAcc->GetXShape() );
793                         pAccessibleChild = pAcc;
794                     }
795                 }
796 
797                 if( xShapes->getCount() )
798                 {
799                     aAny <<= xShapes;
800                     xSel->select( aAny );
801                 }
802             }
803         }
804         else if( nAccessibleChildIndex >= 0 )
805         {
806             // Select or deselect only the child with index
807             // nAccessibleChildIndex.
808 
809             AccessibleShape* pAcc = AccessibleShape::getImplementation(
810                 getAccessibleChild( nAccessibleChildIndex ));
811             pAccessibleChild = pAcc;
812 
813             // Add or remove the shape that is made accessible from the
814             // selection of the controller.
815             if( pAcc )
816             {
817                 uno::Reference< drawing::XShape > xShape( pAcc->GetXShape() );
818 
819                 if( xShape.is() )
820                 {
821                     uno::Reference< drawing::XShapes >  xShapes;
822                     sal_Bool                            bFound = sal_False;
823 
824                     aAny = xSel->getSelection();
825                     aAny >>= xShapes;
826 
827                     // Search shape to be selected in current selection.
828                     if (xShapes.is())
829                     {
830                         sal_Int32 nCount = xShapes->getCount();
831                         for (sal_Int32 i=0; ( i < nCount ) && !bFound; ++i )
832                             if( xShapes->getByIndex( i ) == xShape )
833                                 bFound = sal_True;
834                     }
835                     else
836                         // Create an empty selection to add the shape to.
837                         xShapes = new SvxShapeCollection();
838 
839                     // Update the selection.
840                     if( !bFound && bSelect )
841                         xShapes->add( xShape );
842                     else if( bFound && !bSelect )
843                         xShapes->remove( xShape );
844 
845                     aAny <<= xShapes;
846                     xSel->select( aAny );
847                 }
848             }
849         }
850     }
851 }
852 
853 
854 
855 
Activated(void)856 void AccessibleDrawDocumentView::Activated (void)
857 {
858     if (mpChildrenManager != NULL)
859     {
860     sal_Bool bChange = sal_False;
861         // When none of the children has the focus then claim it for the
862         // view.
863         if ( ! mpChildrenManager->HasFocus())
864     {
865             SetState (AccessibleStateType::FOCUSED);
866         bChange = sal_True;
867     }
868         else
869             ResetState (AccessibleStateType::FOCUSED);
870     mpChildrenManager->UpdateSelection();
871     // if the child gets focus in UpdateSelection(), needs to reset the focus on document.
872     if (mpChildrenManager->HasFocus() && bChange)
873         ResetState (AccessibleStateType::FOCUSED);
874     }
875 }
876 
877 
878 
879 
Deactivated(void)880 void AccessibleDrawDocumentView::Deactivated (void)
881 {
882     if (mpChildrenManager != NULL)
883         mpChildrenManager->RemoveFocus();
884     ResetState (AccessibleStateType::FOCUSED);
885 }
886 
887 
888 
889 
impl_dispose(void)890 void AccessibleDrawDocumentView::impl_dispose (void)
891 {
892     if (mpChildrenManager != NULL)
893     {
894         delete mpChildrenManager;
895         mpChildrenManager = NULL;
896     }
897 
898     AccessibleDocumentViewBase::impl_dispose();
899 }
900 
901 
902 
903 /** This method is called from the component helper base class while
904     disposing.
905 */
disposing(void)906 void SAL_CALL AccessibleDrawDocumentView::disposing (void)
907 {
908 
909     // Release resources.
910     if (mpChildrenManager != NULL)
911     {
912         delete mpChildrenManager;
913         mpChildrenManager = NULL;
914     }
915 
916     // Forward call to base classes.
917     AccessibleDocumentViewBase::disposing ();
918 }
919 
920 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
get_AccFlowTo(const::com::sun::star::uno::Any & rAny,sal_Int32 nType)921         SAL_CALL AccessibleDrawDocumentView::get_AccFlowTo(const ::com::sun::star::uno::Any& rAny, sal_Int32 nType)
922 {
923     const sal_Int32 SPELLCHECKFLOWTO = 1;
924     const sal_Int32 FINDREPLACEFLOWTO = 2;
925     if ( nType == SPELLCHECKFLOWTO )
926     {
927         uno::Reference< ::com::sun::star::drawing::XShape > xShape;
928         rAny >>= xShape;
929         if ( mpChildrenManager && xShape.is() )
930         {
931             uno::Reference < XAccessible > xAcc = mpChildrenManager->GetChild(xShape);
932             uno::Reference < XAccessibleSelection > xAccSelection( xAcc, uno::UNO_QUERY );
933             if ( xAccSelection.is() )
934             {
935                 if ( xAccSelection->getSelectedAccessibleChildCount() )
936                 {
937                     uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 );
938                     if ( xSel.is() )
939                     {
940                         uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
941                         if ( xSelContext.is() )
942                         {
943                             //if in sw we find the selected paragraph here
944                             if ( xSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
945                             {
946                                 uno::Sequence<uno::Any> aRet( 1 );
947                                 aRet[0] = uno::makeAny( xSel );
948                                 return aRet;
949                             }
950                         }
951                     }
952                 }
953             }
954             uno::Reference<XAccessible> xPara = GetSelAccContextInTable();
955             if ( xPara.is() )
956             {
957                 uno::Sequence<uno::Any> aRet( 1 );
958                 aRet[0] = uno::makeAny( xPara );
959                 return aRet;
960             }
961         }
962         else
963         {
964             goto Rt;
965         }
966     }
967     else if ( nType == FINDREPLACEFLOWTO )
968     {
969         sal_Int32 nChildCount = getSelectedAccessibleChildCount();
970         if ( nChildCount )
971         {
972             uno::Reference < XAccessible > xSel = getSelectedAccessibleChild( 0 );
973             if ( xSel.is() )
974             {
975                 uno::Reference < XAccessibleSelection > xAccChildSelection( xSel, uno::UNO_QUERY );
976                 if ( xAccChildSelection.is() )
977                 {
978                     if ( xAccChildSelection->getSelectedAccessibleChildCount() )
979                     {
980                         uno::Reference < XAccessible > xChildSel = xAccChildSelection->getSelectedAccessibleChild( 0 );
981                         if ( xChildSel.is() )
982                         {
983                             uno::Reference < XAccessibleContext > xChildSelContext( xChildSel->getAccessibleContext() );
984                             if ( xChildSelContext.is() &&
985                                 xChildSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
986                             {
987                                 uno::Sequence<uno::Any> aRet( 1 );
988                                 aRet[0] = uno::makeAny( xChildSel );
989                                 return aRet;
990                             }
991                         }
992                     }
993                 }
994             }
995         }
996         else
997         {
998             uno::Reference<XAccessible> xPara = GetSelAccContextInTable();
999             if ( xPara.is() )
1000             {
1001                 uno::Sequence<uno::Any> aRet( 1 );
1002                 aRet[0] = uno::makeAny( xPara );
1003                 return aRet;
1004             }
1005         }
1006     }
1007 
1008 Rt:
1009     ::com::sun::star::uno::Sequence< uno::Any> aRet;
1010     return aRet;
1011 }
GetSelAccContextInTable()1012 uno::Reference<XAccessible> AccessibleDrawDocumentView::GetSelAccContextInTable()
1013 {
1014     uno::Reference<XAccessible> xRet;
1015     sal_Int32 nCount = mpChildrenManager ? mpChildrenManager->GetChildCount() : 0;
1016     if ( nCount )
1017     {
1018         for ( sal_Int32 i = 0; i < nCount; i++ )
1019         {
1020             try
1021             {
1022                 uno::Reference<XAccessible> xObj = mpChildrenManager->GetChild(i);
1023                 if ( xObj.is() )
1024                 {
1025                     uno::Reference<XAccessibleContext> xObjContext( xObj, uno::UNO_QUERY );
1026                     if ( xObjContext.is() && xObjContext->getAccessibleRole() == AccessibleRole::TABLE )
1027                     {
1028                         uno::Reference<XAccessibleSelection> xObjSelection( xObj, uno::UNO_QUERY );
1029                         if ( xObjSelection.is() && xObjSelection->getSelectedAccessibleChildCount() )
1030                         {
1031                             uno::Reference<XAccessible> xCell = xObjSelection->getSelectedAccessibleChild(0);
1032                             if ( xCell.is() )
1033                             {
1034                                 uno::Reference<XAccessibleSelection> xCellSel( xCell, uno::UNO_QUERY );
1035                                 if ( xCellSel.is() && xCellSel->getSelectedAccessibleChildCount() )
1036                                 {
1037                                     uno::Reference<XAccessible> xPara = xCellSel->getSelectedAccessibleChild( 0 );
1038                                     if ( xPara.is() )
1039                                     {
1040                                         uno::Reference<XAccessibleContext> xParaContext( xPara, uno::UNO_QUERY );
1041                                         if ( xParaContext.is() &&
1042                                             xParaContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
1043                                         {
1044                                             xRet = xPara;
1045                                             return xRet;
1046                                         }
1047                                     }
1048                                 }
1049                             }
1050                         }
1051                     }
1052                 }
1053             }
1054             catch ( lang::IndexOutOfBoundsException )
1055             {
1056                 uno::Reference<XAccessible> xEmpty;
1057                 return xEmpty;
1058             }
1059             catch ( uno::RuntimeException )
1060             {
1061                 uno::Reference<XAccessible> xEmpty;
1062                 return xEmpty;
1063             }
1064         }
1065     }
1066 
1067     return xRet;
1068 }
1069 
UpdateAccessibleName(void)1070 void AccessibleDrawDocumentView::UpdateAccessibleName (void)
1071 {
1072     OUString sNewName (CreateAccessibleName());
1073     sNewName += A2S(": ");
1074 
1075     // Add the number of the current slide.
1076     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
1077     if (xView.is())
1078     {
1079         uno::Reference<beans::XPropertySet> xProperties (xView->getCurrentPage(), UNO_QUERY);
1080         if (xProperties.is())
1081             try
1082             {
1083                 sal_Int16 nPageNumber (0);
1084                 if (xProperties->getPropertyValue(A2S("Number")) >>= nPageNumber)
1085                 {
1086                     sNewName += OUString::valueOf(sal_Int32(nPageNumber));
1087                 }
1088             }
1089             catch (beans::UnknownPropertyException&)
1090             {
1091             }
1092     }
1093 
1094     // Add the number of pages/slides.
1095     Reference<drawing::XDrawPagesSupplier> xPagesSupplier (mxModel, UNO_QUERY);
1096     if (xPagesSupplier.is())
1097     {
1098         Reference<container::XIndexAccess> xPages (xPagesSupplier->getDrawPages(), UNO_QUERY);
1099         if (xPages.is())
1100         {
1101             sNewName += A2S(" / ");
1102             sNewName += OUString::valueOf(xPages->getCount());
1103         }
1104     }
1105 
1106     SetAccessibleName (sNewName, AutomaticallyCreated);
1107 }
1108 
1109 
1110 
1111 
1112 } // end of namespace accessibility
1113