fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleDocumentViewBase.cxx
blobd07489869b6ae134cc9ab0a0f72191d80e2d5d0e
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 "AccessibleDocumentViewBase.hxx"
21 #include <com/sun/star/drawing/XDrawPage.hpp>
22 #include <com/sun/star/drawing/XDrawView.hpp>
23 #include <com/sun/star/drawing/XShapes.hpp>
24 #include <com/sun/star/container/XChild.hpp>
25 #include <com/sun/star/frame/XController.hpp>
26 #include <com/sun/star/frame/XFrame.hpp>
27 #include <com/sun/star/document/XEventBroadcaster.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <rtl/ustring.h>
33 #include<sfx2/viewfrm.hxx>
35 #include <svx/AccessibleShape.hxx>
37 #include <svx/svdobj.hxx>
38 #include <svx/svdmodel.hxx>
39 #include <svx/unoapi.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include "Window.hxx"
42 #include <vcl/svapp.hxx>
45 #include "ViewShell.hxx"
46 #include "View.hxx"
47 #include <memory>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::accessibility;
51 using ::com::sun::star::uno::Reference;
53 namespace accessibility {
55 //===== internal ============================================================
56 AccessibleDocumentViewBase::AccessibleDocumentViewBase (
57 ::sd::Window* pSdWindow,
58 ::sd::ViewShell* pViewShell,
59 const uno::Reference<frame::XController>& rxController,
60 const uno::Reference<XAccessible>& rxParent)
61 : AccessibleContextBase (rxParent, AccessibleRole::DOCUMENT),
62 mpWindow (pSdWindow),
63 mxController (rxController),
64 mxModel (NULL),
65 maViewForwarder (
66 static_cast<SdrPaintView*>(pViewShell->GetView()),
67 *static_cast<OutputDevice*>(pSdWindow))
69 if (mxController.is())
70 mxModel = mxController->getModel();
72 // Fill the shape tree info.
73 maShapeTreeInfo.SetModelBroadcaster (
74 uno::Reference<document::XEventBroadcaster>(
75 mxModel, uno::UNO_QUERY));
76 maShapeTreeInfo.SetController (mxController);
77 maShapeTreeInfo.SetSdrView (pViewShell->GetView());
78 maShapeTreeInfo.SetWindow (pSdWindow);
79 maShapeTreeInfo.SetViewForwarder (&maViewForwarder);
81 mxWindow = ::VCLUnoHelper::GetInterface (pSdWindow);
87 AccessibleDocumentViewBase::~AccessibleDocumentViewBase (void)
89 // At this place we should be disposed. You may want to add a
90 // corresponding assertion into the destructor of a derived class.
96 void AccessibleDocumentViewBase::Init (void)
98 // Finish the initialization of the shape tree info container.
99 maShapeTreeInfo.SetDocumentWindow (this);
101 // Register as window listener to stay up to date with its size and
102 // position.
103 mxWindow->addWindowListener (this);
104 // Register as focus listener to
105 mxWindow->addFocusListener (this);
107 // Determine the list of shapes on the current page.
108 uno::Reference<drawing::XShapes> xShapeList;
109 uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
110 if (xView.is())
111 xShapeList = uno::Reference<drawing::XShapes> (
112 xView->getCurrentPage(), uno::UNO_QUERY);
114 // Register this object as dispose event listener at the model.
115 if (mxModel.is())
116 mxModel->addEventListener (
117 static_cast<awt::XWindowListener*>(this));
119 // Register as property change listener at the controller.
120 uno::Reference<beans::XPropertySet> xSet (mxController, uno::UNO_QUERY);
121 if (xSet.is())
122 xSet->addPropertyChangeListener (
124 static_cast<beans::XPropertyChangeListener*>(this));
126 // Register this object as dispose event listener at the controller.
127 if (mxController.is())
128 mxController->addEventListener (
129 static_cast<awt::XWindowListener*>(this));
131 // Register at VCL Window to be informed of activated and deactivated
132 // OLE objects.
133 Window* pWindow = maShapeTreeInfo.GetWindow();
134 if (pWindow != NULL)
136 maWindowLink = LINK(
137 this, AccessibleDocumentViewBase, WindowChildEventListener);
139 pWindow->AddChildEventListener (maWindowLink);
141 sal_uInt16 nCount = pWindow->GetChildCount();
142 for (sal_uInt16 i=0; i<nCount; i++)
144 Window* pChildWindow = pWindow->GetChild (i);
145 if (pChildWindow &&
146 (AccessibleRole::EMBEDDED_OBJECT
147 ==pChildWindow->GetAccessibleRole()))
149 SetAccessibleOLEObject (pChildWindow->GetAccessible());
158 IMPL_LINK(AccessibleDocumentViewBase, WindowChildEventListener,
159 VclSimpleEvent*, pEvent)
161 OSL_ASSERT(pEvent!=NULL && pEvent->ISA(VclWindowEvent));
162 if (pEvent!=NULL && pEvent->ISA(VclWindowEvent))
164 VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent);
165 // DBG_ASSERT( pVclEvent->GetWindow(), "Window???" );
166 switch (pWindowEvent->GetId())
168 case VCLEVENT_OBJECT_DYING:
170 // Window is dying. Unregister from VCL Window.
171 // This is also attempted in the disposing() method.
172 Window* pWindow = maShapeTreeInfo.GetWindow();
173 Window* pDyingWindow = static_cast<Window*>(
174 pWindowEvent->GetWindow());
175 if (pWindow==pDyingWindow && pWindow!=NULL && maWindowLink.IsSet())
177 pWindow->RemoveChildEventListener (maWindowLink);
178 maWindowLink = Link();
181 break;
183 case VCLEVENT_WINDOW_SHOW:
185 // A new window has been created. Is it an OLE object?
186 Window* pChildWindow = static_cast<Window*>(
187 pWindowEvent->GetData());
188 if (pChildWindow!=NULL
189 && (pChildWindow->GetAccessibleRole()
190 == AccessibleRole::EMBEDDED_OBJECT))
192 SetAccessibleOLEObject (pChildWindow->GetAccessible());
195 break;
197 case VCLEVENT_WINDOW_HIDE:
199 // A window has been destroyed. Has that been an OLE
200 // object?
201 Window* pChildWindow = static_cast<Window*>(
202 pWindowEvent->GetData());
203 if (pChildWindow!=NULL
204 && (pChildWindow->GetAccessibleRole()
205 == AccessibleRole::EMBEDDED_OBJECT))
207 SetAccessibleOLEObject (NULL);
210 break;
214 return 0;
220 //===== IAccessibleViewForwarderListener ====================================
222 void AccessibleDocumentViewBase::ViewForwarderChanged(ChangeType, const IAccessibleViewForwarder* )
224 // Empty
230 //===== XAccessibleContext ==================================================
232 Reference<XAccessible> SAL_CALL
233 AccessibleDocumentViewBase::getAccessibleParent (void)
234 throw (uno::RuntimeException)
236 ThrowIfDisposed ();
238 return AccessibleContextBase::getAccessibleParent();
243 sal_Int32 SAL_CALL
244 AccessibleDocumentViewBase::getAccessibleChildCount (void)
245 throw (uno::RuntimeException)
247 ThrowIfDisposed ();
249 if (mxAccessibleOLEObject.is())
250 return 1;
251 else
252 return 0;
258 Reference<XAccessible> SAL_CALL
259 AccessibleDocumentViewBase::getAccessibleChild (sal_Int32 nIndex)
260 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
262 ThrowIfDisposed ();
264 ::osl::MutexGuard aGuard (maMutex);
265 if (mxAccessibleOLEObject.is())
266 if (nIndex == 0)
267 return mxAccessibleOLEObject;
269 throw lang::IndexOutOfBoundsException ( "no child with index " + OUString::valueOf(nIndex), NULL);
275 //===== XAccessibleComponent ================================================
277 /** Iterate over all children and test whether the specified point lies
278 within one of their bounding boxes. Return the first child for which
279 this is true.
281 uno::Reference<XAccessible > SAL_CALL
282 AccessibleDocumentViewBase::getAccessibleAtPoint (
283 const awt::Point& aPoint)
284 throw (uno::RuntimeException)
286 ThrowIfDisposed ();
288 ::osl::MutexGuard aGuard (maMutex);
289 uno::Reference<XAccessible> xChildAtPosition;
291 sal_Int32 nChildCount = getAccessibleChildCount ();
292 for (sal_Int32 i=nChildCount-1; i>=0; --i)
294 Reference<XAccessible> xChild (getAccessibleChild (i));
295 if (xChild.is())
297 Reference<XAccessibleComponent> xChildComponent (
298 xChild->getAccessibleContext(), uno::UNO_QUERY);
299 if (xChildComponent.is())
301 awt::Rectangle aBBox (xChildComponent->getBounds());
302 if ( (aPoint.X >= aBBox.X)
303 && (aPoint.Y >= aBBox.Y)
304 && (aPoint.X < aBBox.X+aBBox.Width)
305 && (aPoint.Y < aBBox.Y+aBBox.Height) )
307 xChildAtPosition = xChild;
308 break;
314 // Have not found a child under the given point. Returning empty
315 // reference to indicate this.
316 return xChildAtPosition;
322 awt::Rectangle SAL_CALL
323 AccessibleDocumentViewBase::getBounds (void)
324 throw (::com::sun::star::uno::RuntimeException)
326 ThrowIfDisposed ();
328 // Transform visible area into screen coordinates.
329 ::Rectangle aVisibleArea (
330 maShapeTreeInfo.GetViewForwarder()->GetVisibleArea());
331 ::Point aPixelTopLeft (
332 maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
333 aVisibleArea.TopLeft()));
334 ::Point aPixelSize (
335 maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
336 aVisibleArea.BottomRight())
337 - aPixelTopLeft);
339 // Prepare to subtract the parent position to transform into relative
340 // coordinates.
341 awt::Point aParentPosition;
342 Reference<XAccessible> xParent = getAccessibleParent ();
343 if (xParent.is())
345 Reference<XAccessibleComponent> xParentComponent (
346 xParent->getAccessibleContext(), uno::UNO_QUERY);
347 if (xParentComponent.is())
348 aParentPosition = xParentComponent->getLocationOnScreen();
351 return awt::Rectangle (
352 aPixelTopLeft.X() - aParentPosition.X,
353 aPixelTopLeft.Y() - aParentPosition.Y,
354 aPixelSize.X(),
355 aPixelSize.Y());
361 awt::Point SAL_CALL
362 AccessibleDocumentViewBase::getLocation (void)
363 throw (uno::RuntimeException)
365 ThrowIfDisposed ();
366 awt::Rectangle aBoundingBox (getBounds());
367 return awt::Point (aBoundingBox.X, aBoundingBox.Y);
373 awt::Point SAL_CALL
374 AccessibleDocumentViewBase::getLocationOnScreen (void)
375 throw (uno::RuntimeException)
377 ThrowIfDisposed ();
378 ::Point aLogicalPoint (maShapeTreeInfo.GetViewForwarder()->GetVisibleArea().TopLeft());
379 ::Point aPixelPoint (maShapeTreeInfo.GetViewForwarder()->LogicToPixel (aLogicalPoint));
380 return awt::Point (aPixelPoint.X(), aPixelPoint.Y());
386 awt::Size SAL_CALL
387 AccessibleDocumentViewBase::getSize (void)
388 throw (uno::RuntimeException)
390 ThrowIfDisposed ();
392 // Transform visible area into screen coordinates.
393 ::Rectangle aVisibleArea (
394 maShapeTreeInfo.GetViewForwarder()->GetVisibleArea());
395 ::Point aPixelTopLeft (
396 maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
397 aVisibleArea.TopLeft()));
398 ::Point aPixelSize (
399 maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
400 aVisibleArea.BottomRight())
401 - aPixelTopLeft);
403 return awt::Size (aPixelSize.X(), aPixelSize.Y());
409 //===== XInterface ==========================================================
411 uno::Any SAL_CALL
412 AccessibleDocumentViewBase::queryInterface (const uno::Type & rType)
413 throw (uno::RuntimeException)
415 uno::Any aReturn = AccessibleContextBase::queryInterface (rType);
416 if ( ! aReturn.hasValue())
417 aReturn = ::cppu::queryInterface (rType,
418 static_cast<XAccessibleComponent*>(this),
419 static_cast<XAccessibleSelection*>(this),
420 static_cast<lang::XEventListener*>(
421 static_cast<awt::XWindowListener*>(this)),
422 static_cast<beans::XPropertyChangeListener*>(this),
423 static_cast<awt::XWindowListener*>(this),
424 static_cast<awt::XFocusListener*>(this)
426 return aReturn;
432 void SAL_CALL
433 AccessibleDocumentViewBase::acquire (void)
434 throw ()
436 AccessibleContextBase::acquire ();
442 void SAL_CALL
443 AccessibleDocumentViewBase::release (void)
444 throw ()
446 AccessibleContextBase::release ();
452 //===== XServiceInfo ========================================================
454 OUString SAL_CALL
455 AccessibleDocumentViewBase::getImplementationName (void)
456 throw (::com::sun::star::uno::RuntimeException)
458 return OUString("AccessibleDocumentViewBase");
464 ::com::sun::star::uno::Sequence< OUString> SAL_CALL
465 AccessibleDocumentViewBase::getSupportedServiceNames (void)
466 throw (::com::sun::star::uno::RuntimeException)
468 ThrowIfDisposed ();
469 return AccessibleContextBase::getSupportedServiceNames ();
476 //===== XTypeProvider =======================================================
478 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL
479 AccessibleDocumentViewBase::getTypes (void)
480 throw (::com::sun::star::uno::RuntimeException)
482 ThrowIfDisposed ();
484 // Get list of types from the context base implementation, ...
485 uno::Sequence<uno::Type> aTypeList (AccessibleContextBase::getTypes());
486 // ... get list of types from component base implementation, ...
487 uno::Sequence<uno::Type> aComponentTypeList (AccessibleComponentBase::getTypes());
490 // ...and add the additional type for the component, ...
491 const uno::Type aLangEventListenerType =
492 ::getCppuType((const uno::Reference<lang::XEventListener>*)0);
493 const uno::Type aPropertyChangeListenerType =
494 ::getCppuType((const uno::Reference<beans::XPropertyChangeListener>*)0);
495 const uno::Type aWindowListenerType =
496 ::getCppuType((const uno::Reference<awt::XWindowListener>*)0);
497 const uno::Type aFocusListenerType =
498 ::getCppuType((const uno::Reference<awt::XFocusListener>*)0);
499 const uno::Type aEventBroadcaster =
500 ::getCppuType((const uno::Reference<XAccessibleEventBroadcaster>*)0);
502 // ... and merge them all into one list.
503 sal_Int32 nTypeCount (aTypeList.getLength()),
504 nComponentTypeCount (aComponentTypeList.getLength()),
507 aTypeList.realloc (nTypeCount + nComponentTypeCount + 5);
509 for (i=0; i<nComponentTypeCount; i++)
510 aTypeList[nTypeCount + i] = aComponentTypeList[i];
512 aTypeList[nTypeCount + i++ ] = aLangEventListenerType;
513 aTypeList[nTypeCount + i++] = aPropertyChangeListenerType;
514 aTypeList[nTypeCount + i++] = aWindowListenerType;
515 aTypeList[nTypeCount + i++] = aFocusListenerType;
516 aTypeList[nTypeCount + i++] = aEventBroadcaster;
518 return aTypeList;
524 void AccessibleDocumentViewBase::impl_dispose()
526 // Unregister from VCL Window.
527 Window* pWindow = maShapeTreeInfo.GetWindow();
528 if (maWindowLink.IsSet())
530 if (pWindow)
531 pWindow->RemoveChildEventListener (maWindowLink);
532 maWindowLink = Link();
534 else
536 DBG_ASSERT (pWindow, "AccessibleDocumentViewBase::disposing");
539 // Unregister from window.
540 if (mxWindow.is())
542 mxWindow->removeWindowListener (this);
543 mxWindow->removeFocusListener (this);
544 mxWindow = NULL;
547 // Unregister form the model.
548 if (mxModel.is())
549 mxModel->removeEventListener (
550 static_cast<awt::XWindowListener*>(this));
552 // Unregister from the controller.
553 if (mxController.is())
555 uno::Reference<beans::XPropertySet> xSet (mxController, uno::UNO_QUERY);
556 if (xSet.is())
557 xSet->removePropertyChangeListener ("", static_cast<beans::XPropertyChangeListener*>(this));
559 mxController->removeEventListener (
560 static_cast<awt::XWindowListener*>(this));
563 // Propagate change of controller down the shape tree.
564 maShapeTreeInfo.SetControllerBroadcaster (NULL);
566 // Reset the model reference.
567 mxModel = NULL;
568 // Reset the model reference.
569 mxController = NULL;
571 maShapeTreeInfo.SetDocumentWindow (NULL);
577 //===== XEventListener ======================================================
579 void SAL_CALL
580 AccessibleDocumentViewBase::disposing (const lang::EventObject& rEventObject)
581 throw (::com::sun::star::uno::RuntimeException)
583 ThrowIfDisposed ();
585 // Register this object as dispose event and document::XEventListener
586 // listener at the model.
588 if ( ! rEventObject.Source.is())
590 // Paranoia. Can this really happen?
592 else if (rEventObject.Source == mxModel || rEventObject.Source == mxController)
594 impl_dispose();
598 //===== XPropertyChangeListener =============================================
600 void SAL_CALL AccessibleDocumentViewBase::propertyChange (const beans::PropertyChangeEvent& )
601 throw (::com::sun::star::uno::RuntimeException)
603 // Empty
609 //===== XWindowListener =====================================================
611 void SAL_CALL
612 AccessibleDocumentViewBase::windowResized (const ::com::sun::star::awt::WindowEvent& )
613 throw (::com::sun::star::uno::RuntimeException)
615 if( IsDisposed() )
616 return;
618 ViewForwarderChanged (
619 IAccessibleViewForwarderListener::VISIBLE_AREA,
620 &maViewForwarder);
626 void SAL_CALL
627 AccessibleDocumentViewBase::windowMoved (const ::com::sun::star::awt::WindowEvent& )
628 throw (::com::sun::star::uno::RuntimeException)
630 if( IsDisposed() )
631 return;
633 ViewForwarderChanged (
634 IAccessibleViewForwarderListener::VISIBLE_AREA,
635 &maViewForwarder);
641 void SAL_CALL
642 AccessibleDocumentViewBase::windowShown (const ::com::sun::star::lang::EventObject& )
643 throw (::com::sun::star::uno::RuntimeException)
645 if( IsDisposed() )
646 return;
648 ViewForwarderChanged (
649 IAccessibleViewForwarderListener::VISIBLE_AREA,
650 &maViewForwarder);
656 void SAL_CALL
657 AccessibleDocumentViewBase::windowHidden (const ::com::sun::star::lang::EventObject& )
658 throw (::com::sun::star::uno::RuntimeException)
660 if( IsDisposed() )
661 return;
663 ViewForwarderChanged (
664 IAccessibleViewForwarderListener::VISIBLE_AREA,
665 &maViewForwarder);
671 //===== XFocusListener ==================================================
673 void AccessibleDocumentViewBase::focusGained (const ::com::sun::star::awt::FocusEvent& e)
674 throw (::com::sun::star::uno::RuntimeException)
676 ThrowIfDisposed ();
677 if (e.Source == mxWindow)
678 Activated ();
681 void AccessibleDocumentViewBase::focusLost (const ::com::sun::star::awt::FocusEvent& e)
682 throw (::com::sun::star::uno::RuntimeException)
684 ThrowIfDisposed ();
685 if (e.Source == mxWindow)
686 Deactivated ();
692 //===== protected internal ==================================================
694 // This method is called from the component helper base class while disposing.
695 void SAL_CALL AccessibleDocumentViewBase::disposing (void)
697 impl_dispose();
699 AccessibleContextBase::disposing ();
705 /// Create a name for this view.
706 OUString
707 AccessibleDocumentViewBase::CreateAccessibleName (void)
708 throw (::com::sun::star::uno::RuntimeException)
710 return OUString ("AccessibleDocumentViewBase");
716 /** Create a description for this view. Use the model's description or URL
717 if a description is not available.
719 OUString
720 AccessibleDocumentViewBase::CreateAccessibleDescription (void)
721 throw (::com::sun::star::uno::RuntimeException)
723 OUString sDescription;
725 uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
726 if (xInfo.is())
728 OUString sFirstService = xInfo->getSupportedServiceNames()[0];
729 if ( sFirstService == "com.sun.star.drawing.DrawingDocumentDrawView" )
731 sDescription = "Draw Document";
733 else
734 sDescription = sFirstService;
736 else
737 sDescription = "Accessible Draw Document";
738 return sDescription;
744 void AccessibleDocumentViewBase::Activated (void)
746 // Empty. Overwrite to do something useful.
752 void AccessibleDocumentViewBase::Deactivated (void)
754 // Empty. Overwrite to do something useful.
760 void AccessibleDocumentViewBase::SetAccessibleOLEObject (
761 const Reference <XAccessible>& xOLEObject)
763 // Send child event about removed accessible OLE object if necessary.
764 if (mxAccessibleOLEObject != xOLEObject)
765 if (mxAccessibleOLEObject.is())
766 CommitChange (
767 AccessibleEventId::CHILD,
768 uno::Any(),
769 uno::makeAny (mxAccessibleOLEObject));
771 // Assume that the accessible OLE Object disposes itself correctly.
774 ::osl::MutexGuard aGuard (maMutex);
775 mxAccessibleOLEObject = xOLEObject;
778 // Send child event about new accessible OLE object if necessary.
779 if (mxAccessibleOLEObject.is())
780 CommitChange (
781 AccessibleEventId::CHILD,
782 uno::makeAny (mxAccessibleOLEObject),
783 uno::Any());
789 //===== methods from AccessibleSelectionBase ==================================================
791 // return the member maMutex;
792 ::osl::Mutex&
793 AccessibleDocumentViewBase::implGetMutex()
795 return( maMutex );
798 // return ourself as context in default case
799 uno::Reference< XAccessibleContext >
800 AccessibleDocumentViewBase::implGetAccessibleContext()
801 throw (uno::RuntimeException)
803 return( this );
806 // return sal_False in default case
807 sal_Bool
808 AccessibleDocumentViewBase::implIsSelected( sal_Int32 )
809 throw (uno::RuntimeException)
811 return( sal_False );
814 // return nothing in default case
815 void
816 AccessibleDocumentViewBase::implSelect( sal_Int32, sal_Bool )
817 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
821 } // end of namespace accessibility
823 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */