merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / accessibility / AccessibleSlideSorterView.cxx
blob4976c392510c3a1f7872a583376a42d87e8a4dc5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleSlideSorterView.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "AccessibleSlideSorterView.hxx"
34 #include "AccessibleSlideSorterObject.hxx"
36 #include "SlideSorter.hxx"
37 #include "controller/SlideSorterController.hxx"
38 #include "controller/SlsPageSelector.hxx"
39 #include "controller/SlsFocusManager.hxx"
40 #include "controller/SlsSelectionManager.hxx"
41 #include "view/SlideSorterView.hxx"
42 #include "model/SlideSorterModel.hxx"
43 #include "model/SlsPageDescriptor.hxx"
44 #include "SlideSorterViewShell.hxx"
46 #include "ViewShellHint.hxx"
47 #include "sdpage.hxx"
48 #include "drawdoc.hxx"
50 #include "sdresid.hxx"
51 #include "accessibility.hrc"
52 #include <com/sun/star/accessibility/AccessibleRole.hpp>
53 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
54 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
55 #include <comphelper/accessibleeventnotifier.hxx>
56 #include <unotools/accessiblestatesethelper.hxx>
57 #include <rtl/ref.hxx>
58 #include <vcl/svapp.hxx>
60 using ::rtl::OUString;
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::accessibility;
65 namespace accessibility {
68 class AccessibleSlideSorterView::Implementation
69 : public SfxListener
71 public:
72 Implementation (
73 AccessibleSlideSorterView& rAccessibleSlideSorter,
74 ::sd::slidesorter::SlideSorter& rSlideSorter,
75 ::Window* pWindow);
76 ~Implementation (void);
78 void UpdateVisibility (void);
79 void UpdateChildren (void);
80 void Clear (void);
81 sal_Int32 GetVisibleChildCount (void) const;
82 AccessibleSlideSorterObject* GetAccessibleChild (sal_Int32 nIndex);
83 AccessibleSlideSorterObject* GetVisibleChild (sal_Int32 nIndex);
85 void ConnectListeners (void);
86 void ReleaseListeners (void);
87 void Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint);
88 DECL_LINK(WindowEventListener, VclWindowEvent*);
89 DECL_LINK(SelectionChangeListener, void*);
90 DECL_LINK(FocusChangeListener, void*);
92 private:
93 AccessibleSlideSorterView& mrAccessibleSlideSorter;
94 ::sd::slidesorter::SlideSorter& mrSlideSorter;
95 typedef ::std::vector<rtl::Reference<AccessibleSlideSorterObject> > PageObjectList;
96 PageObjectList maPageObjects;
97 sal_Int32 mnFirstVisibleChild;
98 sal_Int32 mnLastVisibleChild;
99 bool mbListeningToDocument;
100 ::Window* mpWindow;
101 sal_Int32 mnFocusedIndex;
102 bool mbModelChangeLocked;
108 //===== AccessibleSlideSorterView =============================================
110 AccessibleSlideSorterView::AccessibleSlideSorterView(
111 ::sd::slidesorter::SlideSorter& rSlideSorter,
112 const Reference<XAccessible>& rxParent,
113 ::Window* pContentWindow)
114 : AccessibleSlideSorterViewBase(MutexOwner::maMutex),
115 mpImpl(new Implementation(*this,rSlideSorter,pContentWindow)),
116 mrSlideSorter(rSlideSorter),
117 mxParent(rxParent),
118 mnClientId(0),
119 mpContentWindow(pContentWindow)
121 OSL_TRACE("creating AccessibleSlideSorterView");
127 AccessibleSlideSorterView::~AccessibleSlideSorterView (void)
129 Destroyed ();
135 void AccessibleSlideSorterView::FireAccessibleEvent (
136 short nEventId,
137 const uno::Any& rOldValue,
138 const uno::Any& rNewValue )
140 if (mnClientId != 0)
142 AccessibleEventObject aEventObject;
144 aEventObject.Source = Reference<XWeak>(this);
145 aEventObject.EventId = nEventId;
146 aEventObject.NewValue = rNewValue;
147 aEventObject.OldValue = rOldValue;
149 comphelper::AccessibleEventNotifier::addEvent (mnClientId, aEventObject);
156 void SAL_CALL AccessibleSlideSorterView::disposing (void)
158 if (mnClientId != 0)
160 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
161 mnClientId = 0;
163 mpImpl.reset(NULL);
169 AccessibleSlideSorterObject* AccessibleSlideSorterView::GetAccessibleChildImplementation (
170 sal_Int32 nIndex)
172 AccessibleSlideSorterObject* pResult = NULL;
173 ::osl::MutexGuard aGuard (maMutex);
175 if (nIndex>=0 && nIndex<mpImpl->GetVisibleChildCount())
176 pResult = mpImpl->GetVisibleChild(nIndex);
178 return pResult;
181 void AccessibleSlideSorterView::Destroyed (void)
183 ::osl::MutexGuard aGuard (maMutex);
185 // Send a disposing to all listeners.
186 if (mnClientId != 0)
188 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
189 mnClientId = 0;
193 //===== XAccessible =========================================================
195 Reference<XAccessibleContext > SAL_CALL
196 AccessibleSlideSorterView::getAccessibleContext (void)
197 throw (uno::RuntimeException)
199 ThrowIfDisposed ();
200 return this;
203 //===== XAccessibleContext ==================================================
205 sal_Int32 SAL_CALL AccessibleSlideSorterView::getAccessibleChildCount (void)
206 throw (RuntimeException)
208 ThrowIfDisposed();
209 ::osl::MutexGuard aGuard (maMutex);
210 return mpImpl->GetVisibleChildCount();
213 Reference<XAccessible > SAL_CALL
214 AccessibleSlideSorterView::getAccessibleChild (sal_Int32 nIndex)
215 throw (lang::IndexOutOfBoundsException, RuntimeException)
217 ThrowIfDisposed();
218 ::osl::MutexGuard aGuard (maMutex);
220 if (nIndex<0 || nIndex>=mpImpl->GetVisibleChildCount())
221 throw lang::IndexOutOfBoundsException();
223 return mpImpl->GetVisibleChild(nIndex);
226 Reference<XAccessible > SAL_CALL AccessibleSlideSorterView::getAccessibleParent (void)
227 throw (uno::RuntimeException)
229 ThrowIfDisposed();
230 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
231 Reference<XAccessible> xParent;
233 if (mpContentWindow != NULL)
235 ::Window* pParent = mpContentWindow->GetAccessibleParentWindow();
236 if (pParent != NULL)
237 xParent = pParent->GetAccessible();
240 return xParent;
243 sal_Int32 SAL_CALL AccessibleSlideSorterView::getAccessibleIndexInParent (void)
244 throw (uno::RuntimeException)
246 OSL_ASSERT(getAccessibleParent().is());
247 ThrowIfDisposed();
248 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
249 sal_Int32 nIndexInParent(-1);
252 Reference<XAccessibleContext> xParentContext (getAccessibleParent()->getAccessibleContext());
253 if (xParentContext.is())
255 sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
256 for (sal_Int32 i=0; i<nChildCount; ++i)
257 if (xParentContext->getAccessibleChild(i).get()
258 == static_cast<XAccessible*>(this))
260 nIndexInParent = i;
261 break;
265 return nIndexInParent;
271 sal_Int16 SAL_CALL AccessibleSlideSorterView::getAccessibleRole (void)
272 throw (uno::RuntimeException)
274 ThrowIfDisposed();
275 static sal_Int16 nRole = AccessibleRole::DOCUMENT;
276 return nRole;
282 ::rtl::OUString SAL_CALL AccessibleSlideSorterView::getAccessibleDescription (void)
283 throw (uno::RuntimeException)
285 ThrowIfDisposed();
286 ::vos::OGuard aGuard (Application::GetSolarMutex());
288 return String(SdResId(SID_SD_A11Y_I_SLIDEVIEW_D));
294 ::rtl::OUString SAL_CALL AccessibleSlideSorterView::getAccessibleName (void)
295 throw (uno::RuntimeException)
297 ThrowIfDisposed();
298 ::vos::OGuard aGuard (Application::GetSolarMutex());
300 return String(SdResId(SID_SD_A11Y_I_SLIDEVIEW_N));
306 Reference<XAccessibleRelationSet> SAL_CALL
307 AccessibleSlideSorterView::getAccessibleRelationSet (void)
308 throw (uno::RuntimeException)
310 return Reference<XAccessibleRelationSet>();
316 Reference<XAccessibleStateSet > SAL_CALL
317 AccessibleSlideSorterView::getAccessibleStateSet (void)
318 throw (uno::RuntimeException)
320 ThrowIfDisposed();
321 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
322 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
324 pStateSet->AddState(AccessibleStateType::FOCUSABLE);
325 pStateSet->AddState(AccessibleStateType::SELECTABLE);
326 pStateSet->AddState(AccessibleStateType::ENABLED);
327 pStateSet->AddState(AccessibleStateType::ACTIVE);
328 pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
329 pStateSet->AddState(AccessibleStateType::OPAQUE);
330 if (mpContentWindow!=NULL)
332 if (mpContentWindow->IsVisible())
333 pStateSet->AddState(AccessibleStateType::VISIBLE);
334 if (mpContentWindow->IsReallyVisible())
335 pStateSet->AddState(AccessibleStateType::SHOWING);
338 return pStateSet;
344 lang::Locale SAL_CALL AccessibleSlideSorterView::getLocale (void)
345 throw (IllegalAccessibleComponentStateException,
346 RuntimeException)
348 ThrowIfDisposed ();
349 Reference<XAccessibleContext> xParentContext;
350 Reference<XAccessible> xParent (getAccessibleParent());
351 if (xParent.is())
352 xParentContext = xParent->getAccessibleContext();
354 if (xParentContext.is())
355 return xParentContext->getLocale();
356 else
357 // Strange, no parent! Anyway, return the default locale.
358 return Application::GetSettings().GetLocale();
364 void SAL_CALL AccessibleSlideSorterView::addEventListener(
365 const Reference<XAccessibleEventListener >& rxListener)
366 throw (RuntimeException)
368 if (rxListener.is())
370 const osl::MutexGuard aGuard(maMutex);
372 if (IsDisposed())
374 uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
375 rxListener->disposing (lang::EventObject (x));
377 else
379 if ( ! mnClientId)
380 mnClientId = comphelper::AccessibleEventNotifier::registerClient();
381 comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
389 void SAL_CALL AccessibleSlideSorterView::removeEventListener(
390 const Reference<XAccessibleEventListener >& rxListener)
391 throw (RuntimeException)
393 ThrowIfDisposed();
394 if (rxListener.is())
396 const osl::MutexGuard aGuard(maMutex);
398 if (mnClientId != 0)
400 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener(
401 mnClientId, rxListener );
402 if ( !nListenerCount )
404 // no listeners anymore -> revoke ourself. This may lead to
405 // the notifier thread dying (if we were the last client),
406 // and at least to us not firing any events anymore, in case
407 // somebody calls NotifyAccessibleEvent, again
408 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
409 mnClientId = 0;
418 //===== XAccessibleComponent ==================================================
420 sal_Bool SAL_CALL AccessibleSlideSorterView::containsPoint (const awt::Point& aPoint)
421 throw (RuntimeException)
423 ThrowIfDisposed();
424 const awt::Rectangle aBBox (getBounds());
425 return (aPoint.X >= 0)
426 && (aPoint.X < aBBox.Width)
427 && (aPoint.Y >= 0)
428 && (aPoint.Y < aBBox.Height);
434 Reference<XAccessible> SAL_CALL
435 AccessibleSlideSorterView::getAccessibleAtPoint (const awt::Point& aPoint)
436 throw (RuntimeException)
438 ThrowIfDisposed();
439 Reference<XAccessible> xAccessible;
440 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
442 const Point aTestPoint (aPoint.X, aPoint.Y);
443 ::sd::slidesorter::model::SharedPageDescriptor pHitDescriptor (
444 mrSlideSorter.GetController().GetPageAt(aTestPoint));
445 if (pHitDescriptor.get() != NULL)
446 xAccessible = mpImpl->GetAccessibleChild(
447 (pHitDescriptor->GetPage()->GetPageNum()-1)/2);
449 return xAccessible;
455 awt::Rectangle SAL_CALL AccessibleSlideSorterView::getBounds (void)
456 throw (uno::RuntimeException)
458 ThrowIfDisposed();
459 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
460 awt::Rectangle aBBox;
462 if (mpContentWindow != NULL)
464 const Point aPosition (mpContentWindow->GetPosPixel());
465 const Size aSize (mpContentWindow->GetOutputSizePixel());
467 aBBox.X = aPosition.X();
468 aBBox.Y = aPosition.Y();
469 aBBox.Width = aSize.Width();
470 aBBox.Height = aSize.Height();
473 return aBBox;
479 awt::Point SAL_CALL AccessibleSlideSorterView::getLocation (void)
480 throw (uno::RuntimeException)
482 ThrowIfDisposed();
483 awt::Point aLocation;
485 if (mpContentWindow != NULL)
487 const Point aPosition (mpContentWindow->GetPosPixel());
488 aLocation.X = aPosition.X();
489 aLocation.Y = aPosition.Y();
492 return aLocation;
498 /** Calculate the location on screen from the parent's location on screen
499 and our own relative location.
501 awt::Point SAL_CALL AccessibleSlideSorterView::getLocationOnScreen()
502 throw (uno::RuntimeException)
504 ThrowIfDisposed();
505 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
506 awt::Point aParentLocationOnScreen;
508 Reference<XAccessible> xParent (getAccessibleParent());
509 if (xParent.is())
511 Reference<XAccessibleComponent> xParentComponent (
512 xParent->getAccessibleContext(), uno::UNO_QUERY);
513 if (xParentComponent.is())
514 aParentLocationOnScreen = xParentComponent->getLocationOnScreen();
517 awt::Point aLocationOnScreen (getLocation());
518 aLocationOnScreen.X += aParentLocationOnScreen.X;
519 aLocationOnScreen.Y += aParentLocationOnScreen.Y;
521 return aLocationOnScreen;
527 awt::Size SAL_CALL AccessibleSlideSorterView::getSize (void)
528 throw (uno::RuntimeException)
530 ThrowIfDisposed();
531 awt::Size aSize;
533 if (mpContentWindow != NULL)
535 const Size aOutputSize (mpContentWindow->GetOutputSizePixel());
536 aSize.Width = aOutputSize.Width();
537 aSize.Height = aOutputSize.Height();
540 return aSize;
546 void SAL_CALL AccessibleSlideSorterView::grabFocus (void)
547 throw (uno::RuntimeException)
549 ThrowIfDisposed();
550 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
552 if (mpContentWindow)
553 mpContentWindow->GrabFocus();
559 sal_Int32 SAL_CALL AccessibleSlideSorterView::getForeground (void)
560 throw (RuntimeException)
562 ThrowIfDisposed();
563 svtools::ColorConfig aColorConfig;
564 UINT32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
565 return static_cast<sal_Int32>(nColor);
571 sal_Int32 SAL_CALL AccessibleSlideSorterView::getBackground (void)
572 throw (RuntimeException)
574 ThrowIfDisposed();
575 UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
576 return static_cast<sal_Int32>(nColor);
582 //===== XAccessibleSelection ==================================================
584 void SAL_CALL AccessibleSlideSorterView::selectAccessibleChild (sal_Int32 nChildIndex)
585 throw (lang::IndexOutOfBoundsException,
586 RuntimeException)
588 ThrowIfDisposed();
589 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
591 AccessibleSlideSorterObject* pChild = mpImpl->GetAccessibleChild(nChildIndex);
592 if (pChild != NULL)
593 mrSlideSorter.GetController().GetPageSelector().SelectPage(pChild->GetPageNumber());
594 else
595 throw lang::IndexOutOfBoundsException();
601 sal_Bool SAL_CALL AccessibleSlideSorterView::isAccessibleChildSelected (sal_Int32 nChildIndex)
602 throw (lang::IndexOutOfBoundsException,
603 RuntimeException)
605 ThrowIfDisposed();
606 sal_Bool bIsSelected = sal_False;
607 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
609 AccessibleSlideSorterObject* pChild = mpImpl->GetAccessibleChild(nChildIndex);
610 if (pChild != NULL)
611 bIsSelected = mrSlideSorter.GetController().GetPageSelector().IsPageSelected(
612 pChild->GetPageNumber());
613 else
614 throw lang::IndexOutOfBoundsException();
616 return bIsSelected;
622 void SAL_CALL AccessibleSlideSorterView::clearAccessibleSelection (void)
623 throw (uno::RuntimeException)
625 ThrowIfDisposed();
626 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
628 mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
634 void SAL_CALL AccessibleSlideSorterView::selectAllAccessibleChildren (void)
635 throw (uno::RuntimeException)
637 ThrowIfDisposed();
638 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
640 mrSlideSorter.GetController().GetPageSelector().SelectAllPages();
646 sal_Int32 SAL_CALL AccessibleSlideSorterView::getSelectedAccessibleChildCount (void)
647 throw (uno::RuntimeException)
649 ThrowIfDisposed ();
650 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
651 return mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount();
657 Reference<XAccessible > SAL_CALL
658 AccessibleSlideSorterView::getSelectedAccessibleChild (sal_Int32 nSelectedChildIndex )
659 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
661 ThrowIfDisposed ();
662 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
663 Reference<XAccessible> xChild;
665 ::sd::slidesorter::controller::PageSelector& rSelector (
666 mrSlideSorter.GetController().GetPageSelector());
667 sal_Int32 nPageCount(rSelector.GetPageCount());
668 sal_Int32 nSelectedCount = 0;
669 for (sal_Int32 i=0; i<nPageCount; i++)
670 if (rSelector.IsPageSelected(i))
672 if (nSelectedCount == nSelectedChildIndex)
674 xChild = mpImpl->GetAccessibleChild(i);
675 break;
677 ++nSelectedCount;
681 if ( ! xChild.is() )
682 throw lang::IndexOutOfBoundsException();
684 return xChild;
690 void SAL_CALL AccessibleSlideSorterView::deselectAccessibleChild (sal_Int32 nChildIndex)
691 throw (lang::IndexOutOfBoundsException,
692 RuntimeException)
694 ThrowIfDisposed();
695 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
697 AccessibleSlideSorterObject* pChild = mpImpl->GetAccessibleChild(nChildIndex);
698 if (pChild != NULL)
699 mrSlideSorter.GetController().GetPageSelector().DeselectPage(pChild->GetPageNumber());
700 else
701 throw lang::IndexOutOfBoundsException();
707 //===== XServiceInfo ========================================================
709 ::rtl::OUString SAL_CALL
710 AccessibleSlideSorterView::getImplementationName (void)
711 throw (::com::sun::star::uno::RuntimeException)
713 return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleSlideSorterView"));
719 sal_Bool SAL_CALL
720 AccessibleSlideSorterView::supportsService (const OUString& sServiceName)
721 throw (::com::sun::star::uno::RuntimeException)
723 ThrowIfDisposed ();
725 // Iterate over all supported service names and return true if on of them
726 // matches the given name.
727 uno::Sequence< ::rtl::OUString> aSupportedServices (
728 getSupportedServiceNames ());
729 for (int i=0; i<aSupportedServices.getLength(); i++)
730 if (sServiceName == aSupportedServices[i])
731 return sal_True;
732 return sal_False;
738 uno::Sequence< ::rtl::OUString> SAL_CALL
739 AccessibleSlideSorterView::getSupportedServiceNames (void)
740 throw (::com::sun::star::uno::RuntimeException)
742 ThrowIfDisposed ();
744 static const OUString sServiceNames[3] = {
745 OUString(RTL_CONSTASCII_USTRINGPARAM(
746 "com.sun.star.accessibility.Accessible")),
747 OUString(RTL_CONSTASCII_USTRINGPARAM(
748 "com.sun.star.accessibility.AccessibleContext")),
749 OUString(RTL_CONSTASCII_USTRINGPARAM(
750 "com.sun.star.drawing.AccessibleSlideSorterView"))
752 return uno::Sequence<OUString> (sServiceNames, 3);
758 void AccessibleSlideSorterView::ThrowIfDisposed (void)
759 throw (lang::DisposedException)
761 if (rBHelper.bDisposed || rBHelper.bInDispose)
763 OSL_TRACE ("Calling disposed object. Throwing exception:");
764 throw lang::DisposedException (
765 OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")),
766 static_cast<uno::XWeak*>(this));
772 sal_Bool AccessibleSlideSorterView::IsDisposed (void)
774 return (rBHelper.bDisposed || rBHelper.bInDispose);
777 //===== AccessibleSlideSorterView::Implementation =============================
779 AccessibleSlideSorterView::Implementation::Implementation (
780 AccessibleSlideSorterView& rAccessibleSlideSorter,
781 ::sd::slidesorter::SlideSorter& rSlideSorter,
782 ::Window* pWindow)
783 : mrAccessibleSlideSorter(rAccessibleSlideSorter),
784 mrSlideSorter(rSlideSorter),
785 maPageObjects(),
786 mnFirstVisibleChild(0),
787 mnLastVisibleChild(-1),
788 mbListeningToDocument(false),
789 mpWindow(pWindow),
790 mnFocusedIndex(-1),
791 mbModelChangeLocked(false)
793 ConnectListeners();
794 UpdateChildren();
795 UpdateVisibility();
801 AccessibleSlideSorterView::Implementation::~Implementation (void)
803 ReleaseListeners();
804 Clear();
810 void AccessibleSlideSorterView::Implementation::UpdateVisibility (void)
812 ::sd::slidesorter::view::SlideSorterView::PageRange aRange (
813 mrSlideSorter.GetView().GetVisiblePageRange());
814 mnFirstVisibleChild = aRange.first;
815 mnLastVisibleChild = aRange.second;
821 void AccessibleSlideSorterView::Implementation::UpdateChildren (void)
823 // Clear the list of accessible children and adapt its size. It is
824 // refilled on demand when later the children are requested.
825 Clear();
826 maPageObjects.resize(mrSlideSorter.GetModel().GetPageCount());
827 UpdateVisibility();
833 void AccessibleSlideSorterView::Implementation::Clear (void)
835 PageObjectList::iterator iPageObject;
836 PageObjectList::iterator iEnd = maPageObjects.end();
837 for (iPageObject=maPageObjects.begin(); iPageObject!=iEnd; ++iPageObject)
838 if (*iPageObject != NULL)
840 Reference<XComponent> xComponent (Reference<XWeak>(iPageObject->get()), UNO_QUERY);
841 if (xComponent.is())
842 xComponent->dispose();
843 *iPageObject = NULL;
845 maPageObjects.clear();
851 sal_Int32 AccessibleSlideSorterView::Implementation::GetVisibleChildCount (void) const
853 if (mnFirstVisibleChild <= mnLastVisibleChild)
854 return mnLastVisibleChild - mnFirstVisibleChild + 1;
855 else
856 return 0;
862 AccessibleSlideSorterObject* AccessibleSlideSorterView::Implementation::GetVisibleChild (
863 sal_Int32 nIndex)
865 assert(nIndex>=0 && nIndex<GetVisibleChildCount());
867 return GetAccessibleChild(nIndex+mnFirstVisibleChild);
873 AccessibleSlideSorterObject* AccessibleSlideSorterView::Implementation::GetAccessibleChild (
874 sal_Int32 nIndex)
876 OSL_ASSERT(nIndex>=0 && (sal_uInt32)nIndex<maPageObjects.size());
878 AccessibleSlideSorterObject* pChild = NULL;
880 if (nIndex>=0 && (sal_uInt32)nIndex<maPageObjects.size())
882 if (maPageObjects[nIndex] == NULL)
884 ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
885 mrSlideSorter.GetModel().GetPageDescriptor(nIndex));
886 if (pDescriptor.get() != NULL)
887 maPageObjects[nIndex] = new AccessibleSlideSorterObject(
888 &mrAccessibleSlideSorter,
889 mrSlideSorter,
890 (pDescriptor->GetPage()->GetPageNum()-1)/2);
893 pChild = maPageObjects[nIndex].get();
896 return pChild;
902 void AccessibleSlideSorterView::Implementation::ConnectListeners (void)
904 StartListening (*mrSlideSorter.GetModel().GetDocument());
905 if (mrSlideSorter.GetViewShell() != NULL)
906 StartListening (*mrSlideSorter.GetViewShell());
907 mbListeningToDocument = true;
909 if (mpWindow != NULL)
910 mpWindow->AddEventListener(
911 LINK(this,AccessibleSlideSorterView::Implementation,WindowEventListener));
913 mrSlideSorter.GetController().GetSelectionManager()->AddSelectionChangeListener(
914 LINK(this,AccessibleSlideSorterView::Implementation,SelectionChangeListener));
916 mrSlideSorter.GetController().GetFocusManager().AddFocusChangeListener(
917 LINK(this,AccessibleSlideSorterView::Implementation,FocusChangeListener));
923 void AccessibleSlideSorterView::Implementation::ReleaseListeners (void)
925 mrSlideSorter.GetController().GetFocusManager().RemoveFocusChangeListener(
926 LINK(this,AccessibleSlideSorterView::Implementation,FocusChangeListener));
928 mrSlideSorter.GetController().GetSelectionManager()->RemoveSelectionChangeListener(
929 LINK(this,AccessibleSlideSorterView::Implementation,SelectionChangeListener));
931 if (mpWindow != NULL)
932 mpWindow->RemoveEventListener(
933 LINK(this,AccessibleSlideSorterView::Implementation,WindowEventListener));
935 if (mbListeningToDocument)
937 if (mrSlideSorter.GetViewShell() != NULL)
938 StartListening(*mrSlideSorter.GetViewShell());
939 EndListening (*mrSlideSorter.GetModel().GetDocument());
940 mbListeningToDocument = false;
947 void AccessibleSlideSorterView::Implementation::Notify (
948 SfxBroadcaster&,
949 const SfxHint& rHint)
951 if (rHint.ISA(SdrHint))
953 SdrHint& rSdrHint (*PTR_CAST(SdrHint,&rHint));
954 switch (rSdrHint.GetKind())
956 case HINT_PAGEORDERCHG:
957 if ( ! mbModelChangeLocked)
959 UpdateChildren();
960 mrAccessibleSlideSorter.FireAccessibleEvent(
961 AccessibleEventId::INVALIDATE_ALL_CHILDREN,
962 Any(),
963 Any());
965 break;
966 default:
967 break;
970 else if (rHint.ISA(sd::ViewShellHint))
972 sd::ViewShellHint& rViewShellHint (*PTR_CAST(sd::ViewShellHint, &rHint));
973 switch (rViewShellHint.GetHintId())
975 case sd::ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START:
976 mbModelChangeLocked = true;
977 break;
979 case sd::ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END:
980 mbModelChangeLocked = false;
981 UpdateChildren();
982 mrAccessibleSlideSorter.FireAccessibleEvent(
983 AccessibleEventId::INVALIDATE_ALL_CHILDREN,
984 Any(),
985 Any());
986 break;
987 default:
988 break;
996 IMPL_LINK(AccessibleSlideSorterView::Implementation, WindowEventListener, VclWindowEvent*, pEvent)
998 switch (pEvent->GetId())
1000 case VCLEVENT_WINDOW_MOVE:
1001 case VCLEVENT_WINDOW_RESIZE:
1002 UpdateVisibility();
1003 mrAccessibleSlideSorter.FireAccessibleEvent(
1004 AccessibleEventId::INVALIDATE_ALL_CHILDREN,
1005 Any(),
1006 Any());
1007 break;
1009 case VCLEVENT_WINDOW_GETFOCUS:
1010 case VCLEVENT_WINDOW_LOSEFOCUS:
1011 mrAccessibleSlideSorter.FireAccessibleEvent(
1012 AccessibleEventId::SELECTION_CHANGED,
1013 Any(),
1014 Any());
1015 break;
1016 default:
1017 break;
1019 return 1;
1025 IMPL_LINK(AccessibleSlideSorterView::Implementation, SelectionChangeListener, void*, EMPTYARG )
1027 mrAccessibleSlideSorter.FireAccessibleEvent(
1028 AccessibleEventId::SELECTION_CHANGED,
1029 Any(),
1030 Any());
1031 return 1;
1037 IMPL_LINK(AccessibleSlideSorterView::Implementation, FocusChangeListener, void*, EMPTYARG )
1039 sal_Int32 nNewFocusedIndex (
1040 mrSlideSorter.GetController().GetFocusManager().GetFocusedPageIndex());
1042 if (nNewFocusedIndex != mnFocusedIndex)
1044 if (mnFocusedIndex >= 0)
1046 AccessibleSlideSorterObject* pObject = GetAccessibleChild(mnFocusedIndex);
1047 if (pObject != NULL)
1048 pObject->FireAccessibleEvent(
1049 AccessibleEventId::STATE_CHANGED,
1050 Any(AccessibleStateType::FOCUSED),
1051 Any());
1053 if (nNewFocusedIndex >= 0)
1055 AccessibleSlideSorterObject* pObject = GetAccessibleChild(nNewFocusedIndex);
1056 if (pObject != NULL)
1057 pObject->FireAccessibleEvent(
1058 AccessibleEventId::STATE_CHANGED,
1059 Any(),
1060 Any(AccessibleStateType::FOCUSED));
1062 mnFocusedIndex = nNewFocusedIndex;
1064 return 1;
1068 } // end of namespace ::accessibility