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 <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
34 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
35 #include <comphelper/accessibleeventnotifier.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <sal/log.hxx>
40 #include <sdresid.hxx>
41 #include <vcl/svapp.hxx>
42 #include <vcl/settings.hxx>
44 #include <strings.hrc>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::accessibility
;
50 namespace accessibility
{
52 AccessibleSlideSorterObject::AccessibleSlideSorterObject(
53 const Reference
<XAccessible
>& rxParent
,
54 ::sd::slidesorter::SlideSorter
& rSlideSorter
,
55 sal_uInt16 nPageNumber
)
57 mnPageNumber(nPageNumber
),
58 mrSlideSorter(rSlideSorter
),
63 AccessibleSlideSorterObject::~AccessibleSlideSorterObject()
69 void AccessibleSlideSorterObject::FireAccessibleEvent (
71 const uno::Any
& rOldValue
,
72 const uno::Any
& rNewValue
)
76 AccessibleEventObject aEventObject
;
78 aEventObject
.Source
= Reference
<XWeak
>(this);
79 aEventObject
.EventId
= nEventId
;
80 aEventObject
.NewValue
= rNewValue
;
81 aEventObject
.OldValue
= rOldValue
;
83 comphelper::AccessibleEventNotifier::addEvent(mnClientId
, aEventObject
);
87 void AccessibleSlideSorterObject::disposing(std::unique_lock
<std::mutex
>&)
89 // Send a disposing to all listeners.
92 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId
, *this);
97 //===== XAccessible ===========================================================
99 Reference
<XAccessibleContext
> SAL_CALL
100 AccessibleSlideSorterObject::getAccessibleContext()
106 //===== XAccessibleContext ====================================================
108 sal_Int64 SAL_CALL
AccessibleSlideSorterObject::getAccessibleChildCount()
114 Reference
<XAccessible
> SAL_CALL
AccessibleSlideSorterObject::getAccessibleChild (sal_Int64
)
117 throw lang::IndexOutOfBoundsException();
120 Reference
<XAccessible
> SAL_CALL
AccessibleSlideSorterObject::getAccessibleParent()
126 sal_Int64 SAL_CALL
AccessibleSlideSorterObject::getAccessibleIndexInParent()
129 const SolarMutexGuard aSolarGuard
;
130 sal_Int64
nIndexInParent(-1);
134 Reference
<XAccessibleContext
> xParentContext (mxParent
->getAccessibleContext());
135 if (xParentContext
.is())
137 sal_Int64
nChildCount (xParentContext
->getAccessibleChildCount());
138 for (sal_Int64 i
=0; i
<nChildCount
; ++i
)
139 if (xParentContext
->getAccessibleChild(i
).get()
140 == static_cast<XAccessible
*>(this))
148 return nIndexInParent
;
151 sal_Int16 SAL_CALL
AccessibleSlideSorterObject::getAccessibleRole()
154 return AccessibleRole::SHAPE
;
157 OUString SAL_CALL
AccessibleSlideSorterObject::getAccessibleDescription()
160 return SdResId(STR_PAGE
);
163 OUString SAL_CALL
AccessibleSlideSorterObject::getAccessibleName()
166 const SolarMutexGuard aSolarGuard
;
168 SdPage
* pPage
= GetPage();
169 if (pPage
!= nullptr)
170 return pPage
->GetName();
175 Reference
<XAccessibleRelationSet
> SAL_CALL
176 AccessibleSlideSorterObject::getAccessibleRelationSet()
179 return Reference
<XAccessibleRelationSet
>();
183 AccessibleSlideSorterObject::getAccessibleStateSet()
186 const SolarMutexGuard aSolarGuard
;
187 sal_Int64 nStateSet
= 0;
191 // Unconditional states.
192 nStateSet
|= AccessibleStateType::SELECTABLE
;
193 nStateSet
|= AccessibleStateType::FOCUSABLE
;
194 nStateSet
|= AccessibleStateType::ENABLED
;
195 nStateSet
|= AccessibleStateType::VISIBLE
;
196 nStateSet
|= AccessibleStateType::SHOWING
;
197 nStateSet
|= AccessibleStateType::ACTIVE
;
198 nStateSet
|= AccessibleStateType::SENSITIVE
;
200 // Conditional states.
201 if (mrSlideSorter
.GetController().GetPageSelector().IsPageSelected(mnPageNumber
))
202 nStateSet
|= AccessibleStateType::SELECTED
;
203 if (mrSlideSorter
.GetController().GetFocusManager().GetFocusedPageIndex() == mnPageNumber
)
204 if (mrSlideSorter
.GetController().GetFocusManager().IsFocusShowing())
205 nStateSet
|= AccessibleStateType::FOCUSED
;
211 lang::Locale SAL_CALL
AccessibleSlideSorterObject::getLocale()
214 // Delegate request to parent.
217 Reference
<XAccessibleContext
> xParentContext (mxParent
->getAccessibleContext());
218 if (xParentContext
.is())
219 return xParentContext
->getLocale ();
222 // No locale and no parent. Therefore throw exception to indicate this
224 throw IllegalAccessibleComponentStateException();
227 //===== XAccessibleEventBroadcaster ===========================================
229 void SAL_CALL
AccessibleSlideSorterObject::addAccessibleEventListener(
230 const Reference
<XAccessibleEventListener
>& rxListener
)
232 if (!rxListener
.is())
235 const std::unique_lock
aGuard(m_aMutex
);
239 uno::Reference
<uno::XInterface
> x (static_cast<lang::XComponent
*>(this), uno::UNO_QUERY
);
240 rxListener
->disposing (lang::EventObject (x
));
245 mnClientId
= comphelper::AccessibleEventNotifier::registerClient();
246 comphelper::AccessibleEventNotifier::addEventListener(mnClientId
, rxListener
);
250 void SAL_CALL
AccessibleSlideSorterObject::removeAccessibleEventListener(
251 const Reference
<XAccessibleEventListener
>& rxListener
)
254 if (!rxListener
.is())
257 const std::unique_lock
aGuard(m_aMutex
);
262 sal_Int32 nListenerCount
= comphelper::AccessibleEventNotifier::removeEventListener( mnClientId
, rxListener
);
263 if ( !nListenerCount
)
265 // no listeners anymore
266 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
267 // and at least to us not firing any events anymore, in case somebody calls
268 // NotifyAccessibleEvent, again
269 comphelper::AccessibleEventNotifier::revokeClient( mnClientId
);
274 //===== XAccessibleComponent ==================================================
276 sal_Bool SAL_CALL
AccessibleSlideSorterObject::containsPoint(const awt::Point
& aPoint
)
279 const awt::Size
aSize (getSize());
280 return (aPoint
.X
>= 0)
281 && (aPoint
.X
< aSize
.Width
)
283 && (aPoint
.Y
< aSize
.Height
);
286 Reference
<XAccessible
> SAL_CALL
287 AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point
& )
292 awt::Rectangle SAL_CALL
AccessibleSlideSorterObject::getBounds()
296 const SolarMutexGuard aSolarGuard
;
298 ::tools::Rectangle
aBBox (
299 mrSlideSorter
.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
300 mrSlideSorter
.GetModel().GetPageDescriptor(mnPageNumber
),
301 ::sd::slidesorter::view::PageObjectLayouter::Part::PageObject
,
302 ::sd::slidesorter::view::PageObjectLayouter::WindowCoordinateSystem
));
306 Reference
<XAccessibleComponent
> xParentComponent(mxParent
->getAccessibleContext(), UNO_QUERY
);
307 if (xParentComponent
.is())
309 awt::Rectangle
aParentBBox (xParentComponent
->getBounds());
310 aBBox
.Intersection(::tools::Rectangle(
314 aParentBBox
.Height
));
318 return awt::Rectangle(
325 awt::Point SAL_CALL
AccessibleSlideSorterObject::getLocation ()
328 const awt::Rectangle
aBBox (getBounds());
329 return awt::Point(aBBox
.X
, aBBox
.Y
);
332 awt::Point SAL_CALL
AccessibleSlideSorterObject::getLocationOnScreen()
336 const SolarMutexGuard aSolarGuard
;
338 awt::Point
aLocation (getLocation());
342 Reference
<XAccessibleComponent
> xParentComponent(mxParent
->getAccessibleContext(),UNO_QUERY
);
343 if (xParentComponent
.is())
345 const awt::Point
aParentLocationOnScreen(xParentComponent
->getLocationOnScreen());
346 aLocation
.X
+= aParentLocationOnScreen
.X
;
347 aLocation
.Y
+= aParentLocationOnScreen
.Y
;
354 awt::Size SAL_CALL
AccessibleSlideSorterObject::getSize()
357 const awt::Rectangle
aBBox (getBounds());
358 return awt::Size(aBBox
.Width
,aBBox
.Height
);
361 void SAL_CALL
AccessibleSlideSorterObject::grabFocus()
366 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getForeground()
369 svtools::ColorConfig aColorConfig
;
370 Color nColor
= aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
;
371 return static_cast<sal_Int32
>(nColor
);
374 sal_Int32 SAL_CALL
AccessibleSlideSorterObject::getBackground()
377 Color nColor
= Application::GetSettings().GetStyleSettings().GetWindowColor();
378 return sal_Int32(nColor
);
383 AccessibleSlideSorterObject::getImplementationName()
385 return u
"AccessibleSlideSorterObject"_ustr
;
388 sal_Bool SAL_CALL
AccessibleSlideSorterObject::supportsService (const OUString
& sServiceName
)
390 return cppu::supportsService(this, sServiceName
);
393 uno::Sequence
< OUString
> SAL_CALL
394 AccessibleSlideSorterObject::getSupportedServiceNames()
398 return uno::Sequence
<OUString
> {
399 u
"com.sun.star.accessibility.Accessible"_ustr
,
400 u
"com.sun.star.accessibility.AccessibleContext"_ustr
404 void AccessibleSlideSorterObject::ThrowIfDisposed()
408 SAL_WARN("sd", "Calling disposed object. Throwing exception:");
409 throw lang::DisposedException (u
"object has been already disposed"_ustr
,
410 static_cast<uno::XWeak
*>(this));
414 bool AccessibleSlideSorterObject::IsDisposed() const
419 SdPage
* AccessibleSlideSorterObject::GetPage() const
421 ::sd::slidesorter::model::SharedPageDescriptor
pDescriptor(
422 mrSlideSorter
.GetModel().GetPageDescriptor(mnPageNumber
));
424 return pDescriptor
->GetPage();
429 } // end of namespace ::accessibility
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */