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