LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/Accessibility - AccessiblePreviewHeaderCell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 189 0.5 %
Date: 2012-12-17 Functions: 2 31 6.5 %
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             : #include "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : #include <tools/gen.hxx>
      23             : #include "AccessibleText.hxx"
      24             : #include "editsrc.hxx"
      25             : #include <svx/AccessibleTextHelper.hxx>
      26             : #include "AccessiblePreviewHeaderCell.hxx"
      27             : #include "AccessibilityHints.hxx"
      28             : #include "prevwsh.hxx"
      29             : #include "miscuno.hxx"
      30             : #include "prevloc.hxx"
      31             : #include "scresid.hxx"
      32             : #include "sc.hrc"
      33             : 
      34             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      35             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      36             : 
      37             : #include <vcl/window.hxx>
      38             : #include <vcl/svapp.hxx>
      39             : #include <svl/smplhint.hxx>
      40             : #include <unotools/accessiblestatesethelper.hxx>
      41             : #include <comphelper/sequence.hxx>
      42             : #include <comphelper/servicehelper.hxx>
      43             : #include <toolkit/helper/convert.hxx>
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace ::com::sun::star::accessibility;
      47             : 
      48             : //=====  internal  ============================================================
      49             : 
      50           0 : ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const ::com::sun::star::uno::Reference<
      51             :                                 ::com::sun::star::accessibility::XAccessible>& rxParent,
      52             :                             ScPreviewShell* pViewShell,
      53             :                             const ScAddress& rCellPos, sal_Bool bIsColHdr, sal_Bool bIsRowHdr,
      54             :                             sal_Int32 nIndex ) :
      55             :     ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
      56             :     mpViewShell( pViewShell ),
      57             :     mpTextHelper( NULL ),
      58             :     mnIndex( nIndex ),
      59             :     maCellPos( rCellPos ),
      60             :     mbColumnHeader( bIsColHdr ),
      61             :     mbRowHeader( bIsRowHdr ),
      62           0 :     mpTableInfo( NULL )
      63             : {
      64           0 :     if (mpViewShell)
      65           0 :         mpViewShell->AddAccessibilityObject(*this);
      66           0 : }
      67             : 
      68           0 : ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
      69             : {
      70           0 :     if (mpViewShell)
      71           0 :         mpViewShell->RemoveAccessibilityObject(*this);
      72           0 : }
      73             : 
      74           0 : void SAL_CALL ScAccessiblePreviewHeaderCell::disposing()
      75             : {
      76           0 :     SolarMutexGuard aGuard;
      77           0 :     if (mpViewShell)
      78             :     {
      79           0 :         mpViewShell->RemoveAccessibilityObject(*this);
      80           0 :         mpViewShell = NULL;
      81             :     }
      82             : 
      83           0 :        if (mpTableInfo)
      84           0 :         DELETEZ (mpTableInfo);
      85             : 
      86           0 :     ScAccessibleContextBase::disposing();
      87           0 : }
      88             : 
      89             : //=====  SfxListener  =====================================================
      90             : 
      91           0 : void ScAccessiblePreviewHeaderCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
      92             : {
      93           0 :     if (rHint.ISA( SfxSimpleHint ))
      94             :     {
      95           0 :         const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
      96           0 :         sal_uLong nId = rRef.GetId();
      97           0 :         if (nId == SC_HINT_ACC_VISAREACHANGED)
      98             :         {
      99           0 :             if (mpTextHelper)
     100           0 :                 mpTextHelper->UpdateChildren();
     101             :         }
     102           0 :         else if ( nId == SFX_HINT_DATACHANGED )
     103             :         {
     104             :             //  column / row layout may change with any document change,
     105             :             //  so it must be invalidated
     106           0 :             DELETEZ( mpTableInfo );
     107             :         }
     108             :     }
     109             : 
     110           0 :     ScAccessibleContextBase::Notify(rBC, rHint);
     111           0 : }
     112             : 
     113             : //=====  XInterface  =====================================================
     114             : 
     115           0 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::queryInterface( uno::Type const & rType )
     116             :     throw (uno::RuntimeException)
     117             : {
     118           0 :     uno::Any aAny (ScAccessiblePreviewHeaderCellImpl::queryInterface(rType));
     119           0 :     return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
     120             : }
     121             : 
     122           0 : void SAL_CALL ScAccessiblePreviewHeaderCell::acquire()
     123             :     throw ()
     124             : {
     125           0 :     ScAccessibleContextBase::acquire();
     126           0 : }
     127             : 
     128           0 : void SAL_CALL ScAccessiblePreviewHeaderCell::release()
     129             :     throw ()
     130             : {
     131           0 :     ScAccessibleContextBase::release();
     132           0 : }
     133             : 
     134             : //=====  XAccessibleValue  ================================================
     135             : 
     136           0 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getCurrentValue() throw (uno::RuntimeException)
     137             : {
     138           0 :      SolarMutexGuard aGuard;
     139           0 :     IsObjectValid();
     140             : 
     141           0 :     double fValue(0.0);
     142           0 :     if (mbColumnHeader)
     143           0 :         fValue = maCellPos.Col();
     144             :     else
     145           0 :         fValue = maCellPos.Row();
     146             : 
     147           0 :     uno::Any aAny;
     148           0 :     aAny <<= fValue;
     149           0 :     return aAny;
     150             : }
     151             : 
     152           0 : sal_Bool SAL_CALL ScAccessiblePreviewHeaderCell::setCurrentValue( const uno::Any& /* aNumber */ )
     153             :                                                                 throw (uno::RuntimeException)
     154             : {
     155             :     //  it is not possible to set a value
     156           0 :     return false;
     157             : }
     158             : 
     159           0 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMaximumValue() throw (uno::RuntimeException)
     160             : {
     161           0 :      SolarMutexGuard aGuard;
     162           0 :     IsObjectValid();
     163             : 
     164           0 :     double fValue(0.0);
     165           0 :     if (mbColumnHeader)
     166           0 :         fValue = MAXCOL;
     167             :     else
     168           0 :         fValue = MAXROW;
     169           0 :     uno::Any aAny;
     170           0 :     aAny <<= fValue;
     171           0 :     return aAny;
     172             : }
     173             : 
     174           0 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMinimumValue() throw (uno::RuntimeException)
     175             : {
     176           0 :     double fValue(0.0);
     177           0 :     uno::Any aAny;
     178           0 :     aAny <<= fValue;
     179           0 :     return aAny;
     180             : }
     181             : 
     182             : //=====  XAccessibleComponent  ============================================
     183             : 
     184           0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
     185             :                                 throw (uno::RuntimeException)
     186             : {
     187           0 :     uno::Reference<XAccessible> xRet;
     188           0 :     if (containsPoint(rPoint))
     189             :     {
     190           0 :          SolarMutexGuard aGuard;
     191           0 :         IsObjectValid();
     192             : 
     193           0 :         if(!mpTextHelper)
     194           0 :             CreateTextHelper();
     195             : 
     196           0 :         xRet = mpTextHelper->GetAt(rPoint);
     197             :     }
     198             : 
     199           0 :     return xRet;
     200             : }
     201             : 
     202           0 : void SAL_CALL ScAccessiblePreviewHeaderCell::grabFocus() throw (uno::RuntimeException)
     203             : {
     204           0 :      SolarMutexGuard aGuard;
     205           0 :     IsObjectValid();
     206           0 :     if (getAccessibleParent().is())
     207             :     {
     208           0 :         uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
     209           0 :         if (xAccessibleComponent.is())
     210           0 :             xAccessibleComponent->grabFocus();
     211           0 :     }
     212           0 : }
     213             : 
     214             : //=====  XAccessibleContext  ==============================================
     215             : 
     216           0 : sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChildCount() throw(uno::RuntimeException)
     217             : {
     218           0 :     SolarMutexGuard aGuard;
     219           0 :     IsObjectValid();
     220           0 :     if (!mpTextHelper)
     221           0 :         CreateTextHelper();
     222           0 :     return mpTextHelper->GetChildCount();
     223             : }
     224             : 
     225           0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex)
     226             :                             throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
     227             : {
     228           0 :     SolarMutexGuard aGuard;
     229           0 :     IsObjectValid();
     230           0 :     if (!mpTextHelper)
     231           0 :         CreateTextHelper();
     232           0 :     return mpTextHelper->GetChild(nIndex);
     233             : }
     234             : 
     235           0 : sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent() throw (uno::RuntimeException)
     236             : {
     237           0 :     return mnIndex;
     238             : }
     239             : 
     240           0 : uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
     241             :                             throw(uno::RuntimeException)
     242             : {
     243           0 :     SolarMutexGuard aGuard;
     244             : 
     245           0 :     uno::Reference<XAccessibleStateSet> xParentStates;
     246           0 :     if (getAccessibleParent().is())
     247             :     {
     248           0 :         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
     249           0 :         xParentStates = xParentContext->getAccessibleStateSet();
     250             :     }
     251           0 :     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
     252           0 :     if (IsDefunc(xParentStates))
     253           0 :         pStateSet->AddState(AccessibleStateType::DEFUNC);
     254             :     else
     255             :     {
     256           0 :         pStateSet->AddState(AccessibleStateType::ENABLED);
     257           0 :         pStateSet->AddState(AccessibleStateType::MULTI_LINE);
     258           0 :         if (isShowing())
     259           0 :             pStateSet->AddState(AccessibleStateType::SHOWING);
     260           0 :         pStateSet->AddState(AccessibleStateType::TRANSIENT);
     261           0 :         if (isVisible())
     262           0 :             pStateSet->AddState(AccessibleStateType::VISIBLE);
     263             :     }
     264           0 :     return pStateSet;
     265             : }
     266             : 
     267             : //=====  XServiceInfo  ====================================================
     268             : 
     269           0 : rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::getImplementationName() throw(uno::RuntimeException)
     270             : {
     271           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewHeaderCell"));
     272             : }
     273             : 
     274           0 : uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewHeaderCell::getSupportedServiceNames()
     275             :                                                     throw(uno::RuntimeException)
     276             : {
     277           0 :     uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
     278           0 :     sal_Int32 nOldSize(aSequence.getLength());
     279           0 :     aSequence.realloc(nOldSize + 1);
     280           0 :     ::rtl::OUString* pNames = aSequence.getArray();
     281             : 
     282           0 :     pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
     283             : 
     284           0 :     return aSequence;
     285             : }
     286             : 
     287             : //=====  XTypeProvider  =======================================================
     288             : 
     289           0 : uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
     290             :         throw (uno::RuntimeException)
     291             : {
     292           0 :     return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
     293             : }
     294             : 
     295             : namespace
     296             : {
     297             :     class theScAccessiblePreviewHeaderCellImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePreviewHeaderCellImplementationId > {};
     298             : }
     299             : 
     300             : uno::Sequence<sal_Int8> SAL_CALL
     301           0 :     ScAccessiblePreviewHeaderCell::getImplementationId(void)
     302             :     throw (uno::RuntimeException)
     303             : {
     304           0 :     return theScAccessiblePreviewHeaderCellImplementationId::get().getSeq();
     305             : }
     306             : 
     307             : //====  internal  =========================================================
     308             : 
     309           0 : Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
     310             : {
     311           0 :     Rectangle aCellRect;
     312             : 
     313           0 :     FillTableInfo();
     314             : 
     315           0 :     if (mpTableInfo)
     316             :     {
     317           0 :         const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
     318           0 :         const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
     319             : 
     320           0 :         aCellRect = Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
     321             :     }
     322             : 
     323           0 :     if (mpViewShell)
     324             :     {
     325           0 :         Window* pWindow = mpViewShell->GetWindow();
     326           0 :         if (pWindow)
     327             :         {
     328           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
     329           0 :             aCellRect.setX(aCellRect.getX() + aRect.getX());
     330           0 :             aCellRect.setY(aCellRect.getY() + aRect.getY());
     331             :         }
     332             :     }
     333           0 :     return aCellRect;
     334             : }
     335             : 
     336           0 : Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBox() const throw (uno::RuntimeException)
     337             : {
     338           0 :     FillTableInfo();
     339             : 
     340           0 :     if (mpTableInfo)
     341             :     {
     342           0 :         const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
     343           0 :         const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
     344             : 
     345           0 :         Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
     346           0 :         uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
     347           0 :         if (xAccParent.is())
     348             :         {
     349           0 :             uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
     350           0 :             uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
     351           0 :             if (xAccParentComp.is())
     352             :             {
     353           0 :                 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
     354           0 :                 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
     355           0 :                 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
     356           0 :             }
     357             :         }
     358           0 :         return aCellRect;
     359             :     }
     360           0 :     return Rectangle();
     361             : }
     362             : 
     363           0 : rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleDescription() throw(uno::RuntimeException)
     364             : {
     365           0 :     rtl::OUString sDescription = String(ScResId(STR_ACC_HEADERCELL_DESCR));
     366           0 :     return sDescription;
     367             : }
     368             : 
     369           0 : rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleName() throw(uno::RuntimeException)
     370             : {
     371           0 :     rtl::OUString sName = String(ScResId(STR_ACC_HEADERCELL_NAME));
     372             : 
     373           0 :     if ( mbColumnHeader )
     374             :     {
     375           0 :         if ( mbRowHeader )
     376             :         {
     377             :             //! name for corner cell?
     378             : 
     379             : //          sName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Column/Row Header"));
     380             :         }
     381             :         else
     382             :         {
     383             :             // name of column header
     384           0 :             sName += ScColToAlpha( maCellPos.Col() );
     385             :         }
     386             :     }
     387             :     else
     388             :     {
     389             :         // name of row header
     390           0 :         sName += rtl::OUString::valueOf( (sal_Int32) ( maCellPos.Row() + 1 ) );
     391             :     }
     392             : 
     393           0 :     return sName;
     394             : }
     395             : 
     396           0 : sal_Bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
     397             : {
     398           0 :     return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
     399           0 :         (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
     400             : }
     401             : 
     402           0 : void ScAccessiblePreviewHeaderCell::CreateTextHelper()
     403             : {
     404           0 :     if (!mpTextHelper)
     405             :     {
     406             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     407             :         ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewHeaderCellTextData
     408           0 :             (new ScAccessiblePreviewHeaderCellTextData(mpViewShell, String(getAccessibleName()), maCellPos, mbColumnHeader, mbRowHeader));
     409           0 :         ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewHeaderCellTextData));
     410             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     411             : 
     412           0 :         mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
     413           0 :         mpTextHelper->SetEventSource(this);
     414             :     }
     415           0 : }
     416             : 
     417           0 : void ScAccessiblePreviewHeaderCell::FillTableInfo() const
     418             : {
     419           0 :     if ( mpViewShell && !mpTableInfo )
     420             :     {
     421           0 :         Size aOutputSize;
     422           0 :         Window* pWindow = mpViewShell->GetWindow();
     423           0 :         if ( pWindow )
     424           0 :             aOutputSize = pWindow->GetOutputSizePixel();
     425           0 :         Point aPoint;
     426           0 :         Rectangle aVisRect( aPoint, aOutputSize );
     427             : 
     428           0 :         mpTableInfo = new ScPreviewTableInfo;
     429           0 :         mpViewShell->GetLocationData().GetTableInfo( aVisRect, *mpTableInfo );
     430             :     }
     431         102 : }
     432             : 
     433             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10