xref: /aoo42x/main/sw/source/core/access/accdoc.cxx (revision b3486e44)
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 #include <vcl/window.hxx>
27 #include <rootfrm.hxx>
28 
29 
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #include <unotools/accessiblestatesethelper.hxx>
35 #include <tools/link.hxx>
36 #include <sfx2/viewsh.hxx>
37 #include <vos/mutex.hxx>
38 #include <vcl/svapp.hxx>
39 #include <viewsh.hxx>
40 #include <doc.hxx>
41 #include <accmap.hxx>
42 #include <accdoc.hxx>
43 #ifndef _ACCESS_HRC
44 #include "access.hrc"
45 #endif
46 #include <pagefrm.hxx>
47 
48 //IAccessibility2 Implementation 2009-----
49 #include <editeng/brshitem.hxx>
50 #include <swatrset.hxx>
51 #include <frmatr.hxx>
52 #include "unostyle.hxx"
53 #include "viewsh.hxx"
54 #include "docsh.hxx"
55 #include <crsrsh.hxx>
56 #include "fesh.hxx"
57 #include <fmtclds.hxx>
58 #include <flyfrm.hxx>
59 #include <colfrm.hxx>
60 #include <txtfrm.hxx>
61 #include <sectfrm.hxx>
62 #include <section.hxx>
63 #include <svx/unoapi.hxx>
64 #include <swmodule.hxx>
65 #include <svtools/colorcfg.hxx>
66 
67 #include <fmtanchr.hxx>
68 #include <viewimp.hxx>
69 #include <dview.hxx>
70 #include <dcontact.hxx>
71 #include <svx/svdmark.hxx>
72 //-----IAccessibility2 Implementation 2009
73 const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextDocumentView";
74 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleDocumentView";
75 
76 
77 using namespace ::com::sun::star;
78 using namespace ::com::sun::star::accessibility;
79 using ::rtl::OUString;
80 
81 using lang::IndexOutOfBoundsException;
82 
83 
84 
85 //
86 // SwAccessibleDocumentBase: base class for SwAccessibleDocument and
87 // SwAccessiblePreview
88 //
89 
90 SwAccessibleDocumentBase::SwAccessibleDocumentBase ( SwAccessibleMap *_pMap ) :
91 	SwAccessibleContext( _pMap, AccessibleRole::DOCUMENT,
92                          _pMap->GetShell()->GetLayout() ),//swmod 071107//swmod 071225
93 	mxParent( _pMap->GetShell()->GetWin()->GetAccessibleParentWindow()->GetAccessible() ),
94     mpChildWin( 0 )
95 {
96 }
97 
98 SwAccessibleDocumentBase::~SwAccessibleDocumentBase()
99 {
100 }
101 
102 void SwAccessibleDocumentBase::SetVisArea()
103 {
104 	vos::OGuard aGuard(Application::GetSolarMutex());
105 
106 	SwRect aOldVisArea( GetVisArea() );
107 	const SwRect& rNewVisArea = GetMap()->GetVisArea();
108 	if( aOldVisArea != rNewVisArea )
109 	{
110 		SwAccessibleFrame::SetVisArea( GetMap()->GetVisArea() );
111         // --> OD 2007-12-07 #i58139#
112         // showing state of document view needs also be updated.
113         // Thus, call method <Scrolled(..)> instead of <ChildrenScrolled(..)>
114 //        ChildrenScrolled( GetFrm(), aOldVisArea );
115         Scrolled( aOldVisArea );
116         // <--
117 	}
118 }
119 
120 void SwAccessibleDocumentBase::AddChild( Window *pWin, sal_Bool bFireEvent )
121 {
122 	vos::OGuard aGuard(Application::GetSolarMutex());
123 
124     ASSERT( !mpChildWin, "only one child window is supported" );
125     if( !mpChildWin )
126 	{
127         mpChildWin = pWin;
128 
129 		if( bFireEvent )
130 		{
131 			AccessibleEventObject aEvent;
132 			aEvent.EventId = AccessibleEventId::CHILD;
133             aEvent.NewValue <<= mpChildWin->GetAccessible();
134 			FireAccessibleEvent( aEvent );
135 		}
136 	}
137 }
138 
139 void SwAccessibleDocumentBase::RemoveChild( Window *pWin )
140 {
141 	vos::OGuard aGuard(Application::GetSolarMutex());
142 
143     ASSERT( !mpChildWin || pWin == mpChildWin, "invalid child window to remove" );
144     if( mpChildWin && pWin == mpChildWin )
145 	{
146 		AccessibleEventObject aEvent;
147 		aEvent.EventId = AccessibleEventId::CHILD;
148         aEvent.OldValue <<= mpChildWin->GetAccessible();
149 		FireAccessibleEvent( aEvent );
150 
151         mpChildWin = 0;
152 	}
153 }
154 
155 sal_Int32 SAL_CALL SwAccessibleDocumentBase::getAccessibleChildCount( void )
156         throw (uno::RuntimeException)
157 {
158 	vos::OGuard aGuard(Application::GetSolarMutex());
159 
160 	// CHECK_FOR_DEFUNC is called by parent
161 
162 	sal_Int32 nChildren = SwAccessibleContext::getAccessibleChildCount();
163     if( !IsDisposing() && mpChildWin )
164 		nChildren++;
165 
166 	return nChildren;
167 }
168 
169 uno::Reference< XAccessible> SAL_CALL
170 	SwAccessibleDocumentBase::getAccessibleChild( sal_Int32 nIndex )
171         throw (uno::RuntimeException,
172                 lang::IndexOutOfBoundsException)
173 {
174 	vos::OGuard aGuard(Application::GetSolarMutex());
175 
176     if( mpChildWin  )
177 	{
178 		CHECK_FOR_DEFUNC( XAccessibleContext )
179         if ( nIndex == GetChildCount( *(GetMap()) ) )
180         {
181             return mpChildWin->GetAccessible();
182         }
183 	}
184 
185 	return SwAccessibleContext::getAccessibleChild( nIndex );
186 }
187 
188 
189 uno::Reference< XAccessible> SAL_CALL SwAccessibleDocumentBase::getAccessibleParent (void)
190         throw (uno::RuntimeException)
191 {
192     return mxParent;
193 }
194 
195 sal_Int32 SAL_CALL SwAccessibleDocumentBase::getAccessibleIndexInParent (void)
196         throw (uno::RuntimeException)
197 {
198 	vos::OGuard aGuard(Application::GetSolarMutex());
199 
200 	uno::Reference < XAccessibleContext > xAcc( mxParent->getAccessibleContext() );
201 	uno::Reference < XAccessible > xThis( this );
202 	sal_Int32 nCount = xAcc->getAccessibleChildCount();
203 
204 	for( sal_Int32 i=0; i < nCount; i++ )
205 	{
206 		//IAccessibility2 Implementation 2009-----
207 		try
208 		{
209 			if( xAcc->getAccessibleChild( i ) == xThis )
210 				return i;
211 		}
212 		catch(::com::sun::star::lang::IndexOutOfBoundsException e)
213 		{
214 			return -1L;
215 		}
216 		//-----IAccessibility2 Implementation 2009
217 	}
218 	return -1L;
219 }
220 
221 OUString SAL_CALL SwAccessibleDocumentBase::getAccessibleDescription (void)
222     throw (uno::RuntimeException)
223 {
224 	return GetResource( STR_ACCESS_DOC_DESC );
225 }
226 
227 //IAccessibility2 Implementation 2009-----
228 OUString SAL_CALL SwAccessibleDocumentBase::getAccessibleName (void)
229 		throw (::com::sun::star::uno::RuntimeException)
230 {
231 	OUString sAccName = GetResource( STR_ACCESS_DOC_WORDPROCESSING );
232 	SwDoc *pDoc = GetShell()->GetDoc();
233 	if ( pDoc )
234 	{
235 		OUString sFileName = pDoc->getDocAccTitle();
236 		if ( !sFileName.getLength() )
237 		{
238 			SwDocShell* pDocSh = pDoc->GetDocShell();
239 			if ( pDocSh )
240 			{
241 				sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
242 			}
243 		}
244 		OUString sReadOnly;
245 		if(pDoc->getDocReadOnly())
246 		{
247 			sReadOnly = GetResource( STR_ACCESS_DOC_WORDPROCESSING_READONLY );
248 		}
249 
250 		if ( sFileName.getLength() )
251 		{
252 			sAccName = sFileName + sReadOnly + OUString(RTL_CONSTASCII_USTRINGPARAM(" - ")) + sAccName;
253 		}
254 	}
255 
256 	return sAccName;
257 }
258 //-----IAccessibility2 Implementation 2009
259 
260 awt::Rectangle SAL_CALL SwAccessibleDocumentBase::getBounds()
261 		throw (uno::RuntimeException)
262 {
263 	//IAccessibility2 Implementation 2009-----
264 	try
265 	{
266 		vos::OGuard aGuard(Application::GetSolarMutex());
267 
268 		Window *pWin = GetWindow();
269 
270 		CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
271 
272 			Rectangle aPixBounds( pWin->GetWindowExtentsRelative( pWin->GetAccessibleParentWindow() ) );
273 		awt::Rectangle aBox( aPixBounds.Left(), aPixBounds.Top(),
274 			aPixBounds.GetWidth(), aPixBounds.GetHeight() );
275 
276 		return aBox;
277 	}
278 	catch(::com::sun::star::lang::IndexOutOfBoundsException e)
279 	{
280 		return awt::Rectangle();
281 	}
282 	//-----IAccessibility2 Implementation 2009
283 }
284 
285 
286 awt::Point SAL_CALL SwAccessibleDocumentBase::getLocation()
287 		throw (uno::RuntimeException)
288 {
289 	vos::OGuard aGuard(Application::GetSolarMutex());
290 
291 	Window *pWin = GetWindow();
292 
293 	CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
294 
295 	Point aPixPos( pWin->GetWindowExtentsRelative( pWin->GetAccessibleParentWindow() ).TopLeft() );
296 	awt::Point aLoc( aPixPos.X(), aPixPos.Y() );
297 
298 	return aLoc;
299 }
300 
301 
302 ::com::sun::star::awt::Point SAL_CALL SwAccessibleDocumentBase::getLocationOnScreen()
303 		throw (uno::RuntimeException)
304 {
305 	vos::OGuard aGuard(Application::GetSolarMutex());
306 
307 	Window *pWin = GetWindow();
308 
309 	CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
310 
311 	Point aPixPos( pWin->GetWindowExtentsRelative( 0 ).TopLeft() );
312 	awt::Point aLoc( aPixPos.X(), aPixPos.Y() );
313 
314 	return aLoc;
315 }
316 
317 
318 ::com::sun::star::awt::Size SAL_CALL SwAccessibleDocumentBase::getSize()
319 		throw (uno::RuntimeException)
320 {
321 	vos::OGuard aGuard(Application::GetSolarMutex());
322 
323 	Window *pWin = GetWindow();
324 
325 	CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
326 
327 	Size aPixSize( pWin->GetWindowExtentsRelative( 0 ).GetSize() );
328 	awt::Size aSize( aPixSize.Width(), aPixSize.Height() );
329 
330 	return aSize;
331 }
332 
333 sal_Bool SAL_CALL SwAccessibleDocumentBase::containsPoint(
334 			const awt::Point& aPoint )
335 		throw (uno::RuntimeException)
336 {
337 	vos::OGuard aGuard(Application::GetSolarMutex());
338 
339 	Window *pWin = GetWindow();
340 
341 	CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
342 
343 	Rectangle aPixBounds( pWin->GetWindowExtentsRelative( 0 ) );
344     aPixBounds.Move(-aPixBounds.Left(), -aPixBounds.Top());
345 
346 	Point aPixPoint( aPoint.X, aPoint.Y );
347 	return aPixBounds.IsInside( aPixPoint );
348 }
349 
350 uno::Reference< XAccessible > SAL_CALL SwAccessibleDocumentBase::getAccessibleAtPoint(
351 				const awt::Point& aPoint )
352 		throw (uno::RuntimeException)
353 {
354 	vos::OGuard aGuard(Application::GetSolarMutex());
355 
356     if( mpChildWin  )
357 	{
358 		CHECK_FOR_DEFUNC( XAccessibleComponent )
359 
360 		Window *pWin = GetWindow();
361 		CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
362 
363 		Point aPixPoint( aPoint.X, aPoint.Y ); // px rel to window
364         if( mpChildWin->GetWindowExtentsRelative( pWin ).IsInside( aPixPoint ) )
365             return mpChildWin->GetAccessible();
366 	}
367 
368 	return SwAccessibleContext::getAccessibleAtPoint( aPoint );
369 }
370 
371 //
372 // SwAccessibeDocument
373 //
374 
375 void SwAccessibleDocument::GetStates(
376 		::utl::AccessibleStateSetHelper& rStateSet )
377 {
378 	SwAccessibleContext::GetStates( rStateSet );
379 
380 	// MULTISELECTABLE
381 	rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE );
382 	//IAccessibility2 Implementation 2009-----
383 	rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
384 	//-----IAccessibility2 Implementation 2009
385 }
386 
387 
388 SwAccessibleDocument::SwAccessibleDocument ( SwAccessibleMap* pInitMap ) :
389     SwAccessibleDocumentBase( pInitMap ),
390     maSelectionHelper( *this )
391 {
392 	SetName( GetResource( STR_ACCESS_DOC_NAME ) );
393     Window *pWin = pInitMap->GetShell()->GetWin();
394 	if( pWin )
395 	{
396 		pWin->AddChildEventListener( LINK( this, SwAccessibleDocument, WindowChildEventListener ));
397 		sal_uInt16 nCount =   pWin->GetChildCount();
398 		for( sal_uInt16 i=0; i < nCount; i++ )
399 		{
400             Window* pChildWin = pWin->GetChild( i );
401             if( pChildWin &&
402                 AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
403                 AddChild( pChildWin, sal_False );
404 		}
405 	}
406 }
407 
408 SwAccessibleDocument::~SwAccessibleDocument()
409 {
410 	Window *pWin = GetMap() ? GetMap()->GetShell()->GetWin() : 0;
411 	if( pWin )
412 		pWin->RemoveChildEventListener( LINK( this, SwAccessibleDocument, WindowChildEventListener ));
413 }
414 
415 void SwAccessibleDocument::Dispose( sal_Bool bRecursive )
416 {
417 	ASSERT( GetFrm() && GetMap(), "already disposed" );
418 
419 	Window *pWin = GetMap() ? GetMap()->GetShell()->GetWin() : 0;
420 	if( pWin )
421 		pWin->RemoveChildEventListener( LINK( this, SwAccessibleDocument, WindowChildEventListener ));
422 	SwAccessibleContext::Dispose( bRecursive );
423 }
424 
425 IMPL_LINK( SwAccessibleDocument, WindowChildEventListener, VclSimpleEvent*, pEvent )
426 {
427 	DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
428 	if ( pEvent && pEvent->ISA( VclWindowEvent ) )
429 	{
430 		VclWindowEvent *pVclEvent = static_cast< VclWindowEvent * >( pEvent );
431 		DBG_ASSERT( pVclEvent->GetWindow(), "Window???" );
432 		switch ( pVclEvent->GetId() )
433 		{
434         case VCLEVENT_WINDOW_SHOW:  // send create on show for direct accessible children
435 			{
436 				Window* pChildWin = static_cast< Window* >( pVclEvent->GetData() );
437 				if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
438 				{
439 					AddChild( pChildWin );
440 				}
441 			}
442 			break;
443         case VCLEVENT_WINDOW_HIDE:  // send destroy on hide for direct accessible children
444 			{
445 				Window* pChildWin = static_cast< Window* >( pVclEvent->GetData() );
446 				if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
447 				{
448 					RemoveChild( pChildWin );
449 				}
450 			}
451 			break;
452         case VCLEVENT_OBJECT_DYING:  // send destroy on hide for direct accessible children
453 			{
454 				Window* pChildWin = pVclEvent->GetWindow();
455 				if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
456 				{
457 					RemoveChild( pChildWin );
458 				}
459 			}
460 			break;
461 		}
462 	}
463 	return 0;
464 }
465 
466 
467 OUString SAL_CALL SwAccessibleDocument::getImplementationName()
468         throw( uno::RuntimeException )
469 {
470 	return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
471 }
472 
473 sal_Bool SAL_CALL SwAccessibleDocument::supportsService(
474 		const ::rtl::OUString& sTestServiceName)
475 	throw (uno::RuntimeException)
476 {
477 	return sTestServiceName.equalsAsciiL( sServiceName,
478 										  sizeof(sServiceName)-1 ) ||
479 		   sTestServiceName.equalsAsciiL( sAccessibleServiceName,
480 				   						  sizeof(sAccessibleServiceName)-1 );
481 }
482 
483 uno::Sequence< OUString > SAL_CALL SwAccessibleDocument::getSupportedServiceNames()
484 		throw( uno::RuntimeException )
485 {
486 	uno::Sequence< OUString > aRet(2);
487 	OUString* pArray = aRet.getArray();
488 	pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
489 	pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
490 	return aRet;
491 }
492 
493 //=====  XInterface  ======================================================
494 
495 uno::Any SwAccessibleDocument::queryInterface(
496     const uno::Type& rType )
497     throw ( uno::RuntimeException )
498 {
499     uno::Any aRet;
500     if ( rType == ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) ) )
501     {
502         uno::Reference<XAccessibleSelection> aSelect = this;
503         aRet <<= aSelect;
504     }
505     //IAccessibility2 Implementation 2009-----
506     //Solution:Add XEventListener interface support.
507 	else if ( (rType == ::getCppuType((uno::Reference<com::sun::star::document::XEventListener> *)NULL)) )
508     {
509         uno::Reference<com::sun::star::document::XEventListener> aSelect = this;
510         aRet <<= aSelect;
511     }
512     else  if ( rType == ::getCppuType((uno::Reference<XAccessibleExtendedAttributes> *)NULL) )
513     {
514         uno::Reference<XAccessibleExtendedAttributes> aAttribute = this;
515         aRet <<= aAttribute;
516     }
517     else if(rType == ::getCppuType((uno::Reference<XAccessibleGetAccFlowTo> *)NULL) )
518     {
519 		uno::Reference<XAccessibleGetAccFlowTo> AccFlowTo = this;
520         aRet <<= AccFlowTo;
521     }
522     //-----IAccessibility2 Implementation 2009
523     else
524         aRet = SwAccessibleContext::queryInterface( rType );
525     return aRet;
526 }
527 
528 //====== XTypeProvider ====================================================
529 uno::Sequence< uno::Type > SAL_CALL SwAccessibleDocument::getTypes()
530     throw(uno::RuntimeException)
531 {
532 	uno::Sequence< uno::Type > aTypes( SwAccessibleDocumentBase::getTypes() );
533 
534 	sal_Int32 nIndex = aTypes.getLength();
535 	//IAccessibility2 Implementation 2009-----
536 	//Solution:Reset types memory alloc
537 	//aTypes.realloc( nIndex + 1 );
538 	aTypes.realloc( nIndex + 2 );
539 
540 	uno::Type* pTypes = aTypes.getArray();
541 	pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) );
542 	//Solution:Add XEventListener interface support.
543 	pTypes[nIndex + 1 ] = ::getCppuType( static_cast< uno::Reference< com::sun::star::document::XEventListener > * >( 0 ) );
544 	//-----IAccessibility2 Implementation 2009
545 	return aTypes;
546 }
547 
548 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleDocument::getImplementationId()
549 		throw(uno::RuntimeException)
550 {
551     vos::OGuard aGuard(Application::GetSolarMutex());
552     static uno::Sequence< sal_Int8 > aId( 16 );
553     static sal_Bool bInit = sal_False;
554     if(!bInit)
555     {
556         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
557         bInit = sal_True;
558     }
559     return aId;
560 }
561 
562 //=====  XAccessibleSelection  ============================================
563 
564 void SwAccessibleDocument::selectAccessibleChild(
565     sal_Int32 nChildIndex )
566     throw ( lang::IndexOutOfBoundsException,
567             uno::RuntimeException )
568 {
569     maSelectionHelper.selectAccessibleChild(nChildIndex);
570 }
571 
572 sal_Bool SwAccessibleDocument::isAccessibleChildSelected(
573     sal_Int32 nChildIndex )
574     throw ( lang::IndexOutOfBoundsException,
575             uno::RuntimeException )
576 {
577     return maSelectionHelper.isAccessibleChildSelected(nChildIndex);
578 }
579 
580 void SwAccessibleDocument::clearAccessibleSelection(  )
581     throw ( uno::RuntimeException )
582 {
583     maSelectionHelper.clearAccessibleSelection();
584 }
585 
586 void SwAccessibleDocument::selectAllAccessibleChildren(  )
587     throw ( uno::RuntimeException )
588 {
589     maSelectionHelper.selectAllAccessibleChildren();
590 }
591 
592 sal_Int32 SwAccessibleDocument::getSelectedAccessibleChildCount(  )
593     throw ( uno::RuntimeException )
594 {
595     return maSelectionHelper.getSelectedAccessibleChildCount();
596 }
597 
598 uno::Reference<XAccessible> SwAccessibleDocument::getSelectedAccessibleChild(
599     sal_Int32 nSelectedChildIndex )
600     throw ( lang::IndexOutOfBoundsException,
601             uno::RuntimeException)
602 {
603     return maSelectionHelper.getSelectedAccessibleChild(nSelectedChildIndex);
604 }
605 
606 // --> OD 2004-11-16 #111714# - index has to be treated as global child index.
607 void SwAccessibleDocument::deselectAccessibleChild(
608     sal_Int32 nChildIndex )
609     throw ( lang::IndexOutOfBoundsException,
610             uno::RuntimeException )
611 {
612     maSelectionHelper.deselectAccessibleChild( nChildIndex );
613 }
614 //IAccessibility2 Implementation 2009-----
615 //Solution:Implement XEventListener interfaces
616 void SAL_CALL SwAccessibleDocument::notifyEvent( const ::com::sun::star::document::EventObject& Event )
617 			throw (::com::sun::star::uno::RuntimeException)
618 {
619 	if ( Event.EventName.equalsAscii( "FirstPageShows" ) )
620 	{
621 		FireStateChangedEvent( AccessibleStateType::FOCUSED,sal_True );
622 	}
623 	else if ( Event.EventName.equalsAscii( "LoadFinished" ) )
624 	{
625 		// IA2 CWS. MT: OFFSCREEN == !SHOWING, should stay consistent
626 		// FireStateChangedEvent( AccessibleStateType::OFFSCREEN,sal_True );
627 		// MT: LoadFinished => Why not SHOWING == TRUE?
628 		FireStateChangedEvent( AccessibleStateType::SHOWING,sal_False );
629 	}
630 	else if ( Event.EventName.equalsAscii( "FormatFinished" ) )
631 	{
632 		FireStateChangedEvent( AccessibleStateType::BUSY,sal_False );
633 		// FireStateChangedEvent( AccessibleStateType::OFFSCREEN,sal_False );
634 		FireStateChangedEvent( AccessibleStateType::SHOWING,sal_True );
635 	}
636 	else
637 	{
638 		isIfAsynLoad = sal_False;
639 	}
640 }
641 
642 void SAL_CALL SwAccessibleDocument::disposing( const ::com::sun::star::lang::EventObject& )
643 			throw (::com::sun::star::uno::RuntimeException)
644 {
645 }
646 
647 uno::Any SAL_CALL SwAccessibleDocument::getExtendedAttributes()
648 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
649 {
650 	uno::Any anyAtrribute;
651 	SwDoc *pDoc = GetShell()->GetDoc();
652 
653 	if (!pDoc)
654 		return anyAtrribute;
655 	SwCrsrShell* pCrsrShell = GetCrsrShell();
656 	if( !pCrsrShell )
657 		return anyAtrribute;
658 
659     SwFEShell* pFEShell = pCrsrShell->ISA( SwFEShell )
660 								? static_cast<SwFEShell*>( pCrsrShell )
661 							: 0;
662 	rtl::OUString sAttrName;
663 	rtl::OUString sValue;
664 	sal_uInt16 nPage, nLogPage;
665 	String sDisplay;
666 
667 	if( pFEShell )
668 	{
669 		pFEShell->GetPageNumber(-1,sal_True,nPage,nLogPage,sDisplay);
670 		sAttrName = rtl::OUString::createFromAscii("page-name:");
671 
672 
673 		sValue = sAttrName + sDisplay ;
674 		sAttrName = rtl::OUString::createFromAscii(";page-number:");
675 		sValue += sAttrName;
676 		sValue += String::CreateFromInt32( nPage ) ;
677 		sAttrName = rtl::OUString::createFromAscii(";total-pages:");
678 		sValue += sAttrName;
679 		sValue += String::CreateFromInt32( pCrsrShell->GetPageCnt() ) ;
680 		sValue +=  rtl::OUString::createFromAscii(";");
681 
682 
683 		sAttrName=rtl::OUString::createFromAscii("line-number:");
684 
685 
686 
687 		SwCntntFrm* pCurrFrm = pCrsrShell->GetCurrFrm();
688 		SwPageFrm* pCurrPage=((SwFrm*)pCurrFrm)->FindPageFrm();
689 		sal_uLong nLineNum = 0;
690 		//IAccessibility2 Implementation 2009-----
691 		SwTxtFrm* pTxtFrm = NULL;
692 		SwTxtFrm* pCurrTxtFrm = NULL;
693 		pTxtFrm = static_cast< SwTxtFrm* >(static_cast< SwPageFrm* > (pCurrPage)->ContainsCntnt());
694 		if (pCurrFrm->IsInFly())//such as, graphic,chart
695 		{
696 			SwFlyFrm *pFlyFrm = pCurrFrm->FindFlyFrm();
697 			const SwFmtAnchor& rAnchor = pFlyFrm->GetFmt()->GetAnchor();
698 			RndStdIds eAnchorId = rAnchor.GetAnchorId();
699 			if(eAnchorId == FLY_AS_CHAR)
700 			{
701 				const SwFrm *pSwFrm = pFlyFrm->GetAnchorFrm();
702 				if(pSwFrm->IsTxtFrm())
703 					pCurrTxtFrm = ((SwTxtFrm*)(pSwFrm));
704 			}
705 		}
706 		else
707 			pCurrTxtFrm = static_cast< SwTxtFrm* >(pCurrFrm);
708 		//check whether the text frame where the Graph/OLE/Frame anchored is in the Header/Footer
709 		SwFrm* pFrm = pCurrTxtFrm;
710 		while ( pFrm && !pFrm->IsHeaderFrm() && !pFrm->IsFooterFrm() )
711 			pFrm = pFrm->GetUpper();
712 		if ( pFrm )
713 			pCurrTxtFrm = NULL;
714 		//check shape
715 		if(pCrsrShell->Imp()->GetDrawView())
716 		{
717 			const SdrMarkList &rMrkList = pCrsrShell->Imp()->GetDrawView()->GetMarkedObjectList();
718 			for ( sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i )
719 			{
720 				SdrObject *pObj = rMrkList.GetMark(i)->GetMarkedSdrObj();
721 				SwFrmFmt* pFmt = ((SwDrawContact*)pObj->GetUserCall())->GetFmt();
722 				const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
723 				if( FLY_AS_CHAR != rAnchor.GetAnchorId() )
724 					pCurrTxtFrm = NULL;
725 			}
726 		}
727 		//calculate line number
728 		if (pCurrTxtFrm && pTxtFrm)
729 		{
730 			if (!(pCurrTxtFrm->IsInTab() || pCurrTxtFrm->IsInFtn()))
731 			{
732 				while( pTxtFrm != pCurrTxtFrm )
733 				{
734 					//check header/footer
735 					pFrm = pTxtFrm;
736 					while ( pFrm && !pFrm->IsHeaderFrm() && !pFrm->IsFooterFrm() )
737 						pFrm = pFrm->GetUpper();
738 					if ( pFrm )
739 					{
740 						pTxtFrm = static_cast< SwTxtFrm*>(pTxtFrm->GetNextCntntFrm());
741 						continue;
742 					}
743 					if (!(pTxtFrm->IsInTab() || pTxtFrm->IsInFtn() || pTxtFrm->IsInFly()))
744 						nLineNum += pTxtFrm->GetThisLines();
745 					pTxtFrm = static_cast< SwTxtFrm* >(pTxtFrm ->GetNextCntntFrm());
746 				}
747 				SwPaM* pCaret = pCrsrShell->GetCrsr();
748 				if (!pCurrTxtFrm->IsEmpty() && pCaret)
749 				{
750 					sal_uInt16 nActPos = 0;
751 					if (pCurrTxtFrm->IsTxtFrm())
752 					{
753 						const SwPosition* pPoint = NULL;
754 						if(pCurrTxtFrm->IsInFly())
755 						{
756 							SwFlyFrm *pFlyFrm = pCurrTxtFrm->FindFlyFrm();
757 							const SwFmtAnchor& rAnchor = pFlyFrm->GetFmt()->GetAnchor();
758 							pPoint= rAnchor.GetCntntAnchor();
759 						}
760 						else
761 							pPoint = pCaret->GetPoint();
762 						nActPos = pPoint->nContent.GetIndex();
763 						nLineNum += pCurrTxtFrm->GetLineCount( nActPos );
764 					}
765 					else//graphic, form, shape, etc.
766 					{
767 						SwPosition* pPoint =  pCaret->GetPoint();
768 						Point aPt = pCrsrShell->_GetCrsr()->GetPtPos();
769 						if( pCrsrShell->GetLayout()->GetCrsrOfst( pPoint, aPt/*,* &eTmpState*/ ) )
770 						{
771 							nActPos = pPoint->nContent.GetIndex();
772 							nLineNum += pCurrTxtFrm->GetLineCount( nActPos );
773 						}
774 					}
775 				}
776 				else
777 					++nLineNum;
778 			}
779 		}
780 		//-----IAccessibility2 Implementation 2009
781 
782 		sValue += sAttrName;
783 		sValue += String::CreateFromInt32( nLineNum ) ;
784 
785 		sValue +=  rtl::OUString::createFromAscii(";");
786 
787 
788 		SwFrm* pCurrCol=((SwFrm*)pCurrFrm)->FindColFrm();
789 
790 		sAttrName=rtl::OUString::createFromAscii("column-number:");
791 		sValue += sAttrName;
792 
793 		sal_uInt16 nCurrCol = 1;
794 		if(pCurrCol!=NULL)
795 		{
796 			//SwLayoutFrm* pParent = pCurrCol->GetUpper();
797 			SwFrm* pCurrPageCol=((SwFrm*)pCurrFrm)->FindColFrm();
798 			while(pCurrPageCol && pCurrPageCol->GetUpper() && pCurrPageCol->GetUpper()->IsPageFrm())
799 			{
800 				pCurrPageCol = pCurrPageCol->GetUpper();
801 			}
802 
803 			SwLayoutFrm* pParent = (SwLayoutFrm*)(pCurrPageCol->GetUpper());
804 
805 			if(pParent!=NULL)
806 			{
807 				SwFrm* pCol = pParent->Lower();
808 				while(pCol&&(pCol!=pCurrPageCol))
809 				{
810 					pCol = pCol->GetNext();
811 					nCurrCol +=1;
812 				}
813 			}
814 		}
815 		sValue += String::CreateFromInt32( nCurrCol ) ;
816 		sValue +=  rtl::OUString::createFromAscii(";");
817 
818 		sAttrName=rtl::OUString::createFromAscii("total-columns:");
819 
820 		const SwFmtCol &rFmtCol=pCurrPage->GetAttrSet()->GetCol();
821 		sal_uInt16 nColCount=rFmtCol.GetNumCols();
822 		nColCount = nColCount>0?nColCount:1;
823 		sValue += sAttrName;
824 		sValue += String::CreateFromInt32( nColCount ) ;
825 
826 		sValue +=  rtl::OUString::createFromAscii(";");
827 
828 		if(pCurrFrm!=NULL)
829 		{
830 			SwSectionFrm* pCurrSctFrm=((SwFrm*)pCurrFrm)->FindSctFrm();
831 			if(pCurrSctFrm!=NULL && pCurrSctFrm->GetSection()!=NULL )
832 			{
833 				sAttrName = rtl::OUString::createFromAscii("section-name:");
834 
835 				sValue += sAttrName;
836 				String sectionName = pCurrSctFrm->GetSection()->GetSectionName();
837 
838 				sectionName.SearchAndReplace( String::CreateFromAscii( "\\" ), String::CreateFromAscii("\\\\" ));
839 				sectionName.SearchAndReplace( String::CreateFromAscii( "=" ), String::CreateFromAscii("\\=" ) );
840 				sectionName.SearchAndReplace( String::CreateFromAscii( ";" ), String::CreateFromAscii("\\;" ) );
841 				sectionName.SearchAndReplace( String::CreateFromAscii( "," ), String::CreateFromAscii("\\," ) );
842 				sectionName.SearchAndReplace( String::CreateFromAscii( ":" ), String::CreateFromAscii("\\:" ) );
843 
844 				sValue += sectionName;
845 				//sValue += pCurrSctFrm->GetSection()->GetName();
846 
847 				sValue += rtl::OUString::createFromAscii(";");
848 
849 				//section-columns-number
850 				{
851 				sAttrName=rtl::OUString::createFromAscii("section-columns-number:");
852 
853 				nCurrCol = 1;
854 
855 				if(pCurrCol!=NULL)
856 				{
857 					SwLayoutFrm* pParent = pCurrCol->GetUpper();
858 					if(pParent!=NULL)
859 					{
860 						SwFrm* pCol = pParent->Lower();
861 						while(pCol&&(pCol!=pCurrCol))
862 						{
863 							pCol = pCol->GetNext();
864 							nCurrCol +=1;
865 						}
866 					}
867 				}
868 				sValue += sAttrName;
869 				sValue += String::CreateFromInt32( nCurrCol ) ;
870 				sValue +=  rtl::OUString::createFromAscii(";");
871 				}
872 
873 				//section-total-columns
874 				{
875 				sAttrName=rtl::OUString::createFromAscii("section-total-columns:");
876 				const SwFmtCol &rFmtSctCol=pCurrSctFrm->GetAttrSet()->GetCol();
877 				sal_uInt16 nSctColCount=rFmtSctCol.GetNumCols();
878 				nSctColCount = nSctColCount>0?nSctColCount:1;
879 				sValue += sAttrName;
880 				sValue += String::CreateFromInt32( nSctColCount ) ;
881 
882 				sValue +=  rtl::OUString::createFromAscii(";");
883 				}
884 			}
885 		}
886 		anyAtrribute <<= sValue;
887 	}
888 	return anyAtrribute;
889 }
890 
891 sal_Int32 SAL_CALL SwAccessibleDocument::getBackground()
892 		throw (::com::sun::star::uno::RuntimeException)
893 {
894 	//IAccessibility2 Implementation 2009-----
895 	vos::OGuard aGuard(Application::GetSolarMutex());
896 	return SW_MOD()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor;
897 	//-----IAccessibility2 Implementation 2009
898 }
899 
900 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
901 		SAL_CALL SwAccessibleDocument::get_AccFlowTo(const ::com::sun::star::uno::Any& rAny, sal_Int32 nType)
902 		throw ( ::com::sun::star::uno::RuntimeException )
903 {
904 	const sal_Int32 FORSPELLCHECKFLOWTO = 1;
905 	const sal_Int32 FORFINDREPLACEFLOWTO = 2;
906 	SwAccessibleMap* pAccMap = GetMap();
907 	if ( !pAccMap )
908 	{
909 		goto Rt;
910 	}
911 
912 	if ( nType == FORSPELLCHECKFLOWTO )
913 	{
914 		uno::Reference< ::com::sun::star::drawing::XShape > xShape;
915 		rAny >>= xShape;
916 		if( xShape.is() )
917 		{
918 			SdrObject* pObj = GetSdrObjectFromXShape(xShape);
919 			if( pObj )
920 			{
921 				uno::Reference<XAccessible> xAcc = pAccMap->GetContext(pObj, this, sal_False);
922 				uno::Reference < XAccessibleSelection > xAccSelection( xAcc, uno::UNO_QUERY );
923 				if ( xAccSelection.is() )
924 				{
925 					try
926 					{
927 						if ( xAccSelection->getSelectedAccessibleChildCount() )
928 						{
929 							uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 );
930 							if ( xSel.is() )
931 							{
932 								uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
933 								if ( xSelContext.is() )
934 								{
935 									//if in sw we find the selected paragraph here
936 									if ( xSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
937 									{
938 										uno::Sequence<uno::Any> aRet( 1 );
939 										aRet[0] = uno::makeAny( xSel );
940 										return aRet;
941 									}
942 								}
943 							}
944 						}
945 					}
946 					catch ( com::sun::star::lang::IndexOutOfBoundsException )
947 					{
948 						//return empty sequence
949 						goto Rt;
950 					}
951 					//end of try...catch
952 				}
953 				/*uno::Sequence< uno::Any > aRet(1);
954 				aRet[0] = uno::makeAny( xAcc );
955 				return aRet;*/
956 			}
957 		}
958 		else
959 		{
960 			uno::Reference< XAccessible > xAcc = pAccMap->GetCursorContext();
961 			SwAccessibleContext *pAccImpl = static_cast< SwAccessibleContext *>( xAcc.get() );
962 			if ( pAccImpl && pAccImpl->getAccessibleRole() == AccessibleRole::PARAGRAPH )
963 			{
964 				uno::Sequence< uno::Any > aRet(1);
965 				aRet[0] = uno::makeAny( xAcc );
966 				return aRet;
967 			}
968 		}
969 	}
970 	else if ( nType == FORFINDREPLACEFLOWTO )
971 	{
972 		SwCrsrShell* pCrsrShell = GetCrsrShell();
973 		if ( pCrsrShell )
974 		{
975 			SwPaM *_pStartCrsr = pCrsrShell->GetCrsr(), *__pStartCrsr = _pStartCrsr;
976 			SwCntntNode* pPrevNode = NULL;
977 			std::vector<SwFrm*> vFrmList;
978 			do
979 			{
980 				if ( _pStartCrsr && _pStartCrsr->HasMark() )
981 				{
982 					SwCntntNode* pCntntNode = _pStartCrsr->GetCntntNode();
983 					if ( pCntntNode == pPrevNode )
984 					{
985 						continue;
986 					}
987 					SwFrm* pFrm = pCntntNode ? pCntntNode->getLayoutFrm( pCrsrShell->GetLayout() ) : NULL;
988 					if ( pFrm )
989 					{
990 						vFrmList.push_back( pFrm );
991 					}
992 
993 					pPrevNode = pCntntNode;
994 				}
995 			}
996 
997 			while( _pStartCrsr && ( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != __pStartCrsr) );
998 
999 			if ( vFrmList.size() )
1000 			{
1001 				uno::Sequence< uno::Any > aRet(vFrmList.size());
1002 				std::vector<SwFrm*>::iterator aIter = vFrmList.begin();
1003 				for ( sal_Int32 nIndex = 0; aIter != vFrmList.end(); aIter++, nIndex++ )
1004 				{
1005 					uno::Reference< XAccessible > xAcc = pAccMap->GetContext(*aIter, sal_False);
1006 					if ( xAcc.is() )
1007 					{
1008 						SwAccessibleContext *pAccImpl = static_cast< SwAccessibleContext *>( xAcc.get() );
1009 						if ( pAccImpl && pAccImpl->getAccessibleRole() == AccessibleRole::PARAGRAPH )
1010 						{
1011 							aRet[nIndex] = uno::makeAny( xAcc );
1012 						}
1013 					}
1014 				}
1015 
1016 				return aRet;
1017 			}
1018 		}
1019 	}
1020 
1021 Rt:
1022 	uno::Sequence< uno::Any > aEmpty;
1023 	return aEmpty;
1024 }
1025 //-----IAccessibility2 Implementation 2009
1026