tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleSlideSorterObject.cxx
blobfa1a804b6715bf6851d6760af41ea777c2cc936e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
39 #include <sdpage.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)
56 : mxParent(rxParent),
57 mnPageNumber(nPageNumber),
58 mrSlideSorter(rSlideSorter),
59 mnClientId(0)
63 AccessibleSlideSorterObject::~AccessibleSlideSorterObject()
65 if ( ! IsDisposed())
66 dispose();
69 void AccessibleSlideSorterObject::FireAccessibleEvent (
70 short nEventId,
71 const uno::Any& rOldValue,
72 const uno::Any& rNewValue)
74 if (mnClientId != 0)
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.
90 if (mnClientId != 0)
92 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, *this);
93 mnClientId = 0;
97 //===== XAccessible ===========================================================
99 Reference<XAccessibleContext> SAL_CALL
100 AccessibleSlideSorterObject::getAccessibleContext()
102 ThrowIfDisposed();
103 return this;
106 //===== XAccessibleContext ====================================================
108 sal_Int64 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount()
110 ThrowIfDisposed();
111 return 0;
114 Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleChild (sal_Int64 )
116 ThrowIfDisposed();
117 throw lang::IndexOutOfBoundsException();
120 Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleParent()
122 ThrowIfDisposed();
123 return mxParent;
126 sal_Int64 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
128 ThrowIfDisposed();
129 const SolarMutexGuard aSolarGuard;
130 sal_Int64 nIndexInParent(-1);
132 if (mxParent.is())
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))
142 nIndexInParent = i;
143 break;
148 return nIndexInParent;
151 sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole()
153 ThrowIfDisposed();
154 return AccessibleRole::SHAPE;
157 OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription()
159 ThrowIfDisposed();
160 return SdResId(STR_PAGE);
163 OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName()
165 ThrowIfDisposed();
166 const SolarMutexGuard aSolarGuard;
168 SdPage* pPage = GetPage();
169 if (pPage != nullptr)
170 return pPage->GetName();
171 else
172 return OUString();
175 Reference<XAccessibleRelationSet> SAL_CALL
176 AccessibleSlideSorterObject::getAccessibleRelationSet()
178 ThrowIfDisposed();
179 return Reference<XAccessibleRelationSet>();
182 sal_Int64 SAL_CALL
183 AccessibleSlideSorterObject::getAccessibleStateSet()
185 ThrowIfDisposed();
186 const SolarMutexGuard aSolarGuard;
187 sal_Int64 nStateSet = 0;
189 if (mxParent.is())
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;
208 return nStateSet;
211 lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale()
213 ThrowIfDisposed();
214 // Delegate request to parent.
215 if (mxParent.is())
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
223 // cluelessness.
224 throw IllegalAccessibleComponentStateException();
227 //===== XAccessibleEventBroadcaster ===========================================
229 void SAL_CALL AccessibleSlideSorterObject::addAccessibleEventListener(
230 const Reference<XAccessibleEventListener>& rxListener)
232 if (!rxListener.is())
233 return;
235 const std::unique_lock aGuard(m_aMutex);
237 if (IsDisposed())
239 uno::Reference<uno::XInterface> x (static_cast<lang::XComponent *>(this), uno::UNO_QUERY);
240 rxListener->disposing (lang::EventObject (x));
242 else
244 if (mnClientId == 0)
245 mnClientId = comphelper::AccessibleEventNotifier::registerClient();
246 comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
250 void SAL_CALL AccessibleSlideSorterObject::removeAccessibleEventListener(
251 const Reference<XAccessibleEventListener>& rxListener)
253 ThrowIfDisposed();
254 if (!rxListener.is())
255 return;
257 const std::unique_lock aGuard(m_aMutex);
259 if (!mnClientId)
260 return;
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 );
270 mnClientId = 0;
274 //===== XAccessibleComponent ==================================================
276 sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& aPoint)
278 ThrowIfDisposed();
279 const awt::Size aSize (getSize());
280 return (aPoint.X >= 0)
281 && (aPoint.X < aSize.Width)
282 && (aPoint.Y >= 0)
283 && (aPoint.Y < aSize.Height);
286 Reference<XAccessible> SAL_CALL
287 AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& )
289 return nullptr;
292 awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds()
294 ThrowIfDisposed ();
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));
304 if (mxParent.is())
306 Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(), UNO_QUERY);
307 if (xParentComponent.is())
309 awt::Rectangle aParentBBox (xParentComponent->getBounds());
310 aBBox.Intersection(::tools::Rectangle(
311 aParentBBox.X,
312 aParentBBox.Y,
313 aParentBBox.Width,
314 aParentBBox.Height));
318 return awt::Rectangle(
319 aBBox.Left(),
320 aBBox.Top(),
321 aBBox.GetWidth(),
322 aBBox.GetHeight());
325 awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
327 ThrowIfDisposed ();
328 const awt::Rectangle aBBox (getBounds());
329 return awt::Point(aBBox.X, aBBox.Y);
332 awt::Point SAL_CALL AccessibleSlideSorterObject::getLocationOnScreen()
334 ThrowIfDisposed ();
336 const SolarMutexGuard aSolarGuard;
338 awt::Point aLocation (getLocation());
340 if (mxParent.is())
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;
351 return aLocation;
354 awt::Size SAL_CALL AccessibleSlideSorterObject::getSize()
356 ThrowIfDisposed ();
357 const awt::Rectangle aBBox (getBounds());
358 return awt::Size(aBBox.Width,aBBox.Height);
361 void SAL_CALL AccessibleSlideSorterObject::grabFocus()
363 // nothing to do
366 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground()
368 ThrowIfDisposed ();
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()
376 ThrowIfDisposed ();
377 Color nColor = Application::GetSettings().GetStyleSettings().GetWindowColor();
378 return sal_Int32(nColor);
381 // XServiceInfo
382 OUString SAL_CALL
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()
396 ThrowIfDisposed ();
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()
406 if (m_bDisposed)
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
416 return m_bDisposed;
419 SdPage* AccessibleSlideSorterObject::GetPage() const
421 ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
422 mrSlideSorter.GetModel().GetPageDescriptor(mnPageNumber));
423 if (pDescriptor)
424 return pDescriptor->GetPage();
425 else
426 return nullptr;
429 } // end of namespace ::accessibility
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */