merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / Accessibility / AccessibleFilterMenu.cxx
blob8a76393bfd2c2a697e509fa42359e56fc3d8869a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleDataPilotControl.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sc.hxx"
34 #include "AccessibleGlobal.hxx"
35 #include "AccessibleFilterMenu.hxx"
36 #include "AccessibleFilterMenuItem.hxx"
37 #include "unoguard.hxx"
38 #include "global.hxx"
39 #include "document.hxx"
40 #include "docpool.hxx"
42 #include "tools/gen.hxx"
43 #include "svx/unoedsrc.hxx"
44 #include "svx/editdata.hxx"
45 #include "svx/outliner.hxx"
46 #include "svtools/itemset.hxx"
47 #include "vcl/unohelp.hxx"
48 #include "dpcontrol.hxx"
50 #include <com/sun/star/accessibility/XAccessible.hpp>
51 #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
52 #include <com/sun/star/accessibility/AccessibleRole.hpp>
53 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
54 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::accessibility;
58 using namespace ::com::sun::star::accessibility::AccessibleStateType;
60 using ::com::sun::star::uno::Any;
61 using ::com::sun::star::uno::Reference;
62 using ::com::sun::star::uno::Sequence;
63 using ::com::sun::star::uno::UNO_QUERY;
64 using ::com::sun::star::lang::IndexOutOfBoundsException;
65 using ::com::sun::star::lang::IllegalArgumentException;
66 using ::com::sun::star::uno::RuntimeException;
67 using ::rtl::OUString;
68 using ::std::for_each;
69 using ::std::vector;
71 // ============================================================================
73 namespace {
75 class AddRemoveEventListener : public ::std::unary_function<void, Reference<XAccessible> >
77 public:
78 explicit AddRemoveEventListener(const Reference<XAccessibleEventListener>& rListener, bool bAdd) :
79 mxListener(rListener), mbAdd(bAdd) {}
81 void operator() (const Reference<XAccessible>& xAccessible) const
83 if (!xAccessible.is())
84 return;
86 Reference<XAccessibleEventBroadcaster> xBc(xAccessible, UNO_QUERY);
87 if (xBc.is())
89 if (mbAdd)
90 xBc->addEventListener(mxListener);
91 else
92 xBc->removeEventListener(mxListener);
95 private:
96 Reference<XAccessibleEventListener> mxListener;
97 bool mbAdd;
102 // ============================================================================
104 ScAccessibleFilterMenu::ScAccessibleFilterMenu(const Reference<XAccessible>& rxParent, ScMenuFloatingWindow* pWin, const OUString& rName, size_t nMenuPos, ScDocument* pDoc) :
105 ScAccessibleContextBase(rxParent, AccessibleRole::MENU),
106 mnMenuPos(nMenuPos),
107 mpWindow(pWin),
108 mpDoc(pDoc),
109 mbEnabled(true)
111 SetName(rName);
114 ScAccessibleFilterMenu::~ScAccessibleFilterMenu()
118 // XAccessibleComponent
120 Reference<XAccessible> ScAccessibleFilterMenu::getAccessibleAtPoint( const ::com::sun::star::awt::Point& /*rPoint*/ )
121 throw (RuntimeException)
123 return this;
126 sal_Bool ScAccessibleFilterMenu::isVisible() throw (RuntimeException)
128 return mpWindow->IsVisible();
131 void ScAccessibleFilterMenu::grabFocus()
132 throw (RuntimeException)
136 sal_Int32 ScAccessibleFilterMenu::getForeground()
137 throw (RuntimeException)
139 return 0;
142 sal_Int32 ScAccessibleFilterMenu::getBackground()
143 throw (RuntimeException)
145 return 0;
148 // XAccessibleContext
150 OUString ScAccessibleFilterMenu::getAccessibleName() throw (RuntimeException)
152 return ScAccessibleContextBase::getAccessibleName();
155 sal_Int32 ScAccessibleFilterMenu::getAccessibleChildCount()
156 throw (RuntimeException)
158 return getMenuItemCount();
161 Reference<XAccessible> ScAccessibleFilterMenu::getAccessibleChild(sal_Int32 nIndex)
162 throw (RuntimeException, IndexOutOfBoundsException)
164 if (maMenuItems.size() <= static_cast<size_t>(nIndex))
165 throw IndexOutOfBoundsException();
167 return maMenuItems[nIndex];
170 Reference<XAccessibleStateSet> ScAccessibleFilterMenu::getAccessibleStateSet()
171 throw (RuntimeException)
173 updateStates();
174 return mxStateSet;
177 OUString ScAccessibleFilterMenu::getImplementationName()
178 throw (RuntimeException)
180 return OUString::createFromAscii("ScAccessibleFilterMenu");
183 // XAccessibleEventBroadcaster
185 void ScAccessibleFilterMenu::addEventListener(
186 const ::com::sun::star::uno::Reference<
187 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
188 throw (com::sun::star::uno::RuntimeException)
190 ScAccessibleContextBase::addEventListener(xListener);
191 for_each(maMenuItems.begin(), maMenuItems.end(), AddRemoveEventListener(xListener, true));
194 void ScAccessibleFilterMenu::removeEventListener(
195 const ::com::sun::star::uno::Reference<
196 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
197 throw (com::sun::star::uno::RuntimeException)
199 ScAccessibleContextBase::removeEventListener(xListener);
200 for_each(maMenuItems.begin(), maMenuItems.end(), AddRemoveEventListener(xListener, false));
203 // XAccessibleSelection
205 void ScAccessibleFilterMenu::selectAccessibleChild(sal_Int32 nChildIndex)
206 throw (IndexOutOfBoundsException, RuntimeException)
208 if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
209 throw IndexOutOfBoundsException();
211 mpWindow->setSelectedMenuItem(nChildIndex, false, true);
214 sal_Bool ScAccessibleFilterMenu::isAccessibleChildSelected(sal_Int32 nChildIndex)
215 throw (IndexOutOfBoundsException, RuntimeException)
217 if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
218 throw IndexOutOfBoundsException();
220 return mpWindow->isMenuItemSelected(static_cast<size_t>(nChildIndex));
223 void ScAccessibleFilterMenu::clearAccessibleSelection() throw (RuntimeException)
225 mpWindow->clearSelectedMenuItem();
228 void ScAccessibleFilterMenu::selectAllAccessibleChildren() throw (RuntimeException)
230 // not suported - this is a menu, you can't select all menu items.
233 sal_Int32 ScAccessibleFilterMenu::getSelectedAccessibleChildCount() throw (RuntimeException)
235 // Since this is a menu, either one menu item is selected, or none at all.
236 return mpWindow->getSelectedMenuItem() == ScMenuFloatingWindow::MENU_NOT_SELECTED ? 0 : 1;
239 Reference<XAccessible> ScAccessibleFilterMenu::getSelectedAccessibleChild(sal_Int32 nChildIndex)
240 throw (IndexOutOfBoundsException, RuntimeException)
242 if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
243 throw IndexOutOfBoundsException();
245 return maMenuItems[nChildIndex];
248 void ScAccessibleFilterMenu::deselectAccessibleChild(sal_Int32 nChildIndex) throw (IndexOutOfBoundsException, RuntimeException)
250 if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
251 throw IndexOutOfBoundsException();
253 mpWindow->selectMenuItem(nChildIndex, false, false);
256 // XInterface
258 uno::Any SAL_CALL ScAccessibleFilterMenu::queryInterface( uno::Type const & rType )
259 throw (RuntimeException)
261 Any any = ScAccessibleContextBase::queryInterface(rType);
262 if (any.hasValue())
263 return any;
265 return ScAccessibleFilterMenu_BASE::queryInterface(rType);
268 void SAL_CALL ScAccessibleFilterMenu::acquire() throw ()
270 ScAccessibleContextBase::acquire();
273 void SAL_CALL ScAccessibleFilterMenu::release() throw ()
275 ScAccessibleContextBase::release();
278 // XTypeProvider
280 Sequence<sal_Int8> ScAccessibleFilterMenu::getImplementationId()
281 throw (RuntimeException)
283 Sequence<sal_Int8> aId(16);
284 return aId;
287 Rectangle ScAccessibleFilterMenu::GetBoundingBoxOnScreen() const
288 throw (RuntimeException)
290 if (mnMenuPos == ScMenuFloatingWindow::MENU_NOT_SELECTED)
291 return Rectangle();
293 // Menu object's bounding box is the bounding box of the menu item that
294 // launches the menu, which belongs to the parent window.
295 ScMenuFloatingWindow* pParentWin = mpWindow->getParentMenuWindow();
296 if (!pParentWin)
297 return Rectangle();
299 if (!pParentWin->IsVisible())
300 return Rectangle();
302 Point aPos = pParentWin->OutputToAbsoluteScreenPixel(Point(0,0));
303 Point aMenuPos;
304 Size aMenuSize;
305 pParentWin->getMenuItemPosSize(mnMenuPos, aMenuPos, aMenuSize);
306 Rectangle aRect(aPos + aMenuPos, aMenuSize);
307 return aRect;
310 Rectangle ScAccessibleFilterMenu::GetBoundingBox() const
311 throw (RuntimeException)
313 if (mnMenuPos == ScMenuFloatingWindow::MENU_NOT_SELECTED)
314 return Rectangle();
316 // Menu object's bounding box is the bounding box of the menu item that
317 // launches the menu, which belongs to the parent window.
318 ScMenuFloatingWindow* pParentWin = mpWindow->getParentMenuWindow();
319 if (!pParentWin)
320 return Rectangle();
322 if (!pParentWin->IsVisible())
323 return Rectangle();
325 Point aMenuPos;
326 Size aMenuSize;
327 pParentWin->getMenuItemPosSize(mnMenuPos, aMenuPos, aMenuSize);
328 Rectangle aRect(aMenuPos, aMenuSize);
329 return aRect;
332 void ScAccessibleFilterMenu::appendMenuItem(const OUString& rName, bool bEnabled, size_t nMenuPos)
334 // Check weather this menu item is a sub menu or a regular menu item.
335 ScMenuFloatingWindow* pSubMenu = mpWindow->getSubMenuWindow(nMenuPos);
336 Reference<XAccessible> xAccessible;
337 if (pSubMenu)
339 xAccessible = pSubMenu->CreateAccessible();
340 ScAccessibleFilterMenu* p =
341 static_cast<ScAccessibleFilterMenu*>(xAccessible.get());
342 p->setEnabled(bEnabled);
343 p->setMenuPos(nMenuPos);
345 else
347 xAccessible.set(new ScAccessibleFilterMenuItem(this, mpWindow, rName, nMenuPos));
348 ScAccessibleFilterMenuItem* p =
349 static_cast<ScAccessibleFilterMenuItem*>(xAccessible.get());
350 p->setEnabled(bEnabled);
352 maMenuItems.push_back(xAccessible);
355 void ScAccessibleFilterMenu::setMenuPos(size_t nMenuPos)
357 mnMenuPos = nMenuPos;
360 void ScAccessibleFilterMenu::setEnabled(bool bEnabled)
362 mbEnabled = bEnabled;
365 sal_Int32 ScAccessibleFilterMenu::getMenuItemCount() const
367 return maMenuItems.size();
370 bool ScAccessibleFilterMenu::isSelected() const
372 // Check to see if any of the child menu items is selected.
373 return mpWindow->isMenuItemSelected(mnMenuPos);
376 bool ScAccessibleFilterMenu::isFocused() const
378 return isSelected();
381 void ScAccessibleFilterMenu::updateStates()
383 if (!mxStateSet.is())
384 mxStateSet.set(new ScAccessibleStateSet);
386 ScAccessibleStateSet* p = static_cast<ScAccessibleStateSet*>(
387 mxStateSet.get());
389 p->clear();
391 p->insert(ENABLED);
392 p->insert(FOCUSABLE);
393 p->insert(SELECTABLE);
394 p->insert(SENSITIVE);
395 p->insert(OPAQUE);
397 if (isFocused())
398 p->insert(FOCUSED);
400 if (isSelected())
401 p->insert(SELECTED);