1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
26 #include <osl/mutex.hxx>
27 #include <sal/log.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/awt/Point.hpp>
31 #include <com/sun/star/awt/Rectangle.hpp>
32 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #include <com/sun/star/accessibility/XAccessible.hpp>
35 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
36 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 #include <comphelper/accessibleeventnotifier.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/textdata.hxx>
41 #include <vcl/unohelp.hxx>
44 // Project-local header
47 #include "AccessibleTextEventQueue.hxx"
48 #include <svx/AccessibleTextHelper.hxx>
50 #include <editeng/unoedhlp.hxx>
51 #include <editeng/unoedprx.hxx>
52 #include <editeng/AccessibleParaManager.hxx>
53 #include <editeng/AccessibleEditableTextPara.hxx>
54 #include <svx/svdmodel.hxx>
55 #include <svx/svdpntv.hxx>
57 #include "../table/accessiblecell.hxx"
58 #include <editeng/editdata.hxx>
59 #include <tools/debug.hxx>
60 #include <tools/diagnose_ex.h>
62 using namespace ::com::sun::star
;
63 using namespace ::com::sun::star::accessibility
;
65 namespace accessibility
68 // AccessibleTextHelper_Impl declaration
70 template < typename first_type
, typename second_type
>
71 static ::std::pair
< first_type
, second_type
> makeSortedPair( first_type first
,
75 return ::std::make_pair( second
, first
);
77 return ::std::make_pair( first
, second
);
80 class AccessibleTextHelper_Impl
: public SfxListener
83 typedef ::std::vector
< sal_Int16
> VectorOfStates
;
85 // receive pointer to our frontend class and view window
86 AccessibleTextHelper_Impl();
87 virtual ~AccessibleTextHelper_Impl() override
;
89 // XAccessibleContext child handling methods
90 sal_Int32
getAccessibleChildCount() const;
91 uno::Reference
< XAccessible
> getAccessibleChild( sal_Int32 i
);
93 // XAccessibleEventBroadcaster child related methods
94 void addAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
);
95 void removeAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
);
97 // XAccessibleComponent child related methods
98 uno::Reference
< XAccessible
> getAccessibleAtPoint( const awt::Point
& aPoint
);
100 SvxEditSourceAdapter
& GetEditSource() const;
102 void SetEditSource( ::std::unique_ptr
< SvxEditSource
> && pEditSource
);
104 void SetEventSource( const uno::Reference
< XAccessible
>& rInterface
)
106 mxFrontEnd
= rInterface
;
109 void SetOffset( const Point
& );
110 Point
GetOffset() const
112 ::osl::MutexGuard
aGuard( maMutex
); Point
aPoint( maOffset
);
116 void SetStartIndex( sal_Int32 nOffset
);
117 sal_Int32
GetStartIndex() const
119 // Strictly correct only with locked solar mutex, // but
120 // here we rely on the fact that sal_Int32 access is
125 void SetAdditionalChildStates( const VectorOfStates
& rChildStates
);
129 // do NOT hold object mutex when calling this! Danger of deadlock
130 void FireEvent( const sal_Int16 nEventId
, const uno::Any
& rNewValue
= uno::Any(), const uno::Any
& rOldValue
= uno::Any() ) const;
131 void FireEvent( const AccessibleEventObject
& rEvent
) const;
133 void SetFocus( bool bHaveFocus
);
136 // No locking of solar mutex here, since we rely on the fact
137 // that sal_Bool access is atomic
138 return mbThisHasFocus
;
140 void SetChildFocus( sal_Int32 nChild
, bool bHaveFocus
);
141 void SetShapeFocus( bool bHaveFocus
);
142 void ChangeChildFocus( sal_Int32 nNewChild
);
145 void CheckInvariants() const;
148 // checks all children for visibility, throws away invisible ones
149 void UpdateVisibleChildren( bool bBroadcastEvents
=true );
151 // check all children for changes in position and size
152 void UpdateBoundRect();
154 // calls SetSelection on the forwarder and updates maLastSelection
156 void UpdateSelection();
160 // Process event queue
163 // syntactic sugar for FireEvent
164 void GotPropertyEvent( const uno::Any
& rNewValue
, const sal_Int16 nEventId
) const { FireEvent( nEventId
, rNewValue
); }
166 // shutdown usage of current edit source on myself and the children.
167 void ShutdownEditSource();
169 void ParagraphsMoved( sal_Int32 nFirst
, sal_Int32 nMiddle
, sal_Int32 nLast
);
171 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
173 int getNotifierClientId() const { return mnNotifierClientId
; }
175 // lock solar mutex before
176 SvxTextForwarder
& GetTextForwarder() const;
177 // lock solar mutex before
178 SvxViewForwarder
& GetViewForwarder() const;
179 // lock solar mutex before
180 SvxEditViewForwarder
& GetEditViewForwarder() const;
182 // are we in edit mode?
183 bool IsActive() const;
185 // our frontend class (the one implementing the actual
186 // interface). That's not necessarily the one containing the impl
188 uno::Reference
< XAccessible
> mxFrontEnd
;
190 // a wrapper for the text forwarders (guarded by solar mutex)
191 mutable SvxEditSourceAdapter maEditSource
;
193 // store last selection (to correctly report selection changes, guarded by solar mutex)
194 ESelection maLastSelection
;
196 // cache range of visible children (guarded by solar mutex)
197 sal_Int32 mnFirstVisibleChild
;
198 sal_Int32 mnLastVisibleChild
;
200 // offset to add to all our children (unguarded, relying on
201 // the fact that sal_Int32 access is atomic)
202 sal_Int32 mnStartIndex
;
204 // the object handling our children (guarded by solar mutex)
205 ::accessibility::AccessibleParaManager maParaManager
;
207 // Queued events from Notify() (guarded by solar mutex)
208 AccessibleTextEventQueue maEventQueue
;
210 // spin lock to prevent notify in notify (guarded by solar mutex)
213 // whether the object or its children has the focus set (guarded by solar mutex)
214 bool mbGroupHasFocus
;
216 // whether we (this object) has the focus set (guarded by solar mutex)
219 mutable ::osl::Mutex maMutex
;
221 /// our current offset to the containing shape/cell (guarded by maMutex)
224 /// client Id from AccessibleEventNotifier
225 int mnNotifierClientId
;
228 AccessibleTextHelper_Impl::AccessibleTextHelper_Impl() :
229 maLastSelection( EE_PARA_NOT_FOUND
,EE_INDEX_NOT_FOUND
,EE_PARA_NOT_FOUND
,EE_INDEX_NOT_FOUND
),
230 mnFirstVisibleChild( -1 ),
231 mnLastVisibleChild( -2 ),
234 mbGroupHasFocus( false ),
235 mbThisHasFocus( false ),
237 // well, that's strictly exception safe, though not really
238 // robust. We rely on the fact that this member is constructed
239 // last, and that the constructor body is empty, thus no
240 // chance for exceptions once the Id is fetched. Nevertheless,
241 // normally should employ RAII here...
242 mnNotifierClientId(::comphelper::AccessibleEventNotifier::registerClient())
244 SAL_INFO("svx", "received ID: " << mnNotifierClientId
);
247 AccessibleTextHelper_Impl::~AccessibleTextHelper_Impl()
249 SolarMutexGuard aGuard
;
253 // call Dispose here, too, since we've some resources not
254 // automatically freed otherwise
257 catch( const uno::Exception
& ) {}
260 SvxTextForwarder
& AccessibleTextHelper_Impl::GetTextForwarder() const
262 if( !maEditSource
.IsValid() )
263 throw uno::RuntimeException("Unknown edit source", mxFrontEnd
);
265 SvxTextForwarder
* pTextForwarder
= maEditSource
.GetTextForwarder();
267 if( !pTextForwarder
)
268 throw uno::RuntimeException("Unable to fetch text forwarder, model might be dead", mxFrontEnd
);
270 if( !pTextForwarder
->IsValid() )
271 throw uno::RuntimeException("Text forwarder is invalid, model might be dead", mxFrontEnd
);
273 return *pTextForwarder
;
276 SvxViewForwarder
& AccessibleTextHelper_Impl::GetViewForwarder() const
278 if( !maEditSource
.IsValid() )
279 throw uno::RuntimeException("Unknown edit source", mxFrontEnd
);
281 SvxViewForwarder
* pViewForwarder
= maEditSource
.GetViewForwarder();
283 if( !pViewForwarder
)
284 throw uno::RuntimeException("Unable to fetch view forwarder, model might be dead", mxFrontEnd
);
286 if( !pViewForwarder
->IsValid() )
287 throw uno::RuntimeException("View forwarder is invalid, model might be dead", mxFrontEnd
);
289 return *pViewForwarder
;
292 SvxEditViewForwarder
& AccessibleTextHelper_Impl::GetEditViewForwarder() const
294 if( !maEditSource
.IsValid() )
295 throw uno::RuntimeException("Unknown edit source", mxFrontEnd
);
297 SvxEditViewForwarder
* pViewForwarder
= maEditSource
.GetEditViewForwarder();
299 if( !pViewForwarder
)
301 throw uno::RuntimeException("No edit view forwarder, object not in edit mode", mxFrontEnd
);
304 if( !pViewForwarder
->IsValid() )
306 throw uno::RuntimeException("View forwarder is invalid, object not in edit mode", mxFrontEnd
);
309 return *pViewForwarder
;
312 SvxEditSourceAdapter
& AccessibleTextHelper_Impl::GetEditSource() const
314 if( !maEditSource
.IsValid() )
315 throw uno::RuntimeException("AccessibleTextHelper_Impl::GetEditSource: no edit source", mxFrontEnd
);
321 // functor for sending child events (no stand-alone function, they are maybe not inlined)
322 class AccessibleTextHelper_OffsetChildIndex
325 explicit AccessibleTextHelper_OffsetChildIndex( sal_Int32 nDifference
) : mnDifference(nDifference
) {}
326 void operator()( ::accessibility::AccessibleEditableTextPara
& rPara
)
328 rPara
.SetIndexInParent( rPara
.GetIndexInParent() + mnDifference
);
332 const sal_Int32 mnDifference
;
337 void AccessibleTextHelper_Impl::SetStartIndex( sal_Int32 nOffset
)
339 sal_Int32
nOldOffset( mnStartIndex
);
341 mnStartIndex
= nOffset
;
343 if( nOldOffset
!= nOffset
)
346 AccessibleTextHelper_OffsetChildIndex
aFunctor( nOffset
- nOldOffset
);
348 ::std::for_each( maParaManager
.begin(), maParaManager
.end(),
349 AccessibleParaManager::WeakChildAdapter
< AccessibleTextHelper_OffsetChildIndex
> (aFunctor
) );
353 void AccessibleTextHelper_Impl::SetAdditionalChildStates( const VectorOfStates
& rChildStates
)
355 maParaManager
.SetAdditionalChildStates( rChildStates
);
358 void AccessibleTextHelper_Impl::SetChildFocus( sal_Int32 nChild
, bool bHaveFocus
)
363 SetShapeFocus( false );
365 maParaManager
.SetFocus( nChild
);
367 // we just received the focus, also send caret event then
370 SAL_INFO("svx", "Paragraph " << nChild
<< " received focus");
374 maParaManager
.SetFocus( -1 );
376 SAL_INFO("svx", "Paragraph " << nChild
<< " lost focus");
378 if( mbGroupHasFocus
)
379 SetShapeFocus( true );
383 void AccessibleTextHelper_Impl::ChangeChildFocus( sal_Int32 nNewChild
)
386 SetShapeFocus( false );
388 mbGroupHasFocus
= true;
389 maParaManager
.SetFocus( nNewChild
);
391 SAL_INFO("svx", "Paragraph " << nNewChild
<< " received focus");
394 void AccessibleTextHelper_Impl::SetShapeFocus( bool bHaveFocus
)
396 bool bOldFocus( mbThisHasFocus
);
398 mbThisHasFocus
= bHaveFocus
;
400 if( bOldFocus
== bHaveFocus
)
405 if( mxFrontEnd
.is() )
407 AccessibleCell
* pAccessibleCell
= dynamic_cast< AccessibleCell
* > ( mxFrontEnd
.get() );
408 if ( !pAccessibleCell
)
409 GotPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED
), AccessibleEventId::STATE_CHANGED
);
410 else // the focus event on cell should be fired on table directly
412 AccessibleTableShape
* pAccTable
= pAccessibleCell
->GetParentTable();
414 pAccTable
->SetStateDirectly(AccessibleStateType::FOCUSED
);
417 SAL_INFO("svx", "Parent object received focus" );
421 // The focus state should be reset directly on table.
422 //LostPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED );
423 if( mxFrontEnd
.is() )
425 AccessibleCell
* pAccessibleCell
= dynamic_cast< AccessibleCell
* > ( mxFrontEnd
.get() );
426 if ( !pAccessibleCell
)
427 FireEvent( AccessibleEventId::STATE_CHANGED
, uno::Any(), uno::makeAny(AccessibleStateType::FOCUSED
) );
430 AccessibleTableShape
* pAccTable
= pAccessibleCell
->GetParentTable();
432 pAccTable
->ResetStateDirectly(AccessibleStateType::FOCUSED
);
435 SAL_INFO("svx", "Parent object lost focus" );
439 void AccessibleTextHelper_Impl::SetFocus( bool bHaveFocus
)
441 bool bOldFocus( mbGroupHasFocus
);
443 mbGroupHasFocus
= bHaveFocus
;
449 // find the one with the cursor and get/set focus accordingly
450 ESelection aSelection
;
451 if( GetEditViewForwarder().GetSelection( aSelection
) )
452 SetChildFocus( aSelection
.nEndPara
, bHaveFocus
);
454 catch( const uno::Exception
& ) {}
456 else if( bOldFocus
!= bHaveFocus
)
458 SetShapeFocus( bHaveFocus
);
461 SAL_INFO("svx", "focus changed, Object " << this << ", state: " << (bHaveFocus
? "focused" : "not focused") );
464 bool AccessibleTextHelper_Impl::IsActive() const
468 SvxEditSource
& rEditSource
= GetEditSource();
469 SvxEditViewForwarder
* pViewForwarder
= rEditSource
.GetEditViewForwarder();
471 if( !pViewForwarder
)
474 if( mxFrontEnd
.is() )
476 AccessibleCell
* pAccessibleCell
= dynamic_cast< AccessibleCell
* > ( mxFrontEnd
.get() );
477 if ( pAccessibleCell
)
479 sdr::table::CellRef xCell
= pAccessibleCell
->getCellRef();
481 return xCell
->IsActiveCell();
484 return pViewForwarder
->IsValid();
486 catch( const uno::RuntimeException
& )
492 void AccessibleTextHelper_Impl::UpdateSelection()
496 ESelection aSelection
;
497 if( GetEditViewForwarder().GetSelection( aSelection
) )
499 if( maLastSelection
!= aSelection
&&
500 aSelection
.nEndPara
< maParaManager
.GetNum() )
502 // #103998# Not that important, changed from assertion to trace
505 SAL_INFO("svx", "Parent has focus!");
508 sal_Int32
nMaxValidParaIndex( GetTextForwarder().GetParagraphCount() - 1 );
510 // notify all affected paragraphs (TODO: may be suboptimal,
511 // since some paragraphs might stay selected)
512 if( maLastSelection
.nStartPara
!= EE_PARA_NOT_FOUND
)
514 // Did the caret move from one paragraph to another?
515 // #100530# no caret events if not focused.
516 if( mbGroupHasFocus
&&
517 maLastSelection
.nEndPara
!= aSelection
.nEndPara
)
519 if( maLastSelection
.nEndPara
< maParaManager
.GetNum() )
521 maParaManager
.FireEvent( ::std::min( maLastSelection
.nEndPara
, nMaxValidParaIndex
),
522 ::std::min( maLastSelection
.nEndPara
, nMaxValidParaIndex
)+1,
523 AccessibleEventId::CARET_CHANGED
,
524 uno::makeAny(static_cast<sal_Int32
>(-1)),
525 uno::makeAny(maLastSelection
.nEndPos
) );
528 ChangeChildFocus( aSelection
.nEndPara
);
532 "focus changed, Object: " << this
533 << ", Paragraph: " << aSelection
.nEndPara
534 << ", Last paragraph: "
535 << maLastSelection
.nEndPara
);
539 // #100530# no caret events if not focused.
540 if( mbGroupHasFocus
)
544 // #i13705# The old cursor can only contain valid
545 // values if it's the same paragraph!
546 if( maLastSelection
.nStartPara
!= EE_PARA_NOT_FOUND
&&
547 maLastSelection
.nEndPara
== aSelection
.nEndPara
)
549 aOldCursor
<<= maLastSelection
.nEndPos
;
553 aOldCursor
<<= static_cast<sal_Int32
>(-1);
556 maParaManager
.FireEvent( aSelection
.nEndPara
,
557 aSelection
.nEndPara
+1,
558 AccessibleEventId::CARET_CHANGED
,
559 uno::makeAny(aSelection
.nEndPos
),
565 "caret changed, Object: " << this << ", New pos: "
566 << aSelection
.nEndPos
<< ", Old pos: "
567 << maLastSelection
.nEndPos
<< ", New para: "
568 << aSelection
.nEndPara
<< ", Old para: "
569 << maLastSelection
.nEndPara
);
571 // #108947# Sort new range before calling FireEvent
572 ::std::pair
<sal_Int32
, sal_Int32
> sortedSelection(
573 makeSortedPair(::std::min( aSelection
.nStartPara
, nMaxValidParaIndex
),
574 ::std::min( aSelection
.nEndPara
, nMaxValidParaIndex
) ) );
576 // #108947# Sort last range before calling FireEvent
577 ::std::pair
<sal_Int32
, sal_Int32
> sortedLastSelection(
578 makeSortedPair(::std::min( maLastSelection
.nStartPara
, nMaxValidParaIndex
),
579 ::std::min( maLastSelection
.nEndPara
, nMaxValidParaIndex
) ) );
581 // event TEXT_SELECTION_CHANGED has to be submitted. (#i27299#)
582 const sal_Int16 nTextSelChgEventId
=
583 AccessibleEventId::TEXT_SELECTION_CHANGED
;
584 // #107037# notify selection change
585 if( maLastSelection
.nStartPara
== EE_PARA_NOT_FOUND
)
587 // last selection is undefined
588 // use method <ESelection::HasRange()> (#i27299#)
589 if ( aSelection
.HasRange() )
591 // selection was undefined, now is on
592 maParaManager
.FireEvent( sortedSelection
.first
,
593 sortedSelection
.second
+1,
594 nTextSelChgEventId
);
599 // last selection is valid
600 // use method <ESelection::HasRange()> (#i27299#)
601 if ( maLastSelection
.HasRange() &&
602 !aSelection
.HasRange() )
604 // selection was on, now is empty
605 maParaManager
.FireEvent( sortedLastSelection
.first
,
606 sortedLastSelection
.second
+1,
607 nTextSelChgEventId
);
609 // use method <ESelection::HasRange()> (#i27299#)
610 else if( !maLastSelection
.HasRange() &&
611 aSelection
.HasRange() )
613 // selection was empty, now is on
614 maParaManager
.FireEvent( sortedSelection
.first
,
615 sortedSelection
.second
+1,
616 nTextSelChgEventId
);
618 // no event TEXT_SELECTION_CHANGED event, if new and
619 // last selection are empty. (#i27299#)
620 else if ( maLastSelection
.HasRange() &&
621 aSelection
.HasRange() )
623 // use sorted last and new selection
624 ESelection
aTmpLastSel( maLastSelection
);
625 aTmpLastSel
.Adjust();
626 ESelection
aTmpSel( aSelection
);
628 // first submit event for new and changed selection
629 sal_Int32 nPara
= aTmpSel
.nStartPara
;
630 for ( ; nPara
<= aTmpSel
.nEndPara
; ++nPara
)
632 if ( nPara
< aTmpLastSel
.nStartPara
||
633 nPara
> aTmpLastSel
.nEndPara
)
635 // new selection on paragraph <nPara>
636 maParaManager
.FireEvent( nPara
,
637 nTextSelChgEventId
);
641 // check for changed selection on paragraph <nPara>
642 const sal_Int32 nParaStartPos
=
643 nPara
== aTmpSel
.nStartPara
644 ? aTmpSel
.nStartPos
: 0;
645 const sal_Int32 nParaEndPos
=
646 nPara
== aTmpSel
.nEndPara
647 ? aTmpSel
.nEndPos
: -1;
648 const sal_Int32 nLastParaStartPos
=
649 nPara
== aTmpLastSel
.nStartPara
650 ? aTmpLastSel
.nStartPos
: 0;
651 const sal_Int32 nLastParaEndPos
=
652 nPara
== aTmpLastSel
.nEndPara
653 ? aTmpLastSel
.nEndPos
: -1;
654 if ( nParaStartPos
!= nLastParaStartPos
||
655 nParaEndPos
!= nLastParaEndPos
)
657 maParaManager
.FireEvent(
658 nPara
, nTextSelChgEventId
);
662 // second submit event for 'old' selections
663 nPara
= aTmpLastSel
.nStartPara
;
664 for ( ; nPara
<= aTmpLastSel
.nEndPara
; ++nPara
)
666 if ( nPara
< aTmpSel
.nStartPara
||
667 nPara
> aTmpSel
.nEndPara
)
669 maParaManager
.FireEvent( nPara
,
670 nTextSelChgEventId
);
676 maLastSelection
= aSelection
;
680 // no selection? no update actions
681 catch( const uno::RuntimeException
& ) {}
684 void AccessibleTextHelper_Impl::ShutdownEditSource()
686 // This should only be called with solar mutex locked, i.e. from the main office thread
688 // This here is somewhat clumsy: As soon as our children have
689 // a NULL EditSource (maParaManager.SetEditSource()), they
690 // enter the disposed state and cannot be reanimated. Thus, it
691 // is unavoidable and a hard requirement to let go and create
692 // from scratch each and every child.
694 // invalidate children
695 maParaManager
.Dispose();
696 maParaManager
.SetNum(0);
699 if( mxFrontEnd
.is() )
700 FireEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN
);
702 // quit listen on stale edit source
703 if( maEditSource
.IsValid() )
704 EndListening( maEditSource
.GetBroadcaster() );
706 maEditSource
.SetEditSource( ::std::unique_ptr
< SvxEditSource
>() );
709 void AccessibleTextHelper_Impl::SetEditSource( ::std::unique_ptr
< SvxEditSource
> && pEditSource
)
711 // This should only be called with solar mutex locked, i.e. from the main office thread
713 // shutdown old edit source
714 ShutdownEditSource();
716 // set new edit source
717 maEditSource
.SetEditSource( std::move(pEditSource
) );
719 // init child vector to the current child count
720 if( maEditSource
.IsValid() )
722 maParaManager
.SetNum( GetTextForwarder().GetParagraphCount() );
724 // listen on new edit source
725 StartListening( maEditSource
.GetBroadcaster() );
727 UpdateVisibleChildren();
731 void AccessibleTextHelper_Impl::SetOffset( const Point
& rPoint
)
733 // guard against non-atomic access to maOffset data structure
735 ::osl::MutexGuard
aGuard( maMutex
);
739 maParaManager
.SetEEOffset( rPoint
);
741 // in all cases, check visibility afterwards.
742 UpdateVisibleChildren();
746 void AccessibleTextHelper_Impl::UpdateVisibleChildren( bool bBroadcastEvents
)
750 SvxTextForwarder
& rCacheTF
= GetTextForwarder();
751 sal_Int32 nParas
=rCacheTF
.GetParagraphCount();
753 mnFirstVisibleChild
= -1;
754 mnLastVisibleChild
= -2;
756 for( sal_Int32 nCurrPara
=0; nCurrPara
<nParas
; ++nCurrPara
)
759 mnFirstVisibleChild
= nCurrPara
;
760 mnLastVisibleChild
= nCurrPara
;
761 if (mxFrontEnd
.is() && bBroadcastEvents
)
763 // child not yet created?
764 ::accessibility::AccessibleParaManager::WeakChild
aChild( maParaManager
.GetChild(nCurrPara
) );
765 if( aChild
.second
.Width
== 0 &&
766 aChild
.second
.Height
== 0 )
768 GotPropertyEvent( uno::makeAny( maParaManager
.CreateChild( nCurrPara
- mnFirstVisibleChild
,
769 mxFrontEnd
, GetEditSource(), nCurrPara
).first
),
770 AccessibleEventId::CHILD
);
775 catch( const uno::Exception
& )
777 OSL_FAIL("AccessibleTextHelper_Impl::UpdateVisibleChildren error while determining visible children");
779 // something failed - currently no children
780 mnFirstVisibleChild
= -1;
781 mnLastVisibleChild
= -2;
782 maParaManager
.SetNum(0);
785 if( bBroadcastEvents
)
786 FireEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN
);
792 // functor for checking changes in paragraph bounding boxes (no stand-alone function, maybe not inlined)
793 class AccessibleTextHelper_UpdateChildBounds
796 explicit AccessibleTextHelper_UpdateChildBounds() {}
797 ::accessibility::AccessibleParaManager::WeakChild
operator()( const ::accessibility::AccessibleParaManager::WeakChild
& rChild
)
799 // retrieve hard reference from weak one
800 auto aHardRef( rChild
.first
.get() );
804 awt::Rectangle aNewRect
= aHardRef
->getBounds();
805 const awt::Rectangle
& aOldRect
= rChild
.second
;
807 if( aNewRect
.X
!= aOldRect
.X
||
808 aNewRect
.Y
!= aOldRect
.Y
||
809 aNewRect
.Width
!= aOldRect
.Width
||
810 aNewRect
.Height
!= aOldRect
.Height
)
812 // visible data changed
813 aHardRef
->FireEvent( AccessibleEventId::BOUNDRECT_CHANGED
);
815 // update internal bounds
816 return ::accessibility::AccessibleParaManager::WeakChild( rChild
.first
, aNewRect
);
820 // identity transform
827 void AccessibleTextHelper_Impl::UpdateBoundRect()
829 // send BOUNDRECT_CHANGED to affected children
830 AccessibleTextHelper_UpdateChildBounds aFunctor
;
831 ::std::transform( maParaManager
.begin(), maParaManager
.end(), maParaManager
.begin(), aFunctor
);
835 void AccessibleTextHelper_Impl::CheckInvariants() const
837 if( mnFirstVisibleChild
>= 0 &&
838 mnFirstVisibleChild
> mnLastVisibleChild
)
840 OSL_FAIL( "AccessibleTextHelper: range invalid" );
847 // functor for sending child events (no stand-alone function, they are maybe not inlined)
848 class AccessibleTextHelper_LostChildEvent
851 explicit AccessibleTextHelper_LostChildEvent( AccessibleTextHelper_Impl
& rImpl
) : mrImpl(rImpl
) {}
852 void operator()( const ::accessibility::AccessibleParaManager::WeakChild
& rPara
)
854 // retrieve hard reference from weak one
855 auto aHardRef( rPara
.first
.get() );
858 mrImpl
.FireEvent(AccessibleEventId::CHILD
, uno::Any(), uno::makeAny
<css::uno::Reference
<css::accessibility::XAccessible
>>(aHardRef
.get()) );
862 AccessibleTextHelper_Impl
& mrImpl
;
867 void AccessibleTextHelper_Impl::ParagraphsMoved( sal_Int32 nFirst
, sal_Int32 nMiddle
, sal_Int32 nLast
)
869 const sal_Int32 nParas
= GetTextForwarder().GetParagraphCount();
877 * ... nParagraph ... nParam1 ... nParam2 ...
878 * |______________[xxxxxxxxxxx]
880 * [xxxxxxxxxxx]|______________
885 * ... nParam1 ... nParagraph ... nParam2 ...
886 * [xxxxxxxxxxx|xxxxxxxxxxxxxx]____________
888 * ____________[xxxxxxxxxxx|xxxxxxxxxxxxxx]
890 * tail is nParagraph - nParam1
893 * ... nParam1 ... nParam2 ... nParagraph ...
894 * [xxxxxxxxxxx]___________|____________
896 * ___________|____________[xxxxxxxxxxx]
898 * tail is nParam2 - nParam1
901 // sort nParagraph, nParam1 and nParam2 in ascending order, calc range
902 if( nMiddle
< nFirst
)
904 ::std::swap(nFirst
, nMiddle
);
906 else if( nMiddle
< nLast
)
908 nLast
= nLast
+ nMiddle
- nFirst
;
912 ::std::swap(nMiddle
, nLast
);
913 nLast
= nLast
+ nMiddle
- nFirst
;
916 if( !(nFirst
< nParas
&& nMiddle
< nParas
&& nLast
< nParas
) )
919 // since we have no "paragraph index
920 // changed" event on UAA, remove
921 // [first,last] and insert again later (in
922 // UpdateVisibleChildren)
924 // maParaManager.Rotate( nFirst, nMiddle, nLast );
926 // send CHILD_EVENT to affected children
927 ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator begin
= maParaManager
.begin();
928 ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator end
= begin
;
930 ::std::advance( begin
, nFirst
);
931 ::std::advance( end
, nLast
+1 );
933 // TODO: maybe optimize here in the following way. If the
934 // number of removed children exceeds a certain threshold,
935 // use InvalidateFlags::Children
936 AccessibleTextHelper_LostChildEvent
aFunctor( *this );
938 ::std::for_each( begin
, end
, aFunctor
);
940 maParaManager
.Release(nFirst
, nLast
+1);
941 // should be no need for UpdateBoundRect, since all affected children are cleared.
946 // functor for sending child events (no stand-alone function, they are maybe not inlined)
947 class AccessibleTextHelper_ChildrenTextChanged
950 void operator()( ::accessibility::AccessibleEditableTextPara
& rPara
)
956 /** functor processing queue events
958 Reacts on SfxHintId::TextParaInserted/REMOVED events and stores
961 class AccessibleTextHelper_QueueFunctor
964 AccessibleTextHelper_QueueFunctor() :
967 mnHintId(SfxHintId::NONE
)
969 void operator()( const SfxHint
* pEvent
)
971 if( !pEvent
|| mnParasChanged
== -1 )
974 // determine hint type
975 const TextHint
* pTextHint
= dynamic_cast<const TextHint
*>( pEvent
);
976 const SvxEditSourceHint
* pEditSourceHint
= dynamic_cast<const SvxEditSourceHint
*>( pEvent
);
978 if( !(!pEditSourceHint
&& pTextHint
&&
979 (pTextHint
->GetId() == SfxHintId::TextParaInserted
||
980 pTextHint
->GetId() == SfxHintId::TextParaRemoved
)) )
983 if( pTextHint
->GetValue() == EE_PARA_ALL
)
989 mnHintId
= pTextHint
->GetId();
990 mnParaIndex
= pTextHint
->GetValue();
995 /** Query number of paragraphs changed during queue processing.
997 @return number of changed paragraphs, -1 for
998 "every paragraph changed"
1000 sal_Int32
GetNumberOfParasChanged() const { return mnParasChanged
; }
1001 /** Query index of last added/removed paragraph
1003 @return index of lastly added paragraphs, -1 for none
1006 sal_Int32
GetParaIndex() const { return mnParaIndex
; }
1007 /** Query hint id of last interesting event
1009 @return hint id of last interesting event (REMOVED/INSERTED).
1011 SfxHintId
GetHintId() const { return mnHintId
; }
1014 /** number of paragraphs changed during queue processing. -1 for
1015 "every paragraph changed"
1017 sal_Int32 mnParasChanged
;
1018 /// index of paragraph added/removed last
1019 sal_Int32 mnParaIndex
;
1020 /// TextHint ID (removed/inserted) of last interesting event
1026 void AccessibleTextHelper_Impl::ProcessQueue()
1028 // inspect queue for paragraph insert/remove events. If there
1029 // is exactly _one_ of those in the queue, and the number of
1030 // paragraphs has changed by exactly one, use that event to
1031 // determine a priori which paragraph was added/removed. This
1032 // is necessary, since I must sync right here with the
1033 // EditEngine state (number of paragraphs etc.), since I'm
1034 // potentially sending listener events right away.
1035 AccessibleTextHelper_QueueFunctor aFunctor
;
1036 maEventQueue
.ForEach( aFunctor
);
1038 const sal_Int32
nNewParas( GetTextForwarder().GetParagraphCount() );
1039 const sal_Int32
nCurrParas( maParaManager
.GetNum() );
1041 // whether every paragraph already is updated (no need to
1042 // repeat that later on, e.g. for PARA_MOVED events)
1043 bool bEverythingUpdated( false );
1045 if( std::abs( nNewParas
- nCurrParas
) == 1 &&
1046 aFunctor
.GetNumberOfParasChanged() == 1 )
1048 // #103483# Exactly one paragraph added/removed. This is
1049 // the normal case, optimize event handling here.
1051 if( aFunctor
.GetHintId() == SfxHintId::TextParaInserted
)
1053 // update num of paras
1054 maParaManager
.SetNum( nNewParas
);
1056 // release everything from the insertion position until the end
1057 maParaManager
.Release(aFunctor
.GetParaIndex(), nCurrParas
);
1059 // TODO: Clarify whether this behaviour _really_ saves
1060 // anybody anything!
1061 // update children, _don't_ broadcast
1062 UpdateVisibleChildren( false );
1065 // send insert event
1066 // #109864# Enforce creation of this paragraph
1069 GotPropertyEvent( uno::makeAny( getAccessibleChild( aFunctor
.GetParaIndex() -
1070 mnFirstVisibleChild
+ GetStartIndex() ) ),
1071 AccessibleEventId::CHILD
);
1073 catch( const uno::Exception
& )
1075 OSL_FAIL("AccessibleTextHelper_Impl::ProcessQueue: could not create new paragraph");
1078 else if( aFunctor
.GetHintId() == SfxHintId::TextParaRemoved
)
1080 ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator begin
= maParaManager
.begin();
1081 ::std::advance( begin
, aFunctor
.GetParaIndex() );
1082 ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator end
= begin
;
1083 ::std::advance( end
, 1 );
1085 // #i61812# remember para to be removed for later notification
1086 // AFTER the new state is applied (that after the para got removed)
1087 ::uno::Reference
< XAccessible
> xPara(begin
->first
.get().get());
1089 // release everything from the remove position until the end
1090 maParaManager
.Release(aFunctor
.GetParaIndex(), nCurrParas
);
1092 // update num of paras
1093 maParaManager
.SetNum( nNewParas
);
1095 // TODO: Clarify whether this behaviour _really_ saves
1096 // anybody anything!
1097 // update children, _don't_ broadcast
1098 UpdateVisibleChildren( false );
1101 // #i61812# notification for removed para
1103 FireEvent(AccessibleEventId::CHILD
, uno::Any(), uno::makeAny( xPara
) );
1107 OSL_FAIL("AccessibleTextHelper_Impl::ProcessQueue() invalid hint id");
1110 else if( nNewParas
!= nCurrParas
)
1112 // release all paras
1113 maParaManager
.Release(0, nCurrParas
);
1115 // update num of paras
1116 maParaManager
.SetNum( nNewParas
);
1118 // #109864# create from scratch, don't broadcast
1119 UpdateVisibleChildren( false );
1122 // number of paragraphs somehow changed - but we have no
1123 // chance determining how. Thus, throw away everything and
1124 // create from scratch.
1125 // (child events should be broadcast after the changes are done...)
1126 FireEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN
);
1128 // no need for further updates later on
1129 bEverythingUpdated
= true;
1132 while( !maEventQueue
.IsEmpty() )
1134 ::std::unique_ptr
< SfxHint
> pHint( maEventQueue
.PopFront() );
1137 const SfxHint
& rHint
= *pHint
;
1139 // Note, if you add events here, you need to update the AccessibleTextEventQueue::Append
1140 // code, because only the events we process here, are actually queued there.
1145 if (rHint
.GetId() == SfxHintId::ThisIsAnSdrHint
)
1147 const SdrHint
* pSdrHint
= static_cast< const SdrHint
* >( &rHint
);
1149 switch( pSdrHint
->GetKind() )
1151 case SdrHintKind::BeginEdit
:
1157 // change children state
1158 maParaManager
.SetActive();
1160 // per definition, edit mode text has the focus
1165 case SdrHintKind::EndEdit
:
1167 // focused child now loses focus
1168 ESelection aSelection
;
1169 if( GetEditViewForwarder().GetSelection( aSelection
) )
1170 SetChildFocus( aSelection
.nEndPara
, false );
1172 // change children state
1173 maParaManager
.SetActive( false );
1175 maLastSelection
= ESelection( EE_PARA_NOT_FOUND
, EE_INDEX_NOT_FOUND
,
1176 EE_PARA_NOT_FOUND
, EE_INDEX_NOT_FOUND
);
1183 else if( const SvxEditSourceHint
* pEditSourceHint
= dynamic_cast<const SvxEditSourceHint
*>( &rHint
) )
1185 switch( pEditSourceHint
->GetId() )
1187 case SfxHintId::EditSourceParasMoved
:
1189 DBG_ASSERT( pEditSourceHint
->GetStartValue() < GetTextForwarder().GetParagraphCount() &&
1190 pEditSourceHint
->GetEndValue() < GetTextForwarder().GetParagraphCount(),
1191 "AccessibleTextHelper_Impl::NotifyHdl: Invalid notification");
1193 if( !bEverythingUpdated
)
1195 ParagraphsMoved(pEditSourceHint
->GetStartValue(),
1196 pEditSourceHint
->GetValue(),
1197 pEditSourceHint
->GetEndValue());
1199 // in all cases, check visibility afterwards.
1200 UpdateVisibleChildren();
1205 case SfxHintId::EditSourceSelectionChanged
:
1211 // maybe we're not in edit mode (this is not an error)
1212 catch( const uno::Exception
& ) {}
1217 else if( const TextHint
* pTextHint
= dynamic_cast<const TextHint
*>( &rHint
) )
1219 const sal_Int32 nParas
= GetTextForwarder().GetParagraphCount();
1221 switch( pTextHint
->GetId() )
1223 case SfxHintId::TextModified
:
1226 sal_Int32
nPara( pTextHint
->GetValue() );
1228 // #108900# Delegate change event to children
1229 AccessibleTextHelper_ChildrenTextChanged aNotifyChildrenFunctor
;
1231 if( nPara
== EE_PARA_ALL
)
1233 // #108900# Call every child
1234 ::std::for_each( maParaManager
.begin(), maParaManager
.end(),
1235 AccessibleParaManager::WeakChildAdapter
< AccessibleTextHelper_ChildrenTextChanged
> (aNotifyChildrenFunctor
) );
1238 if( nPara
< nParas
)
1240 // #108900# Call child at index nPara
1241 ::std::for_each( maParaManager
.begin()+nPara
, maParaManager
.begin()+nPara
+1,
1242 AccessibleParaManager::WeakChildAdapter
< AccessibleTextHelper_ChildrenTextChanged
> (aNotifyChildrenFunctor
) );
1247 case SfxHintId::TextParaInserted
:
1248 // already happened above
1251 case SfxHintId::TextParaRemoved
:
1252 // already happened above
1255 case SfxHintId::TextHeightChanged
:
1256 // visibility changed, done below
1259 case SfxHintId::TextViewScrolled
:
1260 // visibility changed, done below
1265 // in all cases, check visibility afterwards.
1266 UpdateVisibleChildren();
1269 else if ( dynamic_cast<const SvxViewChangedHint
*>( &rHint
) )
1271 // just check visibility
1272 UpdateVisibleChildren();
1275 // it's VITAL to keep the SfxSimpleHint last! It's the base of some classes above!
1276 else if( rHint
.GetId() == SfxHintId::Dying
)
1278 // edit source is dying under us, become defunc then
1281 // make edit source inaccessible
1282 // Note: cannot destroy it here, since we're called from there!
1283 ShutdownEditSource();
1285 catch( const uno::Exception
& ) {}
1288 catch( const uno::Exception
& )
1290 DBG_UNHANDLED_EXCEPTION("svx");
1296 void AccessibleTextHelper_Impl::Notify( SfxBroadcaster
& /*rBC*/, const SfxHint
& rHint
)
1298 // precondition: solar mutex locked
1299 DBG_TESTSOLARMUTEX();
1301 // precondition: not in a recursion
1309 // Process notification event, arranged in order of likelihood of
1310 // occurrence to avoid unnecessary dynamic_cast. Note that
1311 // SvxEditSourceHint is derived from TextHint, so has to be checked
1313 if (rHint
.GetId() == SfxHintId::ThisIsAnSdrHint
)
1315 const SdrHint
* pSdrHint
= static_cast< const SdrHint
* >( &rHint
);
1316 // process drawing layer events right away, if not
1317 // within an open EE notification frame. Otherwise,
1318 // event processing would be delayed until next EE
1319 // notification sequence.
1320 maEventQueue
.Append( *pSdrHint
);
1322 else if( const SvxViewChangedHint
* pViewHint
= dynamic_cast<const SvxViewChangedHint
*>( &rHint
) )
1324 // process visibility right away, if not within an
1325 // open EE notification frame. Otherwise, event
1326 // processing would be delayed until next EE
1327 // notification sequence.
1328 maEventQueue
.Append( *pViewHint
);
1330 else if( const SvxEditSourceHint
* pEditSourceHint
= dynamic_cast<const SvxEditSourceHint
*>( &rHint
) )
1332 // EditEngine should emit TEXT_SELECTION_CHANGED events (#i27299#)
1333 maEventQueue
.Append( *pEditSourceHint
);
1335 else if( const TextHint
* pTextHint
= dynamic_cast<const TextHint
*>( &rHint
) )
1337 // EditEngine should emit TEXT_SELECTION_CHANGED events (#i27299#)
1338 if(pTextHint
->GetId() == SfxHintId::TextProcessNotifications
)
1341 maEventQueue
.Append( *pTextHint
);
1343 // it's VITAL to keep the SfxHint last! It's the base of the classes above!
1344 else if( rHint
.GetId() == SfxHintId::Dying
)
1346 // handle this event _at once_, because after that, objects are invalid
1347 // edit source is dying under us, become defunc then
1348 maEventQueue
.Clear();
1351 // make edit source inaccessible
1352 // Note: cannot destroy it here, since we're called from there!
1353 ShutdownEditSource();
1355 catch( const uno::Exception
& ) {}
1358 catch( const uno::Exception
& )
1360 DBG_UNHANDLED_EXCEPTION("svx");
1367 void AccessibleTextHelper_Impl::Dispose()
1369 if( getNotifierClientId() != -1 )
1373 // #106234# Unregister from EventNotifier
1374 ::comphelper::AccessibleEventNotifier::revokeClient( getNotifierClientId() );
1375 SAL_INFO("svx", "disposed ID: " << mnNotifierClientId
);
1377 catch( const uno::Exception
& ) {}
1379 mnNotifierClientId
= -1;
1385 maParaManager
.Dispose();
1387 catch( const uno::Exception
& ) {}
1389 // quit listen on stale edit source
1390 if( maEditSource
.IsValid() )
1391 EndListening( maEditSource
.GetBroadcaster() );
1394 maEditSource
.SetEditSource( ::std::unique_ptr
< SvxEditSource
>() );
1395 mxFrontEnd
= nullptr;
1398 void AccessibleTextHelper_Impl::FireEvent( const sal_Int16 nEventId
, const uno::Any
& rNewValue
, const uno::Any
& rOldValue
) const
1400 // -- object locked --
1401 AccessibleEventObject aEvent
;
1403 osl::MutexGuard
aGuard(maMutex
);
1405 DBG_ASSERT(mxFrontEnd
.is(), "AccessibleTextHelper::FireEvent: no event source set");
1407 if (mxFrontEnd
.is())
1408 aEvent
= AccessibleEventObject(mxFrontEnd
->getAccessibleContext(), nEventId
,
1409 rNewValue
, rOldValue
);
1411 aEvent
= AccessibleEventObject(uno::Reference
<uno::XInterface
>(), nEventId
,
1412 rNewValue
, rOldValue
);
1414 // no locking necessary, FireEvent internally copies listeners
1415 // if someone removes/adds in between Further locking,
1416 // actually, might lead to deadlocks, since we're calling out
1424 void AccessibleTextHelper_Impl::FireEvent( const AccessibleEventObject
& rEvent
) const
1426 // #102261# Call global queue for focus events
1427 if( rEvent
.EventId
== AccessibleStateType::FOCUSED
)
1428 vcl::unohelper::NotifyAccessibleStateEventGlobally( rEvent
);
1430 // #106234# Delegate to EventNotifier
1431 ::comphelper::AccessibleEventNotifier::addEvent( getNotifierClientId(),
1435 // XAccessibleContext
1436 sal_Int32
AccessibleTextHelper_Impl::getAccessibleChildCount() const
1438 return mnLastVisibleChild
- mnFirstVisibleChild
+ 1;
1441 uno::Reference
< XAccessible
> AccessibleTextHelper_Impl::getAccessibleChild( sal_Int32 i
)
1443 i
-= GetStartIndex();
1445 if( 0 > i
|| i
>= getAccessibleChildCount() ||
1446 GetTextForwarder().GetParagraphCount() <= i
)
1448 throw lang::IndexOutOfBoundsException("Invalid child index", mxFrontEnd
);
1451 DBG_ASSERT(mxFrontEnd
.is(), "AccessibleTextHelper_Impl::UpdateVisibleChildren: no frontend set");
1453 if( mxFrontEnd
.is() )
1454 return maParaManager
.CreateChild( i
, mxFrontEnd
, GetEditSource(), mnFirstVisibleChild
+ i
).first
;
1459 void AccessibleTextHelper_Impl::addAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
1461 if( getNotifierClientId() != -1 )
1462 ::comphelper::AccessibleEventNotifier::addEventListener( getNotifierClientId(), xListener
);
1465 void AccessibleTextHelper_Impl::removeAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
1467 if( getNotifierClientId() == -1 )
1470 const sal_Int32 nListenerCount
= ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener
);
1471 if ( !nListenerCount
)
1473 // no listeners anymore
1474 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
1475 // and at least to us not firing any events anymore, in case somebody calls
1476 // NotifyAccessibleEvent, again
1477 ::comphelper::AccessibleEventNotifier::TClientId
nId( getNotifierClientId() );
1478 mnNotifierClientId
= -1;
1479 ::comphelper::AccessibleEventNotifier::revokeClient( nId
);
1483 uno::Reference
< XAccessible
> AccessibleTextHelper_Impl::getAccessibleAtPoint( const awt::Point
& _aPoint
)
1485 // make given position relative
1486 if( !mxFrontEnd
.is() )
1487 throw uno::RuntimeException("AccessibleTextHelper_Impl::getAccessibleAt: frontend invalid", mxFrontEnd
);
1489 uno::Reference
< XAccessibleContext
> xFrontEndContext
= mxFrontEnd
->getAccessibleContext();
1491 if( !xFrontEndContext
.is() )
1492 throw uno::RuntimeException("AccessibleTextHelper_Impl::getAccessibleAt: frontend invalid", mxFrontEnd
);
1494 uno::Reference
< XAccessibleComponent
> xFrontEndComponent( xFrontEndContext
, uno::UNO_QUERY_THROW
);
1496 // #103862# No longer need to make given position relative
1497 Point
aPoint( _aPoint
.X
, _aPoint
.Y
);
1499 // respect EditEngine offset to surrounding shape/cell
1500 aPoint
-= GetOffset();
1502 // convert to EditEngine coordinate system
1503 SvxTextForwarder
& rCacheTF
= GetTextForwarder();
1504 Point
aLogPoint( GetViewForwarder().PixelToLogic( aPoint
, rCacheTF
.GetMapMode() ) );
1506 // iterate over all visible children (including those not yet created)
1508 for( nChild
=mnFirstVisibleChild
; nChild
<= mnLastVisibleChild
; ++nChild
)
1510 DBG_ASSERT(nChild
>= 0,
1511 "AccessibleTextHelper_Impl::getAccessibleAt: index value overflow");
1513 tools::Rectangle
aParaBounds( rCacheTF
.GetParaBounds( nChild
) );
1515 if( aParaBounds
.IsInside( aLogPoint
) )
1516 return getAccessibleChild( nChild
- mnFirstVisibleChild
+ GetStartIndex() );
1524 // AccessibleTextHelper implementation (simply forwards to impl)
1526 AccessibleTextHelper::AccessibleTextHelper( ::std::unique_ptr
< SvxEditSource
> && pEditSource
) :
1527 mpImpl( new AccessibleTextHelper_Impl() )
1529 SolarMutexGuard aGuard
;
1531 SetEditSource( std::move(pEditSource
) );
1534 AccessibleTextHelper::~AccessibleTextHelper()
1538 const SvxEditSource
& AccessibleTextHelper::GetEditSource() const
1541 mpImpl
->CheckInvariants();
1543 const SvxEditSource
& aEditSource
= mpImpl
->GetEditSource();
1545 mpImpl
->CheckInvariants();
1549 return mpImpl
->GetEditSource();
1553 void AccessibleTextHelper::SetEditSource( ::std::unique_ptr
< SvxEditSource
> && pEditSource
)
1556 // precondition: solar mutex locked
1557 DBG_TESTSOLARMUTEX();
1559 mpImpl
->CheckInvariants();
1562 mpImpl
->SetEditSource( std::move(pEditSource
) );
1565 mpImpl
->CheckInvariants();
1569 void AccessibleTextHelper::SetEventSource( const uno::Reference
< XAccessible
>& rInterface
)
1572 mpImpl
->CheckInvariants();
1575 mpImpl
->SetEventSource( rInterface
);
1578 mpImpl
->CheckInvariants();
1582 void AccessibleTextHelper::SetFocus( bool bHaveFocus
)
1585 // precondition: solar mutex locked
1586 DBG_TESTSOLARMUTEX();
1588 mpImpl
->CheckInvariants();
1591 mpImpl
->SetFocus( bHaveFocus
);
1594 mpImpl
->CheckInvariants();
1598 bool AccessibleTextHelper::HaveFocus()
1601 mpImpl
->CheckInvariants();
1603 bool bRet( mpImpl
->HaveFocus() );
1605 mpImpl
->CheckInvariants();
1609 return mpImpl
->HaveFocus();
1613 void AccessibleTextHelper::SetOffset( const Point
& rPoint
)
1616 // precondition: solar mutex locked
1617 DBG_TESTSOLARMUTEX();
1619 mpImpl
->CheckInvariants();
1622 mpImpl
->SetOffset( rPoint
);
1625 mpImpl
->CheckInvariants();
1629 void AccessibleTextHelper::SetStartIndex( sal_Int32 nOffset
)
1632 // precondition: solar mutex locked
1633 DBG_TESTSOLARMUTEX();
1635 mpImpl
->CheckInvariants();
1638 mpImpl
->SetStartIndex( nOffset
);
1641 mpImpl
->CheckInvariants();
1645 sal_Int32
AccessibleTextHelper::GetStartIndex() const
1648 mpImpl
->CheckInvariants();
1650 sal_Int32 nOffset
= mpImpl
->GetStartIndex();
1652 mpImpl
->CheckInvariants();
1656 return mpImpl
->GetStartIndex();
1660 void AccessibleTextHelper::SetAdditionalChildStates( const VectorOfStates
& rChildStates
)
1662 mpImpl
->SetAdditionalChildStates( rChildStates
);
1665 void AccessibleTextHelper::UpdateChildren()
1668 // precondition: solar mutex locked
1669 DBG_TESTSOLARMUTEX();
1671 mpImpl
->CheckInvariants();
1674 mpImpl
->UpdateVisibleChildren();
1675 mpImpl
->UpdateBoundRect();
1677 mpImpl
->UpdateSelection();
1680 mpImpl
->CheckInvariants();
1684 void AccessibleTextHelper::Dispose()
1686 // As Dispose calls ShutdownEditSource, which in turn
1687 // deregisters as listener on the edit source, have to lock
1689 SolarMutexGuard aGuard
;
1692 mpImpl
->CheckInvariants();
1698 mpImpl
->CheckInvariants();
1702 // XAccessibleContext
1703 sal_Int32
AccessibleTextHelper::GetChildCount() const
1705 SolarMutexGuard aGuard
;
1708 mpImpl
->CheckInvariants();
1710 sal_Int32 nRet
= mpImpl
->getAccessibleChildCount();
1712 mpImpl
->CheckInvariants();
1716 return mpImpl
->getAccessibleChildCount();
1720 uno::Reference
< XAccessible
> AccessibleTextHelper::GetChild( sal_Int32 i
)
1722 SolarMutexGuard aGuard
;
1725 mpImpl
->CheckInvariants();
1727 uno::Reference
< XAccessible
> xRet
= mpImpl
->getAccessibleChild( i
);
1729 mpImpl
->CheckInvariants();
1733 return mpImpl
->getAccessibleChild( i
);
1737 void AccessibleTextHelper::AddEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
1740 mpImpl
->CheckInvariants();
1742 mpImpl
->addAccessibleEventListener( xListener
);
1744 mpImpl
->CheckInvariants();
1746 mpImpl
->addAccessibleEventListener( xListener
);
1750 void AccessibleTextHelper::RemoveEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
1753 mpImpl
->CheckInvariants();
1755 mpImpl
->removeAccessibleEventListener( xListener
);
1757 mpImpl
->CheckInvariants();
1759 mpImpl
->removeAccessibleEventListener( xListener
);
1763 // XAccessibleComponent
1764 uno::Reference
< XAccessible
> AccessibleTextHelper::GetAt( const awt::Point
& aPoint
)
1766 SolarMutexGuard aGuard
;
1769 mpImpl
->CheckInvariants();
1771 uno::Reference
< XAccessible
> xChild
= mpImpl
->getAccessibleAtPoint( aPoint
);
1773 mpImpl
->CheckInvariants();
1777 return mpImpl
->getAccessibleAtPoint( aPoint
);
1781 } // end of namespace accessibility
1784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */