xref: /trunk/main/sc/source/ui/Accessibility/AccessibleContextBase.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "AccessibleContextBase.hxx"
33*cdf0e10cSrcweir #include "unoguard.hxx"
34*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
37*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
40*cdf0e10cSrcweir #include <rtl/uuid.h>
41*cdf0e10cSrcweir #include <tools/debug.hxx>
42*cdf0e10cSrcweir #include <tools/gen.hxx>
43*cdf0e10cSrcweir #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX
44*cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
47*cdf0e10cSrcweir #include <svl/smplhint.hxx>
48*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
49*cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
50*cdf0e10cSrcweir #include <vcl/unohelp.hxx>
51*cdf0e10cSrcweir #include <tools/color.hxx>
52*cdf0e10cSrcweir #include <comphelper/accessibleeventnotifier.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using namespace ::rtl;
55*cdf0e10cSrcweir using namespace ::com::sun::star;
56*cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //=====  internal  ============================================================
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir DBG_NAME(ScAccessibleContextBase)
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir ScAccessibleContextBase::ScAccessibleContextBase(
63*cdf0e10cSrcweir                                                  const uno::Reference<XAccessible>& rxParent,
64*cdf0e10cSrcweir                                                  const sal_Int16 aRole)
65*cdf0e10cSrcweir                                                  :
66*cdf0e10cSrcweir     ScAccessibleContextBaseWeakImpl(m_aMutex),
67*cdf0e10cSrcweir     mxParent(rxParent),
68*cdf0e10cSrcweir     mnClientId(0),
69*cdf0e10cSrcweir     maRole(aRole)
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     DBG_CTOR(ScAccessibleContextBase, NULL);
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir ScAccessibleContextBase::~ScAccessibleContextBase(void)
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     DBG_DTOR(ScAccessibleContextBase, NULL);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     if (!IsDefunc() && !rBHelper.bInDispose)
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         // increment refcount to prevent double call off dtor
82*cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
83*cdf0e10cSrcweir         // call dispose to inform object wich have a weak reference to this object
84*cdf0e10cSrcweir         dispose();
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir void ScAccessibleContextBase::Init()
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir     // hold reference to make sure that the destructor is not called
91*cdf0e10cSrcweir     uno::Reference< XAccessibleContext > xOwnContext(this);
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     if (mxParent.is())
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir         uno::Reference< XAccessibleEventBroadcaster > xBroadcaster (mxParent->getAccessibleContext(), uno::UNO_QUERY);
96*cdf0e10cSrcweir         if (xBroadcaster.is())
97*cdf0e10cSrcweir             xBroadcaster->addEventListener(this);
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir     msName = createAccessibleName();
100*cdf0e10cSrcweir     msDescription = createAccessibleDescription();
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir void SAL_CALL ScAccessibleContextBase::disposing()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     ScUnoGuard aGuard;
106*cdf0e10cSrcweir //  CommitDefunc(); not necessary and should not be send, because it cost a lot of time
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     // hold reference to make sure that the destructor is not called
109*cdf0e10cSrcweir     uno::Reference< XAccessibleContext > xOwnContext(this);
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     if ( mnClientId )
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir         sal_Int32 nTemClientId(mnClientId);
114*cdf0e10cSrcweir         mnClientId =  0;
115*cdf0e10cSrcweir         comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nTemClientId, *this );
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     if (mxParent.is())
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         uno::Reference< XAccessibleEventBroadcaster > xBroadcaster (mxParent->getAccessibleContext(), uno::UNO_QUERY);
121*cdf0e10cSrcweir         if (xBroadcaster.is())
122*cdf0e10cSrcweir             xBroadcaster->removeEventListener(this);
123*cdf0e10cSrcweir         mxParent = NULL;
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     ScAccessibleContextBaseWeakImpl::disposing();
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir //=====  XInterface  =====================================================
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir uno::Any SAL_CALL ScAccessibleContextBase::queryInterface( uno::Type const & rType )
132*cdf0e10cSrcweir     throw (uno::RuntimeException)
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     uno::Any aAny (ScAccessibleContextBaseWeakImpl::queryInterface(rType));
135*cdf0e10cSrcweir     return aAny.hasValue() ? aAny : ScAccessibleContextBaseImplEvent::queryInterface(rType);
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir void SAL_CALL ScAccessibleContextBase::acquire()
139*cdf0e10cSrcweir     throw ()
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     ScAccessibleContextBaseWeakImpl::acquire();
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir void SAL_CALL ScAccessibleContextBase::release()
145*cdf0e10cSrcweir     throw ()
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     ScAccessibleContextBaseWeakImpl::release();
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir //=====  SfxListener  =====================================================
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir void ScAccessibleContextBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     if (rHint.ISA( SfxSimpleHint ) )
155*cdf0e10cSrcweir     {
156*cdf0e10cSrcweir         const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
157*cdf0e10cSrcweir         if (rRef.GetId() == SFX_HINT_DYING)
158*cdf0e10cSrcweir         {
159*cdf0e10cSrcweir             // it seems the Broadcaster is dying, since the view is dying
160*cdf0e10cSrcweir             dispose();
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //=====  XAccessible  =========================================================
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir uno::Reference< XAccessibleContext> SAL_CALL
168*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleContext(void)
169*cdf0e10cSrcweir     throw (uno::RuntimeException)
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     return this;
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir //=====  XAccessibleComponent  ================================================
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir sal_Bool SAL_CALL ScAccessibleContextBase::containsPoint(const awt::Point& rPoint )
177*cdf0e10cSrcweir         throw (uno::RuntimeException)
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir     ScUnoGuard aGuard;
180*cdf0e10cSrcweir     IsObjectValid();
181*cdf0e10cSrcweir     return Rectangle (Point(), GetBoundingBox().GetSize()).IsInside(VCLPoint(rPoint));
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleContextBase::getAccessibleAtPoint(
185*cdf0e10cSrcweir         const awt::Point& /* rPoint */ )
186*cdf0e10cSrcweir         throw (uno::RuntimeException)
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     DBG_ERROR("not implemented");
189*cdf0e10cSrcweir     return uno::Reference<XAccessible>();
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir awt::Rectangle SAL_CALL ScAccessibleContextBase::getBounds(  )
193*cdf0e10cSrcweir         throw (uno::RuntimeException)
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     ScUnoGuard aGuard;
196*cdf0e10cSrcweir     IsObjectValid();
197*cdf0e10cSrcweir     return AWTRectangle(GetBoundingBox());
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir awt::Point SAL_CALL ScAccessibleContextBase::getLocation(  )
201*cdf0e10cSrcweir         throw (uno::RuntimeException)
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     ScUnoGuard aGuard;
204*cdf0e10cSrcweir     IsObjectValid();
205*cdf0e10cSrcweir     return AWTPoint(GetBoundingBox().TopLeft());
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir awt::Point SAL_CALL ScAccessibleContextBase::getLocationOnScreen(  )
209*cdf0e10cSrcweir         throw (uno::RuntimeException)
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     ScUnoGuard aGuard;
212*cdf0e10cSrcweir     IsObjectValid();
213*cdf0e10cSrcweir     return AWTPoint(GetBoundingBoxOnScreen().TopLeft());
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir awt::Size SAL_CALL ScAccessibleContextBase::getSize(  )
217*cdf0e10cSrcweir         throw (uno::RuntimeException)
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     ScUnoGuard aGuard;
220*cdf0e10cSrcweir     IsObjectValid();
221*cdf0e10cSrcweir     return AWTSize(GetBoundingBox().GetSize());
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir sal_Bool SAL_CALL ScAccessibleContextBase::isShowing(  )
225*cdf0e10cSrcweir         throw (uno::RuntimeException)
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir     ScUnoGuard aGuard;
228*cdf0e10cSrcweir     IsObjectValid();
229*cdf0e10cSrcweir     sal_Bool bShowing(sal_False);
230*cdf0e10cSrcweir     if (mxParent.is())
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         uno::Reference<XAccessibleComponent> xParentComponent (mxParent->getAccessibleContext(), uno::UNO_QUERY);
233*cdf0e10cSrcweir         if (xParentComponent.is())
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir             Rectangle aParentBounds(VCLRectangle(xParentComponent->getBounds()));
236*cdf0e10cSrcweir             Rectangle aBounds(VCLRectangle(getBounds()));
237*cdf0e10cSrcweir             bShowing = aBounds.IsOver(aParentBounds);
238*cdf0e10cSrcweir         }
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir     return bShowing;
241*cdf0e10cSrcweir }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir sal_Bool SAL_CALL ScAccessibleContextBase::isVisible(  )
244*cdf0e10cSrcweir         throw (uno::RuntimeException)
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir     return sal_True;
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir void SAL_CALL ScAccessibleContextBase::grabFocus(  )
250*cdf0e10cSrcweir         throw (uno::RuntimeException)
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir     DBG_ERROR("not implemented");
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessibleContextBase::getForeground(  )
256*cdf0e10cSrcweir         throw (uno::RuntimeException)
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     return COL_BLACK;
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessibleContextBase::getBackground(  )
262*cdf0e10cSrcweir         throw (uno::RuntimeException)
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir     return COL_WHITE;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir //=====  XAccessibleContext  ==================================================
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir sal_Int32 SAL_CALL
270*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleChildCount(void)
271*cdf0e10cSrcweir     throw (uno::RuntimeException)
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir     DBG_ERROR("should be implemented in the abrevated class");
274*cdf0e10cSrcweir     return 0;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir uno::Reference<XAccessible> SAL_CALL
278*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleChild(sal_Int32 /* nIndex */)
279*cdf0e10cSrcweir         throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir     DBG_ERROR("should be implemented in the abrevated class");
282*cdf0e10cSrcweir     return uno::Reference<XAccessible>();
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir uno::Reference<XAccessible> SAL_CALL
286*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleParent(void)
287*cdf0e10cSrcweir     throw (uno::RuntimeException)
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir     return mxParent;
290*cdf0e10cSrcweir }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir sal_Int32 SAL_CALL
293*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleIndexInParent(void)
294*cdf0e10cSrcweir     throw (uno::RuntimeException)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir     ScUnoGuard aGuard;
297*cdf0e10cSrcweir     IsObjectValid();
298*cdf0e10cSrcweir     //  Use a simple but slow solution for now.  Optimize later.
299*cdf0e10cSrcweir    //   Return -1 to indicate that this object's parent does not know about the
300*cdf0e10cSrcweir    //   object.
301*cdf0e10cSrcweir     sal_Int32 nIndex(-1);
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     //  Iterate over all the parent's children and search for this object.
304*cdf0e10cSrcweir     if (mxParent.is())
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         uno::Reference<XAccessibleContext> xParentContext (
307*cdf0e10cSrcweir             mxParent->getAccessibleContext());
308*cdf0e10cSrcweir         if (xParentContext.is())
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
311*cdf0e10cSrcweir             for (sal_Int32 i=0; i<nChildCount; ++i)
312*cdf0e10cSrcweir             {
313*cdf0e10cSrcweir                 uno::Reference<XAccessible> xChild (xParentContext->getAccessibleChild (i));
314*cdf0e10cSrcweir                 if (xChild.is())
315*cdf0e10cSrcweir                 {
316*cdf0e10cSrcweir                     if (xChild.get() == this)
317*cdf0e10cSrcweir                         nIndex = i;
318*cdf0e10cSrcweir                 }
319*cdf0e10cSrcweir             }
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir    }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir    return nIndex;
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir sal_Int16 SAL_CALL
327*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleRole(void)
328*cdf0e10cSrcweir     throw (uno::RuntimeException)
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir     return maRole;
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
334*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleDescription(void)
335*cdf0e10cSrcweir     throw (uno::RuntimeException)
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir     ScUnoGuard aGuard;
338*cdf0e10cSrcweir     IsObjectValid();
339*cdf0e10cSrcweir     if (!msDescription.getLength())
340*cdf0e10cSrcweir     {
341*cdf0e10cSrcweir         OUString sDescription(createAccessibleDescription());
342*cdf0e10cSrcweir //      DBG_ASSERT(sDescription.getLength(), "We should give always a descripition.");
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir         if (msDescription != sDescription)
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             AccessibleEventObject aEvent;
347*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
348*cdf0e10cSrcweir             aEvent.Source = uno::Reference< XAccessibleContext >(this);
349*cdf0e10cSrcweir             aEvent.OldValue <<= msDescription;
350*cdf0e10cSrcweir             aEvent.NewValue <<= sDescription;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir             msDescription = sDescription;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir             CommitChange(aEvent);
355*cdf0e10cSrcweir         }
356*cdf0e10cSrcweir     }
357*cdf0e10cSrcweir     return msDescription;
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir OUString SAL_CALL
361*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleName(void)
362*cdf0e10cSrcweir     throw (uno::RuntimeException)
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir     ScUnoGuard aGuard;
365*cdf0e10cSrcweir     IsObjectValid();
366*cdf0e10cSrcweir     if (!msName.getLength())
367*cdf0e10cSrcweir     {
368*cdf0e10cSrcweir         OUString sName(createAccessibleName());
369*cdf0e10cSrcweir         DBG_ASSERT(sName.getLength(), "We should give always a name.");
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir         if (msName != sName)
372*cdf0e10cSrcweir         {
373*cdf0e10cSrcweir             AccessibleEventObject aEvent;
374*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::NAME_CHANGED;
375*cdf0e10cSrcweir             aEvent.Source = uno::Reference< XAccessibleContext >(this);
376*cdf0e10cSrcweir             aEvent.OldValue <<= msName;
377*cdf0e10cSrcweir             aEvent.NewValue <<= sName;
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir             msName = sName;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir             CommitChange(aEvent);
382*cdf0e10cSrcweir         }
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir     return msName;
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir uno::Reference<XAccessibleRelationSet> SAL_CALL
388*cdf0e10cSrcweir     ScAccessibleContextBase::getAccessibleRelationSet(void)
389*cdf0e10cSrcweir     throw (uno::RuntimeException)
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir     return new utl::AccessibleRelationSetHelper();
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL
395*cdf0e10cSrcweir         ScAccessibleContextBase::getAccessibleStateSet(void)
396*cdf0e10cSrcweir     throw (uno::RuntimeException)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     return uno::Reference<XAccessibleStateSet>();
399*cdf0e10cSrcweir }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir lang::Locale SAL_CALL
402*cdf0e10cSrcweir     ScAccessibleContextBase::getLocale(void)
403*cdf0e10cSrcweir     throw (IllegalAccessibleComponentStateException,
404*cdf0e10cSrcweir         uno::RuntimeException)
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir     ScUnoGuard aGuard;
407*cdf0e10cSrcweir     IsObjectValid();
408*cdf0e10cSrcweir     if (mxParent.is())
409*cdf0e10cSrcweir     {
410*cdf0e10cSrcweir         uno::Reference<XAccessibleContext> xParentContext (
411*cdf0e10cSrcweir             mxParent->getAccessibleContext());
412*cdf0e10cSrcweir         if (xParentContext.is())
413*cdf0e10cSrcweir             return xParentContext->getLocale ();
414*cdf0e10cSrcweir     }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     //  No locale and no parent.  Therefore throw exception to indicate this
417*cdf0e10cSrcweir     //  cluelessness.
418*cdf0e10cSrcweir     throw IllegalAccessibleComponentStateException ();
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir     //=====  XAccessibleEventBroadcaster  =====================================
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir void SAL_CALL
424*cdf0e10cSrcweir     ScAccessibleContextBase::addEventListener(
425*cdf0e10cSrcweir         const uno::Reference<XAccessibleEventListener>& xListener)
426*cdf0e10cSrcweir     throw (uno::RuntimeException)
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir     if (xListener.is())
429*cdf0e10cSrcweir     {
430*cdf0e10cSrcweir         ScUnoGuard aGuard;
431*cdf0e10cSrcweir         IsObjectValid();
432*cdf0e10cSrcweir         if (!IsDefunc())
433*cdf0e10cSrcweir         {
434*cdf0e10cSrcweir             if (!mnClientId)
435*cdf0e10cSrcweir                 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
436*cdf0e10cSrcweir             comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir void SAL_CALL
442*cdf0e10cSrcweir     ScAccessibleContextBase::removeEventListener(
443*cdf0e10cSrcweir         const uno::Reference<XAccessibleEventListener>& xListener)
444*cdf0e10cSrcweir     throw (uno::RuntimeException)
445*cdf0e10cSrcweir {
446*cdf0e10cSrcweir     if (xListener.is())
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir         ScUnoGuard aGuard;
449*cdf0e10cSrcweir         if (!IsDefunc() && mnClientId)
450*cdf0e10cSrcweir         {
451*cdf0e10cSrcweir             sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
452*cdf0e10cSrcweir             if ( !nListenerCount )
453*cdf0e10cSrcweir             {
454*cdf0e10cSrcweir                 // no listeners anymore
455*cdf0e10cSrcweir                 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
456*cdf0e10cSrcweir                 // and at least to us not firing any events anymore, in case somebody calls
457*cdf0e10cSrcweir                 // NotifyAccessibleEvent, again
458*cdf0e10cSrcweir                 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
459*cdf0e10cSrcweir                 mnClientId = 0;
460*cdf0e10cSrcweir             }
461*cdf0e10cSrcweir         }
462*cdf0e10cSrcweir     }
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir     //=====  XAccessibleEventListener  ========================================
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir void SAL_CALL ScAccessibleContextBase::disposing(
468*cdf0e10cSrcweir     const lang::EventObject& rSource )
469*cdf0e10cSrcweir         throw (uno::RuntimeException)
470*cdf0e10cSrcweir {
471*cdf0e10cSrcweir     ScUnoGuard aGuard;
472*cdf0e10cSrcweir     if (rSource.Source == mxParent)
473*cdf0e10cSrcweir         dispose();
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir void SAL_CALL ScAccessibleContextBase::notifyEvent(
477*cdf0e10cSrcweir         const AccessibleEventObject& /* aEvent */ )
478*cdf0e10cSrcweir         throw (uno::RuntimeException)
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir //=====  XServiceInfo  ========================================================
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
485*cdf0e10cSrcweir     ScAccessibleContextBase::getImplementationName(void)
486*cdf0e10cSrcweir     throw (uno::RuntimeException)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir     return OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleContextBase"));
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir sal_Bool SAL_CALL
492*cdf0e10cSrcweir     ScAccessibleContextBase::supportsService(const OUString& sServiceName)
493*cdf0e10cSrcweir     throw (uno::RuntimeException)
494*cdf0e10cSrcweir {
495*cdf0e10cSrcweir     //  Iterate over all supported service names and return true if on of them
496*cdf0e10cSrcweir     //  matches the given name.
497*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString> aSupportedServices (
498*cdf0e10cSrcweir         getSupportedServiceNames ());
499*cdf0e10cSrcweir     sal_Int32 nLength(aSupportedServices.getLength());
500*cdf0e10cSrcweir     const OUString* pServiceNames = aSupportedServices.getConstArray();
501*cdf0e10cSrcweir     for (int i=0; i<nLength; ++i, ++pServiceNames)
502*cdf0e10cSrcweir         if (sServiceName == *pServiceNames)
503*cdf0e10cSrcweir             return sal_True;
504*cdf0e10cSrcweir     return sal_False;
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SAL_CALL
508*cdf0e10cSrcweir     ScAccessibleContextBase::getSupportedServiceNames(void)
509*cdf0e10cSrcweir     throw (uno::RuntimeException)
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir     uno::Sequence<OUString> aServiceNames(2);
512*cdf0e10cSrcweir     OUString* pServiceNames = aServiceNames.getArray();
513*cdf0e10cSrcweir     if (pServiceNames)
514*cdf0e10cSrcweir     {
515*cdf0e10cSrcweir         pServiceNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.accessibility.Accessible"));
516*cdf0e10cSrcweir         pServiceNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.accessibility.AccessibleContext"));
517*cdf0e10cSrcweir     }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir     return aServiceNames;
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir //=====  XTypeProvider  =======================================================
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL ScAccessibleContextBase::getTypes()
525*cdf0e10cSrcweir         throw (uno::RuntimeException)
526*cdf0e10cSrcweir {
527*cdf0e10cSrcweir     return comphelper::concatSequences(ScAccessibleContextBaseWeakImpl::getTypes(), ScAccessibleContextBaseImplEvent::getTypes());
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
531*cdf0e10cSrcweir     ScAccessibleContextBase::getImplementationId(void)
532*cdf0e10cSrcweir     throw (uno::RuntimeException)
533*cdf0e10cSrcweir {
534*cdf0e10cSrcweir     ScUnoGuard aGuard;
535*cdf0e10cSrcweir     IsObjectValid();
536*cdf0e10cSrcweir     static uno::Sequence<sal_Int8> aId;
537*cdf0e10cSrcweir     if (aId.getLength() == 0)
538*cdf0e10cSrcweir     {
539*cdf0e10cSrcweir         aId.realloc (16);
540*cdf0e10cSrcweir         rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
541*cdf0e10cSrcweir     }
542*cdf0e10cSrcweir     return aId;
543*cdf0e10cSrcweir }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir //=====  internal  ============================================================
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
548*cdf0e10cSrcweir     ScAccessibleContextBase::createAccessibleDescription(void)
549*cdf0e10cSrcweir     throw (uno::RuntimeException)
550*cdf0e10cSrcweir {
551*cdf0e10cSrcweir     DBG_ERROR("should be implemented in the abrevated class");
552*cdf0e10cSrcweir     return rtl::OUString();
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
556*cdf0e10cSrcweir     ScAccessibleContextBase::createAccessibleName(void)
557*cdf0e10cSrcweir     throw (uno::RuntimeException)
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir     DBG_ERROR("should be implemented in the abrevated class");
560*cdf0e10cSrcweir     return rtl::OUString();
561*cdf0e10cSrcweir }
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir void ScAccessibleContextBase::CommitChange(const AccessibleEventObject& rEvent) const
564*cdf0e10cSrcweir {
565*cdf0e10cSrcweir     if (mnClientId)
566*cdf0e10cSrcweir         comphelper::AccessibleEventNotifier::addEvent( mnClientId, rEvent );
567*cdf0e10cSrcweir }
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir void ScAccessibleContextBase::ChangeName()
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir     AccessibleEventObject aEvent;
572*cdf0e10cSrcweir     aEvent.EventId = AccessibleEventId::NAME_CHANGED;
573*cdf0e10cSrcweir     aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
574*cdf0e10cSrcweir     aEvent.OldValue <<= msName;
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir     msName = rtl::OUString(); // reset the name so it will be hold again
577*cdf0e10cSrcweir     getAccessibleName(); // create the new name
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir     aEvent.NewValue <<= msName;
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir     CommitChange(aEvent);
582*cdf0e10cSrcweir }
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir void ScAccessibleContextBase::CommitFocusGained() const
585*cdf0e10cSrcweir {
586*cdf0e10cSrcweir     AccessibleEventObject aEvent;
587*cdf0e10cSrcweir     aEvent.EventId = AccessibleEventId::STATE_CHANGED;
588*cdf0e10cSrcweir     aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
589*cdf0e10cSrcweir     aEvent.NewValue <<= AccessibleStateType::FOCUSED;
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     CommitChange(aEvent);
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir     ::vcl::unohelper::NotifyAccessibleStateEventGlobally(aEvent);
594*cdf0e10cSrcweir }
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir void ScAccessibleContextBase::CommitFocusLost() const
597*cdf0e10cSrcweir {
598*cdf0e10cSrcweir     AccessibleEventObject aEvent;
599*cdf0e10cSrcweir     aEvent.EventId = AccessibleEventId::STATE_CHANGED;
600*cdf0e10cSrcweir     aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
601*cdf0e10cSrcweir     aEvent.OldValue <<= AccessibleStateType::FOCUSED;
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     CommitChange(aEvent);
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir     vcl::unohelper::NotifyAccessibleStateEventGlobally(aEvent);
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir Rectangle ScAccessibleContextBase::GetBoundingBoxOnScreen(void) const
609*cdf0e10cSrcweir         throw (uno::RuntimeException)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     DBG_ERROR("not implemented");
612*cdf0e10cSrcweir     return Rectangle();
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir Rectangle ScAccessibleContextBase::GetBoundingBox(void) const
616*cdf0e10cSrcweir         throw (uno::RuntimeException)
617*cdf0e10cSrcweir {
618*cdf0e10cSrcweir     DBG_ERROR("not implemented");
619*cdf0e10cSrcweir     return Rectangle();
620*cdf0e10cSrcweir }
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir void ScAccessibleContextBase::IsObjectValid() const
623*cdf0e10cSrcweir         throw (lang::DisposedException)
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir     if (rBHelper.bDisposed || rBHelper.bInDispose)
626*cdf0e10cSrcweir         throw lang::DisposedException();
627*cdf0e10cSrcweir }
628*cdf0e10cSrcweir 
629