1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_svx.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir //------------------------------------------------------------------------ 26cdf0e10cSrcweir // Global header 27cdf0e10cSrcweir //------------------------------------------------------------------------ 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <limits.h> 30cdf0e10cSrcweir #include <memory> 31cdf0e10cSrcweir #include <algorithm> 32cdf0e10cSrcweir #include <deque> 33cdf0e10cSrcweir #include <vos/mutex.hxx> 34cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 35cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 36cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 37cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp> 38cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp> 39cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 40cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 41cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp> 42cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleContext.hpp> 43cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleComponent.hpp> 44cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 45cdf0e10cSrcweir #include <comphelper/accessibleeventnotifier.hxx> 46cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 47cdf0e10cSrcweir #include <vcl/unohelp.hxx> 48cdf0e10cSrcweir #include <vcl/svapp.hxx> 499b8096d0SSteve Yin //add TEXT_SELECTION_CHANGED event 509b8096d0SSteve Yin #ifndef _TEXTDATA_HXX 519b8096d0SSteve Yin #include <svtools/textdata.hxx> 529b8096d0SSteve Yin #endif 53cdf0e10cSrcweir 549b8096d0SSteve Yin #include <sfx2/viewfrm.hxx> 559b8096d0SSteve Yin #include <sfx2/viewsh.hxx> 56cdf0e10cSrcweir //------------------------------------------------------------------------ 57cdf0e10cSrcweir // Project-local header 58cdf0e10cSrcweir //------------------------------------------------------------------------ 59cdf0e10cSrcweir #include "AccessibleTextEventQueue.hxx" 60cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx> 61cdf0e10cSrcweir #include <svx/unoshape.hxx> 62cdf0e10cSrcweir #include "editeng/unolingu.hxx" 63cdf0e10cSrcweir #include <editeng/unotext.hxx> 64cdf0e10cSrcweir 65cdf0e10cSrcweir #include "editeng/unoedhlp.hxx" 66cdf0e10cSrcweir #include "editeng/unopracc.hxx" 67cdf0e10cSrcweir #include "editeng/AccessibleParaManager.hxx" 68cdf0e10cSrcweir #include "editeng/AccessibleEditableTextPara.hxx" 69cdf0e10cSrcweir #include <svx/svdmodel.hxx> 70cdf0e10cSrcweir #include <svx/svdpntv.hxx> 719b8096d0SSteve Yin #include "../table/cell.hxx" 729b8096d0SSteve Yin #include "../table/accessiblecell.hxx" 73cdf0e10cSrcweir #include <editeng/editdata.hxx> 74cdf0e10cSrcweir #include <editeng/editeng.hxx> 75cdf0e10cSrcweir #include <editeng/editview.hxx> 76cdf0e10cSrcweir 77cdf0e10cSrcweir using namespace ::com::sun::star; 78cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 79cdf0e10cSrcweir 80cdf0e10cSrcweir namespace accessibility 81cdf0e10cSrcweir { GetCurrentEditorWnd()829b8096d0SSteve Yin Window* GetCurrentEditorWnd() 839b8096d0SSteve Yin { 849b8096d0SSteve Yin Window* pWin = NULL; 859b8096d0SSteve Yin SfxViewFrame* pFrame = SfxViewFrame::Current(); 869b8096d0SSteve Yin if (pFrame) 879b8096d0SSteve Yin { 889b8096d0SSteve Yin const SfxViewShell * pViewShell = pFrame->GetViewShell(); 899b8096d0SSteve Yin if(pViewShell) 909b8096d0SSteve Yin { 919b8096d0SSteve Yin pWin = pViewShell->GetWindow(); 929b8096d0SSteve Yin } 939b8096d0SSteve Yin } 949b8096d0SSteve Yin return pWin; 959b8096d0SSteve Yin } 96cdf0e10cSrcweir 97cdf0e10cSrcweir //------------------------------------------------------------------------ 98cdf0e10cSrcweir // AccessibleTextHelper_Impl declaration 99cdf0e10cSrcweir //------------------------------------------------------------------------ 100cdf0e10cSrcweir DBG_NAME(AccessibleTextHelper_Impl)101cdf0e10cSrcweir DBG_NAME( AccessibleTextHelper_Impl ) 102cdf0e10cSrcweir 103cdf0e10cSrcweir template < typename first_type, typename second_type > 104cdf0e10cSrcweir ::std::pair< first_type, second_type > makeSortedPair( first_type first, 105cdf0e10cSrcweir second_type second ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if( first > second ) 108cdf0e10cSrcweir return ::std::make_pair( second, first ); 109cdf0e10cSrcweir else 110cdf0e10cSrcweir return ::std::make_pair( first, second ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir class AccessibleTextHelper_Impl : public SfxListener 114cdf0e10cSrcweir { 115cdf0e10cSrcweir 116cdf0e10cSrcweir public: 117cdf0e10cSrcweir typedef ::std::vector< sal_Int16 > VectorOfStates; 118cdf0e10cSrcweir 119cdf0e10cSrcweir // receive pointer to our frontend class and view window 120cdf0e10cSrcweir AccessibleTextHelper_Impl(); 121cdf0e10cSrcweir ~AccessibleTextHelper_Impl(); 122cdf0e10cSrcweir 123cdf0e10cSrcweir // XAccessibleContext child handling methods 124cdf0e10cSrcweir sal_Int32 SAL_CALL getAccessibleChildCount() SAL_THROW((uno::RuntimeException)); 125cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException)); 126cdf0e10cSrcweir 127cdf0e10cSrcweir // XAccessibleEventBroadcaster child related methods 128cdf0e10cSrcweir void SAL_CALL addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) SAL_THROW((uno::RuntimeException)); 129cdf0e10cSrcweir void SAL_CALL removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) SAL_THROW((uno::RuntimeException)); 130cdf0e10cSrcweir 131cdf0e10cSrcweir // XAccessibleComponent child related methods 132cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL getAccessibleAtPoint( const awt::Point& aPoint ) SAL_THROW((uno::RuntimeException)); 133cdf0e10cSrcweir 134cdf0e10cSrcweir SvxEditSourceAdapter& GetEditSource() const SAL_THROW((uno::RuntimeException)); 135cdf0e10cSrcweir void SetEditSource( ::std::auto_ptr< SvxEditSource > pEditSource ) SAL_THROW((uno::RuntimeException)); 136cdf0e10cSrcweir SetEventSource(const uno::Reference<XAccessible> & rInterface)137cdf0e10cSrcweir void SetEventSource( const uno::Reference< XAccessible >& rInterface ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 140cdf0e10cSrcweir mxFrontEnd = rInterface; 141cdf0e10cSrcweir } GetEventSource() const142cdf0e10cSrcweir uno::Reference< XAccessible > GetEventSource() const 143cdf0e10cSrcweir { 144cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 145cdf0e10cSrcweir return mxFrontEnd; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir void SetOffset( const Point& ); GetOffset() const149cdf0e10cSrcweir Point GetOffset() const 150cdf0e10cSrcweir { 151cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 152cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex ); Point aPoint( maOffset ); 153cdf0e10cSrcweir return aPoint; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir void SetStartIndex( sal_Int32 nOffset ); GetStartIndex() const157cdf0e10cSrcweir sal_Int32 GetStartIndex() const 158cdf0e10cSrcweir { 159cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 160cdf0e10cSrcweir // Strictly correct only with locked solar mutex, // but 161cdf0e10cSrcweir // here we rely on the fact that sal_Int32 access is 162cdf0e10cSrcweir // atomic 163cdf0e10cSrcweir return mnStartIndex; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir void SetAdditionalChildStates( const VectorOfStates& rChildStates ); 167cdf0e10cSrcweir const VectorOfStates& GetAdditionalChildStates() const; 168cdf0e10cSrcweir 169cdf0e10cSrcweir sal_Bool IsSelected() const; 170cdf0e10cSrcweir 171cdf0e10cSrcweir void Dispose(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir // do NOT hold object mutex when calling this! Danger of deadlock 174cdf0e10cSrcweir void FireEvent( const sal_Int16 nEventId, const uno::Any& rNewValue = uno::Any(), const uno::Any& rOldValue = uno::Any() ) const; 175cdf0e10cSrcweir void FireEvent( const AccessibleEventObject& rEvent ) const; 176cdf0e10cSrcweir 177cdf0e10cSrcweir void SetFocus( sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)); 178cdf0e10cSrcweir sal_Bool HaveFocus() SAL_THROW((::com::sun::star::uno::RuntimeException)); 179cdf0e10cSrcweir void SetChildFocus( sal_Int32 nChild, sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)); 180cdf0e10cSrcweir void SetShapeFocus( sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)); 181cdf0e10cSrcweir void ChangeChildFocus( sal_Int32 nNewChild ) SAL_THROW((::com::sun::star::uno::RuntimeException)); 182cdf0e10cSrcweir 183cdf0e10cSrcweir #ifdef DBG_UTIL 184cdf0e10cSrcweir void CheckInvariants() const; 185cdf0e10cSrcweir #endif 186cdf0e10cSrcweir 187cdf0e10cSrcweir // checks all children for visibility, throws away invisible ones 188cdf0e10cSrcweir void UpdateVisibleChildren( bool bBroadcastEvents=true ); 189cdf0e10cSrcweir 190*88c764bfSmseidel // check all children for changes in position and size 191cdf0e10cSrcweir void UpdateBoundRect(); 192cdf0e10cSrcweir 193cdf0e10cSrcweir // calls SetSelection on the forwarder and updates maLastSelection 194cdf0e10cSrcweir // cache. 195cdf0e10cSrcweir void UpdateSelection(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir private: 198cdf0e10cSrcweir 199cdf0e10cSrcweir // Process event queue 200cdf0e10cSrcweir void ProcessQueue(); 201cdf0e10cSrcweir 202cdf0e10cSrcweir // syntactic sugar for FireEvent GotPropertyEvent(const uno::Any & rNewValue,const sal_Int16 nEventId) const203cdf0e10cSrcweir void GotPropertyEvent( const uno::Any& rNewValue, const sal_Int16 nEventId ) const { FireEvent( nEventId, rNewValue ); } LostPropertyEvent(const uno::Any & rOldValue,const sal_Int16 nEventId) const204cdf0e10cSrcweir void LostPropertyEvent( const uno::Any& rOldValue, const sal_Int16 nEventId ) const { FireEvent( nEventId, uno::Any(), rOldValue ); } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // shutdown usage of current edit source on myself and the children. 207cdf0e10cSrcweir void ShutdownEditSource() SAL_THROW((uno::RuntimeException)); 208cdf0e10cSrcweir 209cdf0e10cSrcweir void ParagraphsMoved( sal_Int32 nFirst, sal_Int32 nMiddle, sal_Int32 nLast ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 212cdf0e10cSrcweir getNotifierClientId() const213cdf0e10cSrcweir int getNotifierClientId() const { return mnNotifierClientId; } 214cdf0e10cSrcweir 215cdf0e10cSrcweir // lock solar mutex before 216cdf0e10cSrcweir SvxTextForwarder& GetTextForwarder() const SAL_THROW((uno::RuntimeException)); 217cdf0e10cSrcweir // lock solar mutex before 218cdf0e10cSrcweir SvxViewForwarder& GetViewForwarder() const SAL_THROW((uno::RuntimeException)); 219cdf0e10cSrcweir // lock solar mutex before 220cdf0e10cSrcweir SvxEditViewForwarder& GetEditViewForwarder( sal_Bool bCreate = sal_False ) const SAL_THROW((uno::RuntimeException)); 221cdf0e10cSrcweir 222cdf0e10cSrcweir // are we in edit mode? 223cdf0e10cSrcweir sal_Bool IsActive() const SAL_THROW((uno::RuntimeException)); 224cdf0e10cSrcweir 225cdf0e10cSrcweir // our frontend class (the one implementing the actual 226cdf0e10cSrcweir // interface). That's not necessarily the one containing the impl 227cdf0e10cSrcweir // pointer! 228cdf0e10cSrcweir uno::Reference< XAccessible > mxFrontEnd; 229cdf0e10cSrcweir 230cdf0e10cSrcweir // a wrapper for the text forwarders (guarded by solar mutex) 231cdf0e10cSrcweir mutable SvxEditSourceAdapter maEditSource; 232cdf0e10cSrcweir 233cdf0e10cSrcweir // store last selection (to correctly report selection changes, guarded by solar mutex) 234cdf0e10cSrcweir ESelection maLastSelection; 235cdf0e10cSrcweir 236cdf0e10cSrcweir // cache range of visible children (guarded by solar mutex) 237cdf0e10cSrcweir sal_Int32 mnFirstVisibleChild; 238cdf0e10cSrcweir sal_Int32 mnLastVisibleChild; 239cdf0e10cSrcweir 240cdf0e10cSrcweir // offset to add to all our children (unguarded, relying on 241cdf0e10cSrcweir // the fact that sal_Int32 access is atomic) 242cdf0e10cSrcweir sal_Int32 mnStartIndex; 243cdf0e10cSrcweir 244cdf0e10cSrcweir // the object handling our children (guarded by solar mutex) 245cdf0e10cSrcweir ::accessibility::AccessibleParaManager maParaManager; 246cdf0e10cSrcweir 247cdf0e10cSrcweir // number of not-yet-closed event frames (BEGIN/END sequences) (guarded by solar mutex) 248cdf0e10cSrcweir sal_Int32 maEventOpenFrames; 249cdf0e10cSrcweir 250cdf0e10cSrcweir // Queued events from Notify() (guarded by solar mutex) 251cdf0e10cSrcweir AccessibleTextEventQueue maEventQueue; 252cdf0e10cSrcweir 253cdf0e10cSrcweir // spin lock to prevent notify in notify (guarded by solar mutex) 254cdf0e10cSrcweir sal_Bool mbInNotify; 255cdf0e10cSrcweir 256cdf0e10cSrcweir // whether the object or it's children has the focus set (guarded by solar mutex) 257cdf0e10cSrcweir sal_Bool mbGroupHasFocus; 258cdf0e10cSrcweir 259cdf0e10cSrcweir // whether we (this object) has the focus set (guarded by solar mutex) 260cdf0e10cSrcweir sal_Bool mbThisHasFocus; 261cdf0e10cSrcweir 262cdf0e10cSrcweir mutable ::osl::Mutex maMutex; 263cdf0e10cSrcweir 264cdf0e10cSrcweir /// our current offset to the containing shape/cell (guarded by maMutex) 265cdf0e10cSrcweir Point maOffset; 266cdf0e10cSrcweir 267cdf0e10cSrcweir /// client Id from AccessibleEventNotifier 268cdf0e10cSrcweir int mnNotifierClientId; 269cdf0e10cSrcweir }; 270cdf0e10cSrcweir 271cdf0e10cSrcweir //------------------------------------------------------------------------ 272cdf0e10cSrcweir // AccessibleTextHelper_Impl implementation 273cdf0e10cSrcweir //------------------------------------------------------------------------ 274cdf0e10cSrcweir AccessibleTextHelper_Impl()275cdf0e10cSrcweir AccessibleTextHelper_Impl::AccessibleTextHelper_Impl() : 276cdf0e10cSrcweir mxFrontEnd( NULL ), 277cdf0e10cSrcweir maLastSelection( EE_PARA_NOT_FOUND,EE_PARA_NOT_FOUND,EE_PARA_NOT_FOUND,EE_PARA_NOT_FOUND ), 278cdf0e10cSrcweir mnFirstVisibleChild( -1 ), 279cdf0e10cSrcweir mnLastVisibleChild( -2 ), 280cdf0e10cSrcweir mnStartIndex( 0 ), 281cdf0e10cSrcweir maEventOpenFrames( 0 ), 282cdf0e10cSrcweir mbInNotify( sal_False ), 283cdf0e10cSrcweir mbGroupHasFocus( sal_False ), 284cdf0e10cSrcweir mbThisHasFocus( sal_False ), 285cdf0e10cSrcweir maOffset(0,0), 286cdf0e10cSrcweir // well, that's strictly exception safe, though not really 287cdf0e10cSrcweir // robust. We rely on the fact that this member is constructed 288cdf0e10cSrcweir // last, and that the constructor body is empty, thus no 289cdf0e10cSrcweir // chance for exceptions once the Id is fetched. Nevertheless, 290cdf0e10cSrcweir // normally should employ RAII here... 291cdf0e10cSrcweir mnNotifierClientId(::comphelper::AccessibleEventNotifier::registerClient()) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir DBG_CTOR( AccessibleTextHelper_Impl, NULL ); 294cdf0e10cSrcweir 295cdf0e10cSrcweir #ifdef DBG_UTIL 296cdf0e10cSrcweir OSL_TRACE( "AccessibleTextHelper_Impl received ID: %d", mnNotifierClientId ); 297cdf0e10cSrcweir #endif 298cdf0e10cSrcweir } 299cdf0e10cSrcweir ~AccessibleTextHelper_Impl()300cdf0e10cSrcweir AccessibleTextHelper_Impl::~AccessibleTextHelper_Impl() 301cdf0e10cSrcweir { 302cdf0e10cSrcweir DBG_DTOR( AccessibleTextHelper_Impl, NULL ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 305cdf0e10cSrcweir 306cdf0e10cSrcweir try 307cdf0e10cSrcweir { 308cdf0e10cSrcweir // call Dispose here, too, since we've some resources not 309cdf0e10cSrcweir // automatically freed otherwise 310cdf0e10cSrcweir Dispose(); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir catch( const uno::Exception& ) {} 313cdf0e10cSrcweir } 314cdf0e10cSrcweir GetTextForwarder() const315cdf0e10cSrcweir SvxTextForwarder& AccessibleTextHelper_Impl::GetTextForwarder() const SAL_THROW((uno::RuntimeException)) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir if( !maEditSource.IsValid() ) 320cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown edit source")), mxFrontEnd); 321cdf0e10cSrcweir 322cdf0e10cSrcweir SvxTextForwarder* pTextForwarder = maEditSource.GetTextForwarder(); 323cdf0e10cSrcweir 324cdf0e10cSrcweir if( !pTextForwarder ) 325cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch text forwarder, model might be dead")), mxFrontEnd); 326cdf0e10cSrcweir 327cdf0e10cSrcweir if( pTextForwarder->IsValid() ) 328cdf0e10cSrcweir return *pTextForwarder; 329cdf0e10cSrcweir else 330cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text forwarder is invalid, model might be dead")), mxFrontEnd); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir GetViewForwarder() const333cdf0e10cSrcweir SvxViewForwarder& AccessibleTextHelper_Impl::GetViewForwarder() const SAL_THROW((uno::RuntimeException)) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 336cdf0e10cSrcweir 337cdf0e10cSrcweir if( !maEditSource.IsValid() ) 338cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown edit source")), mxFrontEnd); 339cdf0e10cSrcweir 340cdf0e10cSrcweir SvxViewForwarder* pViewForwarder = maEditSource.GetViewForwarder(); 341cdf0e10cSrcweir 342cdf0e10cSrcweir if( !pViewForwarder ) 343cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch view forwarder, model might be dead")), mxFrontEnd); 344cdf0e10cSrcweir 345cdf0e10cSrcweir if( pViewForwarder->IsValid() ) 346cdf0e10cSrcweir return *pViewForwarder; 347cdf0e10cSrcweir else 348cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, model might be dead")), mxFrontEnd); 349cdf0e10cSrcweir } 350cdf0e10cSrcweir GetEditViewForwarder(sal_Bool bCreate) const351cdf0e10cSrcweir SvxEditViewForwarder& AccessibleTextHelper_Impl::GetEditViewForwarder( sal_Bool bCreate ) const SAL_THROW((uno::RuntimeException)) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 354cdf0e10cSrcweir 355cdf0e10cSrcweir if( !maEditSource.IsValid() ) 356cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown edit source")), mxFrontEnd); 357cdf0e10cSrcweir 358cdf0e10cSrcweir SvxEditViewForwarder* pViewForwarder = maEditSource.GetEditViewForwarder( bCreate ); 359cdf0e10cSrcweir 360cdf0e10cSrcweir if( !pViewForwarder ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir if( bCreate ) 363cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch edit view forwarder, model might be dead")), mxFrontEnd); 364cdf0e10cSrcweir else 365cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No edit view forwarder, object not in edit mode")), mxFrontEnd); 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir if( pViewForwarder->IsValid() ) 369cdf0e10cSrcweir return *pViewForwarder; 370cdf0e10cSrcweir else 371cdf0e10cSrcweir { 372cdf0e10cSrcweir if( bCreate ) 373cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, model might be dead")), mxFrontEnd); 374cdf0e10cSrcweir else 375cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object not in edit mode")), mxFrontEnd); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir } 378cdf0e10cSrcweir GetEditSource() const379cdf0e10cSrcweir SvxEditSourceAdapter& AccessibleTextHelper_Impl::GetEditSource() const SAL_THROW((uno::RuntimeException)) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 382cdf0e10cSrcweir 383cdf0e10cSrcweir if( maEditSource.IsValid() ) 384cdf0e10cSrcweir return maEditSource; 385cdf0e10cSrcweir else 386cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleTextHelper_Impl::GetEditSource: no edit source")), mxFrontEnd ); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir IsSelected() const389cdf0e10cSrcweir sal_Bool AccessibleTextHelper_Impl::IsSelected() const 390cdf0e10cSrcweir { 391cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 392cdf0e10cSrcweir 393cdf0e10cSrcweir sal_Bool bRet = sal_False; 394cdf0e10cSrcweir 395cdf0e10cSrcweir try 396cdf0e10cSrcweir { 397cdf0e10cSrcweir ESelection aSelection; 398cdf0e10cSrcweir bRet = GetEditViewForwarder().GetSelection( aSelection ); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir catch( const uno::Exception& ) {} 401cdf0e10cSrcweir 402cdf0e10cSrcweir return bRet; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir 405cdf0e10cSrcweir // functor for sending child events (no stand-alone function, they are maybe not inlined) 406cdf0e10cSrcweir class AccessibleTextHelper_OffsetChildIndex : public ::std::unary_function< ::accessibility::AccessibleEditableTextPara&, void > 407cdf0e10cSrcweir { 408cdf0e10cSrcweir public: AccessibleTextHelper_OffsetChildIndex(sal_Int32 nDifference)409cdf0e10cSrcweir AccessibleTextHelper_OffsetChildIndex( sal_Int32 nDifference ) : mnDifference(nDifference) {} operator ()(::accessibility::AccessibleEditableTextPara & rPara)410cdf0e10cSrcweir void operator()( ::accessibility::AccessibleEditableTextPara& rPara ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir rPara.SetIndexInParent( rPara.GetIndexInParent() + mnDifference ); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir private: 416cdf0e10cSrcweir const sal_Int32 mnDifference; 417cdf0e10cSrcweir }; 418cdf0e10cSrcweir SetStartIndex(sal_Int32 nOffset)419cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetStartIndex( sal_Int32 nOffset ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 422cdf0e10cSrcweir 423cdf0e10cSrcweir sal_Int32 nOldOffset( mnStartIndex ); 424cdf0e10cSrcweir 425cdf0e10cSrcweir mnStartIndex = nOffset; 426cdf0e10cSrcweir 427cdf0e10cSrcweir if( nOldOffset != nOffset ) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir // update children 430cdf0e10cSrcweir AccessibleTextHelper_OffsetChildIndex aFunctor( nOffset - nOldOffset ); 431cdf0e10cSrcweir 432cdf0e10cSrcweir ::std::for_each( maParaManager.begin(), maParaManager.end(), 433cdf0e10cSrcweir AccessibleParaManager::WeakChildAdapter< AccessibleTextHelper_OffsetChildIndex > (aFunctor) ); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir } 436cdf0e10cSrcweir SetAdditionalChildStates(const VectorOfStates & rChildStates)437cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetAdditionalChildStates( const VectorOfStates& rChildStates ) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir maParaManager.SetAdditionalChildStates( rChildStates ); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir GetAdditionalChildStates() const442cdf0e10cSrcweir const AccessibleTextHelper_Impl::VectorOfStates& AccessibleTextHelper_Impl::GetAdditionalChildStates() const 443cdf0e10cSrcweir { 444cdf0e10cSrcweir return maParaManager.GetAdditionalChildStates(); 445cdf0e10cSrcweir } 446cdf0e10cSrcweir SetChildFocus(sal_Int32 nChild,sal_Bool bHaveFocus)447cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetChildFocus( sal_Int32 nChild, sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 450cdf0e10cSrcweir 451cdf0e10cSrcweir if( bHaveFocus ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir if( mbThisHasFocus ) 454cdf0e10cSrcweir SetShapeFocus( sal_False ); 455cdf0e10cSrcweir 456cdf0e10cSrcweir maParaManager.SetFocus( nChild ); 457cdf0e10cSrcweir 458cdf0e10cSrcweir // we just received the focus, also send caret event then 459cdf0e10cSrcweir UpdateSelection(); 460cdf0e10cSrcweir 461cdf0e10cSrcweir DBG_TRACE1("AccessibleTextHelper_Impl::SetChildFocus(): Paragraph %d received focus", nChild ); 462cdf0e10cSrcweir } 463cdf0e10cSrcweir else 464cdf0e10cSrcweir { 465cdf0e10cSrcweir maParaManager.SetFocus( -1 ); 466cdf0e10cSrcweir 467cdf0e10cSrcweir DBG_TRACE1("AccessibleTextHelper_Impl::SetChildFocus(): Paragraph %d lost focus", nChild ); 468cdf0e10cSrcweir 469cdf0e10cSrcweir if( mbGroupHasFocus ) 470cdf0e10cSrcweir SetShapeFocus( sal_True ); 471cdf0e10cSrcweir } 472cdf0e10cSrcweir } 473cdf0e10cSrcweir ChangeChildFocus(sal_Int32 nNewChild)474cdf0e10cSrcweir void AccessibleTextHelper_Impl::ChangeChildFocus( sal_Int32 nNewChild ) SAL_THROW((::com::sun::star::uno::RuntimeException)) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 477cdf0e10cSrcweir 478cdf0e10cSrcweir if( mbThisHasFocus ) 479cdf0e10cSrcweir SetShapeFocus( sal_False ); 480cdf0e10cSrcweir 481cdf0e10cSrcweir mbGroupHasFocus = sal_True; 482cdf0e10cSrcweir maParaManager.SetFocus( nNewChild ); 483cdf0e10cSrcweir 484cdf0e10cSrcweir DBG_TRACE1("AccessibleTextHelper_Impl::ChangeChildFocus(): Paragraph %d received focus", nNewChild ); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir SetShapeFocus(sal_Bool bHaveFocus)487cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetShapeFocus( sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 490cdf0e10cSrcweir 491cdf0e10cSrcweir sal_Bool bOldFocus( mbThisHasFocus ); 492cdf0e10cSrcweir 493cdf0e10cSrcweir mbThisHasFocus = bHaveFocus; 494cdf0e10cSrcweir 495cdf0e10cSrcweir if( bOldFocus != bHaveFocus ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir if( bHaveFocus ) 498cdf0e10cSrcweir { 4999b8096d0SSteve Yin if( mxFrontEnd.is() ) 5009b8096d0SSteve Yin { 5019b8096d0SSteve Yin AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); 5029b8096d0SSteve Yin if ( !pAccessibleCell ) 503cdf0e10cSrcweir GotPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); 5040deba7fbSSteve Yin else // the focus event on cell should be fired on table directly 5059b8096d0SSteve Yin { 5069b8096d0SSteve Yin AccessibleTableShape* pAccTable = pAccessibleCell->GetParentTable(); 5079b8096d0SSteve Yin if (pAccTable) 5089b8096d0SSteve Yin pAccTable->SetStateDirectly(AccessibleStateType::FOCUSED); 5099b8096d0SSteve Yin } 5109b8096d0SSteve Yin } 511cdf0e10cSrcweir DBG_TRACE("AccessibleTextHelper_Impl::SetShapeFocus(): Parent object received focus" ); 512cdf0e10cSrcweir } 513cdf0e10cSrcweir else 514cdf0e10cSrcweir { 5159b8096d0SSteve Yin // The focus state should be reset directly on table. 5169b8096d0SSteve Yin //LostPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); 5179b8096d0SSteve Yin if( mxFrontEnd.is() ) 5189b8096d0SSteve Yin { 5199b8096d0SSteve Yin AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); 5209b8096d0SSteve Yin if ( !pAccessibleCell ) 521cdf0e10cSrcweir LostPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); 5229b8096d0SSteve Yin else 5239b8096d0SSteve Yin { 5249b8096d0SSteve Yin AccessibleTableShape* pAccTable = pAccessibleCell->GetParentTable(); 5259b8096d0SSteve Yin if (pAccTable) 5269b8096d0SSteve Yin pAccTable->ResetStateDirectly(AccessibleStateType::FOCUSED); 5279b8096d0SSteve Yin } 5289b8096d0SSteve Yin } 529cdf0e10cSrcweir DBG_TRACE("AccessibleTextHelper_Impl::SetShapeFocus(): Parent object lost focus" ); 530cdf0e10cSrcweir } 531cdf0e10cSrcweir } 532cdf0e10cSrcweir } 533cdf0e10cSrcweir SetFocus(sal_Bool bHaveFocus)534cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetFocus( sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 537cdf0e10cSrcweir 538cdf0e10cSrcweir sal_Bool bOldFocus( mbGroupHasFocus ); 539cdf0e10cSrcweir 540cdf0e10cSrcweir mbGroupHasFocus = bHaveFocus; 541cdf0e10cSrcweir 542cdf0e10cSrcweir if( IsActive() ) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir try 545cdf0e10cSrcweir { 546cdf0e10cSrcweir // find the one with the cursor and get/set focus accordingly 547cdf0e10cSrcweir ESelection aSelection; 548cdf0e10cSrcweir if( GetEditViewForwarder().GetSelection( aSelection ) ) 549cdf0e10cSrcweir SetChildFocus( aSelection.nEndPara, bHaveFocus ); 550cdf0e10cSrcweir } 551cdf0e10cSrcweir catch( const uno::Exception& ) {} 552cdf0e10cSrcweir } 553cdf0e10cSrcweir else if( bOldFocus != bHaveFocus ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir SetShapeFocus( bHaveFocus ); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir DBG_TRACE2("AccessibleTextHelper_Impl::SetFocus: focus changed, Object %d, state: %s", this, bHaveFocus ? "focused" : "not focused"); 559cdf0e10cSrcweir } 560cdf0e10cSrcweir HaveFocus()561cdf0e10cSrcweir sal_Bool AccessibleTextHelper_Impl::HaveFocus() SAL_THROW((::com::sun::star::uno::RuntimeException)) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 564cdf0e10cSrcweir 565cdf0e10cSrcweir // No locking of solar mutex here, since we rely on the fact 566cdf0e10cSrcweir // that sal_Bool access is atomic 567cdf0e10cSrcweir return mbThisHasFocus; 568cdf0e10cSrcweir } 569cdf0e10cSrcweir IsActive() const570cdf0e10cSrcweir sal_Bool AccessibleTextHelper_Impl::IsActive() const SAL_THROW((uno::RuntimeException)) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir try 575cdf0e10cSrcweir { 576cdf0e10cSrcweir SvxEditSource& rEditSource = GetEditSource(); 577cdf0e10cSrcweir SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder(); 578cdf0e10cSrcweir 579cdf0e10cSrcweir if( !pViewForwarder ) 580cdf0e10cSrcweir return sal_False; 581cdf0e10cSrcweir 5829b8096d0SSteve Yin if( mxFrontEnd.is() ) 5839b8096d0SSteve Yin { 5849b8096d0SSteve Yin AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); 5859b8096d0SSteve Yin if ( pAccessibleCell ) 5869b8096d0SSteve Yin { 5879b8096d0SSteve Yin sdr::table::CellRef xCell = pAccessibleCell->getCellRef(); 5889b8096d0SSteve Yin if ( xCell.is() ) 5899b8096d0SSteve Yin return xCell->IsTextEditActive(); 5909b8096d0SSteve Yin } 5919b8096d0SSteve Yin } 592cdf0e10cSrcweir if( pViewForwarder->IsValid() ) 593cdf0e10cSrcweir return sal_True; 594cdf0e10cSrcweir else 595cdf0e10cSrcweir return sal_False; 596cdf0e10cSrcweir } 597cdf0e10cSrcweir catch( const uno::RuntimeException& ) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir return sal_False; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir } 602cdf0e10cSrcweir UpdateSelection()603cdf0e10cSrcweir void AccessibleTextHelper_Impl::UpdateSelection() 604cdf0e10cSrcweir { 605cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 606cdf0e10cSrcweir 607cdf0e10cSrcweir try 608cdf0e10cSrcweir { 609cdf0e10cSrcweir ESelection aSelection; 610cdf0e10cSrcweir if( GetEditViewForwarder().GetSelection( aSelection ) ) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir if( !maLastSelection.IsEqual( aSelection ) && 613cdf0e10cSrcweir aSelection.nEndPara < maParaManager.GetNum() ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir // #103998# Not that important, changed from assertion to trace 616cdf0e10cSrcweir if( mbThisHasFocus ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir DBG_TRACE("AccessibleTextHelper_Impl::UpdateSelection(): Parent has focus!"); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621c2eaa082SDamjan Jovanovic sal_uInt32 nMaxValidParaIndex( GetTextForwarder().GetParagraphCount() - 1 ); 622cdf0e10cSrcweir 623cdf0e10cSrcweir // notify all affected paragraphs (TODO: may be suboptimal, 624cdf0e10cSrcweir // since some paragraphs might stay selected) 625cdf0e10cSrcweir if( maLastSelection.nStartPara != EE_PARA_NOT_FOUND ) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir // Did the caret move from one paragraph to another? 628cdf0e10cSrcweir // #100530# no caret events if not focused. 629cdf0e10cSrcweir if( mbGroupHasFocus && 630cdf0e10cSrcweir maLastSelection.nEndPara != aSelection.nEndPara ) 631cdf0e10cSrcweir { 632cdf0e10cSrcweir if( maLastSelection.nEndPara < maParaManager.GetNum() ) 633cdf0e10cSrcweir { 634cdf0e10cSrcweir maParaManager.FireEvent( ::std::min( maLastSelection.nEndPara, nMaxValidParaIndex ), 635cdf0e10cSrcweir ::std::min( maLastSelection.nEndPara, nMaxValidParaIndex )+1, 636cdf0e10cSrcweir AccessibleEventId::CARET_CHANGED, 637cdf0e10cSrcweir uno::makeAny(static_cast<sal_Int32>(-1)), 638cdf0e10cSrcweir uno::makeAny(static_cast<sal_Int32>(maLastSelection.nEndPos)) ); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir ChangeChildFocus( aSelection.nEndPara ); 642cdf0e10cSrcweir 643cdf0e10cSrcweir DBG_TRACE3("AccessibleTextHelper_Impl::UpdateSelection(): focus changed, Object: %d, Paragraph: %d, Last paragraph: %d", 644cdf0e10cSrcweir this, aSelection.nEndPara, maLastSelection.nEndPara); 645cdf0e10cSrcweir } 646cdf0e10cSrcweir } 647cdf0e10cSrcweir 648cdf0e10cSrcweir // #100530# no caret events if not focused. 649cdf0e10cSrcweir if( mbGroupHasFocus ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir uno::Any aOldCursor; 652cdf0e10cSrcweir 653cdf0e10cSrcweir // #i13705# The old cursor can only contain valid 654cdf0e10cSrcweir // values if it's the same paragraph! 655cdf0e10cSrcweir if( maLastSelection.nStartPara != EE_PARA_NOT_FOUND && 656cdf0e10cSrcweir maLastSelection.nEndPara == aSelection.nEndPara ) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir aOldCursor <<= static_cast<sal_Int32>(maLastSelection.nEndPos); 659cdf0e10cSrcweir } 660cdf0e10cSrcweir else 661cdf0e10cSrcweir { 662cdf0e10cSrcweir aOldCursor <<= static_cast<sal_Int32>(-1); 663cdf0e10cSrcweir } 664cdf0e10cSrcweir 665cdf0e10cSrcweir maParaManager.FireEvent( aSelection.nEndPara, 666cdf0e10cSrcweir aSelection.nEndPara+1, 667cdf0e10cSrcweir AccessibleEventId::CARET_CHANGED, 668cdf0e10cSrcweir uno::makeAny(static_cast<sal_Int32>(aSelection.nEndPos)), 669cdf0e10cSrcweir aOldCursor ); 670cdf0e10cSrcweir } 671cdf0e10cSrcweir 672cdf0e10cSrcweir DBG_TRACE5("AccessibleTextHelper_Impl::UpdateSelection(): caret changed, Object: %d, New pos: %d, Old pos: %d, New para: %d, Old para: %d", 673cdf0e10cSrcweir this, aSelection.nEndPos, maLastSelection.nEndPos, aSelection.nEndPara, maLastSelection.nEndPara); 674cdf0e10cSrcweir 675cdf0e10cSrcweir // #108947# Sort new range before calling FireEvent 676cdf0e10cSrcweir ::std::pair< xub_StrLen, xub_StrLen > sortedSelection( 677cdf0e10cSrcweir makeSortedPair(::std::min( aSelection.nStartPara, nMaxValidParaIndex ), 678cdf0e10cSrcweir ::std::min( aSelection.nEndPara, nMaxValidParaIndex ) ) ); 679cdf0e10cSrcweir 680cdf0e10cSrcweir // #108947# Sort last range before calling FireEvent 681cdf0e10cSrcweir ::std::pair< xub_StrLen, xub_StrLen > sortedLastSelection( 682cdf0e10cSrcweir makeSortedPair(::std::min( maLastSelection.nStartPara, nMaxValidParaIndex ), 683cdf0e10cSrcweir ::std::min( maLastSelection.nEndPara, nMaxValidParaIndex ) ) ); 684cdf0e10cSrcweir 685cdf0e10cSrcweir // --> OD 2005-12-15 #i27299# 686cdf0e10cSrcweir // event TEXT_SELECTION_CHANGED has to be submitted. 687cdf0e10cSrcweir const sal_Int16 nTextSelChgEventId = 688cdf0e10cSrcweir AccessibleEventId::TEXT_SELECTION_CHANGED; 689cdf0e10cSrcweir // <-- 690cdf0e10cSrcweir // #107037# notify selection change 691cdf0e10cSrcweir if( maLastSelection.nStartPara == EE_PARA_NOT_FOUND ) 692cdf0e10cSrcweir { 693cdf0e10cSrcweir // last selection is undefined 694cdf0e10cSrcweir // --> OD 2005-12-15 #i27299# - use method <ESelection::HasRange()> 695cdf0e10cSrcweir if ( aSelection.HasRange() ) 696cdf0e10cSrcweir // <-- 697cdf0e10cSrcweir { 698cdf0e10cSrcweir // selection was undefined, now is on 699cdf0e10cSrcweir maParaManager.FireEvent( sortedSelection.first, 700cdf0e10cSrcweir sortedSelection.second+1, 701cdf0e10cSrcweir nTextSelChgEventId ); 702cdf0e10cSrcweir } 703cdf0e10cSrcweir } 704cdf0e10cSrcweir else 705cdf0e10cSrcweir { 706cdf0e10cSrcweir // last selection is valid 707cdf0e10cSrcweir // --> OD 2005-12-15 #i27299# - use method <ESelection::HasRange()> 708cdf0e10cSrcweir if ( maLastSelection.HasRange() && 709cdf0e10cSrcweir !aSelection.HasRange() ) 710cdf0e10cSrcweir // <-- 711cdf0e10cSrcweir { 712cdf0e10cSrcweir // selection was on, now is empty 713cdf0e10cSrcweir maParaManager.FireEvent( sortedLastSelection.first, 714cdf0e10cSrcweir sortedLastSelection.second+1, 715cdf0e10cSrcweir nTextSelChgEventId ); 716cdf0e10cSrcweir } 717cdf0e10cSrcweir // --> OD 2005-12-15 #i27299# - use method <ESelection::HasRange()> 718cdf0e10cSrcweir else if( !maLastSelection.HasRange() && 719cdf0e10cSrcweir aSelection.HasRange() ) 720cdf0e10cSrcweir // <-- 721cdf0e10cSrcweir { 722cdf0e10cSrcweir // selection was empty, now is on 723cdf0e10cSrcweir maParaManager.FireEvent( sortedSelection.first, 724cdf0e10cSrcweir sortedSelection.second+1, 725cdf0e10cSrcweir nTextSelChgEventId ); 726cdf0e10cSrcweir } 727cdf0e10cSrcweir // --> OD 2005-12-15 #i27299# 728cdf0e10cSrcweir // - no event TEXT_SELECTION_CHANGED event, if new and 729cdf0e10cSrcweir // last selection are empty. 730cdf0e10cSrcweir else if ( maLastSelection.HasRange() && 731cdf0e10cSrcweir aSelection.HasRange() ) 732cdf0e10cSrcweir // <-- 733cdf0e10cSrcweir { 734cdf0e10cSrcweir // --> OD 2005-12-16 #i27299# 735cdf0e10cSrcweir // - send event TEXT_SELECTION_CHANGED for difference 736cdf0e10cSrcweir // between last and new selection. 737cdf0e10cSrcweir // // selection was on, now is different: take union of ranges 738cdf0e10cSrcweir // maParaManager.FireEvent( ::std::min(sortedSelection.first, 739cdf0e10cSrcweir // sortedLastSelection.second), 740cdf0e10cSrcweir // ::std::max(sortedSelection.first, 741cdf0e10cSrcweir // sortedLastSelection.second)+1, 742cdf0e10cSrcweir // nTextSelChgEventId ); 743cdf0e10cSrcweir // use sorted last and new selection 744cdf0e10cSrcweir ESelection aTmpLastSel( maLastSelection ); 745cdf0e10cSrcweir aTmpLastSel.Adjust(); 746cdf0e10cSrcweir ESelection aTmpSel( aSelection ); 747cdf0e10cSrcweir aTmpSel.Adjust(); 748cdf0e10cSrcweir // first submit event for new and changed selection 749cdf0e10cSrcweir sal_uInt32 nPara = aTmpSel.nStartPara; 750cdf0e10cSrcweir for ( ; nPara <= aTmpSel.nEndPara; ++nPara ) 751cdf0e10cSrcweir { 752cdf0e10cSrcweir if ( nPara < aTmpLastSel.nStartPara || 753cdf0e10cSrcweir nPara > aTmpLastSel.nEndPara ) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir // new selection on paragraph <nPara> 756cdf0e10cSrcweir maParaManager.FireEvent( nPara, 757cdf0e10cSrcweir nTextSelChgEventId ); 758cdf0e10cSrcweir } 759cdf0e10cSrcweir else 760cdf0e10cSrcweir { 761cdf0e10cSrcweir // check for changed selection on paragraph <nPara> 762cdf0e10cSrcweir const xub_StrLen nParaStartPos = 763cdf0e10cSrcweir nPara == aTmpSel.nStartPara 764cdf0e10cSrcweir ? aTmpSel.nStartPos : 0; 765cdf0e10cSrcweir const xub_StrLen nParaEndPos = 766cdf0e10cSrcweir nPara == aTmpSel.nEndPara 767cdf0e10cSrcweir ? aTmpSel.nEndPos : STRING_LEN; 768cdf0e10cSrcweir const xub_StrLen nLastParaStartPos = 769cdf0e10cSrcweir nPara == aTmpLastSel.nStartPara 770cdf0e10cSrcweir ? aTmpLastSel.nStartPos : 0; 771cdf0e10cSrcweir const xub_StrLen nLastParaEndPos = 772cdf0e10cSrcweir nPara == aTmpLastSel.nEndPara 773cdf0e10cSrcweir ? aTmpLastSel.nEndPos : STRING_LEN; 774cdf0e10cSrcweir if ( nParaStartPos != nLastParaStartPos || 775cdf0e10cSrcweir nParaEndPos != nLastParaEndPos ) 776cdf0e10cSrcweir { 777cdf0e10cSrcweir maParaManager.FireEvent( 778cdf0e10cSrcweir nPara, nTextSelChgEventId ); 779cdf0e10cSrcweir } 780cdf0e10cSrcweir } 781cdf0e10cSrcweir } 782cdf0e10cSrcweir // second submit event for 'old' selections 783cdf0e10cSrcweir nPara = aTmpLastSel.nStartPara; 784cdf0e10cSrcweir for ( ; nPara <= aTmpLastSel.nEndPara; ++nPara ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir if ( nPara < aTmpSel.nStartPara || 787cdf0e10cSrcweir nPara > aTmpSel.nEndPara ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir maParaManager.FireEvent( nPara, 790cdf0e10cSrcweir nTextSelChgEventId ); 791cdf0e10cSrcweir } 792cdf0e10cSrcweir } 793cdf0e10cSrcweir } 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir maLastSelection = aSelection; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir } 799cdf0e10cSrcweir } 800cdf0e10cSrcweir // no selection? no update actions 801cdf0e10cSrcweir catch( const uno::RuntimeException& ) {} 802cdf0e10cSrcweir } 803cdf0e10cSrcweir ShutdownEditSource()804cdf0e10cSrcweir void AccessibleTextHelper_Impl::ShutdownEditSource() SAL_THROW((uno::RuntimeException)) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 807cdf0e10cSrcweir 808cdf0e10cSrcweir // This should only be called with solar mutex locked, i.e. from the main office thread 809cdf0e10cSrcweir 810cdf0e10cSrcweir // This here is somewhat clumsy: As soon as our children have 811cdf0e10cSrcweir // a NULL EditSource (maParaManager.SetEditSource()), they 812cdf0e10cSrcweir // enter the disposed state and cannot be reanimated. Thus, it 813cdf0e10cSrcweir // is unavoidable and a hard requirement to let go and create 814cdf0e10cSrcweir // from scratch each and every child. 815cdf0e10cSrcweir 816cdf0e10cSrcweir // invalidate children 817cdf0e10cSrcweir maParaManager.Dispose(); 818cdf0e10cSrcweir maParaManager.SetNum(0); 819cdf0e10cSrcweir 820cdf0e10cSrcweir // lost all children 821cdf0e10cSrcweir if( mxFrontEnd.is() ) 822cdf0e10cSrcweir FireEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN); 823cdf0e10cSrcweir 824cdf0e10cSrcweir // quit listen on stale edit source 825cdf0e10cSrcweir if( maEditSource.IsValid() ) 826cdf0e10cSrcweir EndListening( maEditSource.GetBroadcaster() ); 827cdf0e10cSrcweir 828cdf0e10cSrcweir maEditSource.SetEditSource( ::std::auto_ptr< SvxEditSource >(NULL) ); 829cdf0e10cSrcweir } 830cdf0e10cSrcweir SetEditSource(::std::auto_ptr<SvxEditSource> pEditSource)831cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetEditSource( ::std::auto_ptr< SvxEditSource > pEditSource ) SAL_THROW((uno::RuntimeException)) 832cdf0e10cSrcweir { 833cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 834cdf0e10cSrcweir 835cdf0e10cSrcweir // This should only be called with solar mutex locked, i.e. from the main office thread 836cdf0e10cSrcweir 837cdf0e10cSrcweir // shutdown old edit source 838cdf0e10cSrcweir ShutdownEditSource(); 839cdf0e10cSrcweir 840cdf0e10cSrcweir // set new edit source 841cdf0e10cSrcweir maEditSource.SetEditSource( pEditSource ); 842cdf0e10cSrcweir 843cdf0e10cSrcweir // init child vector to the current child count 844cdf0e10cSrcweir if( maEditSource.IsValid() ) 845cdf0e10cSrcweir { 846cdf0e10cSrcweir maParaManager.SetNum( GetTextForwarder().GetParagraphCount() ); 847cdf0e10cSrcweir 848cdf0e10cSrcweir // listen on new edit source 849cdf0e10cSrcweir StartListening( maEditSource.GetBroadcaster() ); 850cdf0e10cSrcweir 851cdf0e10cSrcweir UpdateVisibleChildren(); 852cdf0e10cSrcweir } 853cdf0e10cSrcweir } 854cdf0e10cSrcweir SetOffset(const Point & rPoint)855cdf0e10cSrcweir void AccessibleTextHelper_Impl::SetOffset( const Point& rPoint ) 856cdf0e10cSrcweir { 857cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 858cdf0e10cSrcweir 859cdf0e10cSrcweir // guard against non-atomic access to maOffset data structure 860cdf0e10cSrcweir { 861cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex ); 862cdf0e10cSrcweir maOffset = rPoint; 863cdf0e10cSrcweir } 864cdf0e10cSrcweir 865cdf0e10cSrcweir maParaManager.SetEEOffset( rPoint ); 866cdf0e10cSrcweir 867cdf0e10cSrcweir // in all cases, check visibility afterwards. 868cdf0e10cSrcweir UpdateVisibleChildren(); 869cdf0e10cSrcweir UpdateBoundRect(); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir UpdateVisibleChildren(bool bBroadcastEvents)872cdf0e10cSrcweir void AccessibleTextHelper_Impl::UpdateVisibleChildren( bool bBroadcastEvents ) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 875cdf0e10cSrcweir 876cdf0e10cSrcweir try 877cdf0e10cSrcweir { 878cdf0e10cSrcweir SvxTextForwarder& rCacheTF = GetTextForwarder(); 879cdf0e10cSrcweir SvxViewForwarder& rCacheVF = GetViewForwarder(); 880cdf0e10cSrcweir 881cdf0e10cSrcweir Rectangle aViewArea = rCacheVF.GetVisArea(); 882cdf0e10cSrcweir 883cdf0e10cSrcweir if( IsActive() ) 884cdf0e10cSrcweir { 885cdf0e10cSrcweir // maybe the edit view scrolls, adapt aViewArea 886cdf0e10cSrcweir Rectangle aEditViewArea = GetEditViewForwarder().GetVisArea(); 887cdf0e10cSrcweir aViewArea += aEditViewArea.TopLeft(); 888cdf0e10cSrcweir 889cdf0e10cSrcweir // now determine intersection 890cdf0e10cSrcweir aViewArea.Intersection( aEditViewArea ); 891cdf0e10cSrcweir } 892cdf0e10cSrcweir 893cdf0e10cSrcweir Rectangle aTmpBB, aParaBB; 894cdf0e10cSrcweir sal_Bool bFirstChild = sal_True; 895cdf0e10cSrcweir sal_Int32 nCurrPara; 896cdf0e10cSrcweir sal_Int32 nParas=rCacheTF.GetParagraphCount(); 897cdf0e10cSrcweir 898cdf0e10cSrcweir mnFirstVisibleChild = -1; 899cdf0e10cSrcweir mnLastVisibleChild = -2; 900cdf0e10cSrcweir 901cdf0e10cSrcweir for( nCurrPara=0; nCurrPara<nParas; ++nCurrPara ) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir DBG_ASSERT(nCurrPara >= 0 && nCurrPara <= USHRT_MAX, 904cdf0e10cSrcweir "AccessibleTextHelper_Impl::UpdateVisibleChildren: index value overflow"); 905cdf0e10cSrcweir 906c2eaa082SDamjan Jovanovic aTmpBB = rCacheTF.GetParaBounds( nCurrPara ); 907cdf0e10cSrcweir 908cdf0e10cSrcweir // convert to screen coordinates 909cdf0e10cSrcweir aParaBB = ::accessibility::AccessibleEditableTextPara::LogicToPixel( aTmpBB, rCacheTF.GetMapMode(), rCacheVF ); 9103ea0c3d5SHerbert Dürr 911cdf0e10cSrcweir // at least partially visible 912cdf0e10cSrcweir if( bFirstChild ) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir bFirstChild = sal_False; 915cdf0e10cSrcweir mnFirstVisibleChild = nCurrPara; 916cdf0e10cSrcweir } 917cdf0e10cSrcweir 918cdf0e10cSrcweir mnLastVisibleChild = nCurrPara; 919cdf0e10cSrcweir 920cdf0e10cSrcweir // child not yet created? 921cdf0e10cSrcweir ::accessibility::AccessibleParaManager::WeakChild aChild( maParaManager.GetChild(nCurrPara) ); 922cdf0e10cSrcweir if( aChild.second.Width == 0 && 923cdf0e10cSrcweir aChild.second.Height == 0 && 924cdf0e10cSrcweir mxFrontEnd.is() && 925cdf0e10cSrcweir bBroadcastEvents ) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir GotPropertyEvent( uno::makeAny( maParaManager.CreateChild( nCurrPara - mnFirstVisibleChild, 928cdf0e10cSrcweir mxFrontEnd, GetEditSource(), nCurrPara ).first ), 929cdf0e10cSrcweir AccessibleEventId::CHILD ); 930cdf0e10cSrcweir } 931cdf0e10cSrcweir } 932cdf0e10cSrcweir } 933cdf0e10cSrcweir catch( const uno::Exception& ) 934cdf0e10cSrcweir { 935cdf0e10cSrcweir DBG_ERROR("AccessibleTextHelper_Impl::UpdateVisibleChildren error while determining visible children"); 936cdf0e10cSrcweir 937cdf0e10cSrcweir // something failed - currently no children 938cdf0e10cSrcweir mnFirstVisibleChild = -1; 939cdf0e10cSrcweir mnLastVisibleChild = -2; 940cdf0e10cSrcweir maParaManager.SetNum(0); 941cdf0e10cSrcweir 942cdf0e10cSrcweir // lost all children 943cdf0e10cSrcweir if( bBroadcastEvents ) 944cdf0e10cSrcweir FireEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN); 945cdf0e10cSrcweir } 946cdf0e10cSrcweir } 947cdf0e10cSrcweir 948cdf0e10cSrcweir // functor for checking changes in paragraph bounding boxes (no stand-alone function, maybe not inlined) 949cdf0e10cSrcweir class AccessibleTextHelper_UpdateChildBounds : public ::std::unary_function< const ::accessibility::AccessibleParaManager::WeakChild&, 950cdf0e10cSrcweir ::accessibility::AccessibleParaManager::WeakChild > 951cdf0e10cSrcweir { 952cdf0e10cSrcweir public: AccessibleTextHelper_UpdateChildBounds(AccessibleTextHelper_Impl & rImpl)953cdf0e10cSrcweir AccessibleTextHelper_UpdateChildBounds( AccessibleTextHelper_Impl& rImpl ) : mrImpl(rImpl) {} operator ()(const::accessibility::AccessibleParaManager::WeakChild & rChild)954cdf0e10cSrcweir ::accessibility::AccessibleParaManager::WeakChild operator()( const ::accessibility::AccessibleParaManager::WeakChild& rChild ) 955cdf0e10cSrcweir { 956cdf0e10cSrcweir // retrieve hard reference from weak one 957cdf0e10cSrcweir ::accessibility::AccessibleParaManager::WeakPara::HardRefType aHardRef( rChild.first.get() ); 958cdf0e10cSrcweir 959cdf0e10cSrcweir if( aHardRef.is() ) 960cdf0e10cSrcweir { 961cdf0e10cSrcweir awt::Rectangle aNewRect = aHardRef->getBounds(); 962cdf0e10cSrcweir const awt::Rectangle& aOldRect = rChild.second; 963cdf0e10cSrcweir 964cdf0e10cSrcweir if( aNewRect.X != aOldRect.X || 965cdf0e10cSrcweir aNewRect.Y != aOldRect.Y || 966cdf0e10cSrcweir aNewRect.Width != aOldRect.Width || 967cdf0e10cSrcweir aNewRect.Height != aOldRect.Height ) 968cdf0e10cSrcweir { 969cdf0e10cSrcweir // visible data changed 970cdf0e10cSrcweir aHardRef->FireEvent( AccessibleEventId::BOUNDRECT_CHANGED ); 971cdf0e10cSrcweir 972cdf0e10cSrcweir // update internal bounds 973cdf0e10cSrcweir return ::accessibility::AccessibleParaManager::WeakChild( rChild.first, aNewRect ); 974cdf0e10cSrcweir } 975cdf0e10cSrcweir } 976cdf0e10cSrcweir 977cdf0e10cSrcweir // identity transform 978cdf0e10cSrcweir return rChild; 979cdf0e10cSrcweir } 980cdf0e10cSrcweir 981cdf0e10cSrcweir private: 982cdf0e10cSrcweir AccessibleTextHelper_Impl& mrImpl; 983cdf0e10cSrcweir }; 984cdf0e10cSrcweir UpdateBoundRect()985cdf0e10cSrcweir void AccessibleTextHelper_Impl::UpdateBoundRect() 986cdf0e10cSrcweir { 987cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 988cdf0e10cSrcweir 989cdf0e10cSrcweir // send BOUNDRECT_CHANGED to affected children 990cdf0e10cSrcweir AccessibleTextHelper_UpdateChildBounds aFunctor( *this ); 991cdf0e10cSrcweir ::std::transform( maParaManager.begin(), maParaManager.end(), maParaManager.begin(), aFunctor ); 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir #ifdef DBG_UTIL CheckInvariants() const995cdf0e10cSrcweir void AccessibleTextHelper_Impl::CheckInvariants() const 996cdf0e10cSrcweir { 997cdf0e10cSrcweir if( mnFirstVisibleChild >= 0 && 998cdf0e10cSrcweir mnFirstVisibleChild > mnLastVisibleChild ) 999cdf0e10cSrcweir { 1000cdf0e10cSrcweir DBG_ERROR( "AccessibleTextHelper: range invalid" ); 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir } 1003cdf0e10cSrcweir #endif 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir // functor for sending child events (no stand-alone function, they are maybe not inlined) 1006cdf0e10cSrcweir class AccessibleTextHelper_LostChildEvent : public ::std::unary_function< const ::accessibility::AccessibleParaManager::WeakChild&, void > 1007cdf0e10cSrcweir { 1008cdf0e10cSrcweir public: AccessibleTextHelper_LostChildEvent(AccessibleTextHelper_Impl & rImpl)1009cdf0e10cSrcweir AccessibleTextHelper_LostChildEvent( AccessibleTextHelper_Impl& rImpl ) : mrImpl(rImpl) {} operator ()(const::accessibility::AccessibleParaManager::WeakChild & rPara)1010cdf0e10cSrcweir void operator()( const ::accessibility::AccessibleParaManager::WeakChild& rPara ) 1011cdf0e10cSrcweir { 1012cdf0e10cSrcweir // retrieve hard reference from weak one 1013cdf0e10cSrcweir ::accessibility::AccessibleParaManager::WeakPara::HardRefType aHardRef( rPara.first.get() ); 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir if( aHardRef.is() ) 1016cdf0e10cSrcweir mrImpl.FireEvent(AccessibleEventId::CHILD, uno::Any(), uno::makeAny( aHardRef.getRef() ) ); 1017cdf0e10cSrcweir } 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir private: 1020cdf0e10cSrcweir AccessibleTextHelper_Impl& mrImpl; 1021cdf0e10cSrcweir }; 1022cdf0e10cSrcweir ParagraphsMoved(sal_Int32 nFirst,sal_Int32 nMiddle,sal_Int32 nLast)1023cdf0e10cSrcweir void AccessibleTextHelper_Impl::ParagraphsMoved( sal_Int32 nFirst, sal_Int32 nMiddle, sal_Int32 nLast ) 1024cdf0e10cSrcweir { 1025cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir const sal_Int32 nParas = GetTextForwarder().GetParagraphCount(); 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir /* rotate paragraphs 1030cdf0e10cSrcweir * ================= 1031cdf0e10cSrcweir * 1032cdf0e10cSrcweir * Three cases: 1033cdf0e10cSrcweir * 1034cdf0e10cSrcweir * 1. 1035cdf0e10cSrcweir * ... nParagraph ... nParam1 ... nParam2 ... 1036cdf0e10cSrcweir * |______________[xxxxxxxxxxx] 1037cdf0e10cSrcweir * becomes 1038cdf0e10cSrcweir * [xxxxxxxxxxx]|______________ 1039cdf0e10cSrcweir * 1040cdf0e10cSrcweir * tail is 0 1041cdf0e10cSrcweir * 1042cdf0e10cSrcweir * 2. 1043cdf0e10cSrcweir * ... nParam1 ... nParagraph ... nParam2 ... 1044cdf0e10cSrcweir * [xxxxxxxxxxx|xxxxxxxxxxxxxx]____________ 1045cdf0e10cSrcweir * becomes 1046cdf0e10cSrcweir * ____________[xxxxxxxxxxx|xxxxxxxxxxxxxx] 1047cdf0e10cSrcweir * 1048cdf0e10cSrcweir * tail is nParagraph - nParam1 1049cdf0e10cSrcweir * 1050cdf0e10cSrcweir * 3. 1051cdf0e10cSrcweir * ... nParam1 ... nParam2 ... nParagraph ... 1052cdf0e10cSrcweir * [xxxxxxxxxxx]___________|____________ 1053cdf0e10cSrcweir * becomes 1054cdf0e10cSrcweir * ___________|____________[xxxxxxxxxxx] 1055cdf0e10cSrcweir * 1056cdf0e10cSrcweir * tail is nParam2 - nParam1 1057cdf0e10cSrcweir */ 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir // sort nParagraph, nParam1 and nParam2 in ascending order, calc range 1060cdf0e10cSrcweir if( nMiddle < nFirst ) 1061cdf0e10cSrcweir { 1062cdf0e10cSrcweir ::std::swap(nFirst, nMiddle); 1063cdf0e10cSrcweir } 1064cdf0e10cSrcweir else if( nMiddle < nLast ) 1065cdf0e10cSrcweir { 1066cdf0e10cSrcweir nLast = nLast + nMiddle - nFirst; 1067cdf0e10cSrcweir } 1068cdf0e10cSrcweir else 1069cdf0e10cSrcweir { 1070cdf0e10cSrcweir ::std::swap(nMiddle, nLast); 1071cdf0e10cSrcweir nLast = nLast + nMiddle - nFirst; 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir if( nFirst < nParas && nMiddle < nParas && nLast < nParas ) 1075cdf0e10cSrcweir { 1076cdf0e10cSrcweir // since we have no "paragraph index 1077cdf0e10cSrcweir // changed" event on UAA, remove 1078cdf0e10cSrcweir // [first,last] and insert again later (in 1079cdf0e10cSrcweir // UpdateVisibleChildren) 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir // maParaManager.Rotate( nFirst, nMiddle, nLast ); 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir // send CHILD_EVENT to affected children 1084cdf0e10cSrcweir ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator begin = maParaManager.begin(); 1085cdf0e10cSrcweir ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator end = begin; 1086cdf0e10cSrcweir 1087cdf0e10cSrcweir ::std::advance( begin, nFirst ); 1088cdf0e10cSrcweir ::std::advance( end, nLast+1 ); 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir // TODO: maybe optimize here in the following way. If the 1091cdf0e10cSrcweir // number of removed children exceeds a certain threshold, 1092cdf0e10cSrcweir // use INVALIDATE_CHILDREN 1093cdf0e10cSrcweir AccessibleTextHelper_LostChildEvent aFunctor( *this ); 1094cdf0e10cSrcweir 1095cdf0e10cSrcweir ::std::for_each( begin, end, aFunctor ); 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir maParaManager.Release(nFirst, nLast+1); 1098cdf0e10cSrcweir // should be no need for UpdateBoundRect, since all affected children are cleared. 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir } 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir // functor for sending child events (no stand-alone function, they are maybe not inlined) 1103cdf0e10cSrcweir class AccessibleTextHelper_ChildrenTextChanged : public ::std::unary_function< ::accessibility::AccessibleEditableTextPara&, void > 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir public: operator ()(::accessibility::AccessibleEditableTextPara & rPara)1106cdf0e10cSrcweir void operator()( ::accessibility::AccessibleEditableTextPara& rPara ) 1107cdf0e10cSrcweir { 1108cdf0e10cSrcweir rPara.TextChanged(); 1109cdf0e10cSrcweir } 1110cdf0e10cSrcweir }; 1111cdf0e10cSrcweir 1112cdf0e10cSrcweir /** functor processing queue events 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir Reacts on TEXT_HINT_PARAINSERTED/REMOVED events and stores 1115cdf0e10cSrcweir their content 1116cdf0e10cSrcweir */ 1117cdf0e10cSrcweir class AccessibleTextHelper_QueueFunctor : public ::std::unary_function< const SfxHint*, void > 1118cdf0e10cSrcweir { 1119cdf0e10cSrcweir public: AccessibleTextHelper_QueueFunctor()1120cdf0e10cSrcweir AccessibleTextHelper_QueueFunctor() : 1121cdf0e10cSrcweir mnParasChanged( 0 ), 1122cdf0e10cSrcweir mnParaIndex(-1), 1123cdf0e10cSrcweir mnHintId(-1) 1124cdf0e10cSrcweir {} operator ()(const SfxHint * pEvent)1125cdf0e10cSrcweir void operator()( const SfxHint* pEvent ) 1126cdf0e10cSrcweir { 1127cdf0e10cSrcweir if( pEvent && 1128cdf0e10cSrcweir mnParasChanged != -1 ) 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir // determine hint type 1131cdf0e10cSrcweir const TextHint* pTextHint = PTR_CAST( TextHint, pEvent ); 1132cdf0e10cSrcweir const SvxEditSourceHint* pEditSourceHint = PTR_CAST( SvxEditSourceHint, pEvent ); 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir if( !pEditSourceHint && pTextHint && 1135cdf0e10cSrcweir (pTextHint->GetId() == TEXT_HINT_PARAINSERTED || 1136cdf0e10cSrcweir pTextHint->GetId() == TEXT_HINT_PARAREMOVED ) ) 1137cdf0e10cSrcweir { 1138cdf0e10cSrcweir if( pTextHint->GetValue() == EE_PARA_ALL ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir mnParasChanged = -1; 1141cdf0e10cSrcweir } 1142cdf0e10cSrcweir else 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir mnHintId = pTextHint->GetId(); 1145cdf0e10cSrcweir mnParaIndex = pTextHint->GetValue(); 1146cdf0e10cSrcweir ++mnParasChanged; 1147cdf0e10cSrcweir } 1148cdf0e10cSrcweir } 1149cdf0e10cSrcweir } 1150cdf0e10cSrcweir } 1151cdf0e10cSrcweir 1152cdf0e10cSrcweir /** Query number of paragraphs changed during queue processing. 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir @return number of changed paragraphs, -1 for 1155cdf0e10cSrcweir "every paragraph changed" 1156cdf0e10cSrcweir */ GetNumberOfParasChanged()1157cdf0e10cSrcweir int GetNumberOfParasChanged() { return mnParasChanged; } 1158cdf0e10cSrcweir /** Query index of last added/removed paragraph 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir @return index of lastly added paragraphs, -1 for none 1161cdf0e10cSrcweir added so far. 1162cdf0e10cSrcweir */ GetParaIndex()1163cdf0e10cSrcweir int GetParaIndex() { return mnParaIndex; } 1164cdf0e10cSrcweir /** Query hint id of last interesting event 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir @return hint id of last interesting event (REMOVED/INSERTED). 1167cdf0e10cSrcweir */ GetHintId()1168cdf0e10cSrcweir int GetHintId() { return mnHintId; } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir private: 1171cdf0e10cSrcweir /** number of paragraphs changed during queue processing. -1 for 1172cdf0e10cSrcweir "every paragraph changed" 1173cdf0e10cSrcweir */ 1174cdf0e10cSrcweir int mnParasChanged; 1175cdf0e10cSrcweir /// index of paragraph added/removed last 1176cdf0e10cSrcweir int mnParaIndex; 1177cdf0e10cSrcweir /// TextHint ID (removed/inserted) of last interesting event 1178cdf0e10cSrcweir int mnHintId; 1179cdf0e10cSrcweir }; 1180cdf0e10cSrcweir ProcessQueue()1181cdf0e10cSrcweir void AccessibleTextHelper_Impl::ProcessQueue() 1182cdf0e10cSrcweir { 1183cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1184cdf0e10cSrcweir 1185cdf0e10cSrcweir // inspect queue for paragraph insert/remove events. If there 1186cdf0e10cSrcweir // is exactly _one_ of those in the queue, and the number of 1187cdf0e10cSrcweir // paragraphs has changed by exactly one, use that event to 1188cdf0e10cSrcweir // determine a priori which paragraph was added/removed. This 1189cdf0e10cSrcweir // is necessary, since I must sync right here with the 1190cdf0e10cSrcweir // EditEngine state (number of paragraphs etc.), since I'm 1191cdf0e10cSrcweir // potentially sending listener events right away. 1192cdf0e10cSrcweir AccessibleTextHelper_QueueFunctor aFunctor; 1193cdf0e10cSrcweir maEventQueue.ForEach( aFunctor ); 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir const sal_Int32 nNewParas( GetTextForwarder().GetParagraphCount() ); 1196cdf0e10cSrcweir const sal_Int32 nCurrParas( maParaManager.GetNum() ); 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir // whether every paragraph already is updated (no need to 1199cdf0e10cSrcweir // repeat that later on, e.g. for PARA_MOVED events) 1200cdf0e10cSrcweir bool bEverythingUpdated( false ); 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir if( labs( nNewParas - nCurrParas ) == 1 && 1203cdf0e10cSrcweir aFunctor.GetNumberOfParasChanged() == 1 ) 1204cdf0e10cSrcweir { 1205cdf0e10cSrcweir // #103483# Exactly one paragraph added/removed. This is 1206cdf0e10cSrcweir // the normal case, optimize event handling here. 1207cdf0e10cSrcweir 1208cdf0e10cSrcweir if( aFunctor.GetHintId() == TEXT_HINT_PARAINSERTED ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir // update num of paras 1211cdf0e10cSrcweir maParaManager.SetNum( nNewParas ); 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir // release everything from the insertion position until the end 1214cdf0e10cSrcweir maParaManager.Release(aFunctor.GetParaIndex(), nCurrParas); 1215cdf0e10cSrcweir 1216*88c764bfSmseidel // TODO: Clarify whether this behavior _really_ saves 1217cdf0e10cSrcweir // anybody anything! 1218cdf0e10cSrcweir // update children, _don't_ broadcast 1219cdf0e10cSrcweir UpdateVisibleChildren( false ); 1220cdf0e10cSrcweir UpdateBoundRect(); 1221cdf0e10cSrcweir 1222cdf0e10cSrcweir // send insert event 1223cdf0e10cSrcweir // #109864# Enforce creation of this paragraph 1224cdf0e10cSrcweir try 1225cdf0e10cSrcweir { 1226cdf0e10cSrcweir GotPropertyEvent( uno::makeAny( getAccessibleChild( aFunctor.GetParaIndex() - 1227cdf0e10cSrcweir mnFirstVisibleChild + GetStartIndex() ) ), 1228cdf0e10cSrcweir AccessibleEventId::CHILD ); 1229cdf0e10cSrcweir } 1230cdf0e10cSrcweir catch( const uno::Exception& ) 1231cdf0e10cSrcweir { 1232cdf0e10cSrcweir DBG_ERROR("AccessibleTextHelper_Impl::ProcessQueue: could not create new paragraph"); 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir else if( aFunctor.GetHintId() == TEXT_HINT_PARAREMOVED ) 1236cdf0e10cSrcweir { 1237cdf0e10cSrcweir ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator begin = maParaManager.begin(); 1238cdf0e10cSrcweir ::std::advance( begin, aFunctor.GetParaIndex() ); 1239cdf0e10cSrcweir ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator end = begin; 1240cdf0e10cSrcweir ::std::advance( end, 1 ); 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir // #i61812# remember para to be removed for later notification 1243cdf0e10cSrcweir // AFTER the new state is applied (that after the para got removed) 1244cdf0e10cSrcweir ::uno::Reference< XAccessible > xPara; 1245cdf0e10cSrcweir ::accessibility::AccessibleParaManager::WeakPara::HardRefType aHardRef( begin->first.get() ); 1246cdf0e10cSrcweir if( aHardRef.is() ) 1247cdf0e10cSrcweir xPara = ::uno::Reference< XAccessible >( aHardRef.getRef(), ::uno::UNO_QUERY ); 1248cdf0e10cSrcweir 1249cdf0e10cSrcweir // release everything from the remove position until the end 1250cdf0e10cSrcweir maParaManager.Release(aFunctor.GetParaIndex(), nCurrParas); 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir // update num of paras 1253cdf0e10cSrcweir maParaManager.SetNum( nNewParas ); 1254cdf0e10cSrcweir 1255*88c764bfSmseidel // TODO: Clarify whether this behavior _really_ saves 1256cdf0e10cSrcweir // anybody anything! 1257cdf0e10cSrcweir // update children, _don't_ broadcast 1258cdf0e10cSrcweir UpdateVisibleChildren( false ); 1259cdf0e10cSrcweir UpdateBoundRect(); 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir // #i61812# notification for removed para 1262cdf0e10cSrcweir if (xPara.is()) 1263cdf0e10cSrcweir FireEvent(AccessibleEventId::CHILD, uno::Any(), uno::makeAny( xPara) ); 1264cdf0e10cSrcweir } 1265cdf0e10cSrcweir #ifdef DBG_UTIL 1266cdf0e10cSrcweir else 1267cdf0e10cSrcweir DBG_ERROR("AccessibleTextHelper_Impl::ProcessQueue() invalid hint id"); 1268cdf0e10cSrcweir #endif 1269cdf0e10cSrcweir } 1270cdf0e10cSrcweir else if( nNewParas != nCurrParas ) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir // release all paras 1273cdf0e10cSrcweir maParaManager.Release(0, nCurrParas); 1274cdf0e10cSrcweir 1275cdf0e10cSrcweir // update num of paras 1276cdf0e10cSrcweir maParaManager.SetNum( nNewParas ); 1277cdf0e10cSrcweir 1278cdf0e10cSrcweir // #109864# create from scratch, don't broadcast 1279cdf0e10cSrcweir UpdateVisibleChildren( false ); 1280cdf0e10cSrcweir UpdateBoundRect(); 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir // number of paragraphs somehow changed - but we have no 1283cdf0e10cSrcweir // chance determining how. Thus, throw away everything and 1284cdf0e10cSrcweir // create from scratch. 1285cdf0e10cSrcweir // (child events should be broadcast after the changes are done...) 1286cdf0e10cSrcweir FireEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN); 1287cdf0e10cSrcweir 1288cdf0e10cSrcweir // no need for further updates later on 1289cdf0e10cSrcweir bEverythingUpdated = true; 1290cdf0e10cSrcweir } 1291cdf0e10cSrcweir 1292cdf0e10cSrcweir while( !maEventQueue.IsEmpty() ) 1293cdf0e10cSrcweir { 1294cdf0e10cSrcweir ::std::auto_ptr< SfxHint > pHint( maEventQueue.PopFront() ); 1295cdf0e10cSrcweir if( pHint.get() ) 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir const SfxHint& rHint = *(pHint.get()); 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir // determine hint type 1300cdf0e10cSrcweir const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint ); 1301cdf0e10cSrcweir const SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint ); 1302cdf0e10cSrcweir const TextHint* pTextHint = PTR_CAST( TextHint, &rHint ); 1303cdf0e10cSrcweir const SvxViewHint* pViewHint = PTR_CAST( SvxViewHint, &rHint ); 1304cdf0e10cSrcweir const SvxEditSourceHint* pEditSourceHint = PTR_CAST( SvxEditSourceHint, &rHint ); 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir try 1307cdf0e10cSrcweir { 1308cdf0e10cSrcweir const sal_Int32 nParas = GetTextForwarder().GetParagraphCount(); 1309cdf0e10cSrcweir 1310cdf0e10cSrcweir if( pEditSourceHint ) 1311cdf0e10cSrcweir { 1312cdf0e10cSrcweir switch( pEditSourceHint->GetId() ) 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir case EDITSOURCE_HINT_PARASMOVED: 1315cdf0e10cSrcweir { 1316cdf0e10cSrcweir DBG_ASSERT( pEditSourceHint->GetStartValue() < GetTextForwarder().GetParagraphCount() && 1317cdf0e10cSrcweir pEditSourceHint->GetEndValue() < GetTextForwarder().GetParagraphCount(), 1318cdf0e10cSrcweir "AccessibleTextHelper_Impl::NotifyHdl: Invalid notification"); 1319cdf0e10cSrcweir 1320cdf0e10cSrcweir if( !bEverythingUpdated ) 1321cdf0e10cSrcweir { 1322cdf0e10cSrcweir ParagraphsMoved(pEditSourceHint->GetStartValue(), 1323cdf0e10cSrcweir pEditSourceHint->GetValue(), 1324cdf0e10cSrcweir pEditSourceHint->GetEndValue()); 1325cdf0e10cSrcweir 1326cdf0e10cSrcweir // in all cases, check visibility afterwards. 1327cdf0e10cSrcweir UpdateVisibleChildren(); 1328cdf0e10cSrcweir } 1329cdf0e10cSrcweir break; 1330cdf0e10cSrcweir } 1331cdf0e10cSrcweir 1332cdf0e10cSrcweir case EDITSOURCE_HINT_SELECTIONCHANGED: 1333cdf0e10cSrcweir // notify listeners 1334cdf0e10cSrcweir try 1335cdf0e10cSrcweir { 1336cdf0e10cSrcweir UpdateSelection(); 1337cdf0e10cSrcweir } 1338cdf0e10cSrcweir // maybe we're not in edit mode (this is not an error) 1339cdf0e10cSrcweir catch( const uno::Exception& ) {} 1340cdf0e10cSrcweir break; 1341cdf0e10cSrcweir } 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir else if( pTextHint ) 1344cdf0e10cSrcweir { 1345cdf0e10cSrcweir switch( pTextHint->GetId() ) 1346cdf0e10cSrcweir { 1347cdf0e10cSrcweir case TEXT_HINT_MODIFIED: 1348cdf0e10cSrcweir { 1349cdf0e10cSrcweir // notify listeners 1350cdf0e10cSrcweir sal_Int32 nPara( pTextHint->GetValue() ); 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir // #108900# Delegate change event to children 1353cdf0e10cSrcweir AccessibleTextHelper_ChildrenTextChanged aNotifyChildrenFunctor; 1354cdf0e10cSrcweir 1355cdf0e10cSrcweir if( nPara == static_cast<sal_Int32>(EE_PARA_ALL) ) 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir // #108900# Call every child 1358cdf0e10cSrcweir ::std::for_each( maParaManager.begin(), maParaManager.end(), 1359cdf0e10cSrcweir AccessibleParaManager::WeakChildAdapter< AccessibleTextHelper_ChildrenTextChanged > (aNotifyChildrenFunctor) ); 1360cdf0e10cSrcweir } 1361cdf0e10cSrcweir else 1362cdf0e10cSrcweir if( nPara < nParas ) 1363cdf0e10cSrcweir { 1364cdf0e10cSrcweir // #108900# Call child at index nPara 1365cdf0e10cSrcweir ::std::for_each( maParaManager.begin()+nPara, maParaManager.begin()+nPara+1, 1366cdf0e10cSrcweir AccessibleParaManager::WeakChildAdapter< AccessibleTextHelper_ChildrenTextChanged > (aNotifyChildrenFunctor) ); 1367cdf0e10cSrcweir } 1368cdf0e10cSrcweir break; 1369cdf0e10cSrcweir } 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir case TEXT_HINT_PARAINSERTED: 1372cdf0e10cSrcweir // already happened above 1373cdf0e10cSrcweir break; 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir case TEXT_HINT_PARAREMOVED: 1376cdf0e10cSrcweir // already happened above 1377cdf0e10cSrcweir break; 1378cdf0e10cSrcweir 1379cdf0e10cSrcweir case TEXT_HINT_TEXTHEIGHTCHANGED: 1380cdf0e10cSrcweir // visibility changed, done below 1381cdf0e10cSrcweir break; 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir case TEXT_HINT_VIEWSCROLLED: 1384cdf0e10cSrcweir // visibility changed, done below 1385cdf0e10cSrcweir break; 1386cdf0e10cSrcweir } 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir // in all cases, check visibility afterwards. 1389cdf0e10cSrcweir UpdateVisibleChildren(); 1390cdf0e10cSrcweir UpdateBoundRect(); 1391cdf0e10cSrcweir } 1392cdf0e10cSrcweir else if( pViewHint ) 1393cdf0e10cSrcweir { 1394cdf0e10cSrcweir switch( pViewHint->GetHintType() ) 1395cdf0e10cSrcweir { 1396cdf0e10cSrcweir case SvxViewHint::SVX_HINT_VIEWCHANGED: 1397cdf0e10cSrcweir // just check visibility 1398cdf0e10cSrcweir UpdateVisibleChildren(); 1399cdf0e10cSrcweir UpdateBoundRect(); 1400cdf0e10cSrcweir break; 1401cdf0e10cSrcweir } 1402cdf0e10cSrcweir } 1403cdf0e10cSrcweir else if( pSdrHint ) 1404cdf0e10cSrcweir { 1405cdf0e10cSrcweir switch( pSdrHint->GetKind() ) 1406cdf0e10cSrcweir { 1407cdf0e10cSrcweir case HINT_BEGEDIT: 1408cdf0e10cSrcweir { 14099b8096d0SSteve Yin if(!IsActive()) 14109b8096d0SSteve Yin { 14119b8096d0SSteve Yin break; 14129b8096d0SSteve Yin } 1413cdf0e10cSrcweir // change children state 1414cdf0e10cSrcweir maParaManager.SetActive(); 1415cdf0e10cSrcweir 1416cdf0e10cSrcweir // per definition, edit mode text has the focus 1417cdf0e10cSrcweir SetFocus( sal_True ); 1418cdf0e10cSrcweir break; 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir 1421cdf0e10cSrcweir case HINT_ENDEDIT: 1422cdf0e10cSrcweir { 1423cdf0e10cSrcweir // focused child now looses focus 1424cdf0e10cSrcweir ESelection aSelection; 1425cdf0e10cSrcweir if( GetEditViewForwarder().GetSelection( aSelection ) ) 1426cdf0e10cSrcweir SetChildFocus( aSelection.nEndPara, sal_False ); 1427cdf0e10cSrcweir 1428cdf0e10cSrcweir // change children state 1429cdf0e10cSrcweir maParaManager.SetActive( sal_False ); 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir maLastSelection = ESelection( EE_PARA_NOT_FOUND, EE_PARA_NOT_FOUND, 1432cdf0e10cSrcweir EE_PARA_NOT_FOUND, EE_PARA_NOT_FOUND); 1433cdf0e10cSrcweir break; 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir default: 1436cdf0e10cSrcweir break; 1437cdf0e10cSrcweir } 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir // it's VITAL to keep the SfxSimpleHint last! It's the base of some classes above! 1440cdf0e10cSrcweir else if( pSimpleHint ) 1441cdf0e10cSrcweir { 1442cdf0e10cSrcweir switch( pSimpleHint->GetId() ) 1443cdf0e10cSrcweir { 1444cdf0e10cSrcweir case SFX_HINT_DYING: 1445cdf0e10cSrcweir // edit source is dying under us, become defunc then 1446cdf0e10cSrcweir try 1447cdf0e10cSrcweir { 1448cdf0e10cSrcweir // make edit source inaccessible 1449cdf0e10cSrcweir // Note: cannot destroy it here, since we're called from there! 1450cdf0e10cSrcweir ShutdownEditSource(); 1451cdf0e10cSrcweir } 1452cdf0e10cSrcweir catch( const uno::Exception& ) {} 1453cdf0e10cSrcweir 1454cdf0e10cSrcweir break; 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir } 1457cdf0e10cSrcweir } 1458cdf0e10cSrcweir catch( const uno::Exception& ) 1459cdf0e10cSrcweir { 1460cdf0e10cSrcweir #ifdef DBG_UTIL 1461cdf0e10cSrcweir OSL_TRACE("AccessibleTextHelper_Impl::ProcessQueue: Unhandled exception."); 1462cdf0e10cSrcweir #endif 1463cdf0e10cSrcweir } 1464cdf0e10cSrcweir } 1465cdf0e10cSrcweir } 1466cdf0e10cSrcweir } 1467cdf0e10cSrcweir Notify(SfxBroadcaster &,const SfxHint & rHint)1468cdf0e10cSrcweir void AccessibleTextHelper_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) 1469cdf0e10cSrcweir { 1470cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1471cdf0e10cSrcweir 1472cdf0e10cSrcweir // precondition: solar mutex locked 1473cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1474cdf0e10cSrcweir 1475cdf0e10cSrcweir // precondition: not in a recursion 1476cdf0e10cSrcweir if( mbInNotify ) 1477cdf0e10cSrcweir return; 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir mbInNotify = sal_True; 1480cdf0e10cSrcweir 1481cdf0e10cSrcweir // determine hint type 1482cdf0e10cSrcweir const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint ); 1483cdf0e10cSrcweir const SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint ); 1484cdf0e10cSrcweir const TextHint* pTextHint = PTR_CAST( TextHint, &rHint ); 1485cdf0e10cSrcweir const SvxViewHint* pViewHint = PTR_CAST( SvxViewHint, &rHint ); 1486cdf0e10cSrcweir const SvxEditSourceHint* pEditSourceHint = PTR_CAST( SvxEditSourceHint, &rHint ); 1487cdf0e10cSrcweir 1488cdf0e10cSrcweir try 1489cdf0e10cSrcweir { 1490cdf0e10cSrcweir // Process notification event 1491cdf0e10cSrcweir if( pEditSourceHint ) 1492cdf0e10cSrcweir { 1493cdf0e10cSrcweir maEventQueue.Append( *pEditSourceHint ); 1494cdf0e10cSrcweir // --> OD 2005-12-19 #i27299# 1495cdf0e10cSrcweir if( maEventOpenFrames == 0 ) 1496cdf0e10cSrcweir ProcessQueue(); 1497cdf0e10cSrcweir // <-- 1498cdf0e10cSrcweir } 1499cdf0e10cSrcweir else if( pTextHint ) 1500cdf0e10cSrcweir { 1501cdf0e10cSrcweir switch( pTextHint->GetId() ) 1502cdf0e10cSrcweir { 1503cdf0e10cSrcweir case TEXT_HINT_BLOCKNOTIFICATION_END: 1504cdf0e10cSrcweir case TEXT_HINT_INPUT_END: 1505cdf0e10cSrcweir --maEventOpenFrames; 1506cdf0e10cSrcweir 1507cdf0e10cSrcweir if( maEventOpenFrames == 0 ) 1508cdf0e10cSrcweir { 1509cdf0e10cSrcweir // #103483# 1510cdf0e10cSrcweir /* All information should have arrived 1511cdf0e10cSrcweir * now, process queue. As stated in the 1512cdf0e10cSrcweir * above bug, we can often avoid throwing 1513cdf0e10cSrcweir * away all paragraphs by looking forward 1514cdf0e10cSrcweir * in the event queue (searching for 1515cdf0e10cSrcweir * PARAINSERT/REMOVE events). Furthermore, 1516cdf0e10cSrcweir * processing the event queue only at the 1517cdf0e10cSrcweir * end of an interaction cycle, ensures 1518cdf0e10cSrcweir * that the EditEngine state and the 1519cdf0e10cSrcweir * AccessibleText state are the same 1520cdf0e10cSrcweir * (well, mostly. If there are _multiple_ 1521cdf0e10cSrcweir * interaction cycles in the EE queues, it 1522cdf0e10cSrcweir * can still happen that EE state is 1523cdf0e10cSrcweir * different. That's so to say broken by 1524cdf0e10cSrcweir * design with that delayed EE event 1525cdf0e10cSrcweir * concept). 1526cdf0e10cSrcweir */ 1527cdf0e10cSrcweir ProcessQueue(); 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir break; 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir case TEXT_HINT_BLOCKNOTIFICATION_START: 1532cdf0e10cSrcweir case TEXT_HINT_INPUT_START: 1533cdf0e10cSrcweir ++maEventOpenFrames; 1534*88c764bfSmseidel // --> OD 2005-12-19 #i27299# - no FALLTHROUGH 1535cdf0e10cSrcweir // reason: event will not be processes, thus appending 1536cdf0e10cSrcweir // the event isn't necessary. 1537cdf0e10cSrcweir break; 1538cdf0e10cSrcweir // <-- 1539cdf0e10cSrcweir default: 1540cdf0e10cSrcweir maEventQueue.Append( *pTextHint ); 1541cdf0e10cSrcweir // --> OD 2005-12-19 #i27299# 1542cdf0e10cSrcweir if( maEventOpenFrames == 0 ) 1543cdf0e10cSrcweir ProcessQueue(); 1544cdf0e10cSrcweir // <-- 1545cdf0e10cSrcweir break; 1546cdf0e10cSrcweir } 1547cdf0e10cSrcweir } 1548cdf0e10cSrcweir else if( pViewHint ) 1549cdf0e10cSrcweir { 1550cdf0e10cSrcweir maEventQueue.Append( *pViewHint ); 1551cdf0e10cSrcweir 1552cdf0e10cSrcweir // process visibility right away, if not within an 1553cdf0e10cSrcweir // open EE notification frame. Otherwise, event 1554cdf0e10cSrcweir // processing would be delayed until next EE 1555cdf0e10cSrcweir // notification sequence. 1556cdf0e10cSrcweir if( maEventOpenFrames == 0 ) 1557cdf0e10cSrcweir ProcessQueue(); 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir else if( pSdrHint ) 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir maEventQueue.Append( *pSdrHint ); 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir // process drawing layer events right away, if not 1564cdf0e10cSrcweir // within an open EE notification frame. Otherwise, 1565cdf0e10cSrcweir // event processing would be delayed until next EE 1566cdf0e10cSrcweir // notification sequence. 1567cdf0e10cSrcweir if( maEventOpenFrames == 0 ) 1568cdf0e10cSrcweir ProcessQueue(); 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir // it's VITAL to keep the SfxSimpleHint last! It's the base of some classes above! 1571cdf0e10cSrcweir else if( pSimpleHint ) 1572cdf0e10cSrcweir { 1573cdf0e10cSrcweir // handle this event _at once_, because after that, objects are invalid 1574cdf0e10cSrcweir switch( pSimpleHint->GetId() ) 1575cdf0e10cSrcweir { 1576cdf0e10cSrcweir case SFX_HINT_DYING: 1577cdf0e10cSrcweir // edit source is dying under us, become defunc then 1578cdf0e10cSrcweir maEventQueue.Clear(); 1579cdf0e10cSrcweir try 1580cdf0e10cSrcweir { 1581cdf0e10cSrcweir // make edit source inaccessible 1582cdf0e10cSrcweir // Note: cannot destroy it here, since we're called from there! 1583cdf0e10cSrcweir ShutdownEditSource(); 1584cdf0e10cSrcweir } 1585cdf0e10cSrcweir catch( const uno::Exception& ) {} 1586cdf0e10cSrcweir 1587cdf0e10cSrcweir break; 1588cdf0e10cSrcweir } 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir } 1591cdf0e10cSrcweir catch( const uno::Exception& ) 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir #ifdef DBG_UTIL 1594cdf0e10cSrcweir OSL_TRACE("AccessibleTextHelper_Impl::Notify: Unhandled exception."); 1595cdf0e10cSrcweir #endif 1596cdf0e10cSrcweir mbInNotify = sal_False; 1597cdf0e10cSrcweir } 1598cdf0e10cSrcweir 1599cdf0e10cSrcweir mbInNotify = sal_False; 1600cdf0e10cSrcweir } 1601cdf0e10cSrcweir Dispose()1602cdf0e10cSrcweir void AccessibleTextHelper_Impl::Dispose() 1603cdf0e10cSrcweir { 1604cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1605cdf0e10cSrcweir 1606cdf0e10cSrcweir if( getNotifierClientId() != -1 ) 1607cdf0e10cSrcweir { 1608cdf0e10cSrcweir try 1609cdf0e10cSrcweir { 1610cdf0e10cSrcweir // #106234# Unregister from EventNotifier 1611cdf0e10cSrcweir ::comphelper::AccessibleEventNotifier::revokeClient( getNotifierClientId() ); 1612cdf0e10cSrcweir #ifdef DBG_UTIL 1613cdf0e10cSrcweir OSL_TRACE( "AccessibleTextHelper_Impl disposed ID: %d", mnNotifierClientId ); 1614cdf0e10cSrcweir #endif 1615cdf0e10cSrcweir } 1616cdf0e10cSrcweir catch( const uno::Exception& ) {} 1617cdf0e10cSrcweir 1618cdf0e10cSrcweir mnNotifierClientId = -1; 1619cdf0e10cSrcweir } 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir try 1622cdf0e10cSrcweir { 1623cdf0e10cSrcweir // dispose children 1624cdf0e10cSrcweir maParaManager.Dispose(); 1625cdf0e10cSrcweir } 1626cdf0e10cSrcweir catch( const uno::Exception& ) {} 1627cdf0e10cSrcweir 1628cdf0e10cSrcweir // quit listen on stale edit source 1629cdf0e10cSrcweir if( maEditSource.IsValid() ) 1630cdf0e10cSrcweir EndListening( maEditSource.GetBroadcaster() ); 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir // clear references 1633cdf0e10cSrcweir maEditSource.SetEditSource( ::std::auto_ptr< SvxEditSource >(NULL) ); 1634cdf0e10cSrcweir mxFrontEnd = NULL; 1635cdf0e10cSrcweir } 1636cdf0e10cSrcweir FireEvent(const sal_Int16 nEventId,const uno::Any & rNewValue,const uno::Any & rOldValue) const1637cdf0e10cSrcweir void AccessibleTextHelper_Impl::FireEvent( const sal_Int16 nEventId, const uno::Any& rNewValue, const uno::Any& rOldValue ) const 1638cdf0e10cSrcweir { 1639cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1640cdf0e10cSrcweir 1641cdf0e10cSrcweir // -- object locked -- 1642cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( maMutex ); 1643cdf0e10cSrcweir 1644cdf0e10cSrcweir AccessibleEventObject aEvent; 1645cdf0e10cSrcweir 1646cdf0e10cSrcweir DBG_ASSERT(mxFrontEnd.is(), "AccessibleTextHelper::FireEvent: no event source set" ); 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir if( mxFrontEnd.is() ) 1649cdf0e10cSrcweir aEvent = AccessibleEventObject(mxFrontEnd->getAccessibleContext(), nEventId, rNewValue, rOldValue); 1650cdf0e10cSrcweir else 1651cdf0e10cSrcweir aEvent = AccessibleEventObject(uno::Reference< uno::XInterface >(), nEventId, rNewValue, rOldValue); 1652cdf0e10cSrcweir 1653cdf0e10cSrcweir // no locking necessary, FireEvent internally copies listeners 1654cdf0e10cSrcweir // if someone removes/adds in between Further locking, 1655cdf0e10cSrcweir // actually, might lead to deadlocks, since we're calling out 1656cdf0e10cSrcweir // of this object 1657cdf0e10cSrcweir aGuard.clear(); 1658cdf0e10cSrcweir // -- until here -- 1659cdf0e10cSrcweir 1660cdf0e10cSrcweir FireEvent(aEvent); 1661cdf0e10cSrcweir } 1662cdf0e10cSrcweir FireEvent(const AccessibleEventObject & rEvent) const1663cdf0e10cSrcweir void AccessibleTextHelper_Impl::FireEvent( const AccessibleEventObject& rEvent ) const 1664cdf0e10cSrcweir { 1665cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1666cdf0e10cSrcweir 1667cdf0e10cSrcweir // #102261# Call global queue for focus events 1668cdf0e10cSrcweir if( rEvent.EventId == AccessibleStateType::FOCUSED ) 1669cdf0e10cSrcweir vcl::unohelper::NotifyAccessibleStateEventGlobally( rEvent ); 1670cdf0e10cSrcweir 1671cdf0e10cSrcweir // #106234# Delegate to EventNotifier 1672cdf0e10cSrcweir ::comphelper::AccessibleEventNotifier::addEvent( getNotifierClientId(), 1673cdf0e10cSrcweir rEvent ); 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir // XAccessibleContext getAccessibleChildCount()1677cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTextHelper_Impl::getAccessibleChildCount() SAL_THROW((uno::RuntimeException)) 1678cdf0e10cSrcweir { 1679cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir return mnLastVisibleChild - mnFirstVisibleChild + 1; 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir getAccessibleChild(sal_Int32 i)1684cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL AccessibleTextHelper_Impl::getAccessibleChild( sal_Int32 i ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException)) 1685cdf0e10cSrcweir { 1686cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir i -= GetStartIndex(); 1689cdf0e10cSrcweir 1690cdf0e10cSrcweir if( 0 > i || i >= getAccessibleChildCount() || 1691cdf0e10cSrcweir GetTextForwarder().GetParagraphCount() <= i ) 1692cdf0e10cSrcweir { 1693cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid child index")), mxFrontEnd); 1694cdf0e10cSrcweir } 1695cdf0e10cSrcweir 1696cdf0e10cSrcweir DBG_ASSERT(mxFrontEnd.is(), "AccessibleTextHelper_Impl::UpdateVisibleChildren: no frontend set"); 1697cdf0e10cSrcweir 1698cdf0e10cSrcweir if( mxFrontEnd.is() ) 1699cdf0e10cSrcweir return maParaManager.CreateChild( i, mxFrontEnd, GetEditSource(), mnFirstVisibleChild + i ).first; 1700cdf0e10cSrcweir else 1701cdf0e10cSrcweir return NULL; 1702cdf0e10cSrcweir } 1703cdf0e10cSrcweir addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)1704cdf0e10cSrcweir void SAL_CALL AccessibleTextHelper_Impl::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) SAL_THROW((uno::RuntimeException)) 1705cdf0e10cSrcweir { 1706cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1707cdf0e10cSrcweir 1708cdf0e10cSrcweir if( getNotifierClientId() != -1 ) 1709cdf0e10cSrcweir ::comphelper::AccessibleEventNotifier::addEventListener( getNotifierClientId(), xListener ); 1710cdf0e10cSrcweir } 1711cdf0e10cSrcweir removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)1712cdf0e10cSrcweir void SAL_CALL AccessibleTextHelper_Impl::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) SAL_THROW((uno::RuntimeException)) 1713cdf0e10cSrcweir { 1714cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1715cdf0e10cSrcweir 1716cdf0e10cSrcweir if( getNotifierClientId() != -1 ) 1717cdf0e10cSrcweir ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener ); 1718cdf0e10cSrcweir } 1719cdf0e10cSrcweir getAccessibleAtPoint(const awt::Point & _aPoint)1720cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL AccessibleTextHelper_Impl::getAccessibleAtPoint( const awt::Point& _aPoint ) SAL_THROW((uno::RuntimeException)) 1721cdf0e10cSrcweir { 1722cdf0e10cSrcweir DBG_CHKTHIS( AccessibleTextHelper_Impl, NULL ); 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir // make given position relative 1725cdf0e10cSrcweir if( !mxFrontEnd.is() ) 1726cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleTextHelper_Impl::getAccessibleAt: frontend invalid")), mxFrontEnd ); 1727cdf0e10cSrcweir 1728cdf0e10cSrcweir uno::Reference< XAccessibleContext > xFrontEndContext = mxFrontEnd->getAccessibleContext(); 1729cdf0e10cSrcweir 1730cdf0e10cSrcweir if( !xFrontEndContext.is() ) 1731cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleTextHelper_Impl::getAccessibleAt: frontend invalid")), mxFrontEnd ); 1732cdf0e10cSrcweir 1733cdf0e10cSrcweir uno::Reference< XAccessibleComponent > xFrontEndComponent( xFrontEndContext, uno::UNO_QUERY ); 1734cdf0e10cSrcweir 1735cdf0e10cSrcweir if( !xFrontEndComponent.is() ) 1736cdf0e10cSrcweir throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleTextHelper_Impl::getAccessibleAt: frontend is no XAccessibleComponent")), 1737cdf0e10cSrcweir mxFrontEnd ); 1738cdf0e10cSrcweir 1739cdf0e10cSrcweir // #103862# No longer need to make given position relative 1740cdf0e10cSrcweir Point aPoint( _aPoint.X, _aPoint.Y ); 1741cdf0e10cSrcweir 1742cdf0e10cSrcweir // respect EditEngine offset to surrounding shape/cell 1743cdf0e10cSrcweir aPoint -= GetOffset(); 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir // convert to EditEngine coordinate system 1746cdf0e10cSrcweir SvxTextForwarder& rCacheTF = GetTextForwarder(); 1747cdf0e10cSrcweir Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) ); 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir // iterate over all visible children (including those not yet created) 1750cdf0e10cSrcweir sal_Int32 nChild; 1751cdf0e10cSrcweir for( nChild=mnFirstVisibleChild; nChild <= mnLastVisibleChild; ++nChild ) 1752cdf0e10cSrcweir { 1753cdf0e10cSrcweir DBG_ASSERT(nChild >= 0 && nChild <= USHRT_MAX, 1754cdf0e10cSrcweir "AccessibleTextHelper_Impl::getAccessibleAt: index value overflow"); 1755cdf0e10cSrcweir 1756f6b418d9SDamjan Jovanovic Rectangle aParaBounds( rCacheTF.GetParaBounds( nChild ) ); 1757cdf0e10cSrcweir 1758cdf0e10cSrcweir if( aParaBounds.IsInside( aLogPoint ) ) 1759cdf0e10cSrcweir return getAccessibleChild( nChild - mnFirstVisibleChild + GetStartIndex() ); 1760cdf0e10cSrcweir } 1761cdf0e10cSrcweir 1762cdf0e10cSrcweir // found none 1763cdf0e10cSrcweir return NULL; 1764cdf0e10cSrcweir } 1765cdf0e10cSrcweir 1766cdf0e10cSrcweir //------------------------------------------------------------------------ 1767cdf0e10cSrcweir // AccessibleTextHelper implementation (simply forwards to impl) 1768cdf0e10cSrcweir //------------------------------------------------------------------------ 1769cdf0e10cSrcweir AccessibleTextHelper(::std::auto_ptr<SvxEditSource> pEditSource)1770cdf0e10cSrcweir AccessibleTextHelper::AccessibleTextHelper( ::std::auto_ptr< SvxEditSource > pEditSource ) : 1771cdf0e10cSrcweir mpImpl( new AccessibleTextHelper_Impl() ) 1772cdf0e10cSrcweir { 1773cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1774cdf0e10cSrcweir 1775cdf0e10cSrcweir SetEditSource( pEditSource ); 1776cdf0e10cSrcweir } 1777cdf0e10cSrcweir ~AccessibleTextHelper()1778cdf0e10cSrcweir AccessibleTextHelper::~AccessibleTextHelper() 1779cdf0e10cSrcweir { 1780cdf0e10cSrcweir } 1781cdf0e10cSrcweir GetEditSource() const1782cdf0e10cSrcweir const SvxEditSource& AccessibleTextHelper::GetEditSource() const SAL_THROW((uno::RuntimeException)) 1783cdf0e10cSrcweir { 1784cdf0e10cSrcweir #ifdef DBG_UTIL 1785cdf0e10cSrcweir mpImpl->CheckInvariants(); 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir const SvxEditSource& aEditSource = mpImpl->GetEditSource(); 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir mpImpl->CheckInvariants(); 1790cdf0e10cSrcweir 1791cdf0e10cSrcweir return aEditSource; 1792cdf0e10cSrcweir #else 1793cdf0e10cSrcweir return mpImpl->GetEditSource(); 1794cdf0e10cSrcweir #endif 1795cdf0e10cSrcweir } 1796cdf0e10cSrcweir SetEditSource(::std::auto_ptr<SvxEditSource> pEditSource)1797cdf0e10cSrcweir void AccessibleTextHelper::SetEditSource( ::std::auto_ptr< SvxEditSource > pEditSource ) SAL_THROW((uno::RuntimeException)) 1798cdf0e10cSrcweir { 1799cdf0e10cSrcweir #ifdef DBG_UTIL 1800cdf0e10cSrcweir // precondition: solar mutex locked 1801cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir mpImpl->CheckInvariants(); 1804cdf0e10cSrcweir #endif 1805cdf0e10cSrcweir 1806cdf0e10cSrcweir mpImpl->SetEditSource( pEditSource ); 1807cdf0e10cSrcweir 1808cdf0e10cSrcweir #ifdef DBG_UTIL 1809cdf0e10cSrcweir mpImpl->CheckInvariants(); 1810cdf0e10cSrcweir #endif 1811cdf0e10cSrcweir } 1812cdf0e10cSrcweir SetEventSource(const uno::Reference<XAccessible> & rInterface)1813cdf0e10cSrcweir void AccessibleTextHelper::SetEventSource( const uno::Reference< XAccessible >& rInterface ) 1814cdf0e10cSrcweir { 1815cdf0e10cSrcweir #ifdef DBG_UTIL 1816cdf0e10cSrcweir mpImpl->CheckInvariants(); 1817cdf0e10cSrcweir #endif 1818cdf0e10cSrcweir 1819cdf0e10cSrcweir mpImpl->SetEventSource( rInterface ); 1820cdf0e10cSrcweir 1821cdf0e10cSrcweir #ifdef DBG_UTIL 1822cdf0e10cSrcweir mpImpl->CheckInvariants(); 1823cdf0e10cSrcweir #endif 1824cdf0e10cSrcweir } 1825cdf0e10cSrcweir GetEventSource() const1826cdf0e10cSrcweir uno::Reference< XAccessible > AccessibleTextHelper::GetEventSource() const 1827cdf0e10cSrcweir { 1828cdf0e10cSrcweir #ifdef DBG_UTIL 1829cdf0e10cSrcweir mpImpl->CheckInvariants(); 1830cdf0e10cSrcweir 1831cdf0e10cSrcweir uno::Reference< XAccessible > xRet( mpImpl->GetEventSource() ); 1832cdf0e10cSrcweir 1833cdf0e10cSrcweir mpImpl->CheckInvariants(); 1834cdf0e10cSrcweir 1835cdf0e10cSrcweir return xRet; 1836cdf0e10cSrcweir #else 1837cdf0e10cSrcweir return mpImpl->GetEventSource(); 1838cdf0e10cSrcweir #endif 1839cdf0e10cSrcweir } 1840cdf0e10cSrcweir SetFocus(sal_Bool bHaveFocus)1841cdf0e10cSrcweir void AccessibleTextHelper::SetFocus( sal_Bool bHaveFocus ) SAL_THROW((::com::sun::star::uno::RuntimeException)) 1842cdf0e10cSrcweir { 1843cdf0e10cSrcweir #ifdef DBG_UTIL 1844cdf0e10cSrcweir // precondition: solar mutex locked 1845cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1846cdf0e10cSrcweir 1847cdf0e10cSrcweir mpImpl->CheckInvariants(); 1848cdf0e10cSrcweir #endif 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir mpImpl->SetFocus( bHaveFocus ); 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir #ifdef DBG_UTIL 1853cdf0e10cSrcweir mpImpl->CheckInvariants(); 1854cdf0e10cSrcweir #endif 1855cdf0e10cSrcweir } 1856cdf0e10cSrcweir HaveFocus()1857cdf0e10cSrcweir sal_Bool AccessibleTextHelper::HaveFocus() SAL_THROW((::com::sun::star::uno::RuntimeException)) 1858cdf0e10cSrcweir { 1859cdf0e10cSrcweir #ifdef DBG_UTIL 1860cdf0e10cSrcweir mpImpl->CheckInvariants(); 1861cdf0e10cSrcweir 1862cdf0e10cSrcweir sal_Bool bRet( mpImpl->HaveFocus() ); 1863cdf0e10cSrcweir 1864cdf0e10cSrcweir mpImpl->CheckInvariants(); 1865cdf0e10cSrcweir 1866cdf0e10cSrcweir return bRet; 1867cdf0e10cSrcweir #else 1868cdf0e10cSrcweir return mpImpl->HaveFocus(); 1869cdf0e10cSrcweir #endif 1870cdf0e10cSrcweir } 1871cdf0e10cSrcweir FireEvent(const sal_Int16 nEventId,const uno::Any & rNewValue,const uno::Any & rOldValue) const1872cdf0e10cSrcweir void AccessibleTextHelper::FireEvent( const sal_Int16 nEventId, const uno::Any& rNewValue, const uno::Any& rOldValue ) const 1873cdf0e10cSrcweir { 1874cdf0e10cSrcweir #ifdef DBG_UTIL 1875cdf0e10cSrcweir mpImpl->CheckInvariants(); 1876cdf0e10cSrcweir #endif 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir mpImpl->FireEvent( nEventId, rNewValue, rOldValue ); 1879cdf0e10cSrcweir 1880cdf0e10cSrcweir #ifdef DBG_UTIL 1881cdf0e10cSrcweir mpImpl->CheckInvariants(); 1882cdf0e10cSrcweir #endif 1883cdf0e10cSrcweir } 1884cdf0e10cSrcweir FireEvent(const AccessibleEventObject & rEvent) const1885cdf0e10cSrcweir void AccessibleTextHelper::FireEvent( const AccessibleEventObject& rEvent ) const 1886cdf0e10cSrcweir { 1887cdf0e10cSrcweir #ifdef DBG_UTIL 1888cdf0e10cSrcweir mpImpl->CheckInvariants(); 1889cdf0e10cSrcweir #endif 1890cdf0e10cSrcweir 1891cdf0e10cSrcweir mpImpl->FireEvent( rEvent ); 1892cdf0e10cSrcweir 1893cdf0e10cSrcweir #ifdef DBG_UTIL 1894cdf0e10cSrcweir mpImpl->CheckInvariants(); 1895cdf0e10cSrcweir #endif 1896cdf0e10cSrcweir } 1897cdf0e10cSrcweir SetOffset(const Point & rPoint)1898cdf0e10cSrcweir void AccessibleTextHelper::SetOffset( const Point& rPoint ) 1899cdf0e10cSrcweir { 1900cdf0e10cSrcweir #ifdef DBG_UTIL 1901cdf0e10cSrcweir // precondition: solar mutex locked 1902cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1903cdf0e10cSrcweir 1904cdf0e10cSrcweir mpImpl->CheckInvariants(); 1905cdf0e10cSrcweir #endif 1906cdf0e10cSrcweir 1907cdf0e10cSrcweir mpImpl->SetOffset( rPoint ); 1908cdf0e10cSrcweir 1909cdf0e10cSrcweir #ifdef DBG_UTIL 1910cdf0e10cSrcweir mpImpl->CheckInvariants(); 1911cdf0e10cSrcweir #endif 1912cdf0e10cSrcweir } 1913cdf0e10cSrcweir GetOffset() const1914cdf0e10cSrcweir Point AccessibleTextHelper::GetOffset() const 1915cdf0e10cSrcweir { 1916cdf0e10cSrcweir #ifdef DBG_UTIL 1917cdf0e10cSrcweir mpImpl->CheckInvariants(); 1918cdf0e10cSrcweir 1919cdf0e10cSrcweir Point aPoint( mpImpl->GetOffset() ); 1920cdf0e10cSrcweir 1921cdf0e10cSrcweir mpImpl->CheckInvariants(); 1922cdf0e10cSrcweir 1923cdf0e10cSrcweir return aPoint; 1924cdf0e10cSrcweir #else 1925cdf0e10cSrcweir return mpImpl->GetOffset(); 1926cdf0e10cSrcweir #endif 1927cdf0e10cSrcweir } 1928cdf0e10cSrcweir SetStartIndex(sal_Int32 nOffset)1929cdf0e10cSrcweir void AccessibleTextHelper::SetStartIndex( sal_Int32 nOffset ) 1930cdf0e10cSrcweir { 1931cdf0e10cSrcweir #ifdef DBG_UTIL 1932cdf0e10cSrcweir // precondition: solar mutex locked 1933cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1934cdf0e10cSrcweir 1935cdf0e10cSrcweir mpImpl->CheckInvariants(); 1936cdf0e10cSrcweir #endif 1937cdf0e10cSrcweir 1938cdf0e10cSrcweir mpImpl->SetStartIndex( nOffset ); 1939cdf0e10cSrcweir 1940cdf0e10cSrcweir #ifdef DBG_UTIL 1941cdf0e10cSrcweir mpImpl->CheckInvariants(); 1942cdf0e10cSrcweir #endif 1943cdf0e10cSrcweir } 1944cdf0e10cSrcweir GetStartIndex() const1945cdf0e10cSrcweir sal_Int32 AccessibleTextHelper::GetStartIndex() const 1946cdf0e10cSrcweir { 1947cdf0e10cSrcweir #ifdef DBG_UTIL 1948cdf0e10cSrcweir mpImpl->CheckInvariants(); 1949cdf0e10cSrcweir 1950cdf0e10cSrcweir sal_Int32 nOffset = mpImpl->GetStartIndex(); 1951cdf0e10cSrcweir 1952cdf0e10cSrcweir mpImpl->CheckInvariants(); 1953cdf0e10cSrcweir 1954cdf0e10cSrcweir return nOffset; 1955cdf0e10cSrcweir #else 1956cdf0e10cSrcweir return mpImpl->GetStartIndex(); 1957cdf0e10cSrcweir #endif 1958cdf0e10cSrcweir } 1959cdf0e10cSrcweir SetAdditionalChildStates(const VectorOfStates & rChildStates)1960cdf0e10cSrcweir void AccessibleTextHelper::SetAdditionalChildStates( const VectorOfStates& rChildStates ) 1961cdf0e10cSrcweir { 1962cdf0e10cSrcweir mpImpl->SetAdditionalChildStates( rChildStates ); 1963cdf0e10cSrcweir } 1964cdf0e10cSrcweir GetAdditionalChildStates() const1965cdf0e10cSrcweir const AccessibleTextHelper::VectorOfStates& AccessibleTextHelper::GetAdditionalChildStates() const 1966cdf0e10cSrcweir { 1967cdf0e10cSrcweir return mpImpl->GetAdditionalChildStates(); 1968cdf0e10cSrcweir } 1969cdf0e10cSrcweir UpdateChildren()1970cdf0e10cSrcweir void AccessibleTextHelper::UpdateChildren() SAL_THROW((::com::sun::star::uno::RuntimeException)) 1971cdf0e10cSrcweir { 1972cdf0e10cSrcweir #ifdef DBG_UTIL 1973cdf0e10cSrcweir // precondition: solar mutex locked 1974cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1975cdf0e10cSrcweir 1976cdf0e10cSrcweir mpImpl->CheckInvariants(); 1977cdf0e10cSrcweir #endif 1978cdf0e10cSrcweir 1979cdf0e10cSrcweir mpImpl->UpdateVisibleChildren(); 1980cdf0e10cSrcweir mpImpl->UpdateBoundRect(); 1981cdf0e10cSrcweir 1982cdf0e10cSrcweir mpImpl->UpdateSelection(); 1983cdf0e10cSrcweir 1984cdf0e10cSrcweir #ifdef DBG_UTIL 1985cdf0e10cSrcweir mpImpl->CheckInvariants(); 1986cdf0e10cSrcweir #endif 1987cdf0e10cSrcweir } 1988cdf0e10cSrcweir Dispose()1989cdf0e10cSrcweir void AccessibleTextHelper::Dispose() 1990cdf0e10cSrcweir { 1991cdf0e10cSrcweir // As Dispose calls ShutdownEditSource, which in turn 1992cdf0e10cSrcweir // deregisters as listener on the edit source, have to lock 1993cdf0e10cSrcweir // here 1994cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1995cdf0e10cSrcweir 1996cdf0e10cSrcweir #ifdef DBG_UTIL 1997cdf0e10cSrcweir mpImpl->CheckInvariants(); 1998cdf0e10cSrcweir #endif 1999cdf0e10cSrcweir 2000cdf0e10cSrcweir mpImpl->Dispose(); 2001cdf0e10cSrcweir 2002cdf0e10cSrcweir #ifdef DBG_UTIL 2003cdf0e10cSrcweir mpImpl->CheckInvariants(); 2004cdf0e10cSrcweir #endif 2005cdf0e10cSrcweir } 2006cdf0e10cSrcweir IsSelected() const2007cdf0e10cSrcweir sal_Bool AccessibleTextHelper::IsSelected() const 2008cdf0e10cSrcweir { 2009cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 2010cdf0e10cSrcweir 2011cdf0e10cSrcweir #ifdef DBG_UTIL 2012cdf0e10cSrcweir mpImpl->CheckInvariants(); 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir sal_Bool aRet = mpImpl->IsSelected(); 2015cdf0e10cSrcweir 2016cdf0e10cSrcweir mpImpl->CheckInvariants(); 2017cdf0e10cSrcweir 2018cdf0e10cSrcweir return aRet; 2019cdf0e10cSrcweir #else 2020cdf0e10cSrcweir return mpImpl->IsSelected(); 2021cdf0e10cSrcweir #endif 2022cdf0e10cSrcweir } 2023cdf0e10cSrcweir 2024cdf0e10cSrcweir // XAccessibleContext GetChildCount()2025cdf0e10cSrcweir sal_Int32 AccessibleTextHelper::GetChildCount() SAL_THROW((uno::RuntimeException)) 2026cdf0e10cSrcweir { 2027cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 2028cdf0e10cSrcweir 2029cdf0e10cSrcweir #ifdef DBG_UTIL 2030cdf0e10cSrcweir mpImpl->CheckInvariants(); 2031cdf0e10cSrcweir 2032cdf0e10cSrcweir sal_Int32 nRet = mpImpl->getAccessibleChildCount(); 2033cdf0e10cSrcweir 2034cdf0e10cSrcweir mpImpl->CheckInvariants(); 2035cdf0e10cSrcweir 2036cdf0e10cSrcweir return nRet; 2037cdf0e10cSrcweir #else 2038cdf0e10cSrcweir return mpImpl->getAccessibleChildCount(); 2039cdf0e10cSrcweir #endif 2040cdf0e10cSrcweir } 2041cdf0e10cSrcweir GetChild(sal_Int32 i)2042cdf0e10cSrcweir uno::Reference< XAccessible > AccessibleTextHelper::GetChild( sal_Int32 i ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException)) 2043cdf0e10cSrcweir { 2044cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 2045cdf0e10cSrcweir 2046cdf0e10cSrcweir #ifdef DBG_UTIL 2047cdf0e10cSrcweir mpImpl->CheckInvariants(); 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir uno::Reference< XAccessible > xRet = mpImpl->getAccessibleChild( i ); 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir mpImpl->CheckInvariants(); 2052cdf0e10cSrcweir 2053cdf0e10cSrcweir return xRet; 2054cdf0e10cSrcweir #else 2055cdf0e10cSrcweir return mpImpl->getAccessibleChild( i ); 2056cdf0e10cSrcweir #endif 2057cdf0e10cSrcweir } 2058cdf0e10cSrcweir AddEventListener(const uno::Reference<XAccessibleEventListener> & xListener)2059cdf0e10cSrcweir void AccessibleTextHelper::AddEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) SAL_THROW((uno::RuntimeException)) 2060cdf0e10cSrcweir { 2061cdf0e10cSrcweir #ifdef DBG_UTIL 2062cdf0e10cSrcweir mpImpl->CheckInvariants(); 2063cdf0e10cSrcweir 2064cdf0e10cSrcweir mpImpl->addEventListener( xListener ); 2065cdf0e10cSrcweir 2066cdf0e10cSrcweir mpImpl->CheckInvariants(); 2067cdf0e10cSrcweir #else 2068cdf0e10cSrcweir mpImpl->addEventListener( xListener ); 2069cdf0e10cSrcweir #endif 2070cdf0e10cSrcweir } 2071cdf0e10cSrcweir RemoveEventListener(const uno::Reference<XAccessibleEventListener> & xListener)2072cdf0e10cSrcweir void AccessibleTextHelper::RemoveEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) SAL_THROW((uno::RuntimeException)) 2073cdf0e10cSrcweir { 2074cdf0e10cSrcweir #ifdef DBG_UTIL 2075cdf0e10cSrcweir mpImpl->CheckInvariants(); 2076cdf0e10cSrcweir 2077cdf0e10cSrcweir mpImpl->removeEventListener( xListener ); 2078cdf0e10cSrcweir 2079cdf0e10cSrcweir mpImpl->CheckInvariants(); 2080cdf0e10cSrcweir #else 2081cdf0e10cSrcweir mpImpl->removeEventListener( xListener ); 2082cdf0e10cSrcweir #endif 2083cdf0e10cSrcweir } 2084cdf0e10cSrcweir 2085cdf0e10cSrcweir // XAccessibleComponent GetAt(const awt::Point & aPoint)2086cdf0e10cSrcweir uno::Reference< XAccessible > AccessibleTextHelper::GetAt( const awt::Point& aPoint ) SAL_THROW((uno::RuntimeException)) 2087cdf0e10cSrcweir { 2088cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 2089cdf0e10cSrcweir 2090cdf0e10cSrcweir #ifdef DBG_UTIL 2091cdf0e10cSrcweir mpImpl->CheckInvariants(); 2092cdf0e10cSrcweir 2093cdf0e10cSrcweir uno::Reference< XAccessible > xChild = mpImpl->getAccessibleAtPoint( aPoint ); 2094cdf0e10cSrcweir 2095cdf0e10cSrcweir mpImpl->CheckInvariants(); 2096cdf0e10cSrcweir 2097cdf0e10cSrcweir return xChild; 2098cdf0e10cSrcweir #else 2099cdf0e10cSrcweir return mpImpl->getAccessibleAtPoint( aPoint ); 2100cdf0e10cSrcweir #endif 2101cdf0e10cSrcweir } 2102cdf0e10cSrcweir 2103cdf0e10cSrcweir } // end of namespace accessibility 2104cdf0e10cSrcweir 2105*88c764bfSmseidel /* vim: set noet sw=4 ts=4: */ 2106