/Users/ericb/Desktop/SRC680_m247/starmath/source/accessibility.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: accessibility.cxx,v $
00006  *
00007  *  $Revision: 1.33 $
00008  *
00009  *  last change: $Author: obo $ $Date: 2007/07/18 12:51:10 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 
00036 // MARKER(update_precomp.py): autogen include statement, do not remove
00037 #include "precompiled_starmath.hxx"
00038 
00039 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
00040 #include <com/sun/star/accessibility/AccessibleRole.hpp>
00041 #endif
00042 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
00043 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
00044 #endif
00045 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLETEXTTYPE_HPP_
00046 #include <com/sun/star/accessibility/AccessibleTextType.hpp>
00047 #endif
00048 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEEVENTLISTENER_HPP_
00049 #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
00050 #endif
00051 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTOBJECT_HPP_
00052 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
00053 #endif
00054 #ifndef _COM_SUN_STAR_AWT_FOCUSEVENT_HPP_
00055 #include <com/sun/star/awt/FocusEvent.hpp>
00056 #endif
00057 #ifndef _COM_SUN_STAR_AWT_XFOCUSLISTENER_HPP_
00058 #include <com/sun/star/awt/XFocusListener.hpp>
00059 #endif
00060 #ifndef _UTL_ACCESSIBLERELATIONSETHELPER_HXX_
00061 #include <unotools/accessiblerelationsethelper.hxx>
00062 #endif
00063 
00064 
00065 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARD_HPP_
00066 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
00067 #endif
00068 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XFLUSHABLECLIPBOARD_HPP_
00069 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
00070 #endif
00071 
00072 #ifndef _COM_SUN_STAR_I18N_WORDTYPE_HPP_
00073 #include <com/sun/star/i18n/WordType.hpp>
00074 #endif
00075 
00076 #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
00077 #include <unotools/accessiblestatesethelper.hxx>
00078 #endif
00079 #ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
00080 #include <comphelper/accessibleeventnotifier.hxx>
00081 #endif
00082 #ifndef _TOOLS_DEBUG_HXX
00083 #include <tools/debug.hxx>
00084 #endif
00085 #ifndef _SV_SVAPP_HXX
00086 #include <vcl/svapp.hxx>
00087 #endif
00088 #ifndef _SV_WINDOW_HXX
00089 #include <vcl/window.hxx>
00090 #endif
00091 #ifndef _VCL_UNOHELP2_HXX
00092 #include <vcl/unohelp2.hxx>
00093 #endif
00094 #ifndef _SV_GEN_HXX
00095 #include <tools/gen.hxx>
00096 #endif
00097 #ifndef _VOS_MUTEX_HXX_
00098 #include <vos/mutex.hxx>
00099 #endif
00100 #ifndef _SFXITEMSET_HXX
00101 #include <svtools/itemset.hxx>
00102 #endif
00103 
00104 #include <svx/editdata.hxx>
00105 #ifndef _MyEDITVIEW_HXX
00106 #include <svx/editview.hxx>
00107 #endif
00108 #ifndef _EEITEM_HXX
00109 #include <svx/eeitem.hxx>
00110 #endif
00111 #ifndef _OUTLINER_HXX
00112 #include <svx/outliner.hxx>
00113 #endif
00114 #ifndef _SVX_UNOEDHLP_HXX
00115 #include <svx/unoedhlp.hxx>
00116 #endif
00117 
00118 
00119 #ifndef _ACCESSIBILITY_HXX_
00120 #include "accessibility.hxx"
00121 #endif
00122 #ifndef APPLICAT_HXX
00123 #include <applicat.hxx>
00124 #endif
00125 #ifndef DOCUMENT_HXX
00126 #include <document.hxx>
00127 #endif
00128 #ifndef VIEW_HXX
00129 #include <view.hxx>
00130 #endif
00131 
00132 using namespace rtl;
00133 using namespace com::sun::star;
00134 using namespace com::sun::star::lang;
00135 using namespace com::sun::star::uno;
00136 using namespace com::sun::star::accessibility;
00137 
00138 #define C2U(cChar)  rtl::OUString::createFromAscii(cChar)
00139 
00141 
00142 static awt::Rectangle lcl_GetBounds( Window *pWin )
00143 {
00144     // !! see VCLXAccessibleComponent::implGetBounds()
00145 
00148 
00149     awt::Rectangle aBounds;
00150     if (pWin)
00151     {
00152         Rectangle aRect = pWin->GetWindowExtentsRelative( NULL );
00153         aBounds.X       = aRect.Left();
00154         aBounds.Y       = aRect.Top();
00155         aBounds.Width   = aRect.GetWidth();
00156         aBounds.Height  = aRect.GetHeight();
00157         Window* pParent = pWin->GetAccessibleParentWindow();
00158         if (pParent)
00159         {
00160             Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
00161             awt::Point aParentScreenLoc( aParentRect.Left(), aParentRect.Top() );
00162             aBounds.X -= aParentScreenLoc.X;
00163             aBounds.Y -= aParentScreenLoc.Y;
00164         }
00165     }
00166     return aBounds;
00167 }
00168 
00169 static awt::Point lcl_GetLocationOnScreen( Window *pWin )
00170 {
00171     // !! see VCLXAccessibleComponent::getLocationOnScreen()
00172 
00173     awt::Point aPos;
00174     if (pWin)
00175     {
00176         Rectangle aRect = pWin->GetWindowExtentsRelative( NULL );
00177         aPos.X = aRect.Left();
00178         aPos.Y = aRect.Top();
00179     }
00180     return aPos;
00181 }
00182 
00184 
00185 SmGraphicAccessible::SmGraphicAccessible( SmGraphicWindow *pGraphicWin ) :
00186     aAccName            ( String(SmResId(RID_DOCUMENTSTR)) ),
00187     nClientId           (0),
00188     pWin                (pGraphicWin)
00189 {
00190     DBG_ASSERT( pWin, "SmGraphicAccessible: window missing" );
00191     //++aRefCount;
00192 }
00193 
00194 
00195 SmGraphicAccessible::SmGraphicAccessible( const SmGraphicAccessible &rSmAcc ) :
00196     SmGraphicAccessibleBaseClass(),
00197     aAccName            ( String(SmResId(RID_DOCUMENTSTR)) ),
00198     nClientId           (0)
00199 {
00200     //vos::OGuard aGuard(Application::GetSolarMutex());
00201     pWin = rSmAcc.pWin;
00202     DBG_ASSERT( pWin, "SmGraphicAccessible: window missing" );
00203     //++aRefCount;
00204 }
00205 
00206 
00207 SmGraphicAccessible::~SmGraphicAccessible()
00208 {
00209 /*
00210         vos::OGuard aGuard(Application::GetSolarMutex());
00211     if (--aRefCount == 0)
00212     {
00213     }
00214 */
00215 }
00216 
00217 
00218 SmDocShell * SmGraphicAccessible::GetDoc_Impl()
00219 {
00220     SmViewShell *pView = pWin ? pWin->GetView() : 0;
00221     return pView ? pView->GetDoc() : 0;
00222 }
00223 
00224 String SmGraphicAccessible::GetAccessibleText_Impl()
00225 {
00226     String aTxt;
00227     SmDocShell *pDoc = GetDoc_Impl();
00228     if (pDoc)
00229         aTxt = pDoc->GetAccessibleText();
00230     return aTxt;
00231 }
00232 
00233 void SmGraphicAccessible::ClearWin()
00234 {
00235     pWin = 0;   // implicitly results in AccessibleStateType::DEFUNC set
00236 
00237         if ( nClientId )
00238         {
00239         comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, *this );
00240                 nClientId =  0;
00241         }
00242 }
00243 
00244 void SmGraphicAccessible::LaunchEvent(
00245         const sal_Int16 nAccesibleEventId,
00246         const uno::Any &rOldVal,
00247         const uno::Any &rNewVal)
00248 {
00249     AccessibleEventObject aEvt;
00250     aEvt.Source     = (XAccessible *) this;
00251     aEvt.EventId    = nAccesibleEventId;
00252     aEvt.OldValue   = rOldVal;
00253     aEvt.NewValue   = rNewVal ;
00254 
00255     // pass event on to event-listener's
00256         if (nClientId)
00257                 comphelper::AccessibleEventNotifier::addEvent( nClientId, aEvt );
00258 }
00259 
00260 uno::Reference< XAccessibleContext > SAL_CALL SmGraphicAccessible::getAccessibleContext()
00261     throw (RuntimeException)
00262 {
00263         vos::OGuard aGuard(Application::GetSolarMutex());
00264     return this;
00265 }
00266 
00267 sal_Bool SAL_CALL SmGraphicAccessible::containsPoint( const awt::Point& aPoint )
00268     throw (RuntimeException)
00269 {
00272 
00273         vos::OGuard aGuard(Application::GetSolarMutex());
00274     if (!pWin)
00275         throw RuntimeException();
00276 
00277     Size aSz( pWin->GetSizePixel() );
00278     return  aPoint.X >= 0  &&  aPoint.Y >= 0  &&
00279             aPoint.X < aSz.Width()  &&  aPoint.Y < aSz.Height();
00280 }
00281 
00282 uno::Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleAtPoint(
00283         const awt::Point& aPoint )
00284     throw (RuntimeException)
00285 {
00286         vos::OGuard aGuard(Application::GetSolarMutex());
00287     XAccessible *pRes = 0;
00288     if (containsPoint( aPoint ))
00289         pRes = this;
00290     return pRes;
00291 }
00292 
00293 awt::Rectangle SAL_CALL SmGraphicAccessible::getBounds()
00294     throw (RuntimeException)
00295 {
00296         vos::OGuard aGuard(Application::GetSolarMutex());
00297     if (!pWin)
00298         throw RuntimeException();
00299     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
00300             "mismatch of window parent and accessible parent" );
00301     return lcl_GetBounds( pWin );
00302 }
00303 
00304 awt::Point SAL_CALL SmGraphicAccessible::getLocation()
00305     throw (RuntimeException)
00306 {
00307         vos::OGuard aGuard(Application::GetSolarMutex());
00308     if (!pWin)
00309         throw RuntimeException();
00310     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
00311             "mismatch of window parent and accessible parent" );
00312     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
00313     return awt::Point( aRect.X, aRect.Y );
00314 }
00315 
00316 awt::Point SAL_CALL SmGraphicAccessible::getLocationOnScreen()
00317     throw (RuntimeException)
00318 {
00319         vos::OGuard aGuard(Application::GetSolarMutex());
00320     if (!pWin)
00321         throw RuntimeException();
00322     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
00323             "mismatch of window parent and accessible parent" );
00324     return lcl_GetLocationOnScreen( pWin );
00325 }
00326 
00327 awt::Size SAL_CALL SmGraphicAccessible::getSize()
00328     throw (RuntimeException)
00329 {
00330         vos::OGuard aGuard(Application::GetSolarMutex());
00331     if (!pWin)
00332         throw RuntimeException();
00333     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
00334             "mismatch of window parent and accessible parent" );
00335 
00336     Size aSz( pWin->GetSizePixel() );
00337 #if OSL_DEBUG_LEVEL > 1
00338     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
00339     Size aSz2( aRect.Width, aRect.Height );
00340     DBG_ASSERT( aSz == aSz2, "mismatch in width" );
00341 #endif
00342     return awt::Size( aSz.Width(), aSz.Height() );
00343 }
00344 
00345 void SAL_CALL SmGraphicAccessible::grabFocus()
00346     throw (RuntimeException)
00347 {
00348         vos::OGuard aGuard(Application::GetSolarMutex());
00349     if (!pWin)
00350         throw RuntimeException();
00351 
00352     pWin->GrabFocus();
00353 }
00354 
00355 sal_Int32 SAL_CALL SmGraphicAccessible::getForeground()
00356     throw (RuntimeException)
00357 {
00358     vos::OGuard aGuard(Application::GetSolarMutex());
00359 
00360     if (!pWin)
00361         throw RuntimeException();
00362     return (sal_Int32) pWin->GetTextColor().GetColor();
00363 }
00364 
00365 sal_Int32 SAL_CALL SmGraphicAccessible::getBackground()
00366     throw (RuntimeException)
00367 {
00368     vos::OGuard aGuard(Application::GetSolarMutex());
00369 
00370     if (!pWin)
00371         throw RuntimeException();
00372     Wallpaper aWall( pWin->GetDisplayBackground() );
00373     ColorData nCol;
00374     if (aWall.IsBitmap() || aWall.IsGradient())
00375         nCol = pWin->GetSettings().GetStyleSettings().GetWindowColor().GetColor();
00376     else
00377         nCol = aWall.GetColor().GetColor();
00378     return (sal_Int32) nCol;
00379 }
00380 
00381 sal_Int32 SAL_CALL SmGraphicAccessible::getAccessibleChildCount()
00382     throw (RuntimeException)
00383 {
00384         vos::OGuard aGuard(Application::GetSolarMutex());
00385     return 0;
00386 }
00387 
00388 Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleChild(
00389         sal_Int32 /*i*/ )
00390     throw (IndexOutOfBoundsException, RuntimeException)
00391 {
00392         vos::OGuard aGuard(Application::GetSolarMutex());
00393     throw IndexOutOfBoundsException();  // there is no child...
00394     /*return 0;*/
00395 }
00396 
00397 Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleParent()
00398     throw (RuntimeException)
00399 {
00400         vos::OGuard aGuard(Application::GetSolarMutex());
00401     if (!pWin)
00402         throw RuntimeException();
00403 
00404     Window *pAccParent = pWin->GetAccessibleParentWindow();
00405     DBG_ASSERT( pAccParent, "accessible parent missing" );
00406     return pAccParent ? pAccParent->GetAccessible() : Reference< XAccessible >();
00407 }
00408 
00409 sal_Int32 SAL_CALL SmGraphicAccessible::getAccessibleIndexInParent()
00410     throw (RuntimeException)
00411 {
00412         vos::OGuard aGuard(Application::GetSolarMutex());
00413     sal_Int32 nIdx = -1;
00414     Window *pAccParent = pWin ? pWin->GetAccessibleParentWindow() : 0;
00415     if (pAccParent)
00416     {
00417         USHORT nCnt = pAccParent->GetAccessibleChildWindowCount();
00418         for (USHORT i = 0;  i < nCnt  &&  nIdx == -1;  ++i)
00419             if (pAccParent->GetAccessibleChildWindow( i ) == pWin)
00420                 nIdx = i;
00421     }
00422     return nIdx;
00423 }
00424 
00425 sal_Int16 SAL_CALL SmGraphicAccessible::getAccessibleRole()
00426     throw (RuntimeException)
00427 {
00428         vos::OGuard aGuard(Application::GetSolarMutex());
00429     return AccessibleRole::DOCUMENT;
00430 }
00431 
00432 OUString SAL_CALL SmGraphicAccessible::getAccessibleDescription()
00433     throw (RuntimeException)
00434 {
00435         vos::OGuard aGuard(Application::GetSolarMutex());
00436     SmDocShell *pDoc = GetDoc_Impl();
00437     return pDoc ? OUString(pDoc->GetText()) : OUString();
00438 }
00439 
00440 OUString SAL_CALL SmGraphicAccessible::getAccessibleName()
00441     throw (RuntimeException)
00442 {
00443         vos::OGuard aGuard(Application::GetSolarMutex());
00444     return aAccName;
00445 }
00446 
00447 Reference< XAccessibleRelationSet > SAL_CALL SmGraphicAccessible::getAccessibleRelationSet()
00448     throw (RuntimeException)
00449 {
00450         vos::OGuard aGuard(Application::GetSolarMutex());
00451     Reference< XAccessibleRelationSet > xRelSet = new utl::AccessibleRelationSetHelper();
00452     return xRelSet;   // empty relation set
00453 }
00454 
00455 Reference< XAccessibleStateSet > SAL_CALL SmGraphicAccessible::getAccessibleStateSet()
00456     throw (RuntimeException)
00457 {
00458         vos::OGuard aGuard(Application::GetSolarMutex());
00459         ::utl::AccessibleStateSetHelper *pStateSet =
00460             new ::utl::AccessibleStateSetHelper;
00461 
00462         Reference<XAccessibleStateSet> xStateSet( pStateSet );
00463 
00464     if (!pWin)
00465         pStateSet->AddState( AccessibleStateType::DEFUNC );
00466     else
00467     {
00468         //pStateSet->AddState( AccessibleStateType::EDITABLE );
00469         //pStateSet->AddState( AccessibleStateType::HORIZONTAL );
00470         //pStateSet->AddState( AccessibleStateType::TRANSIENT );
00471         pStateSet->AddState( AccessibleStateType::ENABLED );
00472         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
00473         if (pWin->HasFocus())
00474             pStateSet->AddState( AccessibleStateType::FOCUSED );
00475         if (pWin->IsActive())
00476             pStateSet->AddState( AccessibleStateType::ACTIVE );
00477         if (pWin->IsVisible())
00478             pStateSet->AddState( AccessibleStateType::SHOWING );
00479         if (pWin->IsReallyVisible())
00480             pStateSet->AddState( AccessibleStateType::VISIBLE );
00481         if (COL_TRANSPARENT != pWin->GetBackground().GetColor().GetColor())
00482             pStateSet->AddState( AccessibleStateType::OPAQUE );
00483     }
00484 
00485         return xStateSet;
00486 }
00487 
00488 Locale SAL_CALL SmGraphicAccessible::getLocale()
00489     throw (IllegalAccessibleComponentStateException, RuntimeException)
00490 {
00491         vos::OGuard aGuard(Application::GetSolarMutex());
00492     // should be the document language...
00493     // We use the language of the localized symbol names here.
00494     return Application::GetSettings().GetUILocale();
00495 }
00496 
00497 
00498 void SAL_CALL SmGraphicAccessible::addEventListener(
00499         const Reference< XAccessibleEventListener >& xListener )
00500     throw (RuntimeException)
00501 {
00502         if (xListener.is())
00503     {
00504                 vos::OGuard aGuard(Application::GetSolarMutex());
00505                 if (pWin)
00506                 {
00507                         if (!nClientId)
00508                 nClientId = comphelper::AccessibleEventNotifier::registerClient( );
00509                         comphelper::AccessibleEventNotifier::addEventListener( nClientId, xListener );
00510                 }
00511     }
00512 }
00513 
00514 void SAL_CALL SmGraphicAccessible::removeEventListener(
00515         const Reference< XAccessibleEventListener >& xListener )
00516     throw (RuntimeException)
00517 {
00518         if (xListener.is())
00519         {
00520                 vos::OGuard aGuard(Application::GetSolarMutex());
00521                 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( nClientId, xListener );
00522                 if ( !nListenerCount )
00523                 {
00524                         // no listeners anymore
00525                         // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
00526                         // and at least to us not firing any events anymore, in case somebody calls
00527                         // NotifyAccessibleEvent, again
00528                         comphelper::AccessibleEventNotifier::revokeClient( nClientId );
00529                         nClientId = 0;
00530                 }
00531         }
00532 }
00533 
00534 sal_Int32 SAL_CALL SmGraphicAccessible::getCaretPosition()
00535     throw (RuntimeException)
00536 {
00537         vos::OGuard aGuard(Application::GetSolarMutex());
00538     return 0;
00539 }
00540 
00541 sal_Bool SAL_CALL SmGraphicAccessible::setCaretPosition( sal_Int32 nIndex )
00542     throw (IndexOutOfBoundsException, RuntimeException)
00543 {
00544     xub_StrLen nIdx = (xub_StrLen) nIndex;
00545     String aTxt( GetAccessibleText_Impl() );
00546     if (!(/*0 <= nIdx  &&*/  nIdx < aTxt.Len()))
00547         throw IndexOutOfBoundsException();
00548         return sal_False;
00549 }
00550 
00551 sal_Unicode SAL_CALL SmGraphicAccessible::getCharacter( sal_Int32 nIndex )
00552     throw (IndexOutOfBoundsException, RuntimeException)
00553 {
00554         vos::OGuard aGuard(Application::GetSolarMutex());
00555 
00556     xub_StrLen nIdx = (xub_StrLen) nIndex;
00557     String aTxt( GetAccessibleText_Impl() );
00558     if (!(/*0 <= nIdx  &&*/  nIdx < aTxt.Len()))
00559         throw IndexOutOfBoundsException();
00560     return aTxt.GetChar( nIdx );
00561 }
00562 
00563 Sequence< beans::PropertyValue > SAL_CALL SmGraphicAccessible::getCharacterAttributes(
00564         sal_Int32 nIndex, 
00565         const uno::Sequence< ::rtl::OUString > & /*rRequestedAttributes*/ )
00566     throw (IndexOutOfBoundsException, RuntimeException)
00567 {
00568         vos::OGuard aGuard(Application::GetSolarMutex());
00569     INT32 nLen = GetAccessibleText_Impl().Len();
00570     if (!(0 <= nIndex  &&  nIndex < nLen))
00571         throw IndexOutOfBoundsException();
00572     return Sequence< beans::PropertyValue >();
00573 }
00574 
00575 awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nIndex )
00576     throw (IndexOutOfBoundsException, RuntimeException)
00577 {
00578         vos::OGuard aGuard(Application::GetSolarMutex());
00579 
00580     awt::Rectangle aRes;
00581 
00582     if (!pWin)
00583         throw RuntimeException();
00584     else
00585     {
00586         // get accessible text
00587         SmViewShell *pView = pWin->GetView();
00588         SmDocShell  *pDoc  = pView ? pView->GetDoc() : 0;
00589         if (!pDoc)
00590             throw RuntimeException();
00591         String aTxt( GetAccessibleText_Impl() );
00592         if (!(0 <= nIndex  &&  nIndex <= aTxt.Len()))   // #108812# aTxt.Len() is valid
00593             throw IndexOutOfBoundsException();
00594 
00595         // #108812# find a reasonable rectangle for position aTxt.Len().
00596         bool bWasBehindText = (nIndex == aTxt.Len());
00597         if (bWasBehindText && nIndex)
00598             --nIndex;
00599 
00600         const SmNode *pTree = pDoc->GetFormulaTree();
00601         const SmNode *pNode = pTree->FindNodeWithAccessibleIndex( (xub_StrLen) nIndex );
00604         if (pNode)
00605         {
00606             sal_Int32 nAccIndex = pNode->GetAccessibleIndex();
00607             DBG_ASSERT( nAccIndex >= 0, "invalid accessible index" );
00608             DBG_ASSERT( nIndex >= nAccIndex, "index out of range" );
00609 
00610             String    aNodeText;
00611             pNode->GetAccessibleText( aNodeText );
00612             sal_Int32 nNodeIndex = nIndex - nAccIndex;
00613             if (0 <= nNodeIndex  &&  nNodeIndex < aNodeText.Len())
00614             {
00615                 // get appropriate rectangle
00616                 Point aOffset(pNode->GetTopLeft() - pTree->GetTopLeft());
00617                 Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
00618 //                aTLPos.X() -= pNode->GetItalicLeftSpace();
00619 //                Size  aSize (pNode->GetItalicSize());
00620                 aTLPos.X() -= 0;
00621                 Size  aSize (pNode->GetSize());
00622 
00623                 sal_Int32 *pXAry = new sal_Int32[ aNodeText.Len() ];
00624                 pWin->SetFont( pNode->GetFont() );
00625                 pWin->GetTextArray( aNodeText, pXAry, 0, aNodeText.Len() );
00626                 aTLPos.X()    += nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0;
00627                 aSize.Width()  = nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex];
00628                 delete[] pXAry;
00629 
00630 #if OSL_DEBUG_LEVEL > 1
00631     Point aLP00( pWin->LogicToPixel( Point(0,0)) );
00632     Point aPL00( pWin->PixelToLogic( Point(0,0)) );
00633 #endif
00634                 aTLPos = pWin->LogicToPixel( aTLPos );
00635                 aSize  = pWin->LogicToPixel( aSize );
00636                 aRes.X = aTLPos.X();
00637                 aRes.Y = aTLPos.Y();
00638                 aRes.Width  = aSize.Width();
00639                 aRes.Height = aSize.Height();
00640             }
00641         }
00642 
00643         // #108812# take rectangle from last character and move it to the right
00644         if (bWasBehindText)
00645             aRes.X += aRes.Width;
00646     }
00647 
00648     return aRes;
00649 }
00650 
00651 sal_Int32 SAL_CALL SmGraphicAccessible::getCharacterCount()
00652     throw (RuntimeException)
00653 {
00654         vos::OGuard aGuard(Application::GetSolarMutex());
00655     return GetAccessibleText_Impl().Len();
00656 }
00657 
00658 sal_Int32 SAL_CALL SmGraphicAccessible::getIndexAtPoint( const awt::Point& aPoint )
00659     throw (RuntimeException)
00660 {
00661         vos::OGuard aGuard(Application::GetSolarMutex());
00662 
00663     sal_Int32 nRes = -1;
00664     if (pWin)
00665     {
00666         const SmNode *pTree = pWin->GetView()->GetDoc()->GetFormulaTree();
00669                 if (!pTree)
00670             return nRes;
00671 
00672         // get position relativ to formula draw position
00673         Point  aPos( aPoint.X, aPoint.Y );
00674         aPos = pWin->PixelToLogic( aPos );
00675         aPos -= pWin->GetFormulaDrawPos();
00676 
00677         // if it was inside the formula then get the appropriate node
00678                 const SmNode *pNode = 0;
00679                 if (pTree->OrientedDist(aPos) <= 0)
00680                         pNode = pTree->FindRectClosestTo(aPos);
00681 
00682         if (pNode)
00683         {
00684             // get appropriate rectangle
00685             Point   aOffset( pNode->GetTopLeft() - pTree->GetTopLeft() );
00686             Point   aTLPos ( /*pWin->GetFormulaDrawPos() +*/ aOffset );
00687 //            aTLPos.X() -= pNode->GetItalicLeftSpace();
00688 //            Size  aSize( pNode->GetItalicSize() );
00689             aTLPos.X() -= 0;
00690             Size  aSize( pNode->GetSize() );
00691 #if OSL_DEBUG_LEVEL > 1
00692     Point aLP00( pWin->LogicToPixel( Point(0,0)) );
00693     Point aPL00( pWin->PixelToLogic( Point(0,0)) );
00694 #endif
00695 
00696             Rectangle aRect( aTLPos, aSize );
00697             if (aRect.IsInside( aPos ))
00698             {
00699                 DBG_ASSERT( pNode->IsVisible(), "node is not a leaf" );
00700                 String aTxt;
00701                 pNode->GetAccessibleText( aTxt );
00702                 DBG_ASSERT( aTxt.Len(), "no accessible text available" );
00703 
00704                 long nNodeX = pNode->GetLeft();
00705 
00706                 sal_Int32 *pXAry = new sal_Int32[ aTxt.Len() ];
00707                 pWin->SetFont( pNode->GetFont() );
00708                 pWin->GetTextArray( aTxt, pXAry, 0, aTxt.Len() );
00709                 for (sal_Int32 i = 0;  i < aTxt.Len()  &&  nRes == -1;  ++i)
00710                 {
00711                     if (pXAry[i] + nNodeX > aPos.X())
00712                         nRes = i;
00713                 }
00714                 delete[] pXAry;
00715                 DBG_ASSERT( nRes >= 0  &&  nRes < aTxt.Len(), "index out of range" );
00716                 DBG_ASSERT( pNode->GetAccessibleIndex() >= 0,
00717                         "invalid accessible index" );
00718 
00719                 nRes = pNode->GetAccessibleIndex() + nRes;
00720             }
00721                 }
00722     }
00723     return nRes;
00724 }
00725 
00726 OUString SAL_CALL SmGraphicAccessible::getSelectedText()
00727     throw (RuntimeException)
00728 {
00729         vos::OGuard aGuard(Application::GetSolarMutex());
00730     return OUString();
00731 }
00732 
00733 sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionStart()
00734     throw (RuntimeException)
00735 {
00736         vos::OGuard aGuard(Application::GetSolarMutex());
00737     return -1;
00738 }
00739 
00740 sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionEnd()
00741     throw (RuntimeException)
00742 {
00743         vos::OGuard aGuard(Application::GetSolarMutex());
00744     return -1;
00745 }
00746 
00747 sal_Bool SAL_CALL SmGraphicAccessible::setSelection(
00748         sal_Int32 nStartIndex,
00749         sal_Int32 nEndIndex )
00750     throw (IndexOutOfBoundsException, RuntimeException)
00751 {
00752         vos::OGuard aGuard(Application::GetSolarMutex());
00753     INT32 nLen = GetAccessibleText_Impl().Len();
00754     if (!(0 <= nStartIndex  &&  nStartIndex < nLen) ||
00755         !(0 <= nEndIndex    &&  nEndIndex   < nLen))
00756         throw IndexOutOfBoundsException();
00757     return FALSE;
00758 }
00759 
00760 OUString SAL_CALL SmGraphicAccessible::getText()
00761     throw (RuntimeException)
00762 {
00763         vos::OGuard aGuard(Application::GetSolarMutex());
00764     return GetAccessibleText_Impl();
00765 }
00766 
00767 OUString SAL_CALL SmGraphicAccessible::getTextRange(
00768         sal_Int32 nStartIndex,
00769         sal_Int32 nEndIndex )
00770     throw (IndexOutOfBoundsException, RuntimeException)
00771 {
00775 
00776     vos::OGuard aGuard(Application::GetSolarMutex());
00777     String aTxt( GetAccessibleText_Impl() );
00778     xub_StrLen nStart = (xub_StrLen) Min(nStartIndex, nEndIndex);
00779     xub_StrLen nEnd   = (xub_StrLen) Max(nStartIndex, nEndIndex);
00780     if (!(/*0 <= nStart  &&*/  nStart <= aTxt.Len()) ||
00781         !(/*0 <= nEnd    &&*/  nEnd   <= aTxt.Len()))
00782         throw IndexOutOfBoundsException();
00783     return aTxt.Copy( nStart, nEnd - nStart );
00784 }
00785 
00786 ::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)
00787 {
00788         vos::OGuard aGuard(Application::GetSolarMutex());
00789     String aTxt( GetAccessibleText_Impl() );
00790     xub_StrLen nIdx = (xub_StrLen) nIndex;
00792     if (!(/*0 <= nIdx  &&*/  nIdx <= aTxt.Len()))
00793         throw IndexOutOfBoundsException();
00794 
00795     ::com::sun::star::accessibility::TextSegment aResult;
00796     aResult.SegmentStart = -1;
00797     aResult.SegmentEnd = -1;
00798     if ( (AccessibleTextType::CHARACTER == aTextType)  &&  (nIdx < aTxt.Len()) )
00799     {
00800         aResult.SegmentText = aTxt.Copy(nIdx, 1);
00801         aResult.SegmentStart = nIdx;
00802         aResult.SegmentEnd = nIdx+1;
00803     }
00804     return aResult;
00805 }
00806 
00807 ::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)
00808 {
00809         vos::OGuard aGuard(Application::GetSolarMutex());
00810     String aTxt( GetAccessibleText_Impl() );
00811     xub_StrLen nIdx = (xub_StrLen) nIndex;
00813     if (!(/*0 <= nIdx  &&*/  nIdx <= aTxt.Len()))
00814         throw IndexOutOfBoundsException();
00815 
00816     ::com::sun::star::accessibility::TextSegment aResult;
00817     aResult.SegmentStart = -1;
00818     aResult.SegmentEnd = -1;
00819 
00820     if ( (AccessibleTextType::CHARACTER == aTextType)  && nIdx )
00821     {
00822         aResult.SegmentText = aTxt.Copy(nIdx-1, 1);
00823         aResult.SegmentStart = nIdx-1;
00824         aResult.SegmentEnd = nIdx;
00825     }
00826     return aResult;
00827 }
00828 
00829 ::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)
00830 {
00831         vos::OGuard aGuard(Application::GetSolarMutex());
00832     String aTxt( GetAccessibleText_Impl() );
00833     xub_StrLen nIdx = (xub_StrLen) nIndex;
00835     if (!(/*0 <= nIdx  &&*/  nIdx <= aTxt.Len()))
00836         throw IndexOutOfBoundsException();
00837 
00838     ::com::sun::star::accessibility::TextSegment aResult;
00839     aResult.SegmentStart = -1;
00840     aResult.SegmentEnd = -1;
00841 
00842     nIdx++; // text *behind*
00843     if ( (AccessibleTextType::CHARACTER == aTextType)  &&  (nIdx < aTxt.Len()) )
00844     {
00845         aResult.SegmentText = aTxt.Copy(nIdx, 1);
00846         aResult.SegmentStart = nIdx;
00847         aResult.SegmentEnd = nIdx+1;
00848     }
00849     return aResult;
00850 }
00851 
00852 sal_Bool SAL_CALL SmGraphicAccessible::copyText(
00853         sal_Int32 nStartIndex,
00854         sal_Int32 nEndIndex )
00855     throw (IndexOutOfBoundsException, RuntimeException)
00856 {
00857         vos::OGuard aGuard(Application::GetSolarMutex());
00858         sal_Bool bReturn = sal_False;
00859 
00860     if (!pWin)
00861         throw RuntimeException();
00862     else
00863         {
00864         Reference< datatransfer::clipboard::XClipboard > xClipboard = pWin->GetClipboard();
00865                 if ( xClipboard.is() )
00866                 {
00867             ::rtl::OUString sText( getTextRange(nStartIndex, nEndIndex) );
00868 
00869                         ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
00870                         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
00871                         xClipboard->setContents( pDataObj, NULL );
00872 
00873                         Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
00874                         if( xFlushableClipboard.is() )
00875                                 xFlushableClipboard->flushClipboard();
00876 
00877                         Application::AcquireSolarMutex( nRef );
00878 
00879                         bReturn = sal_True;
00880                 }
00881         }
00882 
00883     return bReturn;
00884 }
00885 
00886 OUString SAL_CALL SmGraphicAccessible::getImplementationName()
00887     throw (RuntimeException)
00888 {
00889     //vos::OGuard aGuard(Application::GetSolarMutex());
00890     return C2U("SmGraphicAccessible");
00891 }
00892 
00893 sal_Bool SAL_CALL SmGraphicAccessible::supportsService(
00894         const OUString& rServiceName )
00895     throw (RuntimeException)
00896 {
00897     //vos::OGuard aGuard(Application::GetSolarMutex());
00898     return  rServiceName == C2U( "com::sun::star::accessibility::Accessible" ) ||
00899             rServiceName == C2U( "com::sun::star::accessibility::AccessibleComponent" ) ||
00900             rServiceName == C2U( "com::sun::star::accessibility::AccessibleContext" ) ||
00901             rServiceName == C2U( "com::sun::star::accessibility::AccessibleText" );
00902 }
00903 
00904 Sequence< OUString > SAL_CALL SmGraphicAccessible::getSupportedServiceNames()
00905     throw (RuntimeException)
00906 {
00907     //vos::OGuard aGuard(Application::GetSolarMutex());
00908     Sequence< OUString > aNames(4);
00909     OUString *pNames = aNames.getArray();
00910     pNames[0] = C2U( "com::sun::star::accessibility::Accessible" );
00911     pNames[1] = C2U( "com::sun::star::accessibility::AccessibleComponent" );
00912     pNames[2] = C2U( "com::sun::star::accessibility::AccessibleContext" );
00913     pNames[3] = C2U( "com::sun::star::accessibility::AccessibleText" );
00914     return aNames;
00915 }
00916 
00918 
00919 //------------------------------------------------------------------------
00920 
00921 SmEditSource::SmEditSource( SmEditWindow * /*pWin*/, SmEditAccessible &rAcc ) :
00922     aViewFwd    (rAcc),
00923     aTextFwd    (rAcc, *this),
00924     aEditViewFwd(rAcc),
00925     rEditAcc (rAcc)
00926 {
00927 }
00928 
00929 SmEditSource::SmEditSource( const SmEditSource &rSrc ) :
00930     SvxEditSource(),
00931     aViewFwd    (rSrc.rEditAcc),
00932     aTextFwd    (rSrc.rEditAcc, *this),
00933     aEditViewFwd(rSrc.rEditAcc),
00934     rEditAcc    (rSrc.rEditAcc)
00935 {
00936     //aBroadCaster;     can be completely new
00937 }
00938 
00939 SmEditSource::~SmEditSource()
00940 {
00941 }
00942 
00943 SvxEditSource* SmEditSource::Clone() const
00944 {
00945     return new SmEditSource( *this );
00946 }
00947 
00948 SvxTextForwarder* SmEditSource::GetTextForwarder()
00949 {
00950     return &aTextFwd;
00951 }
00952 
00953 SvxViewForwarder* SmEditSource::GetViewForwarder()
00954 {
00955     return &aViewFwd;
00956 }
00957 
00958 SvxEditViewForwarder* SmEditSource::GetEditViewForwarder( sal_Bool /*bCreate*/ )
00959 {
00960     return &aEditViewFwd;
00961 }
00962 
00963 void SmEditSource::UpdateData()
00964 {
00965     // would possibly only by needed if the XText inteface is implemented
00966     // and its text needs to be updated.
00967 }
00968 
00969 SfxBroadcaster & SmEditSource::GetBroadcaster() const
00970 {
00971     return ((SmEditSource *) this)->aBroadCaster;
00972 }
00973 
00974 //------------------------------------------------------------------------
00975 
00976 SmViewForwarder::SmViewForwarder( SmEditAccessible &rAcc ) :
00977     rEditAcc(rAcc)
00978 {
00979 }
00980 
00981 SmViewForwarder::~SmViewForwarder()
00982 {
00983 }
00984 
00985 BOOL SmViewForwarder::IsValid() const
00986 {
00987     return rEditAcc.GetEditView() != 0;
00988 }
00989 
00990 Rectangle SmViewForwarder::GetVisArea() const
00991 {
00992         EditView *pEditView = rEditAcc.GetEditView();
00993         OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
00994 
00995     if( pOutDev && pEditView)
00996     {
00997         Rectangle aVisArea = pEditView->GetVisArea();
00998 
00999         // figure out map mode from edit engine
01000         EditEngine* pEditEngine = pEditView->GetEditEngine();
01001 
01002         if( pEditEngine )
01003         {
01004             MapMode aMapMode(pOutDev->GetMapMode());
01005             aVisArea = OutputDevice::LogicToLogic( aVisArea,
01006                                                    pEditEngine->GetRefMapMode(),
01007                                                    aMapMode.GetMapUnit() );
01008             aMapMode.SetOrigin(Point());
01009             return pOutDev->LogicToPixel( aVisArea, aMapMode );
01010         }
01011     }
01012 
01013     return Rectangle();
01014 }
01015 
01016 Point SmViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
01017 {
01018         EditView *pEditView = rEditAcc.GetEditView();
01019         OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
01020 
01021     if( pOutDev )
01022     {
01023         MapMode aMapMode(pOutDev->GetMapMode());
01024         Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
01025                                                   aMapMode.GetMapUnit() ) );
01026         aMapMode.SetOrigin(Point());
01027         return pOutDev->LogicToPixel( aPoint, aMapMode );
01028     }
01029 
01030     return Point();
01031 }
01032 
01033 Point SmViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
01034 {
01035         EditView *pEditView = rEditAcc.GetEditView();
01036         OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
01037 
01038     if( pOutDev )
01039     {
01040         MapMode aMapMode(pOutDev->GetMapMode());
01041         aMapMode.SetOrigin(Point());
01042         Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) );
01043         return OutputDevice::LogicToLogic( aPoint,
01044                                            aMapMode.GetMapUnit(),
01045                                            rMapMode );
01046     }
01047 
01048     return Point();
01049 }
01050 
01051 
01052 //------------------------------------------------------------------------
01053 
01054 SmTextForwarder::SmTextForwarder( SmEditAccessible& rAcc, SmEditSource & rSource) :
01055     rEditAcc ( rAcc ),
01056     rEditSource (rSource)
01057 {
01058         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01059         if (pEditEngine)
01060                 pEditEngine->SetNotifyHdl( LINK(this, SmTextForwarder, NotifyHdl) );
01061 }
01062 
01063 SmTextForwarder::~SmTextForwarder()
01064 {
01065     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01066     if (pEditEngine)
01067         pEditEngine->SetNotifyHdl( Link() );
01068 }
01069 
01070 IMPL_LINK(SmTextForwarder, NotifyHdl, EENotify*, aNotify)
01071 {
01072     if (aNotify)
01073     {
01074         ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
01075         if (aHint.get())
01076             rEditSource.GetBroadcaster().Broadcast( *aHint.get() );
01077     }
01078 
01079     return 0;
01080 }
01081 
01082 USHORT SmTextForwarder::GetParagraphCount() const
01083 {
01084         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01085         return pEditEngine ? pEditEngine->GetParagraphCount() : 0;
01086 }
01087 
01088 USHORT SmTextForwarder::GetTextLen( USHORT nParagraph ) const
01089 {
01090         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01091         return pEditEngine ? pEditEngine->GetTextLen( nParagraph ) : 0;
01092 }
01093 
01094 String SmTextForwarder::GetText( const ESelection& rSel ) const
01095 {
01096         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01097         String aRet;
01098         if (pEditEngine)
01099                 aRet = pEditEngine->GetText( rSel, LINEEND_LF );
01100         aRet.ConvertLineEnd();
01101         return aRet;
01102 }
01103 
01104 SfxItemSet SmTextForwarder::GetAttribs( const ESelection& rSel, BOOL bOnlyHardAttrib ) const
01105 {
01106         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01107         DBG_ASSERT( pEditEngine, "EditEngine missing" );
01108         if( rSel.nStartPara == rSel.nEndPara )
01109         {
01110                 sal_uInt8 nFlags = 0;
01111                 switch( bOnlyHardAttrib )
01112                 {
01113                 case EditEngineAttribs_All:
01114                         nFlags = GETATTRIBS_ALL;
01115                         break;
01116                 case EditEngineAttribs_HardAndPara:
01117                         nFlags = GETATTRIBS_PARAATTRIBS|GETATTRIBS_CHARATTRIBS;
01118                         break;
01119                 case EditEngineAttribs_OnlyHard:
01120                         nFlags = GETATTRIBS_CHARATTRIBS;
01121                         break;
01122                 default:
01123             DBG_ERROR("unknown flags for SmTextForwarder::GetAttribs");
01124                 }
01125 
01126                 return pEditEngine->GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags );
01127         }
01128         else
01129         {
01130                 return pEditEngine->GetAttribs( rSel, bOnlyHardAttrib );
01131         }
01132 }
01133 
01134 SfxItemSet SmTextForwarder::GetParaAttribs( USHORT nPara ) const
01135 {
01136         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01137         DBG_ASSERT( pEditEngine, "EditEngine missing" );
01138 
01139         SfxItemSet aSet( pEditEngine->GetParaAttribs( nPara ) );
01140 
01141         USHORT nWhich = EE_PARA_START;
01142         while( nWhich <= EE_PARA_END )
01143         {
01144                 if( aSet.GetItemState( nWhich, TRUE ) != SFX_ITEM_ON )
01145                 {
01146                         if( pEditEngine->HasParaAttrib( nPara, nWhich ) )
01147                                 aSet.Put( pEditEngine->GetParaAttrib( nPara, nWhich ) );
01148                 }
01149                 nWhich++;
01150         }
01151 
01152         return aSet;
01153 }
01154 
01155 void SmTextForwarder::SetParaAttribs( USHORT nPara, const SfxItemSet& rSet )
01156 {
01157         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01158         if (pEditEngine)
01159                 pEditEngine->SetParaAttribs( nPara, rSet );
01160 }
01161 
01162 SfxItemPool* SmTextForwarder::GetPool() const
01163 {
01164         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01165         return pEditEngine ? pEditEngine->GetEmptyItemSet().GetPool() : 0;
01166 }
01167 
01168 void SmTextForwarder::GetPortions( USHORT nPara, SvUShorts& rList ) const
01169 {
01170         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01171         if (pEditEngine)
01172                 pEditEngine->GetPortions( nPara, rList );
01173 }
01174 
01175 void SmTextForwarder::QuickInsertText( const String& rText, const ESelection& rSel )
01176 {
01177         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01178         if (pEditEngine)
01179                 pEditEngine->QuickInsertText( rText, rSel );
01180 }
01181 
01182 void SmTextForwarder::QuickInsertLineBreak( const ESelection& rSel )
01183 {
01184         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01185         if (pEditEngine)
01186                 pEditEngine->QuickInsertLineBreak( rSel );
01187 }
01188 
01189 void SmTextForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
01190 {
01191         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01192         if (pEditEngine)
01193                 pEditEngine->QuickInsertField( rFld, rSel );
01194 }
01195 
01196 void SmTextForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
01197 {
01198         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01199         if (pEditEngine)
01200                 pEditEngine->QuickSetAttribs( rSet, rSel );
01201 }
01202 
01203 BOOL SmTextForwarder::IsValid() const
01204 {
01205         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01206     // cannot reliably query EditEngine state
01207     // while in the middle of an update
01208         return pEditEngine ? pEditEngine->GetUpdateMode() : FALSE;
01209 }
01210 
01211 XubString SmTextForwarder::CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rpTxtColor, Color*& rpFldColor )
01212 {
01213         XubString aTxt;
01214         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01215         if (pEditEngine)
01216                 aTxt = pEditEngine->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
01217         return aTxt;
01218 }
01219 
01220 USHORT GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, USHORT nWhich )
01221 {
01222         EECharAttribArray aAttribs;
01223 
01224         const SfxPoolItem*      pLastItem = NULL;
01225 
01226         SfxItemState eState = SFX_ITEM_DEFAULT;
01227 
01228         // check all paragraphs inside the selection
01229         for( USHORT nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++ )
01230         {
01231                 SfxItemState eParaState = SFX_ITEM_DEFAULT;
01232 
01233                 // calculate start and endpos for this paragraph
01234                 USHORT nPos = 0;
01235                 if( rSel.nStartPara == nPara )
01236                         nPos = rSel.nStartPos;
01237 
01238                 USHORT nEndPos = rSel.nEndPos;
01239                 if( rSel.nEndPara != nPara )
01240                         nEndPos = rEditEngine.GetTextLen( nPara );
01241 
01242 
01243                 // get list of char attribs
01244                 rEditEngine.GetCharAttribs( nPara, aAttribs );
01245 
01246                 BOOL bEmpty = TRUE;             // we found no item inside the selektion of this paragraph
01247                 BOOL bGaps  = FALSE;    // we found items but theire gaps between them
01248                 USHORT nLastEnd = nPos;
01249 
01250                 const SfxPoolItem* pParaItem = NULL;
01251 
01252                 for( USHORT nAttrib = 0; nAttrib < aAttribs.Count(); nAttrib++ )
01253                 {
01254                         struct EECharAttrib aAttrib = aAttribs.GetObject( nAttrib );
01255                         DBG_ASSERT( aAttrib.pAttr, "GetCharAttribs gives corrupt data" );
01256 
01257                         const sal_Bool bEmptyPortion = aAttrib.nStart == aAttrib.nEnd;
01258                         if( (!bEmptyPortion && (aAttrib.nStart >= nEndPos)) || (bEmptyPortion && (aAttrib.nStart > nEndPos)) )
01259                                 break;  // break if we are already behind our selektion
01260 
01261                         if( (!bEmptyPortion && (aAttrib.nEnd <= nPos)) || (bEmptyPortion && (aAttrib.nEnd < nPos)) )
01262                                 continue;       // or if the attribute ends before our selektion
01263 
01264                         if( aAttrib.pAttr->Which() != nWhich )
01265                                 continue; // skip if is not the searched item
01266 
01267                         // if we already found an item
01268                         if( pParaItem )
01269                         {
01270                                 // ... and its different to this one than the state is dont care
01271                                 if( *pParaItem != *aAttrib.pAttr )
01272                                         return SFX_ITEM_DONTCARE;
01273                         }
01274                         else
01275                         {
01276                                 pParaItem = aAttrib.pAttr;
01277                         }
01278 
01279                         if( bEmpty )
01280                                 bEmpty = FALSE;
01281 
01282                         if( !bGaps && aAttrib.nStart > nLastEnd )
01283                                 bGaps = TRUE;
01284 
01285                         nLastEnd = aAttrib.nEnd;
01286                 }
01287 
01288                 if( !bEmpty && !bGaps && nLastEnd < ( nEndPos - 1 ) )
01289                         bGaps = TRUE;
01290 /*
01291                 // since we have no portion with our item or if there were gaps
01292                 if( bEmpty || bGaps )
01293                 {
01294                         // we need to check the paragraph item
01295                         const SfxItemSet& rParaSet = rEditEngine.GetParaAttribs( nPara );
01296                         if( rParaSet.GetItemState( nWhich ) == SFX_ITEM_SET )
01297                         {
01298                                 eState = SFX_ITEM_SET;
01299                                 // get item from the paragraph
01300                                 const SfxPoolItem* pTempItem = rParaSet.GetItem( nWhich );
01301                                 if( pParaItem )
01302                                 {
01303                                         if( *pParaItem != *pTempItem )
01304                                                 return SFX_ITEM_DONTCARE;
01305                                 }
01306                                 else
01307                                 {
01308                                         pParaItem = pTempItem;
01309                                 }
01310 
01311                                 // set if theres no last item or if its the same
01312                                 eParaState = SFX_ITEM_SET;
01313                         }
01314                         else if( bEmpty )
01315                         {
01316                                 eParaState = SFX_ITEM_DEFAULT;
01317                         }
01318                         else if( bGaps )
01319                         {
01320                                 // gaps and item not set in paragraph, thats a dont care
01321                                 return SFX_ITEM_DONTCARE;
01322                         }
01323                 }
01324                 else
01325                 {
01326                         eParaState = SFX_ITEM_SET;
01327                 }
01328 */
01329                 if( bEmpty )
01330                         eParaState = SFX_ITEM_DEFAULT;
01331                 else if( bGaps )
01332                         eParaState = SFX_ITEM_DONTCARE;
01333                 else
01334                         eParaState = SFX_ITEM_SET;
01335 
01336                 // if we already found an item check if we found the same
01337                 if( pLastItem )
01338                 {
01339                         if( (pParaItem == NULL) || (*pLastItem != *pParaItem) )
01340                                 return SFX_ITEM_DONTCARE;
01341                 }
01342                 else
01343                 {
01344                         pLastItem = pParaItem;
01345                         eState = eParaState;
01346                 }
01347         }
01348 
01349         return eState;
01350 }
01351 
01352 USHORT SmTextForwarder::GetItemState( const ESelection& rSel, USHORT nWhich ) const
01353 {
01354         USHORT nState = SFX_ITEM_DISABLED;
01355         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01356         if (pEditEngine)
01357                 nState = GetSvxEditEngineItemState( *pEditEngine, rSel, nWhich );
01358         return nState;
01359 }
01360 
01361 USHORT SmTextForwarder::GetItemState( USHORT nPara, USHORT nWhich ) const
01362 {
01363         USHORT nState = SFX_ITEM_DISABLED;
01364         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01365         if (pEditEngine)
01366         {
01367                 const SfxItemSet& rSet = pEditEngine->GetParaAttribs( nPara );
01368                 nState = rSet.GetItemState( nWhich );
01369         }
01370         return nState;
01371 }
01372 
01373 LanguageType SmTextForwarder::GetLanguage( USHORT nPara, USHORT nIndex ) const
01374 {
01375         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01376         return pEditEngine ? pEditEngine->GetLanguage(nPara, nIndex) : LANGUAGE_NONE;
01377 }
01378 
01379 USHORT SmTextForwarder::GetFieldCount( USHORT nPara ) const
01380 {
01381         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01382         return pEditEngine ? pEditEngine->GetFieldCount(nPara) : 0;
01383 }
01384 
01385 EFieldInfo SmTextForwarder::GetFieldInfo( USHORT nPara, USHORT nField ) const
01386 {
01387         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01388         return pEditEngine ? pEditEngine->GetFieldInfo( nPara, nField ) : EFieldInfo();
01389 }
01390 
01391 EBulletInfo SmTextForwarder::GetBulletInfo( USHORT /*nPara*/ ) const
01392 {
01393     return EBulletInfo();
01394 }
01395 
01396 Rectangle SmTextForwarder::GetCharBounds( USHORT nPara, USHORT nIndex ) const
01397 {
01398         Rectangle aRect(0,0,0,0);
01399         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01400     
01401         if (pEditEngine)
01402         {
01403                 // #108900# Handle virtual position one-past-the end of the string
01404                 if( nIndex >= pEditEngine->GetTextLen(nPara) )
01405                 {
01406                         if( nIndex )
01407                                 aRect = pEditEngine->GetCharacterBounds( EPosition(nPara, nIndex-1) );
01408 
01409                         aRect.Move( aRect.Right() - aRect.Left(), 0 );
01410                         aRect.SetSize( Size(1, pEditEngine->GetTextHeight()) );
01411                 }
01412                 else
01413                 {
01414                         aRect = pEditEngine->GetCharacterBounds( EPosition(nPara, nIndex) );
01415             }
01416         }
01417         return aRect;
01418 }
01419 
01420 Rectangle SmTextForwarder::GetParaBounds( USHORT nPara ) const
01421 {
01422         Rectangle aRect(0,0,0,0);
01423         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01424         
01425         if (pEditEngine)
01426         {
01427                 const Point aPnt = pEditEngine->GetDocPosTopLeft( nPara );
01428                 const ULONG nWidth = pEditEngine->CalcTextWidth();
01429                 const ULONG nHeight = pEditEngine->GetTextHeight( nPara );
01430                 aRect = Rectangle( aPnt.X(), aPnt.Y(), aPnt.X() + nWidth, aPnt.Y() + nHeight );
01431         }
01432 
01433     return aRect;
01434 }
01435 
01436 MapMode SmTextForwarder::GetMapMode() const
01437 {
01438         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01439         return pEditEngine ? pEditEngine->GetRefMapMode() : MapMode( MAP_100TH_MM );
01440 }
01441 
01442 OutputDevice* SmTextForwarder::GetRefDevice() const
01443 {
01444         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01445         return pEditEngine ? pEditEngine->GetRefDevice() : 0;
01446 }
01447 
01448 sal_Bool SmTextForwarder::GetIndexAtPoint( const Point& rPos, USHORT& nPara, USHORT& nIndex ) const
01449 {
01450         sal_Bool bRes = sal_False;
01451         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01452         if (pEditEngine)
01453         {
01454                 EPosition aDocPos = pEditEngine->FindDocPosition( rPos );
01455                 nPara   = aDocPos.nPara;
01456                 nIndex  = aDocPos.nIndex;
01457                 bRes = sal_True;
01458         }
01459         return bRes;
01460 }
01461 
01462 sal_Bool SmTextForwarder::GetWordIndices( USHORT nPara, USHORT nIndex, USHORT& nStart, USHORT& nEnd ) const
01463 {
01464         sal_Bool bRes = sal_False;
01465         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01466         if (pEditEngine)
01467         {
01468                 ESelection aRes = pEditEngine->GetWord( ESelection(nPara, nIndex, nPara, nIndex), com::sun::star::i18n::WordType::DICTIONARY_WORD );
01469 
01470                 if( aRes.nStartPara == nPara &&
01471                         aRes.nStartPara == aRes.nEndPara )
01472                 {
01473                         nStart = aRes.nStartPos;
01474                         nEnd = aRes.nEndPos;
01475 
01476                         bRes = sal_True;
01477             }
01478         }
01479 
01480     return bRes;
01481 }
01482 
01483 sal_Bool SmTextForwarder::GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, USHORT nPara, USHORT nIndex ) const
01484 {
01485         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01486     return pEditEngine ? 
01487                                 SvxEditSourceHelper::GetAttributeRun( nStartIndex, nEndIndex, *pEditEngine, nPara, nIndex )
01488                                 : sal_False;
01489 }
01490 
01491 USHORT SmTextForwarder::GetLineCount( USHORT nPara ) const
01492 {
01493         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01494         return pEditEngine ? pEditEngine->GetLineCount(nPara) : 0;
01495 }
01496 
01497 USHORT SmTextForwarder::GetLineLen( USHORT nPara, USHORT nLine ) const
01498 {
01499         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01500         return pEditEngine ? pEditEngine->GetLineLen(nPara, nLine) : 0;
01501 }
01502 
01503 sal_Bool SmTextForwarder::QuickFormatDoc( BOOL /*bFull*/ )
01504 {
01505         sal_Bool bRes = sal_False;
01506         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01507         if (pEditEngine)
01508         {
01509                 pEditEngine->QuickFormatDoc();
01510                 bRes = sal_True;
01511         }
01512     return bRes;
01513 }
01514 
01515 USHORT SmTextForwarder::GetDepth( USHORT /*nPara*/ ) const
01516 {
01517     // math has no outliner...
01518     return 0;
01519 }
01520 
01521 sal_Bool SmTextForwarder::SetDepth( USHORT /*nPara*/, USHORT nNewDepth )
01522 {
01523     // math has no outliner...
01524     return 0 == nNewDepth;  // is it the value from 'GetDepth' ?
01525 }
01526 
01527 sal_Bool SmTextForwarder::Delete( const ESelection& rSelection )
01528 {
01529         sal_Bool bRes = sal_False;
01530         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01531         if (pEditEngine)
01532         {
01533                 pEditEngine->QuickDelete( rSelection );
01534                 pEditEngine->QuickFormatDoc();
01535                 bRes = sal_True;
01536         }
01537         return bRes;
01538 }
01539 
01540 sal_Bool SmTextForwarder::InsertText( const String& rStr, const ESelection& rSelection )
01541 {
01542         sal_Bool bRes = sal_False;
01543         EditEngine *pEditEngine = rEditAcc.GetEditEngine();
01544         if (pEditEngine)
01545         {
01546                 pEditEngine->QuickInsertText( rStr, rSelection );
01547                 pEditEngine->QuickFormatDoc();
01548                 bRes = sal_True;
01549         }
01550         return bRes;
01551 }
01552 
01553 const SfxItemSet*   SmTextForwarder::GetEmptyItemSetPtr()
01554 {
01555     DBG_ERROR("not yet implemented")
01556     return 0;
01557 }
01558 void SmTextForwarder::AppendParagraph()
01559 {
01560     DBG_ERROR("not yet implemented")
01561 }
01562 xub_StrLen SmTextForwarder::AppendTextPortion( USHORT /*nPara*/, const String &/*rText*/, const SfxItemSet &/*rSet*/ )
01563 {
01564     DBG_ERROR("not yet implemented")
01565     return 0;
01566 }
01567 //------------------------------------------------------------------------
01568 
01569 SmEditViewForwarder::SmEditViewForwarder( SmEditAccessible& rAcc ) :
01570     rEditAcc( rAcc )
01571 {
01572 }
01573 
01574 SmEditViewForwarder::~SmEditViewForwarder()
01575 {
01576 }
01577 
01578 BOOL SmEditViewForwarder::IsValid() const
01579 {
01580     return rEditAcc.GetEditView() != 0;
01581 }
01582 
01583 Rectangle SmEditViewForwarder::GetVisArea() const
01584 {
01585         Rectangle aRect(0,0,0,0);
01586 
01587         EditView *pEditView = rEditAcc.GetEditView();
01588         OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
01589 
01590     if( pOutDev && pEditView)
01591     {
01592         Rectangle aVisArea = pEditView->GetVisArea();
01593 
01594         // figure out map mode from edit engine
01595         EditEngine* pEditEngine = pEditView->GetEditEngine();
01596 
01597         if( pEditEngine )
01598         {
01599             MapMode aMapMode(pOutDev->GetMapMode());
01600             aVisArea = OutputDevice::LogicToLogic( aVisArea,
01601                                                    pEditEngine->GetRefMapMode(),
01602                                                    aMapMode.GetMapUnit() );
01603             aMapMode.SetOrigin(Point());
01604             aRect = pOutDev->LogicToPixel( aVisArea, aMapMode );
01605         }
01606     }
01607 
01608     return aRect;
01609 }
01610 
01611 Point SmEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
01612 {
01613         EditView *pEditView = rEditAcc.GetEditView();
01614         OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
01615 
01616     if( pOutDev )
01617     {
01618         MapMode aMapMode(pOutDev->GetMapMode());
01619         Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
01620                                                   aMapMode.GetMapUnit() ) );
01621         aMapMode.SetOrigin(Point());
01622         return pOutDev->LogicToPixel( aPoint, aMapMode );
01623     }
01624 
01625     return Point();
01626 }
01627 
01628 Point SmEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
01629 {
01630         EditView *pEditView = rEditAcc.GetEditView();
01631         OutputDevice* pOutDev = pEditView ? pEditView->GetWindow() : 0;
01632 
01633     if( pOutDev )
01634     {
01635         MapMode aMapMode(pOutDev->GetMapMode());
01636         aMapMode.SetOrigin(Point());
01637         Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) );
01638         return OutputDevice::LogicToLogic( aPoint,
01639                                            aMapMode.GetMapUnit(),
01640                                            rMapMode );
01641     }
01642 
01643     return Point();
01644 }
01645 
01646 sal_Bool SmEditViewForwarder::GetSelection( ESelection& rSelection ) const
01647 {
01648         sal_Bool bRes = sal_False;
01649         EditView *pEditView = rEditAcc.GetEditView();
01650         if (pEditView)
01651         {
01652                 rSelection = pEditView->GetSelection();
01653                 bRes = sal_True;
01654         }
01655     return bRes;
01656 }
01657 
01658 sal_Bool SmEditViewForwarder::SetSelection( const ESelection& rSelection )
01659 {
01660         sal_Bool bRes = sal_False;
01661         EditView *pEditView = rEditAcc.GetEditView();
01662         if (pEditView)
01663         {
01664                 pEditView->SetSelection( rSelection );
01665                 bRes = sal_True;
01666         }
01667         return bRes;
01668 }
01669 
01670 sal_Bool SmEditViewForwarder::Copy()
01671 {
01672         sal_Bool bRes = sal_False;
01673         EditView *pEditView = rEditAcc.GetEditView();
01674         if (pEditView)
01675         {
01676                 pEditView->Copy();
01677                 bRes = sal_True;
01678         }
01679         return bRes;
01680 }
01681 
01682 sal_Bool SmEditViewForwarder::Cut()
01683 {
01684         sal_Bool bRes = sal_False;
01685         EditView *pEditView = rEditAcc.GetEditView();
01686         if (pEditView)
01687         {
01688                 pEditView->Cut();
01689                 bRes = sal_True;
01690         }
01691         return bRes;
01692 }
01693 
01694 sal_Bool SmEditViewForwarder::Paste()
01695 {
01696         sal_Bool bRes = sal_False;
01697         EditView *pEditView = rEditAcc.GetEditView();
01698         if (pEditView)
01699         {
01700                 pEditView->Paste();
01701                 bRes = sal_True;
01702         }
01703         return bRes;
01704 }
01705 
01706 //------------------------------------------------------------------------
01707 
01708 SmEditAccessible::SmEditAccessible( SmEditWindow *pEditWin ) :
01709     aAccName            ( String(SmResId(STR_CMDBOXWINDOW)) ),
01710     pTextHelper         (0),
01711     pWin                (pEditWin)
01712 {
01713     DBG_ASSERT( pWin, "SmEditAccessible: window missing" );
01714     //++aRefCount;
01715 }
01716 
01717 
01718 SmEditAccessible::SmEditAccessible( const SmEditAccessible &rSmAcc ) :
01719     SmEditAccessibleBaseClass(),
01720     aAccName            ( String(SmResId(STR_CMDBOXWINDOW)) )
01721 {
01722     //vos::OGuard aGuard(Application::GetSolarMutex());
01723     pWin = rSmAcc.pWin;
01724     DBG_ASSERT( pWin, "SmEditAccessible: window missing" );
01725     //++aRefCount;
01726 }
01727 
01728 SmEditAccessible::~SmEditAccessible()
01729 {
01730     delete pTextHelper;
01731 /*
01732         vos::OGuard aGuard(Application::GetSolarMutex());
01733     if (--aRefCount == 0)
01734     {
01735     }
01736 */
01737 }
01738 
01739 void SmEditAccessible::Init()
01740 {
01741     DBG_ASSERT( pWin, "SmEditAccessible: window missing" );
01742     if (pWin)
01743     {
01744         EditEngine *pEditEngine = pWin->GetEditEngine();
01745         EditView   *pEditView   = pWin->GetEditView();
01746         if (pEditEngine && pEditView)
01747         {
01748             ::std::auto_ptr< SvxEditSource > pEditSource(
01749                     new SmEditSource( pWin, *this ) );
01750             pTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
01751             pTextHelper->SetEventSource( this );
01752         }
01753     }
01754 }
01755 
01756 SmDocShell * SmEditAccessible::GetDoc_Impl()
01757 {
01758     SmViewShell *pView = pWin ? pWin->GetView() : 0;
01759     return pView ? pView->GetDoc() : 0;
01760 }
01761 
01762 void SmEditAccessible::ClearWin()
01763 {
01764         // #112565# remove handler before current object gets destroyed
01765         // (avoid handler being called for already dead object)
01766         EditEngine *pEditEngine = GetEditEngine();
01767         if (pEditEngine)
01768                 pEditEngine->SetNotifyHdl( Link() );
01769 
01770         pWin = 0;   // implicitly results in AccessibleStateType::DEFUNC set
01771 
01773     pTextHelper->SetEditSource( ::std::auto_ptr<SvxEditSource>(NULL) );
01776     pTextHelper->Dispose();
01777     delete pTextHelper;     pTextHelper = 0;
01778 }
01779 
01780 // XAccessible
01781 uno::Reference< XAccessibleContext > SAL_CALL SmEditAccessible::getAccessibleContext(  )
01782     throw (RuntimeException)
01783 {
01784         vos::OGuard aGuard(Application::GetSolarMutex());
01785     return this;
01786 }
01787 
01788 // XAccessibleComponent
01789 sal_Bool SAL_CALL SmEditAccessible::containsPoint( const awt::Point& aPoint )
01790     throw (RuntimeException)
01791 {
01794 
01795         vos::OGuard aGuard(Application::GetSolarMutex());
01796     if (!pWin)
01797         throw RuntimeException();
01798 
01799     Size aSz( pWin->GetSizePixel() );
01800     return  aPoint.X >= 0  &&  aPoint.Y >= 0  &&
01801             aPoint.X < aSz.Width()  &&  aPoint.Y < aSz.Height();
01802 }
01803 
01804 uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleAtPoint( const awt::Point& aPoint )
01805     throw (RuntimeException)
01806 {
01807         vos::OGuard aGuard(Application::GetSolarMutex());
01808     if (!pTextHelper)
01809         throw RuntimeException();
01810     return pTextHelper->GetAt( aPoint );
01811 }
01812 
01813 awt::Rectangle SAL_CALL SmEditAccessible::getBounds(  )
01814     throw (RuntimeException)
01815 {
01816         vos::OGuard aGuard(Application::GetSolarMutex());
01817     if (!pWin)
01818         throw RuntimeException();
01819     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
01820             "mismatch of window parent and accessible parent" );
01821     return lcl_GetBounds( pWin );
01822 }
01823 
01824 awt::Point SAL_CALL SmEditAccessible::getLocation(  )
01825     throw (RuntimeException)
01826 {
01827         vos::OGuard aGuard(Application::GetSolarMutex());
01828     if (!pWin)
01829         throw RuntimeException();
01830     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
01831             "mismatch of window parent and accessible parent" );
01832     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
01833     return awt::Point( aRect.X, aRect.Y );
01834 }
01835 
01836 awt::Point SAL_CALL SmEditAccessible::getLocationOnScreen(  )
01837     throw (RuntimeException)
01838 {
01839     vos::OGuard aGuard(Application::GetSolarMutex());
01840     if (!pWin)
01841         throw RuntimeException();
01842     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
01843             "mismatch of window parent and accessible parent" );
01844     return lcl_GetLocationOnScreen( pWin );
01845 }
01846 
01847 awt::Size SAL_CALL SmEditAccessible::getSize(  )
01848     throw (RuntimeException)
01849 {
01850         vos::OGuard aGuard(Application::GetSolarMutex());
01851     if (!pWin)
01852         throw RuntimeException();
01853     DBG_ASSERT(pWin->GetParent()->GetAccessible() == getAccessibleParent(),
01854             "mismatch of window parent and accessible parent" );
01855 
01856     Size aSz( pWin->GetSizePixel() );
01857 #if OSL_DEBUG_LEVEL > 1
01858     awt::Rectangle aRect( lcl_GetBounds( pWin ) );
01859     Size aSz2( aRect.Width, aRect.Height );
01860     DBG_ASSERT( aSz == aSz2, "mismatch in width" );
01861 #endif
01862     return awt::Size( aSz.Width(), aSz.Height() );
01863 }
01864 
01865 void SAL_CALL SmEditAccessible::grabFocus(  )
01866     throw (RuntimeException)
01867 {
01868         vos::OGuard aGuard(Application::GetSolarMutex());
01869     if (!pWin)
01870         throw RuntimeException();
01871 
01872     pWin->GrabFocus();
01873 }
01874 
01875 sal_Int32 SAL_CALL SmEditAccessible::getForeground()
01876     throw (RuntimeException)
01877 {
01878     vos::OGuard aGuard(Application::GetSolarMutex());
01879 
01880     if (!pWin)
01881         throw RuntimeException();
01882     return (sal_Int32) pWin->GetTextColor().GetColor();
01883 }
01884 
01885 sal_Int32 SAL_CALL SmEditAccessible::getBackground()
01886     throw (RuntimeException)
01887 {
01888     vos::OGuard aGuard(Application::GetSolarMutex());
01889 
01890     if (!pWin)
01891         throw RuntimeException();
01892     Wallpaper aWall( pWin->GetDisplayBackground() );
01893     ColorData nCol;
01894     if (aWall.IsBitmap() || aWall.IsGradient())
01895         nCol = pWin->GetSettings().GetStyleSettings().GetWindowColor().GetColor();
01896     else
01897         nCol = aWall.GetColor().GetColor();
01898     return (sal_Int32) nCol;
01899 }
01900 
01901 // XAccessibleContext
01902 sal_Int32 SAL_CALL SmEditAccessible::getAccessibleChildCount(  )
01903     throw (RuntimeException)
01904 {
01905         vos::OGuard aGuard(Application::GetSolarMutex());
01906     if (!pTextHelper)
01907         throw RuntimeException();
01908     return pTextHelper->GetChildCount();
01909 }
01910 
01911 uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleChild( sal_Int32 i )
01912     throw (IndexOutOfBoundsException, RuntimeException)
01913 {
01914     vos::OGuard aGuard(Application::GetSolarMutex());
01915     if (!pTextHelper)
01916         throw RuntimeException();
01917     return pTextHelper->GetChild( i );
01918 }
01919 
01920 uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleParent(  )
01921     throw (RuntimeException)
01922 {
01923         vos::OGuard aGuard(Application::GetSolarMutex());
01924     if (!pWin)
01925         throw RuntimeException();
01926 
01927     Window *pAccParent = pWin->GetAccessibleParentWindow();
01928     DBG_ASSERT( pAccParent, "accessible parent missing" );
01929     return pAccParent ? pAccParent->GetAccessible() : Reference< XAccessible >();
01930 }
01931 
01932 sal_Int32 SAL_CALL SmEditAccessible::getAccessibleIndexInParent(  )
01933     throw (RuntimeException)
01934 {
01935         vos::OGuard aGuard(Application::GetSolarMutex());
01936     sal_Int32 nIdx = -1;
01937     Window *pAccParent = pWin ? pWin->GetAccessibleParentWindow() : 0;
01938     if (pAccParent)
01939     {
01940         USHORT nCnt = pAccParent->GetAccessibleChildWindowCount();
01941         for (USHORT i = 0;  i < nCnt  &&  nIdx == -1;  ++i)
01942             if (pAccParent->GetAccessibleChildWindow( i ) == pWin)
01943                 nIdx = i;
01944     }
01945     return nIdx;
01946 }
01947 
01948 sal_Int16 SAL_CALL SmEditAccessible::getAccessibleRole(  )
01949     throw (RuntimeException)
01950 {
01951         vos::OGuard aGuard(Application::GetSolarMutex());
01952     return AccessibleRole::PANEL /*TEXT ?*/;
01953 }
01954 
01955 rtl::OUString SAL_CALL SmEditAccessible::getAccessibleDescription(  )
01956     throw (RuntimeException)
01957 {
01958         vos::OGuard aGuard(Application::GetSolarMutex());
01959     return OUString();  // empty as agreed with product-management
01960 }
01961 
01962 rtl::OUString SAL_CALL SmEditAccessible::getAccessibleName(  )
01963     throw (RuntimeException)
01964 {
01965         vos::OGuard aGuard(Application::GetSolarMutex());
01966     // same name as displayed by the window when not docked
01967     return aAccName;
01968 }
01969 
01970 uno::Reference< XAccessibleRelationSet > SAL_CALL SmEditAccessible::getAccessibleRelationSet(  )
01971     throw (RuntimeException)
01972 {
01973         vos::OGuard aGuard(Application::GetSolarMutex());
01974     Reference< XAccessibleRelationSet > xRelSet = new utl::AccessibleRelationSetHelper();
01975     return xRelSet;   // empty relation set
01976 }
01977 
01978 uno::Reference< XAccessibleStateSet > SAL_CALL SmEditAccessible::getAccessibleStateSet(  )
01979     throw (RuntimeException)
01980 {
01981         vos::OGuard aGuard(Application::GetSolarMutex());
01982         ::utl::AccessibleStateSetHelper *pStateSet =
01983             new ::utl::AccessibleStateSetHelper;
01984 
01985         Reference<XAccessibleStateSet> xStateSet( pStateSet );
01986 
01987     if (!pWin || !pTextHelper)
01988         pStateSet->AddState( AccessibleStateType::DEFUNC );
01989     else
01990     {
01991         //pStateSet->AddState( AccessibleStateType::EDITABLE );
01992         pStateSet->AddState( AccessibleStateType::MULTI_LINE );
01993         //pStateSet->AddState( AccessibleStateType::HORIZONTAL );
01994         //pStateSet->AddState( AccessibleStateType::TRANSIENT );
01995         pStateSet->AddState( AccessibleStateType::ENABLED );
01996         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
01997         if (pWin->HasFocus())
01998             pStateSet->AddState( AccessibleStateType::FOCUSED );
01999         if (pWin->IsActive())
02000             pStateSet->AddState( AccessibleStateType::ACTIVE );
02001         if (pWin->IsVisible())
02002             pStateSet->AddState( AccessibleStateType::SHOWING );
02003         if (pWin->IsReallyVisible())
02004             pStateSet->AddState( AccessibleStateType::VISIBLE );
02005         if (COL_TRANSPARENT != pWin->GetBackground().GetColor().GetColor())
02006             pStateSet->AddState( AccessibleStateType::OPAQUE );
02007     }
02008 
02009         return xStateSet;
02010 }
02011 
02012 Locale SAL_CALL SmEditAccessible::getLocale(  )
02013     throw (IllegalAccessibleComponentStateException, RuntimeException)
02014 {
02015         vos::OGuard aGuard(Application::GetSolarMutex());
02016     // should be the document language...
02017     // We use the language of the localized symbol names here.
02018     return Application::GetSettings().GetUILocale();
02019 }
02020 
02021 
02022 // XAccessibleEventBroadcaster
02023 void SAL_CALL SmEditAccessible::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
02024     throw (RuntimeException)
02025 {
02026     //vos::OGuard aGuard(Application::GetSolarMutex());   if (pTextHelper)   // not disposing (about to destroy view shell)
02027         pTextHelper->AddEventListener( xListener );
02028 }
02029 
02030 void SAL_CALL SmEditAccessible::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
02031     throw (RuntimeException)
02032 {
02033     //vos::OGuard aGuard(Application::GetSolarMutex());
02034    if (pTextHelper)   // not disposing (about to destroy view shell)
02035         pTextHelper->RemoveEventListener( xListener );
02036 }
02037 
02038 OUString SAL_CALL SmEditAccessible::getImplementationName()
02039     throw (RuntimeException)
02040 {
02041     //vos::OGuard aGuard(Application::GetSolarMutex());
02042     return C2U("SmEditAccessible");
02043 }
02044 
02045 sal_Bool SAL_CALL SmEditAccessible::supportsService(
02046         const OUString& rServiceName )
02047     throw (RuntimeException)
02048 {
02049     //vos::OGuard aGuard(Application::GetSolarMutex());
02050     return  rServiceName == C2U( "com::sun::star::accessibility::Accessible" ) ||
02051             rServiceName == C2U( "com::sun::star::accessibility::AccessibleComponent" ) ||
02052             rServiceName == C2U( "com::sun::star::accessibility::AccessibleContext" );
02053 }
02054 
02055 Sequence< OUString > SAL_CALL SmEditAccessible::getSupportedServiceNames()
02056     throw (RuntimeException)
02057 {
02058     //vos::OGuard aGuard(Application::GetSolarMutex());
02059     Sequence< OUString > aNames(3);
02060     OUString *pNames = aNames.getArray();
02061     pNames[0] = C2U( "com::sun::star::accessibility::Accessible" );
02062     pNames[1] = C2U( "com::sun::star::accessibility::AccessibleComponent" );
02063     pNames[2] = C2U( "com::sun::star::accessibility::AccessibleContext" );
02064     return aNames;
02065 }
02066 
02068 

Generated on Wed Feb 20 17:21:56 2008 for maths by  doxygen 1.5.1