fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleSlideSorterView.cxx
blobba31c04cb623cf3d25a8dc3b0d24f8f7d58f36f3
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 .
21 #include "AccessibleSlideSorterView.hxx"
22 #include "AccessibleSlideSorterObject.hxx"
24 #include "SlideSorter.hxx"
25 #include "controller/SlideSorterController.hxx"
26 #include "controller/SlsPageSelector.hxx"
27 #include "controller/SlsFocusManager.hxx"
28 #include "controller/SlsSelectionManager.hxx"
29 #include "view/SlideSorterView.hxx"
30 #include "model/SlideSorterModel.hxx"
31 #include "model/SlsPageDescriptor.hxx"
32 #include "SlideSorterViewShell.hxx"
34 #include "ViewShellHint.hxx"
35 #include "sdpage.hxx"
36 #include "drawdoc.hxx"
38 #include "sdresid.hxx"
39 #include "accessibility.hrc"
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
42 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43 #include <comphelper/accessibleeventnotifier.hxx>
44 #include <unotools/accessiblestatesethelper.hxx>
45 #include <rtl/ref.hxx>
46 #include <vcl/svapp.hxx>
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::accessibility;
52 namespace accessibility {
55 /** Inner implementation class of the AccessibleSlideSorterView.
57 Note that some event broadcasting is done asynchronously because
58 otherwise it could lead to deadlocks on (at least) some Solaris
59 machines. Probably (but unverified) this can happen on all GTK based
60 systems. The asynchronous broadcasting is just a workaround for a
61 poorly understood problem.
63 class AccessibleSlideSorterView::Implementation
64 : public SfxListener
66 public:
67 Implementation (
68 AccessibleSlideSorterView& rAccessibleSlideSorter,
69 ::sd::slidesorter::SlideSorter& rSlideSorter,
70 ::Window* pWindow);
71 ~Implementation (void);
73 void RequestUpdateChildren (void);
74 void Clear (void);
75 sal_Int32 GetVisibleChildCount (void) const;
76 AccessibleSlideSorterObject* GetAccessibleChild (sal_Int32 nIndex);
77 AccessibleSlideSorterObject* GetVisibleChild (sal_Int32 nIndex);
79 void ConnectListeners (void);
80 void ReleaseListeners (void);
81 void Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint);
82 DECL_LINK(WindowEventListener, VclWindowEvent*);
83 DECL_LINK(SelectionChangeListener, void*);
84 DECL_LINK(BroadcastSelectionChange, void*);
85 DECL_LINK(FocusChangeListener, void*);
86 DECL_LINK(VisibilityChangeListener, void*);
87 DECL_LINK(UpdateChildrenCallback, void*);
89 private:
90 AccessibleSlideSorterView& mrAccessibleSlideSorter;
91 ::sd::slidesorter::SlideSorter& mrSlideSorter;
92 typedef ::std::vector<rtl::Reference<AccessibleSlideSorterObject> > PageObjectList;
93 PageObjectList maPageObjects;
94 sal_Int32 mnFirstVisibleChild;
95 sal_Int32 mnLastVisibleChild;
96 bool mbListeningToDocument;
97 ::Window* mpWindow;
98 sal_Int32 mnFocusedIndex;
99 bool mbModelChangeLocked;
100 sal_uLong mnUpdateChildrenUserEventId;
101 sal_uLong mnSelectionChangeUserEventId;
103 void UpdateChildren (void);
109 //===== AccessibleSlideSorterView =============================================
111 AccessibleSlideSorterView::AccessibleSlideSorterView(
112 ::sd::slidesorter::SlideSorter& rSlideSorter,
113 const Reference<XAccessible>& rxParent,
114 ::Window* pContentWindow)
115 : AccessibleSlideSorterViewBase(MutexOwner::maMutex),
116 mrSlideSorter(rSlideSorter),
117 mxParent(rxParent),
118 mnClientId(0),
119 mpContentWindow(pContentWindow)
127 void AccessibleSlideSorterView::Init()
129 mpImpl.reset(new Implementation(*this,mrSlideSorter,mpContentWindow));
136 AccessibleSlideSorterView::~AccessibleSlideSorterView (void)
138 Destroyed ();
144 void AccessibleSlideSorterView::FireAccessibleEvent (
145 short nEventId,
146 const uno::Any& rOldValue,
147 const uno::Any& rNewValue )
149 if (mnClientId != 0)
151 AccessibleEventObject aEventObject;
153 aEventObject.Source = Reference<XWeak>(this);
154 aEventObject.EventId = nEventId;
155 aEventObject.NewValue = rNewValue;
156 aEventObject.OldValue = rOldValue;
158 comphelper::AccessibleEventNotifier::addEvent (mnClientId, aEventObject);
165 void SAL_CALL AccessibleSlideSorterView::disposing (void)
167 if (mnClientId != 0)
169 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
170 mnClientId = 0;
172 mpImpl.reset(NULL);
178 AccessibleSlideSorterObject* AccessibleSlideSorterView::GetAccessibleChildImplementation (
179 sal_Int32 nIndex)
181 AccessibleSlideSorterObject* pResult = NULL;
182 ::osl::MutexGuard aGuard (maMutex);
184 if (nIndex>=0 && nIndex<mpImpl->GetVisibleChildCount())
185 pResult = mpImpl->GetVisibleChild(nIndex);
187 return pResult;
190 void AccessibleSlideSorterView::Destroyed (void)
192 ::osl::MutexGuard aGuard (maMutex);
194 // Send a disposing to all listeners.
195 if (mnClientId != 0)
197 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
198 mnClientId = 0;
202 //===== XAccessible =========================================================
204 Reference<XAccessibleContext > SAL_CALL
205 AccessibleSlideSorterView::getAccessibleContext (void)
206 throw (uno::RuntimeException)
208 ThrowIfDisposed ();
209 return this;
212 //===== XAccessibleContext ==================================================
214 sal_Int32 SAL_CALL AccessibleSlideSorterView::getAccessibleChildCount (void)
215 throw (RuntimeException)
217 ThrowIfDisposed();
218 ::osl::MutexGuard aGuard (maMutex);
219 return mpImpl->GetVisibleChildCount();
222 Reference<XAccessible > SAL_CALL
223 AccessibleSlideSorterView::getAccessibleChild (sal_Int32 nIndex)
224 throw (lang::IndexOutOfBoundsException, RuntimeException)
226 ThrowIfDisposed();
227 ::osl::MutexGuard aGuard (maMutex);
229 if (nIndex<0 || nIndex>=mpImpl->GetVisibleChildCount())
230 throw lang::IndexOutOfBoundsException();
232 return mpImpl->GetVisibleChild(nIndex);
235 Reference<XAccessible > SAL_CALL AccessibleSlideSorterView::getAccessibleParent (void)
236 throw (uno::RuntimeException)
238 ThrowIfDisposed();
239 const SolarMutexGuard aSolarGuard;
240 Reference<XAccessible> xParent;
242 if (mpContentWindow != NULL)
244 ::Window* pParent = mpContentWindow->GetAccessibleParentWindow();
245 if (pParent != NULL)
246 xParent = pParent->GetAccessible();
249 return xParent;
252 sal_Int32 SAL_CALL AccessibleSlideSorterView::getAccessibleIndexInParent (void)
253 throw (uno::RuntimeException)
255 OSL_ASSERT(getAccessibleParent().is());
256 ThrowIfDisposed();
257 const SolarMutexGuard aSolarGuard;
258 sal_Int32 nIndexInParent(-1);
261 Reference<XAccessibleContext> xParentContext (getAccessibleParent()->getAccessibleContext());
262 if (xParentContext.is())
264 sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
265 for (sal_Int32 i=0; i<nChildCount; ++i)
266 if (xParentContext->getAccessibleChild(i).get()
267 == static_cast<XAccessible*>(this))
269 nIndexInParent = i;
270 break;
274 return nIndexInParent;
280 sal_Int16 SAL_CALL AccessibleSlideSorterView::getAccessibleRole (void)
281 throw (uno::RuntimeException)
283 ThrowIfDisposed();
284 static sal_Int16 nRole = AccessibleRole::DOCUMENT;
285 return nRole;
291 OUString SAL_CALL AccessibleSlideSorterView::getAccessibleDescription (void)
292 throw (uno::RuntimeException)
294 ThrowIfDisposed();
295 SolarMutexGuard aGuard;
297 return String(SdResId(SID_SD_A11Y_I_SLIDEVIEW_D));
303 OUString SAL_CALL AccessibleSlideSorterView::getAccessibleName (void)
304 throw (uno::RuntimeException)
306 ThrowIfDisposed();
307 SolarMutexGuard aGuard;
309 return String(SdResId(SID_SD_A11Y_I_SLIDEVIEW_N));
315 Reference<XAccessibleRelationSet> SAL_CALL
316 AccessibleSlideSorterView::getAccessibleRelationSet (void)
317 throw (uno::RuntimeException)
319 return Reference<XAccessibleRelationSet>();
325 Reference<XAccessibleStateSet > SAL_CALL
326 AccessibleSlideSorterView::getAccessibleStateSet (void)
327 throw (uno::RuntimeException)
329 ThrowIfDisposed();
330 const SolarMutexGuard aSolarGuard;
331 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
333 pStateSet->AddState(AccessibleStateType::FOCUSABLE);
334 pStateSet->AddState(AccessibleStateType::SELECTABLE);
335 pStateSet->AddState(AccessibleStateType::ENABLED);
336 pStateSet->AddState(AccessibleStateType::ACTIVE);
337 pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
338 pStateSet->AddState(AccessibleStateType::OPAQUE);
339 if (mpContentWindow!=NULL)
341 if (mpContentWindow->IsVisible())
342 pStateSet->AddState(AccessibleStateType::VISIBLE);
343 if (mpContentWindow->IsReallyVisible())
344 pStateSet->AddState(AccessibleStateType::SHOWING);
347 return pStateSet;
353 lang::Locale SAL_CALL AccessibleSlideSorterView::getLocale (void)
354 throw (IllegalAccessibleComponentStateException,
355 RuntimeException)
357 ThrowIfDisposed ();
358 Reference<XAccessibleContext> xParentContext;
359 Reference<XAccessible> xParent (getAccessibleParent());
360 if (xParent.is())
361 xParentContext = xParent->getAccessibleContext();
363 if (xParentContext.is())
364 return xParentContext->getLocale();
365 else
366 // Strange, no parent! Anyway, return the default locale.
367 return Application::GetSettings().GetLanguageTag().getLocale();
373 void SAL_CALL AccessibleSlideSorterView::addAccessibleEventListener(
374 const Reference<XAccessibleEventListener >& rxListener)
375 throw (RuntimeException)
377 if (rxListener.is())
379 const osl::MutexGuard aGuard(maMutex);
381 if (IsDisposed())
383 uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
384 rxListener->disposing (lang::EventObject (x));
386 else
388 if ( ! mnClientId)
389 mnClientId = comphelper::AccessibleEventNotifier::registerClient();
390 comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
398 void SAL_CALL AccessibleSlideSorterView::removeAccessibleEventListener(
399 const Reference<XAccessibleEventListener >& rxListener)
400 throw (RuntimeException)
402 ThrowIfDisposed();
403 if (rxListener.is())
405 const osl::MutexGuard aGuard(maMutex);
407 if (mnClientId != 0)
409 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener(
410 mnClientId, rxListener );
411 if ( !nListenerCount )
413 // no listeners anymore -> revoke ourself. This may lead to
414 // the notifier thread dying (if we were the last client),
415 // and at least to us not firing any events anymore, in case
416 // somebody calls NotifyAccessibleEvent, again
417 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
418 mnClientId = 0;
427 //===== XAccessibleComponent ==================================================
429 sal_Bool SAL_CALL AccessibleSlideSorterView::containsPoint (const awt::Point& aPoint)
430 throw (RuntimeException)
432 ThrowIfDisposed();
433 const awt::Rectangle aBBox (getBounds());
434 return (aPoint.X >= 0)
435 && (aPoint.X < aBBox.Width)
436 && (aPoint.Y >= 0)
437 && (aPoint.Y < aBBox.Height);
443 Reference<XAccessible> SAL_CALL
444 AccessibleSlideSorterView::getAccessibleAtPoint (const awt::Point& aPoint)
445 throw (RuntimeException)
447 ThrowIfDisposed();
448 Reference<XAccessible> xAccessible;
449 const SolarMutexGuard aSolarGuard;
451 const Point aTestPoint (aPoint.X, aPoint.Y);
452 ::sd::slidesorter::model::SharedPageDescriptor pHitDescriptor (
453 mrSlideSorter.GetController().GetPageAt(aTestPoint));
454 if (pHitDescriptor.get() != NULL)
455 xAccessible = mpImpl->GetAccessibleChild(
456 (pHitDescriptor->GetPage()->GetPageNum()-1)/2);
458 return xAccessible;
464 awt::Rectangle SAL_CALL AccessibleSlideSorterView::getBounds (void)
465 throw (uno::RuntimeException)
467 ThrowIfDisposed();
468 const SolarMutexGuard aSolarGuard;
469 awt::Rectangle aBBox;
471 if (mpContentWindow != NULL)
473 const Point aPosition (mpContentWindow->GetPosPixel());
474 const Size aSize (mpContentWindow->GetOutputSizePixel());
476 aBBox.X = aPosition.X();
477 aBBox.Y = aPosition.Y();
478 aBBox.Width = aSize.Width();
479 aBBox.Height = aSize.Height();
482 return aBBox;
488 awt::Point SAL_CALL AccessibleSlideSorterView::getLocation (void)
489 throw (uno::RuntimeException)
491 ThrowIfDisposed();
492 awt::Point aLocation;
494 if (mpContentWindow != NULL)
496 const Point aPosition (mpContentWindow->GetPosPixel());
497 aLocation.X = aPosition.X();
498 aLocation.Y = aPosition.Y();
501 return aLocation;
507 /** Calculate the location on screen from the parent's location on screen
508 and our own relative location.
510 awt::Point SAL_CALL AccessibleSlideSorterView::getLocationOnScreen()
511 throw (uno::RuntimeException)
513 ThrowIfDisposed();
514 const SolarMutexGuard aSolarGuard;
515 awt::Point aParentLocationOnScreen;
517 Reference<XAccessible> xParent (getAccessibleParent());
518 if (xParent.is())
520 Reference<XAccessibleComponent> xParentComponent (
521 xParent->getAccessibleContext(), uno::UNO_QUERY);
522 if (xParentComponent.is())
523 aParentLocationOnScreen = xParentComponent->getLocationOnScreen();
526 awt::Point aLocationOnScreen (getLocation());
527 aLocationOnScreen.X += aParentLocationOnScreen.X;
528 aLocationOnScreen.Y += aParentLocationOnScreen.Y;
530 return aLocationOnScreen;
536 awt::Size SAL_CALL AccessibleSlideSorterView::getSize (void)
537 throw (uno::RuntimeException)
539 ThrowIfDisposed();
540 awt::Size aSize;
542 if (mpContentWindow != NULL)
544 const Size aOutputSize (mpContentWindow->GetOutputSizePixel());
545 aSize.Width = aOutputSize.Width();
546 aSize.Height = aOutputSize.Height();
549 return aSize;
555 void SAL_CALL AccessibleSlideSorterView::grabFocus (void)
556 throw (uno::RuntimeException)
558 ThrowIfDisposed();
559 const SolarMutexGuard aSolarGuard;
561 if (mpContentWindow)
562 mpContentWindow->GrabFocus();
568 sal_Int32 SAL_CALL AccessibleSlideSorterView::getForeground (void)
569 throw (RuntimeException)
571 ThrowIfDisposed();
572 svtools::ColorConfig aColorConfig;
573 sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
574 return static_cast<sal_Int32>(nColor);
580 sal_Int32 SAL_CALL AccessibleSlideSorterView::getBackground (void)
581 throw (RuntimeException)
583 ThrowIfDisposed();
584 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
585 return static_cast<sal_Int32>(nColor);
591 //===== XAccessibleSelection ==================================================
593 void SAL_CALL AccessibleSlideSorterView::selectAccessibleChild (sal_Int32 nChildIndex)
594 throw (lang::IndexOutOfBoundsException,
595 RuntimeException)
597 ThrowIfDisposed();
598 const SolarMutexGuard aSolarGuard;
600 AccessibleSlideSorterObject* pChild = mpImpl->GetAccessibleChild(nChildIndex);
601 if (pChild != NULL)
602 mrSlideSorter.GetController().GetPageSelector().SelectPage(pChild->GetPageNumber());
603 else
604 throw lang::IndexOutOfBoundsException();
610 sal_Bool SAL_CALL AccessibleSlideSorterView::isAccessibleChildSelected (sal_Int32 nChildIndex)
611 throw (lang::IndexOutOfBoundsException,
612 RuntimeException)
614 ThrowIfDisposed();
615 sal_Bool bIsSelected = sal_False;
616 const SolarMutexGuard aSolarGuard;
618 AccessibleSlideSorterObject* pChild = mpImpl->GetAccessibleChild(nChildIndex);
619 if (pChild != NULL)
620 bIsSelected = mrSlideSorter.GetController().GetPageSelector().IsPageSelected(
621 pChild->GetPageNumber());
622 else
623 throw lang::IndexOutOfBoundsException();
625 return bIsSelected;
631 void SAL_CALL AccessibleSlideSorterView::clearAccessibleSelection (void)
632 throw (uno::RuntimeException)
634 ThrowIfDisposed();
635 const SolarMutexGuard aSolarGuard;
637 mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
643 void SAL_CALL AccessibleSlideSorterView::selectAllAccessibleChildren (void)
644 throw (uno::RuntimeException)
646 ThrowIfDisposed();
647 const SolarMutexGuard aSolarGuard;
649 mrSlideSorter.GetController().GetPageSelector().SelectAllPages();
655 sal_Int32 SAL_CALL AccessibleSlideSorterView::getSelectedAccessibleChildCount (void)
656 throw (uno::RuntimeException)
658 ThrowIfDisposed ();
659 const SolarMutexGuard aSolarGuard;
660 return mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount();
666 Reference<XAccessible > SAL_CALL
667 AccessibleSlideSorterView::getSelectedAccessibleChild (sal_Int32 nSelectedChildIndex )
668 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
670 ThrowIfDisposed ();
671 const SolarMutexGuard aSolarGuard;
672 Reference<XAccessible> xChild;
674 ::sd::slidesorter::controller::PageSelector& rSelector (
675 mrSlideSorter.GetController().GetPageSelector());
676 sal_Int32 nPageCount(rSelector.GetPageCount());
677 sal_Int32 nSelectedCount = 0;
678 for (sal_Int32 i=0; i<nPageCount; i++)
679 if (rSelector.IsPageSelected(i))
681 if (nSelectedCount == nSelectedChildIndex)
683 xChild = mpImpl->GetAccessibleChild(i);
684 break;
686 ++nSelectedCount;
690 if ( ! xChild.is() )
691 throw lang::IndexOutOfBoundsException();
693 return xChild;
699 void SAL_CALL AccessibleSlideSorterView::deselectAccessibleChild (sal_Int32 nChildIndex)
700 throw (lang::IndexOutOfBoundsException,
701 RuntimeException)
703 ThrowIfDisposed();
704 const SolarMutexGuard aSolarGuard;
706 AccessibleSlideSorterObject* pChild = mpImpl->GetAccessibleChild(nChildIndex);
707 if (pChild != NULL)
708 mrSlideSorter.GetController().GetPageSelector().DeselectPage(pChild->GetPageNumber());
709 else
710 throw lang::IndexOutOfBoundsException();
716 //===== XServiceInfo ========================================================
718 OUString SAL_CALL
719 AccessibleSlideSorterView::getImplementationName (void)
720 throw (::com::sun::star::uno::RuntimeException)
722 return OUString("AccessibleSlideSorterView");
728 sal_Bool SAL_CALL
729 AccessibleSlideSorterView::supportsService (const OUString& sServiceName)
730 throw (::com::sun::star::uno::RuntimeException)
732 ThrowIfDisposed ();
734 // Iterate over all supported service names and return true if on of them
735 // matches the given name.
736 uno::Sequence< OUString> aSupportedServices (
737 getSupportedServiceNames ());
738 for (int i=0; i<aSupportedServices.getLength(); i++)
739 if (sServiceName == aSupportedServices[i])
740 return sal_True;
741 return sal_False;
747 uno::Sequence< OUString> SAL_CALL
748 AccessibleSlideSorterView::getSupportedServiceNames (void)
749 throw (::com::sun::star::uno::RuntimeException)
751 ThrowIfDisposed ();
753 static const OUString sServiceNames[3] = {
754 OUString("com.sun.star.accessibility.Accessible"),
755 OUString("com.sun.star.accessibility.AccessibleContext"),
756 OUString("com.sun.star.drawing.AccessibleSlideSorterView")
758 return uno::Sequence<OUString> (sServiceNames, 3);
764 void AccessibleSlideSorterView::ThrowIfDisposed (void)
765 throw (lang::DisposedException)
767 if (rBHelper.bDisposed || rBHelper.bInDispose)
769 OSL_TRACE ("Calling disposed object. Throwing exception:");
770 throw lang::DisposedException ("object has been already disposed",
771 static_cast<uno::XWeak*>(this));
777 sal_Bool AccessibleSlideSorterView::IsDisposed (void)
779 return (rBHelper.bDisposed || rBHelper.bInDispose);
785 //===== AccessibleSlideSorterView::Implementation =============================
787 AccessibleSlideSorterView::Implementation::Implementation (
788 AccessibleSlideSorterView& rAccessibleSlideSorter,
789 ::sd::slidesorter::SlideSorter& rSlideSorter,
790 ::Window* pWindow)
791 : mrAccessibleSlideSorter(rAccessibleSlideSorter),
792 mrSlideSorter(rSlideSorter),
793 maPageObjects(),
794 mnFirstVisibleChild(0),
795 mnLastVisibleChild(-1),
796 mbListeningToDocument(false),
797 mpWindow(pWindow),
798 mnFocusedIndex(-1),
799 mbModelChangeLocked(false),
800 mnUpdateChildrenUserEventId(0),
801 mnSelectionChangeUserEventId(0)
803 ConnectListeners();
804 UpdateChildren();
810 AccessibleSlideSorterView::Implementation::~Implementation (void)
812 if (mnUpdateChildrenUserEventId != 0)
813 Application::RemoveUserEvent(mnUpdateChildrenUserEventId);
814 if (mnSelectionChangeUserEventId != 0)
815 Application::RemoveUserEvent(mnSelectionChangeUserEventId);
816 ReleaseListeners();
817 Clear();
823 void AccessibleSlideSorterView::Implementation::RequestUpdateChildren (void)
825 if (mnUpdateChildrenUserEventId == 0)
826 mnUpdateChildrenUserEventId = Application::PostUserEvent(
827 LINK(this, AccessibleSlideSorterView::Implementation,
828 UpdateChildrenCallback));
834 void AccessibleSlideSorterView::Implementation::UpdateChildren (void)
836 if (mbModelChangeLocked)
838 // Do nothing right now. When the flag is reset, this method is
839 // called again.
840 return;
843 const Pair aRange (mrSlideSorter.GetView().GetVisiblePageRange());
844 mnFirstVisibleChild = aRange.A();
845 mnLastVisibleChild = aRange.B();
847 // Release all children.
848 Clear();
850 // Create new children for the modified visible range.
851 maPageObjects.resize(mrSlideSorter.GetModel().GetPageCount());
853 // No Visible children
854 if (mnFirstVisibleChild == -1 && mnLastVisibleChild == -1)
855 return;
857 for (sal_Int32 nIndex(mnFirstVisibleChild); nIndex<=mnLastVisibleChild; ++nIndex)
858 GetAccessibleChild(nIndex);
864 void AccessibleSlideSorterView::Implementation::Clear (void)
866 PageObjectList::iterator iPageObject;
867 PageObjectList::iterator iEnd = maPageObjects.end();
868 for (iPageObject=maPageObjects.begin(); iPageObject!=iEnd; ++iPageObject)
869 if (*iPageObject != NULL)
871 mrAccessibleSlideSorter.FireAccessibleEvent(
872 AccessibleEventId::CHILD,
873 Any(Reference<XAccessible>(iPageObject->get())),
874 Any());
876 Reference<XComponent> xComponent (Reference<XWeak>(iPageObject->get()), UNO_QUERY);
877 if (xComponent.is())
878 xComponent->dispose();
879 *iPageObject = NULL;
881 maPageObjects.clear();
887 sal_Int32 AccessibleSlideSorterView::Implementation::GetVisibleChildCount (void) const
889 if (mnFirstVisibleChild<=mnLastVisibleChild && mnFirstVisibleChild>=0)
890 return mnLastVisibleChild - mnFirstVisibleChild + 1;
891 else
892 return 0;
898 AccessibleSlideSorterObject* AccessibleSlideSorterView::Implementation::GetVisibleChild (
899 sal_Int32 nIndex)
901 assert(nIndex>=0 && nIndex<GetVisibleChildCount());
903 return GetAccessibleChild(nIndex+mnFirstVisibleChild);
909 AccessibleSlideSorterObject* AccessibleSlideSorterView::Implementation::GetAccessibleChild (
910 sal_Int32 nIndex)
912 AccessibleSlideSorterObject* pChild = NULL;
914 if (nIndex>=0 && (sal_uInt32)nIndex<maPageObjects.size())
916 if (maPageObjects[nIndex] == NULL)
918 ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
919 mrSlideSorter.GetModel().GetPageDescriptor(nIndex));
920 if (pDescriptor.get() != NULL)
922 maPageObjects[nIndex] = new AccessibleSlideSorterObject(
923 &mrAccessibleSlideSorter,
924 mrSlideSorter,
925 (pDescriptor->GetPage()->GetPageNum()-1)/2);
927 mrAccessibleSlideSorter.FireAccessibleEvent(
928 AccessibleEventId::CHILD,
929 Any(),
930 Any(Reference<XAccessible>(maPageObjects[nIndex].get())));
935 pChild = maPageObjects[nIndex].get();
937 else
939 OSL_ASSERT(nIndex>=0 && (sal_uInt32)nIndex<maPageObjects.size());
942 return pChild;
948 void AccessibleSlideSorterView::Implementation::ConnectListeners (void)
950 StartListening (*mrSlideSorter.GetModel().GetDocument());
951 if (mrSlideSorter.GetViewShell() != NULL)
952 StartListening (*mrSlideSorter.GetViewShell());
953 mbListeningToDocument = true;
955 if (mpWindow != NULL)
956 mpWindow->AddEventListener(
957 LINK(this,AccessibleSlideSorterView::Implementation,WindowEventListener));
959 mrSlideSorter.GetController().GetSelectionManager()->AddSelectionChangeListener(
960 LINK(this,AccessibleSlideSorterView::Implementation,SelectionChangeListener));
961 mrSlideSorter.GetController().GetFocusManager().AddFocusChangeListener(
962 LINK(this,AccessibleSlideSorterView::Implementation,FocusChangeListener));
963 mrSlideSorter.GetView().AddVisibilityChangeListener(
964 LINK(this,AccessibleSlideSorterView::Implementation,VisibilityChangeListener));
970 void AccessibleSlideSorterView::Implementation::ReleaseListeners (void)
972 mrSlideSorter.GetController().GetFocusManager().RemoveFocusChangeListener(
973 LINK(this,AccessibleSlideSorterView::Implementation,FocusChangeListener));
974 mrSlideSorter.GetController().GetSelectionManager()->RemoveSelectionChangeListener(
975 LINK(this,AccessibleSlideSorterView::Implementation,SelectionChangeListener));
976 mrSlideSorter.GetView().RemoveVisibilityChangeListener(
977 LINK(this,AccessibleSlideSorterView::Implementation,VisibilityChangeListener));
979 if (mpWindow != NULL)
980 mpWindow->RemoveEventListener(
981 LINK(this,AccessibleSlideSorterView::Implementation,WindowEventListener));
983 if (mbListeningToDocument)
985 if (mrSlideSorter.GetViewShell() != NULL)
986 StartListening(*mrSlideSorter.GetViewShell());
987 EndListening (*mrSlideSorter.GetModel().GetDocument());
988 mbListeningToDocument = false;
995 void AccessibleSlideSorterView::Implementation::Notify (
996 SfxBroadcaster&,
997 const SfxHint& rHint)
999 if (rHint.ISA(SdrHint))
1001 SdrHint& rSdrHint (*PTR_CAST(SdrHint,&rHint));
1002 switch (rSdrHint.GetKind())
1004 case HINT_PAGEORDERCHG:
1005 RequestUpdateChildren();
1006 break;
1007 default:
1008 break;
1011 else if (rHint.ISA(sd::ViewShellHint))
1013 sd::ViewShellHint& rViewShellHint (*PTR_CAST(sd::ViewShellHint, &rHint));
1014 switch (rViewShellHint.GetHintId())
1016 case sd::ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START:
1017 mbModelChangeLocked = true;
1018 break;
1020 case sd::ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END:
1021 mbModelChangeLocked = false;
1022 RequestUpdateChildren();
1023 break;
1024 default:
1025 break;
1033 IMPL_LINK(AccessibleSlideSorterView::Implementation, WindowEventListener, VclWindowEvent*, pEvent)
1035 switch (pEvent->GetId())
1037 case VCLEVENT_WINDOW_MOVE:
1038 case VCLEVENT_WINDOW_RESIZE:
1039 RequestUpdateChildren();
1040 break;
1042 case VCLEVENT_WINDOW_GETFOCUS:
1043 case VCLEVENT_WINDOW_LOSEFOCUS:
1044 mrAccessibleSlideSorter.FireAccessibleEvent(
1045 AccessibleEventId::SELECTION_CHANGED,
1046 Any(),
1047 Any());
1048 break;
1049 default:
1050 break;
1052 return 1;
1058 IMPL_LINK_NOARG(AccessibleSlideSorterView::Implementation, SelectionChangeListener)
1060 if (mnSelectionChangeUserEventId == 0)
1061 mnSelectionChangeUserEventId = Application::PostUserEvent(
1062 LINK(this, AccessibleSlideSorterView::Implementation, BroadcastSelectionChange));
1063 return 1;
1069 IMPL_LINK_NOARG(AccessibleSlideSorterView::Implementation, BroadcastSelectionChange)
1071 mnSelectionChangeUserEventId = 0;
1072 mrAccessibleSlideSorter.FireAccessibleEvent(
1073 AccessibleEventId::SELECTION_CHANGED,
1074 Any(),
1075 Any());
1076 return 1;
1082 IMPL_LINK_NOARG(AccessibleSlideSorterView::Implementation, FocusChangeListener)
1084 sal_Int32 nNewFocusedIndex (
1085 mrSlideSorter.GetController().GetFocusManager().GetFocusedPageIndex());
1087 if (nNewFocusedIndex != mnFocusedIndex)
1089 if (mnFocusedIndex >= 0)
1091 AccessibleSlideSorterObject* pObject = GetAccessibleChild(mnFocusedIndex);
1092 if (pObject != NULL)
1093 pObject->FireAccessibleEvent(
1094 AccessibleEventId::STATE_CHANGED,
1095 Any(AccessibleStateType::FOCUSED),
1096 Any());
1098 if (nNewFocusedIndex >= 0)
1100 AccessibleSlideSorterObject* pObject = GetAccessibleChild(nNewFocusedIndex);
1101 if (pObject != NULL)
1102 pObject->FireAccessibleEvent(
1103 AccessibleEventId::STATE_CHANGED,
1104 Any(),
1105 Any(AccessibleStateType::FOCUSED));
1107 mnFocusedIndex = nNewFocusedIndex;
1109 return 1;
1115 IMPL_LINK_NOARG(AccessibleSlideSorterView::Implementation, UpdateChildrenCallback)
1117 mnUpdateChildrenUserEventId = 0;
1118 UpdateChildren();
1120 return 1;
1126 IMPL_LINK_NOARG(AccessibleSlideSorterView::Implementation, VisibilityChangeListener)
1128 UpdateChildren();
1129 return 1;
1132 } // end of namespace ::accessibility
1134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */