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

Generated by: LCOV version 1.10