1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "AccessibleSlideSorterObject.hxx"
22 #include "SlideSorter.hxx"
23 #include "controller/SlideSorterController.hxx"
24 #include "controller/SlsPageSelector.hxx"
25 #include "controller/SlsFocusManager.hxx"
26 #include "model/SlideSorterModel.hxx"
27 #include "model/SlsPageDescriptor.hxx"
28 #include "view/SlideSorterView.hxx"
29 #include "view/SlsLayouter.hxx"
30 #include "view/SlsPageObjectLayouter.hxx"
31 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 #include <comphelper/accessibleeventnotifier.hxx>
34 #include <cppuhelper/supportsservice.hxx>
35 #include <unotools/accessiblestatesethelper.hxx>
38 #include "sdresid.hxx"
39 #include <vcl/svapp.hxx>
40 #include <vcl/settings.hxx>
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::accessibility
;
48 namespace accessibility
{
50 AccessibleSlideSorterObject::AccessibleSlideSorterObject(
51 const Reference
<XAccessible
>& rxParent
,
52 ::sd::slidesorter::SlideSorter
& rSlideSorter
,
53 sal_uInt16 nPageNumber
)
54 : AccessibleSlideSorterObjectBase(::sd::MutexOwner::maMutex
),
56 mnPageNumber(nPageNumber
),
57 mrSlideSorter(rSlideSorter
),
62 AccessibleSlideSorterObject::~AccessibleSlideSorterObject()
68 void AccessibleSlideSorterObject::FireAccessibleEvent (
70 const uno::Any
& rOldValue
,
71 const uno::Any
& rNewValue
)
75 AccessibleEventObject aEventObject
;
77 aEventObject
.Source
= Reference
<XWeak
>(this);
78 aEventObject
.EventId
= nEventId
;
79 aEventObject
.NewValue
= rNewValue
;
80 aEventObject
.OldValue
= rOldValue
;
82 comphelper::AccessibleEventNotifier::addEvent(mnClientId
, aEventObject
);
86 void SAL_CALL
AccessibleSlideSorterObject::disposing()
88 const SolarMutexGuard aSolarGuard
;
90 // Send a disposing to all listeners.
93 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId
, *this);
98 //===== XAccessible ===========================================================
100 Reference
<XAccessibleContext
> SAL_CALL
101 AccessibleSlideSorterObject::getAccessibleContext()
102 throw (uno::RuntimeException
, std::exception
)
108 //===== XAccessibleContext ====================================================
110 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getAccessibleChildCount()
111 throw (uno::RuntimeException
, std::exception
)
117 Reference
<XAccessible
> SAL_CALL
AccessibleSlideSorterObject::getAccessibleChild (sal_Int32
)
118 throw (lang::IndexOutOfBoundsException
, RuntimeException
, std::exception
)
121 throw lang::IndexOutOfBoundsException();
124 Reference
<XAccessible
> SAL_CALL
AccessibleSlideSorterObject::getAccessibleParent()
125 throw (uno::RuntimeException
, std::exception
)
131 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getAccessibleIndexInParent()
132 throw (uno::RuntimeException
, std::exception
)
135 const SolarMutexGuard aSolarGuard
;
136 sal_Int32
nIndexInParent(-1);
140 Reference
<XAccessibleContext
> xParentContext (mxParent
->getAccessibleContext());
141 if (xParentContext
.is())
143 sal_Int32
nChildCount (xParentContext
->getAccessibleChildCount());
144 for (sal_Int32 i
=0; i
<nChildCount
; ++i
)
145 if (xParentContext
->getAccessibleChild(i
).get()
146 == static_cast<XAccessible
*>(this))
154 return nIndexInParent
;
157 sal_Int16 SAL_CALL
AccessibleSlideSorterObject::getAccessibleRole()
158 throw (uno::RuntimeException
, std::exception
)
162 //static sal_Int16 nRole = AccessibleRole::LIST_ITEM;
163 static sal_Int16 nRole
= AccessibleRole::SHAPE
;
167 OUString SAL_CALL
AccessibleSlideSorterObject::getAccessibleDescription()
168 throw (uno::RuntimeException
, std::exception
)
171 return SD_RESSTR(STR_PAGE
);
174 OUString SAL_CALL
AccessibleSlideSorterObject::getAccessibleName()
175 throw (uno::RuntimeException
, std::exception
)
178 const SolarMutexGuard aSolarGuard
;
180 SdPage
* pPage
= GetPage();
182 return pPage
->GetName();
187 Reference
<XAccessibleRelationSet
> SAL_CALL
188 AccessibleSlideSorterObject::getAccessibleRelationSet()
189 throw (uno::RuntimeException
, std::exception
)
192 return Reference
<XAccessibleRelationSet
>();
195 Reference
<XAccessibleStateSet
> SAL_CALL
196 AccessibleSlideSorterObject::getAccessibleStateSet()
197 throw (uno::RuntimeException
, std::exception
)
200 const SolarMutexGuard aSolarGuard
;
201 ::utl::AccessibleStateSetHelper
* pStateSet
= new ::utl::AccessibleStateSetHelper();
205 // Unconditional states.
206 pStateSet
->AddState(AccessibleStateType::SELECTABLE
);
207 pStateSet
->AddState(AccessibleStateType::FOCUSABLE
);
208 pStateSet
->AddState(AccessibleStateType::ENABLED
);
209 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
210 pStateSet
->AddState(AccessibleStateType::SHOWING
);
211 pStateSet
->AddState(AccessibleStateType::ACTIVE
);
212 pStateSet
->AddState(AccessibleStateType::SENSITIVE
);
214 // Conditional states.
215 if (mrSlideSorter
.GetController().GetPageSelector().IsPageSelected(mnPageNumber
))
216 pStateSet
->AddState(AccessibleStateType::SELECTED
);
217 if (mrSlideSorter
.GetController().GetFocusManager().GetFocusedPageIndex() == mnPageNumber
)
218 if (mrSlideSorter
.GetController().GetFocusManager().IsFocusShowing())
219 pStateSet
->AddState(AccessibleStateType::FOCUSED
);
225 lang::Locale SAL_CALL
AccessibleSlideSorterObject::getLocale()
226 throw (IllegalAccessibleComponentStateException
,
227 RuntimeException
, std::exception
)
230 // Delegate request to parent.
233 Reference
<XAccessibleContext
> xParentContext (mxParent
->getAccessibleContext());
234 if (xParentContext
.is())
235 return xParentContext
->getLocale ();
238 // No locale and no parent. Therefore throw exception to indicate this
240 throw IllegalAccessibleComponentStateException();
243 //===== XAccessibleEventBroadcaster ===========================================
245 void SAL_CALL
AccessibleSlideSorterObject::addAccessibleEventListener(
246 const Reference
<XAccessibleEventListener
>& rxListener
)
247 throw (RuntimeException
, std::exception
)
251 const osl::MutexGuard
aGuard(maMutex
);
255 uno::Reference
<uno::XInterface
> x ((lang::XComponent
*)this, uno::UNO_QUERY
);
256 rxListener
->disposing (lang::EventObject (x
));
261 mnClientId
= comphelper::AccessibleEventNotifier::registerClient();
262 comphelper::AccessibleEventNotifier::addEventListener(mnClientId
, rxListener
);
267 void SAL_CALL
AccessibleSlideSorterObject::removeAccessibleEventListener(
268 const Reference
<XAccessibleEventListener
>& rxListener
)
269 throw (uno::RuntimeException
, std::exception
)
274 const osl::MutexGuard
aGuard(maMutex
);
276 sal_Int32 nListenerCount
= comphelper::AccessibleEventNotifier::removeEventListener( mnClientId
, rxListener
);
277 if ( !nListenerCount
)
279 // no listeners anymore
280 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
281 // and at least to us not firing any events anymore, in case somebody calls
282 // NotifyAccessibleEvent, again
283 comphelper::AccessibleEventNotifier::revokeClient( mnClientId
);
289 //===== XAccessibleComponent ==================================================
291 sal_Bool SAL_CALL
AccessibleSlideSorterObject::containsPoint(const awt::Point
& aPoint
)
292 throw (uno::RuntimeException
, std::exception
)
295 const awt::Size
aSize (getSize());
296 return (aPoint
.X
>= 0)
297 && (aPoint
.X
< aSize
.Width
)
299 && (aPoint
.Y
< aSize
.Height
);
302 Reference
<XAccessible
> SAL_CALL
303 AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point
& )
304 throw (uno::RuntimeException
, std::exception
)
309 awt::Rectangle SAL_CALL
AccessibleSlideSorterObject::getBounds()
310 throw (RuntimeException
, std::exception
)
314 const SolarMutexGuard aSolarGuard
;
317 mrSlideSorter
.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
318 mrSlideSorter
.GetModel().GetPageDescriptor(mnPageNumber
),
319 ::sd::slidesorter::view::PageObjectLayouter::PageObject
,
320 ::sd::slidesorter::view::PageObjectLayouter::WindowCoordinateSystem
));
324 Reference
<XAccessibleComponent
> xParentComponent(mxParent
->getAccessibleContext(), UNO_QUERY
);
325 if (xParentComponent
.is())
327 awt::Rectangle
aParentBBox (xParentComponent
->getBounds());
328 aBBox
.Intersection(Rectangle(
332 aParentBBox
.Height
));
336 return awt::Rectangle(
343 awt::Point SAL_CALL
AccessibleSlideSorterObject::getLocation ()
344 throw (RuntimeException
, std::exception
)
347 const awt::Rectangle
aBBox (getBounds());
348 return awt::Point(aBBox
.X
, aBBox
.Y
);
351 awt::Point SAL_CALL
AccessibleSlideSorterObject::getLocationOnScreen()
352 throw (RuntimeException
, std::exception
)
356 const SolarMutexGuard aSolarGuard
;
358 awt::Point
aLocation (getLocation());
362 Reference
<XAccessibleComponent
> xParentComponent(mxParent
->getAccessibleContext(),UNO_QUERY
);
363 if (xParentComponent
.is())
365 const awt::Point
aParentLocationOnScreen(xParentComponent
->getLocationOnScreen());
366 aLocation
.X
+= aParentLocationOnScreen
.X
;
367 aLocation
.Y
+= aParentLocationOnScreen
.Y
;
374 awt::Size SAL_CALL
AccessibleSlideSorterObject::getSize()
375 throw (RuntimeException
, std::exception
)
378 const awt::Rectangle
aBBox (getBounds());
379 return awt::Size(aBBox
.Width
,aBBox
.Height
);
382 void SAL_CALL
AccessibleSlideSorterObject::grabFocus()
383 throw (RuntimeException
, std::exception
)
388 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getForeground()
389 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
392 svtools::ColorConfig aColorConfig
;
393 sal_uInt32 nColor
= aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
;
394 return static_cast<sal_Int32
>(nColor
);
397 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getBackground()
398 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
401 sal_uInt32 nColor
= Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
402 return static_cast<sal_Int32
>(nColor
);
407 AccessibleSlideSorterObject::getImplementationName()
408 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
410 return OUString("AccessibleSlideSorterObject");
413 sal_Bool SAL_CALL
AccessibleSlideSorterObject::supportsService (const OUString
& sServiceName
)
414 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
416 return cppu::supportsService(this, sServiceName
);
419 uno::Sequence
< OUString
> SAL_CALL
420 AccessibleSlideSorterObject::getSupportedServiceNames()
421 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
425 static const OUString sServiceNames
[2] = {
426 OUString("com.sun.star.accessibility.Accessible"),
427 OUString("com.sun.star.accessibility.AccessibleContext")
429 return uno::Sequence
<OUString
> (sServiceNames
, 2);
432 void AccessibleSlideSorterObject::ThrowIfDisposed()
433 throw (lang::DisposedException
)
435 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
437 OSL_TRACE ("Calling disposed object. Throwing exception:");
438 throw lang::DisposedException ("object has been already disposed",
439 static_cast<uno::XWeak
*>(this));
443 bool AccessibleSlideSorterObject::IsDisposed()
445 return (rBHelper
.bDisposed
|| rBHelper
.bInDispose
);
448 SdPage
* AccessibleSlideSorterObject::GetPage() const
450 ::sd::slidesorter::model::SharedPageDescriptor
pDescriptor(
451 mrSlideSorter
.GetModel().GetPageDescriptor(mnPageNumber
));
452 if (pDescriptor
.get() != NULL
)
453 return pDescriptor
->GetPage();
458 } // end of namespace ::accessibility
460 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */