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