1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <AccessibleSmElement.hxx>
21 #include <ElementsDockingWindow.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <toolkit/helper/convert.hxx>
30 #include <unotools/accessiblerelationsethelper.hxx>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/svapp.hxx>
35 using namespace ::com::sun::star::accessibility
;
36 using namespace ::com::sun::star
;
37 using OContextEntryGuard
= ::comphelper::OContextEntryGuard
;
38 using OExternalLockGuard
= ::comphelper::OExternalLockGuard
;
40 AccessibleSmElement::AccessibleSmElement(SmElementsControl
* pSmElementsControl
, sal_uInt16 nItemId
,
41 sal_Int32 nIndexInParent
)
42 : m_pSmElementsControl(pSmElementsControl
)
43 , m_nIndexInParent(nIndexInParent
)
47 assert(m_pSmElementsControl
);
48 m_nRole
= m_pSmElementsControl
->itemIsSeparator(m_nItemId
) ? AccessibleRole::SEPARATOR
49 : AccessibleRole::PUSH_BUTTON
;
52 AccessibleSmElement::~AccessibleSmElement() {}
54 void AccessibleSmElement::SetFocus(bool bFocus
)
56 if (m_bHasFocus
== bFocus
)
62 aOldValue
<<= AccessibleStateType::FOCUSED
;
64 aNewValue
<<= AccessibleStateType::FOCUSED
;
66 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
69 awt::Rectangle
AccessibleSmElement::implGetBounds()
72 if (m_pSmElementsControl
)
73 aRect
= AWTRectangle(m_pSmElementsControl
->itemPosRect(m_nItemId
));
79 IMPLEMENT_FORWARD_REFCOUNT(AccessibleSmElement
, comphelper::OAccessibleComponentHelper
)
81 uno::Any
AccessibleSmElement::queryInterface(const uno::Type
& _rType
)
83 if (_rType
== cppu::UnoType
<XAccessibleAction
>::get()
84 && (!m_pSmElementsControl
|| m_pSmElementsControl
->itemIsSeparator(m_nItemId
)))
87 uno::Any aReturn
= comphelper::OAccessibleComponentHelper::queryInterface(_rType
);
88 if (!aReturn
.hasValue())
89 aReturn
= AccessibleSmElement_BASE::queryInterface(_rType
);
95 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleSmElement
, comphelper::OAccessibleComponentHelper
,
96 AccessibleSmElement_BASE
)
100 void AccessibleSmElement::disposing()
102 comphelper::OAccessibleComponentHelper::disposing();
103 m_pSmElementsControl
= nullptr;
108 OUString
AccessibleSmElement::getImplementationName()
110 return "com.sun.star.comp.toolkit.AccessibleSmElement";
113 sal_Bool
AccessibleSmElement::supportsService(const OUString
& rServiceName
)
115 return cppu::supportsService(this, rServiceName
);
118 uno::Sequence
<OUString
> AccessibleSmElement::getSupportedServiceNames()
120 return { "com.sun.star.accessibility.AccessibleContext",
121 "com.sun.star.accessibility.AccessibleComponent",
122 "com.sun.star.accessibility.AccessibleSmElement" };
127 uno::Reference
<XAccessibleContext
> AccessibleSmElement::getAccessibleContext() { return this; }
129 // XAccessibleContext
131 sal_Int32
AccessibleSmElement::getAccessibleChildCount() { return 0; }
133 uno::Reference
<accessibility::XAccessible
> AccessibleSmElement::getAccessibleChild(sal_Int32
)
135 return uno::Reference
<XAccessible
>();
138 uno::Reference
<XAccessible
> AccessibleSmElement::getAccessibleParent()
140 OContextEntryGuard
aGuard(this);
141 uno::Reference
<XAccessible
> xParent
;
142 if (m_pSmElementsControl
)
143 xParent
.set(m_pSmElementsControl
->GetAccessible().get());
147 sal_Int32
AccessibleSmElement::getAccessibleIndexInParent()
149 OContextEntryGuard
aGuard(this);
150 return m_nIndexInParent
;
153 sal_Int16
AccessibleSmElement::getAccessibleRole()
155 OContextEntryGuard
aGuard(this);
159 OUString
AccessibleSmElement::getAccessibleDescription() { return getAccessibleName(); }
161 OUString
AccessibleSmElement::getAccessibleName()
163 OExternalLockGuard
aGuard(this);
165 if (m_pSmElementsControl
)
166 aName
= m_pSmElementsControl
->itemName(m_nItemId
);
170 uno::Reference
<XAccessibleRelationSet
> AccessibleSmElement::getAccessibleRelationSet()
172 OContextEntryGuard
aGuard(this);
174 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
175 uno::Reference
<XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
179 uno::Reference
<XAccessibleStateSet
> AccessibleSmElement::getAccessibleStateSet()
181 OExternalLockGuard
aGuard(this);
183 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
184 uno::Reference
<XAccessibleStateSet
> xStateSet
= pStateSetHelper
;
186 if (m_pSmElementsControl
&& !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
188 if (m_pSmElementsControl
->itemIsVisible(m_nItemId
))
189 pStateSetHelper
->AddState(AccessibleStateType::VISIBLE
);
190 if (!m_pSmElementsControl
->itemIsSeparator(m_nItemId
))
192 if (m_pSmElementsControl
->IsEnabled())
194 pStateSetHelper
->AddState(AccessibleStateType::ENABLED
);
195 pStateSetHelper
->AddState(AccessibleStateType::SENSITIVE
);
197 pStateSetHelper
->AddState(AccessibleStateType::FOCUSABLE
);
199 pStateSetHelper
->AddState(AccessibleStateType::FOCUSED
);
203 pStateSetHelper
->AddState(AccessibleStateType::DEFUNC
);
208 // XAccessibleComponent
210 uno::Reference
<XAccessible
> AccessibleSmElement::getAccessibleAtPoint(const awt::Point
&)
212 return uno::Reference
<XAccessible
>();
215 void AccessibleSmElement::grabFocus()
217 uno::Reference
<XAccessible
> xParent(getAccessibleParent());
221 uno::Reference
<XAccessibleSelection
> rxAccessibleSelection(xParent
->getAccessibleContext(),
223 if (rxAccessibleSelection
.is())
224 rxAccessibleSelection
->selectAccessibleChild(getAccessibleIndexInParent());
228 sal_Int32
AccessibleSmElement::getForeground()
230 OExternalLockGuard
aGuard(this);
232 Color nColor
= SmElementsControl::GetTextColor();
233 return sal_Int32(nColor
);
236 sal_Int32
AccessibleSmElement::getBackground()
238 OExternalLockGuard
aGuard(this);
240 Color nColor
= SmElementsControl::GetControlBackground();
241 return sal_Int32(nColor
);
246 sal_Int32
AccessibleSmElement::getAccessibleActionCount()
248 // only one action -> "Press"
249 return m_pSmElementsControl
->itemIsSeparator(m_nItemId
) ? 0 : 1;
252 void AccessibleSmElement::testAction(sal_Int32 nIndex
) const
254 if (!m_pSmElementsControl
|| m_pSmElementsControl
->itemIsSeparator(m_nItemId
) || (nIndex
!= 0))
255 throw lang::IndexOutOfBoundsException();
258 sal_Bool
AccessibleSmElement::doAccessibleAction(sal_Int32 nIndex
)
260 OExternalLockGuard
aGuard(this);
264 return m_pSmElementsControl
->itemTrigger(m_nItemId
);
267 OUString
AccessibleSmElement::getAccessibleActionDescription(sal_Int32 nIndex
)
269 OExternalLockGuard
aGuard(this);
276 uno::Reference
<XAccessibleKeyBinding
>
277 AccessibleSmElement::getAccessibleActionKeyBinding(sal_Int32 nIndex
)
279 OContextEntryGuard
aGuard(this);
283 return uno::Reference
<XAccessibleKeyBinding
>();
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */