merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / accessibility / AccessibleSlideSorterObject.cxx
bloba8cd0cc3e5e6b9f26a52cb2d320e122e24335754
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: AccessibleSlideSorterObject.cxx,v $
10 * $Revision: 1.12 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.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 "model/SlideSorterModel.hxx"
41 #include "model/SlsPageDescriptor.hxx"
42 #include "view/SlideSorterView.hxx"
43 #include <com/sun/star/accessibility/AccessibleRole.hpp>
44 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
45 #include <comphelper/accessibleeventnotifier.hxx>
46 #include <unotools/accessiblestatesethelper.hxx>
48 #include "sdpage.hxx"
49 #include "sdresid.hxx"
50 #include <vcl/svapp.hxx>
52 #include "glob.hrc"
54 using ::rtl::OUString;
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::accessibility;
60 namespace accessibility {
63 AccessibleSlideSorterObject::AccessibleSlideSorterObject(
64 const Reference<XAccessible>& rxParent,
65 ::sd::slidesorter::SlideSorter& rSlideSorter,
66 sal_uInt16 nPageNumber)
67 : AccessibleSlideSorterObjectBase(::sd::MutexOwner::maMutex),
68 mxParent(rxParent),
69 mnPageNumber(nPageNumber),
70 mrSlideSorter(rSlideSorter),
71 mnClientId(0)
78 AccessibleSlideSorterObject::~AccessibleSlideSorterObject (void)
80 if ( ! IsDisposed())
81 dispose();
87 sal_uInt16 AccessibleSlideSorterObject::GetPageNumber (void) const
89 return mnPageNumber;
95 void AccessibleSlideSorterObject::FireAccessibleEvent (
96 short nEventId,
97 const uno::Any& rOldValue,
98 const uno::Any& rNewValue)
100 if (mnClientId != 0)
102 AccessibleEventObject aEventObject;
104 aEventObject.Source = Reference<XWeak>(this);
105 aEventObject.EventId = nEventId;
106 aEventObject.NewValue = rNewValue;
107 aEventObject.OldValue = rOldValue;
109 comphelper::AccessibleEventNotifier::addEvent(mnClientId, aEventObject);
116 void SAL_CALL AccessibleSlideSorterObject::disposing (void)
118 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
120 // Send a disposing to all listeners.
121 if (mnClientId != 0)
123 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, *this);
124 mnClientId = 0;
130 //===== XAccessible ===========================================================
132 Reference<XAccessibleContext> SAL_CALL
133 AccessibleSlideSorterObject::getAccessibleContext (void)
134 throw (uno::RuntimeException)
136 ThrowIfDisposed();
137 return this;
142 //===== XAccessibleContext ====================================================
144 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount (void)
145 throw (uno::RuntimeException)
147 ThrowIfDisposed();
148 return 0;
154 Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleChild (sal_Int32 )
155 throw (lang::IndexOutOfBoundsException, RuntimeException)
157 ThrowIfDisposed();
158 throw lang::IndexOutOfBoundsException();
164 Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleParent (void)
165 throw (uno::RuntimeException)
167 ThrowIfDisposed();
168 return mxParent;
174 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
175 throw (uno::RuntimeException)
177 ThrowIfDisposed();
178 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
179 sal_Int32 nIndexInParent(-1);
181 if (mxParent.is())
183 Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
184 if (xParentContext.is())
186 sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
187 for (sal_Int32 i=0; i<nChildCount; ++i)
188 if (xParentContext->getAccessibleChild(i).get()
189 == static_cast<XAccessible*>(this))
191 nIndexInParent = i;
192 break;
197 return nIndexInParent;
203 sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole (void)
204 throw (uno::RuntimeException)
206 ThrowIfDisposed();
207 static sal_Int16 nRole = AccessibleRole::LIST_ITEM;
208 return nRole;
214 ::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription (void)
215 throw (uno::RuntimeException)
217 ThrowIfDisposed();
218 return String(SdResId(STR_PAGE));
224 ::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName (void)
225 throw (uno::RuntimeException)
227 ThrowIfDisposed();
228 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
230 SdPage* pPage = GetPage();
231 if (pPage != NULL)
232 return pPage->GetName();
233 else
234 return String();
240 Reference<XAccessibleRelationSet> SAL_CALL
241 AccessibleSlideSorterObject::getAccessibleRelationSet (void)
242 throw (uno::RuntimeException)
244 ThrowIfDisposed();
245 return Reference<XAccessibleRelationSet>();
251 Reference<XAccessibleStateSet> SAL_CALL
252 AccessibleSlideSorterObject::getAccessibleStateSet (void)
253 throw (uno::RuntimeException)
255 ThrowIfDisposed();
256 const vos::OGuard aSolarGuard (Application::GetSolarMutex());
257 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
259 if (mxParent.is())
261 // SELECTABLE
262 pStateSet->AddState(AccessibleStateType::SELECTABLE);
264 // SELECTED
265 if (mrSlideSorter.GetController().GetPageSelector().IsPageSelected(mnPageNumber))
266 pStateSet->AddState(AccessibleStateType::SELECTED);
268 // FOCUSABLE
269 pStateSet->AddState(AccessibleStateType::FOCUSABLE);
271 // FOCUSED
272 if (mrSlideSorter.GetController().GetFocusManager().GetFocusedPageIndex() == mnPageNumber)
273 if (mrSlideSorter.GetController().GetFocusManager().IsFocusShowing())
274 pStateSet->AddState(AccessibleStateType::FOCUSED);
276 pStateSet->AddState(AccessibleStateType::ENABLED);
277 pStateSet->AddState(AccessibleStateType::VISIBLE);
278 pStateSet->AddState(AccessibleStateType::SHOWING);
279 pStateSet->AddState(AccessibleStateType::ACTIVE);
282 return pStateSet;
288 lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale (void)
289 throw (IllegalAccessibleComponentStateException,
290 RuntimeException)
292 ThrowIfDisposed();
293 // Delegate request to parent.
294 if (mxParent.is())
296 Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
297 if (xParentContext.is())
298 return xParentContext->getLocale ();
301 // No locale and no parent. Therefore throw exception to indicate this
302 // cluelessness.
303 throw IllegalAccessibleComponentStateException();
310 //===== XAccessibleEventBroadcaster ===========================================
312 void SAL_CALL AccessibleSlideSorterObject::addEventListener(
313 const Reference<XAccessibleEventListener>& rxListener)
314 throw (RuntimeException)
316 if (rxListener.is())
318 const osl::MutexGuard aGuard(maMutex);
320 if (IsDisposed())
322 uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
323 rxListener->disposing (lang::EventObject (x));
325 else
327 if (mnClientId == 0)
328 mnClientId = comphelper::AccessibleEventNotifier::registerClient();
329 comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
337 void SAL_CALL AccessibleSlideSorterObject::removeEventListener(
338 const Reference<XAccessibleEventListener>& rxListener)
339 throw (uno::RuntimeException)
341 ThrowIfDisposed();
342 if (rxListener.is())
344 const osl::MutexGuard aGuard(maMutex);
346 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, rxListener );
347 if ( !nListenerCount )
349 // no listeners anymore
350 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
351 // and at least to us not firing any events anymore, in case somebody calls
352 // NotifyAccessibleEvent, again
353 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
354 mnClientId = 0;
362 //===== XAccessibleComponent ==================================================
364 sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& aPoint)
365 throw (uno::RuntimeException)
367 ThrowIfDisposed();
368 const awt::Size aSize (getSize());
369 return (aPoint.X >= 0)
370 && (aPoint.X < aSize.Width)
371 && (aPoint.Y >= 0)
372 && (aPoint.Y < aSize.Height);
378 Reference<XAccessible> SAL_CALL
379 AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& )
380 throw (uno::RuntimeException)
382 return NULL;
388 awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds (void)
389 throw (RuntimeException)
391 ThrowIfDisposed ();
393 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
395 Rectangle aBBox (mrSlideSorter.GetView().GetPageBoundingBox (
396 mnPageNumber,
397 ::sd::slidesorter::view::SlideSorterView::CS_SCREEN,
398 ::sd::slidesorter::view::SlideSorterView::BBT_INFO));
400 if (mxParent.is())
402 Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(), UNO_QUERY);
403 if (xParentComponent.is())
405 awt::Rectangle aParentBBox (xParentComponent->getBounds());
406 aBBox.Intersection(Rectangle(
407 aParentBBox.X,
408 aParentBBox.Y,
409 aParentBBox.Width,
410 aParentBBox.Height));
414 return awt::Rectangle(
415 aBBox.Left(),
416 aBBox.Top(),
417 aBBox.GetWidth(),
418 aBBox.GetHeight());
424 awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
425 throw (RuntimeException)
427 ThrowIfDisposed ();
428 const awt::Rectangle aBBox (getBounds());
429 return awt::Point(aBBox.X, aBBox.Y);
435 awt::Point SAL_CALL AccessibleSlideSorterObject::getLocationOnScreen (void)
436 throw (RuntimeException)
438 ThrowIfDisposed ();
440 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
442 awt::Point aLocation (getLocation());
444 if (mxParent.is())
446 Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(),UNO_QUERY);
447 if (xParentComponent.is())
449 const awt::Point aParentLocationOnScreen(xParentComponent->getLocationOnScreen());
450 aLocation.X += aParentLocationOnScreen.X;
451 aLocation.Y += aParentLocationOnScreen.Y;
455 return aLocation;
461 awt::Size SAL_CALL AccessibleSlideSorterObject::getSize (void)
462 throw (RuntimeException)
464 ThrowIfDisposed ();
465 const awt::Rectangle aBBox (getBounds());
466 return awt::Size(aBBox.Width,aBBox.Height);
472 void SAL_CALL AccessibleSlideSorterObject::grabFocus (void)
473 throw (RuntimeException)
475 // nothing to do
481 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground (void)
482 throw (::com::sun::star::uno::RuntimeException)
484 ThrowIfDisposed ();
485 svtools::ColorConfig aColorConfig;
486 UINT32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
487 return static_cast<sal_Int32>(nColor);
493 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getBackground (void)
494 throw (::com::sun::star::uno::RuntimeException)
496 ThrowIfDisposed ();
497 UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
498 return static_cast<sal_Int32>(nColor);
505 //===== XServiceInfo ========================================================
507 ::rtl::OUString SAL_CALL
508 AccessibleSlideSorterObject::getImplementationName (void)
509 throw (::com::sun::star::uno::RuntimeException)
511 return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleSlideSorterObject"));
517 sal_Bool SAL_CALL
518 AccessibleSlideSorterObject::supportsService (const OUString& sServiceName)
519 throw (::com::sun::star::uno::RuntimeException)
521 ThrowIfDisposed ();
523 // Iterate over all supported service names and return true if on of them
524 // matches the given name.
525 uno::Sequence< ::rtl::OUString> aSupportedServices (
526 getSupportedServiceNames ());
527 for (int i=0; i<aSupportedServices.getLength(); i++)
528 if (sServiceName == aSupportedServices[i])
529 return sal_True;
530 return sal_False;
536 uno::Sequence< ::rtl::OUString> SAL_CALL
537 AccessibleSlideSorterObject::getSupportedServiceNames (void)
538 throw (::com::sun::star::uno::RuntimeException)
540 ThrowIfDisposed ();
542 static const OUString sServiceNames[2] = {
543 OUString(RTL_CONSTASCII_USTRINGPARAM(
544 "com.sun.star.accessibility.Accessible")),
545 OUString(RTL_CONSTASCII_USTRINGPARAM(
546 "com.sun.star.accessibility.AccessibleContext"))
548 return uno::Sequence<OUString> (sServiceNames, 2);
554 void AccessibleSlideSorterObject::ThrowIfDisposed (void)
555 throw (lang::DisposedException)
557 if (rBHelper.bDisposed || rBHelper.bInDispose)
559 OSL_TRACE ("Calling disposed object. Throwing exception:");
560 throw lang::DisposedException (
561 OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")),
562 static_cast<uno::XWeak*>(this));
568 sal_Bool AccessibleSlideSorterObject::IsDisposed (void)
570 return (rBHelper.bDisposed || rBHelper.bInDispose);
576 SdPage* AccessibleSlideSorterObject::GetPage (void) const
578 ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
579 mrSlideSorter.GetModel().GetPageDescriptor(mnPageNumber));
580 if (pDescriptor.get() != NULL)
581 return pDescriptor->GetPage();
582 else
583 return NULL;
587 } // end of namespace ::accessibility