LCOV - code coverage report
Current view: top level - starmath/source - accessibility.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 398 957 41.6 %
Date: 2015-06-13 12:38:46 Functions: 87 160 54.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <memory>
      23             : #include <utility>
      24             : 
      25             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      27             : #include <com/sun/star/accessibility/AccessibleTextType.hpp>
      28             : #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
      29             : #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
      30             : #include <com/sun/star/awt/FocusEvent.hpp>
      31             : #include <com/sun/star/awt/XFocusListener.hpp>
      32             : #include <unotools/accessiblerelationsethelper.hxx>
      33             : 
      34             : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
      35             : #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
      36             : #include <com/sun/star/i18n/WordType.hpp>
      37             : #include <unotools/accessiblestatesethelper.hxx>
      38             : #include <comphelper/accessibleeventnotifier.hxx>
      39             : #include <cppuhelper/supportsservice.hxx>
      40             : #include <osl/diagnose.h>
      41             : #include <vcl/svapp.hxx>
      42             : #include <vcl/window.hxx>
      43             : #include <vcl/unohelp2.hxx>
      44             : #include <vcl/settings.hxx>
      45             : 
      46             : #include <tools/gen.hxx>
      47             : #include <osl/mutex.hxx>
      48             : #include <svl/itemset.hxx>
      49             : 
      50             : #include <editeng/editobj.hxx>
      51             : #include <editeng/editdata.hxx>
      52             : #include <editeng/editview.hxx>
      53             : #include <editeng/eeitem.hxx>
      54             : #include <editeng/outliner.hxx>
      55             : #include <editeng/unoedhlp.hxx>
      56             : 
      57             : 
      58             : #include "accessibility.hxx"
      59             : #include <unomodel.hxx>
      60             : #include <document.hxx>
      61             : #include <view.hxx>
      62             : 
      63             : using namespace com::sun::star;
      64             : using namespace com::sun::star::lang;
      65             : using namespace com::sun::star::uno;
      66             : using namespace com::sun::star::accessibility;
      67             : 
      68             : 
      69             : 
      70           4 : static awt::Rectangle lcl_GetBounds( vcl::Window *pWin )
      71             : {
      72             :     // !! see VCLXAccessibleComponent::implGetBounds()
      73             : 
      74             :     //! the coordinates returned are relativ to the parent window !
      75             :     //! Thus the top-left point may be different from (0, 0) !
      76             : 
      77           4 :     awt::Rectangle aBounds;
      78           4 :     if (pWin)
      79             :     {
      80           4 :         Rectangle aRect = pWin->GetWindowExtentsRelative( NULL );
      81           4 :         aBounds.X       = aRect.Left();
      82           4 :         aBounds.Y       = aRect.Top();
      83           4 :         aBounds.Width   = aRect.GetWidth();
      84           4 :         aBounds.Height  = aRect.GetHeight();
      85           4 :         vcl::Window* pParent = pWin->GetAccessibleParentWindow();
      86           4 :         if (pParent)
      87             :         {
      88           4 :             Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
      89           4 :             awt::Point aParentScreenLoc( aParentRect.Left(), aParentRect.Top() );
      90           4 :             aBounds.X -= aParentScreenLoc.X;
      91           4 :             aBounds.Y -= aParentScreenLoc.Y;
      92             :         }
      93             :     }
      94           4 :     return aBounds;
      95             : }
      96             : 
      97           2 : static awt::Point lcl_GetLocationOnScreen( vcl::Window *pWin )
      98             : {
      99             :     // !! see VCLXAccessibleComponent::getLocationOnScreen()
     100             : 
     101           2 :     awt::Point aPos;
     102           2 :     if (pWin)
     103             :     {
     104           2 :         Rectangle aRect = pWin->GetWindowExtentsRelative( NULL );
     105           2 :         aPos.X = aRect.Left();
     106           2 :         aPos.Y = aRect.Top();
     107             :     }
     108           2 :     return aPos;
     109             : }
     110             : 
     111             : 
     112             : 
     113           3 : SmGraphicAccessible::SmGraphicAccessible( SmGraphicWindow *pGraphicWin ) :
     114             :     aAccName            (SM_RESSTR(RID_DOCUMENTSTR)),
     115             :     nClientId           (0),
     116           3 :     pWin                (pGraphicWin)
     117             : {
     118             :     OSL_ENSURE( pWin, "SmGraphicAccessible: window missing" );
     119           3 : }
     120             : 
     121           6 : SmGraphicAccessible::~SmGraphicAccessible()
     122             : {
     123           6 : }
     124             : 
     125             : 
     126           3 : SmDocShell * SmGraphicAccessible::GetDoc_Impl()
     127             : {
     128           3 :     SmViewShell *pView = pWin ? pWin->GetView() : 0;
     129           3 :     return pView ? pView->GetDoc() : 0;
     130             : }
     131             : 
     132           0 : OUString SmGraphicAccessible::GetAccessibleText_Impl()
     133             : {
     134           0 :     OUString aTxt;
     135           0 :     SmDocShell *pDoc = GetDoc_Impl();
     136           0 :     if (pDoc)
     137           0 :         aTxt = pDoc->GetAccessibleText();
     138           0 :     return aTxt;
     139             : }
     140             : 
     141           3 : void SmGraphicAccessible::ClearWin()
     142             : {
     143           3 :     pWin = 0;   // implicitly results in AccessibleStateType::DEFUNC set
     144             : 
     145           3 :     if ( nClientId )
     146             :     {
     147           0 :         comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, *this );
     148           0 :         nClientId =  0;
     149             :     }
     150           3 : }
     151             : 
     152           1 : void SmGraphicAccessible::LaunchEvent(
     153             :         const sal_Int16 nAccesibleEventId,
     154             :         const uno::Any &rOldVal,
     155             :         const uno::Any &rNewVal)
     156             : {
     157           1 :     AccessibleEventObject aEvt;
     158           1 :     aEvt.Source     = static_cast<XAccessible *>(this);
     159           1 :     aEvt.EventId    = nAccesibleEventId;
     160           1 :     aEvt.OldValue   = rOldVal;
     161           1 :     aEvt.NewValue   = rNewVal ;
     162             : 
     163             :     // pass event on to event-listener's
     164           1 :     if (nClientId)
     165           0 :         comphelper::AccessibleEventNotifier::addEvent( nClientId, aEvt );
     166           1 : }
     167             : 
     168           7 : uno::Reference< XAccessibleContext > SAL_CALL SmGraphicAccessible::getAccessibleContext()
     169             :     throw (RuntimeException, std::exception)
     170             : {
     171           7 :     SolarMutexGuard aGuard;
     172           7 :     return this;
     173             : }
     174             : 
     175        1728 : sal_Bool SAL_CALL SmGraphicAccessible::containsPoint( const awt::Point& aPoint )
     176             :     throw (RuntimeException, std::exception)
     177             : {
     178             :     //! the arguments coordinates are relativ to the current window !
     179             :     //! Thus the top-left point is (0, 0)
     180             : 
     181        1728 :     SolarMutexGuard aGuard;
     182        1728 :     if (!pWin)
     183           0 :         throw RuntimeException();
     184             : 
     185        1728 :     Size aSz( pWin->GetSizePixel() );
     186        3947 :     return  aPoint.X >= 0  &&  aPoint.Y >= 0  &&
     187        3085 :             aPoint.X < aSz.Width()  &&  aPoint.Y < aSz.Height();
     188             : }
     189             : 
     190           0 : uno::Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleAtPoint(
     191             :         const awt::Point& aPoint )
     192             :     throw (RuntimeException, std::exception)
     193             : {
     194           0 :     SolarMutexGuard aGuard;
     195           0 :     XAccessible *pRes = 0;
     196           0 :     if (containsPoint( aPoint ))
     197           0 :         pRes = this;
     198           0 :     return pRes;
     199             : }
     200             : 
     201           1 : awt::Rectangle SAL_CALL SmGraphicAccessible::getBounds()
     202             :     throw (RuntimeException, std::exception)
     203             : {
     204           1 :     SolarMutexGuard aGuard;
     205           1 :     if (!pWin)
     206           0 :         throw RuntimeException();
     207             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
     208             :             "mismatch of window parent and accessible parent" );
     209           1 :     return lcl_GetBounds( pWin );
     210             : }
     211             : 
     212           1 : awt::Point SAL_CALL SmGraphicAccessible::getLocation()
     213             :     throw (RuntimeException, std::exception)
     214             : {
     215           1 :     SolarMutexGuard aGuard;
     216           1 :     if (!pWin)
     217           0 :         throw RuntimeException();
     218             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
     219             :             "mismatch of window parent and accessible parent" );
     220           1 :     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
     221           1 :     return awt::Point( aRect.X, aRect.Y );
     222             : }
     223             : 
     224           1 : awt::Point SAL_CALL SmGraphicAccessible::getLocationOnScreen()
     225             :     throw (RuntimeException, std::exception)
     226             : {
     227           1 :     SolarMutexGuard aGuard;
     228           1 :     if (!pWin)
     229           0 :         throw RuntimeException();
     230             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
     231             :             "mismatch of window parent and accessible parent" );
     232           1 :     return lcl_GetLocationOnScreen( pWin );
     233             : }
     234             : 
     235           1 : awt::Size SAL_CALL SmGraphicAccessible::getSize()
     236             :     throw (RuntimeException, std::exception)
     237             : {
     238           1 :     SolarMutexGuard aGuard;
     239           1 :     if (!pWin)
     240           0 :         throw RuntimeException();
     241             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
     242             :             "mismatch of window parent and accessible parent" );
     243             : 
     244           1 :     Size aSz( pWin->GetSizePixel() );
     245             : #if OSL_DEBUG_LEVEL > 1
     246             :     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
     247             :     Size aSz2( aRect.Width, aRect.Height );
     248             :     OSL_ENSURE( aSz == aSz2, "mismatch in width" );
     249             : #endif
     250           1 :     return awt::Size( aSz.Width(), aSz.Height() );
     251             : }
     252             : 
     253           1 : void SAL_CALL SmGraphicAccessible::grabFocus()
     254             :     throw (RuntimeException, std::exception)
     255             : {
     256           1 :     SolarMutexGuard aGuard;
     257           1 :     if (!pWin)
     258           0 :         throw RuntimeException();
     259             : 
     260           1 :     pWin->GrabFocus();
     261           1 : }
     262             : 
     263           1 : sal_Int32 SAL_CALL SmGraphicAccessible::getForeground()
     264             :     throw (RuntimeException, std::exception)
     265             : {
     266           1 :     SolarMutexGuard aGuard;
     267             : 
     268           1 :     if (!pWin)
     269           0 :         throw RuntimeException();
     270           1 :     return (sal_Int32) pWin->GetTextColor().GetColor();
     271             : }
     272             : 
     273           1 : sal_Int32 SAL_CALL SmGraphicAccessible::getBackground()
     274             :     throw (RuntimeException, std::exception)
     275             : {
     276           1 :     SolarMutexGuard aGuard;
     277             : 
     278           1 :     if (!pWin)
     279           0 :         throw RuntimeException();
     280           2 :     Wallpaper aWall( pWin->GetDisplayBackground() );
     281             :     ColorData nCol;
     282           1 :     if (aWall.IsBitmap() || aWall.IsGradient())
     283           0 :         nCol = pWin->GetSettings().GetStyleSettings().GetWindowColor().GetColor();
     284             :     else
     285           1 :         nCol = aWall.GetColor().GetColor();
     286           2 :     return (sal_Int32) nCol;
     287             : }
     288             : 
     289           8 : sal_Int32 SAL_CALL SmGraphicAccessible::getAccessibleChildCount()
     290             :     throw (RuntimeException, std::exception)
     291             : {
     292           8 :     SolarMutexGuard aGuard;
     293           8 :     return 0;
     294             : }
     295             : 
     296           0 : Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleChild(
     297             :         sal_Int32 /*i*/ )
     298             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     299             : {
     300           0 :     SolarMutexGuard aGuard;
     301           0 :     throw IndexOutOfBoundsException();  // there is no child...
     302             : }
     303             : 
     304           4 : Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleParent()
     305             :     throw (RuntimeException, std::exception)
     306             : {
     307           4 :     SolarMutexGuard aGuard;
     308           4 :     if (!pWin)
     309           0 :         throw RuntimeException();
     310             : 
     311           4 :     vcl::Window *pAccParent = pWin->GetAccessibleParentWindow();
     312             :     OSL_ENSURE( pAccParent, "accessible parent missing" );
     313           4 :     return pAccParent ? pAccParent->GetAccessible() : Reference< XAccessible >();
     314             : }
     315             : 
     316           1 : sal_Int32 SAL_CALL SmGraphicAccessible::getAccessibleIndexInParent()
     317             :     throw (RuntimeException, std::exception)
     318             : {
     319           1 :     SolarMutexGuard aGuard;
     320           1 :     sal_Int32 nIdx = -1;
     321           1 :     vcl::Window *pAccParent = pWin ? pWin->GetAccessibleParentWindow() : 0;
     322           1 :     if (pAccParent)
     323             :     {
     324           1 :         sal_uInt16 nCnt = pAccParent->GetAccessibleChildWindowCount();
     325           2 :         for (sal_uInt16 i = 0;  i < nCnt  &&  nIdx == -1;  ++i)
     326           1 :             if (pAccParent->GetAccessibleChildWindow( i ) == pWin)
     327           1 :                 nIdx = i;
     328             :     }
     329           1 :     return nIdx;
     330             : }
     331             : 
     332           6 : sal_Int16 SAL_CALL SmGraphicAccessible::getAccessibleRole()
     333             :     throw (RuntimeException, std::exception)
     334             : {
     335           6 :     SolarMutexGuard aGuard;
     336           6 :     return AccessibleRole::DOCUMENT;
     337             : }
     338             : 
     339           3 : OUString SAL_CALL SmGraphicAccessible::getAccessibleDescription()
     340             :     throw (RuntimeException, std::exception)
     341             : {
     342           3 :     SolarMutexGuard aGuard;
     343           3 :     SmDocShell *pDoc = GetDoc_Impl();
     344           3 :     return pDoc ? OUString(pDoc->GetText()) : OUString();
     345             : }
     346             : 
     347           4 : OUString SAL_CALL SmGraphicAccessible::getAccessibleName()
     348             :     throw (RuntimeException, std::exception)
     349             : {
     350           4 :     SolarMutexGuard aGuard;
     351           4 :     return aAccName;
     352             : }
     353             : 
     354           1 : Reference< XAccessibleRelationSet > SAL_CALL SmGraphicAccessible::getAccessibleRelationSet()
     355             :     throw (RuntimeException, std::exception)
     356             : {
     357           1 :     SolarMutexGuard aGuard;
     358           1 :     Reference< XAccessibleRelationSet > xRelSet = new utl::AccessibleRelationSetHelper();
     359           1 :     return xRelSet;   // empty relation set
     360             : }
     361             : 
     362           4 : Reference< XAccessibleStateSet > SAL_CALL SmGraphicAccessible::getAccessibleStateSet()
     363             :     throw (RuntimeException, std::exception)
     364             : {
     365           4 :     SolarMutexGuard aGuard;
     366             :     ::utl::AccessibleStateSetHelper *pStateSet =
     367           4 :             new ::utl::AccessibleStateSetHelper;
     368             : 
     369           4 :     Reference<XAccessibleStateSet> xStateSet( pStateSet );
     370             : 
     371           4 :     if (!pWin)
     372           0 :         pStateSet->AddState( AccessibleStateType::DEFUNC );
     373             :     else
     374             :     {
     375           4 :         pStateSet->AddState( AccessibleStateType::ENABLED );
     376           4 :         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
     377           4 :         if (pWin->HasFocus())
     378           1 :             pStateSet->AddState( AccessibleStateType::FOCUSED );
     379           4 :         if (pWin->IsActive())
     380           0 :             pStateSet->AddState( AccessibleStateType::ACTIVE );
     381           4 :         if (pWin->IsVisible())
     382           4 :             pStateSet->AddState( AccessibleStateType::SHOWING );
     383           4 :         if (pWin->IsReallyVisible())
     384           4 :             pStateSet->AddState( AccessibleStateType::VISIBLE );
     385           4 :         if (COL_TRANSPARENT != pWin->GetBackground().GetColor().GetColor())
     386           4 :             pStateSet->AddState( AccessibleStateType::OPAQUE );
     387             :     }
     388             : 
     389           4 :     return xStateSet;
     390             : }
     391             : 
     392           1 : Locale SAL_CALL SmGraphicAccessible::getLocale()
     393             :     throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
     394             : {
     395           1 :     SolarMutexGuard aGuard;
     396             :     // should be the document language...
     397             :     // We use the language of the localized symbol names here.
     398           1 :     return Application::GetSettings().GetUILanguageTag().getLocale();
     399             : }
     400             : 
     401             : 
     402           0 : void SAL_CALL SmGraphicAccessible::addAccessibleEventListener(
     403             :         const Reference< XAccessibleEventListener >& xListener )
     404             :     throw (RuntimeException, std::exception)
     405             : {
     406           0 :     if (xListener.is())
     407             :     {
     408           0 :         SolarMutexGuard aGuard;
     409           0 :         if (pWin)
     410             :         {
     411           0 :             if (!nClientId)
     412           0 :                 nClientId = comphelper::AccessibleEventNotifier::registerClient( );
     413           0 :             comphelper::AccessibleEventNotifier::addEventListener( nClientId, xListener );
     414           0 :         }
     415             :     }
     416           0 : }
     417             : 
     418           0 : void SAL_CALL SmGraphicAccessible::removeAccessibleEventListener(
     419             :         const Reference< XAccessibleEventListener >& xListener )
     420             :     throw (RuntimeException, std::exception)
     421             : {
     422           0 :     if (xListener.is())
     423             :     {
     424           0 :         SolarMutexGuard aGuard;
     425           0 :         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( nClientId, xListener );
     426           0 :         if ( !nListenerCount )
     427             :         {
     428             :             // no listeners anymore
     429             :             // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
     430             :             // and at least to us not firing any events anymore, in case somebody calls
     431             :             // NotifyAccessibleEvent, again
     432           0 :             comphelper::AccessibleEventNotifier::revokeClient( nClientId );
     433           0 :             nClientId = 0;
     434           0 :         }
     435             :     }
     436           0 : }
     437             : 
     438           0 : sal_Int32 SAL_CALL SmGraphicAccessible::getCaretPosition()
     439             :     throw (RuntimeException, std::exception)
     440             : {
     441           0 :     SolarMutexGuard aGuard;
     442           0 :     return 0;
     443             : }
     444             : 
     445           0 : sal_Bool SAL_CALL SmGraphicAccessible::setCaretPosition( sal_Int32 nIndex )
     446             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     447             : {
     448           0 :     SolarMutexGuard aGuard;
     449           0 :     OUString aTxt( GetAccessibleText_Impl() );
     450           0 :     if (!(nIndex < aTxt.getLength()))
     451           0 :         throw IndexOutOfBoundsException();
     452           0 :     return sal_False;
     453             : }
     454             : 
     455           0 : sal_Unicode SAL_CALL SmGraphicAccessible::getCharacter( sal_Int32 nIndex )
     456             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     457             : {
     458           0 :     SolarMutexGuard aGuard;
     459           0 :     OUString aTxt( GetAccessibleText_Impl() );
     460           0 :     if (!(nIndex < aTxt.getLength()))
     461           0 :         throw IndexOutOfBoundsException();
     462           0 :     return aTxt[nIndex];
     463             : }
     464             : 
     465           0 : Sequence< beans::PropertyValue > SAL_CALL SmGraphicAccessible::getCharacterAttributes(
     466             :         sal_Int32 nIndex,
     467             :         const uno::Sequence< OUString > & /*rRequestedAttributes*/ )
     468             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     469             : {
     470           0 :     SolarMutexGuard aGuard;
     471           0 :     sal_Int32 nLen = GetAccessibleText_Impl().getLength();
     472           0 :     if (!(0 <= nIndex  &&  nIndex < nLen))
     473           0 :         throw IndexOutOfBoundsException();
     474           0 :     return Sequence< beans::PropertyValue >();
     475             : }
     476             : 
     477           0 : awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nIndex )
     478             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     479             : {
     480           0 :     SolarMutexGuard aGuard;
     481             : 
     482           0 :     awt::Rectangle aRes;
     483             : 
     484           0 :     if (!pWin)
     485           0 :         throw RuntimeException();
     486             :     else
     487             :     {
     488             :         // get accessible text
     489           0 :         SmViewShell *pView = pWin->GetView();
     490           0 :         SmDocShell  *pDoc  = pView ? pView->GetDoc() : 0;
     491           0 :         if (!pDoc)
     492           0 :             throw RuntimeException();
     493           0 :         OUString aTxt( GetAccessibleText_Impl() );
     494           0 :         if (!(0 <= nIndex  &&  nIndex <= aTxt.getLength()))   // aTxt.getLength() is valid
     495           0 :             throw IndexOutOfBoundsException();
     496             : 
     497             :         // find a reasonable rectangle for position aTxt.getLength().
     498           0 :         bool bWasBehindText = (nIndex == aTxt.getLength());
     499           0 :         if (bWasBehindText && nIndex)
     500           0 :             --nIndex;
     501             : 
     502           0 :         const SmNode *pTree = pDoc->GetFormulaTree();
     503           0 :         const SmNode *pNode = pTree->FindNodeWithAccessibleIndex( nIndex );
     504             :         //! pNode may be 0 if the index belongs to a char that was inserted
     505             :         //! only for the accessible text!
     506           0 :         if (pNode)
     507             :         {
     508           0 :             sal_Int32 nAccIndex = pNode->GetAccessibleIndex();
     509             :             OSL_ENSURE( nAccIndex >= 0, "invalid accessible index" );
     510             :             OSL_ENSURE( nIndex >= nAccIndex, "index out of range" );
     511             : 
     512           0 :             OUStringBuffer aBuf;
     513           0 :             pNode->GetAccessibleText(aBuf);
     514           0 :             OUString aNodeText = aBuf.makeStringAndClear();
     515           0 :             sal_Int32 nNodeIndex = nIndex - nAccIndex;
     516           0 :             if (0 <= nNodeIndex  &&  nNodeIndex < aNodeText.getLength())
     517             :             {
     518             :                 // get appropriate rectangle
     519           0 :                 Point aOffset(pNode->GetTopLeft() - pTree->GetTopLeft());
     520           0 :                 Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
     521           0 :                 aTLPos.X() -= 0;
     522           0 :                 Size  aSize (pNode->GetSize());
     523             : 
     524           0 :                 long* pXAry = new long[ aNodeText.getLength() ];
     525           0 :                 pWin->SetFont( pNode->GetFont() );
     526           0 :                 pWin->GetTextArray( aNodeText, pXAry, 0, aNodeText.getLength() );
     527           0 :                 aTLPos.X()    += nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0;
     528           0 :                 aSize.Width()  = nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex];
     529           0 :                 delete[] pXAry;
     530             : 
     531           0 :                 aTLPos = pWin->LogicToPixel( aTLPos );
     532           0 :                 aSize  = pWin->LogicToPixel( aSize );
     533           0 :                 aRes.X = aTLPos.X();
     534           0 :                 aRes.Y = aTLPos.Y();
     535           0 :                 aRes.Width  = aSize.Width();
     536           0 :                 aRes.Height = aSize.Height();
     537           0 :             }
     538             :         }
     539             : 
     540             :         // take rectangle from last character and move it to the right
     541           0 :         if (bWasBehindText)
     542           0 :             aRes.X += aRes.Width;
     543             :     }
     544             : 
     545           0 :     return aRes;
     546             : }
     547             : 
     548           0 : sal_Int32 SAL_CALL SmGraphicAccessible::getCharacterCount()
     549             :     throw (RuntimeException, std::exception)
     550             : {
     551           0 :     SolarMutexGuard aGuard;
     552           0 :     return GetAccessibleText_Impl().getLength();
     553             : }
     554             : 
     555           0 : sal_Int32 SAL_CALL SmGraphicAccessible::getIndexAtPoint( const awt::Point& aPoint )
     556             :     throw (RuntimeException, std::exception)
     557             : {
     558           0 :     SolarMutexGuard aGuard;
     559             : 
     560           0 :     sal_Int32 nRes = -1;
     561           0 :     if (pWin)
     562             :     {
     563           0 :         const SmNode *pTree = pWin->GetView()->GetDoc()->GetFormulaTree();
     564             :         // can be NULL! e.g. if one clicks within the window already during loading of the
     565             :         // document (before the parser even started)
     566           0 :         if (!pTree)
     567           0 :             return nRes;
     568             : 
     569             :         // get position relative to formula draw position
     570           0 :         Point  aPos( aPoint.X, aPoint.Y );
     571           0 :         aPos = pWin->PixelToLogic( aPos );
     572           0 :         aPos -= pWin->GetFormulaDrawPos();
     573             : 
     574             :         // if it was inside the formula then get the appropriate node
     575           0 :         const SmNode *pNode = 0;
     576           0 :         if (pTree->OrientedDist(aPos) <= 0)
     577           0 :             pNode = pTree->FindRectClosestTo(aPos);
     578             : 
     579           0 :         if (pNode)
     580             :         {
     581             :             // get appropriate rectangle
     582           0 :             Point   aOffset( pNode->GetTopLeft() - pTree->GetTopLeft() );
     583           0 :             Point   aTLPos ( aOffset );
     584           0 :             aTLPos.X() -= 0;
     585           0 :             Size  aSize( pNode->GetSize() );
     586             : 
     587           0 :             Rectangle aRect( aTLPos, aSize );
     588           0 :             if (aRect.IsInside( aPos ))
     589             :             {
     590             :                 OSL_ENSURE( pNode->IsVisible(), "node is not a leaf" );
     591           0 :                 OUStringBuffer aBuf;
     592           0 :                 pNode->GetAccessibleText(aBuf);
     593           0 :                 OUString aTxt = aBuf.makeStringAndClear();
     594             :                 OSL_ENSURE( !aTxt.isEmpty(), "no accessible text available" );
     595             : 
     596           0 :                 long nNodeX = pNode->GetLeft();
     597             : 
     598           0 :                 long* pXAry = new long[ aTxt.getLength() ];
     599           0 :                 pWin->SetFont( pNode->GetFont() );
     600           0 :                 pWin->GetTextArray( aTxt, pXAry, 0, aTxt.getLength() );
     601           0 :                 for (sal_Int32 i = 0;  i < aTxt.getLength()  &&  nRes == -1;  ++i)
     602             :                 {
     603           0 :                     if (pXAry[i] + nNodeX > aPos.X())
     604           0 :                         nRes = i;
     605             :                 }
     606           0 :                 delete[] pXAry;
     607             :                 OSL_ENSURE( nRes >= 0  &&  nRes < aTxt.getLength(), "index out of range" );
     608             :                 OSL_ENSURE( pNode->GetAccessibleIndex() >= 0,
     609             :                         "invalid accessible index" );
     610             : 
     611           0 :                 nRes = pNode->GetAccessibleIndex() + nRes;
     612             :             }
     613             :         }
     614             :     }
     615           0 :     return nRes;
     616             : }
     617             : 
     618           0 : OUString SAL_CALL SmGraphicAccessible::getSelectedText()
     619             :     throw (RuntimeException, std::exception)
     620             : {
     621           0 :     SolarMutexGuard aGuard;
     622           0 :     return OUString();
     623             : }
     624             : 
     625           0 : sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionStart()
     626             :     throw (RuntimeException, std::exception)
     627             : {
     628           0 :     SolarMutexGuard aGuard;
     629           0 :     return -1;
     630             : }
     631             : 
     632           0 : sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionEnd()
     633             :     throw (RuntimeException, std::exception)
     634             : {
     635           0 :     SolarMutexGuard aGuard;
     636           0 :     return -1;
     637             : }
     638             : 
     639           0 : sal_Bool SAL_CALL SmGraphicAccessible::setSelection(
     640             :         sal_Int32 nStartIndex,
     641             :         sal_Int32 nEndIndex )
     642             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     643             : {
     644           0 :     SolarMutexGuard aGuard;
     645           0 :     sal_Int32 nLen = GetAccessibleText_Impl().getLength();
     646           0 :     if (!(0 <= nStartIndex  &&  nStartIndex < nLen) ||
     647           0 :         !(0 <= nEndIndex    &&  nEndIndex   < nLen))
     648           0 :         throw IndexOutOfBoundsException();
     649           0 :     return sal_False;
     650             : }
     651             : 
     652           0 : OUString SAL_CALL SmGraphicAccessible::getText()
     653             :     throw (RuntimeException, std::exception)
     654             : {
     655           0 :     SolarMutexGuard aGuard;
     656           0 :     return GetAccessibleText_Impl();
     657             : }
     658             : 
     659           0 : OUString SAL_CALL SmGraphicAccessible::getTextRange(
     660             :         sal_Int32 nStartIndex,
     661             :         sal_Int32 nEndIndex )
     662             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     663             : {
     664             :     //!! nEndIndex may be the string length per definition of the interface !!
     665             :     //!! text should be copied exclusive that end index though. And arguments
     666             :     //!! may be switched.
     667             : 
     668           0 :     SolarMutexGuard aGuard;
     669           0 :     OUString aTxt( GetAccessibleText_Impl() );
     670           0 :     sal_Int32 nStart = std::min(nStartIndex, nEndIndex);
     671           0 :     sal_Int32 nEnd   = std::max(nStartIndex, nEndIndex);
     672           0 :     if (!(nStart <= aTxt.getLength()) ||
     673           0 :         !(nEnd   <= aTxt.getLength()))
     674           0 :         throw IndexOutOfBoundsException();
     675           0 :     return aTxt.copy( nStart, nEnd - nStart );
     676             : }
     677             : 
     678           0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     679             : {
     680           0 :     SolarMutexGuard aGuard;
     681           0 :     OUString aTxt( GetAccessibleText_Impl() );
     682             :     //!! nIndex is allowed to be the string length
     683           0 :     if (!(nIndex <= aTxt.getLength()))
     684           0 :         throw IndexOutOfBoundsException();
     685             : 
     686           0 :     ::com::sun::star::accessibility::TextSegment aResult;
     687           0 :     aResult.SegmentStart = -1;
     688           0 :     aResult.SegmentEnd = -1;
     689           0 :     if ( (AccessibleTextType::CHARACTER == aTextType)  &&  (nIndex < aTxt.getLength()) )
     690             :     {
     691           0 :         aResult.SegmentText = aTxt.copy(nIndex, 1);
     692           0 :         aResult.SegmentStart = nIndex;
     693           0 :         aResult.SegmentEnd = nIndex+1;
     694             :     }
     695           0 :     return aResult;
     696             : }
     697             : 
     698           0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     699             : {
     700           0 :     SolarMutexGuard aGuard;
     701           0 :     OUString aTxt( GetAccessibleText_Impl() );
     702             :     //!! nIndex is allowed to be the string length
     703           0 :     if (!(nIndex <= aTxt.getLength()))
     704           0 :         throw IndexOutOfBoundsException();
     705             : 
     706           0 :     ::com::sun::star::accessibility::TextSegment aResult;
     707           0 :     aResult.SegmentStart = -1;
     708           0 :     aResult.SegmentEnd = -1;
     709             : 
     710           0 :     if ( (AccessibleTextType::CHARACTER == aTextType)  && nIndex )
     711             :     {
     712           0 :         aResult.SegmentText = aTxt.copy(nIndex-1, 1);
     713           0 :         aResult.SegmentStart = nIndex-1;
     714           0 :         aResult.SegmentEnd = nIndex;
     715             :     }
     716           0 :     return aResult;
     717             : }
     718             : 
     719           0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     720             : {
     721           0 :     SolarMutexGuard aGuard;
     722           0 :     OUString aTxt( GetAccessibleText_Impl() );
     723             :     //!! nIndex is allowed to be the string length
     724           0 :     if (!(nIndex <= aTxt.getLength()))
     725           0 :         throw IndexOutOfBoundsException();
     726             : 
     727           0 :     ::com::sun::star::accessibility::TextSegment aResult;
     728           0 :     aResult.SegmentStart = -1;
     729           0 :     aResult.SegmentEnd = -1;
     730             : 
     731           0 :     nIndex++; // text *behind*
     732           0 :     if ( (AccessibleTextType::CHARACTER == aTextType)  &&  (nIndex < aTxt.getLength()) )
     733             :     {
     734           0 :         aResult.SegmentText = aTxt.copy(nIndex, 1);
     735           0 :         aResult.SegmentStart = nIndex;
     736           0 :         aResult.SegmentEnd = nIndex+1;
     737             :     }
     738           0 :     return aResult;
     739             : }
     740             : 
     741           0 : sal_Bool SAL_CALL SmGraphicAccessible::copyText(
     742             :         sal_Int32 nStartIndex,
     743             :         sal_Int32 nEndIndex )
     744             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     745             : {
     746           0 :     SolarMutexGuard aGuard;
     747           0 :     bool bReturn = false;
     748             : 
     749           0 :     if (!pWin)
     750           0 :         throw RuntimeException();
     751             :     else
     752             :     {
     753           0 :         Reference< datatransfer::clipboard::XClipboard > xClipboard = pWin->GetClipboard();
     754           0 :         if ( xClipboard.is() )
     755             :         {
     756           0 :             OUString sText( getTextRange(nStartIndex, nEndIndex) );
     757             : 
     758           0 :             vcl::unohelper::TextDataObject* pDataObj = new vcl::unohelper::TextDataObject( sText );
     759           0 :             SolarMutexReleaser aReleaser;
     760           0 :             xClipboard->setContents( pDataObj, NULL );
     761             : 
     762           0 :             Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
     763           0 :             if( xFlushableClipboard.is() )
     764           0 :                 xFlushableClipboard->flushClipboard();
     765             : 
     766           0 :             bReturn = true;
     767           0 :         }
     768             :     }
     769             : 
     770           0 :     return bReturn;
     771             : }
     772             : 
     773           2 : OUString SAL_CALL SmGraphicAccessible::getImplementationName()
     774             :     throw (RuntimeException, std::exception)
     775             : {
     776           2 :     return OUString("SmGraphicAccessible");
     777             : }
     778             : 
     779           0 : sal_Bool SAL_CALL SmGraphicAccessible::supportsService(
     780             :         const OUString& rServiceName )
     781             :     throw (RuntimeException, std::exception)
     782             : {
     783           0 :     return  cppu::supportsService(this, rServiceName);
     784             : }
     785             : 
     786           0 : Sequence< OUString > SAL_CALL SmGraphicAccessible::getSupportedServiceNames()
     787             :     throw (RuntimeException, std::exception)
     788             : {
     789             :     return Sequence< OUString >{
     790             :         "com::sun::star::accessibility::Accessible",
     791             :         "com::sun::star::accessibility::AccessibleComponent",
     792             :         "com::sun::star::accessibility::AccessibleContext",
     793             :         "com::sun::star::accessibility::AccessibleText"
     794           0 :     };
     795             : }
     796             : 
     797             : 
     798             : 
     799             : 
     800             : 
     801           2 : SmEditSource::SmEditSource( SmEditWindow * /*pWin*/, SmEditAccessible &rAcc ) :
     802             :     aViewFwd    (rAcc),
     803             :     aTextFwd    (rAcc, *this),
     804             :     aEditViewFwd(rAcc),
     805           2 :     rEditAcc (rAcc)
     806             : {
     807           2 : }
     808             : 
     809           0 : SmEditSource::SmEditSource( const SmEditSource &rSrc ) :
     810             :     SvxEditSource(),
     811             :     aViewFwd    (rSrc.rEditAcc),
     812             :     aTextFwd    (rSrc.rEditAcc, *this),
     813             :     aEditViewFwd(rSrc.rEditAcc),
     814           0 :     rEditAcc    (rSrc.rEditAcc)
     815             : {
     816           0 : }
     817             : 
     818           4 : SmEditSource::~SmEditSource()
     819             : {
     820           4 : }
     821             : 
     822           0 : SvxEditSource* SmEditSource::Clone() const
     823             : {
     824           0 :     return new SmEditSource( *this );
     825             : }
     826             : 
     827          80 : SvxTextForwarder* SmEditSource::GetTextForwarder()
     828             : {
     829          80 :     return &aTextFwd;
     830             : }
     831             : 
     832          12 : SvxViewForwarder* SmEditSource::GetViewForwarder()
     833             : {
     834          12 :     return &aViewFwd;
     835             : }
     836             : 
     837          13 : SvxEditViewForwarder* SmEditSource::GetEditViewForwarder( bool /*bCreate*/ )
     838             : {
     839          13 :     return &aEditViewFwd;
     840             : }
     841             : 
     842           0 : void SmEditSource::UpdateData()
     843             : {
     844             :     // would possibly only by needed if the XText interface is implemented
     845             :     // and its text needs to be updated.
     846           0 : }
     847             : 
     848          17 : SfxBroadcaster & SmEditSource::GetBroadcaster() const
     849             : {
     850          17 :     return const_cast<SmEditSource*>(this)->aBroadCaster;
     851             : }
     852             : 
     853           2 : SmViewForwarder::SmViewForwarder( SmEditAccessible &rAcc ) :
     854           2 :     rEditAcc(rAcc)
     855             : {
     856           2 : }
     857             : 
     858           2 : SmViewForwarder::~SmViewForwarder()
     859             : {
     860           2 : }
     861             : 
     862          12 : bool SmViewForwarder::IsValid() const
     863             : {
     864          12 :     return rEditAcc.GetEditView() != 0;
     865             : }
     866             : 
     867           5 : Rectangle SmViewForwarder::GetVisArea() const
     868             : {
     869           5 :     EditView *pEditView = rEditAcc.GetEditView();
     870           5 :     OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
     871             : 
     872           5 :     if( pOutDev && pEditView)
     873             :     {
     874           5 :         Rectangle aVisArea = pEditView->GetVisArea();
     875             : 
     876             :         // figure out map mode from edit engine
     877           5 :         EditEngine* pEditEngine = pEditView->GetEditEngine();
     878             : 
     879           5 :         if( pEditEngine )
     880             :         {
     881           5 :             MapMode aMapMode(pOutDev->GetMapMode());
     882             :             aVisArea = OutputDevice::LogicToLogic( aVisArea,
     883             :                                                    pEditEngine->GetRefMapMode(),
     884           5 :                                                    aMapMode.GetMapUnit() );
     885           5 :             aMapMode.SetOrigin(Point());
     886           5 :             return pOutDev->LogicToPixel( aVisArea, aMapMode );
     887             :         }
     888             :     }
     889             : 
     890           0 :     return Rectangle();
     891             : }
     892             : 
     893          20 : Point SmViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
     894             : {
     895          20 :     EditView *pEditView = rEditAcc.GetEditView();
     896          20 :     OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
     897             : 
     898          20 :     if( pOutDev )
     899             :     {
     900          20 :         MapMode aMapMode(pOutDev->GetMapMode());
     901             :         Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
     902          20 :                                                   aMapMode.GetMapUnit() ) );
     903          20 :         aMapMode.SetOrigin(Point());
     904          20 :         return pOutDev->LogicToPixel( aPoint, aMapMode );
     905             :     }
     906             : 
     907           0 :     return Point();
     908             : }
     909             : 
     910           2 : Point SmViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
     911             : {
     912           2 :     EditView *pEditView = rEditAcc.GetEditView();
     913           2 :     OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
     914             : 
     915           2 :     if( pOutDev )
     916             :     {
     917           2 :         MapMode aMapMode(pOutDev->GetMapMode());
     918           2 :         aMapMode.SetOrigin(Point());
     919           2 :         Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) );
     920             :         return OutputDevice::LogicToLogic( aPoint,
     921             :                                            aMapMode.GetMapUnit(),
     922           2 :                                            rMapMode );
     923             :     }
     924             : 
     925           0 :     return Point();
     926             : }
     927             : 
     928             : 
     929             : 
     930             : 
     931           2 : SmTextForwarder::SmTextForwarder( SmEditAccessible& rAcc, SmEditSource & rSource) :
     932             :     rEditAcc ( rAcc ),
     933           2 :     rEditSource (rSource)
     934             : {
     935           2 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     936           2 :     if (pEditEngine)
     937           2 :         pEditEngine->SetNotifyHdl( LINK(this, SmTextForwarder, NotifyHdl) );
     938           2 : }
     939             : 
     940           4 : SmTextForwarder::~SmTextForwarder()
     941             : {
     942           2 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     943           2 :     if (pEditEngine)
     944           0 :         pEditEngine->SetNotifyHdl( Link<>() );
     945           2 : }
     946             : 
     947          26 : IMPL_LINK(SmTextForwarder, NotifyHdl, EENotify*, aNotify)
     948             : {
     949          13 :     if (aNotify)
     950             :     {
     951          13 :         ::std::unique_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
     952          13 :         if (aHint.get())
     953          13 :             rEditSource.GetBroadcaster().Broadcast( *aHint.get() );
     954             :     }
     955             : 
     956          13 :     return 0;
     957             : }
     958             : 
     959          26 : sal_Int32 SmTextForwarder::GetParagraphCount() const
     960             : {
     961          26 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     962          26 :     return pEditEngine ? pEditEngine->GetParagraphCount() : 0;
     963             : }
     964             : 
     965          12 : sal_Int32 SmTextForwarder::GetTextLen( sal_Int32 nParagraph ) const
     966             : {
     967          12 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     968          12 :     return pEditEngine ? pEditEngine->GetTextLen( nParagraph ) : 0;
     969             : }
     970             : 
     971          16 : OUString SmTextForwarder::GetText( const ESelection& rSel ) const
     972             : {
     973          16 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     974          16 :     OUString aRet;
     975          16 :     if (pEditEngine)
     976          16 :         aRet = pEditEngine->GetText( rSel, LINEEND_LF );
     977          16 :     return convertLineEnd(aRet, GetSystemLineEnd());
     978             : }
     979             : 
     980           0 : SfxItemSet SmTextForwarder::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib ) const
     981             : {
     982           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     983             :     OSL_ENSURE( pEditEngine, "EditEngine missing" );
     984           0 :     if( rSel.nStartPara == rSel.nEndPara )
     985             :     {
     986           0 :         GetAttribsFlags nFlags = GetAttribsFlags::NONE;
     987           0 :         switch( nOnlyHardAttrib )
     988             :         {
     989             :         case EditEngineAttribs_All:
     990           0 :             nFlags = GetAttribsFlags::ALL;
     991           0 :             break;
     992             :         case EditEngineAttribs_HardAndPara:
     993           0 :             nFlags = GetAttribsFlags::PARAATTRIBS|GetAttribsFlags::CHARATTRIBS;
     994           0 :             break;
     995             :         case EditEngineAttribs_OnlyHard:
     996           0 :             nFlags = GetAttribsFlags::CHARATTRIBS;
     997           0 :             break;
     998             :         default:
     999             :             SAL_WARN("starmath", "unknown flags for SmTextForwarder::GetAttribs");
    1000             :         }
    1001             : 
    1002           0 :         return pEditEngine->GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags );
    1003             :     }
    1004             :     else
    1005             :     {
    1006           0 :         return pEditEngine->GetAttribs( rSel, nOnlyHardAttrib );
    1007             :     }
    1008             : }
    1009             : 
    1010           0 : SfxItemSet SmTextForwarder::GetParaAttribs( sal_Int32 nPara ) const
    1011             : {
    1012           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1013             :     OSL_ENSURE( pEditEngine, "EditEngine missing" );
    1014             : 
    1015           0 :     SfxItemSet aSet( pEditEngine->GetParaAttribs( nPara ) );
    1016             : 
    1017           0 :     sal_uInt16 nWhich = EE_PARA_START;
    1018           0 :     while( nWhich <= EE_PARA_END )
    1019             :     {
    1020           0 :         if( aSet.GetItemState( nWhich, true ) != SfxItemState::SET )
    1021             :         {
    1022           0 :             if( pEditEngine->HasParaAttrib( nPara, nWhich ) )
    1023           0 :                 aSet.Put( pEditEngine->GetParaAttrib( nPara, nWhich ) );
    1024             :         }
    1025           0 :         nWhich++;
    1026             :     }
    1027             : 
    1028           0 :     return aSet;
    1029             : }
    1030             : 
    1031           0 : void SmTextForwarder::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
    1032             : {
    1033           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1034           0 :     if (pEditEngine)
    1035           0 :         pEditEngine->SetParaAttribs( nPara, rSet );
    1036           0 : }
    1037             : 
    1038           0 : SfxItemPool* SmTextForwarder::GetPool() const
    1039             : {
    1040           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1041           0 :     return pEditEngine ? pEditEngine->GetEmptyItemSet().GetPool() : 0;
    1042             : }
    1043             : 
    1044           0 : void SmTextForwarder::RemoveAttribs( const ESelection& rSelection, bool bRemoveParaAttribs, sal_uInt16 nWhich )
    1045             : {
    1046           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1047           0 :     if (pEditEngine)
    1048           0 :         pEditEngine->RemoveAttribs( rSelection, bRemoveParaAttribs, nWhich );
    1049           0 : }
    1050             : 
    1051           0 : void SmTextForwarder::GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const
    1052             : {
    1053           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1054           0 :     if (pEditEngine)
    1055           0 :         pEditEngine->GetPortions( nPara, rList );
    1056           0 : }
    1057             : 
    1058           0 : void SmTextForwarder::QuickInsertText( const OUString& rText, const ESelection& rSel )
    1059             : {
    1060           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1061           0 :     if (pEditEngine)
    1062           0 :         pEditEngine->QuickInsertText( rText, rSel );
    1063           0 : }
    1064             : 
    1065           0 : void SmTextForwarder::QuickInsertLineBreak( const ESelection& rSel )
    1066             : {
    1067           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1068           0 :     if (pEditEngine)
    1069           0 :         pEditEngine->QuickInsertLineBreak( rSel );
    1070           0 : }
    1071             : 
    1072           0 : void SmTextForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
    1073             : {
    1074           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1075           0 :     if (pEditEngine)
    1076           0 :         pEditEngine->QuickInsertField( rFld, rSel );
    1077           0 : }
    1078             : 
    1079           0 : void SmTextForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
    1080             : {
    1081           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1082           0 :     if (pEditEngine)
    1083           0 :         pEditEngine->QuickSetAttribs( rSet, rSel );
    1084           0 : }
    1085             : 
    1086          67 : bool SmTextForwarder::IsValid() const
    1087             : {
    1088          67 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1089             :     // cannot reliably query EditEngine state
    1090             :     // while in the middle of an update
    1091          67 :     return pEditEngine && pEditEngine->GetUpdateMode();
    1092             : }
    1093             : 
    1094           0 : OUString SmTextForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
    1095             : {
    1096           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1097           0 :     return pEditEngine ? pEditEngine->CalcFieldValue(rField, nPara, nPos, rpTxtColor, rpFldColor) : OUString();
    1098             : }
    1099             : 
    1100           0 : void SmTextForwarder::FieldClicked(const SvxFieldItem&, sal_Int32, sal_Int32)
    1101             : {
    1102           0 : }
    1103             : 
    1104           0 : static SfxItemState GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, sal_uInt16 nWhich )
    1105             : {
    1106           0 :     std::vector<EECharAttrib> aAttribs;
    1107             : 
    1108           0 :     const SfxPoolItem*  pLastItem = NULL;
    1109             : 
    1110           0 :     SfxItemState eState = SfxItemState::DEFAULT;
    1111             : 
    1112             :     // check all paragraphs inside the selection
    1113           0 :     for( sal_Int32 nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++ )
    1114             :     {
    1115           0 :         SfxItemState eParaState = SfxItemState::DEFAULT;
    1116             : 
    1117             :         // calculate start and endpos for this paragraph
    1118           0 :         sal_Int32 nPos = 0;
    1119           0 :         if( rSel.nStartPara == nPara )
    1120           0 :             nPos = rSel.nStartPos;
    1121             : 
    1122           0 :         sal_Int32 nEndPos = rSel.nEndPos;
    1123           0 :         if( rSel.nEndPara != nPara )
    1124           0 :             nEndPos = rEditEngine.GetTextLen( nPara );
    1125             : 
    1126             : 
    1127             :         // get list of char attribs
    1128           0 :         rEditEngine.GetCharAttribs( nPara, aAttribs );
    1129             : 
    1130           0 :         bool bEmpty = true;     // we found no item inside the selection of this paragraph
    1131           0 :         bool bGaps  = false;    // we found items but theire gaps between them
    1132           0 :         sal_Int32 nLastEnd = nPos;
    1133             : 
    1134           0 :         const SfxPoolItem* pParaItem = NULL;
    1135             : 
    1136           0 :         for(std::vector<EECharAttrib>::const_iterator i = aAttribs.begin(); i < aAttribs.end(); ++i)
    1137             :         {
    1138             :             OSL_ENSURE( i->pAttr, "GetCharAttribs gives corrupt data" );
    1139             : 
    1140           0 :             const bool bEmptyPortion = (i->nStart == i->nEnd);
    1141           0 :             if( (!bEmptyPortion && (i->nStart >= nEndPos)) || (bEmptyPortion && (i->nStart > nEndPos)) )
    1142           0 :                 break;  // break if we are already behind our selection
    1143             : 
    1144           0 :             if( (!bEmptyPortion && (i->nEnd <= nPos)) || (bEmptyPortion && (i->nEnd < nPos)) )
    1145           0 :                 continue;   // or if the attribute ends before our selection
    1146             : 
    1147           0 :             if( i->pAttr->Which() != nWhich )
    1148           0 :                 continue; // skip if is not the searched item
    1149             : 
    1150             :             // if we already found an item
    1151           0 :             if( pParaItem )
    1152             :             {
    1153             :                 // ... and its different to this one than the state is dont care
    1154           0 :                 if( *pParaItem != *(i->pAttr) )
    1155           0 :                     return SfxItemState::DONTCARE;
    1156             :             }
    1157             :             else
    1158             :             {
    1159           0 :                 pParaItem = i->pAttr;
    1160             :             }
    1161             : 
    1162           0 :             if( bEmpty )
    1163           0 :                 bEmpty = false;
    1164             : 
    1165           0 :             if( !bGaps && i->nStart > nLastEnd )
    1166           0 :                 bGaps = true;
    1167             : 
    1168           0 :             nLastEnd = i->nEnd;
    1169             :         }
    1170             : 
    1171           0 :         if( !bEmpty && !bGaps && nLastEnd < ( nEndPos - 1 ) )
    1172           0 :             bGaps = true;
    1173           0 :         if( bEmpty )
    1174           0 :             eParaState = SfxItemState::DEFAULT;
    1175           0 :         else if( bGaps )
    1176           0 :             eParaState = SfxItemState::DONTCARE;
    1177             :         else
    1178           0 :             eParaState = SfxItemState::SET;
    1179             : 
    1180             :         // if we already found an item check if we found the same
    1181           0 :         if( pLastItem )
    1182             :         {
    1183           0 :             if( (pParaItem == NULL) || (*pLastItem != *pParaItem) )
    1184           0 :                 return SfxItemState::DONTCARE;
    1185             :         }
    1186             :         else
    1187             :         {
    1188           0 :             pLastItem = pParaItem;
    1189           0 :             eState = eParaState;
    1190             :         }
    1191             :     }
    1192             : 
    1193           0 :     return eState;
    1194             : }
    1195             : 
    1196           0 : SfxItemState SmTextForwarder::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const
    1197             : {
    1198           0 :     SfxItemState nState = SfxItemState::DISABLED;
    1199           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1200           0 :     if (pEditEngine)
    1201           0 :         nState = GetSvxEditEngineItemState( *pEditEngine, rSel, nWhich );
    1202           0 :     return nState;
    1203             : }
    1204             : 
    1205           0 : SfxItemState SmTextForwarder::GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const
    1206             : {
    1207           0 :     SfxItemState nState = SfxItemState::DISABLED;
    1208           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1209           0 :     if (pEditEngine)
    1210             :     {
    1211           0 :         const SfxItemSet& rSet = pEditEngine->GetParaAttribs( nPara );
    1212           0 :         nState = rSet.GetItemState( nWhich );
    1213             :     }
    1214           0 :     return nState;
    1215             : }
    1216             : 
    1217           0 : LanguageType SmTextForwarder::GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const
    1218             : {
    1219           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1220           0 :     return pEditEngine ? pEditEngine->GetLanguage(nPara, nIndex) : LANGUAGE_NONE;
    1221             : }
    1222             : 
    1223          54 : sal_Int32 SmTextForwarder::GetFieldCount( sal_Int32 nPara ) const
    1224             : {
    1225          54 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1226          54 :     return pEditEngine ? pEditEngine->GetFieldCount(nPara) : 0;
    1227             : }
    1228             : 
    1229           0 : EFieldInfo SmTextForwarder::GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const
    1230             : {
    1231           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1232           0 :     return pEditEngine ? pEditEngine->GetFieldInfo( nPara, nField ) : EFieldInfo();
    1233             : }
    1234             : 
    1235         104 : EBulletInfo SmTextForwarder::GetBulletInfo( sal_Int32 /*nPara*/ ) const
    1236             : {
    1237         104 :     return EBulletInfo();
    1238             : }
    1239             : 
    1240           0 : Rectangle SmTextForwarder::GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const
    1241             : {
    1242           0 :     Rectangle aRect(0,0,0,0);
    1243           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1244             : 
    1245           0 :     if (pEditEngine)
    1246             :     {
    1247             :         // Handle virtual position one-past-the end of the string
    1248           0 :         if( nIndex >= pEditEngine->GetTextLen(nPara) )
    1249             :         {
    1250           0 :             if( nIndex )
    1251           0 :                 aRect = pEditEngine->GetCharacterBounds( EPosition(nPara, nIndex-1) );
    1252             : 
    1253           0 :             aRect.Move( aRect.Right() - aRect.Left(), 0 );
    1254           0 :             aRect.SetSize( Size(1, pEditEngine->GetTextHeight()) );
    1255             :         }
    1256             :         else
    1257             :         {
    1258           0 :             aRect = pEditEngine->GetCharacterBounds( EPosition(nPara, nIndex) );
    1259             :         }
    1260             :     }
    1261           0 :     return aRect;
    1262             : }
    1263             : 
    1264          12 : Rectangle SmTextForwarder::GetParaBounds( sal_Int32 nPara ) const
    1265             : {
    1266          12 :     Rectangle aRect(0,0,0,0);
    1267          12 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1268             : 
    1269          12 :     if (pEditEngine)
    1270             :     {
    1271          12 :         const Point aPnt = pEditEngine->GetDocPosTopLeft( nPara );
    1272          12 :         const sal_uLong nWidth = pEditEngine->CalcTextWidth();
    1273          12 :         const sal_uLong nHeight = pEditEngine->GetTextHeight( nPara );
    1274          12 :         aRect = Rectangle( aPnt.X(), aPnt.Y(), aPnt.X() + nWidth, aPnt.Y() + nHeight );
    1275             :     }
    1276             : 
    1277          12 :     return aRect;
    1278             : }
    1279             : 
    1280          12 : MapMode SmTextForwarder::GetMapMode() const
    1281             : {
    1282          12 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1283          12 :     return pEditEngine ? pEditEngine->GetRefMapMode() : MapMode( MAP_100TH_MM );
    1284             : }
    1285             : 
    1286           0 : OutputDevice* SmTextForwarder::GetRefDevice() const
    1287             : {
    1288           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1289           0 :     return pEditEngine ? pEditEngine->GetRefDevice() : 0;
    1290             : }
    1291             : 
    1292           0 : bool SmTextForwarder::GetIndexAtPoint( const Point& rPos, sal_Int32& nPara, sal_Int32& nIndex ) const
    1293             : {
    1294           0 :     bool bRes = false;
    1295           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1296           0 :     if (pEditEngine)
    1297             :     {
    1298           0 :         EPosition aDocPos = pEditEngine->FindDocPosition( rPos );
    1299           0 :         nPara   = aDocPos.nPara;
    1300           0 :         nIndex  = aDocPos.nIndex;
    1301           0 :         bRes = true;
    1302             :     }
    1303           0 :     return bRes;
    1304             : }
    1305             : 
    1306           0 : bool SmTextForwarder::GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd ) const
    1307             : {
    1308           0 :     bool bRes = false;
    1309           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1310           0 :     if (pEditEngine)
    1311             :     {
    1312           0 :         ESelection aRes = pEditEngine->GetWord( ESelection(nPara, nIndex, nPara, nIndex), com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1313             : 
    1314           0 :         if( aRes.nStartPara == nPara &&
    1315           0 :             aRes.nStartPara == aRes.nEndPara )
    1316             :         {
    1317           0 :             nStart = aRes.nStartPos;
    1318           0 :             nEnd = aRes.nEndPos;
    1319             : 
    1320           0 :             bRes = true;
    1321             :         }
    1322             :     }
    1323             : 
    1324           0 :     return bRes;
    1325             : }
    1326             : 
    1327           0 : bool SmTextForwarder::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell ) const
    1328             : {
    1329           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1330           0 :     return pEditEngine &&
    1331           0 :            SvxEditSourceHelper::GetAttributeRun( nStartIndex, nEndIndex, *pEditEngine, nPara, nIndex, bInCell );
    1332             : }
    1333             : 
    1334           4 : sal_Int32 SmTextForwarder::GetLineCount( sal_Int32 nPara ) const
    1335             : {
    1336           4 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1337           4 :     return pEditEngine ? pEditEngine->GetLineCount(nPara) : 0;
    1338             : }
    1339             : 
    1340           4 : sal_Int32 SmTextForwarder::GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const
    1341             : {
    1342           4 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1343           4 :     return pEditEngine ? pEditEngine->GetLineLen(nPara, nLine) : 0;
    1344             : }
    1345             : 
    1346           0 : void SmTextForwarder::GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nPara, sal_Int32 nLine ) const
    1347             : {
    1348           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1349           0 :     if (pEditEngine)
    1350           0 :         pEditEngine->GetLineBoundaries(rStart, rEnd, nPara, nLine);
    1351             :     else
    1352           0 :         rStart = rEnd = 0;
    1353           0 : }
    1354             : 
    1355           0 : sal_Int32 SmTextForwarder::GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const
    1356             : {
    1357           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1358           0 :     return pEditEngine ? pEditEngine->GetLineNumberAtIndex(nPara, nIndex) : 0;
    1359             : }
    1360             : 
    1361           0 : bool SmTextForwarder::QuickFormatDoc( bool /*bFull*/ )
    1362             : {
    1363           0 :     bool bRes = false;
    1364           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1365           0 :     if (pEditEngine)
    1366             :     {
    1367           0 :         pEditEngine->QuickFormatDoc();
    1368           0 :         bRes = true;
    1369             :     }
    1370           0 :     return bRes;
    1371             : }
    1372             : 
    1373           0 : sal_Int16 SmTextForwarder::GetDepth( sal_Int32 /*nPara*/ ) const
    1374             : {
    1375             :     // math has no outliner...
    1376           0 :     return -1;
    1377             : }
    1378             : 
    1379           0 : bool SmTextForwarder::SetDepth( sal_Int32 /*nPara*/, sal_Int16 nNewDepth )
    1380             : {
    1381             :     // math has no outliner...
    1382           0 :     return -1 == nNewDepth;  // is it the value from 'GetDepth' ?
    1383             : }
    1384             : 
    1385           0 : bool SmTextForwarder::Delete( const ESelection& rSelection )
    1386             : {
    1387           0 :     bool bRes = false;
    1388           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1389           0 :     if (pEditEngine)
    1390             :     {
    1391           0 :         pEditEngine->QuickDelete( rSelection );
    1392           0 :         pEditEngine->QuickFormatDoc();
    1393           0 :         bRes = true;
    1394             :     }
    1395           0 :     return bRes;
    1396             : }
    1397             : 
    1398           0 : bool SmTextForwarder::InsertText( const OUString& rStr, const ESelection& rSelection )
    1399             : {
    1400           0 :     bool bRes = false;
    1401           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1402           0 :     if (pEditEngine)
    1403             :     {
    1404           0 :         pEditEngine->QuickInsertText( rStr, rSelection );
    1405           0 :         pEditEngine->QuickFormatDoc();
    1406           0 :         bRes = true;
    1407             :     }
    1408           0 :     return bRes;
    1409             : }
    1410             : 
    1411           0 : const SfxItemSet*   SmTextForwarder::GetEmptyItemSetPtr()
    1412             : {
    1413           0 :     const SfxItemSet *pItemSet = 0;
    1414           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1415           0 :     if (pEditEngine)
    1416             :     {
    1417           0 :         pItemSet = &pEditEngine->GetEmptyItemSet();
    1418             :     }
    1419           0 :     return pItemSet;
    1420             : }
    1421             : 
    1422           0 : void SmTextForwarder::AppendParagraph()
    1423             : {
    1424             :     // append an empty paragraph
    1425           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1426           0 :     if (pEditEngine)
    1427             :     {
    1428           0 :         sal_Int32 nParaCount = pEditEngine->GetParagraphCount();
    1429           0 :         pEditEngine->InsertParagraph( nParaCount, OUString() );
    1430             :     }
    1431           0 : }
    1432             : 
    1433           0 : sal_Int32 SmTextForwarder::AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet &rSet )
    1434             : {
    1435           0 :     sal_uInt16 nRes = 0;
    1436           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1437           0 :     if (pEditEngine && nPara < pEditEngine->GetParagraphCount())
    1438             :     {
    1439             :         // append text
    1440           0 :         ESelection aSel( nPara, pEditEngine->GetTextLen( nPara ) );
    1441           0 :         pEditEngine->QuickInsertText( rText, aSel );
    1442             : 
    1443             :         // set attributes for new appended text
    1444           0 :         nRes = aSel.nEndPos = pEditEngine->GetTextLen( nPara );
    1445           0 :         pEditEngine->QuickSetAttribs( rSet, aSel );
    1446             :     }
    1447           0 :     return nRes;
    1448             : }
    1449             : 
    1450           0 : void SmTextForwarder::CopyText(const SvxTextForwarder& rSource)
    1451             : {
    1452             : 
    1453           0 :     const SmTextForwarder* pSourceForwarder = dynamic_cast< const SmTextForwarder* >( &rSource );
    1454           0 :     if( !pSourceForwarder )
    1455           0 :         return;
    1456           0 :     EditEngine* pSourceEditEngine = pSourceForwarder->rEditAcc.GetEditEngine();
    1457           0 :     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
    1458           0 :     if (pEditEngine && pSourceEditEngine )
    1459             :     {
    1460           0 :         EditTextObject* pNewTextObject = pSourceEditEngine->CreateTextObject();
    1461           0 :         pEditEngine->SetText( *pNewTextObject );
    1462           0 :         delete pNewTextObject;
    1463             :     }
    1464             : }
    1465             : 
    1466             : 
    1467             : 
    1468           2 : SmEditViewForwarder::SmEditViewForwarder( SmEditAccessible& rAcc ) :
    1469           2 :     rEditAcc( rAcc )
    1470             : {
    1471           2 : }
    1472             : 
    1473           2 : SmEditViewForwarder::~SmEditViewForwarder()
    1474             : {
    1475           2 : }
    1476             : 
    1477          13 : bool SmEditViewForwarder::IsValid() const
    1478             : {
    1479          13 :     return rEditAcc.GetEditView() != 0;
    1480             : }
    1481             : 
    1482           5 : Rectangle SmEditViewForwarder::GetVisArea() const
    1483             : {
    1484           5 :     Rectangle aRect(0,0,0,0);
    1485             : 
    1486           5 :     EditView *pEditView = rEditAcc.GetEditView();
    1487           5 :     OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
    1488             : 
    1489           5 :     if( pOutDev && pEditView)
    1490             :     {
    1491           5 :         Rectangle aVisArea = pEditView->GetVisArea();
    1492             : 
    1493             :         // figure out map mode from edit engine
    1494           5 :         EditEngine* pEditEngine = pEditView->GetEditEngine();
    1495             : 
    1496           5 :         if( pEditEngine )
    1497             :         {
    1498           5 :             MapMode aMapMode(pOutDev->GetMapMode());
    1499             :             aVisArea = OutputDevice::LogicToLogic( aVisArea,
    1500             :                                                    pEditEngine->GetRefMapMode(),
    1501           5 :                                                    aMapMode.GetMapUnit() );
    1502           5 :             aMapMode.SetOrigin(Point());
    1503           5 :             aRect = pOutDev->LogicToPixel( aVisArea, aMapMode );
    1504             :         }
    1505             :     }
    1506             : 
    1507           5 :     return aRect;
    1508             : }
    1509             : 
    1510           0 : Point SmEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
    1511             : {
    1512           0 :     EditView *pEditView = rEditAcc.GetEditView();
    1513           0 :     OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
    1514             : 
    1515           0 :     if( pOutDev )
    1516             :     {
    1517           0 :         MapMode aMapMode(pOutDev->GetMapMode());
    1518             :         Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
    1519           0 :                                                   aMapMode.GetMapUnit() ) );
    1520           0 :         aMapMode.SetOrigin(Point());
    1521           0 :         return pOutDev->LogicToPixel( aPoint, aMapMode );
    1522             :     }
    1523             : 
    1524           0 :     return Point();
    1525             : }
    1526             : 
    1527           0 : Point SmEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
    1528             : {
    1529           0 :     EditView *pEditView = rEditAcc.GetEditView();
    1530           0 :     OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
    1531             : 
    1532           0 :     if( pOutDev )
    1533             :     {
    1534           0 :         MapMode aMapMode(pOutDev->GetMapMode());
    1535           0 :         aMapMode.SetOrigin(Point());
    1536           0 :         Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) );
    1537             :         return OutputDevice::LogicToLogic( aPoint,
    1538             :                                            aMapMode.GetMapUnit(),
    1539           0 :                                            rMapMode );
    1540             :     }
    1541             : 
    1542           0 :     return Point();
    1543             : }
    1544             : 
    1545           3 : bool SmEditViewForwarder::GetSelection( ESelection& rSelection ) const
    1546             : {
    1547           3 :     bool bRes = false;
    1548           3 :     EditView *pEditView = rEditAcc.GetEditView();
    1549           3 :     if (pEditView)
    1550             :     {
    1551           3 :         rSelection = pEditView->GetSelection();
    1552           3 :         bRes = true;
    1553             :     }
    1554           3 :     return bRes;
    1555             : }
    1556             : 
    1557           0 : bool SmEditViewForwarder::SetSelection( const ESelection& rSelection )
    1558             : {
    1559           0 :     bool bRes = false;
    1560           0 :     EditView *pEditView = rEditAcc.GetEditView();
    1561           0 :     if (pEditView)
    1562             :     {
    1563           0 :         pEditView->SetSelection( rSelection );
    1564           0 :         bRes = true;
    1565             :     }
    1566           0 :     return bRes;
    1567             : }
    1568             : 
    1569           0 : bool SmEditViewForwarder::Copy()
    1570             : {
    1571           0 :     bool bRes = false;
    1572           0 :     EditView *pEditView = rEditAcc.GetEditView();
    1573           0 :     if (pEditView)
    1574             :     {
    1575           0 :         pEditView->Copy();
    1576           0 :         bRes = true;
    1577             :     }
    1578           0 :     return bRes;
    1579             : }
    1580             : 
    1581           0 : bool SmEditViewForwarder::Cut()
    1582             : {
    1583           0 :     bool bRes = false;
    1584           0 :     EditView *pEditView = rEditAcc.GetEditView();
    1585           0 :     if (pEditView)
    1586             :     {
    1587           0 :         pEditView->Cut();
    1588           0 :         bRes = true;
    1589             :     }
    1590           0 :     return bRes;
    1591             : }
    1592             : 
    1593           0 : bool SmEditViewForwarder::Paste()
    1594             : {
    1595           0 :     bool bRes = false;
    1596           0 :     EditView *pEditView = rEditAcc.GetEditView();
    1597           0 :     if (pEditView)
    1598             :     {
    1599           0 :         pEditView->Paste();
    1600           0 :         bRes = true;
    1601             :     }
    1602           0 :     return bRes;
    1603             : }
    1604             : 
    1605             : 
    1606             : 
    1607           2 : SmEditAccessible::SmEditAccessible( SmEditWindow *pEditWin ) :
    1608             :     aAccName            (SM_RESSTR(STR_CMDBOXWINDOW)),
    1609             :     pTextHelper         (0),
    1610           2 :     pWin                (pEditWin)
    1611             : {
    1612             :     OSL_ENSURE( pWin, "SmEditAccessible: window missing" );
    1613           2 : }
    1614             : 
    1615           6 : SmEditAccessible::~SmEditAccessible()
    1616             : {
    1617           2 :     delete pTextHelper;
    1618           4 : }
    1619             : 
    1620           2 : void SmEditAccessible::Init()
    1621             : {
    1622             :     OSL_ENSURE( pWin, "SmEditAccessible: window missing" );
    1623           2 :     if (pWin)
    1624             :     {
    1625           2 :         EditEngine *pEditEngine = pWin->GetEditEngine();
    1626           2 :         EditView   *pEditView   = pWin->GetEditView();
    1627           2 :         if (pEditEngine && pEditView)
    1628             :         {
    1629             :             ::std::unique_ptr< SvxEditSource > pEditSource(
    1630           2 :                     new SmEditSource( pWin, *this ) );
    1631           2 :             pTextHelper = new ::accessibility::AccessibleTextHelper( std::move(pEditSource) );
    1632           2 :             pTextHelper->SetEventSource( this );
    1633             :         }
    1634             :     }
    1635           2 : }
    1636             : 
    1637           2 : void SmEditAccessible::ClearWin()
    1638             : {
    1639             :     // remove handler before current object gets destroyed
    1640             :     // (avoid handler being called for already dead object)
    1641           2 :     EditEngine *pEditEngine = GetEditEngine();
    1642           2 :     if (pEditEngine)
    1643           2 :         pEditEngine->SetNotifyHdl( Link<>() );
    1644             : 
    1645           2 :     pWin = 0;   // implicitly results in AccessibleStateType::DEFUNC set
    1646             : 
    1647             :     //! make TextHelper implicitly release C++ references to some core objects
    1648           2 :     pTextHelper->SetEditSource( ::std::unique_ptr<SvxEditSource>() );
    1649             :     //! make TextHelper release references
    1650             :     //! (e.g. the one set by the 'SetEventSource' call)
    1651           2 :     pTextHelper->Dispose();
    1652           2 :     delete pTextHelper;     pTextHelper = 0;
    1653           2 : }
    1654             : 
    1655             : // XAccessible
    1656          15 : uno::Reference< XAccessibleContext > SAL_CALL SmEditAccessible::getAccessibleContext(  )
    1657             :     throw (RuntimeException, std::exception)
    1658             : {
    1659          15 :     SolarMutexGuard aGuard;
    1660          15 :     return this;
    1661             : }
    1662             : 
    1663             : // XAccessibleComponent
    1664        1244 : sal_Bool SAL_CALL SmEditAccessible::containsPoint( const awt::Point& aPoint )
    1665             :     throw (RuntimeException, std::exception)
    1666             : {
    1667             :     //! the arguments coordinates are relativ to the current window !
    1668             :     //! Thus the top left-point is (0, 0)
    1669             : 
    1670        1244 :     SolarMutexGuard aGuard;
    1671        1244 :     if (!pWin)
    1672           0 :         throw RuntimeException();
    1673             : 
    1674        1244 :     Size aSz( pWin->GetSizePixel() );
    1675        2967 :     return  aPoint.X >= 0  &&  aPoint.Y >= 0  &&
    1676        2347 :             aPoint.X < aSz.Width()  &&  aPoint.Y < aSz.Height();
    1677             : }
    1678             : 
    1679           2 : uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleAtPoint( const awt::Point& aPoint )
    1680             :     throw (RuntimeException, std::exception)
    1681             : {
    1682           2 :     SolarMutexGuard aGuard;
    1683           2 :     if (!pTextHelper)
    1684           0 :         throw RuntimeException();
    1685           2 :     return pTextHelper->GetAt( aPoint );
    1686             : }
    1687             : 
    1688           1 : awt::Rectangle SAL_CALL SmEditAccessible::getBounds(  )
    1689             :     throw (RuntimeException, std::exception)
    1690             : {
    1691           1 :     SolarMutexGuard aGuard;
    1692           1 :     if (!pWin)
    1693           0 :         throw RuntimeException();
    1694             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
    1695             :             "mismatch of window parent and accessible parent" );
    1696           1 :     return lcl_GetBounds( pWin );
    1697             : }
    1698             : 
    1699           1 : awt::Point SAL_CALL SmEditAccessible::getLocation(  )
    1700             :     throw (RuntimeException, std::exception)
    1701             : {
    1702           1 :     SolarMutexGuard aGuard;
    1703           1 :     if (!pWin)
    1704           0 :         throw RuntimeException();
    1705             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
    1706             :             "mismatch of window parent and accessible parent" );
    1707           1 :     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
    1708           1 :     return awt::Point( aRect.X, aRect.Y );
    1709             : }
    1710             : 
    1711           1 : awt::Point SAL_CALL SmEditAccessible::getLocationOnScreen(  )
    1712             :     throw (RuntimeException, std::exception)
    1713             : {
    1714           1 :     SolarMutexGuard aGuard;
    1715           1 :     if (!pWin)
    1716           0 :         throw RuntimeException();
    1717             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
    1718             :             "mismatch of window parent and accessible parent" );
    1719           1 :     return lcl_GetLocationOnScreen( pWin );
    1720             : }
    1721             : 
    1722           1 : awt::Size SAL_CALL SmEditAccessible::getSize(  )
    1723             :     throw (RuntimeException, std::exception)
    1724             : {
    1725           1 :     SolarMutexGuard aGuard;
    1726           1 :     if (!pWin)
    1727           0 :         throw RuntimeException();
    1728             :     OSL_ENSURE(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
    1729             :             "mismatch of window parent and accessible parent" );
    1730             : 
    1731           1 :     Size aSz( pWin->GetSizePixel() );
    1732             : #if OSL_DEBUG_LEVEL > 1
    1733             :     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
    1734             :     Size aSz2( aRect.Width, aRect.Height );
    1735             :     OSL_ENSURE( aSz == aSz2, "mismatch in width" );
    1736             : #endif
    1737           1 :     return awt::Size( aSz.Width(), aSz.Height() );
    1738             : }
    1739             : 
    1740           1 : void SAL_CALL SmEditAccessible::grabFocus(  )
    1741             :     throw (RuntimeException, std::exception)
    1742             : {
    1743           1 :     SolarMutexGuard aGuard;
    1744           1 :     if (!pWin)
    1745           0 :         throw RuntimeException();
    1746             : 
    1747           1 :     pWin->GrabFocus();
    1748           1 : }
    1749             : 
    1750           1 : sal_Int32 SAL_CALL SmEditAccessible::getForeground()
    1751             :     throw (RuntimeException, std::exception)
    1752             : {
    1753           1 :     SolarMutexGuard aGuard;
    1754             : 
    1755           1 :     if (!pWin)
    1756           0 :         throw RuntimeException();
    1757           1 :     return (sal_Int32) pWin->GetTextColor().GetColor();
    1758             : }
    1759             : 
    1760           1 : sal_Int32 SAL_CALL SmEditAccessible::getBackground()
    1761             :     throw (RuntimeException, std::exception)
    1762             : {
    1763           1 :     SolarMutexGuard aGuard;
    1764             : 
    1765           1 :     if (!pWin)
    1766           0 :         throw RuntimeException();
    1767           2 :     Wallpaper aWall( pWin->GetDisplayBackground() );
    1768             :     ColorData nCol;
    1769           1 :     if (aWall.IsBitmap() || aWall.IsGradient())
    1770           0 :         nCol = pWin->GetSettings().GetStyleSettings().GetWindowColor().GetColor();
    1771             :     else
    1772           1 :         nCol = aWall.GetColor().GetColor();
    1773           2 :     return (sal_Int32) nCol;
    1774             : }
    1775             : 
    1776             : // XAccessibleContext
    1777           8 : sal_Int32 SAL_CALL SmEditAccessible::getAccessibleChildCount(  )
    1778             :     throw (RuntimeException, std::exception)
    1779             : {
    1780           8 :     SolarMutexGuard aGuard;
    1781           8 :     if (!pTextHelper)
    1782           0 :         throw RuntimeException();
    1783           8 :     return pTextHelper->GetChildCount();
    1784             : }
    1785             : 
    1786           2 : uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleChild( sal_Int32 i )
    1787             :     throw (IndexOutOfBoundsException, RuntimeException, std::exception)
    1788             : {
    1789           2 :     SolarMutexGuard aGuard;
    1790           2 :     if (!pTextHelper)
    1791           0 :         throw RuntimeException();
    1792           2 :     return pTextHelper->GetChild( i );
    1793             : }
    1794             : 
    1795           8 : uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleParent(  )
    1796             :     throw (RuntimeException, std::exception)
    1797             : {
    1798           8 :     SolarMutexGuard aGuard;
    1799           8 :     if (!pWin)
    1800           0 :         throw RuntimeException();
    1801             : 
    1802           8 :     vcl::Window *pAccParent = pWin->GetAccessibleParentWindow();
    1803             :     OSL_ENSURE( pAccParent, "accessible parent missing" );
    1804           8 :     return pAccParent ? pAccParent->GetAccessible() : Reference< XAccessible >();
    1805             : }
    1806             : 
    1807           1 : sal_Int32 SAL_CALL SmEditAccessible::getAccessibleIndexInParent(  )
    1808             :     throw (RuntimeException, std::exception)
    1809             : {
    1810           1 :     SolarMutexGuard aGuard;
    1811           1 :     sal_Int32 nIdx = -1;
    1812           1 :     vcl::Window *pAccParent = pWin ? pWin->GetAccessibleParentWindow() : 0;
    1813           1 :     if (pAccParent)
    1814             :     {
    1815           1 :         sal_uInt16 nCnt = pAccParent->GetAccessibleChildWindowCount();
    1816           2 :         for (sal_uInt16 i = 0;  i < nCnt  &&  nIdx == -1;  ++i)
    1817           1 :             if (pAccParent->GetAccessibleChildWindow( i ) == pWin)
    1818           1 :                 nIdx = i;
    1819             :     }
    1820           1 :     return nIdx;
    1821             : }
    1822             : 
    1823           9 : sal_Int16 SAL_CALL SmEditAccessible::getAccessibleRole(  )
    1824             :     throw (RuntimeException, std::exception)
    1825             : {
    1826           9 :     SolarMutexGuard aGuard;
    1827           9 :     return AccessibleRole::PANEL /*TEXT ?*/;
    1828             : }
    1829             : 
    1830           7 : OUString SAL_CALL SmEditAccessible::getAccessibleDescription(  )
    1831             :     throw (RuntimeException, std::exception)
    1832             : {
    1833           7 :     SolarMutexGuard aGuard;
    1834           7 :     return OUString();  // empty as agreed with product-management
    1835             : }
    1836             : 
    1837           9 : OUString SAL_CALL SmEditAccessible::getAccessibleName(  )
    1838             :     throw (RuntimeException, std::exception)
    1839             : {
    1840           9 :     SolarMutexGuard aGuard;
    1841             :     // same name as displayed by the window when not docked
    1842           9 :     return aAccName;
    1843             : }
    1844             : 
    1845           1 : uno::Reference< XAccessibleRelationSet > SAL_CALL SmEditAccessible::getAccessibleRelationSet(  )
    1846             :     throw (RuntimeException, std::exception)
    1847             : {
    1848           1 :     SolarMutexGuard aGuard;
    1849           1 :     Reference< XAccessibleRelationSet > xRelSet = new utl::AccessibleRelationSetHelper();
    1850           1 :     return xRelSet;   // empty relation set
    1851             : }
    1852             : 
    1853           4 : uno::Reference< XAccessibleStateSet > SAL_CALL SmEditAccessible::getAccessibleStateSet(  )
    1854             :     throw (RuntimeException, std::exception)
    1855             : {
    1856           4 :     SolarMutexGuard aGuard;
    1857             :     ::utl::AccessibleStateSetHelper *pStateSet =
    1858           4 :             new ::utl::AccessibleStateSetHelper;
    1859             : 
    1860           4 :     Reference<XAccessibleStateSet> xStateSet( pStateSet );
    1861             : 
    1862           4 :     if (!pWin || !pTextHelper)
    1863           0 :         pStateSet->AddState( AccessibleStateType::DEFUNC );
    1864             :     else
    1865             :     {
    1866           4 :         pStateSet->AddState( AccessibleStateType::MULTI_LINE );
    1867           4 :         pStateSet->AddState( AccessibleStateType::ENABLED );
    1868           4 :         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
    1869           4 :         if (pWin->HasFocus())
    1870           4 :             pStateSet->AddState( AccessibleStateType::FOCUSED );
    1871           4 :         if (pWin->IsActive())
    1872           0 :             pStateSet->AddState( AccessibleStateType::ACTIVE );
    1873           4 :         if (pWin->IsVisible())
    1874           4 :             pStateSet->AddState( AccessibleStateType::SHOWING );
    1875           4 :         if (pWin->IsReallyVisible())
    1876           4 :             pStateSet->AddState( AccessibleStateType::VISIBLE );
    1877           4 :         if (COL_TRANSPARENT != pWin->GetBackground().GetColor().GetColor())
    1878           4 :             pStateSet->AddState( AccessibleStateType::OPAQUE );
    1879             :     }
    1880             : 
    1881           4 :     return xStateSet;
    1882             : }
    1883             : 
    1884           1 : Locale SAL_CALL SmEditAccessible::getLocale(  )
    1885             :     throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
    1886             : {
    1887           1 :     SolarMutexGuard aGuard;
    1888             :     // should be the document language...
    1889             :     // We use the language of the localized symbol names here.
    1890           1 :     return Application::GetSettings().GetUILanguageTag().getLocale();
    1891             : }
    1892             : 
    1893             : 
    1894             : // XAccessibleEventBroadcaster
    1895           0 : void SAL_CALL SmEditAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
    1896             :     throw (RuntimeException, std::exception)
    1897             : {
    1898           0 :     if (pTextHelper)   // not disposing (about to destroy view shell)
    1899           0 :         pTextHelper->AddEventListener( xListener );
    1900           0 : }
    1901             : 
    1902           0 : void SAL_CALL SmEditAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
    1903             :     throw (RuntimeException, std::exception)
    1904             : {
    1905           0 :    if (pTextHelper)   // not disposing (about to destroy view shell)
    1906           0 :         pTextHelper->RemoveEventListener( xListener );
    1907           0 : }
    1908             : 
    1909           4 : OUString SAL_CALL SmEditAccessible::getImplementationName()
    1910             :     throw (RuntimeException, std::exception)
    1911             : {
    1912           4 :     return OUString("SmEditAccessible");
    1913             : }
    1914             : 
    1915           0 : sal_Bool SAL_CALL SmEditAccessible::supportsService(
    1916             :         const OUString& rServiceName )
    1917             :     throw (RuntimeException, std::exception)
    1918             : {
    1919           0 :     return  cppu::supportsService(this, rServiceName);
    1920             : }
    1921             : 
    1922           0 : Sequence< OUString > SAL_CALL SmEditAccessible::getSupportedServiceNames()
    1923             :     throw (RuntimeException, std::exception)
    1924             : {
    1925             :     return Sequence< OUString >{
    1926             :         "com::sun::star::accessibility::Accessible",
    1927             :         "com::sun::star::accessibility::AccessibleComponent",
    1928             :         "com::sun::star::accessibility::AccessibleContext"
    1929           0 :     };
    1930          42 : }
    1931             : 
    1932             : 
    1933             : 
    1934             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11