Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "AccessibleSlideSorterObject.hxx"
22 :
23 : #include "SlideSorter.hxx"
24 : #include "controller/SlideSorterController.hxx"
25 : #include "controller/SlsPageSelector.hxx"
26 : #include "controller/SlsFocusManager.hxx"
27 : #include "model/SlideSorterModel.hxx"
28 : #include "model/SlsPageDescriptor.hxx"
29 : #include "view/SlideSorterView.hxx"
30 : #include "view/SlsLayouter.hxx"
31 : #include "view/SlsPageObjectLayouter.hxx"
32 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
33 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
34 : #include <comphelper/accessibleeventnotifier.hxx>
35 : #include <unotools/accessiblestatesethelper.hxx>
36 :
37 : #include "sdpage.hxx"
38 : #include "sdresid.hxx"
39 : #include <vcl/svapp.hxx>
40 :
41 : #include "glob.hrc"
42 :
43 : using ::rtl::OUString;
44 : using namespace ::com::sun::star;
45 : using namespace ::com::sun::star::uno;
46 : using namespace ::com::sun::star::accessibility;
47 :
48 :
49 : namespace accessibility {
50 :
51 :
52 0 : AccessibleSlideSorterObject::AccessibleSlideSorterObject(
53 : const Reference<XAccessible>& rxParent,
54 : ::sd::slidesorter::SlideSorter& rSlideSorter,
55 : sal_uInt16 nPageNumber)
56 : : AccessibleSlideSorterObjectBase(::sd::MutexOwner::maMutex),
57 : mxParent(rxParent),
58 : mnPageNumber(nPageNumber),
59 : mrSlideSorter(rSlideSorter),
60 0 : mnClientId(0)
61 : {
62 0 : }
63 :
64 :
65 :
66 :
67 0 : AccessibleSlideSorterObject::~AccessibleSlideSorterObject (void)
68 : {
69 0 : if ( ! IsDisposed())
70 0 : dispose();
71 0 : }
72 :
73 :
74 :
75 :
76 0 : sal_uInt16 AccessibleSlideSorterObject::GetPageNumber (void) const
77 : {
78 0 : return mnPageNumber;
79 : }
80 :
81 :
82 :
83 :
84 0 : void AccessibleSlideSorterObject::FireAccessibleEvent (
85 : short nEventId,
86 : const uno::Any& rOldValue,
87 : const uno::Any& rNewValue)
88 : {
89 0 : if (mnClientId != 0)
90 : {
91 0 : AccessibleEventObject aEventObject;
92 :
93 0 : aEventObject.Source = Reference<XWeak>(this);
94 0 : aEventObject.EventId = nEventId;
95 0 : aEventObject.NewValue = rNewValue;
96 0 : aEventObject.OldValue = rOldValue;
97 :
98 0 : comphelper::AccessibleEventNotifier::addEvent(mnClientId, aEventObject);
99 : }
100 0 : }
101 :
102 :
103 :
104 :
105 0 : void SAL_CALL AccessibleSlideSorterObject::disposing (void)
106 : {
107 0 : const SolarMutexGuard aSolarGuard;
108 :
109 : // Send a disposing to all listeners.
110 0 : if (mnClientId != 0)
111 : {
112 0 : comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, *this);
113 0 : mnClientId = 0;
114 0 : }
115 0 : }
116 :
117 :
118 :
119 : //===== XAccessible ===========================================================
120 :
121 : Reference<XAccessibleContext> SAL_CALL
122 0 : AccessibleSlideSorterObject::getAccessibleContext (void)
123 : throw (uno::RuntimeException)
124 : {
125 0 : ThrowIfDisposed();
126 0 : return this;
127 : }
128 :
129 :
130 :
131 : //===== XAccessibleContext ====================================================
132 :
133 0 : sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount (void)
134 : throw (uno::RuntimeException)
135 : {
136 0 : ThrowIfDisposed();
137 0 : return 0;
138 : }
139 :
140 :
141 :
142 :
143 0 : Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleChild (sal_Int32 )
144 : throw (lang::IndexOutOfBoundsException, RuntimeException)
145 : {
146 0 : ThrowIfDisposed();
147 0 : throw lang::IndexOutOfBoundsException();
148 : }
149 :
150 :
151 :
152 :
153 0 : Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleParent (void)
154 : throw (uno::RuntimeException)
155 : {
156 0 : ThrowIfDisposed();
157 0 : return mxParent;
158 : }
159 :
160 :
161 :
162 :
163 0 : sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
164 : throw (uno::RuntimeException)
165 : {
166 0 : ThrowIfDisposed();
167 0 : const SolarMutexGuard aSolarGuard;
168 0 : sal_Int32 nIndexInParent(-1);
169 :
170 0 : if (mxParent.is())
171 : {
172 0 : Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
173 0 : if (xParentContext.is())
174 : {
175 0 : sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
176 0 : for (sal_Int32 i=0; i<nChildCount; ++i)
177 0 : if (xParentContext->getAccessibleChild(i).get()
178 : == static_cast<XAccessible*>(this))
179 : {
180 0 : nIndexInParent = i;
181 0 : break;
182 : }
183 0 : }
184 : }
185 :
186 0 : return nIndexInParent;
187 : }
188 :
189 :
190 :
191 :
192 0 : sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole (void)
193 : throw (uno::RuntimeException)
194 : {
195 0 : ThrowIfDisposed();
196 : static sal_Int16 nRole = AccessibleRole::LIST_ITEM;
197 0 : return nRole;
198 : }
199 :
200 :
201 :
202 :
203 0 : ::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription (void)
204 : throw (uno::RuntimeException)
205 : {
206 0 : ThrowIfDisposed();
207 0 : return String(SdResId(STR_PAGE));
208 : }
209 :
210 :
211 :
212 :
213 0 : ::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName (void)
214 : throw (uno::RuntimeException)
215 : {
216 0 : ThrowIfDisposed();
217 0 : const SolarMutexGuard aSolarGuard;
218 :
219 0 : SdPage* pPage = GetPage();
220 0 : if (pPage != NULL)
221 0 : return pPage->GetName();
222 : else
223 0 : return String();
224 : }
225 :
226 :
227 :
228 :
229 : Reference<XAccessibleRelationSet> SAL_CALL
230 0 : AccessibleSlideSorterObject::getAccessibleRelationSet (void)
231 : throw (uno::RuntimeException)
232 : {
233 0 : ThrowIfDisposed();
234 0 : return Reference<XAccessibleRelationSet>();
235 : }
236 :
237 :
238 :
239 :
240 : Reference<XAccessibleStateSet> SAL_CALL
241 0 : AccessibleSlideSorterObject::getAccessibleStateSet (void)
242 : throw (uno::RuntimeException)
243 : {
244 0 : ThrowIfDisposed();
245 0 : const SolarMutexGuard aSolarGuard;
246 0 : ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
247 :
248 0 : if (mxParent.is())
249 : {
250 : // Unconditional states.
251 0 : pStateSet->AddState(AccessibleStateType::SELECTABLE);
252 0 : pStateSet->AddState(AccessibleStateType::FOCUSABLE);
253 0 : pStateSet->AddState(AccessibleStateType::ENABLED);
254 0 : pStateSet->AddState(AccessibleStateType::VISIBLE);
255 0 : pStateSet->AddState(AccessibleStateType::SHOWING);
256 0 : pStateSet->AddState(AccessibleStateType::ACTIVE);
257 0 : pStateSet->AddState(AccessibleStateType::SENSITIVE);
258 :
259 : // Conditional states.
260 0 : if (mrSlideSorter.GetController().GetPageSelector().IsPageSelected(mnPageNumber))
261 0 : pStateSet->AddState(AccessibleStateType::SELECTED);
262 0 : if (mrSlideSorter.GetController().GetFocusManager().GetFocusedPageIndex() == mnPageNumber)
263 0 : if (mrSlideSorter.GetController().GetFocusManager().IsFocusShowing())
264 0 : pStateSet->AddState(AccessibleStateType::FOCUSED);
265 : }
266 :
267 0 : return pStateSet;
268 : }
269 :
270 :
271 :
272 :
273 0 : lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale (void)
274 : throw (IllegalAccessibleComponentStateException,
275 : RuntimeException)
276 : {
277 0 : ThrowIfDisposed();
278 : // Delegate request to parent.
279 0 : if (mxParent.is())
280 : {
281 0 : Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
282 0 : if (xParentContext.is())
283 0 : return xParentContext->getLocale ();
284 : }
285 :
286 : // No locale and no parent. Therefore throw exception to indicate this
287 : // cluelessness.
288 0 : throw IllegalAccessibleComponentStateException();
289 : }
290 :
291 :
292 :
293 :
294 :
295 : //===== XAccessibleEventBroadcaster ===========================================
296 :
297 0 : void SAL_CALL AccessibleSlideSorterObject::addAccessibleEventListener(
298 : const Reference<XAccessibleEventListener>& rxListener)
299 : throw (RuntimeException)
300 : {
301 0 : if (rxListener.is())
302 : {
303 0 : const osl::MutexGuard aGuard(maMutex);
304 :
305 0 : if (IsDisposed())
306 : {
307 0 : uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
308 0 : rxListener->disposing (lang::EventObject (x));
309 : }
310 : else
311 : {
312 0 : if (mnClientId == 0)
313 0 : mnClientId = comphelper::AccessibleEventNotifier::registerClient();
314 0 : comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
315 0 : }
316 : }
317 0 : }
318 :
319 :
320 :
321 :
322 0 : void SAL_CALL AccessibleSlideSorterObject::removeAccessibleEventListener(
323 : const Reference<XAccessibleEventListener>& rxListener)
324 : throw (uno::RuntimeException)
325 : {
326 0 : ThrowIfDisposed();
327 0 : if (rxListener.is())
328 : {
329 0 : const osl::MutexGuard aGuard(maMutex);
330 :
331 0 : sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, rxListener );
332 0 : if ( !nListenerCount )
333 : {
334 : // no listeners anymore
335 : // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
336 : // and at least to us not firing any events anymore, in case somebody calls
337 : // NotifyAccessibleEvent, again
338 0 : comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
339 0 : mnClientId = 0;
340 0 : }
341 : }
342 0 : }
343 :
344 :
345 :
346 :
347 : //===== XAccessibleComponent ==================================================
348 :
349 0 : sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& aPoint)
350 : throw (uno::RuntimeException)
351 : {
352 0 : ThrowIfDisposed();
353 0 : const awt::Size aSize (getSize());
354 : return (aPoint.X >= 0)
355 : && (aPoint.X < aSize.Width)
356 : && (aPoint.Y >= 0)
357 0 : && (aPoint.Y < aSize.Height);
358 : }
359 :
360 :
361 :
362 :
363 : Reference<XAccessible> SAL_CALL
364 0 : AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& )
365 : throw (uno::RuntimeException)
366 : {
367 0 : return NULL;
368 : }
369 :
370 :
371 :
372 :
373 0 : awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds (void)
374 : throw (RuntimeException)
375 : {
376 0 : ThrowIfDisposed ();
377 :
378 0 : const SolarMutexGuard aSolarGuard;
379 :
380 : Rectangle aBBox (
381 0 : mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
382 0 : mrSlideSorter.GetModel().GetPageDescriptor(mnPageNumber),
383 : ::sd::slidesorter::view::PageObjectLayouter::PageObject,
384 0 : ::sd::slidesorter::view::PageObjectLayouter::WindowCoordinateSystem));
385 :
386 0 : if (mxParent.is())
387 : {
388 0 : Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(), UNO_QUERY);
389 0 : if (xParentComponent.is())
390 : {
391 0 : awt::Rectangle aParentBBox (xParentComponent->getBounds());
392 : aBBox.Intersection(Rectangle(
393 : aParentBBox.X,
394 : aParentBBox.Y,
395 : aParentBBox.Width,
396 0 : aParentBBox.Height));
397 0 : }
398 : }
399 :
400 : return awt::Rectangle(
401 0 : aBBox.Left(),
402 0 : aBBox.Top(),
403 0 : aBBox.GetWidth(),
404 0 : aBBox.GetHeight());
405 : }
406 :
407 :
408 :
409 :
410 0 : awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
411 : throw (RuntimeException)
412 : {
413 0 : ThrowIfDisposed ();
414 0 : const awt::Rectangle aBBox (getBounds());
415 0 : return awt::Point(aBBox.X, aBBox.Y);
416 : }
417 :
418 :
419 :
420 :
421 0 : awt::Point SAL_CALL AccessibleSlideSorterObject::getLocationOnScreen (void)
422 : throw (RuntimeException)
423 : {
424 0 : ThrowIfDisposed ();
425 :
426 0 : const SolarMutexGuard aSolarGuard;
427 :
428 0 : awt::Point aLocation (getLocation());
429 :
430 0 : if (mxParent.is())
431 : {
432 0 : Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(),UNO_QUERY);
433 0 : if (xParentComponent.is())
434 : {
435 0 : const awt::Point aParentLocationOnScreen(xParentComponent->getLocationOnScreen());
436 0 : aLocation.X += aParentLocationOnScreen.X;
437 0 : aLocation.Y += aParentLocationOnScreen.Y;
438 0 : }
439 : }
440 :
441 0 : return aLocation;
442 : }
443 :
444 :
445 :
446 :
447 0 : awt::Size SAL_CALL AccessibleSlideSorterObject::getSize (void)
448 : throw (RuntimeException)
449 : {
450 0 : ThrowIfDisposed ();
451 0 : const awt::Rectangle aBBox (getBounds());
452 0 : return awt::Size(aBBox.Width,aBBox.Height);
453 : }
454 :
455 :
456 :
457 :
458 0 : void SAL_CALL AccessibleSlideSorterObject::grabFocus (void)
459 : throw (RuntimeException)
460 : {
461 : // nothing to do
462 0 : }
463 :
464 :
465 :
466 :
467 0 : sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground (void)
468 : throw (::com::sun::star::uno::RuntimeException)
469 : {
470 0 : ThrowIfDisposed ();
471 0 : svtools::ColorConfig aColorConfig;
472 0 : sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
473 0 : return static_cast<sal_Int32>(nColor);
474 : }
475 :
476 :
477 :
478 :
479 0 : sal_Int32 SAL_CALL AccessibleSlideSorterObject::getBackground (void)
480 : throw (::com::sun::star::uno::RuntimeException)
481 : {
482 0 : ThrowIfDisposed ();
483 0 : sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
484 0 : return static_cast<sal_Int32>(nColor);
485 : }
486 :
487 :
488 :
489 :
490 :
491 : //===== XServiceInfo ========================================================
492 :
493 : ::rtl::OUString SAL_CALL
494 0 : AccessibleSlideSorterObject::getImplementationName (void)
495 : throw (::com::sun::star::uno::RuntimeException)
496 : {
497 0 : return OUString("AccessibleSlideSorterObject");
498 : }
499 :
500 :
501 :
502 :
503 : sal_Bool SAL_CALL
504 0 : AccessibleSlideSorterObject::supportsService (const OUString& sServiceName)
505 : throw (::com::sun::star::uno::RuntimeException)
506 : {
507 0 : ThrowIfDisposed ();
508 :
509 : // Iterate over all supported service names and return true if on of them
510 : // matches the given name.
511 : uno::Sequence< ::rtl::OUString> aSupportedServices (
512 0 : getSupportedServiceNames ());
513 0 : for (int i=0; i<aSupportedServices.getLength(); i++)
514 0 : if (sServiceName == aSupportedServices[i])
515 0 : return sal_True;
516 0 : return sal_False;
517 : }
518 :
519 :
520 :
521 :
522 : uno::Sequence< ::rtl::OUString> SAL_CALL
523 0 : AccessibleSlideSorterObject::getSupportedServiceNames (void)
524 : throw (::com::sun::star::uno::RuntimeException)
525 : {
526 0 : ThrowIfDisposed ();
527 :
528 : static const OUString sServiceNames[2] = {
529 : OUString("com.sun.star.accessibility.Accessible"),
530 : OUString("com.sun.star.accessibility.AccessibleContext")
531 0 : };
532 0 : return uno::Sequence<OUString> (sServiceNames, 2);
533 : }
534 :
535 :
536 :
537 :
538 0 : void AccessibleSlideSorterObject::ThrowIfDisposed (void)
539 : throw (lang::DisposedException)
540 : {
541 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
542 : {
543 : OSL_TRACE ("Calling disposed object. Throwing exception:");
544 : throw lang::DisposedException ("object has been already disposed",
545 0 : static_cast<uno::XWeak*>(this));
546 : }
547 0 : }
548 :
549 :
550 :
551 0 : sal_Bool AccessibleSlideSorterObject::IsDisposed (void)
552 : {
553 0 : return (rBHelper.bDisposed || rBHelper.bInDispose);
554 : }
555 :
556 0 : SdPage* AccessibleSlideSorterObject::GetPage (void) const
557 : {
558 : ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
559 0 : mrSlideSorter.GetModel().GetPageDescriptor(mnPageNumber));
560 0 : if (pDescriptor.get() != NULL)
561 0 : return pDescriptor->GetPage();
562 : else
563 0 : return NULL;
564 : }
565 :
566 : } // end of namespace ::accessibility
567 :
568 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|