LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/Accessibility - AccessibleFilterMenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 155 0.6 %
Date: 2013-07-09 Functions: 2 41 4.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10