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_sd.hxx"
26 #include "AccessibleDocumentViewBase.hxx"
27 #include <com/sun/star/drawing/XDrawPage.hpp>
28 #include <com/sun/star/drawing/XDrawView.hpp>
29 #include <com/sun/star/drawing/XShapes.hpp>
30 #include <com/sun/star/container/XChild.hpp>
31 #include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/frame/XFrame.hpp>
33 #include <com/sun/star/document/XEventBroadcaster.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <rtl/ustring.h>
39 #include<sfx2/viewfrm.hxx>
40 //IAccessibility2 Implementation 2009-----
41 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 #include <sfx2/objsh.hxx>
43 //-----IAccessibility2 Implementation 2009
44 #include <svx/AccessibleShape.hxx>
45 
46 #include <svx/svdobj.hxx>
47 #include <svx/svdmodel.hxx>
48 #include <svx/unoapi.hxx>
49 #include <toolkit/helper/vclunohelper.hxx>
50 #include "Window.hxx"
51 #include <vcl/svapp.hxx>
52 //IAccessibility2 Implementation 2009-----
53 #include "OutlineViewShell.hxx"
54 
55 #include "SlideViewShell.hxx"
56 
57 #include <svx/svdlayer.hxx>
58 #include <editeng/editobj.hxx>
59 #include "LayerTabBar.hxx"
60 #include <svtools/colorcfg.hxx>
61 //-----IAccessibility2 Implementation 2009
62 #include "ViewShell.hxx"
63 #include "View.hxx"
64 #include <memory>
65 
66 using ::rtl::OUString;
67 using namespace ::com::sun::star;
68 using namespace	::com::sun::star::accessibility;
69 using ::com::sun::star::uno::Reference;
70 
71 class SfxViewFrame;
72 
73 namespace accessibility {
74 
75 //=====  internal  ============================================================
76 AccessibleDocumentViewBase::AccessibleDocumentViewBase (
77     ::sd::Window* pSdWindow,
78     ::sd::ViewShell* pViewShell,
79     const uno::Reference<frame::XController>& rxController,
80     const uno::Reference<XAccessible>& rxParent)
81     : AccessibleContextBase (rxParent, AccessibleRole::DOCUMENT),
82       mpWindow (pSdWindow),
83       mxController (rxController),
84       mxModel (NULL),
85       maViewForwarder (
86         static_cast<SdrPaintView*>(pViewShell->GetView()),
87         *static_cast<OutputDevice*>(pSdWindow))
88 {
89     if (mxController.is())
90         mxModel = mxController->getModel();
91 
92     // Fill the shape tree info.
93     maShapeTreeInfo.SetModelBroadcaster (
94         uno::Reference<document::XEventBroadcaster>(
95             mxModel, uno::UNO_QUERY));
96     maShapeTreeInfo.SetController (mxController);
97     maShapeTreeInfo.SetSdrView (pViewShell->GetView());
98     maShapeTreeInfo.SetWindow (pSdWindow);
99     maShapeTreeInfo.SetViewForwarder (&maViewForwarder);
100 
101     mxWindow = ::VCLUnoHelper::GetInterface (pSdWindow);
102 //IAccessibility2 Implementation 2009-----
103 	mpViewShell = pViewShell;
104 //-----IAccessibility2 Implementation 2009
105 }
106 
107 
108 
109 
110 AccessibleDocumentViewBase::~AccessibleDocumentViewBase (void)
111 {
112     // At this place we should be disposed.  You may want to add a
113     // corresponding assertion into the destructor of a derived class.
114 }
115 
116 
117 
118 
119 void AccessibleDocumentViewBase::Init (void)
120 {
121     // Finish the initialization of the shape tree info container.
122     maShapeTreeInfo.SetDocumentWindow (this);
123 
124     // Register as window listener to stay up to date with its size and
125     // position.
126     mxWindow->addWindowListener (this);
127     // Register as focus listener to
128     mxWindow->addFocusListener (this);
129 
130     // Determine the list of shapes on the current page.
131     uno::Reference<drawing::XShapes> xShapeList;
132     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
133     if (xView.is())
134         xShapeList = uno::Reference<drawing::XShapes> (
135             xView->getCurrentPage(), uno::UNO_QUERY);
136 
137     // Register this object as dispose event listener at the model.
138 	if (mxModel.is())
139 		mxModel->addEventListener (
140             static_cast<awt::XWindowListener*>(this));
141 
142     // Register as property change listener at the controller.
143     uno::Reference<beans::XPropertySet> xSet (mxController, uno::UNO_QUERY);
144     if (xSet.is())
145         xSet->addPropertyChangeListener (
146             OUString (RTL_CONSTASCII_USTRINGPARAM("")),
147             static_cast<beans::XPropertyChangeListener*>(this));
148 
149     // Register this object as dispose event listener at the controller.
150     if (mxController.is())
151         mxController->addEventListener (
152             static_cast<awt::XWindowListener*>(this));
153 
154     // Register at VCL Window to be informed of activated and deactivated
155     // OLE objects.
156     Window* pWindow = maShapeTreeInfo.GetWindow();
157     if (pWindow != NULL)
158     {
159         maWindowLink = LINK(
160             this, AccessibleDocumentViewBase, WindowChildEventListener);
161 
162         pWindow->AddChildEventListener (maWindowLink);
163 
164         sal_uInt16 nCount = pWindow->GetChildCount();
165         for (sal_uInt16 i=0; i<nCount; i++)
166         {
167             Window* pChildWindow = pWindow->GetChild (i);
168             if (pChildWindow &&
169                 (AccessibleRole::EMBEDDED_OBJECT
170                     ==pChildWindow->GetAccessibleRole()))
171             {
172                 SetAccessibleOLEObject (pChildWindow->GetAccessible());
173             }
174         }
175     }
176 //IAccessibility2 Implementation 2009-----
177 	SfxObjectShell* pObjShell = mpViewShell->GetViewFrame()->GetObjectShell();
178 	if(!pObjShell->IsReadOnly())
179 		SetState(AccessibleStateType::EDITABLE);
180 //-----IAccessibility2 Implementation 2009
181 }
182 
183 
184 
185 
186 IMPL_LINK(AccessibleDocumentViewBase, WindowChildEventListener,
187     VclSimpleEvent*, pEvent)
188 {
189     OSL_ASSERT(pEvent!=NULL && pEvent->ISA(VclWindowEvent));
190     if (pEvent!=NULL && pEvent->ISA(VclWindowEvent))
191     {
192         VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent);
193         //      DBG_ASSERT( pVclEvent->GetWindow(), "Window???" );
194         switch (pWindowEvent->GetId())
195         {
196             case VCLEVENT_OBJECT_DYING:
197             {
198                 // Window is dying.  Unregister from VCL Window.
199                 // This is also attempted in the disposing() method.
200                 Window* pWindow = maShapeTreeInfo.GetWindow();
201                 Window* pDyingWindow = static_cast<Window*>(
202                     pWindowEvent->GetWindow());
203                 if (pWindow==pDyingWindow && pWindow!=NULL && maWindowLink.IsSet())
204                 {
205                     pWindow->RemoveChildEventListener (maWindowLink);
206                     maWindowLink = Link();
207                 }
208             }
209             break;
210 
211             case VCLEVENT_WINDOW_SHOW:
212             {
213                 // A new window has been created.  Is it an OLE object?
214                 Window* pChildWindow = static_cast<Window*>(
215                     pWindowEvent->GetData());
216                 if (pChildWindow!=NULL
217                     && (pChildWindow->GetAccessibleRole()
218                         == AccessibleRole::EMBEDDED_OBJECT))
219                 {
220                     SetAccessibleOLEObject (pChildWindow->GetAccessible());
221                 }
222             }
223             break;
224 
225             case VCLEVENT_WINDOW_HIDE:
226             {
227                 // A window has been destroyed.  Has that been an OLE
228                 // object?
229                 Window* pChildWindow = static_cast<Window*>(
230                     pWindowEvent->GetData());
231                 if (pChildWindow!=NULL
232                     && (pChildWindow->GetAccessibleRole()
233                         == AccessibleRole::EMBEDDED_OBJECT))
234                 {
235                     SetAccessibleOLEObject (NULL);
236                 }
237             }
238             break;
239         }
240     }
241 
242     return 0;
243 }
244 
245 
246 
247 
248 //=====  IAccessibleViewForwarderListener  ====================================
249 
250 void AccessibleDocumentViewBase::ViewForwarderChanged(ChangeType, const IAccessibleViewForwarder* )
251 {
252     // Empty
253 }
254 
255 
256 
257 
258 //=====  XAccessibleContext  ==================================================
259 
260 Reference<XAccessible> SAL_CALL
261    	AccessibleDocumentViewBase::getAccessibleParent (void)
262     throw (uno::RuntimeException)
263 {
264     ThrowIfDisposed ();
265 
266     return AccessibleContextBase::getAccessibleParent();
267 }
268 
269 
270 
271 sal_Int32 SAL_CALL
272     AccessibleDocumentViewBase::getAccessibleChildCount (void)
273     throw (uno::RuntimeException)
274 {
275     ThrowIfDisposed ();
276 
277     if (mxAccessibleOLEObject.is())
278         return 1;
279     else
280         return 0;
281 }
282 
283 
284 
285 
286 Reference<XAccessible> SAL_CALL
287     AccessibleDocumentViewBase::getAccessibleChild (sal_Int32 nIndex)
288     throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
289 {
290     ThrowIfDisposed ();
291 
292     ::osl::MutexGuard aGuard (maMutex);
293     if (mxAccessibleOLEObject.is())
294         if (nIndex == 0)
295             return mxAccessibleOLEObject;
296 
297     throw lang::IndexOutOfBoundsException (
298         ::rtl::OUString::createFromAscii ("no child with index ")
299         + rtl::OUString::valueOf(nIndex),
300 		NULL);
301 }
302 
303 
304 
305 
306 //=====  XAccessibleComponent  ================================================
307 
308 /** Iterate over all children and test whether the specified point lies
309     within one of their bounding boxes.  Return the first child for which
310     this is true.
311 */
312 uno::Reference<XAccessible > SAL_CALL
313     AccessibleDocumentViewBase::getAccessibleAtPoint (
314         const awt::Point& aPoint)
315     throw (uno::RuntimeException)
316 {
317     ThrowIfDisposed ();
318 
319     ::osl::MutexGuard aGuard (maMutex);
320     uno::Reference<XAccessible> xChildAtPosition;
321 
322     sal_Int32 nChildCount = getAccessibleChildCount ();
323     for (sal_Int32 i=nChildCount-1; i>=0; --i)
324     {
325         Reference<XAccessible> xChild (getAccessibleChild (i));
326         if (xChild.is())
327         {
328             Reference<XAccessibleComponent> xChildComponent (
329                 xChild->getAccessibleContext(), uno::UNO_QUERY);
330             if (xChildComponent.is())
331             {
332                 awt::Rectangle aBBox (xChildComponent->getBounds());
333                 if ( (aPoint.X >= aBBox.X)
334                     && (aPoint.Y >= aBBox.Y)
335                     && (aPoint.X < aBBox.X+aBBox.Width)
336                     && (aPoint.Y < aBBox.Y+aBBox.Height) )
337                 {
338                     xChildAtPosition = xChild;
339                     break;
340                 }
341             }
342         }
343     }
344 
345     // Have not found a child under the given point.  Returning empty
346     // reference to indicate this.
347     return xChildAtPosition;
348 }
349 
350 
351 
352 
353 awt::Rectangle SAL_CALL
354     AccessibleDocumentViewBase::getBounds (void)
355     throw (::com::sun::star::uno::RuntimeException)
356 {
357     ThrowIfDisposed ();
358 
359     // Transform visible area into screen coordinates.
360     ::Rectangle aVisibleArea (
361         maShapeTreeInfo.GetViewForwarder()->GetVisibleArea());
362     ::Point aPixelTopLeft (
363         maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
364             aVisibleArea.TopLeft()));
365     ::Point aPixelSize (
366         maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
367             aVisibleArea.BottomRight())
368         - aPixelTopLeft);
369 
370     // Prepare to subtract the parent position to transform into relative
371     // coordinates.
372     awt::Point aParentPosition;
373     Reference<XAccessible> xParent = getAccessibleParent ();
374     if (xParent.is())
375     {
376         Reference<XAccessibleComponent> xParentComponent (
377             xParent->getAccessibleContext(), uno::UNO_QUERY);
378         if (xParentComponent.is())
379             aParentPosition = xParentComponent->getLocationOnScreen();
380     }
381 
382     return awt::Rectangle (
383         aPixelTopLeft.X() - aParentPosition.X,
384         aPixelTopLeft.Y() - aParentPosition.Y,
385         aPixelSize.X(),
386         aPixelSize.Y());
387 }
388 
389 
390 
391 
392 awt::Point SAL_CALL
393     AccessibleDocumentViewBase::getLocation (void)
394     throw (uno::RuntimeException)
395 {
396     ThrowIfDisposed ();
397     awt::Rectangle aBoundingBox (getBounds());
398     return awt::Point (aBoundingBox.X, aBoundingBox.Y);
399 }
400 
401 
402 
403 
404 awt::Point SAL_CALL
405     AccessibleDocumentViewBase::getLocationOnScreen (void)
406     throw (uno::RuntimeException)
407 {
408     ThrowIfDisposed ();
409     ::Point aLogicalPoint (maShapeTreeInfo.GetViewForwarder()->GetVisibleArea().TopLeft());
410     ::Point aPixelPoint (maShapeTreeInfo.GetViewForwarder()->LogicToPixel (aLogicalPoint));
411     return awt::Point (aPixelPoint.X(), aPixelPoint.Y());
412 }
413 
414 
415 
416 
417 awt::Size SAL_CALL
418     AccessibleDocumentViewBase::getSize (void)
419     throw (uno::RuntimeException)
420 {
421     ThrowIfDisposed ();
422 
423     // Transform visible area into screen coordinates.
424     ::Rectangle aVisibleArea (
425         maShapeTreeInfo.GetViewForwarder()->GetVisibleArea());
426     ::Point aPixelTopLeft (
427         maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
428             aVisibleArea.TopLeft()));
429     ::Point aPixelSize (
430         maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
431             aVisibleArea.BottomRight())
432         - aPixelTopLeft);
433 
434     return awt::Size (aPixelSize.X(), aPixelSize.Y());
435 }
436 
437 
438 
439 
440 //=====  XInterface  ==========================================================
441 
442 uno::Any SAL_CALL
443     AccessibleDocumentViewBase::queryInterface (const uno::Type & rType)
444     throw (uno::RuntimeException)
445 {
446     uno::Any aReturn = AccessibleContextBase::queryInterface (rType);
447     if ( ! aReturn.hasValue())
448         aReturn = ::cppu::queryInterface (rType,
449             static_cast<XAccessibleComponent*>(this),
450             static_cast<XAccessibleSelection*>(this),
451             static_cast<lang::XEventListener*>(
452                 static_cast<awt::XWindowListener*>(this)),
453             static_cast<beans::XPropertyChangeListener*>(this),
454             static_cast<awt::XWindowListener*>(this),
455             static_cast<awt::XFocusListener*>(this)
456 //IAccessibility2 Implementation 2009-----
457 		   ,static_cast<XAccessibleExtendedAttributes*>(this)
458 		   ,static_cast<XAccessibleGetAccFlowTo*>(this)
459 //-----IAccessibility2 Implementation 2009
460             );
461     return aReturn;
462 }
463 
464 
465 
466 
467 void SAL_CALL
468     AccessibleDocumentViewBase::acquire (void)
469     throw ()
470 {
471     AccessibleContextBase::acquire ();
472 }
473 
474 
475 
476 
477 void SAL_CALL
478     AccessibleDocumentViewBase::release (void)
479     throw ()
480 {
481     AccessibleContextBase::release ();
482 }
483 
484 
485 
486 
487 //=====  XServiceInfo  ========================================================
488 
489 ::rtl::OUString SAL_CALL
490     AccessibleDocumentViewBase::getImplementationName (void)
491     throw (::com::sun::star::uno::RuntimeException)
492 {
493 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleDocumentViewBase"));
494 }
495 
496 
497 
498 
499 ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
500     AccessibleDocumentViewBase::getSupportedServiceNames (void)
501     throw (::com::sun::star::uno::RuntimeException)
502 {
503     ThrowIfDisposed ();
504     return AccessibleContextBase::getSupportedServiceNames ();
505 }
506 
507 
508 
509 
510 
511 //=====  XTypeProvider  =======================================================
512 
513 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL
514     AccessibleDocumentViewBase::getTypes (void)
515     throw (::com::sun::star::uno::RuntimeException)
516 {
517     ThrowIfDisposed ();
518 
519     // Get list of types from the context base implementation, ...
520 	uno::Sequence<uno::Type> aTypeList (AccessibleContextBase::getTypes());
521     // ... get list of types from component base implementation, ...
522 	uno::Sequence<uno::Type> aComponentTypeList (AccessibleComponentBase::getTypes());
523 
524 
525     // ...and add the additional type for the component, ...
526     const uno::Type aLangEventListenerType =
527      	::getCppuType((const uno::Reference<lang::XEventListener>*)0);
528     const uno::Type aPropertyChangeListenerType =
529      	::getCppuType((const uno::Reference<beans::XPropertyChangeListener>*)0);
530     const uno::Type aWindowListenerType =
531      	::getCppuType((const uno::Reference<awt::XWindowListener>*)0);
532     const uno::Type aFocusListenerType =
533      	::getCppuType((const uno::Reference<awt::XFocusListener>*)0);
534     const uno::Type aEventBroadcaster =
535      	::getCppuType((const uno::Reference<XAccessibleEventBroadcaster>*)0);
536 
537     // ... and merge them all into one list.
538     sal_Int32 nTypeCount (aTypeList.getLength()),
539         nComponentTypeCount (aComponentTypeList.getLength()),
540         i;
541 
542     aTypeList.realloc (nTypeCount + nComponentTypeCount + 5);
543 
544     for (i=0; i<nComponentTypeCount; i++)
545         aTypeList[nTypeCount + i] = aComponentTypeList[i];
546 
547     aTypeList[nTypeCount + i++ ] = aLangEventListenerType;
548     aTypeList[nTypeCount + i++] = aPropertyChangeListenerType;
549     aTypeList[nTypeCount + i++] = aWindowListenerType;
550     aTypeList[nTypeCount + i++] = aFocusListenerType;
551     aTypeList[nTypeCount + i++] = aEventBroadcaster;
552 
553 	return aTypeList;
554 }
555 
556 
557 
558 
559 void AccessibleDocumentViewBase::impl_dispose()
560 {
561     // Unregister from VCL Window.
562     Window* pWindow = maShapeTreeInfo.GetWindow();
563     if (maWindowLink.IsSet())
564     {
565         if (pWindow)
566             pWindow->RemoveChildEventListener (maWindowLink);
567         maWindowLink = Link();
568     }
569     else
570     {
571         DBG_ASSERT (pWindow, "AccessibleDocumentViewBase::disposing");
572     }
573 
574     // Unregister from window.
575     if (mxWindow.is())
576     {
577         mxWindow->removeWindowListener (this);
578         mxWindow->removeFocusListener (this);
579         mxWindow = NULL;
580     }
581 
582     // Unregister form the model.
583     if (mxModel.is())
584         mxModel->removeEventListener (
585             static_cast<awt::XWindowListener*>(this));
586 
587     // Unregister from the controller.
588     if (mxController.is())
589     {
590         uno::Reference<beans::XPropertySet> xSet (mxController, uno::UNO_QUERY);
591         if (xSet.is())
592             xSet->removePropertyChangeListener (
593                 OUString (RTL_CONSTASCII_USTRINGPARAM("")),
594                 static_cast<beans::XPropertyChangeListener*>(this));
595 
596         mxController->removeEventListener (
597             static_cast<awt::XWindowListener*>(this));
598     }
599 
600     // Propagate change of controller down the shape tree.
601     maShapeTreeInfo.SetControllerBroadcaster (NULL);
602 
603     // Reset the model reference.
604     mxModel = NULL;
605     // Reset the model reference.
606     mxController = NULL;
607 
608     maShapeTreeInfo.SetDocumentWindow (NULL);
609 }
610 
611 
612 
613 
614 //=====  XEventListener  ======================================================
615 
616 void SAL_CALL
617     AccessibleDocumentViewBase::disposing (const lang::EventObject& rEventObject)
618     throw (::com::sun::star::uno::RuntimeException)
619 {
620     ThrowIfDisposed ();
621 
622     // Register this object as dispose event and document::XEventListener
623     // listener at the model.
624 
625     if ( ! rEventObject.Source.is())
626     {
627         // Paranoia. Can this really happen?
628     }
629     else if (rEventObject.Source == mxModel || rEventObject.Source == mxController)
630     {
631         impl_dispose();
632     }
633 }
634 
635 //=====  XPropertyChangeListener  =============================================
636 
637 void SAL_CALL AccessibleDocumentViewBase::propertyChange (const beans::PropertyChangeEvent& )
638     throw (::com::sun::star::uno::RuntimeException)
639 {
640     // Empty
641 }
642 
643 
644 
645 
646 //=====  XWindowListener  =====================================================
647 
648 void SAL_CALL
649     AccessibleDocumentViewBase::windowResized (const ::com::sun::star::awt::WindowEvent& )
650     throw (::com::sun::star::uno::RuntimeException)
651 {
652     if( IsDisposed() )
653         return;
654 
655     ViewForwarderChanged (
656         IAccessibleViewForwarderListener::VISIBLE_AREA,
657         &maViewForwarder);
658 }
659 
660 
661 
662 
663 void SAL_CALL
664     AccessibleDocumentViewBase::windowMoved (const ::com::sun::star::awt::WindowEvent& )
665     throw (::com::sun::star::uno::RuntimeException)
666 {
667     if( IsDisposed() )
668         return;
669 
670     ViewForwarderChanged (
671         IAccessibleViewForwarderListener::VISIBLE_AREA,
672         &maViewForwarder);
673 }
674 
675 
676 
677 
678 void SAL_CALL
679     AccessibleDocumentViewBase::windowShown (const ::com::sun::star::lang::EventObject& )
680     throw (::com::sun::star::uno::RuntimeException)
681 {
682     if( IsDisposed() )
683         return;
684 
685     ViewForwarderChanged (
686         IAccessibleViewForwarderListener::VISIBLE_AREA,
687         &maViewForwarder);
688 }
689 
690 
691 
692 
693 void SAL_CALL
694     AccessibleDocumentViewBase::windowHidden (const ::com::sun::star::lang::EventObject& )
695     throw (::com::sun::star::uno::RuntimeException)
696 {
697     if( IsDisposed() )
698         return;
699 
700     ViewForwarderChanged (
701         IAccessibleViewForwarderListener::VISIBLE_AREA,
702         &maViewForwarder);
703 }
704 
705 
706 
707 
708 //=====  XFocusListener  ==================================================
709 
710 void AccessibleDocumentViewBase::focusGained (const ::com::sun::star::awt::FocusEvent& e)
711     throw (::com::sun::star::uno::RuntimeException)
712 {
713     ThrowIfDisposed ();
714     if (e.Source == mxWindow)
715         Activated ();
716 }
717 
718 void AccessibleDocumentViewBase::focusLost (const ::com::sun::star::awt::FocusEvent& e)
719     throw (::com::sun::star::uno::RuntimeException)
720 {
721     ThrowIfDisposed ();
722     if (e.Source == mxWindow)
723         Deactivated ();
724 }
725 
726 
727 
728 
729 //=====  protected internal  ==================================================
730 
731 // This method is called from the component helper base class while disposing.
732 void SAL_CALL AccessibleDocumentViewBase::disposing (void)
733 {
734     impl_dispose();
735 
736     AccessibleContextBase::disposing ();
737 }
738 
739 
740 
741 
742 ///	Create a name for this view.
743 ::rtl::OUString
744     AccessibleDocumentViewBase::CreateAccessibleName (void)
745     throw (::com::sun::star::uno::RuntimeException)
746 {
747 	return ::rtl::OUString (
748         RTL_CONSTASCII_USTRINGPARAM("AccessibleDocumentViewBase"));
749 }
750 
751 
752 
753 
754 /** Create a description for this view.  Use the model's description or URL
755     if a description is not available.
756 */
757 ::rtl::OUString
758     AccessibleDocumentViewBase::CreateAccessibleDescription (void)
759     throw (::com::sun::star::uno::RuntimeException)
760 {
761 	rtl::OUString sDescription;
762 
763     uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
764     if (xInfo.is())
765     {
766         OUString sFirstService = xInfo->getSupportedServiceNames()[0];
767         if (sFirstService == OUString (
768                 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocumentDrawView")))
769         {
770             sDescription = OUString (RTL_CONSTASCII_USTRINGPARAM("Draw Document"));
771         }
772         else
773             sDescription = sFirstService;
774     }
775     else
776         sDescription = OUString (
777             RTL_CONSTASCII_USTRINGPARAM("Accessible Draw Document"));
778 	return sDescription;
779 }
780 
781 
782 
783 
784 void AccessibleDocumentViewBase::Activated (void)
785 {
786     // Empty.  Overwrite to do something usefull.
787 }
788 
789 
790 
791 
792 void AccessibleDocumentViewBase::Deactivated (void)
793 {
794     // Empty.  Overwrite to do something usefull.
795 }
796 
797 
798 
799 
800 void AccessibleDocumentViewBase::SetAccessibleOLEObject (
801     const Reference <XAccessible>& xOLEObject)
802 {
803     // Send child event about removed accessible OLE object if necessary.
804     if (mxAccessibleOLEObject != xOLEObject)
805         if (mxAccessibleOLEObject.is())
806             CommitChange (
807                 AccessibleEventId::CHILD,
808                 uno::Any(),
809                 uno::makeAny (mxAccessibleOLEObject));
810 
811     // Assume that the accessible OLE Object disposes itself correctly.
812 
813     {
814         ::osl::MutexGuard aGuard (maMutex);
815         mxAccessibleOLEObject = xOLEObject;
816     }
817 
818     // Send child event about new accessible OLE object if necessary.
819     if (mxAccessibleOLEObject.is())
820         CommitChange (
821             AccessibleEventId::CHILD,
822             uno::makeAny (mxAccessibleOLEObject),
823             uno::Any());
824 }
825 
826 
827 
828 
829 //=====  methods from AccessibleSelectionBase ==================================================
830 
831 // return the member maMutex;
832 ::osl::Mutex&
833     AccessibleDocumentViewBase::implGetMutex()
834 {
835     return( maMutex );
836 }
837 
838 // return ourself as context in default case
839 uno::Reference< XAccessibleContext >
840     AccessibleDocumentViewBase::implGetAccessibleContext()
841     throw (uno::RuntimeException)
842 {
843     return( this );
844 }
845 
846 // return sal_False in default case
847 sal_Bool
848     AccessibleDocumentViewBase::implIsSelected( sal_Int32 )
849     throw (uno::RuntimeException)
850 {
851     return( sal_False );
852 }
853 
854 // return nothing in default case
855 void
856     AccessibleDocumentViewBase::implSelect( sal_Int32, sal_Bool )
857     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
858 {
859 }
860 
861 //IAccessibility2 Implementation 2009-----
862 uno::Any SAL_CALL AccessibleDocumentViewBase::getExtendedAttributes()
863 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
864 {
865 	uno::Any anyAtrribute;
866 	rtl::OUString sValue;
867 	if (mpViewShell && mpViewShell->ISA(::sd::DrawViewShell))
868 	{
869 		::sd::DrawViewShell* pDrViewSh = (::sd::DrawViewShell*) mpViewShell;
870 		rtl::OUString sName;
871 		String sDisplay;
872 			sName = rtl::OUString::createFromAscii("page-name:");
873 			// MT IA2: Not used...
874 			// SdPage*	pCurrPge = pDrViewSh->getCurrentPage();
875 			SdDrawDocument* pDoc = pDrViewSh->GetDoc();
876 			sDisplay = pDrViewSh->getCurrentPage()->GetName();
877 			sDisplay.SearchAndReplace( String::CreateFromAscii( "\\" ), String::CreateFromAscii("\\\\" ));
878 			sDisplay.SearchAndReplace( String::CreateFromAscii( "=" ), String::CreateFromAscii("\\=" ) );
879 			sDisplay.SearchAndReplace( String::CreateFromAscii( ";" ), String::CreateFromAscii("\\;" ) );
880 			sDisplay.SearchAndReplace( String::CreateFromAscii( "," ), String::CreateFromAscii("\\," ) );
881 			sDisplay.SearchAndReplace( String::CreateFromAscii( ":" ), String::CreateFromAscii("\\:" ) );
882 			sValue = sName + sDisplay ;
883 			sName = rtl::OUString::createFromAscii(";page-number:");
884 			sValue += sName;
885 			sValue += String::CreateFromInt32((sal_Int16)((sal_uInt16)((pDrViewSh->getCurrentPage()->GetPageNum()-1)>>1) + 1)) ;
886 			sName = rtl::OUString::createFromAscii(";total-pages:");
887 			sValue += sName;
888 			sValue += String::CreateFromInt32(pDrViewSh->GetPageTabControl()->GetPageCount()) ;
889 			sValue +=  rtl::OUString::createFromAscii(";");
890 		if(pDrViewSh->IsLayerModeActive() )
891 		{
892 			sName = rtl::OUString::createFromAscii("page-name:");
893 			sValue = sName;
894 			sDisplay = pDrViewSh->GetLayerTabControl()->GetPageText(pDrViewSh->GetLayerTabControl()->GetCurPageId());
895 			if( pDoc )
896 			{
897 				SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
898 				SdrLayer* aSdrLayer = rLayerAdmin.GetLayer(sDisplay, sal_False);
899 				if( aSdrLayer )
900 				{
901 					String layerAltText = aSdrLayer->GetTitle();
902 					if(  layerAltText.Len() > 0)
903 					{
904 						sName = rtl::OUString::createFromAscii(" ");
905 						sDisplay = sDisplay + sName;
906 						sDisplay += layerAltText;
907 					}
908 				}
909 			}
910 			sDisplay.SearchAndReplace( String::CreateFromAscii( "\\" ), String::CreateFromAscii("\\\\" ));
911 			sDisplay.SearchAndReplace( String::CreateFromAscii( "=" ), String::CreateFromAscii("\\=" ));
912 			sDisplay.SearchAndReplace( String::CreateFromAscii( ";" ), String::CreateFromAscii("\\;" ));
913 			sDisplay.SearchAndReplace( String::CreateFromAscii( "," ), String::CreateFromAscii("\\," ));
914 			sDisplay.SearchAndReplace( String::CreateFromAscii( ":" ), String::CreateFromAscii("\\:" ));
915 			sValue +=  sDisplay;
916 			sName = rtl::OUString::createFromAscii(";page-number:");
917 			sValue += sName;
918 			sValue += String::CreateFromInt32(pDrViewSh->GetActiveTabLayerIndex()+1) ;
919 			sName = rtl::OUString::createFromAscii(";total-pages:");
920 			sValue += sName;
921 			sValue += String::CreateFromInt32(pDrViewSh->GetLayerTabControl()->GetPageCount()) ;
922 			sValue +=  rtl::OUString::createFromAscii(";");
923 		}
924 	}
925 	if (mpViewShell && mpViewShell->ISA(::sd::PresentationViewShell))
926 	{
927 		::sd::PresentationViewShell* pPresViewSh = (::sd::PresentationViewShell*) mpViewShell;
928 		SdPage*	pCurrPge = pPresViewSh->getCurrentPage();
929 		SdDrawDocument* pDoc = pPresViewSh->GetDoc();
930 		SdPage*	pNotesPge = (SdPage*)pDoc->GetSdPage((pCurrPge->GetPageNum()-1)>>1, PK_NOTES);
931 		if (pNotesPge)
932 		{
933 			SdrObject* pNotesObj = pNotesPge->GetPresObj(PRESOBJ_NOTES);
934 			if (pNotesObj)
935 			{
936 				OutlinerParaObject* pPara = pNotesObj->GetOutlinerParaObject();
937 				if (pPara)
938 				{
939 					sValue += rtl::OUString::createFromAscii("note:");
940 					const EditTextObject& rEdit = pPara->GetTextObject();
941 					for (sal_uInt16 i=0;i<rEdit.GetParagraphCount();i++)
942 					{
943 						String strNote = rEdit.GetText(i);
944 						strNote.SearchAndReplace( String::CreateFromAscii( "\\" ), String::CreateFromAscii("\\\\" ));
945 						strNote.SearchAndReplace( String::CreateFromAscii( "=" ), String::CreateFromAscii("\\=" ));
946 						strNote.SearchAndReplace( String::CreateFromAscii( ";" ), String::CreateFromAscii("\\;" ));
947 						strNote.SearchAndReplace( String::CreateFromAscii( "," ), String::CreateFromAscii("\\," ));
948 						strNote.SearchAndReplace( String::CreateFromAscii( ":" ), String::CreateFromAscii("\\:" ));
949 						sValue += rtl::OUString( strNote );
950 						sValue += rtl::OUString::createFromAscii(";");//to divide each paragraph
951 					}
952 				}
953 			}
954 		}
955 	}
956 	if (mpViewShell && mpViewShell->ISA(::sd::OutlineViewShell) )
957 	{
958 		rtl::OUString sName;
959 		String sDisplay;
960 		SdPage*	pCurrPge = mpViewShell->GetActualPage();
961 		SdDrawDocument* pDoc = mpViewShell->GetDoc();
962 		if(pCurrPge && pDoc)
963 		{
964 			sName = rtl::OUString::createFromAscii("page-name:");
965 			sDisplay = pCurrPge->GetName();
966 			sDisplay.SearchAndReplace( String::CreateFromAscii( "=" ), String::CreateFromAscii("\\=" ) );
967 			sDisplay.SearchAndReplace( String::CreateFromAscii( ";" ), String::CreateFromAscii("\\;" ) );
968 			sDisplay.SearchAndReplace( String::CreateFromAscii( "," ), String::CreateFromAscii("\\," ) );
969 			sDisplay.SearchAndReplace( String::CreateFromAscii( ":" ), String::CreateFromAscii("\\:" ) );
970 			sValue = sName + sDisplay ;
971 			sName = rtl::OUString::createFromAscii(";page-number:");
972 			sValue += sName;
973 			sValue += String::CreateFromInt32((sal_Int16)((sal_uInt16)((pCurrPge->GetPageNum()-1)>>1) + 1)) ;
974 			sName = rtl::OUString::createFromAscii(";total-pages:");
975 			sValue += sName;
976 			sValue += String::CreateFromInt32(pDoc->GetSdPageCount(PK_STANDARD)) ;
977 			sValue +=  rtl::OUString::createFromAscii(";");
978 		}
979 	}
980 	if (sValue.getLength())
981 		anyAtrribute <<= sValue;
982 	return anyAtrribute;
983 }
984 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
985 		SAL_CALL AccessibleDocumentViewBase::get_AccFlowTo(const ::com::sun::star::uno::Any&, sal_Int32 )
986 		throw ( ::com::sun::star::uno::RuntimeException )
987 {
988 	::com::sun::star::uno::Sequence< uno::Any> aRet;
989 
990 	return aRet;
991 }
992 
993 sal_Int32 SAL_CALL AccessibleDocumentViewBase::getForeground(  )
994         throw (uno::RuntimeException)
995 {
996     return COL_BLACK;
997 }
998 
999 sal_Int32 SAL_CALL AccessibleDocumentViewBase::getBackground(  )
1000         throw (uno::RuntimeException)
1001 {
1002 	 ThrowIfDisposed ();
1003     ::osl::MutexGuard aGuard (maMutex);
1004     return mpViewShell->GetView()->getColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor;
1005 }
1006 //-----IAccessibility2 Implementation 2009
1007 } // end of namespace accessibility
1008