LCOV - code coverage report
Current view: top level - sc/source/ui/Accessibility - AccessibleCsvControl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 804 0.1 %
Date: 2014-04-11 Functions: 2 162 1.2 %
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 "AccessibleCsvControl.hxx"
      21             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      22             : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
      23             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      24             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      25             : #include <com/sun/star/accessibility/AccessibleTextType.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
      27             : #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
      28             : #include <tools/debug.hxx>
      29             : #include <toolkit/helper/convert.hxx>
      30             : #include <unotools/accessiblerelationsethelper.hxx>
      31             : #include <unotools/accessiblestatesethelper.hxx>
      32             : #include <comphelper/sequence.hxx>
      33             : #include <comphelper/servicehelper.hxx>
      34             : #include "scitems.hxx"
      35             : #include <editeng/fontitem.hxx>
      36             : #include <editeng/fhgtitem.hxx>
      37             : #include <editeng/langitem.hxx>
      38             : #include "csvcontrol.hxx"
      39             : #include "csvruler.hxx"
      40             : #include "csvgrid.hxx"
      41             : #include "AccessibleText.hxx"
      42             : #include "editsrc.hxx"
      43             : #include "scresid.hxx"
      44             : #include "sc.hrc"
      45             : #include "scmod.hxx"
      46             : #include <svtools/colorcfg.hxx>
      47             : #include <vcl/svapp.hxx>
      48             : #include <vcl/settings.hxx>
      49             : // ause
      50             : #include "editutil.hxx"
      51             : 
      52             : using ::utl::AccessibleRelationSetHelper;
      53             : using ::utl::AccessibleStateSetHelper;
      54             : using ::accessibility::AccessibleStaticTextBase;
      55             : using ::com::sun::star::uno::Any;
      56             : using ::com::sun::star::uno::Reference;
      57             : using ::com::sun::star::uno::Sequence;
      58             : using ::com::sun::star::uno::RuntimeException;
      59             : using ::com::sun::star::uno::XInterface;
      60             : using ::com::sun::star::lang::DisposedException;
      61             : using ::com::sun::star::lang::IndexOutOfBoundsException;
      62             : using ::com::sun::star::lang::IllegalArgumentException;
      63             : using ::com::sun::star::beans::PropertyValue;
      64             : using namespace ::com::sun::star::accessibility;
      65             : 
      66             : 
      67             : const sal_uInt16 nRulerRole         = AccessibleRole::TEXT;
      68             : const sal_uInt16 nGridRole          = AccessibleRole::TABLE;
      69             : const sal_uInt16 nCellRole          = AccessibleRole::TEXT;
      70             : 
      71             : #define RULER_IMPL_NAME             "ScAccessibleCsvRuler"
      72             : #define GRID_IMPL_NAME              "ScAccessibleCsvGrid"
      73             : #define CELL_IMPL_NAME              "ScAccessibleCsvCell"
      74             : 
      75             : const sal_Unicode cRulerDot         = '.';
      76             : const sal_Unicode cRulerLine        = '|';
      77             : 
      78             : const sal_Int32 CSV_LINE_HEADER     = CSV_POS_INVALID;
      79             : const sal_uInt32 CSV_COLUMN_HEADER  = CSV_COLUMN_INVALID;
      80             : 
      81           0 : ScAccessibleCsvControl::ScAccessibleCsvControl(
      82             :         const Reference< XAccessible >& rxParent,
      83             :         ScCsvControl& rControl,
      84             :         sal_uInt16 nRole ) :
      85             :     ScAccessibleContextBase( rxParent, nRole ),
      86           0 :     mpControl( &rControl )
      87             : {
      88           0 : }
      89             : 
      90           0 : ScAccessibleCsvControl::~ScAccessibleCsvControl()
      91             : {
      92           0 :     implDispose();
      93           0 : }
      94             : 
      95           0 : void SAL_CALL ScAccessibleCsvControl::disposing()
      96             : {
      97           0 :     SolarMutexGuard aGuard;
      98           0 :     mpControl = NULL;
      99           0 :     ScAccessibleContextBase::disposing();
     100           0 : }
     101             : 
     102             : 
     103             : // XAccessibleComponent -------------------------------------------------------
     104             : 
     105           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvControl::getAccessibleAtPoint( const AwtPoint& /* rPoint */ )
     106             :         throw( RuntimeException, std::exception )
     107             : {
     108           0 :     ensureAlive();
     109           0 :     return NULL;
     110             : }
     111             : 
     112           0 : sal_Bool SAL_CALL ScAccessibleCsvControl::isVisible() throw( RuntimeException, std::exception )
     113             : {
     114           0 :     SolarMutexGuard aGuard;
     115           0 :     ensureAlive();
     116           0 :     return implGetControl().IsVisible();
     117             : }
     118             : 
     119           0 : void SAL_CALL ScAccessibleCsvControl::grabFocus() throw( RuntimeException, std::exception )
     120             : {
     121           0 :     SolarMutexGuard aGuard;
     122           0 :     ensureAlive();
     123           0 :     implGetControl().GrabFocus();
     124           0 : }
     125             : 
     126             : 
     127             : // events ---------------------------------------------------------------------
     128             : 
     129           0 : void ScAccessibleCsvControl::SendFocusEvent( bool bFocused )
     130             : {
     131           0 :     if( bFocused )
     132           0 :         CommitFocusGained();
     133             :     else
     134           0 :         CommitFocusLost();
     135           0 : }
     136             : 
     137           0 : void ScAccessibleCsvControl::SendCaretEvent()
     138             : {
     139             :     OSL_FAIL( "ScAccessibleCsvControl::SendCaretEvent - Illegal call" );
     140           0 : }
     141             : 
     142           0 : void ScAccessibleCsvControl::SendVisibleEvent()
     143             : {
     144           0 :     AccessibleEventObject aEvent;
     145           0 :     aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
     146           0 :     aEvent.Source = Reference< XAccessible >( this );
     147           0 :     CommitChange( aEvent );
     148           0 : }
     149             : 
     150           0 : void ScAccessibleCsvControl::SendSelectionEvent()
     151             : {
     152           0 :     AccessibleEventObject aEvent;
     153           0 :     aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
     154           0 :     aEvent.Source = Reference< XAccessible >( this );
     155           0 :     CommitChange( aEvent );
     156           0 : }
     157             : 
     158           0 : void ScAccessibleCsvControl::SendTableUpdateEvent( sal_uInt32 /* nFirstColumn */, sal_uInt32 /* nLastColumn */, bool /* bAllRows */ )
     159             : {
     160             :     OSL_FAIL( "ScAccessibleCsvControl::SendTableUpdateEvent - Illegal call" );
     161           0 : }
     162             : 
     163           0 : void ScAccessibleCsvControl::SendInsertColumnEvent( sal_uInt32 /* nFirstColumn */, sal_uInt32 /* nLastColumn */ )
     164             : {
     165             :     OSL_FAIL( "ScAccessibleCsvControl::SendInsertColumnEvent - Illegal call" );
     166           0 : }
     167             : 
     168           0 : void ScAccessibleCsvControl::SendRemoveColumnEvent( sal_uInt32 /* nFirstColumn */, sal_uInt32 /* nLastColumn */ )
     169             : {
     170             :     OSL_FAIL( "ScAccessibleCsvControl::SendRemoveColumnEvent - Illegal call" );
     171           0 : }
     172             : 
     173             : 
     174             : // helpers --------------------------------------------------------------------
     175             : 
     176           0 : Rectangle ScAccessibleCsvControl::GetBoundingBoxOnScreen() const throw( RuntimeException, std::exception )
     177             : {
     178           0 :     SolarMutexGuard aGuard;
     179           0 :     ensureAlive();
     180           0 :     return implGetControl().GetWindowExtentsRelative( NULL );
     181             : }
     182             : 
     183           0 : Rectangle ScAccessibleCsvControl::GetBoundingBox() const throw( RuntimeException, std::exception )
     184             : {
     185           0 :     SolarMutexGuard aGuard;
     186           0 :     ensureAlive();
     187           0 :     return implGetControl().GetWindowExtentsRelative( implGetControl().GetAccessibleParentWindow() );
     188             : }
     189             : 
     190           0 : void ScAccessibleCsvControl::ensureAlive() const throw( DisposedException )
     191             : {
     192           0 :     if( !implIsAlive() )
     193           0 :         throw DisposedException();
     194           0 : }
     195             : 
     196           0 : ScCsvControl& ScAccessibleCsvControl::implGetControl() const
     197             : {
     198             :     OSL_ENSURE( mpControl, "ScAccessibleCsvControl::implGetControl - missing control" );
     199           0 :     return *mpControl;
     200             : }
     201             : 
     202           0 : Reference< XAccessible > ScAccessibleCsvControl::implGetChildByRole(
     203             :         const Reference< XAccessible >& rxParentObj, sal_uInt16 nRole ) throw( RuntimeException )
     204             : {
     205           0 :     Reference< XAccessible > xAccObj;
     206           0 :     if( rxParentObj.is() )
     207             :     {
     208           0 :         Reference< XAccessibleContext > xParentCtxt = rxParentObj->getAccessibleContext();
     209           0 :         if( xParentCtxt.is() )
     210             :         {
     211           0 :             sal_Int32 nCount = xParentCtxt->getAccessibleChildCount();
     212           0 :             sal_Int32 nIndex = 0;
     213           0 :             while( !xAccObj.is() && (nIndex < nCount) )
     214             :             {
     215           0 :                 Reference< XAccessible > xCurrObj = xParentCtxt->getAccessibleChild( nIndex );
     216           0 :                 if( xCurrObj.is() )
     217             :                 {
     218           0 :                     Reference< XAccessibleContext > xCurrCtxt = xCurrObj->getAccessibleContext();
     219           0 :                     if( xCurrCtxt.is() && (xCurrCtxt->getAccessibleRole() == nRole) )
     220           0 :                         xAccObj = xCurrObj;
     221             :                 }
     222           0 :                 ++nIndex;
     223           0 :             }
     224           0 :         }
     225             :     }
     226           0 :     return xAccObj;
     227             : }
     228             : 
     229           0 : AccessibleStateSetHelper* ScAccessibleCsvControl::implCreateStateSet()
     230             : {
     231           0 :     SolarMutexGuard aGuard;
     232           0 :     AccessibleStateSetHelper* pStateSet = new AccessibleStateSetHelper();
     233           0 :     if( implIsAlive() )
     234             :     {
     235           0 :         const ScCsvControl& rCtrl = implGetControl();
     236           0 :         pStateSet->AddState( AccessibleStateType::OPAQUE );
     237           0 :         if( rCtrl.IsEnabled() )
     238           0 :             pStateSet->AddState( AccessibleStateType::ENABLED );
     239           0 :         if( isShowing() )
     240           0 :             pStateSet->AddState( AccessibleStateType::SHOWING );
     241           0 :         if( isVisible() )
     242           0 :             pStateSet->AddState( AccessibleStateType::VISIBLE );
     243             :     }
     244             :     else
     245           0 :         pStateSet->AddState( AccessibleStateType::DEFUNC );
     246           0 :     return pStateSet;
     247             : }
     248             : 
     249           0 : void ScAccessibleCsvControl::implDispose()
     250             : {
     251           0 :     if( implIsAlive() )
     252             :     {
     253             :         // prevent multiple call of dtor
     254           0 :         osl_atomic_increment( &m_refCount );
     255           0 :         dispose();
     256             :     }
     257           0 : }
     258             : 
     259           0 : Point ScAccessibleCsvControl::implGetAbsPos( const Point& rPos ) const
     260             : {
     261           0 :     return rPos + implGetControl().GetWindowExtentsRelative( NULL ).TopLeft();
     262             : }
     263             : 
     264             : 
     265             : // Ruler ======================================================================
     266             : 
     267             : /** Converts a ruler cursor position to API text index. */
     268           0 : static sal_Int32 lcl_GetApiPos( sal_Int32 nRulerPos )
     269             : {
     270           0 :     sal_Int32 nApiPos = nRulerPos;
     271           0 :     sal_Int32 nStart = (nRulerPos - 1) / 10;
     272           0 :     sal_Int32 nExp = 1;
     273           0 :     while( nStart >= nExp )
     274             :     {
     275           0 :         nApiPos += nStart - nExp + 1;
     276           0 :         nExp *= 10;
     277             :     }
     278           0 :     return ::std::max( nApiPos, static_cast<sal_Int32>(0) );
     279             : }
     280             : 
     281             : /** Converts an API text index to a ruler cursor position. */
     282           0 : static sal_Int32 lcl_GetRulerPos( sal_Int32 nApiPos )
     283             : {
     284           0 :     sal_Int32 nDiv = 10;
     285           0 :     sal_Int32 nExp = 10;
     286           0 :     sal_Int32 nRulerPos = 0;
     287           0 :     sal_Int32 nApiBase = 0;
     288           0 :     sal_Int32 nApiLimit = 10;
     289           0 :     while( nApiPos >= nApiLimit )
     290             :     {
     291           0 :         ++nDiv;
     292           0 :         nRulerPos = nExp;
     293           0 :         nExp *= 10;
     294           0 :         nApiBase = nApiLimit;
     295           0 :         nApiLimit = lcl_GetApiPos( nExp );
     296             :     }
     297           0 :     sal_Int32 nRelPos = nApiPos - nApiBase;
     298           0 :     return nRulerPos + nRelPos / nDiv * 10 + ::std::max( nRelPos % nDiv - nDiv + 10L, 0L );
     299             : }
     300             : 
     301             : /** Expands the sequence's size and returns the base index of the new inserted elements. */
     302           0 : static inline sal_Int32 lcl_ExpandSequence( Sequence< PropertyValue >& rSeq, sal_Int32 nExp )
     303             : {
     304             :     OSL_ENSURE( nExp > 0, "lcl_ExpandSequence - invalid value" );
     305           0 :     rSeq.realloc( rSeq.getLength() + nExp );
     306           0 :     return rSeq.getLength() - nExp;
     307             : }
     308             : 
     309             : /** Fills the property value rVal with the specified name and value from the item. */
     310           0 : static inline void lcl_FillProperty( PropertyValue& rVal, const OUString& rPropName, const SfxPoolItem& rItem, sal_uInt8 nMID )
     311             : {
     312           0 :     rVal.Name = rPropName;
     313           0 :     rItem.QueryValue( rVal.Value, nMID );
     314           0 : }
     315             : 
     316             : /** Fills the sequence with all font attributes of rFont. */
     317           0 : static void lcl_FillFontAttributes( Sequence< PropertyValue >& rSeq, const Font& rFont )
     318             : {
     319           0 :     SvxFontItem aFontItem( rFont.GetFamily(), rFont.GetName(), rFont.GetStyleName(), rFont.GetPitch(), rFont.GetCharSet(), ATTR_FONT );
     320           0 :     SvxFontHeightItem aHeightItem( rFont.GetSize().Height(), 100, ATTR_FONT_HEIGHT );
     321           0 :     SvxLanguageItem aLangItem( rFont.GetLanguage(), ATTR_FONT_LANGUAGE );
     322             : 
     323           0 :     sal_Int32 nIndex = lcl_ExpandSequence( rSeq, 7 );
     324           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharFontName",      aFontItem,   MID_FONT_FAMILY_NAME );
     325           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharFontFamily",    aFontItem,   MID_FONT_FAMILY );
     326           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharFontStyleName", aFontItem,   MID_FONT_STYLE_NAME );
     327           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharFontCharSet",   aFontItem,   MID_FONT_PITCH );
     328           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharFontPitch",     aFontItem,   MID_FONT_CHAR_SET );
     329           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharHeight",        aHeightItem, MID_FONTHEIGHT );
     330           0 :     lcl_FillProperty( rSeq[ nIndex++ ], "CharLocale",        aLangItem,   MID_LANG_LOCALE );
     331           0 : }
     332             : 
     333           0 : ScAccessibleCsvRuler::ScAccessibleCsvRuler( ScCsvRuler& rRuler ) :
     334           0 :     ScAccessibleCsvControl( rRuler.GetAccessibleParentWindow()->GetAccessible(), rRuler, nRulerRole )
     335             : {
     336           0 :     constructStringBuffer();
     337           0 : }
     338             : 
     339           0 : ScAccessibleCsvRuler::~ScAccessibleCsvRuler()
     340             : {
     341           0 :     implDispose();
     342           0 : }
     343             : 
     344             : // XAccessibleComponent -----------------------------------------------------
     345             : 
     346           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getForeground(  )
     347             :     throw (RuntimeException, std::exception)
     348             : {
     349           0 :     SolarMutexGuard aGuard;
     350           0 :     ensureAlive();
     351           0 :     return implGetRuler().GetSettings().GetStyleSettings().GetLabelTextColor().GetColor();
     352             : }
     353             : 
     354           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getBackground(  )
     355             :     throw (RuntimeException, std::exception)
     356             : {
     357           0 :     SolarMutexGuard aGuard;
     358           0 :     ensureAlive();
     359           0 :     return implGetRuler().GetSettings().GetStyleSettings().GetFaceColor().GetColor();
     360             : }
     361             : 
     362             : // XAccessibleContext ---------------------------------------------------------
     363             : 
     364           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getAccessibleChildCount() throw( RuntimeException, std::exception )
     365             : {
     366           0 :     ensureAlive();
     367           0 :     return 0;
     368             : }
     369             : 
     370           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvRuler::getAccessibleChild( sal_Int32 /* nIndex */ )
     371             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     372             : {
     373           0 :     ensureAlive();
     374           0 :     throw IndexOutOfBoundsException();
     375             : }
     376             : 
     377           0 : Reference< XAccessibleRelationSet > SAL_CALL ScAccessibleCsvRuler::getAccessibleRelationSet()
     378             :         throw( RuntimeException, std::exception )
     379             : {
     380           0 :     SolarMutexGuard aGuard;
     381           0 :     ensureAlive();
     382           0 :     AccessibleRelationSetHelper* pRelationSet = new AccessibleRelationSetHelper();
     383           0 :     Reference< XAccessible > xAccObj = implGetChildByRole( getAccessibleParent(), nGridRole );
     384           0 :     if( xAccObj.is() )
     385             :     {
     386           0 :         Sequence< Reference< XInterface > > aSeq( 1 );
     387           0 :         aSeq[ 0 ] = xAccObj;
     388           0 :         pRelationSet->AddRelation( AccessibleRelation( AccessibleRelationType::CONTROLLER_FOR, aSeq ) );
     389             :     }
     390           0 :     return pRelationSet;
     391             : }
     392             : 
     393           0 : Reference< XAccessibleStateSet > SAL_CALL ScAccessibleCsvRuler::getAccessibleStateSet()
     394             :         throw( RuntimeException, std::exception )
     395             : {
     396           0 :     SolarMutexGuard aGuard;
     397           0 :     AccessibleStateSetHelper* pStateSet = implCreateStateSet();
     398           0 :     if( implIsAlive() )
     399             :     {
     400           0 :         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
     401           0 :         pStateSet->AddState( AccessibleStateType::SINGLE_LINE );
     402           0 :         if( implGetRuler().HasFocus() )
     403           0 :             pStateSet->AddState( AccessibleStateType::FOCUSED );
     404             :     }
     405           0 :     return pStateSet;
     406             : }
     407             : 
     408             : 
     409             : // XAccessibleText ------------------------------------------------------------
     410             : 
     411           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getCaretPosition() throw( RuntimeException, std::exception )
     412             : {
     413           0 :     SolarMutexGuard aGuard;
     414           0 :     ensureAlive();
     415           0 :     return lcl_GetApiPos( implGetRuler().GetRulerCursorPos() );
     416             : }
     417             : 
     418           0 : sal_Bool SAL_CALL ScAccessibleCsvRuler::setCaretPosition( sal_Int32 nIndex )
     419             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     420             : {
     421           0 :     SolarMutexGuard aGuard;
     422           0 :     ensureAlive();
     423           0 :     ensureValidIndex( nIndex );
     424           0 :     ScCsvRuler& rRuler = implGetRuler();
     425           0 :     sal_Int32 nOldCursor = rRuler.GetRulerCursorPos();
     426           0 :     rRuler.Execute( CSVCMD_MOVERULERCURSOR, lcl_GetRulerPos( nIndex ) );
     427           0 :     return rRuler.GetRulerCursorPos() != nOldCursor;
     428             : }
     429             : 
     430           0 : sal_Unicode SAL_CALL ScAccessibleCsvRuler::getCharacter( sal_Int32 nIndex )
     431             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     432             : {
     433           0 :     SolarMutexGuard aGuard;
     434           0 :     ensureAlive();
     435           0 :     ensureValidIndex( nIndex );
     436           0 :     return maBuffer[nIndex];
     437             : }
     438             : 
     439           0 : Sequence< PropertyValue > SAL_CALL ScAccessibleCsvRuler::getCharacterAttributes( sal_Int32 nIndex,
     440             :             const ::com::sun::star::uno::Sequence< OUString >& /* aRequestedAttributes */ )
     441             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     442             : {
     443           0 :     SolarMutexGuard aGuard;
     444           0 :     ensureAlive();
     445           0 :     ensureValidIndexWithEnd( nIndex );
     446           0 :     Sequence< PropertyValue > aSeq;
     447           0 :     lcl_FillFontAttributes( aSeq, implGetRuler().GetFont() );
     448           0 :     return aSeq;
     449             : }
     450             : 
     451           0 : ScAccessibleCsvRuler::AwtRectangle SAL_CALL ScAccessibleCsvRuler::getCharacterBounds( sal_Int32 nIndex )
     452             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     453             : {
     454           0 :     SolarMutexGuard aGuard;
     455           0 :     ensureAlive();
     456           0 :     ensureValidIndexWithEnd( nIndex );
     457           0 :     ScCsvRuler& rRuler = implGetRuler();
     458           0 :     Point aPos( rRuler.GetX( lcl_GetRulerPos( nIndex ) ) - rRuler.GetCharWidth() / 2, 0 );
     459           0 :     AwtRectangle aRect( aPos.X(), aPos.Y(), rRuler.GetCharWidth(), rRuler.GetSizePixel().Height() );
     460             :     // do not return rectangle out of window
     461           0 :     sal_Int32 nWidth = rRuler.GetOutputSizePixel().Width();
     462           0 :     if( aRect.X >= nWidth )
     463           0 :         throw IndexOutOfBoundsException();
     464           0 :     if( aRect.X + aRect.Width > nWidth )
     465           0 :         aRect.Width = nWidth - aRect.X;
     466           0 :     return aRect;
     467             : }
     468             : 
     469           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getCharacterCount() throw( RuntimeException, std::exception )
     470             : {
     471           0 :     SolarMutexGuard aGuard;
     472           0 :     ensureAlive();
     473           0 :     return implGetTextLength();
     474             : }
     475             : 
     476           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getIndexAtPoint( const AwtPoint& rPoint )
     477             :         throw( RuntimeException, std::exception )
     478             : {
     479           0 :     SolarMutexGuard aGuard;
     480           0 :     ensureAlive();
     481           0 :     ScCsvRuler& rRuler = implGetRuler();
     482             :     // use object's coordinate system, convert to API position
     483           0 :     return lcl_GetApiPos( ::std::min( ::std::max( rRuler.GetPosFromX( rPoint.X ), static_cast<sal_Int32>(0) ), rRuler.GetPosCount() ) );
     484             : }
     485             : 
     486           0 : OUString SAL_CALL ScAccessibleCsvRuler::getSelectedText() throw( RuntimeException, std::exception )
     487             : {
     488           0 :     ensureAlive();
     489           0 :     return OUString();
     490             : }
     491             : 
     492           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getSelectionStart() throw( RuntimeException, std::exception )
     493             : {
     494           0 :     ensureAlive();
     495           0 :     return -1;
     496             : }
     497             : 
     498           0 : sal_Int32 SAL_CALL ScAccessibleCsvRuler::getSelectionEnd() throw( RuntimeException, std::exception )
     499             : {
     500           0 :     ensureAlive();
     501           0 :     return -1;
     502             : }
     503             : 
     504           0 : sal_Bool SAL_CALL ScAccessibleCsvRuler::setSelection( sal_Int32 /* nStartIndex */, sal_Int32 /* nEndIndex */ )
     505             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     506             : {
     507           0 :     ensureAlive();
     508           0 :     return false;
     509             : }
     510             : 
     511           0 : OUString SAL_CALL ScAccessibleCsvRuler::getText() throw( RuntimeException, std::exception )
     512             : {
     513           0 :     SolarMutexGuard aGuard;
     514           0 :     ensureAlive();
     515           0 :     return OUString( maBuffer.getStr(), implGetTextLength() );
     516             : }
     517             : 
     518           0 : OUString SAL_CALL ScAccessibleCsvRuler::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
     519             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     520             : {
     521           0 :     SolarMutexGuard aGuard;
     522           0 :     ensureAlive();
     523           0 :     ensureValidRange( nStartIndex, nEndIndex );
     524           0 :     return OUString( maBuffer.getStr() + nStartIndex, nEndIndex - nStartIndex );
     525             : }
     526             : 
     527           0 : TextSegment SAL_CALL ScAccessibleCsvRuler::getTextAtIndex( sal_Int32 nIndex, sal_Int16 nTextType )
     528             :         throw( IndexOutOfBoundsException, IllegalArgumentException, RuntimeException, std::exception )
     529             : {
     530           0 :     SolarMutexGuard aGuard;
     531           0 :     ensureAlive();
     532             : 
     533           0 :     TextSegment aResult;
     534           0 :     aResult.SegmentStart = -1;
     535           0 :     aResult.SegmentEnd = -1;
     536             : 
     537           0 :     if( (nIndex == implGetTextLength()) && (nTextType != AccessibleTextType::LINE) )
     538           0 :         return aResult;
     539             : 
     540           0 :     ensureValidIndex( nIndex );
     541             : 
     542           0 :     OUStringBuffer aResultText;     // will be assigned to aResult.SegmentText below
     543           0 :     sal_Int32 nRulerPos = lcl_GetRulerPos( nIndex );
     544             : 
     545           0 :     switch( nTextType )
     546             :     {
     547             :         // single character
     548             :         case AccessibleTextType::CHARACTER:
     549             :         {
     550           0 :             aResult.SegmentStart = nIndex;
     551           0 :             aResultText.append(maBuffer[nIndex]);
     552             :         }
     553           0 :         break;
     554             : 
     555             :         // entire number or single dot/line
     556             :         case AccessibleTextType::WORD:
     557             :         case AccessibleTextType::GLYPH:
     558           0 :             aResult.SegmentStart = nIndex;
     559           0 :             if( nRulerPos % 10 )
     560           0 :                 aResultText.append(maBuffer[nIndex]);
     561             :             else
     562           0 :                 aResultText.append( nRulerPos );    // string representation of sal_Int32!!!
     563           0 :         break;
     564             : 
     565             :         // entire text
     566             :         case AccessibleTextType::SENTENCE:
     567             :         case AccessibleTextType::PARAGRAPH:
     568             :         case AccessibleTextType::LINE:
     569           0 :             aResult.SegmentStart = 0;
     570           0 :             aResultText.append( maBuffer.getStr(), implGetTextLength() );
     571           0 :         break;
     572             : 
     573             :         // equal-formatted text
     574             :         case AccessibleTextType::ATTRIBUTE_RUN:
     575             :         {
     576           0 :             sal_Int32 nFirstIndex = implGetFirstEqualFormatted( nIndex );
     577           0 :             sal_Int32 nLastIndex = implGetLastEqualFormatted( nIndex );
     578           0 :             aResult.SegmentStart = nFirstIndex;
     579           0 :             aResultText.append( maBuffer.getStr() + nFirstIndex, nLastIndex - nFirstIndex + 1 );
     580             :         }
     581           0 :         break;
     582             : 
     583             :         default:
     584           0 :             throw RuntimeException();
     585             :     }
     586             : 
     587           0 :     aResult.SegmentText = aResultText.makeStringAndClear();
     588           0 :     aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength();
     589           0 :     return aResult;
     590             : }
     591             : 
     592           0 : TextSegment SAL_CALL ScAccessibleCsvRuler::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 nTextType )
     593             :         throw( IndexOutOfBoundsException, IllegalArgumentException, RuntimeException, std::exception )
     594             : {
     595           0 :     SolarMutexGuard aGuard;
     596           0 :     ensureAlive();
     597           0 :     ensureValidIndexWithEnd( nIndex );
     598             : 
     599           0 :     TextSegment aResult;
     600           0 :     aResult.SegmentStart = -1;
     601           0 :     aResult.SegmentEnd = -1;
     602             : 
     603           0 :     sal_Int32 nRulerPos = lcl_GetRulerPos( nIndex );
     604             : 
     605           0 :     switch( nTextType )
     606             :     {
     607             :         // single character
     608             :         case AccessibleTextType::CHARACTER:
     609           0 :             if( nIndex > 0 )
     610           0 :                 aResult = getTextAtIndex( nIndex - 1, nTextType );
     611             :             // else empty
     612           0 :         break;
     613             : 
     614             :         // entire number or single dot/line
     615             :         case AccessibleTextType::WORD:
     616             :         case AccessibleTextType::GLYPH:
     617           0 :             if( nRulerPos > 0 )
     618           0 :                 aResult = getTextAtIndex( lcl_GetApiPos( nRulerPos - 1 ), nTextType );
     619             :             // else empty
     620           0 :         break;
     621             : 
     622             :         // entire text
     623             :         case AccessibleTextType::SENTENCE:
     624             :         case AccessibleTextType::PARAGRAPH:
     625             :         case AccessibleTextType::LINE:
     626             :             // empty
     627           0 :         break;
     628             : 
     629             :         // equal-formatted text
     630             :         case AccessibleTextType::ATTRIBUTE_RUN:
     631             :         {
     632           0 :             sal_Int32 nFirstIndex = implGetFirstEqualFormatted( nIndex );
     633           0 :             if( nFirstIndex > 0 )
     634           0 :                 aResult = getTextAtIndex( nFirstIndex - 1, nTextType );
     635             :             // else empty
     636             :         }
     637           0 :         break;
     638             : 
     639             :         default:
     640           0 :             throw RuntimeException();
     641             :     }
     642           0 :     return aResult;
     643             : }
     644             : 
     645           0 : TextSegment SAL_CALL ScAccessibleCsvRuler::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 nTextType )
     646             :         throw( IndexOutOfBoundsException, IllegalArgumentException, RuntimeException, std::exception )
     647             : {
     648           0 :     SolarMutexGuard aGuard;
     649           0 :     ensureAlive();
     650           0 :     ensureValidIndexWithEnd( nIndex );
     651             : 
     652           0 :     TextSegment aResult;
     653           0 :     aResult.SegmentStart = -1;
     654           0 :     aResult.SegmentEnd = -1;
     655             : 
     656           0 :     sal_Int32 nRulerPos = lcl_GetRulerPos( nIndex );
     657           0 :     sal_Int32 nLastValid = implGetTextLength();
     658             : 
     659           0 :     switch( nTextType )
     660             :     {
     661             :         // single character
     662             :         case AccessibleTextType::CHARACTER:
     663           0 :             if( nIndex < nLastValid )
     664           0 :                 aResult = getTextAtIndex( nIndex + 1, nTextType );
     665             :             // else empty
     666           0 :         break;
     667             : 
     668             :         // entire number or single dot/line
     669             :         case AccessibleTextType::WORD:
     670             :         case AccessibleTextType::GLYPH:
     671           0 :             if( nRulerPos < implGetRuler().GetPosCount() )
     672           0 :                 aResult = getTextAtIndex( lcl_GetApiPos( nRulerPos + 1 ), nTextType );
     673             :             // else empty
     674           0 :         break;
     675             : 
     676             :         // entire text
     677             :         case AccessibleTextType::SENTENCE:
     678             :         case AccessibleTextType::PARAGRAPH:
     679             :         case AccessibleTextType::LINE:
     680             :             // empty
     681           0 :         break;
     682             : 
     683             :         // equal-formatted text
     684             :         case AccessibleTextType::ATTRIBUTE_RUN:
     685             :         {
     686           0 :             sal_Int32 nLastIndex = implGetLastEqualFormatted( nIndex );
     687           0 :             if( nLastIndex < nLastValid )
     688           0 :                 aResult = getTextAtIndex( nLastIndex + 1, nTextType );
     689             :             // else empty
     690             :         }
     691           0 :         break;
     692             : 
     693             :         default:
     694           0 :             throw RuntimeException();
     695             :     }
     696           0 :     return aResult;
     697             : }
     698             : 
     699           0 : sal_Bool SAL_CALL ScAccessibleCsvRuler::copyText( sal_Int32 /* nStartIndex */, sal_Int32 /* nEndIndex */ )
     700             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     701             : {
     702           0 :     ensureAlive();
     703           0 :     return false;
     704             : }
     705             : 
     706             : 
     707             : // XInterface -----------------------------------------------------------------
     708             : 
     709           0 : Any SAL_CALL ScAccessibleCsvRuler::queryInterface( const ::com::sun::star::uno::Type& rType )
     710             :         throw( RuntimeException, std::exception )
     711             : {
     712           0 :     Any aAny( ScAccessibleCsvRulerImpl::queryInterface( rType ) );
     713           0 :     return aAny.hasValue() ? aAny : ScAccessibleCsvControl::queryInterface( rType );
     714             : }
     715             : 
     716           0 : void SAL_CALL ScAccessibleCsvRuler::acquire() throw ()
     717             : {
     718           0 :     ScAccessibleCsvControl::acquire();
     719           0 : }
     720             : 
     721           0 : void SAL_CALL ScAccessibleCsvRuler::release() throw ()
     722             : {
     723           0 :     ScAccessibleCsvControl::release();
     724           0 : }
     725             : 
     726             : 
     727             : // XServiceInfo ---------------------------------------------------------------
     728             : 
     729           0 : OUString SAL_CALL ScAccessibleCsvRuler::getImplementationName() throw( RuntimeException, std::exception )
     730             : {
     731           0 :     return OUString( RULER_IMPL_NAME );
     732             : }
     733             : 
     734             : 
     735             : // XTypeProvider --------------------------------------------------------------
     736             : 
     737           0 : Sequence< ::com::sun::star::uno::Type > SAL_CALL ScAccessibleCsvRuler::getTypes() throw( RuntimeException, std::exception )
     738             : {
     739           0 :     Sequence< ::com::sun::star::uno::Type > aSeq( 1 );
     740           0 :     aSeq[ 0 ] = getCppuType( static_cast< const Reference< XAccessibleText >* >( NULL ) );
     741           0 :     return ::comphelper::concatSequences( ScAccessibleCsvControl::getTypes(), aSeq );
     742             : }
     743             : 
     744           0 : Sequence< sal_Int8 > SAL_CALL ScAccessibleCsvRuler::getImplementationId() throw( RuntimeException, std::exception )
     745             : {
     746           0 :     return css::uno::Sequence<sal_Int8>();
     747             : }
     748             : 
     749             : 
     750             : // events ---------------------------------------------------------------------
     751             : 
     752           0 : void ScAccessibleCsvRuler::SendCaretEvent()
     753             : {
     754           0 :     sal_Int32 nPos = implGetRuler().GetRulerCursorPos();
     755           0 :     if( nPos != CSV_POS_INVALID )
     756             :     {
     757           0 :         AccessibleEventObject aEvent;
     758           0 :         aEvent.EventId = AccessibleEventId::CARET_CHANGED;
     759           0 :         aEvent.Source = Reference< XAccessible >( this );
     760           0 :         aEvent.NewValue <<= nPos;
     761           0 :         CommitChange( aEvent );
     762             :     }
     763           0 : }
     764             : 
     765             : 
     766             : // helpers --------------------------------------------------------------------
     767             : 
     768           0 : OUString SAL_CALL ScAccessibleCsvRuler::createAccessibleName() throw( RuntimeException, std::exception )
     769             : {
     770           0 :     return OUString( ScResId( STR_ACC_CSVRULER_NAME ) );
     771             : }
     772             : 
     773           0 : OUString SAL_CALL ScAccessibleCsvRuler::createAccessibleDescription() throw( RuntimeException )
     774             : {
     775           0 :     return OUString( ScResId( STR_ACC_CSVRULER_DESCR ) );
     776             : }
     777             : 
     778           0 : void ScAccessibleCsvRuler::ensureValidIndex( sal_Int32 nIndex ) const
     779             :         throw( IndexOutOfBoundsException )
     780             : {
     781           0 :     if( (nIndex < 0) || (nIndex >= implGetTextLength()) )
     782           0 :         throw IndexOutOfBoundsException();
     783           0 : }
     784             : 
     785           0 : void ScAccessibleCsvRuler::ensureValidIndexWithEnd( sal_Int32 nIndex ) const
     786             :         throw( IndexOutOfBoundsException )
     787             : {
     788           0 :     if( (nIndex < 0) || (nIndex > implGetTextLength()) )
     789           0 :         throw IndexOutOfBoundsException();
     790           0 : }
     791             : 
     792           0 : void ScAccessibleCsvRuler::ensureValidRange( sal_Int32& rnStartIndex, sal_Int32& rnEndIndex ) const
     793             :         throw( IndexOutOfBoundsException )
     794             : {
     795           0 :     if( rnStartIndex > rnEndIndex )
     796           0 :         ::std::swap( rnStartIndex, rnEndIndex );
     797           0 :     if( (rnStartIndex < 0) || (rnEndIndex > implGetTextLength()) )
     798           0 :         throw IndexOutOfBoundsException();
     799           0 : }
     800             : 
     801           0 : ScCsvRuler& ScAccessibleCsvRuler::implGetRuler() const
     802             : {
     803           0 :     return static_cast< ScCsvRuler& >( implGetControl() );
     804             : }
     805             : 
     806           0 : void ScAccessibleCsvRuler::constructStringBuffer() throw( RuntimeException )
     807             : {
     808           0 :     SolarMutexGuard aGuard;
     809           0 :     ensureAlive();
     810             :     // extend existing string buffer to new ruler size
     811           0 :     sal_Int32 nRulerCount = implGetRuler().GetPosCount();
     812           0 :     sal_Int32 nRulerPos = lcl_GetRulerPos( maBuffer.getLength() );
     813           0 :     for( ; nRulerPos <= nRulerCount; ++nRulerPos ) // include last position
     814             :     {
     815           0 :         switch( nRulerPos % 10 )
     816             :         {
     817           0 :             case 0:     maBuffer.append( nRulerPos );   break;
     818           0 :             case 5:     maBuffer.append( cRulerLine );  break;
     819           0 :             default:    maBuffer.append( cRulerDot );
     820             :         }
     821           0 :     }
     822           0 : }
     823             : 
     824           0 : sal_Int32 ScAccessibleCsvRuler::implGetTextLength() const
     825             : {
     826           0 :     return lcl_GetApiPos( implGetRuler().GetPosCount() + 1 );
     827             : }
     828             : 
     829           0 : bool ScAccessibleCsvRuler::implHasSplit( sal_Int32 nApiPos )
     830             : {
     831           0 :     sal_Int32 nRulerPos = lcl_GetRulerPos( nApiPos );
     832           0 :     return implGetRuler().HasSplit( nRulerPos ) && (nApiPos == lcl_GetApiPos( nRulerPos ));
     833             : }
     834             : 
     835           0 : sal_Int32 ScAccessibleCsvRuler::implGetFirstEqualFormatted( sal_Int32 nApiPos )
     836             : {
     837           0 :     bool bSplit = implHasSplit( nApiPos );
     838           0 :     while( (nApiPos > 0) && (implHasSplit( nApiPos - 1 ) == bSplit) )
     839           0 :         --nApiPos;
     840           0 :     return nApiPos;
     841             : }
     842             : 
     843           0 : sal_Int32 ScAccessibleCsvRuler::implGetLastEqualFormatted( sal_Int32 nApiPos )
     844             : {
     845           0 :     bool bSplit = implHasSplit( nApiPos );
     846           0 :     sal_Int32 nLength = implGetTextLength();
     847           0 :     while( (nApiPos < nLength - 1) && (implHasSplit( nApiPos + 1 ) == bSplit) )
     848           0 :         ++nApiPos;
     849           0 :     return nApiPos;
     850             : }
     851             : 
     852             : 
     853             : // Grid =======================================================================
     854             : 
     855             : /** Converts a grid columnm index to an API column index. */
     856           0 : static inline sal_Int32 lcl_GetApiColumn( sal_uInt32 nGridColumn )
     857             : {
     858           0 :     return (nGridColumn != CSV_COLUMN_HEADER) ? static_cast< sal_Int32 >( nGridColumn + 1 ) : 0;
     859             : }
     860             : 
     861             : /** Converts an API columnm index to a ScCsvGrid column index. */
     862           0 : static inline sal_uInt32 lcl_GetGridColumn( sal_Int32 nApiColumn )
     863             : {
     864           0 :     return (nApiColumn > 0) ? static_cast< sal_uInt32 >( nApiColumn - 1 ) : CSV_COLUMN_HEADER;
     865             : }
     866             : 
     867           0 : ScAccessibleCsvGrid::ScAccessibleCsvGrid( ScCsvGrid& rGrid ) :
     868           0 :     ScAccessibleCsvControl( rGrid.GetAccessibleParentWindow()->GetAccessible(), rGrid, nGridRole )
     869             : {
     870           0 : }
     871             : 
     872           0 : ScAccessibleCsvGrid::~ScAccessibleCsvGrid()
     873             : {
     874           0 :     implDispose();
     875           0 : }
     876             : 
     877             : 
     878             : // XAccessibleComponent -------------------------------------------------------
     879             : 
     880           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvGrid::getAccessibleAtPoint( const AwtPoint& rPoint )
     881             :         throw( RuntimeException, std::exception )
     882             : {
     883           0 :     Reference< XAccessible > xRet;
     884           0 :     if( containsPoint( rPoint ) )
     885             :     {
     886           0 :         SolarMutexGuard aGuard;
     887           0 :         ensureAlive();
     888             : 
     889           0 :         const ScCsvGrid& rGrid = implGetGrid();
     890             :         // #102679#; use <= instead of <, because the offset is the size and not the point
     891           0 :         sal_Int32 nColumn = ((rGrid.GetFirstX() <= rPoint.X) && (rPoint.X <= rGrid.GetLastX())) ?
     892           0 :             lcl_GetApiColumn( rGrid.GetColumnFromX( rPoint.X ) ) : 0;
     893           0 :         sal_Int32 nRow = (rPoint.Y >= rGrid.GetHdrHeight()) ?
     894           0 :             (rGrid.GetLineFromY( rPoint.Y ) - rGrid.GetFirstVisLine() + 1) : 0;
     895           0 :         xRet = implCreateCellObj( nRow, nColumn );
     896             :     }
     897           0 :     return xRet;
     898             : }
     899             : 
     900           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getForeground(  )
     901             : throw (RuntimeException, std::exception)
     902             : {
     903           0 :     SolarMutexGuard aGuard;
     904           0 :     ensureAlive();
     905           0 :     return implGetGrid().GetSettings().GetStyleSettings().GetButtonTextColor().GetColor();
     906             : }
     907             : 
     908           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getBackground(  )
     909             : throw (RuntimeException, std::exception)
     910             : {
     911           0 :     SolarMutexGuard aGuard;
     912           0 :     ensureAlive();
     913           0 :     return SC_MOD()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor;
     914             : }
     915             : 
     916             : // XAccessibleContext ---------------------------------------------------------
     917             : 
     918           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleChildCount() throw( RuntimeException, std::exception )
     919             : {
     920           0 :     SolarMutexGuard aGuard;
     921           0 :     ensureAlive();
     922           0 :     return implGetCellCount();
     923             : }
     924             : 
     925           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvGrid::getAccessibleChild( sal_Int32 nIndex )
     926             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     927             : {
     928           0 :     SolarMutexGuard aGuard;
     929           0 :     ensureAlive();
     930           0 :     ensureValidIndex( nIndex );
     931           0 :     return implCreateCellObj( implGetRow( nIndex ), implGetColumn( nIndex ) );
     932             : }
     933             : 
     934           0 : Reference< XAccessibleRelationSet > SAL_CALL ScAccessibleCsvGrid::getAccessibleRelationSet()
     935             :         throw( RuntimeException, std::exception )
     936             : {
     937           0 :     SolarMutexGuard aGuard;
     938           0 :     ensureAlive();
     939           0 :     AccessibleRelationSetHelper* pRelationSet = new AccessibleRelationSetHelper();
     940           0 :     Reference< XAccessible > xAccObj = implGetChildByRole( getAccessibleParent(), nRulerRole );
     941           0 :     if( xAccObj.is() )
     942             :     {
     943           0 :         Sequence< Reference< XInterface > > aSeq( 1 );
     944           0 :         aSeq[ 0 ] = xAccObj;
     945           0 :         pRelationSet->AddRelation( AccessibleRelation( AccessibleRelationType::CONTROLLED_BY, aSeq ) );
     946             :     }
     947           0 :     return pRelationSet;
     948             : }
     949             : 
     950           0 : Reference< XAccessibleStateSet > SAL_CALL ScAccessibleCsvGrid::getAccessibleStateSet()
     951             :         throw( RuntimeException, std::exception )
     952             : {
     953           0 :     SolarMutexGuard aGuard;
     954           0 :     AccessibleStateSetHelper* pStateSet = implCreateStateSet();
     955           0 :     if( implIsAlive() )
     956             :     {
     957           0 :         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
     958           0 :         pStateSet->AddState( AccessibleStateType::MULTI_SELECTABLE );
     959           0 :         pStateSet->AddState( AccessibleStateType::MANAGES_DESCENDANTS );
     960           0 :         if( implGetGrid().HasFocus() )
     961           0 :             pStateSet->AddState( AccessibleStateType::FOCUSED );
     962             :     }
     963             :     else
     964           0 :         pStateSet->AddState( AccessibleStateType::DEFUNC );
     965           0 :     return pStateSet;
     966             : }
     967             : 
     968             : 
     969             : // XAccessibleTable -----------------------------------------------------------
     970             : 
     971           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleRowCount() throw( RuntimeException, std::exception )
     972             : {
     973           0 :     SolarMutexGuard aGuard;
     974           0 :     ensureAlive();
     975           0 :     return implGetRowCount();
     976             : }
     977             : 
     978           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleColumnCount() throw( RuntimeException, std::exception )
     979             : {
     980           0 :     SolarMutexGuard aGuard;
     981           0 :     ensureAlive();
     982           0 :     return implGetColumnCount();
     983             : }
     984             : 
     985           0 : OUString SAL_CALL ScAccessibleCsvGrid::getAccessibleRowDescription( sal_Int32 nRow )
     986             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     987             : {
     988           0 :     SolarMutexGuard aGuard;
     989           0 :     ensureAlive();
     990           0 :     ensureValidPosition( nRow, 0 );
     991           0 :     return implGetCellText( nRow, 0 );
     992             : }
     993             : 
     994           0 : OUString SAL_CALL ScAccessibleCsvGrid::getAccessibleColumnDescription( sal_Int32 nColumn )
     995             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
     996             : {
     997           0 :     SolarMutexGuard aGuard;
     998           0 :     ensureAlive();
     999           0 :     ensureValidPosition( 0, nColumn );
    1000           0 :     return implGetCellText( 0, nColumn );
    1001             : }
    1002             : 
    1003           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
    1004             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1005             : {
    1006           0 :     ensureAlive();
    1007           0 :     ensureValidPosition( nRow, nColumn );
    1008           0 :     return 1;
    1009             : }
    1010             : 
    1011           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
    1012             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1013             : {
    1014           0 :     ensureAlive();
    1015           0 :     ensureValidPosition( nRow, nColumn );
    1016           0 :     return 1;
    1017             : }
    1018             : 
    1019           0 : Reference< XAccessibleTable > SAL_CALL ScAccessibleCsvGrid::getAccessibleRowHeaders()
    1020             :         throw( RuntimeException, std::exception )
    1021             : {
    1022           0 :     ensureAlive();
    1023           0 :     return NULL;
    1024             : }
    1025             : 
    1026           0 : Reference< XAccessibleTable > SAL_CALL ScAccessibleCsvGrid::getAccessibleColumnHeaders()
    1027             :         throw( RuntimeException, std::exception )
    1028             : {
    1029           0 :     ensureAlive();
    1030           0 :     return NULL;
    1031             : }
    1032             : 
    1033           0 : Sequence< sal_Int32 > SAL_CALL ScAccessibleCsvGrid::getSelectedAccessibleRows()
    1034             :         throw( RuntimeException, std::exception )
    1035             : {
    1036           0 :     ensureAlive();
    1037           0 :     return Sequence< sal_Int32 >();
    1038             : }
    1039             : 
    1040           0 : Sequence< sal_Int32 > SAL_CALL ScAccessibleCsvGrid::getSelectedAccessibleColumns()
    1041             :         throw( RuntimeException, std::exception )
    1042             : {
    1043           0 :     SolarMutexGuard aGuard;
    1044           0 :     ensureAlive();
    1045             : 
    1046           0 :     ScCsvGrid& rGrid = implGetGrid();
    1047           0 :     Sequence< sal_Int32 > aSeq( implGetColumnCount() );
    1048             : 
    1049           0 :     sal_Int32 nSeqIx = 0;
    1050           0 :     sal_uInt32 nColIx = rGrid.GetFirstSelected();
    1051           0 :     for( ; nColIx != CSV_COLUMN_INVALID; ++nSeqIx, nColIx = rGrid.GetNextSelected( nColIx ) )
    1052           0 :         aSeq[ nSeqIx ] = lcl_GetApiColumn( nColIx );
    1053             : 
    1054           0 :     aSeq.realloc( nSeqIx );
    1055           0 :     return aSeq;
    1056             : }
    1057             : 
    1058           0 : sal_Bool SAL_CALL ScAccessibleCsvGrid::isAccessibleRowSelected( sal_Int32 /* nRow */ )
    1059             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1060             : {
    1061           0 :     ensureAlive();
    1062           0 :     return false;
    1063             : }
    1064             : 
    1065           0 : sal_Bool SAL_CALL ScAccessibleCsvGrid::isAccessibleColumnSelected( sal_Int32 nColumn )
    1066             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1067             : {
    1068           0 :     SolarMutexGuard aGuard;
    1069           0 :     ensureAlive();
    1070           0 :     ensureValidIndex( nColumn );
    1071           0 :     return implIsColumnSelected( nColumn );
    1072             : }
    1073             : 
    1074           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvGrid::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn )
    1075             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1076             : {
    1077           0 :     SolarMutexGuard aGuard;
    1078           0 :     ensureAlive();
    1079           0 :     ensureValidPosition( nRow, nColumn );
    1080           0 :     return implCreateCellObj( nRow, nColumn );
    1081             : }
    1082             : 
    1083           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvGrid::getAccessibleCaption()
    1084             :         throw( RuntimeException, std::exception )
    1085             : {
    1086           0 :     ensureAlive();
    1087           0 :     return NULL;
    1088             : }
    1089             : 
    1090           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvGrid::getAccessibleSummary()
    1091             :         throw( RuntimeException, std::exception )
    1092             : {
    1093           0 :     ensureAlive();
    1094           0 :     return NULL;
    1095             : }
    1096             : 
    1097           0 : sal_Bool SAL_CALL ScAccessibleCsvGrid::isAccessibleSelected( sal_Int32 /* nRow */, sal_Int32 nColumn )
    1098             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1099             : {
    1100           0 :     return isAccessibleColumnSelected( nColumn );
    1101             : }
    1102             : 
    1103           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
    1104             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1105             : {
    1106           0 :     SolarMutexGuard aGuard;
    1107           0 :     ensureAlive();
    1108           0 :     ensureValidPosition( nRow, nColumn );
    1109           0 :     return implGetIndex( nRow, nColumn );
    1110             : }
    1111             : 
    1112           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleRow( sal_Int32 nChildIndex )
    1113             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1114             : {
    1115           0 :     SolarMutexGuard aGuard;
    1116           0 :     ensureAlive();
    1117           0 :     ensureValidIndex( nChildIndex );
    1118           0 :     return implGetRow( nChildIndex );
    1119             : }
    1120             : 
    1121           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getAccessibleColumn( sal_Int32 nChildIndex )
    1122             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1123             : {
    1124           0 :     SolarMutexGuard aGuard;
    1125           0 :     ensureAlive();
    1126           0 :     ensureValidIndex( nChildIndex );
    1127           0 :     return implGetColumn( nChildIndex );
    1128             : }
    1129             : 
    1130             : 
    1131             : // XAccessibleSelection -------------------------------------------------------
    1132             : 
    1133           0 : void SAL_CALL ScAccessibleCsvGrid::selectAccessibleChild( sal_Int32 nChildIndex )
    1134             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1135             : {
    1136           0 :     SolarMutexGuard aGuard;
    1137           0 :     ensureAlive();
    1138           0 :     ensureValidIndex( nChildIndex );
    1139           0 :     sal_Int32 nColumn = implGetColumn( nChildIndex );
    1140           0 :     if( nChildIndex == 0 )
    1141           0 :         implGetGrid().SelectAll();
    1142             :     else
    1143           0 :         implSelectColumn( nColumn, true );
    1144           0 : }
    1145             : 
    1146           0 : sal_Bool SAL_CALL ScAccessibleCsvGrid::isAccessibleChildSelected( sal_Int32 nChildIndex )
    1147             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1148             : {
    1149           0 :     SolarMutexGuard aGuard;
    1150           0 :     ensureAlive();
    1151           0 :     ensureValidIndex( nChildIndex );
    1152           0 :     sal_Int32 nColumn = implGetColumn( nChildIndex );
    1153           0 :     return implIsColumnSelected( nColumn );
    1154             : }
    1155             : 
    1156           0 : void SAL_CALL ScAccessibleCsvGrid::clearAccessibleSelection() throw( RuntimeException, std::exception )
    1157             : {
    1158           0 :     SolarMutexGuard aGuard;
    1159           0 :     ensureAlive();
    1160           0 :     implGetGrid().SelectAll( false );
    1161           0 : }
    1162             : 
    1163           0 : void SAL_CALL ScAccessibleCsvGrid::selectAllAccessibleChildren() throw( RuntimeException, std::exception )
    1164             : {
    1165           0 :     selectAccessibleChild( 0 );
    1166           0 : }
    1167             : 
    1168           0 : sal_Int32 SAL_CALL ScAccessibleCsvGrid::getSelectedAccessibleChildCount() throw( RuntimeException, std::exception )
    1169             : {
    1170           0 :     SolarMutexGuard aGuard;
    1171           0 :     ensureAlive();
    1172           0 :     return implGetRowCount() * implGetSelColumnCount();
    1173             : }
    1174             : 
    1175           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvGrid::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
    1176             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1177             : {
    1178           0 :     SolarMutexGuard aGuard;
    1179           0 :     ensureAlive();
    1180           0 :     sal_Int32 nColumns = implGetSelColumnCount();
    1181           0 :     if( nColumns == 0 )
    1182           0 :         throw IndexOutOfBoundsException();
    1183             : 
    1184           0 :     sal_Int32 nRow = nSelectedChildIndex / nColumns;
    1185           0 :     sal_Int32 nColumn = implGetSelColumn( nSelectedChildIndex % nColumns );
    1186           0 :     return getAccessibleCellAt( nRow, nColumn );
    1187             : }
    1188             : 
    1189           0 : void SAL_CALL ScAccessibleCsvGrid::deselectAccessibleChild( sal_Int32 nSelectedChildIndex )
    1190             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1191             : {
    1192           0 :     SolarMutexGuard aGuard;
    1193           0 :     ensureAlive();
    1194           0 :     sal_Int32 nColumns = implGetSelColumnCount();
    1195           0 :     if( nColumns == 0 )
    1196           0 :         throw IndexOutOfBoundsException();
    1197             : 
    1198           0 :     sal_Int32 nColumn = implGetSelColumn( nSelectedChildIndex % nColumns );
    1199           0 :     ensureValidPosition( nSelectedChildIndex / nColumns, nColumn );
    1200           0 :     if( nColumn > 0 )
    1201           0 :         implSelectColumn( nColumn, false );
    1202           0 : }
    1203             : 
    1204             : 
    1205             : // XInterface -----------------------------------------------------------------
    1206             : 
    1207           0 : Any SAL_CALL ScAccessibleCsvGrid::queryInterface( const ::com::sun::star::uno::Type& rType )
    1208             :         throw( RuntimeException, std::exception )
    1209             : {
    1210           0 :     Any aAny( ScAccessibleCsvGridImpl::queryInterface( rType ) );
    1211           0 :     return aAny.hasValue() ? aAny : ScAccessibleCsvControl::queryInterface( rType );
    1212             : }
    1213             : 
    1214           0 : void SAL_CALL ScAccessibleCsvGrid::acquire() throw ()
    1215             : {
    1216           0 :     ScAccessibleCsvControl::acquire();
    1217           0 : }
    1218             : 
    1219           0 : void SAL_CALL ScAccessibleCsvGrid::release() throw ()
    1220             : {
    1221           0 :     ScAccessibleCsvControl::release();
    1222           0 : }
    1223             : 
    1224             : 
    1225             : // XServiceInfo ---------------------------------------------------------------
    1226             : 
    1227           0 : OUString SAL_CALL ScAccessibleCsvGrid::getImplementationName() throw( RuntimeException, std::exception )
    1228             : {
    1229           0 :     return OUString( GRID_IMPL_NAME );
    1230             : }
    1231             : 
    1232             : 
    1233             : // XTypeProvider --------------------------------------------------------------
    1234             : 
    1235           0 : Sequence< ::com::sun::star::uno::Type > SAL_CALL ScAccessibleCsvGrid::getTypes() throw( RuntimeException, std::exception )
    1236             : {
    1237           0 :     Sequence< ::com::sun::star::uno::Type > aSeq( 2 );
    1238           0 :     aSeq[ 0 ] = getCppuType( static_cast< const Reference< XAccessibleTable >* >( NULL ) );
    1239           0 :     aSeq[ 1 ] = getCppuType( static_cast< const Reference< XAccessibleSelection >* >( NULL ) );
    1240           0 :     return ::comphelper::concatSequences( ScAccessibleCsvControl::getTypes(), aSeq );
    1241             : }
    1242             : 
    1243           0 : Sequence< sal_Int8 > SAL_CALL ScAccessibleCsvGrid::getImplementationId() throw( RuntimeException, std::exception )
    1244             : {
    1245           0 :     return css::uno::Sequence<sal_Int8>();
    1246             : }
    1247             : 
    1248             : 
    1249             : // events ---------------------------------------------------------------------
    1250             : 
    1251           0 : void ScAccessibleCsvGrid::SendFocusEvent( bool bFocused )
    1252             : {
    1253           0 :     ScAccessibleCsvControl::SendFocusEvent( bFocused );
    1254             : 
    1255           0 :     AccessibleEventObject aEvent;
    1256           0 :     aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
    1257           0 :     aEvent.Source = Reference< XAccessible >( this );
    1258           0 :     (bFocused ? aEvent.NewValue : aEvent.OldValue) <<=
    1259           0 :         getAccessibleCellAt( 0, lcl_GetApiColumn( implGetGrid().GetFocusColumn() ) );
    1260           0 :     CommitChange( aEvent );
    1261           0 : }
    1262             : 
    1263           0 : void ScAccessibleCsvGrid::SendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows )
    1264             : {
    1265           0 :     if( nFirstColumn <= nLastColumn )
    1266             :     {
    1267             :         AccessibleTableModelChange aModelChange(
    1268           0 :             AccessibleTableModelChangeType::UPDATE, 0, bAllRows ? implGetRowCount() - 1 : 0,
    1269           0 :             lcl_GetApiColumn( nFirstColumn ), lcl_GetApiColumn( nLastColumn ) );
    1270           0 :         AccessibleEventObject aEvent;
    1271           0 :         aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
    1272           0 :         aEvent.Source = Reference< XAccessible >( this );
    1273           0 :         aEvent.NewValue <<= aModelChange;
    1274           0 :         CommitChange( aEvent );
    1275             :     }
    1276           0 : }
    1277             : 
    1278           0 : void ScAccessibleCsvGrid::SendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
    1279             : {
    1280           0 :     if( nFirstColumn <= nLastColumn )
    1281             :     {
    1282             :         AccessibleTableModelChange aModelChange(
    1283           0 :             AccessibleTableModelChangeType::INSERT, 0, implGetRowCount() - 1,
    1284           0 :             lcl_GetApiColumn( nFirstColumn ), lcl_GetApiColumn( nLastColumn ) );
    1285           0 :         AccessibleEventObject aEvent;
    1286           0 :         aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
    1287           0 :         aEvent.Source = Reference< XAccessible >( this );
    1288           0 :         aEvent.NewValue <<= aModelChange;
    1289           0 :         CommitChange( aEvent );
    1290             :     }
    1291           0 : }
    1292             : 
    1293           0 : void ScAccessibleCsvGrid::SendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
    1294             : {
    1295           0 :     if( nFirstColumn <= nLastColumn )
    1296             :     {
    1297             :         AccessibleTableModelChange aModelChange(
    1298           0 :             AccessibleTableModelChangeType::DELETE, 0, implGetRowCount() - 1,
    1299           0 :             lcl_GetApiColumn( nFirstColumn ), lcl_GetApiColumn( nLastColumn ) );
    1300           0 :         AccessibleEventObject aEvent;
    1301           0 :         aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
    1302           0 :         aEvent.Source = Reference< XAccessible >( this );
    1303           0 :         aEvent.NewValue <<= aModelChange;
    1304           0 :         CommitChange( aEvent );
    1305             :     }
    1306           0 : }
    1307             : 
    1308             : 
    1309             : // helpers --------------------------------------------------------------------
    1310             : 
    1311           0 : OUString SAL_CALL ScAccessibleCsvGrid::createAccessibleName() throw( RuntimeException, std::exception )
    1312             : {
    1313           0 :     return OUString( ScResId( STR_ACC_CSVGRID_NAME ) );
    1314             : }
    1315             : 
    1316           0 : OUString SAL_CALL ScAccessibleCsvGrid::createAccessibleDescription() throw( RuntimeException )
    1317             : {
    1318           0 :     return OUString( ScResId( STR_ACC_CSVGRID_DESCR ) );
    1319             : }
    1320             : 
    1321           0 : void ScAccessibleCsvGrid::ensureValidIndex( sal_Int32 nIndex ) const
    1322             :         throw( IndexOutOfBoundsException )
    1323             : {
    1324           0 :     if( (nIndex < 0) || (nIndex >= implGetCellCount()) )
    1325           0 :         throw IndexOutOfBoundsException();
    1326           0 : }
    1327             : 
    1328           0 : void ScAccessibleCsvGrid::ensureValidPosition( sal_Int32 nRow, sal_Int32 nColumn ) const
    1329             :         throw( IndexOutOfBoundsException )
    1330             : {
    1331           0 :     if( (nRow < 0) || (nRow >= implGetRowCount()) || (nColumn < 0) || (nColumn >= implGetColumnCount()) )
    1332           0 :         throw IndexOutOfBoundsException();
    1333           0 : }
    1334             : 
    1335           0 : ScCsvGrid& ScAccessibleCsvGrid::implGetGrid() const
    1336             : {
    1337           0 :     return static_cast< ScCsvGrid& >( implGetControl() );
    1338             : }
    1339             : 
    1340           0 : bool ScAccessibleCsvGrid::implIsColumnSelected( sal_Int32 nColumn ) const
    1341             : {
    1342           0 :     return (nColumn > 0) && implGetGrid().IsSelected( lcl_GetGridColumn( nColumn ) );
    1343             : }
    1344             : 
    1345           0 : void ScAccessibleCsvGrid::implSelectColumn( sal_Int32 nColumn, bool bSelect )
    1346             : {
    1347           0 :     if( nColumn > 0 )
    1348           0 :         implGetGrid().Select( lcl_GetGridColumn( nColumn ), bSelect );
    1349           0 : }
    1350             : 
    1351           0 : sal_Int32 ScAccessibleCsvGrid::implGetRowCount() const
    1352             : {
    1353           0 :     return static_cast< sal_Int32 >( implGetGrid().GetLastVisLine() - implGetGrid().GetFirstVisLine() + 2 );
    1354             : }
    1355             : 
    1356           0 : sal_Int32 ScAccessibleCsvGrid::implGetColumnCount() const
    1357             : {
    1358           0 :     return static_cast< sal_Int32 >( implGetGrid().GetColumnCount() + 1 );
    1359             : }
    1360             : 
    1361           0 : sal_Int32 ScAccessibleCsvGrid::implGetSelColumnCount() const
    1362             : {
    1363           0 :     ScCsvGrid& rGrid = implGetGrid();
    1364           0 :     sal_Int32 nCount = 0;
    1365           0 :     for( sal_uInt32 nColIx = rGrid.GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = rGrid.GetNextSelected( nColIx ) )
    1366           0 :         ++nCount;
    1367           0 :     return nCount;
    1368             : }
    1369             : 
    1370           0 : sal_Int32 ScAccessibleCsvGrid::implGetSelColumn( sal_Int32 nSelColumn ) const
    1371             : {
    1372           0 :     ScCsvGrid& rGrid = implGetGrid();
    1373           0 :     sal_Int32 nColumn = 0;
    1374           0 :     for( sal_uInt32 nColIx = rGrid.GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = rGrid.GetNextSelected( nColIx ) )
    1375             :     {
    1376           0 :         if( nColumn == nSelColumn )
    1377           0 :             return static_cast< sal_Int32 >( nColIx + 1 );
    1378           0 :         ++nColumn;
    1379             :     }
    1380           0 :     return 0;
    1381             : }
    1382             : 
    1383           0 : OUString ScAccessibleCsvGrid::implGetCellText( sal_Int32 nRow, sal_Int32 nColumn ) const
    1384             : {
    1385           0 :     ScCsvGrid& rGrid = implGetGrid();
    1386           0 :     sal_Int32 nLine = nRow + rGrid.GetFirstVisLine() - 1;
    1387           0 :     OUString aCellStr;
    1388           0 :     if( (nColumn > 0) && (nRow > 0) )
    1389           0 :         aCellStr = rGrid.GetCellText( lcl_GetGridColumn( nColumn ), nLine );
    1390           0 :     else if( nRow > 0 )
    1391           0 :         aCellStr = OUString::number( nLine + 1L );
    1392           0 :     else if( nColumn > 0 )
    1393           0 :         aCellStr = rGrid.GetColumnTypeName( lcl_GetGridColumn( nColumn ) );
    1394           0 :     return aCellStr;
    1395             : }
    1396             : 
    1397             : 
    1398           0 : ScAccessibleCsvControl* ScAccessibleCsvGrid::implCreateCellObj( sal_Int32 nRow, sal_Int32 nColumn ) const
    1399             : {
    1400           0 :     return new ScAccessibleCsvCell( implGetGrid(), implGetCellText( nRow, nColumn ), nRow, nColumn );
    1401             : }
    1402             : 
    1403           0 : ScAccessibleCsvCell::ScAccessibleCsvCell(
    1404             :         ScCsvGrid& rGrid,
    1405             :         const OUString& rCellText,
    1406             :         sal_Int32 nRow, sal_Int32 nColumn ) :
    1407             :     ScAccessibleCsvControl( rGrid.GetAccessible(), rGrid, nCellRole ),
    1408             :     AccessibleStaticTextBase( SvxEditSourcePtr( NULL ) ),
    1409             :     maCellText( rCellText ),
    1410           0 :     mnLine( nRow ? (nRow + rGrid.GetFirstVisLine() - 1) : CSV_LINE_HEADER ),
    1411           0 :     mnColumn( lcl_GetGridColumn( nColumn ) ),
    1412           0 :     mnIndex( nRow * (rGrid.GetColumnCount() + 1) + nColumn )
    1413             : {
    1414           0 :     SetEditSource( implCreateEditSource() );
    1415           0 : }
    1416             : 
    1417           0 : ScAccessibleCsvCell::~ScAccessibleCsvCell()
    1418             : {
    1419           0 : }
    1420             : 
    1421           0 : void SAL_CALL ScAccessibleCsvCell::disposing()
    1422             : {
    1423           0 :     SolarMutexGuard aGuard;
    1424           0 :     SetEditSource( SvxEditSourcePtr( NULL ) );
    1425           0 :     ScAccessibleCsvControl::disposing();
    1426           0 : }
    1427             : 
    1428             : 
    1429             : // XAccessibleComponent -------------------------------------------------------
    1430             : 
    1431           0 : void SAL_CALL ScAccessibleCsvCell::grabFocus() throw( RuntimeException, std::exception )
    1432             : {
    1433           0 :     SolarMutexGuard aGuard;
    1434           0 :     ensureAlive();
    1435           0 :     ScCsvGrid& rGrid = implGetGrid();
    1436           0 :     rGrid.Execute( CSVCMD_MOVEGRIDCURSOR, rGrid.GetColumnPos( mnColumn ) );
    1437           0 : }
    1438             : 
    1439           0 : sal_Int32 SAL_CALL ScAccessibleCsvCell::getForeground(  )
    1440             : throw (RuntimeException, std::exception)
    1441             : {
    1442           0 :     SolarMutexGuard aGuard;
    1443           0 :     ensureAlive();
    1444           0 :     return implGetGrid().GetSettings().GetStyleSettings().GetButtonTextColor().GetColor();
    1445             : }
    1446             : 
    1447           0 : sal_Int32 SAL_CALL ScAccessibleCsvCell::getBackground(  )
    1448             : throw (RuntimeException, std::exception)
    1449             : {
    1450           0 :     SolarMutexGuard aGuard;
    1451           0 :     ensureAlive();
    1452           0 :     return SC_MOD()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor;
    1453             : }
    1454             : 
    1455             : // XAccessibleContext -----------------------------------------------------
    1456             : 
    1457           0 : sal_Int32 SAL_CALL ScAccessibleCsvCell::getAccessibleChildCount() throw( RuntimeException, std::exception )
    1458             : {
    1459           0 :     return AccessibleStaticTextBase::getAccessibleChildCount();
    1460             : }
    1461             : 
    1462           0 : Reference< XAccessible > SAL_CALL ScAccessibleCsvCell::getAccessibleChild( sal_Int32 nIndex )
    1463             :         throw( IndexOutOfBoundsException, RuntimeException, std::exception )
    1464             : {
    1465           0 :     return AccessibleStaticTextBase::getAccessibleChild( nIndex );
    1466             : }
    1467             : 
    1468           0 : sal_Int32 SAL_CALL ScAccessibleCsvCell::getAccessibleIndexInParent() throw( RuntimeException, std::exception )
    1469             : {
    1470           0 :     SolarMutexGuard aGuard;
    1471           0 :     ensureAlive();
    1472           0 :     return mnIndex;
    1473             : }
    1474             : 
    1475           0 : Reference< XAccessibleRelationSet > SAL_CALL ScAccessibleCsvCell::getAccessibleRelationSet()
    1476             :         throw( RuntimeException, std::exception )
    1477             : {
    1478           0 :     SolarMutexGuard aGuard;
    1479           0 :     ensureAlive();
    1480           0 :     return new AccessibleRelationSetHelper();
    1481             : }
    1482             : 
    1483           0 : Reference< XAccessibleStateSet > SAL_CALL ScAccessibleCsvCell::getAccessibleStateSet()
    1484             :         throw( RuntimeException, std::exception )
    1485             : {
    1486           0 :     SolarMutexGuard aGuard;
    1487           0 :     AccessibleStateSetHelper* pStateSet = implCreateStateSet();
    1488           0 :     if( implIsAlive() )
    1489             :     {
    1490           0 :         const ScCsvGrid& rGrid = implGetGrid();
    1491           0 :         pStateSet->AddState( AccessibleStateType::SINGLE_LINE );
    1492           0 :         if( mnColumn != CSV_COLUMN_HEADER )
    1493           0 :             pStateSet->AddState( AccessibleStateType::SELECTABLE );
    1494           0 :         if( rGrid.HasFocus() && (rGrid.GetFocusColumn() == mnColumn) && (mnLine == CSV_LINE_HEADER) )
    1495           0 :             pStateSet->AddState( AccessibleStateType::ACTIVE );
    1496           0 :         if( rGrid.IsSelected( mnColumn ) )
    1497           0 :             pStateSet->AddState( AccessibleStateType::SELECTED );
    1498             :     }
    1499           0 :     return pStateSet;
    1500             : }
    1501             : 
    1502             : // XInterface -----------------------------------------------------------------
    1503             : 
    1504           0 : IMPLEMENT_FORWARD_XINTERFACE2( ScAccessibleCsvCell, ScAccessibleCsvControl, AccessibleStaticTextBase )
    1505             : 
    1506             : // XTypeProvider --------------------------------------------------------------
    1507             : 
    1508           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScAccessibleCsvCell, ScAccessibleCsvControl, AccessibleStaticTextBase )
    1509             : 
    1510             : // XServiceInfo ---------------------------------------------------------------
    1511             : 
    1512           0 : OUString SAL_CALL ScAccessibleCsvCell::getImplementationName() throw( RuntimeException, std::exception )
    1513             : {
    1514           0 :     return OUString( CELL_IMPL_NAME );
    1515             : }
    1516             : 
    1517             : // helpers --------------------------------------------------------------------
    1518             : 
    1519           0 : Rectangle ScAccessibleCsvCell::GetBoundingBoxOnScreen() const throw( RuntimeException, std::exception )
    1520             : {
    1521           0 :     SolarMutexGuard aGuard;
    1522           0 :     ensureAlive();
    1523           0 :     Rectangle aRect( implGetBoundingBox() );
    1524           0 :     aRect.SetPos( implGetAbsPos( aRect.TopLeft() ) );
    1525           0 :     return aRect;
    1526             : }
    1527             : 
    1528           0 : Rectangle ScAccessibleCsvCell::GetBoundingBox() const throw( RuntimeException, std::exception )
    1529             : {
    1530           0 :     SolarMutexGuard aGuard;
    1531           0 :     ensureAlive();
    1532           0 :     return implGetBoundingBox();
    1533             : }
    1534             : 
    1535           0 : OUString SAL_CALL ScAccessibleCsvCell::createAccessibleName() throw( RuntimeException, std::exception )
    1536             : {
    1537           0 :     return maCellText;
    1538             : }
    1539             : 
    1540           0 : OUString SAL_CALL ScAccessibleCsvCell::createAccessibleDescription() throw( RuntimeException )
    1541             : {
    1542           0 :     return OUString();
    1543             : }
    1544             : 
    1545           0 : ScCsvGrid& ScAccessibleCsvCell::implGetGrid() const
    1546             : {
    1547           0 :     return static_cast< ScCsvGrid& >( implGetControl() );
    1548             : }
    1549             : 
    1550           0 : Point ScAccessibleCsvCell::implGetRealPos() const
    1551             : {
    1552           0 :     ScCsvGrid& rGrid = implGetGrid();
    1553             :     return Point(
    1554           0 :         (mnColumn == CSV_COLUMN_HEADER) ? rGrid.GetHdrX() : rGrid.GetColumnX( mnColumn ),
    1555           0 :         (mnLine == CSV_LINE_HEADER) ? 0 : rGrid.GetY( mnLine ) );
    1556             : }
    1557             : 
    1558           0 : sal_uInt32 ScAccessibleCsvCell::implCalcPixelWidth(sal_uInt32 nChars) const
    1559             : {
    1560           0 :     ScCsvGrid& rGrid = implGetGrid();
    1561           0 :     return rGrid.GetCharWidth() * nChars;
    1562             : }
    1563             : 
    1564           0 : Size ScAccessibleCsvCell::implGetRealSize() const
    1565             : {
    1566           0 :     ScCsvGrid& rGrid = implGetGrid();
    1567             :     return Size(
    1568           0 :         (mnColumn == CSV_COLUMN_HEADER) ? rGrid.GetHdrWidth() : implCalcPixelWidth( rGrid.GetColumnWidth( mnColumn ) ),
    1569           0 :         (mnLine == CSV_LINE_HEADER) ? rGrid.GetHdrHeight() : rGrid.GetLineHeight() );
    1570             : }
    1571             : 
    1572           0 : Rectangle ScAccessibleCsvCell::implGetBoundingBox() const
    1573             : {
    1574           0 :     ScCsvGrid& rGrid = implGetGrid();
    1575           0 :     Rectangle aClipRect( Point( 0, 0 ), rGrid.GetSizePixel() );
    1576           0 :     if( mnColumn != CSV_COLUMN_HEADER )
    1577             :     {
    1578           0 :         aClipRect.Left() = rGrid.GetFirstX();
    1579           0 :         aClipRect.Right() = rGrid.GetLastX();
    1580             :     }
    1581           0 :     if( mnLine != CSV_LINE_HEADER )
    1582           0 :          aClipRect.Top() = rGrid.GetHdrHeight();
    1583             : 
    1584           0 :     Rectangle aRect( implGetRealPos(), implGetRealSize() );
    1585           0 :     aRect.Intersection( aClipRect );
    1586           0 :     if( (aRect.GetWidth() <= 0) || (aRect.GetHeight() <= 0) )
    1587           0 :         aRect.SetSize( Size( -1, -1 ) );
    1588           0 :     return aRect;
    1589             : }
    1590             : 
    1591             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1592           0 : ::std::auto_ptr< SvxEditSource > ScAccessibleCsvCell::implCreateEditSource()
    1593             : {
    1594           0 :     ScCsvGrid& rGrid = implGetGrid();
    1595           0 :     Rectangle aBoundRect( implGetBoundingBox() );
    1596           0 :     aBoundRect -= implGetRealPos();
    1597             : 
    1598             :     ::std::auto_ptr< ScAccessibleTextData > pCsvTextData( new ScAccessibleCsvTextData(
    1599           0 :         &rGrid, rGrid.GetEditEngine(), maCellText, aBoundRect, implGetRealSize() ) );
    1600             : 
    1601           0 :     ::std::auto_ptr< SvxEditSource > pEditSource( new ScAccessibilityEditSource( pCsvTextData ) );
    1602           0 :     return pEditSource;
    1603             : }
    1604         102 : SAL_WNODEPRECATED_DECLARATIONS_POP
    1605             : 
    1606             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10