bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleSlideSorterObject.cxx
blob69b7dabdac06ba7aacd2a27aad797cac42598b7c
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 <comphelper/accessibleeventnotifier.hxx>
34 #include <cppuhelper/supportsservice.hxx>
35 #include <unotools/accessiblestatesethelper.hxx>
37 #include "sdpage.hxx"
38 #include "sdresid.hxx"
39 #include <vcl/svapp.hxx>
40 #include <vcl/settings.hxx>
42 #include "glob.hrc"
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),
55 mxParent(rxParent),
56 mnPageNumber(nPageNumber),
57 mrSlideSorter(rSlideSorter),
58 mnClientId(0)
62 AccessibleSlideSorterObject::~AccessibleSlideSorterObject()
64 if ( ! IsDisposed())
65 dispose();
68 void AccessibleSlideSorterObject::FireAccessibleEvent (
69 short nEventId,
70 const uno::Any& rOldValue,
71 const uno::Any& rNewValue)
73 if (mnClientId != 0)
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.
91 if (mnClientId != 0)
93 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, *this);
94 mnClientId = 0;
98 //===== XAccessible ===========================================================
100 Reference<XAccessibleContext> SAL_CALL
101 AccessibleSlideSorterObject::getAccessibleContext()
102 throw (uno::RuntimeException, std::exception)
104 ThrowIfDisposed();
105 return this;
108 //===== XAccessibleContext ====================================================
110 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount()
111 throw (uno::RuntimeException, std::exception)
113 ThrowIfDisposed();
114 return 0;
117 Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleChild (sal_Int32 )
118 throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
120 ThrowIfDisposed();
121 throw lang::IndexOutOfBoundsException();
124 Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleParent()
125 throw (uno::RuntimeException, std::exception)
127 ThrowIfDisposed();
128 return mxParent;
131 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
132 throw (uno::RuntimeException, std::exception)
134 ThrowIfDisposed();
135 const SolarMutexGuard aSolarGuard;
136 sal_Int32 nIndexInParent(-1);
138 if (mxParent.is())
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))
148 nIndexInParent = i;
149 break;
154 return nIndexInParent;
157 sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole()
158 throw (uno::RuntimeException, std::exception)
160 ThrowIfDisposed();
161 //set Role = Shape
162 //static sal_Int16 nRole = AccessibleRole::LIST_ITEM;
163 static sal_Int16 nRole = AccessibleRole::SHAPE;
164 return nRole;
167 OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription()
168 throw (uno::RuntimeException, std::exception)
170 ThrowIfDisposed();
171 return SD_RESSTR(STR_PAGE);
174 OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName()
175 throw (uno::RuntimeException, std::exception)
177 ThrowIfDisposed();
178 const SolarMutexGuard aSolarGuard;
180 SdPage* pPage = GetPage();
181 if (pPage != NULL)
182 return pPage->GetName();
183 else
184 return OUString();
187 Reference<XAccessibleRelationSet> SAL_CALL
188 AccessibleSlideSorterObject::getAccessibleRelationSet()
189 throw (uno::RuntimeException, std::exception)
191 ThrowIfDisposed();
192 return Reference<XAccessibleRelationSet>();
195 Reference<XAccessibleStateSet> SAL_CALL
196 AccessibleSlideSorterObject::getAccessibleStateSet()
197 throw (uno::RuntimeException, std::exception)
199 ThrowIfDisposed();
200 const SolarMutexGuard aSolarGuard;
201 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
203 if (mxParent.is())
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);
222 return pStateSet;
225 lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale()
226 throw (IllegalAccessibleComponentStateException,
227 RuntimeException, std::exception)
229 ThrowIfDisposed();
230 // Delegate request to parent.
231 if (mxParent.is())
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
239 // cluelessness.
240 throw IllegalAccessibleComponentStateException();
243 //===== XAccessibleEventBroadcaster ===========================================
245 void SAL_CALL AccessibleSlideSorterObject::addAccessibleEventListener(
246 const Reference<XAccessibleEventListener>& rxListener)
247 throw (RuntimeException, std::exception)
249 if (rxListener.is())
251 const osl::MutexGuard aGuard(maMutex);
253 if (IsDisposed())
255 uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
256 rxListener->disposing (lang::EventObject (x));
258 else
260 if (mnClientId == 0)
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)
271 ThrowIfDisposed();
272 if (rxListener.is())
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 );
284 mnClientId = 0;
289 //===== XAccessibleComponent ==================================================
291 sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& aPoint)
292 throw (uno::RuntimeException, std::exception)
294 ThrowIfDisposed();
295 const awt::Size aSize (getSize());
296 return (aPoint.X >= 0)
297 && (aPoint.X < aSize.Width)
298 && (aPoint.Y >= 0)
299 && (aPoint.Y < aSize.Height);
302 Reference<XAccessible> SAL_CALL
303 AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& )
304 throw (uno::RuntimeException, std::exception)
306 return NULL;
309 awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds()
310 throw (RuntimeException, std::exception)
312 ThrowIfDisposed ();
314 const SolarMutexGuard aSolarGuard;
316 Rectangle aBBox (
317 mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
318 mrSlideSorter.GetModel().GetPageDescriptor(mnPageNumber),
319 ::sd::slidesorter::view::PageObjectLayouter::PageObject,
320 ::sd::slidesorter::view::PageObjectLayouter::WindowCoordinateSystem));
322 if (mxParent.is())
324 Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(), UNO_QUERY);
325 if (xParentComponent.is())
327 awt::Rectangle aParentBBox (xParentComponent->getBounds());
328 aBBox.Intersection(Rectangle(
329 aParentBBox.X,
330 aParentBBox.Y,
331 aParentBBox.Width,
332 aParentBBox.Height));
336 return awt::Rectangle(
337 aBBox.Left(),
338 aBBox.Top(),
339 aBBox.GetWidth(),
340 aBBox.GetHeight());
343 awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
344 throw (RuntimeException, std::exception)
346 ThrowIfDisposed ();
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)
354 ThrowIfDisposed ();
356 const SolarMutexGuard aSolarGuard;
358 awt::Point aLocation (getLocation());
360 if (mxParent.is())
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;
371 return aLocation;
374 awt::Size SAL_CALL AccessibleSlideSorterObject::getSize()
375 throw (RuntimeException, std::exception)
377 ThrowIfDisposed ();
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)
385 // nothing to do
388 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground()
389 throw (::com::sun::star::uno::RuntimeException, std::exception)
391 ThrowIfDisposed ();
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)
400 ThrowIfDisposed ();
401 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
402 return static_cast<sal_Int32>(nColor);
405 // XServiceInfo
406 OUString SAL_CALL
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)
423 ThrowIfDisposed ();
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();
454 else
455 return NULL;
458 } // end of namespace ::accessibility
460 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */