Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "AccessibleGlobal.hxx"
21 : #include "AccessibleFilterMenu.hxx"
22 : #include "AccessibleFilterMenuItem.hxx"
23 : #include "global.hxx"
24 : #include "docpool.hxx"
25 :
26 : #include <tools/gen.hxx>
27 : #include <editeng/unoedsrc.hxx>
28 : #include <editeng/editdata.hxx>
29 : #include <editeng/outliner.hxx>
30 : #include <vcl/unohelp.hxx>
31 : #include "checklistmenu.hxx"
32 :
33 : #include <com/sun/star/accessibility/XAccessible.hpp>
34 : #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
35 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 :
39 : using namespace ::com::sun::star;
40 : using namespace ::com::sun::star::accessibility;
41 : using namespace ::com::sun::star::accessibility::AccessibleStateType;
42 :
43 : using ::com::sun::star::uno::Any;
44 : using ::com::sun::star::uno::Reference;
45 : using ::com::sun::star::uno::Sequence;
46 : using ::com::sun::star::uno::UNO_QUERY;
47 : using ::com::sun::star::lang::IndexOutOfBoundsException;
48 : using ::com::sun::star::lang::IllegalArgumentException;
49 : using ::com::sun::star::uno::RuntimeException;
50 : using ::std::for_each;
51 : using ::std::vector;
52 :
53 : namespace {
54 :
55 0 : class AddRemoveEventListener : public ::std::unary_function<void, Reference<XAccessible> >
56 : {
57 : public:
58 0 : explicit AddRemoveEventListener(const Reference<XAccessibleEventListener>& rListener, bool bAdd) :
59 0 : mxListener(rListener), mbAdd(bAdd) {}
60 :
61 0 : void operator() (const Reference<XAccessible>& xAccessible) const
62 : {
63 0 : if (!xAccessible.is())
64 0 : return;
65 :
66 0 : Reference<XAccessibleEventBroadcaster> xBc(xAccessible, UNO_QUERY);
67 0 : if (xBc.is())
68 : {
69 0 : if (mbAdd)
70 0 : xBc->addAccessibleEventListener(mxListener);
71 : else
72 0 : xBc->removeAccessibleEventListener(mxListener);
73 0 : }
74 : }
75 : private:
76 : Reference<XAccessibleEventListener> mxListener;
77 : bool mbAdd;
78 : };
79 :
80 : }
81 :
82 0 : ScAccessibleFilterMenu::ScAccessibleFilterMenu(const Reference<XAccessible>& rxParent, ScMenuFloatingWindow* pWin, const OUString& rName, size_t nMenuPos) :
83 : ScAccessibleContextBase(rxParent, AccessibleRole::MENU),
84 : mnMenuPos(nMenuPos),
85 : mpWindow(pWin),
86 0 : mbEnabled(true)
87 : {
88 0 : SetName(rName);
89 0 : }
90 :
91 0 : ScAccessibleFilterMenu::~ScAccessibleFilterMenu()
92 : {
93 0 : }
94 :
95 : // XAccessibleComponent
96 :
97 0 : Reference<XAccessible> ScAccessibleFilterMenu::getAccessibleAtPoint( const ::com::sun::star::awt::Point& /*rPoint*/ )
98 : throw (RuntimeException, std::exception)
99 : {
100 0 : return this;
101 : }
102 :
103 0 : bool ScAccessibleFilterMenu::isVisible() throw (RuntimeException, std::exception)
104 : {
105 0 : return mpWindow->IsVisible();
106 : }
107 :
108 0 : void ScAccessibleFilterMenu::grabFocus()
109 : throw (RuntimeException, std::exception)
110 : {
111 0 : }
112 :
113 0 : sal_Int32 ScAccessibleFilterMenu::getForeground()
114 : throw (RuntimeException, std::exception)
115 : {
116 0 : return 0;
117 : }
118 :
119 0 : sal_Int32 ScAccessibleFilterMenu::getBackground()
120 : throw (RuntimeException, std::exception)
121 : {
122 0 : return 0;
123 : }
124 :
125 : // XAccessibleContext
126 :
127 0 : OUString ScAccessibleFilterMenu::getAccessibleName() throw (RuntimeException, std::exception)
128 : {
129 0 : return ScAccessibleContextBase::getAccessibleName();
130 : }
131 :
132 0 : sal_Int32 ScAccessibleFilterMenu::getAccessibleChildCount()
133 : throw (RuntimeException, std::exception)
134 : {
135 0 : return getMenuItemCount();
136 : }
137 :
138 0 : Reference<XAccessible> ScAccessibleFilterMenu::getAccessibleChild(sal_Int32 nIndex)
139 : throw (RuntimeException, IndexOutOfBoundsException, std::exception)
140 : {
141 0 : if (maMenuItems.size() <= static_cast<size_t>(nIndex))
142 0 : throw IndexOutOfBoundsException();
143 :
144 0 : return maMenuItems[nIndex];
145 : }
146 :
147 0 : Reference<XAccessibleStateSet> ScAccessibleFilterMenu::getAccessibleStateSet()
148 : throw (RuntimeException, std::exception)
149 : {
150 0 : updateStates();
151 0 : return mxStateSet;
152 : }
153 :
154 0 : OUString ScAccessibleFilterMenu::getImplementationName()
155 : throw (RuntimeException, std::exception)
156 : {
157 0 : return OUString("ScAccessibleFilterMenu");
158 : }
159 :
160 : // XAccessibleEventBroadcaster
161 :
162 0 : void ScAccessibleFilterMenu::addAccessibleEventListener(
163 : const ::com::sun::star::uno::Reference<
164 : ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
165 : throw (com::sun::star::uno::RuntimeException, std::exception)
166 : {
167 0 : ScAccessibleContextBase::addAccessibleEventListener(xListener);
168 0 : for_each(maMenuItems.begin(), maMenuItems.end(), AddRemoveEventListener(xListener, true));
169 0 : }
170 :
171 0 : void ScAccessibleFilterMenu::removeAccessibleEventListener(
172 : const ::com::sun::star::uno::Reference<
173 : ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
174 : throw (com::sun::star::uno::RuntimeException, std::exception)
175 : {
176 0 : ScAccessibleContextBase::removeAccessibleEventListener(xListener);
177 0 : for_each(maMenuItems.begin(), maMenuItems.end(), AddRemoveEventListener(xListener, false));
178 0 : }
179 :
180 : // XAccessibleSelection
181 :
182 0 : void ScAccessibleFilterMenu::selectAccessibleChild(sal_Int32 nChildIndex)
183 : throw (IndexOutOfBoundsException, RuntimeException, std::exception)
184 : {
185 0 : if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
186 0 : throw IndexOutOfBoundsException();
187 :
188 0 : mpWindow->setSelectedMenuItem(nChildIndex, false, true);
189 0 : }
190 :
191 0 : sal_Bool ScAccessibleFilterMenu::isAccessibleChildSelected(sal_Int32 nChildIndex)
192 : throw (IndexOutOfBoundsException, RuntimeException, std::exception)
193 : {
194 0 : if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
195 0 : throw IndexOutOfBoundsException();
196 :
197 0 : return mpWindow->isMenuItemSelected(static_cast<size_t>(nChildIndex));
198 : }
199 :
200 0 : void ScAccessibleFilterMenu::clearAccessibleSelection() throw (RuntimeException, std::exception)
201 : {
202 0 : mpWindow->clearSelectedMenuItem();
203 0 : }
204 :
205 0 : void ScAccessibleFilterMenu::selectAllAccessibleChildren() throw (RuntimeException, std::exception)
206 : {
207 : // not supported - this is a menu, you can't select all menu items.
208 0 : }
209 :
210 0 : sal_Int32 ScAccessibleFilterMenu::getSelectedAccessibleChildCount() throw (RuntimeException, std::exception)
211 : {
212 : // Since this is a menu, either one menu item is selected, or none at all.
213 0 : return mpWindow->getSelectedMenuItem() == ScMenuFloatingWindow::MENU_NOT_SELECTED ? 0 : 1;
214 : }
215 :
216 0 : Reference<XAccessible> ScAccessibleFilterMenu::getSelectedAccessibleChild(sal_Int32 nChildIndex)
217 : throw (IndexOutOfBoundsException, RuntimeException, std::exception)
218 : {
219 0 : if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
220 0 : throw IndexOutOfBoundsException();
221 :
222 0 : return maMenuItems[nChildIndex];
223 : }
224 :
225 0 : void ScAccessibleFilterMenu::deselectAccessibleChild(sal_Int32 nChildIndex) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
226 : {
227 0 : if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
228 0 : throw IndexOutOfBoundsException();
229 :
230 0 : mpWindow->selectMenuItem(nChildIndex, false, false);
231 0 : }
232 :
233 : // XInterface
234 :
235 0 : uno::Any SAL_CALL ScAccessibleFilterMenu::queryInterface( uno::Type const & rType )
236 : throw (RuntimeException, std::exception)
237 : {
238 0 : Any any = ScAccessibleContextBase::queryInterface(rType);
239 0 : if (any.hasValue())
240 0 : return any;
241 :
242 0 : return ScAccessibleFilterMenu_BASE::queryInterface(rType);
243 : }
244 :
245 0 : void SAL_CALL ScAccessibleFilterMenu::acquire() throw ()
246 : {
247 0 : ScAccessibleContextBase::acquire();
248 0 : }
249 :
250 0 : void SAL_CALL ScAccessibleFilterMenu::release() throw ()
251 : {
252 0 : ScAccessibleContextBase::release();
253 0 : }
254 :
255 : // XTypeProvider
256 :
257 0 : Sequence<sal_Int8> ScAccessibleFilterMenu::getImplementationId()
258 : throw (RuntimeException, std::exception)
259 : {
260 0 : return css::uno::Sequence<sal_Int8>();
261 : }
262 :
263 0 : Rectangle ScAccessibleFilterMenu::GetBoundingBoxOnScreen() const
264 : throw (RuntimeException, std::exception)
265 : {
266 0 : if (mnMenuPos == ScMenuFloatingWindow::MENU_NOT_SELECTED)
267 0 : return Rectangle();
268 :
269 : // Menu object's bounding box is the bounding box of the menu item that
270 : // launches the menu, which belongs to the parent window.
271 0 : ScMenuFloatingWindow* pParentWin = mpWindow->getParentMenuWindow();
272 0 : if (!pParentWin)
273 0 : return Rectangle();
274 :
275 0 : if (!pParentWin->IsVisible())
276 0 : return Rectangle();
277 :
278 0 : Point aPos = pParentWin->OutputToAbsoluteScreenPixel(Point(0,0));
279 0 : Point aMenuPos;
280 0 : Size aMenuSize;
281 0 : pParentWin->getMenuItemPosSize(mnMenuPos, aMenuPos, aMenuSize);
282 0 : Rectangle aRect(aPos + aMenuPos, aMenuSize);
283 0 : return aRect;
284 : }
285 :
286 0 : Rectangle ScAccessibleFilterMenu::GetBoundingBox() const
287 : throw (RuntimeException, std::exception)
288 : {
289 0 : if (mnMenuPos == ScMenuFloatingWindow::MENU_NOT_SELECTED)
290 0 : return Rectangle();
291 :
292 : // Menu object's bounding box is the bounding box of the menu item that
293 : // launches the menu, which belongs to the parent window.
294 0 : ScMenuFloatingWindow* pParentWin = mpWindow->getParentMenuWindow();
295 0 : if (!pParentWin)
296 0 : return Rectangle();
297 :
298 0 : if (!pParentWin->IsVisible())
299 0 : return Rectangle();
300 :
301 0 : Point aMenuPos;
302 0 : Size aMenuSize;
303 0 : pParentWin->getMenuItemPosSize(mnMenuPos, aMenuPos, aMenuSize);
304 0 : Rectangle aRect(aMenuPos, aMenuSize);
305 0 : return aRect;
306 : }
307 :
308 0 : void ScAccessibleFilterMenu::appendMenuItem(const OUString& rName, bool bEnabled, size_t nMenuPos)
309 : {
310 : // Check whether this menu item is a sub menu or a regular menu item.
311 0 : ScMenuFloatingWindow* pSubMenu = mpWindow->getSubMenuWindow(nMenuPos);
312 0 : Reference<XAccessible> xAccessible;
313 0 : if (pSubMenu)
314 : {
315 0 : xAccessible = pSubMenu->CreateAccessible();
316 : ScAccessibleFilterMenu* p =
317 0 : static_cast<ScAccessibleFilterMenu*>(xAccessible.get());
318 0 : p->setEnabled(bEnabled);
319 0 : p->setMenuPos(nMenuPos);
320 : }
321 : else
322 : {
323 0 : xAccessible.set(new ScAccessibleFilterMenuItem(this, mpWindow, rName, nMenuPos));
324 : ScAccessibleFilterMenuItem* p =
325 0 : static_cast<ScAccessibleFilterMenuItem*>(xAccessible.get());
326 0 : p->setEnabled(bEnabled);
327 : }
328 0 : maMenuItems.push_back(xAccessible);
329 0 : }
330 :
331 0 : void ScAccessibleFilterMenu::setMenuPos(size_t nMenuPos)
332 : {
333 0 : mnMenuPos = nMenuPos;
334 0 : }
335 :
336 0 : void ScAccessibleFilterMenu::setEnabled(bool bEnabled)
337 : {
338 0 : mbEnabled = bEnabled;
339 0 : }
340 :
341 0 : sal_Int32 ScAccessibleFilterMenu::getMenuItemCount() const
342 : {
343 0 : return maMenuItems.size();
344 : }
345 :
346 0 : bool ScAccessibleFilterMenu::isSelected() const
347 : {
348 : // Check to see if any of the child menu items is selected.
349 0 : return mpWindow->isMenuItemSelected(mnMenuPos);
350 : }
351 :
352 0 : bool ScAccessibleFilterMenu::isFocused() const
353 : {
354 0 : return isSelected();
355 : }
356 :
357 0 : void ScAccessibleFilterMenu::updateStates()
358 : {
359 0 : if (!mxStateSet.is())
360 0 : mxStateSet.set(new ScAccessibleStateSet);
361 :
362 : ScAccessibleStateSet* p = static_cast<ScAccessibleStateSet*>(
363 0 : mxStateSet.get());
364 :
365 0 : p->clear();
366 :
367 0 : p->insert(ENABLED);
368 0 : p->insert(FOCUSABLE);
369 0 : p->insert(SELECTABLE);
370 0 : p->insert(SENSITIVE);
371 0 : p->insert(OPAQUE);
372 :
373 0 : if (isFocused())
374 0 : p->insert(FOCUSED);
375 :
376 0 : if (isSelected())
377 0 : p->insert(SELECTED);
378 156 : }
379 :
380 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|