1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleSlideSorterObject.cxx,v $
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>
49 #include "sdresid.hxx"
50 #include <vcl/svapp.hxx>
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
),
69 mnPageNumber(nPageNumber
),
70 mrSlideSorter(rSlideSorter
),
78 AccessibleSlideSorterObject::~AccessibleSlideSorterObject (void)
87 sal_uInt16
AccessibleSlideSorterObject::GetPageNumber (void) const
95 void AccessibleSlideSorterObject::FireAccessibleEvent (
97 const uno::Any
& rOldValue
,
98 const uno::Any
& rNewValue
)
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.
123 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId
, *this);
130 //===== XAccessible ===========================================================
132 Reference
<XAccessibleContext
> SAL_CALL
133 AccessibleSlideSorterObject::getAccessibleContext (void)
134 throw (uno::RuntimeException
)
142 //===== XAccessibleContext ====================================================
144 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getAccessibleChildCount (void)
145 throw (uno::RuntimeException
)
154 Reference
<XAccessible
> SAL_CALL
AccessibleSlideSorterObject::getAccessibleChild (sal_Int32
)
155 throw (lang::IndexOutOfBoundsException
, RuntimeException
)
158 throw lang::IndexOutOfBoundsException();
164 Reference
<XAccessible
> SAL_CALL
AccessibleSlideSorterObject::getAccessibleParent (void)
165 throw (uno::RuntimeException
)
174 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getAccessibleIndexInParent()
175 throw (uno::RuntimeException
)
178 const vos::OGuard
aSolarGuard (Application::GetSolarMutex());
179 sal_Int32
nIndexInParent(-1);
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))
197 return nIndexInParent
;
203 sal_Int16 SAL_CALL
AccessibleSlideSorterObject::getAccessibleRole (void)
204 throw (uno::RuntimeException
)
207 static sal_Int16 nRole
= AccessibleRole::LIST_ITEM
;
214 ::rtl::OUString SAL_CALL
AccessibleSlideSorterObject::getAccessibleDescription (void)
215 throw (uno::RuntimeException
)
218 return String(SdResId(STR_PAGE
));
224 ::rtl::OUString SAL_CALL
AccessibleSlideSorterObject::getAccessibleName (void)
225 throw (uno::RuntimeException
)
228 const vos::OGuard
aSolarGuard (Application::GetSolarMutex());
230 SdPage
* pPage
= GetPage();
232 return pPage
->GetName();
240 Reference
<XAccessibleRelationSet
> SAL_CALL
241 AccessibleSlideSorterObject::getAccessibleRelationSet (void)
242 throw (uno::RuntimeException
)
245 return Reference
<XAccessibleRelationSet
>();
251 Reference
<XAccessibleStateSet
> SAL_CALL
252 AccessibleSlideSorterObject::getAccessibleStateSet (void)
253 throw (uno::RuntimeException
)
256 const vos::OGuard
aSolarGuard (Application::GetSolarMutex());
257 ::utl::AccessibleStateSetHelper
* pStateSet
= new ::utl::AccessibleStateSetHelper();
262 pStateSet
->AddState(AccessibleStateType::SELECTABLE
);
265 if (mrSlideSorter
.GetController().GetPageSelector().IsPageSelected(mnPageNumber
))
266 pStateSet
->AddState(AccessibleStateType::SELECTED
);
269 pStateSet
->AddState(AccessibleStateType::FOCUSABLE
);
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
);
288 lang::Locale SAL_CALL
AccessibleSlideSorterObject::getLocale (void)
289 throw (IllegalAccessibleComponentStateException
,
293 // Delegate request to parent.
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
303 throw IllegalAccessibleComponentStateException();
310 //===== XAccessibleEventBroadcaster ===========================================
312 void SAL_CALL
AccessibleSlideSorterObject::addEventListener(
313 const Reference
<XAccessibleEventListener
>& rxListener
)
314 throw (RuntimeException
)
318 const osl::MutexGuard
aGuard(maMutex
);
322 uno::Reference
<uno::XInterface
> x ((lang::XComponent
*)this, uno::UNO_QUERY
);
323 rxListener
->disposing (lang::EventObject (x
));
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
)
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
);
362 //===== XAccessibleComponent ==================================================
364 sal_Bool SAL_CALL
AccessibleSlideSorterObject::containsPoint(const awt::Point
& aPoint
)
365 throw (uno::RuntimeException
)
368 const awt::Size
aSize (getSize());
369 return (aPoint
.X
>= 0)
370 && (aPoint
.X
< aSize
.Width
)
372 && (aPoint
.Y
< aSize
.Height
);
378 Reference
<XAccessible
> SAL_CALL
379 AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point
& )
380 throw (uno::RuntimeException
)
388 awt::Rectangle SAL_CALL
AccessibleSlideSorterObject::getBounds (void)
389 throw (RuntimeException
)
393 const vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
395 Rectangle
aBBox (mrSlideSorter
.GetView().GetPageBoundingBox (
397 ::sd::slidesorter::view::SlideSorterView::CS_SCREEN
,
398 ::sd::slidesorter::view::SlideSorterView::BBT_INFO
));
402 Reference
<XAccessibleComponent
> xParentComponent(mxParent
->getAccessibleContext(), UNO_QUERY
);
403 if (xParentComponent
.is())
405 awt::Rectangle
aParentBBox (xParentComponent
->getBounds());
406 aBBox
.Intersection(Rectangle(
410 aParentBBox
.Height
));
414 return awt::Rectangle(
424 awt::Point SAL_CALL
AccessibleSlideSorterObject::getLocation ()
425 throw (RuntimeException
)
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
)
440 const vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
442 awt::Point
aLocation (getLocation());
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
;
461 awt::Size SAL_CALL
AccessibleSlideSorterObject::getSize (void)
462 throw (RuntimeException
)
465 const awt::Rectangle
aBBox (getBounds());
466 return awt::Size(aBBox
.Width
,aBBox
.Height
);
472 void SAL_CALL
AccessibleSlideSorterObject::grabFocus (void)
473 throw (RuntimeException
)
481 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getForeground (void)
482 throw (::com::sun::star::uno::RuntimeException
)
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
)
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"));
518 AccessibleSlideSorterObject::supportsService (const OUString
& sServiceName
)
519 throw (::com::sun::star::uno::RuntimeException
)
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
])
536 uno::Sequence
< ::rtl::OUString
> SAL_CALL
537 AccessibleSlideSorterObject::getSupportedServiceNames (void)
538 throw (::com::sun::star::uno::RuntimeException
)
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();
587 } // end of namespace ::accessibility