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