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