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

Generated by: LCOV version 1.10