LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/accessibility - AccessibleSlideSorterObject.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 195 0.5 %
Date: 2013-07-09 Functions: 2 37 5.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10