bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleDrawDocumentView.cxx
blob2e295a0eaf5601ec55363bc1f50821068b82408c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <AccessibleDrawDocumentView.hxx>
21 #include <com/sun/star/drawing/ShapeCollection.hpp>
22 #include <com/sun/star/drawing/XDrawView.hpp>
23 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
24 #include <com/sun/star/drawing/XShapes.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/accessibility/AccessibleRole.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/view/XSelectionSupplier.hpp>
32 #include <cppuhelper/queryinterface.hxx>
33 #include <comphelper/accflowenum.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <sal/log.hxx>
36 #include <tools/debug.hxx>
38 #include <svx/AccessibleShape.hxx>
39 #include <svx/ChildrenManager.hxx>
40 #include <svx/svdobj.hxx>
41 #include <svx/unoapi.hxx>
42 #include <vcl/svapp.hxx>
44 #include <ViewShell.hxx>
45 #include <View.hxx>
46 #include <DrawDocShell.hxx>
47 #include <drawdoc.hxx>
48 #include <algorithm>
49 #include <slideshow.hxx>
50 #include <anminfo.hxx>
51 #include <AccessiblePageShape.hxx>
53 #include <strings.hrc>
54 #include <sdresid.hxx>
55 #include <osl/mutex.hxx>
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::accessibility;
61 namespace accessibility {
63 struct XShapePosCompareHelper
65 bool operator() ( const uno::Reference<drawing::XShape>& xshape1,
66 const uno::Reference<drawing::XShape>& xshape2 ) const
68 // modify the compare method to return the Z-Order, not layout order
69 SdrObject* pObj1 = GetSdrObjectFromXShape(xshape1);
70 SdrObject* pObj2 = GetSdrObjectFromXShape(xshape2);
71 if(pObj1 && pObj2)
72 return pObj1->GetOrdNum() < pObj2->GetOrdNum();
73 else
74 return false;
77 //===== internal ============================================================
79 AccessibleDrawDocumentView::AccessibleDrawDocumentView (
80 ::sd::Window* pSdWindow,
81 ::sd::ViewShell* pViewShell,
82 const uno::Reference<frame::XController>& rxController,
83 const uno::Reference<XAccessible>& rxParent)
84 : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
85 mpSdViewSh( pViewShell )
87 UpdateAccessibleName();
90 AccessibleDrawDocumentView::~AccessibleDrawDocumentView()
92 DBG_ASSERT (rBHelper.bDisposed || rBHelper.bInDispose,
93 "~AccessibleDrawDocumentView: object has not been disposed");
96 void AccessibleDrawDocumentView::Init()
98 AccessibleDocumentViewBase::Init ();
100 // Determine the list of shapes on the current page.
101 uno::Reference<drawing::XShapes> xShapeList;
102 uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
103 if (xView.is())
104 xShapeList = xView->getCurrentPage();
106 // Create the children manager.
107 mpChildrenManager.reset(new ChildrenManager(this, xShapeList, maShapeTreeInfo, *this));
109 rtl::Reference<AccessiblePageShape> xPage(CreateDrawPageShape());
110 if (xPage.is())
112 xPage->Init();
113 mpChildrenManager->AddAccessibleShape (xPage.get());
114 mpChildrenManager->Update ();
117 mpChildrenManager->UpdateSelection ();
120 void AccessibleDrawDocumentView::ViewForwarderChanged()
122 AccessibleDocumentViewBase::ViewForwarderChanged();
123 if (mpChildrenManager != nullptr)
124 mpChildrenManager->ViewForwarderChanged();
127 /** The page shape is created on every call at the moment (provided that
128 everything goes well).
130 rtl::Reference<AccessiblePageShape> AccessibleDrawDocumentView::CreateDrawPageShape()
132 rtl::Reference<AccessiblePageShape> xShape;
134 // Create a shape that represents the actual draw page.
135 uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
136 if (xView.is())
138 uno::Reference<beans::XPropertySet> xSet (
139 uno::Reference<beans::XPropertySet> (xView->getCurrentPage(), uno::UNO_QUERY));
140 if (xSet.is())
142 // Create a rectangle shape that will represent the draw page.
143 uno::Reference<lang::XMultiServiceFactory> xFactory (mxModel, uno::UNO_QUERY);
144 uno::Reference<drawing::XShape> xRectangle;
145 if (xFactory.is())
146 xRectangle.set(xFactory->createInstance ("com.sun.star.drawing.RectangleShape"),
147 uno::UNO_QUERY);
149 // Set the shape's size and position.
150 if (xRectangle.is())
152 uno::Any aValue;
153 awt::Point aPosition;
154 awt::Size aSize;
156 // Set size and position of the shape to those of the draw
157 // page.
158 aValue = xSet->getPropertyValue ("BorderLeft");
159 aValue >>= aPosition.X;
160 aValue = xSet->getPropertyValue ("BorderTop");
161 aValue >>= aPosition.Y;
162 xRectangle->setPosition (aPosition);
164 aValue = xSet->getPropertyValue ("Width");
165 aValue >>= aSize.Width;
166 aValue = xSet->getPropertyValue ("Height");
167 aValue >>= aSize.Height;
168 xRectangle->setSize (aSize);
170 // Create the accessible object for the shape and
171 // initialize it.
172 xShape = new AccessiblePageShape (
173 xView->getCurrentPage(), this, maShapeTreeInfo);
177 return xShape;
180 //===== XAccessibleContext ==================================================
182 sal_Int32 SAL_CALL
183 AccessibleDrawDocumentView::getAccessibleChildCount()
185 ThrowIfDisposed ();
187 long nChildCount = AccessibleDocumentViewBase::getAccessibleChildCount();
189 // Forward request to children manager.
190 if (mpChildrenManager != nullptr)
191 nChildCount += mpChildrenManager->GetChildCount();
193 return nChildCount;
196 uno::Reference<XAccessible> SAL_CALL
197 AccessibleDrawDocumentView::getAccessibleChild (sal_Int32 nIndex)
199 ThrowIfDisposed ();
201 ::osl::ClearableMutexGuard aGuard (maMutex);
203 // Take care of children of the base class.
204 sal_Int32 nCount = AccessibleDocumentViewBase::getAccessibleChildCount();
205 if (nCount > 0)
207 if (nIndex < nCount)
208 return AccessibleDocumentViewBase::getAccessibleChild(nIndex);
209 else
210 nIndex -= nCount;
213 // Create a copy of the pointer to the children manager and release the
214 // mutex before calling any of its methods.
215 ChildrenManager* pChildrenManager = mpChildrenManager.get();
216 aGuard.clear();
218 // Forward request to children manager.
219 if (pChildrenManager == nullptr)
220 throw lang::IndexOutOfBoundsException (
221 "no accessible child with index " + OUString::number(nIndex),
222 static_cast<uno::XWeak*>(this));
224 return pChildrenManager->GetChild (nIndex);
227 OUString SAL_CALL
228 AccessibleDrawDocumentView::getAccessibleName()
230 SolarMutexGuard g;
232 OUString sName = SdResId(SID_SD_A11Y_D_PRESENTATION);
233 ::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
234 if ( pSdView )
236 SdDrawDocument& rDoc = pSdView->GetDoc();
237 OUString sFileName = rDoc.getDocAccTitle();
238 if ( !sFileName.getLength() )
240 ::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
241 if ( pDocSh )
243 sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
247 OUString sReadOnly;
248 if(rDoc.getDocReadOnly())
250 sReadOnly = SdResId(SID_SD_A11Y_D_PRESENTATION_READONLY);
253 if ( sFileName.getLength() )
255 sName = sFileName + sReadOnly + " - " + sName;
259 return sName;
262 //===== XEventListener ======================================================
264 void SAL_CALL
265 AccessibleDrawDocumentView::disposing (const lang::EventObject& rEventObject)
267 ThrowIfDisposed ();
269 AccessibleDocumentViewBase::disposing (rEventObject);
270 if (rEventObject.Source == mxModel)
272 ::osl::Guard< ::osl::Mutex> aGuard (::osl::Mutex::getGlobalMutex());
273 // maShapeTreeInfo has been modified in base class.
274 if (mpChildrenManager != nullptr)
275 mpChildrenManager->SetInfo (maShapeTreeInfo);
279 //===== XPropertyChangeListener =============================================
281 void SAL_CALL
282 AccessibleDrawDocumentView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
284 ThrowIfDisposed ();
286 AccessibleDocumentViewBase::propertyChange (rEventObject);
288 // add page switch event for slide show mode
289 if (rEventObject.PropertyName == "CurrentPage" ||
290 rEventObject.PropertyName == "PageChange")
292 // Update the accessible name to reflect the current slide.
293 UpdateAccessibleName();
295 // The current page changed. Update the children manager accordingly.
296 uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
297 if (xView.is() && mpChildrenManager!=nullptr)
299 // Inform the children manager to forget all children and give
300 // him the new ones.
301 mpChildrenManager->ClearAccessibleShapeList ();
302 mpChildrenManager->SetShapeList (xView->getCurrentPage());
304 rtl::Reference<AccessiblePageShape> xPage(CreateDrawPageShape ());
305 if (xPage.is())
307 xPage->Init();
308 mpChildrenManager->AddAccessibleShape (xPage.get());
309 mpChildrenManager->Update (false);
312 else
313 SAL_WARN("sd", "View invalid");
314 CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
316 else if ( rEventObject.PropertyName == "VisibleArea" )
318 if (mpChildrenManager != nullptr)
319 mpChildrenManager->ViewForwarderChanged();
321 else if (rEventObject.PropertyName == "ActiveLayer")
323 CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
325 else if (rEventObject.PropertyName == "UpdateAcc")
327 // The current page changed. Update the children manager accordingly.
328 uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
329 if (xView.is() && mpChildrenManager!=nullptr)
331 // Inform the children manager to forget all children and give
332 // him the new ones.
333 mpChildrenManager->ClearAccessibleShapeList ();
334 // update the slide show page's accessible info
335 //mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
336 // xView->getCurrentPage(), uno::UNO_QUERY));
337 rtl::Reference< sd::SlideShow > xSlideshow( sd::SlideShow::GetSlideShow( mpSdViewSh->GetViewShellBase() ) );
338 if( xSlideshow.is() && xSlideshow->isRunning() && xSlideshow->isFullScreen() )
340 css::uno::Reference< drawing::XDrawPage > xSlide;
341 // MT IA2: Not used...
342 // sal_Int32 currentPageIndex = xSlideshow->getCurrentPageIndex();
343 css::uno::Reference< css::presentation::XSlideShowController > xSlideController = xSlideshow->getController();
344 if( xSlideController.is() )
346 xSlide = xSlideController->getCurrentSlide();
347 if (xSlide.is())
349 mpChildrenManager->SetShapeList (xSlide);
353 rtl::Reference<AccessiblePageShape> xPage(CreateDrawPageShape ());
354 if (xPage.is())
356 xPage->Init();
357 mpChildrenManager->AddAccessibleShape (xPage.get());
358 mpChildrenManager->Update (false);
362 else
364 SAL_INFO("sd", "unhandled");
368 // XServiceInfo
370 OUString SAL_CALL
371 AccessibleDrawDocumentView::getImplementationName()
373 return "AccessibleDrawDocumentView";
376 css::uno::Sequence< OUString> SAL_CALL
377 AccessibleDrawDocumentView::getSupportedServiceNames()
379 ThrowIfDisposed();
380 // Get list of supported service names from base class...
381 uno::Sequence<OUString> aServiceNames =
382 AccessibleDocumentViewBase::getSupportedServiceNames();
383 sal_Int32 nCount (aServiceNames.getLength());
385 // ...and add additional names.
386 aServiceNames.realloc (nCount + 1);
387 aServiceNames[nCount] = "com.sun.star.drawing.AccessibleDrawDocumentView";
389 return aServiceNames;
392 //===== XInterface ==========================================================
394 uno::Any SAL_CALL
395 AccessibleDrawDocumentView::queryInterface (const uno::Type & rType)
397 uno::Any aReturn = AccessibleDocumentViewBase::queryInterface (rType);
398 if ( ! aReturn.hasValue())
399 aReturn = ::cppu::queryInterface (rType,
400 static_cast<XAccessibleGroupPosition*>(this)
402 return aReturn;
405 void SAL_CALL
406 AccessibleDrawDocumentView::acquire()
407 throw ()
409 AccessibleDocumentViewBase::acquire ();
411 void SAL_CALL
412 AccessibleDrawDocumentView::release()
413 throw ()
415 AccessibleDocumentViewBase::release ();
417 //===== XAccessibleGroupPosition =========================================
418 uno::Sequence< sal_Int32 > SAL_CALL
419 AccessibleDrawDocumentView::getGroupPosition( const uno::Any& rAny )
421 SolarMutexGuard g;
423 // we will return the:
424 // [0] group level(always be 0 now)
425 // [1] similar items counts in the group
426 // [2] the position of the object in the group
427 uno::Sequence< sal_Int32 > aRet( 3 );
428 //get the xShape of the current selected drawing object
429 uno::Reference<XAccessibleContext> xAccContent;
430 rAny >>= xAccContent;
431 if ( !xAccContent.is() )
433 return aRet;
435 AccessibleShape* pAcc = comphelper::getUnoTunnelImplementation<AccessibleShape>( xAccContent );
436 if ( !pAcc )
438 return aRet;
440 uno::Reference< drawing::XShape > xCurShape = pAcc->GetXShape();
441 if ( !xCurShape.is() )
443 return aRet;
445 //find all the child in the page, insert them into a vector and sort
446 if ( mpChildrenManager == nullptr )
448 return aRet;
450 std::vector< uno::Reference<drawing::XShape> > vXShapes;
451 sal_Int32 nCount = mpChildrenManager->GetChildCount();
452 //get pointer of SdView & SdrPageView for further use.
453 SdrPageView* pPV = nullptr;
454 ::sd::View* pSdView = nullptr;
455 if ( mpSdViewSh )
457 pSdView = mpSdViewSh->GetView();
458 pPV = pSdView->GetSdrPageView();
460 for ( sal_Int32 i = 0; i < nCount; i++ )
462 uno::Reference< drawing::XShape > xShape = mpChildrenManager->GetChildShape(i);
463 if ( xShape.is() )
465 //if the object is visible in the page, we add it into the group list.
466 SdrObject* pObj = GetSdrObjectFromXShape(xShape);
467 if ( pObj && pPV && pSdView && pSdView->IsObjMarkable( pObj, pPV ) )
469 vXShapes.push_back( xShape );
473 std::sort( vXShapes.begin(), vXShapes.end(), XShapePosCompareHelper() );
474 //get the index of the selected object in the group
475 auto aIter = std::find_if(vXShapes.begin(), vXShapes.end(),
476 [&xCurShape](const uno::Reference<drawing::XShape>& rxShape) { return rxShape.get() == xCurShape.get(); });
477 if (aIter != vXShapes.end())
479 sal_Int32* pArray = aRet.getArray();
480 pArray[0] = 1; //it should be 1 based, not 0 based.
481 pArray[1] = vXShapes.size();
482 pArray[2] = static_cast<sal_Int32>(std::distance(vXShapes.begin(), aIter)) + 1; //we start counting position from 1
484 return aRet;
487 OUString AccessibleDrawDocumentView::getObjectLink( const uno::Any& rAny )
489 SolarMutexGuard g;
491 OUString aRet;
492 //get the xShape of the current selected drawing object
493 uno::Reference<XAccessibleContext> xAccContent;
494 rAny >>= xAccContent;
495 if ( !xAccContent.is() )
497 return aRet;
499 AccessibleShape* pAcc = comphelper::getUnoTunnelImplementation<AccessibleShape>( xAccContent );
500 if ( !pAcc )
502 return aRet;
504 uno::Reference< drawing::XShape > xCurShape = pAcc->GetXShape();
505 if ( !xCurShape.is() )
507 return aRet;
509 SdrObject* pObj = GetSdrObjectFromXShape(xCurShape);
510 if (pObj)
512 SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
513 if( pInfo && (pInfo->meClickAction == presentation::ClickAction_DOCUMENT) )
514 aRet = pInfo->GetBookmark();
516 return aRet;
519 /// Create a name for this view.
520 OUString AccessibleDrawDocumentView::CreateAccessibleName()
522 OUString sName;
524 uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
525 if (xInfo.is())
527 uno::Sequence< OUString > aServices( xInfo->getSupportedServiceNames() );
528 OUString sFirstService = aServices[0];
529 if ( sFirstService == "com.sun.star.drawing.DrawingDocumentDrawView" )
531 if( aServices.getLength() >= 2 && aServices[1] == "com.sun.star.presentation.PresentationView")
533 SolarMutexGuard aGuard;
535 sName = SdResId(SID_SD_A11Y_I_DRAWVIEW_N);
537 else
539 SolarMutexGuard aGuard;
541 sName = SdResId(SID_SD_A11Y_D_DRAWVIEW_N);
544 else if ( sFirstService == "com.sun.star.presentation.NotesView" )
546 SolarMutexGuard aGuard;
548 sName = SdResId(SID_SD_A11Y_I_NOTESVIEW_N);
550 else if ( sFirstService == "com.sun.star.presentation.HandoutView" )
552 SolarMutexGuard aGuard;
554 sName = SdResId(SID_SD_A11Y_I_HANDOUTVIEW_N);
556 else
558 sName = sFirstService;
561 else
563 sName = "AccessibleDrawDocumentView";
565 return sName;
568 /** Return selection state of specified child
570 bool
571 AccessibleDrawDocumentView::implIsSelected( sal_Int32 nAccessibleChildIndex )
573 const SolarMutexGuard aSolarGuard;
574 uno::Reference< view::XSelectionSupplier > xSel( mxController, uno::UNO_QUERY );
575 bool bRet = false;
577 OSL_ENSURE( 0 <= nAccessibleChildIndex, "AccessibleDrawDocumentView::implIsSelected: invalid index!" );
579 if( xSel.is() && ( 0 <= nAccessibleChildIndex ) )
581 uno::Any aAny( xSel->getSelection() );
582 uno::Reference< drawing::XShapes > xShapes;
584 aAny >>= xShapes;
586 if( xShapes.is() )
588 AccessibleShape* pAcc = comphelper::getUnoTunnelImplementation<AccessibleShape>( getAccessibleChild( nAccessibleChildIndex ) );
590 if( pAcc )
592 uno::Reference< drawing::XShape > xShape( pAcc->GetXShape() );
594 if( xShape.is() )
596 for( sal_Int32 i = 0, nCount = xShapes->getCount(); ( i < nCount ) && !bRet; ++i )
597 if( xShapes->getByIndex( i ) == xShape )
598 bRet = true;
604 return bRet;
607 /** Select or deselect the specified shapes. The corresponding accessible
608 shapes are notified over the selection change listeners registered with
609 the XSelectionSupplier of the controller.
611 void
612 AccessibleDrawDocumentView::implSelect( sal_Int32 nAccessibleChildIndex, bool bSelect )
614 const SolarMutexGuard aSolarGuard;
615 uno::Reference< view::XSelectionSupplier > xSel( mxController, uno::UNO_QUERY );
617 if( !xSel.is() )
618 return;
620 uno::Any aAny;
622 if( ACCESSIBLE_SELECTION_CHILD_ALL == nAccessibleChildIndex )
624 // Select or deselect all children.
626 if( !bSelect )
627 xSel->select( aAny );
628 else
630 uno::Reference< drawing::XShapes > xShapes = drawing::ShapeCollection::create(
631 comphelper::getProcessComponentContext());
633 for(sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
635 AccessibleShape* pAcc = comphelper::getUnoTunnelImplementation<AccessibleShape>( getAccessibleChild( i ) );
637 if( pAcc && pAcc->GetXShape().is() )
638 xShapes->add( pAcc->GetXShape() );
641 if( xShapes->getCount() )
643 xSel->select( Any(xShapes) );
647 else if( nAccessibleChildIndex >= 0 )
649 // Select or deselect only the child with index
650 // nAccessibleChildIndex.
652 AccessibleShape* pAcc = comphelper::getUnoTunnelImplementation<AccessibleShape>(
653 getAccessibleChild( nAccessibleChildIndex ));
655 // Add or remove the shape that is made accessible from the
656 // selection of the controller.
657 if( pAcc )
659 uno::Reference< drawing::XShape > xShape( pAcc->GetXShape() );
661 if( xShape.is() )
663 uno::Reference< drawing::XShapes > xShapes;
664 bool bFound = false;
666 aAny = xSel->getSelection();
667 aAny >>= xShapes;
669 // Search shape to be selected in current selection.
670 if (xShapes.is())
672 sal_Int32 nCount = xShapes->getCount();
673 for (sal_Int32 i=0; ( i < nCount ) && !bFound; ++i )
674 if( xShapes->getByIndex( i ) == xShape )
675 bFound = true;
677 else
678 // Create an empty selection to add the shape to.
679 xShapes = drawing::ShapeCollection::create(
680 comphelper::getProcessComponentContext());
682 // Update the selection.
683 if( !bFound && bSelect )
684 xShapes->add( xShape );
685 else if( bFound && !bSelect )
686 xShapes->remove( xShape );
688 xSel->select( Any(xShapes) );
694 void AccessibleDrawDocumentView::Activated()
696 if (mpChildrenManager == nullptr)
697 return;
699 bool bChange = false;
700 // When none of the children has the focus then claim it for the
701 // view.
702 if ( ! mpChildrenManager->HasFocus())
704 SetState (AccessibleStateType::FOCUSED);
705 bChange = true;
707 else
708 ResetState (AccessibleStateType::FOCUSED);
709 mpChildrenManager->UpdateSelection();
710 // if the child gets focus in UpdateSelection(), needs to reset the focus on document.
711 if (mpChildrenManager->HasFocus() && bChange)
712 ResetState (AccessibleStateType::FOCUSED);
715 void AccessibleDrawDocumentView::Deactivated()
717 if (mpChildrenManager != nullptr)
718 mpChildrenManager->RemoveFocus();
719 ResetState (AccessibleStateType::FOCUSED);
722 void AccessibleDrawDocumentView::impl_dispose()
724 mpChildrenManager.reset();
725 AccessibleDocumentViewBase::impl_dispose();
728 /** This method is called from the component helper base class while
729 disposing.
731 void SAL_CALL AccessibleDrawDocumentView::disposing()
733 // Release resources.
734 mpChildrenManager.reset();
736 // Forward call to base classes.
737 AccessibleDocumentViewBase::disposing ();
740 css::uno::Sequence< css::uno::Any >
741 SAL_CALL AccessibleDrawDocumentView::getAccFlowTo(const css::uno::Any& rAny, sal_Int32 nType)
743 SolarMutexGuard g;
745 if (nType == AccessibilityFlowTo::FORSPELLCHECKFLOWTO)
747 uno::Reference< css::drawing::XShape > xShape;
748 rAny >>= xShape;
749 if ( mpChildrenManager && xShape.is() )
751 uno::Reference < XAccessible > xAcc = mpChildrenManager->GetChild(xShape);
752 uno::Reference < XAccessibleSelection > xAccSelection( xAcc, uno::UNO_QUERY );
753 if ( xAccSelection.is() )
755 if ( xAccSelection->getSelectedAccessibleChildCount() )
757 uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 );
758 if ( xSel.is() )
760 uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
761 if ( xSelContext.is() )
763 //if in sw we find the selected paragraph here
764 if ( xSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
766 uno::Sequence<uno::Any> aRet( 1 );
767 aRet[0] <<= xSel;
768 return aRet;
774 uno::Reference<XAccessible> xPara = GetSelAccContextInTable();
775 if ( xPara.is() )
777 uno::Sequence<uno::Any> aRet( 1 );
778 aRet[0] <<= xPara;
779 return aRet;
782 else
784 goto Rt;
787 else if (nType == AccessibilityFlowTo::FORFINDREPLACEFLOWTO_ITEM || nType == AccessibilityFlowTo::FORFINDREPLACEFLOWTO_RANGE)
789 sal_Int32 nChildCount = getSelectedAccessibleChildCount();
790 if ( nChildCount )
792 uno::Reference < XAccessible > xSel = getSelectedAccessibleChild( 0 );
793 if ( xSel.is() )
795 uno::Reference < XAccessibleSelection > xAccChildSelection( xSel, uno::UNO_QUERY );
796 if ( xAccChildSelection.is() )
798 if ( xAccChildSelection->getSelectedAccessibleChildCount() )
800 uno::Reference < XAccessible > xChildSel = xAccChildSelection->getSelectedAccessibleChild( 0 );
801 if ( xChildSel.is() )
803 uno::Reference < XAccessibleContext > xChildSelContext( xChildSel->getAccessibleContext() );
804 if ( xChildSelContext.is() &&
805 xChildSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
807 uno::Sequence<uno::Any> aRet( 1 );
808 aRet[0] <<= xChildSel;
809 return aRet;
816 else
818 uno::Reference<XAccessible> xPara = GetSelAccContextInTable();
819 if ( xPara.is() )
821 uno::Sequence<uno::Any> aRet( 1 );
822 aRet[0] <<= xPara;
823 return aRet;
829 css::uno::Sequence< uno::Any> aRet;
830 return aRet;
832 uno::Reference<XAccessible> AccessibleDrawDocumentView::GetSelAccContextInTable()
834 uno::Reference<XAccessible> xRet;
835 sal_Int32 nCount = mpChildrenManager ? mpChildrenManager->GetChildCount() : 0;
836 if ( nCount )
838 for ( sal_Int32 i = 0; i < nCount; i++ )
842 uno::Reference<XAccessible> xObj = mpChildrenManager->GetChild(i);
843 if ( xObj.is() )
845 uno::Reference<XAccessibleContext> xObjContext( xObj, uno::UNO_QUERY );
846 if ( xObjContext.is() && xObjContext->getAccessibleRole() == AccessibleRole::TABLE )
848 uno::Reference<XAccessibleSelection> xObjSelection( xObj, uno::UNO_QUERY );
849 if ( xObjSelection.is() && xObjSelection->getSelectedAccessibleChildCount() )
851 uno::Reference<XAccessible> xCell = xObjSelection->getSelectedAccessibleChild(0);
852 if ( xCell.is() )
854 uno::Reference<XAccessibleSelection> xCellSel( xCell, uno::UNO_QUERY );
855 if ( xCellSel.is() && xCellSel->getSelectedAccessibleChildCount() )
857 uno::Reference<XAccessible> xPara = xCellSel->getSelectedAccessibleChild( 0 );
858 if ( xPara.is() )
860 uno::Reference<XAccessibleContext> xParaContext( xPara, uno::UNO_QUERY );
861 if ( xParaContext.is() &&
862 xParaContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
864 xRet = xPara;
865 return xRet;
874 catch (const lang::IndexOutOfBoundsException&)
876 uno::Reference<XAccessible> xEmpty;
877 return xEmpty;
879 catch (const uno::RuntimeException&)
881 uno::Reference<XAccessible> xEmpty;
882 return xEmpty;
887 return xRet;
890 void AccessibleDrawDocumentView::UpdateAccessibleName()
892 OUString sNewName (CreateAccessibleName() + ": ");
894 // Add the number of the current slide.
895 uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
896 if (xView.is())
898 uno::Reference<beans::XPropertySet> xProperties (xView->getCurrentPage(), UNO_QUERY);
899 if (xProperties.is())
902 sal_Int16 nPageNumber (0);
903 if (xProperties->getPropertyValue("Number") >>= nPageNumber)
905 sNewName += OUString::number(nPageNumber);
908 catch (const beans::UnknownPropertyException&)
913 // Add the number of pages/slides.
914 Reference<drawing::XDrawPagesSupplier> xPagesSupplier (mxModel, UNO_QUERY);
915 if (xPagesSupplier.is())
917 Reference<container::XIndexAccess> xPages = xPagesSupplier->getDrawPages();
918 if (xPages.is())
920 sNewName += " / " + OUString::number(xPages->getCount());
924 SetAccessibleName (sNewName, AutomaticallyCreated);
927 } // end of namespace accessibility
929 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */