1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "AccessibleTreeNode.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "taskpane/TaskPaneTreeNode.hxx"
30cdf0e10cSrcweir #include "taskpane/ControlContainer.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "sdresid.hxx"
33cdf0e10cSrcweir #include "accessibility.hrc"
34cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
35cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36cdf0e10cSrcweir #include <comphelper/accessibleeventnotifier.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <vcl/svapp.hxx>
39cdf0e10cSrcweir #include <vcl/window.hxx>
40cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
46cdf0e10cSrcweir using namespace ::sd::toolpanel;
47cdf0e10cSrcweir
48cdf0e10cSrcweir namespace accessibility {
49cdf0e10cSrcweir
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir //===== AccessibleTreeNode =============================================
53cdf0e10cSrcweir
AccessibleTreeNode(::sd::toolpanel::TreeNode & rNode,const OUString & rsName,const OUString & rsDescription,sal_Int16 eRole)54cdf0e10cSrcweir AccessibleTreeNode::AccessibleTreeNode(
55cdf0e10cSrcweir ::sd::toolpanel::TreeNode& rNode,
56cdf0e10cSrcweir const OUString& rsName,
57cdf0e10cSrcweir const OUString& rsDescription,
58cdf0e10cSrcweir sal_Int16 eRole)
59cdf0e10cSrcweir : AccessibleTreeNodeBase(MutexOwner::maMutex),
60cdf0e10cSrcweir mxParent(NULL),
61cdf0e10cSrcweir mrTreeNode(rNode),
62cdf0e10cSrcweir mrStateSet(new ::utl::AccessibleStateSetHelper()),
63cdf0e10cSrcweir msName(rsName),
64cdf0e10cSrcweir msDescription(rsDescription),
65cdf0e10cSrcweir meRole(eRole),
66cdf0e10cSrcweir mnClientId(0)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir ::Window* pWindow = mrTreeNode.GetWindow();
69cdf0e10cSrcweir if (pWindow != NULL)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir ::Window* pParentWindow = pWindow->GetAccessibleParentWindow();
72cdf0e10cSrcweir if (pParentWindow != NULL && pParentWindow != pWindow)
73cdf0e10cSrcweir mxParent = pParentWindow->GetAccessible();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir CommonConstructor();
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir
79cdf0e10cSrcweir
80cdf0e10cSrcweir
CommonConstructor(void)81cdf0e10cSrcweir void AccessibleTreeNode::CommonConstructor (void)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir UpdateStateSet();
84cdf0e10cSrcweir
85cdf0e10cSrcweir Link aStateChangeLink (LINK(this,AccessibleTreeNode,StateChangeListener));
86cdf0e10cSrcweir mrTreeNode.AddStateChangeListener(aStateChangeLink);
87cdf0e10cSrcweir
88cdf0e10cSrcweir if (mrTreeNode.GetWindow() != NULL)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir Link aWindowEventLink (LINK(this,AccessibleTreeNode,WindowEventListener));
91cdf0e10cSrcweir mrTreeNode.GetWindow()->AddEventListener(aWindowEventLink);
92cdf0e10cSrcweir }
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweir
~AccessibleTreeNode(void)98cdf0e10cSrcweir AccessibleTreeNode::~AccessibleTreeNode (void)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir OSL_ASSERT(IsDisposed());
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir
104cdf0e10cSrcweir
105cdf0e10cSrcweir
FireAccessibleEvent(short nEventId,const uno::Any & rOldValue,const uno::Any & rNewValue)106cdf0e10cSrcweir void AccessibleTreeNode::FireAccessibleEvent (
107cdf0e10cSrcweir short nEventId,
108cdf0e10cSrcweir const uno::Any& rOldValue,
109cdf0e10cSrcweir const uno::Any& rNewValue )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir if (mnClientId != 0)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir AccessibleEventObject aEventObject;
114cdf0e10cSrcweir
115cdf0e10cSrcweir aEventObject.Source = Reference<XWeak>(this);
116cdf0e10cSrcweir aEventObject.EventId = nEventId;
117cdf0e10cSrcweir aEventObject.NewValue = rNewValue;
118cdf0e10cSrcweir aEventObject.OldValue = rOldValue;
119cdf0e10cSrcweir
120cdf0e10cSrcweir comphelper::AccessibleEventNotifier::addEvent (mnClientId, aEventObject);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir
125cdf0e10cSrcweir
126cdf0e10cSrcweir
disposing(void)127cdf0e10cSrcweir void SAL_CALL AccessibleTreeNode::disposing (void)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir // We are still listening to the tree node and its window. Both
130cdf0e10cSrcweir // probably are by now more or less dead and we must not call them to
131cdf0e10cSrcweir // unregister.
132cdf0e10cSrcweir
133cdf0e10cSrcweir if (mnClientId != 0)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
136cdf0e10cSrcweir mnClientId = 0;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir
141cdf0e10cSrcweir
142cdf0e10cSrcweir
143cdf0e10cSrcweir //===== XAccessible =========================================================
144cdf0e10cSrcweir
145cdf0e10cSrcweir Reference<XAccessibleContext > SAL_CALL
getAccessibleContext(void)146cdf0e10cSrcweir AccessibleTreeNode::getAccessibleContext (void)
147cdf0e10cSrcweir throw (uno::RuntimeException)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir ThrowIfDisposed ();
150cdf0e10cSrcweir return this;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir
154cdf0e10cSrcweir
155cdf0e10cSrcweir
156cdf0e10cSrcweir //===== XAccessibleContext ==================================================
157cdf0e10cSrcweir
getAccessibleChildCount(void)158cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTreeNode::getAccessibleChildCount (void)
159cdf0e10cSrcweir throw (RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir ThrowIfDisposed();
162cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
163cdf0e10cSrcweir return mrTreeNode.GetControlContainer().GetControlCount();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweir
169cdf0e10cSrcweir Reference<XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nIndex)170cdf0e10cSrcweir AccessibleTreeNode::getAccessibleChild (sal_Int32 nIndex)
171cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir ThrowIfDisposed();
174cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
175cdf0e10cSrcweir
176cdf0e10cSrcweir if (nIndex<0 || (sal_uInt32)nIndex>=mrTreeNode.GetControlContainer().GetControlCount())
177cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
178cdf0e10cSrcweir
179cdf0e10cSrcweir Reference<XAccessible> xChild;
180cdf0e10cSrcweir
181cdf0e10cSrcweir ::sd::toolpanel::TreeNode* pNode = mrTreeNode.GetControlContainer().GetControl(nIndex);
182cdf0e10cSrcweir if (pNode != NULL)
183cdf0e10cSrcweir xChild = pNode->GetAccessibleObject();
184cdf0e10cSrcweir
185cdf0e10cSrcweir return xChild;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir
189cdf0e10cSrcweir
190cdf0e10cSrcweir
getAccessibleParent(void)191cdf0e10cSrcweir Reference<XAccessible > SAL_CALL AccessibleTreeNode::getAccessibleParent (void)
192cdf0e10cSrcweir throw (uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir ThrowIfDisposed();
195cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
196cdf0e10cSrcweir return mxParent;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir
200cdf0e10cSrcweir
201cdf0e10cSrcweir
getAccessibleIndexInParent(void)202cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTreeNode::getAccessibleIndexInParent (void)
203cdf0e10cSrcweir throw (uno::RuntimeException)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir OSL_ASSERT(getAccessibleParent().is());
206cdf0e10cSrcweir ThrowIfDisposed();
207cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
208cdf0e10cSrcweir sal_Int32 nIndexInParent(-1);
209cdf0e10cSrcweir
210cdf0e10cSrcweir
211cdf0e10cSrcweir Reference<XAccessibleContext> xParentContext (getAccessibleParent()->getAccessibleContext());
212cdf0e10cSrcweir if (xParentContext.is())
213cdf0e10cSrcweir {
214cdf0e10cSrcweir sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
215cdf0e10cSrcweir for (sal_Int32 i=0; i<nChildCount; ++i)
216cdf0e10cSrcweir if (xParentContext->getAccessibleChild(i).get()
217cdf0e10cSrcweir == static_cast<XAccessible*>(this))
218cdf0e10cSrcweir {
219cdf0e10cSrcweir nIndexInParent = i;
220cdf0e10cSrcweir break;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
224cdf0e10cSrcweir return nIndexInParent;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir
228cdf0e10cSrcweir
229cdf0e10cSrcweir
getAccessibleRole(void)230cdf0e10cSrcweir sal_Int16 SAL_CALL AccessibleTreeNode::getAccessibleRole (void)
231cdf0e10cSrcweir throw (uno::RuntimeException)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir ThrowIfDisposed();
234cdf0e10cSrcweir return meRole;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
237cdf0e10cSrcweir
238cdf0e10cSrcweir
239cdf0e10cSrcweir
getAccessibleDescription(void)240cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleTreeNode::getAccessibleDescription (void)
241cdf0e10cSrcweir throw (uno::RuntimeException)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir ThrowIfDisposed();
244cdf0e10cSrcweir return msDescription;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir
248cdf0e10cSrcweir
249cdf0e10cSrcweir
getAccessibleName(void)250cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleTreeNode::getAccessibleName (void)
251cdf0e10cSrcweir throw (uno::RuntimeException)
252cdf0e10cSrcweir {
253cdf0e10cSrcweir ThrowIfDisposed();
254cdf0e10cSrcweir return msName;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir
258cdf0e10cSrcweir
259cdf0e10cSrcweir
260cdf0e10cSrcweir Reference<XAccessibleRelationSet> SAL_CALL
getAccessibleRelationSet(void)261cdf0e10cSrcweir AccessibleTreeNode::getAccessibleRelationSet (void)
262cdf0e10cSrcweir throw (uno::RuntimeException)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir ThrowIfDisposed();
265cdf0e10cSrcweir return Reference<XAccessibleRelationSet>();
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
268cdf0e10cSrcweir
269cdf0e10cSrcweir
270cdf0e10cSrcweir
271cdf0e10cSrcweir Reference<XAccessibleStateSet > SAL_CALL
getAccessibleStateSet(void)272cdf0e10cSrcweir AccessibleTreeNode::getAccessibleStateSet (void)
273cdf0e10cSrcweir throw (uno::RuntimeException)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir ThrowIfDisposed();
276cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
277cdf0e10cSrcweir return mrStateSet.get();
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir
281cdf0e10cSrcweir
282cdf0e10cSrcweir
UpdateStateSet(void)283cdf0e10cSrcweir void AccessibleTreeNode::UpdateStateSet (void)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir if (mrTreeNode.IsExpandable())
286cdf0e10cSrcweir {
287cdf0e10cSrcweir UpdateState(AccessibleStateType::EXPANDABLE, true);
288cdf0e10cSrcweir UpdateState(AccessibleStateType::EXPANDED, mrTreeNode.IsExpanded());
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir UpdateState(AccessibleStateType::FOCUSABLE, true);
292cdf0e10cSrcweir
293cdf0e10cSrcweir ::Window* pWindow = mrTreeNode.GetWindow();
294cdf0e10cSrcweir if (pWindow != NULL)
295cdf0e10cSrcweir {
296cdf0e10cSrcweir UpdateState(AccessibleStateType::ENABLED, pWindow->IsEnabled());
297cdf0e10cSrcweir UpdateState(AccessibleStateType::FOCUSED, pWindow->HasFocus());
298cdf0e10cSrcweir UpdateState(AccessibleStateType::VISIBLE, pWindow->IsVisible());
299cdf0e10cSrcweir UpdateState(AccessibleStateType::SHOWING, pWindow->IsReallyVisible());
300cdf0e10cSrcweir }
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir
304cdf0e10cSrcweir
305cdf0e10cSrcweir
UpdateState(sal_Int16 aState,bool bValue)306cdf0e10cSrcweir void AccessibleTreeNode::UpdateState(
307cdf0e10cSrcweir sal_Int16 aState,
308cdf0e10cSrcweir bool bValue)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir if ((mrStateSet->contains(aState)!=sal_False) != bValue)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir if (bValue)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir mrStateSet->AddState(aState);
315cdf0e10cSrcweir FireAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(),Any(aState));
316cdf0e10cSrcweir }
317cdf0e10cSrcweir else
318cdf0e10cSrcweir {
319cdf0e10cSrcweir mrStateSet->RemoveState(aState);
320cdf0e10cSrcweir FireAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(aState),Any());
321cdf0e10cSrcweir }
322cdf0e10cSrcweir }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir
325cdf0e10cSrcweir
326cdf0e10cSrcweir
327cdf0e10cSrcweir
getLocale(void)328cdf0e10cSrcweir lang::Locale SAL_CALL AccessibleTreeNode::getLocale (void)
329cdf0e10cSrcweir throw (IllegalAccessibleComponentStateException,
330cdf0e10cSrcweir RuntimeException)
331cdf0e10cSrcweir {
332cdf0e10cSrcweir ThrowIfDisposed ();
333cdf0e10cSrcweir Reference<XAccessibleContext> xParentContext;
334cdf0e10cSrcweir Reference<XAccessible> xParent (getAccessibleParent());
335cdf0e10cSrcweir if (xParent.is())
336cdf0e10cSrcweir xParentContext = xParent->getAccessibleContext();
337cdf0e10cSrcweir
338cdf0e10cSrcweir if (xParentContext.is())
339cdf0e10cSrcweir return xParentContext->getLocale();
340cdf0e10cSrcweir else
341cdf0e10cSrcweir // Strange, no parent! Anyway, return the default locale.
342cdf0e10cSrcweir return Application::GetSettings().GetLocale();
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir
346cdf0e10cSrcweir
347cdf0e10cSrcweir
addEventListener(const Reference<XAccessibleEventListener> & rxListener)348cdf0e10cSrcweir void SAL_CALL AccessibleTreeNode::addEventListener(
349cdf0e10cSrcweir const Reference<XAccessibleEventListener >& rxListener)
350cdf0e10cSrcweir throw (RuntimeException)
351cdf0e10cSrcweir {
352cdf0e10cSrcweir if (rxListener.is())
353cdf0e10cSrcweir {
354cdf0e10cSrcweir const osl::MutexGuard aGuard(maMutex);
355cdf0e10cSrcweir
356cdf0e10cSrcweir if (IsDisposed())
357cdf0e10cSrcweir {
358cdf0e10cSrcweir uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
359cdf0e10cSrcweir rxListener->disposing (lang::EventObject (x));
360cdf0e10cSrcweir }
361cdf0e10cSrcweir else
362cdf0e10cSrcweir {
363cdf0e10cSrcweir if (mnClientId == 0)
364cdf0e10cSrcweir mnClientId = comphelper::AccessibleEventNotifier::registerClient();
365cdf0e10cSrcweir if (mnClientId != 0)
366cdf0e10cSrcweir comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
367cdf0e10cSrcweir }
368cdf0e10cSrcweir }
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir
372cdf0e10cSrcweir
373cdf0e10cSrcweir
removeEventListener(const Reference<XAccessibleEventListener> & rxListener)374cdf0e10cSrcweir void SAL_CALL AccessibleTreeNode::removeEventListener(
375cdf0e10cSrcweir const Reference<XAccessibleEventListener >& rxListener)
376cdf0e10cSrcweir throw (RuntimeException)
377cdf0e10cSrcweir {
378cdf0e10cSrcweir ThrowIfDisposed();
379cdf0e10cSrcweir if (rxListener.is())
380cdf0e10cSrcweir {
381cdf0e10cSrcweir const osl::MutexGuard aGuard(maMutex);
382cdf0e10cSrcweir
383cdf0e10cSrcweir sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, rxListener );
384cdf0e10cSrcweir if ( !nListenerCount )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir // no listeners anymore
387cdf0e10cSrcweir // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
388cdf0e10cSrcweir // and at least to us not firing any events anymore, in case somebody calls
389cdf0e10cSrcweir // NotifyAccessibleEvent, again
390cdf0e10cSrcweir if (mnClientId != 0)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
393cdf0e10cSrcweir mnClientId = 0;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir }
396cdf0e10cSrcweir }
397cdf0e10cSrcweir }
398cdf0e10cSrcweir
399cdf0e10cSrcweir
400cdf0e10cSrcweir
401cdf0e10cSrcweir
402cdf0e10cSrcweir //===== XAccessibleComponent ==================================================
403cdf0e10cSrcweir
containsPoint(const awt::Point & aPoint)404cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleTreeNode::containsPoint (const awt::Point& aPoint)
405cdf0e10cSrcweir throw (RuntimeException)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir ThrowIfDisposed();
408cdf0e10cSrcweir const awt::Rectangle aBBox (getBounds());
409cdf0e10cSrcweir return (aPoint.X >= 0)
410cdf0e10cSrcweir && (aPoint.X < aBBox.Width)
411cdf0e10cSrcweir && (aPoint.Y >= 0)
412cdf0e10cSrcweir && (aPoint.Y < aBBox.Height);
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
415cdf0e10cSrcweir
416cdf0e10cSrcweir
417cdf0e10cSrcweir
418cdf0e10cSrcweir Reference<XAccessible> SAL_CALL
getAccessibleAtPoint(const awt::Point & aPoint)419cdf0e10cSrcweir AccessibleTreeNode::getAccessibleAtPoint (const awt::Point& aPoint)
420cdf0e10cSrcweir throw (RuntimeException)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir ThrowIfDisposed();
423cdf0e10cSrcweir Reference<XAccessible> xChildAtPoint;
424cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
425cdf0e10cSrcweir
426cdf0e10cSrcweir sal_Int32 nChildCount = getAccessibleChildCount();
427cdf0e10cSrcweir for (sal_Int32 nIndex=0; nIndex<nChildCount; ++nIndex)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir Reference<XAccessibleComponent> xChildComponent(
430cdf0e10cSrcweir getAccessibleChild(nIndex), UNO_QUERY);
431cdf0e10cSrcweir if (xChildComponent.is())
432cdf0e10cSrcweir {
433cdf0e10cSrcweir awt::Point aChildPoint(aPoint);
434cdf0e10cSrcweir awt::Point aChildOrigin(xChildComponent->getLocation());
435cdf0e10cSrcweir aChildPoint.X -= aChildOrigin.X;
436cdf0e10cSrcweir aChildPoint.Y -= aChildOrigin.Y;
437cdf0e10cSrcweir if (xChildComponent->containsPoint(aChildPoint))
438cdf0e10cSrcweir {
439cdf0e10cSrcweir xChildAtPoint = getAccessibleChild(nIndex);
440cdf0e10cSrcweir break;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir }
443cdf0e10cSrcweir }
444cdf0e10cSrcweir
445cdf0e10cSrcweir return xChildAtPoint;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir
448cdf0e10cSrcweir
449cdf0e10cSrcweir
450cdf0e10cSrcweir
getBounds(void)451cdf0e10cSrcweir awt::Rectangle SAL_CALL AccessibleTreeNode::getBounds (void)
452cdf0e10cSrcweir throw (RuntimeException)
453cdf0e10cSrcweir {
454cdf0e10cSrcweir ThrowIfDisposed ();
455cdf0e10cSrcweir
456cdf0e10cSrcweir awt::Rectangle aBBox;
457cdf0e10cSrcweir
458cdf0e10cSrcweir ::Window* pWindow = mrTreeNode.GetWindow();
459cdf0e10cSrcweir if (pWindow != NULL)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir Point aPosition;
462cdf0e10cSrcweir if (mxParent.is())
463cdf0e10cSrcweir {
464cdf0e10cSrcweir aPosition = pWindow->OutputToAbsoluteScreenPixel(Point(0,0));
465cdf0e10cSrcweir Reference<XAccessibleComponent> xParentComponent (
466cdf0e10cSrcweir mxParent->getAccessibleContext(), UNO_QUERY);
467cdf0e10cSrcweir if (xParentComponent.is())
468cdf0e10cSrcweir {
469cdf0e10cSrcweir awt::Point aParentPosition (xParentComponent->getLocationOnScreen());
470cdf0e10cSrcweir aPosition.X() -= aParentPosition.X;
471cdf0e10cSrcweir aPosition.Y() -= aParentPosition.Y;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir else
475cdf0e10cSrcweir aPosition = pWindow->GetPosPixel();
476cdf0e10cSrcweir aBBox.X = aPosition.X();
477cdf0e10cSrcweir aBBox.Y = aPosition.Y();
478cdf0e10cSrcweir
479cdf0e10cSrcweir Size aSize (pWindow->GetSizePixel());
480cdf0e10cSrcweir aBBox.Width = aSize.Width();
481cdf0e10cSrcweir aBBox.Height = aSize.Height();
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir return aBBox;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
487cdf0e10cSrcweir
488cdf0e10cSrcweir
489cdf0e10cSrcweir
getLocation(void)490cdf0e10cSrcweir awt::Point SAL_CALL AccessibleTreeNode::getLocation (void)
491cdf0e10cSrcweir throw (uno::RuntimeException)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir ThrowIfDisposed();
494cdf0e10cSrcweir const awt::Rectangle aBBox (getBounds());
495cdf0e10cSrcweir return awt::Point(aBBox.X,aBBox.Y);
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir
499cdf0e10cSrcweir
500cdf0e10cSrcweir
501cdf0e10cSrcweir /** Calculate the location on screen from the parent's location on screen
502cdf0e10cSrcweir and our own relative location.
503cdf0e10cSrcweir */
getLocationOnScreen()504cdf0e10cSrcweir awt::Point SAL_CALL AccessibleTreeNode::getLocationOnScreen()
505cdf0e10cSrcweir throw (uno::RuntimeException)
506cdf0e10cSrcweir {
507cdf0e10cSrcweir ThrowIfDisposed();
508cdf0e10cSrcweir const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
509cdf0e10cSrcweir awt::Point aLocationOnScreen;
510cdf0e10cSrcweir
511cdf0e10cSrcweir ::Window* pWindow = mrTreeNode.GetWindow();
512cdf0e10cSrcweir if (pWindow != NULL)
513cdf0e10cSrcweir {
514cdf0e10cSrcweir Point aPoint (pWindow->OutputToAbsoluteScreenPixel(Point(0,0)));
515cdf0e10cSrcweir aLocationOnScreen.X = aPoint.X();
516cdf0e10cSrcweir aLocationOnScreen.Y = aPoint.Y();
517cdf0e10cSrcweir }
518cdf0e10cSrcweir
519cdf0e10cSrcweir return aLocationOnScreen;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir
522cdf0e10cSrcweir
523cdf0e10cSrcweir
524cdf0e10cSrcweir
getSize(void)525cdf0e10cSrcweir awt::Size SAL_CALL AccessibleTreeNode::getSize (void)
526cdf0e10cSrcweir throw (uno::RuntimeException)
527cdf0e10cSrcweir {
528cdf0e10cSrcweir ThrowIfDisposed();
529cdf0e10cSrcweir const awt::Rectangle aBBox (getBounds());
530cdf0e10cSrcweir return awt::Size(aBBox.Width,aBBox.Height);
531cdf0e10cSrcweir }
532cdf0e10cSrcweir
533cdf0e10cSrcweir
534cdf0e10cSrcweir
535cdf0e10cSrcweir
grabFocus(void)536cdf0e10cSrcweir void SAL_CALL AccessibleTreeNode::grabFocus (void)
537cdf0e10cSrcweir throw (uno::RuntimeException)
538cdf0e10cSrcweir {
539cdf0e10cSrcweir ThrowIfDisposed();
540cdf0e10cSrcweir const vos::OGuard aSolarGuard (Application::GetSolarMutex());
541cdf0e10cSrcweir
542cdf0e10cSrcweir if (mrTreeNode.GetWindow() != NULL)
543cdf0e10cSrcweir mrTreeNode.GetWindow()->GrabFocus();
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
546cdf0e10cSrcweir
547cdf0e10cSrcweir
548cdf0e10cSrcweir
getForeground(void)549cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTreeNode::getForeground (void)
550cdf0e10cSrcweir throw (RuntimeException)
551cdf0e10cSrcweir {
552cdf0e10cSrcweir ThrowIfDisposed();
553cdf0e10cSrcweir svtools::ColorConfig aColorConfig;
554cdf0e10cSrcweir sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
555cdf0e10cSrcweir return static_cast<sal_Int32>(nColor);
556cdf0e10cSrcweir }
557cdf0e10cSrcweir
558cdf0e10cSrcweir
559cdf0e10cSrcweir
560cdf0e10cSrcweir
getBackground(void)561cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTreeNode::getBackground (void)
562cdf0e10cSrcweir throw (RuntimeException)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir ThrowIfDisposed();
565cdf0e10cSrcweir sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
566cdf0e10cSrcweir return static_cast<sal_Int32>(nColor);
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
569cdf0e10cSrcweir
570cdf0e10cSrcweir
571cdf0e10cSrcweir
572cdf0e10cSrcweir //===== XServiceInfo ========================================================
573cdf0e10cSrcweir
574cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getImplementationName(void)575cdf0e10cSrcweir AccessibleTreeNode::getImplementationName (void)
576cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
577cdf0e10cSrcweir {
578cdf0e10cSrcweir return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleTreeNode"));
579cdf0e10cSrcweir }
580cdf0e10cSrcweir
581cdf0e10cSrcweir
582cdf0e10cSrcweir
583cdf0e10cSrcweir
584cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const OUString & sServiceName)585cdf0e10cSrcweir AccessibleTreeNode::supportsService (const OUString& sServiceName)
586cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
587cdf0e10cSrcweir {
588cdf0e10cSrcweir ThrowIfDisposed ();
589cdf0e10cSrcweir
590cdf0e10cSrcweir // Iterate over all supported service names and return true if on of them
591cdf0e10cSrcweir // matches the given name.
592cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> aSupportedServices (
593cdf0e10cSrcweir getSupportedServiceNames ());
594cdf0e10cSrcweir for (int i=0; i<aSupportedServices.getLength(); i++)
595cdf0e10cSrcweir if (sServiceName == aSupportedServices[i])
596cdf0e10cSrcweir return sal_True;
597cdf0e10cSrcweir return sal_False;
598cdf0e10cSrcweir }
599cdf0e10cSrcweir
600cdf0e10cSrcweir
601cdf0e10cSrcweir
602cdf0e10cSrcweir
603cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SAL_CALL
getSupportedServiceNames(void)604cdf0e10cSrcweir AccessibleTreeNode::getSupportedServiceNames (void)
605cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
606cdf0e10cSrcweir {
607cdf0e10cSrcweir ThrowIfDisposed ();
608cdf0e10cSrcweir static const OUString sServiceNames[2] = {
609cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM(
610cdf0e10cSrcweir "com.sun.star.accessibility.Accessible")),
611cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM(
612cdf0e10cSrcweir "com.sun.star.accessibility.AccessibleContext")),
613cdf0e10cSrcweir };
614cdf0e10cSrcweir return uno::Sequence<OUString> (sServiceNames, 2);
615cdf0e10cSrcweir }
616cdf0e10cSrcweir
617cdf0e10cSrcweir
618cdf0e10cSrcweir
619cdf0e10cSrcweir
ThrowIfDisposed(void)620cdf0e10cSrcweir void AccessibleTreeNode::ThrowIfDisposed (void)
621cdf0e10cSrcweir throw (lang::DisposedException)
622cdf0e10cSrcweir {
623cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose)
624cdf0e10cSrcweir {
625cdf0e10cSrcweir OSL_TRACE ("Calling disposed object. Throwing exception:");
626cdf0e10cSrcweir throw lang::DisposedException (
627cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")),
628cdf0e10cSrcweir static_cast<uno::XWeak*>(this));
629cdf0e10cSrcweir }
630cdf0e10cSrcweir }
631cdf0e10cSrcweir
632cdf0e10cSrcweir
633cdf0e10cSrcweir
IsDisposed(void)634cdf0e10cSrcweir sal_Bool AccessibleTreeNode::IsDisposed (void)
635cdf0e10cSrcweir {
636cdf0e10cSrcweir return (rBHelper.bDisposed || rBHelper.bInDispose);
637cdf0e10cSrcweir }
638cdf0e10cSrcweir
639cdf0e10cSrcweir
640cdf0e10cSrcweir
641cdf0e10cSrcweir
IMPL_LINK(AccessibleTreeNode,StateChangeListener,TreeNodeStateChangeEvent *,pEvent)642cdf0e10cSrcweir IMPL_LINK(AccessibleTreeNode, StateChangeListener, TreeNodeStateChangeEvent*, pEvent)
643cdf0e10cSrcweir {
644cdf0e10cSrcweir OSL_ASSERT(pEvent!=NULL);
645cdf0e10cSrcweir OSL_ASSERT(&pEvent->mrSource==&mrTreeNode);
646cdf0e10cSrcweir
647cdf0e10cSrcweir switch(pEvent->meEventId)
648cdf0e10cSrcweir {
649cdf0e10cSrcweir case EID_CHILD_ADDED:
650cdf0e10cSrcweir if (pEvent->mpChild != NULL)
651cdf0e10cSrcweir FireAccessibleEvent(AccessibleEventId::CHILD,
652cdf0e10cSrcweir Any(),
653cdf0e10cSrcweir Any(pEvent->mpChild->GetAccessibleObject()));
654cdf0e10cSrcweir else
655cdf0e10cSrcweir FireAccessibleEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN,Any(),Any());
656cdf0e10cSrcweir break;
657cdf0e10cSrcweir
658cdf0e10cSrcweir case EID_ALL_CHILDREN_REMOVED:
659cdf0e10cSrcweir FireAccessibleEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN,Any(),Any());
660cdf0e10cSrcweir break;
661cdf0e10cSrcweir
662cdf0e10cSrcweir case EID_EXPANSION_STATE_CHANGED:
663cdf0e10cSrcweir case EID_FOCUSED_STATE_CHANGED:
664cdf0e10cSrcweir case EID_SHOWING_STATE_CHANGED:
665cdf0e10cSrcweir UpdateStateSet();
666cdf0e10cSrcweir break;
667cdf0e10cSrcweir }
668cdf0e10cSrcweir return 1;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir
671cdf0e10cSrcweir
672cdf0e10cSrcweir
673cdf0e10cSrcweir
IMPL_LINK(AccessibleTreeNode,WindowEventListener,VclWindowEvent *,pEvent)674cdf0e10cSrcweir IMPL_LINK(AccessibleTreeNode, WindowEventListener, VclWindowEvent*, pEvent)
675cdf0e10cSrcweir {
676cdf0e10cSrcweir switch (pEvent->GetId())
677cdf0e10cSrcweir {
678cdf0e10cSrcweir case VCLEVENT_WINDOW_HIDE:
679cdf0e10cSrcweir // This event may be sent while the window is destroyed so do
680cdf0e10cSrcweir // not call UpdateStateSet() which calls back to the window but
681cdf0e10cSrcweir // just set the two states VISIBLE and SHOWING to false.
682cdf0e10cSrcweir UpdateState(AccessibleStateType::VISIBLE, false);
683cdf0e10cSrcweir UpdateState(AccessibleStateType::SHOWING, false);
684cdf0e10cSrcweir break;
685cdf0e10cSrcweir
686cdf0e10cSrcweir case VCLEVENT_WINDOW_SHOW:
687cdf0e10cSrcweir case VCLEVENT_WINDOW_DATACHANGED:
688cdf0e10cSrcweir UpdateStateSet();
689cdf0e10cSrcweir break;
690cdf0e10cSrcweir
691cdf0e10cSrcweir case VCLEVENT_WINDOW_MOVE:
692cdf0e10cSrcweir case VCLEVENT_WINDOW_RESIZE:
693cdf0e10cSrcweir FireAccessibleEvent(AccessibleEventId::BOUNDRECT_CHANGED,Any(),Any());
694cdf0e10cSrcweir break;
695cdf0e10cSrcweir
696cdf0e10cSrcweir case VCLEVENT_WINDOW_GETFOCUS:
697cdf0e10cSrcweir case VCLEVENT_WINDOW_LOSEFOCUS:
698cdf0e10cSrcweir UpdateStateSet();
699cdf0e10cSrcweir break;
700cdf0e10cSrcweir }
701cdf0e10cSrcweir return 1;
702cdf0e10cSrcweir }
703cdf0e10cSrcweir
704cdf0e10cSrcweir } // end of namespace ::accessibility
705