xref: /trunk/main/sw/source/core/access/acccontext.cxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #if (OSL_DEBUG_LEVEL > 1) && defined TEST_MIB
27     #ifndef _STRING_HXX
28     #include <tools/string.hxx>
29     #endif
30 
31     #ifndef _STREAM_HXX
32     #include <tools/stream.hxx>
33     #endif
34 #endif // #if (OSL_DEBUG_LEVEL > 1) && defined TEST_MIB
35 #include <tools/debug.hxx>
36 #include <vcl/window.hxx>
37 #include <errhdl.hxx>
38 #include <swtypes.hxx>
39 
40 #include <com/sun/star/accessibility/XAccessible.hpp>
41 #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
42 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
44 #include <vos/mutex.hxx>
45 #include <vcl/svapp.hxx>
46 #include <unotools/accessiblestatesethelper.hxx>
47 #include <unotools/accessiblerelationsethelper.hxx>
48 #include <viewsh.hxx>
49 #include <crsrsh.hxx>
50 #include <fesh.hxx>
51 #include <txtfrm.hxx>
52 #include <ndtxt.hxx>
53 #include <pagefrm.hxx>
54 #include <flyfrm.hxx>
55 #include <dflyobj.hxx>
56 #include <pam.hxx>
57 #include <viewimp.hxx>
58 #include <accmap.hxx>
59 #include <accfrmobjslist.hxx>
60 #include <acccontext.hxx>
61 #include <svx/AccessibleShape.hxx>
62 #include <comphelper/accessibleeventnotifier.hxx>
63 //IAccessibility2 Implementation 2009-----
64 #ifndef _ACCPARA_HXX
65 #include "accpara.hxx"
66 #endif
67 //-----IAccessibility2 Implementation 2009
68 #include <PostItMgr.hxx>
69 
70 using namespace sw::access;
71 
72 #if (OSL_DEBUG_LEVEL > 1) && defined TEST_MIB
73 #define DBG_MSG( _msg ) \
74     lcl_SwAccessibleContext_DbgMsg( this, _msg, 0, sal_False );
75 #define DBG_MSG_CD( _msg ) \
76     lcl_SwAccessibleContext_DbgMsg( this, _msg, 0, sal_True );
77 #define DBG_MSG_PARAM( _msg, _param ) \
78     lcl_SwAccessibleContext_DbgMsg( this, _msg, _param, sal_False );
79 #define DBG_MSG_THIS_PARAM( _msg, _this, _param ) \
80     lcl_SwAccessibleContext_DbgMsg( _this, _msg, _param, sal_False );
81 
82 void lcl_SwAccessibleContext_DbgMsg( SwAccessibleContext *pThisAcc,
83                                      const char *pMsg,
84                                      SwAccessibleContext *pChildAcc,
85                                      sal_Bool bConstrDestr );
86 #else
87 #define DBG_MSG( _msg )
88 #define DBG_MSG_PARAM( _msg, _param )
89 #define DBG_MSG_THIS_PARAM( _msg, _this, _param )
90 #define DBG_MSG_CD( _msg )
91 #endif
92 
93 using namespace ::com::sun::star;
94 using namespace ::com::sun::star::accessibility;
95 using ::rtl::OUString;
96 
97 void SwAccessibleContext::InitStates()
98 {
99     bIsShowingState = GetMap() ? IsShowing( *(GetMap()) ) : sal_False;
100 
101     ViewShell *pVSh = GetMap()->GetShell();
102     bIsEditableState = pVSh && IsEditable( pVSh );
103     bIsOpaqueState = pVSh && IsOpaque( pVSh );
104     bIsDefuncState = sal_False;
105 }
106 
107 void SwAccessibleContext::SetParent( SwAccessibleContext *pParent )
108 {
109     vos::OGuard aGuard( aMutex );
110 
111     uno::Reference < XAccessible > xParent( pParent );
112     xWeakParent = xParent;
113 }
114 
115 uno::Reference< XAccessible > SwAccessibleContext::GetWeakParent() const
116 {
117     vos::OGuard aGuard( aMutex );
118 
119     uno::Reference< XAccessible > xParent( xWeakParent );
120     return xParent;
121 }
122 
123 Window *SwAccessibleContext::GetWindow()
124 {
125     Window *pWin = 0;
126 
127     if( GetMap() )
128     {
129         const ViewShell *pVSh = GetMap()->GetShell();
130         ASSERT( pVSh, "no view shell" );
131         if( pVSh )
132             pWin = pVSh->GetWin();
133 
134         ASSERT( pWin, "no window" );
135     }
136 
137     return pWin;
138 }
139 
140 // get ViewShell from accessibility map, and cast to cursor shell
141 SwCrsrShell* SwAccessibleContext::GetCrsrShell()
142 {
143     SwCrsrShell* pCrsrShell;
144     ViewShell* pViewShell = GetMap() ? GetMap()->GetShell() : 0;
145     ASSERT( pViewShell, "no view shell" );
146     if( pViewShell && pViewShell->ISA( SwCrsrShell ) )
147         pCrsrShell = static_cast<SwCrsrShell*>( pViewShell );
148     else
149         pCrsrShell = NULL;
150 
151     return pCrsrShell;
152 }
153 
154 const SwCrsrShell* SwAccessibleContext::GetCrsrShell() const
155 {
156     // just like non-const GetCrsrShell
157     const SwCrsrShell* pCrsrShell;
158     const ViewShell* pViewShell = GetMap() ? GetMap()->GetShell() : 0;
159     ASSERT( pViewShell, "no view shell" );
160     if( pViewShell && pViewShell->ISA( SwCrsrShell ) )
161         pCrsrShell = static_cast<const SwCrsrShell*>( pViewShell );
162     else
163         pCrsrShell = NULL;
164 
165     return pCrsrShell;
166 }
167 
168 
169 enum Action { NONE, SCROLLED, SCROLLED_WITHIN,
170                           SCROLLED_IN, SCROLLED_OUT };
171 
172 void SwAccessibleContext::ChildrenScrolled( const SwFrm *pFrm,
173                                             const SwRect& rOldVisArea )
174 {
175     const SwRect& rNewVisArea = GetVisArea();
176     const bool bVisibleChildrenOnly = SwAccessibleChild( pFrm ).IsVisibleChildrenOnly();
177 
178     const SwAccessibleChildSList aList( *pFrm, *(GetMap()) );
179     SwAccessibleChildSList::const_iterator aIter( aList.begin() );
180     while( aIter != aList.end() )
181     {
182         const SwAccessibleChild& rLower = *aIter;
183         const SwRect aBox( rLower.GetBox( *(GetMap()) ) );
184         if( rLower.IsAccessible( GetShell()->IsPreView() ) )
185         {
186             Action eAction = NONE;
187             if( aBox.IsOver( rNewVisArea ) )
188             {
189                 if( aBox.IsOver( rOldVisArea ) )
190                 {
191                     eAction = SCROLLED_WITHIN;
192                 }
193                 else
194                 {
195                     if ( bVisibleChildrenOnly &&
196                          !rLower.AlwaysIncludeAsChild() )
197                     {
198                         eAction = SCROLLED_IN;
199                     }
200                     else
201                     {
202                         eAction = SCROLLED;
203                     }
204                 }
205             }
206             else if( aBox.IsOver( rOldVisArea ) )
207             {
208                 if ( bVisibleChildrenOnly &&
209                      !rLower.AlwaysIncludeAsChild() )
210                 {
211                     eAction = SCROLLED_OUT;
212                 }
213                 else
214                 {
215                     eAction = SCROLLED;
216                 }
217             }
218             else if( !bVisibleChildrenOnly ||
219                      rLower.AlwaysIncludeAsChild() )
220             {
221                 // This wouldn't be required if the SwAccessibleFrame,
222                 // wouldn't know about the vis area.
223                 eAction = SCROLLED;
224             }
225             if( NONE != eAction )
226             {
227                 if ( rLower.GetSwFrm() )
228                 {
229                     ASSERT( !rLower.AlwaysIncludeAsChild(),
230                             "<SwAccessibleContext::ChildrenScrolled(..)> - always included child not considered!" );
231                     const SwFrm* pLower( rLower.GetSwFrm() );
232                     ::vos::ORef< SwAccessibleContext > xAccImpl =
233                         //IAccessibility2 Implementation 2009-----
234                         //O is: GetMap()->GetContextImpl( pLower, SCROLLED_OUT == eAction ||
235                         //                      SCROLLED_IN == eAction );
236                         GetMap()->GetContextImpl( pLower, sal_True );
237                         //-----IAccessibility2 Implementation 2009
238                     if( xAccImpl.isValid() )
239                     {
240                         switch( eAction )
241                         {
242                         case SCROLLED:
243                             xAccImpl->Scrolled( rOldVisArea );
244                             break;
245                         case SCROLLED_WITHIN:
246                             xAccImpl->ScrolledWithin( rOldVisArea );
247                             break;
248                         case SCROLLED_IN:
249                             xAccImpl->ScrolledIn();
250                             break;
251                         case SCROLLED_OUT:
252                             xAccImpl->ScrolledOut( rOldVisArea );
253                             break;
254                         case NONE:
255                             break;
256                         }
257                     }
258                     else
259                     {
260                         ChildrenScrolled( pLower, rOldVisArea );
261                     }
262                 }
263                 else if ( rLower.GetDrawObject() )
264                 {
265                     ASSERT( !rLower.AlwaysIncludeAsChild(),
266                             "<SwAccessibleContext::ChildrenScrolled(..)> - always included child not considered!" );
267                     ::vos::ORef< ::accessibility::AccessibleShape > xAccImpl =
268                         //IAccessibility2 Implementation 2009-----
269                         //O is: GetMap()->GetContextImpl( rLower.GetSdrObject(),
270                         //                        this,
271                         //                        SCROLLED_OUT == eAction ||
272                         //                        SCROLLED_IN == eAction );
273                         GetMap()->GetContextImpl( rLower.GetDrawObject(),
274                                                   this,
275                                                   sal_True );
276                         //-----IAccessibility2 Implementation 2009
277                     if( xAccImpl.isValid() )
278                     {
279                         switch( eAction )
280                         {
281                         case SCROLLED:
282                         case SCROLLED_WITHIN:
283                             xAccImpl->ViewForwarderChanged(
284                                 ::accessibility::IAccessibleViewForwarderListener::VISIBLE_AREA,
285                                 GetMap() );
286                             break;
287                         case SCROLLED_IN:
288                             ScrolledInShape( rLower.GetDrawObject(),
289                                              xAccImpl.getBodyPtr() );
290                             break;
291                         case SCROLLED_OUT:
292                             {
293                                 xAccImpl->ViewForwarderChanged(
294                                     ::accessibility::IAccessibleViewForwarderListener::VISIBLE_AREA,
295                                     GetMap() );
296                                 //IAccessibility2 Implementation 2009-----
297                                 //Remove
298                                 //DisposeShape( rLower.GetDrawObject(),
299                                 //            xAccImpl.getBodyPtr() );
300                                 //-----IAccessibility2 Implementation 2009
301                             }
302                             break;
303                         case NONE:
304                             break;
305                         }
306                     }
307                 }
308                 else if ( rLower.GetWindow() )
309                 {
310                     // nothing to do - as such children are always included as children.
311                     ASSERT( rLower.AlwaysIncludeAsChild(),
312                             "<SwAccessibleContext::ChildrenScrolled(..)> - not always included child not considered!" );
313                 }
314             }
315         }
316         else if ( rLower.GetSwFrm() &&
317                   ( !bVisibleChildrenOnly ||
318                     aBox.IsOver( rOldVisArea ) ||
319                     aBox.IsOver( rNewVisArea ) ) )
320         {
321             // There are no unaccessible SdrObjects that need to be notified
322             ChildrenScrolled( rLower.GetSwFrm(), rOldVisArea );
323         }
324         ++aIter;
325     }
326 }
327 
328 void SwAccessibleContext::Scrolled( const SwRect& rOldVisArea )
329 {
330     SetVisArea( GetMap()->GetVisArea() );
331 
332     ChildrenScrolled( GetFrm(), rOldVisArea );
333 
334     sal_Bool bIsOldShowingState;
335     sal_Bool bIsNewShowingState = IsShowing( *(GetMap()) );
336     {
337         vos::OGuard aGuard( aMutex );
338         bIsOldShowingState = bIsShowingState;
339         bIsShowingState = bIsNewShowingState;
340     }
341 
342     if( bIsOldShowingState != bIsNewShowingState )
343         FireStateChangedEvent( AccessibleStateType::SHOWING,
344                                bIsNewShowingState  );
345 }
346 
347 void SwAccessibleContext::ScrolledWithin( const SwRect& rOldVisArea )
348 {
349     SetVisArea( GetMap()->GetVisArea() );
350 
351     ChildrenScrolled( GetFrm(), rOldVisArea );
352 
353     FireVisibleDataEvent();
354 }
355 
356 void SwAccessibleContext::ScrolledIn()
357 {
358     // This accessible should be freshly created, because it
359     // was not visisble before. Therefor, its vis area must already
360     // reflect the scrolling.
361     ASSERT( GetVisArea() == GetMap()->GetVisArea(),
362             "Vis area of child is wrong. Did it exist already?" );
363 
364     // Send child event at parent. That's all we have to do here.
365     const SwFrm* pParent = GetParent();
366     ::vos::ORef< SwAccessibleContext > xParentImpl(
367          GetMap()->GetContextImpl( pParent, sal_False ) );
368     uno::Reference < XAccessibleContext > xThis( this );
369     if( xParentImpl.isValid() )
370     {
371         SetParent( xParentImpl.getBodyPtr() );
372 
373         AccessibleEventObject aEvent;
374         aEvent.EventId = AccessibleEventId::CHILD;
375         aEvent.NewValue <<= xThis;
376 
377         xParentImpl->FireAccessibleEvent( aEvent );
378         DBG_MSG_PARAM( "AccessibleChild (added)", xChildImpl.getBodyPtr() );
379 
380         if( HasCursor() )
381         {
382             Window *pWin = GetWindow();
383             if( pWin && pWin->HasFocus() )
384             {
385                 FireStateChangedEvent( AccessibleStateType::FOCUSED, sal_True );
386             }
387         }
388 
389     }
390 }
391 
392 void SwAccessibleContext::ScrolledOut( const SwRect& rOldVisArea )
393 {
394     SetVisArea( GetMap()->GetVisArea() );
395 
396     // First of all, update the children. That's required to dispose
397     // all children that are existing only if they are visible. They
398     // are not disposed by the recusive Dispose call that follows later on,
399     // because this call will only dispose children that are in the
400     // new vis area. The children we want to dispode however are in the
401     // old vis area all.
402     ChildrenScrolled( GetFrm(), rOldVisArea );
403 
404     // Broadcast a state changed event for the showing state.
405     // It might be that the child is freshly created just to send
406     // the child event. In this case no listener will exist.
407     FireStateChangedEvent( AccessibleStateType::SHOWING, sal_False );
408 
409     //IAccessibility2 Implementation 2009-----
410     //Remove Dispose When scrolledout
411     // We now dispose the frame
412     //  Dispose( sal_True );
413     //-----IAccessibility2 Implementation 2009
414 }
415 
416 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
417 void SwAccessibleContext::InvalidateChildrenStates( const SwFrm* _pFrm,
418                                                     tAccessibleStates _nStates )
419 {
420     const SwAccessibleChildSList aVisList( GetVisArea(), *_pFrm, *(GetMap()) );
421 
422     SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
423     while( aIter != aVisList.end() )
424     {
425         const SwAccessibleChild& rLower = *aIter;
426         const SwFrm* pLower = rLower.GetSwFrm();
427         if( pLower )
428         {
429             ::vos::ORef< SwAccessibleContext > xAccImpl;
430             if( rLower.IsAccessible( GetShell()->IsPreView() ) )
431                 xAccImpl = GetMap()->GetContextImpl( pLower, sal_False );
432             if( xAccImpl.isValid() )
433                 xAccImpl->InvalidateStates( _nStates );
434             else
435                 InvalidateChildrenStates( pLower, _nStates );
436         }
437         else if ( rLower.GetDrawObject() )
438         {
439             // TODO: SdrObjects
440         }
441         else if ( rLower.GetWindow() )
442         {
443             // nothing to do ?
444         }
445 
446         ++aIter;
447     }
448 }
449 // <--
450 
451 void SwAccessibleContext::DisposeChildren( const SwFrm *pFrm,
452                                        sal_Bool bRecursive )
453 {
454     const SwAccessibleChildSList aVisList( GetVisArea(), *pFrm, *(GetMap()) );
455     SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
456     while( aIter != aVisList.end() )
457     {
458         const SwAccessibleChild& rLower = *aIter;
459         const SwFrm* pLower = rLower.GetSwFrm();
460         if( pLower )
461         {
462             ::vos::ORef< SwAccessibleContext > xAccImpl;
463             if( rLower.IsAccessible( GetShell()->IsPreView() ) )
464                 xAccImpl = GetMap()->GetContextImpl( pLower, sal_False );
465             if( xAccImpl.isValid() )
466                 xAccImpl->Dispose( bRecursive );
467             else if( bRecursive )
468                 DisposeChildren( pLower, bRecursive );
469         }
470         else if ( rLower.GetDrawObject() )
471         {
472             ::vos::ORef< ::accessibility::AccessibleShape > xAccImpl(
473                     GetMap()->GetContextImpl( rLower.GetDrawObject(),
474                                           this, sal_False )  );
475             if( xAccImpl.isValid() )
476                 DisposeShape( rLower.GetDrawObject(), xAccImpl.getBodyPtr() );
477         }
478         else if ( rLower.GetWindow() )
479         {
480             DisposeChild( rLower, sal_False );
481         }
482         ++aIter;
483     }
484 }
485 
486 void SwAccessibleContext::_InvalidateContent( sal_Bool )
487 {
488 }
489 
490 void SwAccessibleContext::_InvalidateCursorPos()
491 {
492 }
493 
494 void SwAccessibleContext::_InvalidateFocus()
495 {
496 }
497 
498 void SwAccessibleContext::FireAccessibleEvent( AccessibleEventObject& rEvent )
499 {
500     ASSERT( GetFrm(), "fire event for diposed frame?" );
501     if( !GetFrm() )
502         return;
503 
504     if( !rEvent.Source.is() )
505     {
506         uno::Reference < XAccessibleContext > xThis( this );
507         rEvent.Source = xThis;
508     }
509 
510     if (nClientId)
511         comphelper::AccessibleEventNotifier::addEvent( nClientId, rEvent );
512 }
513 
514 void SwAccessibleContext::FireVisibleDataEvent()
515 {
516     AccessibleEventObject aEvent;
517     aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
518 
519     FireAccessibleEvent( aEvent );
520     DBG_MSG( "AccessibleVisibleData" )
521 }
522 
523 void SwAccessibleContext::FireStateChangedEvent( sal_Int16 nState,
524                                                  sal_Bool bNewState )
525 {
526     AccessibleEventObject aEvent;
527 
528     aEvent.EventId = AccessibleEventId::STATE_CHANGED;
529     if( bNewState )
530         aEvent.NewValue <<= nState;
531     else
532         aEvent.OldValue <<= nState;
533 
534     FireAccessibleEvent( aEvent );
535     DBG_MSG( "StateChanged" )
536 }
537 
538 void SwAccessibleContext::GetStates(
539         ::utl::AccessibleStateSetHelper& rStateSet )
540 {
541     vos::OGuard aGuard(Application::GetSolarMutex());
542 
543     // SHOWING
544     if( bIsShowingState )
545         rStateSet.AddState( AccessibleStateType::SHOWING );
546 
547     // EDITABLE
548     if( bIsEditableState )
549     //IAccessibility2 Implementation 2009-----
550     //Solution:Set editable state to graphic and other object when the document is editable
551     {
552         rStateSet.AddState( AccessibleStateType::EDITABLE );
553         rStateSet.AddState( AccessibleStateType::RESIZABLE );
554         rStateSet.AddState( AccessibleStateType::MOVEABLE );
555     }
556     //-----IAccessibility2 Implementation 2009
557     // ENABLED
558     rStateSet.AddState( AccessibleStateType::ENABLED );
559 
560     // OPAQUE
561     if( bIsOpaqueState )
562         rStateSet.AddState( AccessibleStateType::OPAQUE );
563 
564     // VISIBLE
565     rStateSet.AddState( AccessibleStateType::VISIBLE );
566 
567     if( bIsDefuncState )
568         rStateSet.AddState( AccessibleStateType::DEFUNC );
569 }
570 
571 sal_Bool SwAccessibleContext::IsEditableState()
572 {
573     sal_Bool bRet;
574     {
575         vos::OGuard aGuard( aMutex );
576         bRet = bIsEditableState;
577     }
578 
579     return bRet;
580 }
581 
582 SwAccessibleContext::SwAccessibleContext( SwAccessibleMap *pM,
583                                           sal_Int16 nR,
584                                           const SwFrm *pF )
585     : SwAccessibleFrame( pM->GetVisArea().SVRect(), pF,
586                          pM->GetShell()->IsPreView() )
587     , pMap( pM )
588     , nClientId(0)
589     , nRole( nR )
590     , bDisposing( sal_False )
591     , bRegisteredAtAccessibleMap( true )
592     //IAccessibility2 Implementation 2009-----
593     //Solution:Initialize the begin document load and IfAsynLoad to true
594     , bBeginDocumentLoad( sal_True )
595     , isIfAsynLoad( sal_True )
596     , bIsSeletedInDoc( sal_False)
597     //-----IAccessibility2 Implementation 2009
598 {
599     InitStates();
600     DBG_MSG_CD( "constructed" )
601 }
602 
603 SwAccessibleContext::~SwAccessibleContext()
604 {
605     vos::OGuard aGuard(Application::GetSolarMutex());
606 
607     DBG_MSG_CD( "destructed" )
608     RemoveFrmFromAccessibleMap();
609 }
610 
611 uno::Reference< XAccessibleContext > SAL_CALL
612     SwAccessibleContext::getAccessibleContext( void )
613         throw (uno::RuntimeException)
614 {
615     uno::Reference < XAccessibleContext > xRet( this );
616     return xRet;
617 }
618 
619 sal_Int32 SAL_CALL SwAccessibleContext::getAccessibleChildCount( void )
620         throw (uno::RuntimeException)
621 {
622     vos::OGuard aGuard(Application::GetSolarMutex());
623 
624     CHECK_FOR_DEFUNC( XAccessibleContext )
625     //IAccessibility2 Implementation 2009-----
626     //Solution:Notify the frame is a document
627     if( nRole == AccessibleRole::DOCUMENT )
628         bIsAccDocUse = sal_True;
629     //-----IAccessibility2 Implementation 2009
630 
631     return bDisposing ? 0 : GetChildCount( *(GetMap()) );
632 }
633 
634 uno::Reference< XAccessible> SAL_CALL
635     SwAccessibleContext::getAccessibleChild( sal_Int32 nIndex )
636         throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
637 {
638     vos::OGuard aGuard(Application::GetSolarMutex());
639 
640     CHECK_FOR_DEFUNC( XAccessibleContext )
641 
642     //IAccessibility2 Implementation 2009-----
643     //Solution:Notify the frame is a document
644     if( nRole == AccessibleRole::DOCUMENT )
645         bIsAccDocUse = sal_True;
646     //-----IAccessibility2 Implementation 2009
647 
648     const SwAccessibleChild aChild( GetChild( *(GetMap()), nIndex ) );
649     if( !aChild.IsValid() )
650     {
651         uno::Reference < XAccessibleContext > xThis( this );
652         lang::IndexOutOfBoundsException aExcept(
653                 OUString( RTL_CONSTASCII_USTRINGPARAM("index out of bounds") ),
654                 xThis );
655         throw aExcept;
656     }
657 
658     uno::Reference< XAccessible > xChild;
659     if( aChild.GetSwFrm() )
660     {
661         ::vos::ORef < SwAccessibleContext > xChildImpl(
662                 GetMap()->GetContextImpl( aChild.GetSwFrm(), !bDisposing )  );
663         //IAccessibility2 Implementation 2009-----
664         //Solution:Send out accessible event when begin load.
665         if( bBeginDocumentLoad && nRole == AccessibleRole::DOCUMENT )
666         {
667 
668             FireStateChangedEvent( AccessibleStateType::FOCUSABLE,sal_True );
669             FireStateChangedEvent( AccessibleStateType::BUSY,sal_True );
670             if( !isIfAsynLoad )
671             {
672                 FireStateChangedEvent( AccessibleStateType::FOCUSED,sal_True );
673                 // IA2 CWS. MT: OFFSCREEN == !SHOWING, should stay consistent
674                 // FireStateChangedEvent( AccessibleStateType::OFFSCREEN,sal_True );
675                 FireStateChangedEvent( AccessibleStateType::SHOWING,sal_True );
676                 FireStateChangedEvent( AccessibleStateType::BUSY,sal_False );
677                 // MT: OFFSCREEN again?
678                 // FireStateChangedEvent( AccessibleStateType::OFFSCREEN,sal_False );
679             }
680             bBeginDocumentLoad = sal_False;
681         }
682         //-----IAccessibility2 Implementation 2009
683         if( xChildImpl.isValid() )
684         {
685             xChildImpl->SetParent( this );
686             xChild = xChildImpl.getBodyPtr();
687         }
688     }
689     else if ( aChild.GetDrawObject() )
690     {
691         ::vos::ORef < ::accessibility::AccessibleShape > xChildImpl(
692                 GetMap()->GetContextImpl( aChild.GetDrawObject(),
693                                           this, !bDisposing )  );
694         if( xChildImpl.isValid() )
695             xChild = xChildImpl.getBodyPtr();
696     }
697     else if ( aChild.GetWindow() )
698     {
699         xChild = aChild.GetWindow()->GetAccessible();
700     }
701 
702     return xChild;
703 }
704 
705 uno::Reference< XAccessible> SAL_CALL SwAccessibleContext::getAccessibleParent (void)
706         throw (uno::RuntimeException)
707 {
708     vos::OGuard aGuard(Application::GetSolarMutex());
709 
710     CHECK_FOR_DEFUNC( XAccessibleContext )
711 
712     const SwFrm *pUpper = GetParent();
713     ASSERT( pUpper != 0 || bDisposing, "no upper found" );
714 
715     uno::Reference< XAccessible > xAcc;
716     if( pUpper )
717         xAcc = GetMap()->GetContext( pUpper, !bDisposing );
718 
719     ASSERT( xAcc.is() || bDisposing, "no parent found" );
720 
721     // Remember the parent as weak ref.
722     {
723         vos::OGuard aWeakParentGuard( aMutex );
724         xWeakParent = xAcc;
725     }
726 
727     return xAcc;
728 }
729 
730 sal_Int32 SAL_CALL SwAccessibleContext::getAccessibleIndexInParent (void)
731         throw (uno::RuntimeException)
732 {
733     vos::OGuard aGuard(Application::GetSolarMutex());
734 
735     CHECK_FOR_DEFUNC( XAccessibleContext )
736 
737     const SwFrm *pUpper = GetParent();
738     ASSERT( pUpper != 0 || bDisposing, "no upper found" );
739 
740     sal_Int32 nIndex = -1;
741     if( pUpper )
742     {
743         ::vos::ORef < SwAccessibleContext > xAccImpl(
744             GetMap()->GetContextImpl( pUpper, !bDisposing )  );
745         ASSERT( xAccImpl.isValid() || bDisposing, "no parent found" );
746         if( xAccImpl.isValid() )
747             nIndex = xAccImpl->GetChildIndex( *(GetMap()), SwAccessibleChild(GetFrm()) );
748     }
749 
750     return nIndex;
751 }
752 
753 sal_Int16 SAL_CALL SwAccessibleContext::getAccessibleRole (void)
754         throw (uno::RuntimeException)
755 {
756     return nRole;
757 }
758 
759 OUString SAL_CALL SwAccessibleContext::getAccessibleDescription (void)
760         throw (uno::RuntimeException)
761 {
762     ASSERT( !this, "description needs to be overloaded" );
763     THROW_RUNTIME_EXCEPTION( XAccessibleContext, "internal error (method must be overloaded)" );
764 }
765 
766 OUString SAL_CALL SwAccessibleContext::getAccessibleName (void)
767         throw (uno::RuntimeException)
768 {
769     return sName;
770 }
771 
772 uno::Reference< XAccessibleRelationSet> SAL_CALL
773     SwAccessibleContext::getAccessibleRelationSet (void)
774         throw (uno::RuntimeException)
775 {
776     // by default there are no relations
777     uno::Reference< XAccessibleRelationSet> xRet( new utl::AccessibleRelationSetHelper() );
778     return xRet;
779 }
780 
781 uno::Reference<XAccessibleStateSet> SAL_CALL
782     SwAccessibleContext::getAccessibleStateSet (void)
783         throw (uno::RuntimeException)
784 {
785     vos::OGuard aGuard(Application::GetSolarMutex());
786 
787     CHECK_FOR_DEFUNC( XAccessibleContext )
788 
789     ::utl::AccessibleStateSetHelper *pStateSet =
790         new ::utl::AccessibleStateSetHelper;
791 
792     //IAccessibility2 Implementation 2009-----
793     if( bIsSeletedInDoc )
794         pStateSet->AddState( AccessibleStateType::SELECTED );
795     //-----IAccessibility2 Implementation 2009
796 
797     uno::Reference<XAccessibleStateSet> xStateSet( pStateSet );
798     GetStates( *pStateSet );
799 
800     return xStateSet;
801 }
802 
803 lang::Locale SAL_CALL SwAccessibleContext::getLocale (void)
804         throw (IllegalAccessibleComponentStateException, uno::RuntimeException)
805 {
806     vos::OGuard aGuard(Application::GetSolarMutex());
807 
808     lang::Locale aLoc( Application::GetSettings().GetLocale() );
809     return aLoc;
810 }
811 
812 void SAL_CALL SwAccessibleContext::addEventListener(
813             const uno::Reference< XAccessibleEventListener >& xListener )
814         throw (uno::RuntimeException)
815 {
816     DBG_MSG( "accessible event listener added" )
817 
818     if (xListener.is())
819     {
820         vos::OGuard aGuard(Application::GetSolarMutex());
821         if (!nClientId)
822             nClientId = comphelper::AccessibleEventNotifier::registerClient( );
823         comphelper::AccessibleEventNotifier::addEventListener( nClientId, xListener );
824     }
825 }
826 
827 void SAL_CALL SwAccessibleContext::removeEventListener(
828             const uno::Reference< XAccessibleEventListener >& xListener )
829         throw (uno::RuntimeException)
830 {
831     DBG_MSG( "accessible event listener removed" )
832 
833     if (xListener.is())
834     {
835         vos::OGuard aGuard(Application::GetSolarMutex());
836         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( nClientId, xListener );
837         if ( !nListenerCount )
838         {
839             // no listeners anymore
840             // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
841             // and at least to us not firing any events anymore, in case somebody calls
842             // NotifyAccessibleEvent, again
843             comphelper::AccessibleEventNotifier::revokeClient( nClientId );
844             nClientId = 0;
845         }
846     }
847 }
848 
849 static sal_Bool lcl_PointInRectangle(const awt::Point & aPoint,
850                                      const awt::Rectangle & aRect)
851 {
852     long nDiffX = aPoint.X - aRect.X;
853     long nDiffY = aPoint.Y - aRect.Y;
854 
855     return
856         nDiffX >= 0 && nDiffX < aRect.Width && nDiffY >= 0 &&
857         nDiffY < aRect.Height;
858 
859 }
860 
861 sal_Bool SAL_CALL SwAccessibleContext::containsPoint(
862             const awt::Point& aPoint )
863         throw (uno::RuntimeException)
864 {
865     awt::Rectangle aPixBounds = getBoundsImpl(sal_True);
866     aPixBounds.X = 0;
867     aPixBounds.Y = 0;
868 
869     return lcl_PointInRectangle(aPoint, aPixBounds);
870 }
871 
872 uno::Reference< XAccessible > SAL_CALL SwAccessibleContext::getAccessibleAtPoint(
873                 const awt::Point& aPoint )
874         throw (uno::RuntimeException)
875 {
876     vos::OGuard aGuard(Application::GetSolarMutex());
877 
878     CHECK_FOR_DEFUNC( XAccessibleComponent )
879 
880     uno::Reference< XAccessible > xAcc;
881 
882     Window *pWin = GetWindow();
883     CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
884 
885     Point aPixPoint( aPoint.X, aPoint.Y ); // px rel to parent
886     if( !GetFrm()->IsRootFrm() )
887     {
888         SwRect aLogBounds( GetBounds( *(GetMap()), GetFrm() ) ); // twip rel to doc root
889         Point aPixPos( GetMap()->CoreToPixel( aLogBounds.SVRect() ).TopLeft() );
890         aPixPoint.X() += aPixPos.X();
891         aPixPoint.Y() += aPixPos.Y();
892     }
893 
894     const SwAccessibleChild aChild( GetChildAtPixel( aPixPoint, *(GetMap()) ) );
895     if( aChild.GetSwFrm() )
896     {
897         xAcc = GetMap()->GetContext( aChild.GetSwFrm() );
898     }
899     else if( aChild.GetDrawObject() )
900     {
901         xAcc = GetMap()->GetContext( aChild.GetDrawObject(), this );
902     }
903     else if ( aChild.GetWindow() )
904     {
905         xAcc = aChild.GetWindow()->GetAccessible();
906     }
907 
908     return xAcc;
909 }
910 
911 
912 /**
913    Get bounding box.
914 
915    There are two modes.
916 
917    - realative
918 
919      Return bounding box relative to parent if parent is no root
920      frame. Otherwise return the absolute bounding box.
921 
922    - absolute
923 
924      Return the absolute bounding box.
925 
926    @param bRelative
927    true: Use relative mode.
928    false: Use absolute mode.
929 */
930 awt::Rectangle SAL_CALL SwAccessibleContext::getBoundsImpl(sal_Bool bRelative)
931         throw (uno::RuntimeException)
932 {
933     vos::OGuard aGuard(Application::GetSolarMutex());
934 
935     CHECK_FOR_DEFUNC( XAccessibleComponent )
936 
937     const SwFrm *pParent = GetParent();
938     ASSERT( pParent, "no Parent found" );
939     Window *pWin = GetWindow();
940 
941     CHECK_FOR_WINDOW( XAccessibleComponent, pWin && pParent )
942 
943     SwRect aLogBounds( GetBounds( *(GetMap()), GetFrm() ) ); // twip rel to doc root
944     Rectangle aPixBounds( 0, 0, 0, 0 );
945     if( GetFrm()->IsPageFrm() &&
946         static_cast < const SwPageFrm * >( GetFrm() )->IsEmptyPage() )
947     {
948         ASSERT( GetShell()->IsPreView(), "empty page accessible?" );
949         if( GetShell()->IsPreView() )
950         {
951             // OD 15.01.2003 #103492# - adjust method call <GetMap()->GetPreViewPageSize()>
952             sal_uInt16 nPageNum =
953                 static_cast < const SwPageFrm * >( GetFrm() )->GetPhyPageNum();
954             aLogBounds.SSize( GetMap()->GetPreViewPageSize( nPageNum ) );
955         }
956     }
957     if( !aLogBounds.IsEmpty() )
958     {
959         aPixBounds = GetMap()->CoreToPixel( aLogBounds.SVRect() );
960         if( !pParent->IsRootFrm() && bRelative)
961         {
962             SwRect aParentLogBounds( GetBounds( *(GetMap()), pParent ) ); // twip rel to doc root
963             Point aParentPixPos( GetMap()->CoreToPixel( aParentLogBounds.SVRect() ).TopLeft() );
964             aPixBounds.Move( -aParentPixPos.X(), -aParentPixPos.Y() );
965         }
966     }
967 
968     awt::Rectangle aBox( aPixBounds.Left(), aPixBounds.Top(),
969                          aPixBounds.GetWidth(), aPixBounds.GetHeight() );
970 
971     return aBox;
972 }
973 
974 
975 awt::Rectangle SAL_CALL SwAccessibleContext::getBounds()
976         throw (uno::RuntimeException)
977 {
978     return getBoundsImpl(sal_True);
979 }
980 
981 awt::Point SAL_CALL SwAccessibleContext::getLocation()
982     throw (uno::RuntimeException)
983 {
984     awt::Rectangle aRect = getBoundsImpl(sal_True);
985     awt::Point aPoint(aRect.X, aRect.Y);
986 
987     return aPoint;
988 }
989 
990 
991 
992 awt::Point SAL_CALL SwAccessibleContext::getLocationOnScreen()
993         throw (uno::RuntimeException)
994 {
995     awt::Rectangle aRect = getBoundsImpl(sal_False);
996 
997     Point aPixPos(aRect.X, aRect.Y);
998 
999     /* getBoundsImpl already checked that GetWindow returns valid pointer. */
1000     aPixPos = GetWindow()->OutputToAbsoluteScreenPixel(aPixPos);
1001     awt::Point aPoint(aPixPos.X(), aPixPos.Y());
1002 
1003     return aPoint;
1004 }
1005 
1006 
1007 awt::Size SAL_CALL SwAccessibleContext::getSize()
1008         throw (uno::RuntimeException)
1009 {
1010     awt::Rectangle aRect = getBoundsImpl(sal_False);
1011     awt::Size aSize( aRect.Width, aRect.Height );
1012 
1013     return aSize;
1014 }
1015 
1016 void SAL_CALL SwAccessibleContext::grabFocus()
1017         throw (uno::RuntimeException)
1018 {
1019     vos::OGuard aGuard(Application::GetSolarMutex());
1020 
1021     CHECK_FOR_DEFUNC( XAccessibleContext );
1022 
1023     if( GetFrm()->IsFlyFrm() )
1024     {
1025         const SdrObject *pObj =
1026             static_cast < const SwFlyFrm * >( GetFrm() )->GetVirtDrawObj();
1027         if( pObj )
1028             Select( const_cast < SdrObject * >( pObj ), sal_False );
1029     }
1030     else
1031     {
1032         const SwCntntFrm *pCFrm = 0;
1033         if( GetFrm()->IsCntntFrm() )
1034             pCFrm = static_cast< const SwCntntFrm * >( GetFrm() );
1035         else if( GetFrm()->IsLayoutFrm() )
1036             pCFrm = static_cast< const SwLayoutFrm * >( GetFrm() )->ContainsCntnt();
1037 
1038         if( pCFrm && pCFrm->IsTxtFrm() )
1039         {
1040             const SwTxtFrm *pTxtFrm = static_cast< const SwTxtFrm * >( pCFrm );
1041             const SwTxtNode *pTxtNd = pTxtFrm->GetTxtNode();
1042             if( pTxtNd )
1043             {
1044                 // create pam for selection
1045                 SwIndex aIndex( const_cast< SwTxtNode * >( pTxtNd ),
1046                                 pTxtFrm->GetOfst() );
1047                 SwPosition aStartPos( *pTxtNd, aIndex );
1048                 SwPaM aPaM( aStartPos );
1049 
1050                 // set PaM at cursor shell
1051                 Select( aPaM );
1052             }
1053         }
1054     }
1055 }
1056 
1057 
1058 uno::Any SAL_CALL SwAccessibleContext::getAccessibleKeyBinding()
1059         throw (uno::RuntimeException)
1060 {
1061     // There are no key bindings
1062     return uno::Any();
1063 }
1064 
1065 sal_Int32 SAL_CALL SwAccessibleContext::getForeground()
1066         throw (uno::RuntimeException)
1067 {
1068     //IAccessibility2 Implementation 2009-----
1069     return COL_BLACK;
1070     //-----IAccessibility2 Implementation 2009
1071 }
1072 
1073 sal_Int32 SAL_CALL SwAccessibleContext::getBackground()
1074         throw (uno::RuntimeException)
1075 {
1076     return COL_WHITE;
1077 }
1078 
1079 
1080 OUString SAL_CALL SwAccessibleContext::getImplementationName()
1081         throw( uno::RuntimeException )
1082 {
1083     ASSERT( !this, "implementation name needs to be overloaded" );
1084 
1085     THROW_RUNTIME_EXCEPTION( lang::XServiceInfo, "implementation name needs to be overloaded" )
1086 }
1087 
1088 sal_Bool SAL_CALL
1089     SwAccessibleContext::supportsService (const ::rtl::OUString& )
1090         throw (uno::RuntimeException)
1091 {
1092     ASSERT( !this, "supports service needs to be overloaded" );
1093     THROW_RUNTIME_EXCEPTION( lang::XServiceInfo, "supports service needs to be overloaded" )
1094 }
1095 
1096 uno::Sequence< OUString > SAL_CALL SwAccessibleContext::getSupportedServiceNames()
1097         throw( uno::RuntimeException )
1098 {
1099     ASSERT( !this, "supported services names needs to be overloaded" );
1100     THROW_RUNTIME_EXCEPTION( lang::XServiceInfo, "supported services needs to be overloaded" )
1101 }
1102 
1103 void SwAccessibleContext::DisposeShape( const SdrObject *pObj,
1104                                 ::accessibility::AccessibleShape *pAccImpl )
1105 {
1106     ::vos::ORef< ::accessibility::AccessibleShape > xAccImpl( pAccImpl );
1107     if( !xAccImpl.isValid() )
1108         xAccImpl = GetMap()->GetContextImpl( pObj, this, sal_True );
1109 
1110     AccessibleEventObject aEvent;
1111     aEvent.EventId = AccessibleEventId::CHILD;
1112     uno::Reference< XAccessible > xAcc( xAccImpl.getBodyPtr() );
1113     aEvent.OldValue <<= xAcc;
1114     FireAccessibleEvent( aEvent );
1115 
1116     GetMap()->RemoveContext( pObj );
1117     xAccImpl->dispose();
1118 }
1119 
1120 void SwAccessibleContext::ScrolledInShape( const SdrObject* ,
1121                                 ::accessibility::AccessibleShape *pAccImpl )
1122 {
1123     //IAccessibility2 Implementation 2009-----
1124     if(NULL == pAccImpl)
1125     {
1126         return ;
1127     }
1128     //-----IAccessibility2 Implementation 2009
1129     AccessibleEventObject aEvent;
1130     aEvent.EventId = AccessibleEventId::CHILD;
1131     uno::Reference< XAccessible > xAcc( pAccImpl );
1132     aEvent.NewValue <<= xAcc;
1133     FireAccessibleEvent( aEvent );
1134 
1135     if( pAccImpl->GetState( AccessibleStateType::FOCUSED ) )
1136     {
1137         Window *pWin = GetWindow();
1138         if( pWin && pWin->HasFocus() )
1139         {
1140             AccessibleEventObject aStateChangedEvent;
1141             aStateChangedEvent.EventId = AccessibleEventId::STATE_CHANGED;
1142             aStateChangedEvent.NewValue <<= AccessibleStateType::FOCUSED;
1143             aStateChangedEvent.Source = xAcc;
1144 
1145             FireAccessibleEvent( aStateChangedEvent );
1146         }
1147     }
1148 }
1149 
1150 void SwAccessibleContext::Dispose( sal_Bool bRecursive )
1151 {
1152     vos::OGuard aGuard(Application::GetSolarMutex());
1153 
1154     ASSERT( GetFrm() && GetMap(), "already disposed" );
1155     ASSERT( GetMap()->GetVisArea() == GetVisArea(),
1156                 "invalid vis area for dispose" );
1157 
1158     bDisposing = sal_True;
1159 
1160     // dispose children
1161     if( bRecursive )
1162         DisposeChildren( GetFrm(), bRecursive );
1163 
1164     // get parent
1165     uno::Reference< XAccessible > xParent( GetWeakParent() );
1166     uno::Reference < XAccessibleContext > xThis( this );
1167 
1168     // send child event at parent
1169     if( xParent.is() )
1170     {
1171         SwAccessibleContext *pAcc = (SwAccessibleContext *)xParent.get();
1172 
1173         AccessibleEventObject aEvent;
1174         aEvent.EventId = AccessibleEventId::CHILD;
1175         aEvent.OldValue <<= xThis;
1176         pAcc->FireAccessibleEvent( aEvent );
1177         DBG_MSG_THIS_PARAM( "AccessibleChild (removed)", pAcc, this )
1178     }
1179 
1180     // set defunc state (its not required to broadcast a state changed
1181     // event if the object is diposed afterwards)
1182     {
1183         vos::OGuard aDefuncStateGuard( aMutex );
1184         bIsDefuncState = sal_True;
1185     }
1186 
1187     // broadcast dispose event
1188     if ( nClientId )
1189     {
1190         comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, *this );
1191         nClientId =  0;
1192         DBG_MSG_CD( "dispose" )
1193     }
1194 
1195     RemoveFrmFromAccessibleMap();
1196     ClearFrm();
1197     pMap = 0;
1198 
1199     bDisposing = sal_False;
1200 }
1201 
1202 void SwAccessibleContext::DisposeChild( const SwAccessibleChild& rChildFrmOrObj,
1203                                         sal_Bool bRecursive )
1204 {
1205     vos::OGuard aGuard(Application::GetSolarMutex());
1206 
1207     if ( IsShowing( *(GetMap()), rChildFrmOrObj ) ||
1208          rChildFrmOrObj.AlwaysIncludeAsChild() ||
1209          !SwAccessibleChild( GetFrm() ).IsVisibleChildrenOnly() )
1210     {
1211         // If the object could have existed before, than there is nothing to do,
1212         // because no wrapper exists now and therefor no one is interested to
1213         // get notified of the movement.
1214         if( rChildFrmOrObj.GetSwFrm() )
1215         {
1216             ::vos::ORef< SwAccessibleContext > xAccImpl =
1217                     GetMap()->GetContextImpl( rChildFrmOrObj.GetSwFrm(),
1218                                               sal_True );
1219             xAccImpl->Dispose( bRecursive );
1220         }
1221         else if ( rChildFrmOrObj.GetDrawObject() )
1222         {
1223             ::vos::ORef< ::accessibility::AccessibleShape > xAccImpl =
1224                     GetMap()->GetContextImpl( rChildFrmOrObj.GetDrawObject(),
1225                                               this, sal_True );
1226             DisposeShape( rChildFrmOrObj.GetDrawObject(),
1227                           xAccImpl.getBodyPtr() );
1228         }
1229         else if ( rChildFrmOrObj.GetWindow() )
1230         {
1231             AccessibleEventObject aEvent;
1232             aEvent.EventId = AccessibleEventId::CHILD;
1233             uno::Reference< XAccessible > xAcc =
1234                                     rChildFrmOrObj.GetWindow()->GetAccessible();
1235             aEvent.OldValue <<= xAcc;
1236             FireAccessibleEvent( aEvent );
1237         }
1238     }
1239     else if( bRecursive && rChildFrmOrObj.GetSwFrm() )
1240         DisposeChildren( rChildFrmOrObj.GetSwFrm(), bRecursive );
1241 }
1242 
1243 void SwAccessibleContext::InvalidatePosOrSize( const SwRect& )
1244 {
1245     vos::OGuard aGuard(Application::GetSolarMutex());
1246 
1247     ASSERT( GetFrm() && !GetFrm()->Frm().IsEmpty(), "context should have a size" );
1248 
1249     sal_Bool bIsOldShowingState;
1250     sal_Bool bIsNewShowingState = IsShowing( *(GetMap()) );
1251     {
1252         vos::OGuard aShowingStateGuard( aMutex );
1253         bIsOldShowingState = bIsShowingState;
1254         bIsShowingState = bIsNewShowingState;
1255     }
1256 
1257     if( bIsOldShowingState != bIsNewShowingState )
1258     {
1259         FireStateChangedEvent( AccessibleStateType::SHOWING,
1260                                bIsNewShowingState  );
1261     }
1262     else if( bIsNewShowingState )
1263     {
1264         // The frame stays visible -> broadcast event
1265         FireVisibleDataEvent();
1266     }
1267 
1268     if( !bIsNewShowingState &&
1269         SwAccessibleChild( GetParent() ).IsVisibleChildrenOnly() )
1270     {
1271         // The frame is now invisible -> dispose it
1272         //IAccessibility2 Implementation 2009-----
1273         //Remove
1274         //Dispose( sal_True );
1275         //-----IAccessibility2 Implementation 2009
1276     }
1277     else
1278     {
1279         _InvalidateContent( sal_True );
1280     }
1281 }
1282 
1283 void SwAccessibleContext::InvalidateChildPosOrSize(
1284                     const SwAccessibleChild& rChildFrmOrObj,
1285                     const SwRect& rOldFrm )
1286 {
1287     vos::OGuard aGuard(Application::GetSolarMutex());
1288 
1289     ASSERT( !rChildFrmOrObj.GetSwFrm() ||
1290             !rChildFrmOrObj.GetSwFrm()->Frm().IsEmpty(),
1291             "child context should have a size" );
1292 
1293     if ( rChildFrmOrObj.AlwaysIncludeAsChild() )
1294     {
1295         // nothing to do;
1296         return;
1297     }
1298 
1299     const bool bVisibleChildrenOnly = SwAccessibleChild( GetFrm() ).IsVisibleChildrenOnly();
1300     const bool bNew = rOldFrm.IsEmpty() ||
1301                      ( rOldFrm.Left() == 0 && rOldFrm.Top() == 0 );
1302     if( IsShowing( *(GetMap()), rChildFrmOrObj ) )
1303     {
1304         // If the object could have existed before, than there is nothing to do,
1305         // because no wrapper exists now and therefor no one is interested to
1306         // get notified of the movement.
1307         if( bNew || (bVisibleChildrenOnly && !IsShowing( rOldFrm )) )
1308         {
1309             if( rChildFrmOrObj.GetSwFrm() )
1310             {
1311                 // The frame becomes visible. A child event must be send.
1312                 ::vos::ORef< SwAccessibleContext > xAccImpl =
1313                     GetMap()->GetContextImpl( rChildFrmOrObj.GetSwFrm(),
1314                                               sal_True );
1315                 xAccImpl->ScrolledIn();
1316             }
1317             else if ( rChildFrmOrObj.GetDrawObject() )
1318             {
1319                 ::vos::ORef< ::accessibility::AccessibleShape > xAccImpl =
1320                         GetMap()->GetContextImpl( rChildFrmOrObj.GetDrawObject(),
1321                                                   this, sal_True );
1322                 // --> OD 2004-11-29 #i37790#
1323                 if ( xAccImpl.isValid() )
1324                 {
1325                     ScrolledInShape( rChildFrmOrObj.GetDrawObject(),
1326                                      xAccImpl.getBodyPtr() );
1327                 }
1328                 else
1329                 {
1330                     ASSERT( false ,
1331                             "<SwAccessibleContext::InvalidateChildPosOrSize(..)> - no accessible shape found." );
1332                 }
1333                 // <--
1334             }
1335             else if ( rChildFrmOrObj.GetWindow() )
1336             {
1337                 AccessibleEventObject aEvent;
1338                 aEvent.EventId = AccessibleEventId::CHILD;
1339                 aEvent.NewValue <<= (rChildFrmOrObj.GetWindow()->GetAccessible());
1340                 FireAccessibleEvent( aEvent );
1341             }
1342         }
1343     }
1344     else
1345     {
1346         // If the frame was visible before, than a child event for the parent
1347         // needs to be send. However, there is no wrapper existing, and so
1348         // no notifications for grandchildren are required. If the are
1349         // grandgrandchildren, they would be notified by the layout.
1350         if( bVisibleChildrenOnly &&
1351             !bNew && IsShowing( rOldFrm ) )
1352         {
1353             if( rChildFrmOrObj.GetSwFrm() )
1354             {
1355                 ::vos::ORef< SwAccessibleContext > xAccImpl =
1356                     GetMap()->GetContextImpl( rChildFrmOrObj.GetSwFrm(),
1357                                               sal_True );
1358                 xAccImpl->SetParent( this );
1359                 xAccImpl->Dispose( sal_True );
1360             }
1361             else if ( rChildFrmOrObj.GetDrawObject() )
1362             {
1363                 ::vos::ORef< ::accessibility::AccessibleShape > xAccImpl =
1364                         GetMap()->GetContextImpl( rChildFrmOrObj.GetDrawObject(),
1365                                                   this, sal_True );
1366                 DisposeShape( rChildFrmOrObj.GetDrawObject(),
1367                           xAccImpl.getBodyPtr() );
1368             }
1369             else if ( rChildFrmOrObj.GetWindow() )
1370             {
1371                 ASSERT( false,
1372                         "<SwAccessibleContext::InvalidateChildPosOrSize(..)> - not expected to handle dispose of child of type <Window>." );
1373             }
1374         }
1375     }
1376 }
1377 
1378 void SwAccessibleContext::InvalidateContent()
1379 {
1380     vos::OGuard aGuard(Application::GetSolarMutex());
1381 
1382     _InvalidateContent( sal_False );
1383 }
1384 
1385 void SwAccessibleContext::InvalidateCursorPos()
1386 {
1387     vos::OGuard aGuard(Application::GetSolarMutex());
1388 
1389     _InvalidateCursorPos();
1390 }
1391 
1392 void SwAccessibleContext::InvalidateFocus()
1393 {
1394     vos::OGuard aGuard(Application::GetSolarMutex());
1395 
1396     _InvalidateFocus();
1397 }
1398 
1399 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
1400 void SwAccessibleContext::InvalidateStates( tAccessibleStates _nStates )
1401 {
1402     if( GetMap() )
1403     {
1404         ViewShell *pVSh = GetMap()->GetShell();
1405         if( pVSh )
1406         {
1407             if( (_nStates & ACC_STATE_EDITABLE) != 0 )
1408             {
1409                 sal_Bool bIsOldEditableState;
1410                 sal_Bool bIsNewEditableState = IsEditable( pVSh );
1411                 {
1412                     vos::OGuard aGuard( aMutex );
1413                     bIsOldEditableState = bIsEditableState;
1414                     bIsEditableState = bIsNewEditableState;
1415                 }
1416 
1417                 if( bIsOldEditableState != bIsNewEditableState )
1418                     FireStateChangedEvent( AccessibleStateType::EDITABLE,
1419                                            bIsNewEditableState  );
1420             }
1421             if( (_nStates & ACC_STATE_OPAQUE) != 0 )
1422             {
1423                 sal_Bool bIsOldOpaqueState;
1424                 sal_Bool bIsNewOpaqueState = IsOpaque( pVSh );
1425                 {
1426                     vos::OGuard aGuard( aMutex );
1427                     bIsOldOpaqueState = bIsOpaqueState;
1428                     bIsOpaqueState = bIsNewOpaqueState;
1429                 }
1430 
1431                 if( bIsOldOpaqueState != bIsNewOpaqueState )
1432                     FireStateChangedEvent( AccessibleStateType::OPAQUE,
1433                                            bIsNewOpaqueState  );
1434             }
1435         }
1436 
1437         InvalidateChildrenStates( GetFrm(), _nStates );
1438     }
1439 }
1440 // <--
1441 
1442 void SwAccessibleContext::InvalidateRelation( sal_uInt16 nType )
1443 {
1444     AccessibleEventObject aEvent;
1445     aEvent.EventId = nType;
1446 
1447     FireAccessibleEvent( aEvent );
1448 }
1449 
1450 /** text selection has changed
1451 
1452     OD 2005-12-14 #i27301#
1453 
1454     @author OD
1455 */
1456 void SwAccessibleContext::InvalidateTextSelection()
1457 {
1458     AccessibleEventObject aEvent;
1459     aEvent.EventId = AccessibleEventId::TEXT_SELECTION_CHANGED;
1460 
1461     FireAccessibleEvent( aEvent );
1462 }
1463 
1464 /** attributes has changed
1465 
1466     OD 2009-01-06 #i88069#
1467 
1468     @author OD
1469 */
1470 void SwAccessibleContext::InvalidateAttr()
1471 {
1472     AccessibleEventObject aEvent;
1473     aEvent.EventId = AccessibleEventId::TEXT_ATTRIBUTE_CHANGED;
1474 
1475     FireAccessibleEvent( aEvent );
1476 }
1477 
1478 sal_Bool SwAccessibleContext::HasCursor()
1479 {
1480     return sal_False;
1481 }
1482 
1483 sal_Bool SwAccessibleContext::Select( SwPaM *pPaM, SdrObject *pObj,
1484                                       sal_Bool bAdd )
1485 {
1486     SwCrsrShell* pCrsrShell = GetCrsrShell();
1487     if( !pCrsrShell )
1488         return sal_False;
1489 
1490     SwFEShell* pFEShell = pCrsrShell->ISA( SwFEShell )
1491                                 ? static_cast<SwFEShell*>( pCrsrShell )
1492                                 : 0;
1493     // Get rid of activated OLE object
1494     if( pFEShell )
1495         pFEShell->FinishOLEObj();
1496 
1497     sal_Bool bRet = sal_False;
1498     if( pObj )
1499     {
1500         if( pFEShell )
1501         {
1502             Point aDummy;
1503             sal_uInt8 nFlags = bAdd ? SW_ADD_SELECT : 0;
1504             pFEShell->SelectObj( aDummy, nFlags, pObj );
1505             bRet = sal_True;
1506         }
1507     }
1508     else if( pPaM )
1509     {
1510         // Get rid of frame selection. If there is one, make text cursor
1511         // visible again.
1512         sal_Bool bCallShowCrsr = sal_False;
1513         if( pFEShell && (pFEShell->IsFrmSelected() ||
1514                          pFEShell->IsObjSelected()) )
1515         {
1516             Point aPt( LONG_MIN, LONG_MIN );
1517             pFEShell->SelectObj( aPt, 0 );
1518             bCallShowCrsr = sal_True;
1519         }
1520         pCrsrShell->KillPams();
1521         pCrsrShell->SetSelection( *pPaM );
1522         if( bCallShowCrsr )
1523             pCrsrShell->ShowCrsr();
1524         bRet = sal_True;
1525     }
1526 
1527     return bRet;
1528 }
1529 
1530 OUString SwAccessibleContext::GetResource( sal_uInt16 nResId,
1531                                            const OUString *pArg1,
1532                                            const OUString *pArg2 )
1533 {
1534     String sStr;
1535     {
1536         vos::OGuard aGuard(Application::GetSolarMutex());
1537 
1538         sStr = SW_RES( nResId );
1539     }
1540 
1541     if( pArg1 )
1542     {
1543         sStr.SearchAndReplace( String::CreateFromAscii(
1544                                     RTL_CONSTASCII_STRINGPARAM( "$(ARG1)" )),
1545                                String( *pArg1 ) );
1546     }
1547     if( pArg2 )
1548     {
1549         sStr.SearchAndReplace( String::CreateFromAscii(
1550                                     RTL_CONSTASCII_STRINGPARAM( "$(ARG2)" )),
1551                                String( *pArg2 ) );
1552     }
1553 
1554     return OUString( sStr );
1555 }
1556 
1557 void SwAccessibleContext::RemoveFrmFromAccessibleMap()
1558 {
1559     if( bRegisteredAtAccessibleMap && GetFrm() && GetMap() )
1560         GetMap()->RemoveContext( GetFrm() );
1561 }
1562 
1563 bool SwAccessibleContext::HasAdditionalAccessibleChildren()
1564 {
1565     bool bRet( false );
1566 
1567     if ( GetFrm()->IsTxtFrm() )
1568     {
1569         SwPostItMgr* pPostItMgr = GetMap()->GetShell()->GetPostItMgr();
1570         if ( pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() )
1571         {
1572             bRet = pPostItMgr->HasFrmConnectedSidebarWins( *(GetFrm()) );
1573         }
1574     }
1575 
1576     return bRet;
1577 }
1578 /** get additional accessible child by index
1579 
1580     OD 2010-01-27 #i88070#
1581 
1582     @author OD
1583 */
1584 Window* SwAccessibleContext::GetAdditionalAccessibleChild( const sal_Int32 nIndex )
1585 {
1586     Window* pAdditionalAccessibleChild( 0 );
1587 
1588     if ( GetFrm()->IsTxtFrm() )
1589     {
1590         SwPostItMgr* pPostItMgr = GetMap()->GetShell()->GetPostItMgr();
1591         if ( pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() )
1592         {
1593             pAdditionalAccessibleChild =
1594                     pPostItMgr->GetSidebarWinForFrmByIndex( *(GetFrm()), nIndex );
1595         }
1596     }
1597 
1598     return pAdditionalAccessibleChild;
1599 }
1600 
1601 /** get all additional accessible children
1602 
1603     OD 2010-01-27 #i88070#
1604 
1605     @author OD
1606 */
1607 void SwAccessibleContext::GetAdditionalAccessibleChildren( std::vector< Window* >* pChildren )
1608 {
1609     if ( GetFrm()->IsTxtFrm() )
1610     {
1611         SwPostItMgr* pPostItMgr = GetMap()->GetShell()->GetPostItMgr();
1612         if ( pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() )
1613         {
1614             pPostItMgr->GetAllSidebarWinForFrm( *(GetFrm()), pChildren );
1615         }
1616     }
1617 }
1618 
1619 #if (OSL_DEBUG_LEVEL > 1) && defined TEST_MIB
1620 void lcl_SwAccessibleContext_DbgMsg( SwAccessibleContext *pThisAcc,
1621                                      const char *pMsg,
1622                                      SwAccessibleContext *pChildAcc,
1623                                      sal_Bool bConstrDestr )
1624 {
1625     static SvFileStream aStrm( String::CreateFromAscii("j:\\acc.log"),
1626                     STREAM_WRITE|STREAM_TRUNC|STREAM_SHARE_DENYNONE );
1627     ByteString aName( String(pThisAcc->GetName()),
1628                       RTL_TEXTENCODING_ISO_8859_1 );
1629     if( aName.Len() )
1630     {
1631         aStrm << aName.GetBuffer()
1632               << ": ";
1633     }
1634     aStrm << pMsg;
1635     if( pChildAcc )
1636     {
1637         ByteString aChild( String(pChildAcc->GetName()),
1638                            RTL_TEXTENCODING_ISO_8859_1 );
1639         aStrm << ": "
1640               << aChild.GetBuffer();
1641     }
1642     aStrm << "\r\n    (";
1643 
1644     if( !bConstrDestr )
1645     {
1646         ByteString aDesc( String(pThisAcc->getAccessibleDescription()),
1647                            RTL_TEXTENCODING_ISO_8859_1 );
1648         aStrm << aDesc.GetBuffer()
1649               << ", ";
1650     }
1651 
1652     Rectangle aVisArea( pThisAcc->GetVisArea() );
1653     aStrm << "VA: "
1654           << ByteString::CreateFromInt32( aVisArea.Left() ).GetBuffer()
1655           << ","
1656           << ByteString::CreateFromInt32( aVisArea.Top() ).GetBuffer()
1657           << ","
1658           << ByteString::CreateFromInt32( aVisArea.GetWidth() ).GetBuffer()
1659           << ","
1660           << ByteString::CreateFromInt32( aVisArea.GetHeight() ).GetBuffer();
1661 
1662     if( pThisAcc->GetFrm() )
1663     {
1664         Rectangle aBounds( pThisAcc->GetBounds( pThisAcc->GetFrm() ) );
1665         aStrm << ", BB: "
1666               << ByteString::CreateFromInt32( aBounds.Left() ).GetBuffer()
1667               << ","
1668               << ByteString::CreateFromInt32( aBounds.Top() ).GetBuffer()
1669               << ","
1670               << ByteString::CreateFromInt32( aBounds.GetWidth() ).GetBuffer()
1671               << ","
1672               << ByteString::CreateFromInt32( aBounds.GetHeight() ).GetBuffer()
1673               << ")\r\n";
1674     }
1675 
1676     aStrm.Flush();
1677 }
1678 #endif
1679 //IAccessibility2 Implementation 2009-----
1680 sal_Bool SwAccessibleContext::SetSelectedState(sal_Bool bSeleted)
1681 {
1682     if(bIsSeletedInDoc != bSeleted)
1683     {
1684         bIsSeletedInDoc = bSeleted;
1685         FireStateChangedEvent( AccessibleStateType::SELECTED, bSeleted );
1686         return sal_True;
1687     }
1688     return sal_False;
1689 };
1690 //-----IAccessibility2 Implementation 2009
1691