LCOV - code coverage report
Current view: top level - svtools/source/control - toolbarmenuimp.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 3 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 2 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             : #ifndef INCLUDED_SVTOOLS_SOURCE_CONTROL_TOOLBARMENUIMP_HXX
      21             : #define INCLUDED_SVTOOLS_SOURCE_CONTROL_TOOLBARMENUIMP_HXX
      22             : 
      23             : #include <osl/mutex.hxx>
      24             : #include <vcl/image.hxx>
      25             : #include <vcl/menu.hxx>
      26             : 
      27             : #include <cppuhelper/compbase4.hxx>
      28             : #include <cppuhelper/compbase5.hxx>
      29             : #include <comphelper/broadcasthelper.hxx>
      30             : 
      31             : #include <com/sun/star/frame/XFrame.hpp>
      32             : #include <com/sun/star/accessibility/XAccessible.hpp>
      33             : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
      34             : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
      35             : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
      36             : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
      37             : #include <com/sun/star/lang/DisposedException.hpp>
      38             : 
      39             : #include <rtl/ref.hxx>
      40             : 
      41             : #include <vector>
      42             : 
      43             : #include <svtools/framestatuslistener.hxx>
      44             : 
      45             : namespace svtools {
      46             : 
      47             : struct ToolbarMenu_Impl;
      48             : class ToolbarMenu;
      49             : class ToolbarMenuEntry;
      50             : 
      51             : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener > > EventListenerVector;
      52             : typedef std::vector< ToolbarMenuEntry * > ToolbarMenuEntryVector;
      53             : 
      54             : const int SEPARATOR_HEIGHT = 4;
      55             : const int TITLE_ID = -1;
      56             : const int BORDER_X = 0;
      57             : const int BORDER_Y = 0;
      58             : 
      59             : 
      60             : // - ToolbarMenuEntry -
      61             : 
      62             : 
      63             : class ToolbarMenuEntry
      64             : {
      65             : public:
      66             :     ToolbarMenu& mrMenu;
      67             : 
      68             :     int mnEntryId;
      69             :     MenuItemBits mnBits;
      70             :     Size maSize;
      71             : 
      72             :     bool mbHasText;
      73             :     bool mbHasImage;
      74             :     bool mbChecked;
      75             :     bool mbEnabled;
      76             : 
      77             :     OUString maText;
      78             :     Image maImage;
      79             :     VclPtr<Control> mpControl;
      80             :     Rectangle maRect;
      81             : 
      82             :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > mxAccContext;
      83             : 
      84             : public:
      85             :     ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const OUString& rText, MenuItemBits nBits );
      86             :     ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const Image& rImage, const OUString& rText, MenuItemBits nBits );
      87             :     ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, Control* pControl, MenuItemBits nBits );
      88             :     ~ToolbarMenuEntry();
      89             : 
      90             :     void init( int nEntryId, MenuItemBits nBits );
      91             : 
      92             :     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& GetAccessible( bool bCreate = false );
      93             : 
      94             :     sal_Int32 getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
      95             :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getAccessibleChild( sal_Int32 index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
      96             :     void selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
      97             : 
      98           0 :     bool HasCheck() const
      99             :     {
     100           0 :         return mbChecked || ( mnBits & ( MenuItemBits::RADIOCHECK | MenuItemBits::CHECKABLE | MenuItemBits::AUTOCHECK ) );
     101             :     }
     102             : };
     103             : 
     104             : 
     105             : // - ToolbarMenuAcc -
     106             : 
     107             : 
     108             : typedef ::cppu::WeakComponentImplHelper5<
     109             :     ::com::sun::star::accessibility::XAccessible,
     110             :     ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
     111             :     ::com::sun::star::accessibility::XAccessibleContext,
     112             :     ::com::sun::star::accessibility::XAccessibleComponent,
     113             :     ::com::sun::star::accessibility::XAccessibleSelection >
     114             :     ToolbarMenuAccComponentBase;
     115             : 
     116             : class ToolbarMenuAcc :
     117             :     public ::comphelper::OBaseMutex,
     118             :     public ToolbarMenuAccComponentBase
     119             : {
     120             : public:
     121             : 
     122             :     explicit ToolbarMenuAcc( ToolbarMenu_Impl& rParent );
     123             :     virtual ~ToolbarMenuAcc();
     124             : 
     125             :     void                FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
     126           0 :     bool                HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
     127             : 
     128             : public:
     129             : 
     130             :     // XAccessible
     131             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     132             : 
     133             :     // XAccessibleEventBroadcaster
     134             :     virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     135             :     virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     136             : 
     137             :     // XAccessibleContext
     138             :     virtual sal_Int32 SAL_CALL getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     139             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     140             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     141             :     virtual sal_Int32 SAL_CALL getAccessibleIndexInParent(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     142             :     virtual sal_Int16 SAL_CALL getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     143             :     virtual OUString SAL_CALL getAccessibleDescription(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     144             :     virtual OUString SAL_CALL getAccessibleName(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     145             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     147             :     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale(  ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     148             : 
     149             :     // XAccessibleComponent
     150             :     virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     151             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     152             :     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     153             :     virtual ::com::sun::star::awt::Point SAL_CALL getLocation(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     154             :     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     155             :     virtual ::com::sun::star::awt::Size SAL_CALL getSize(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     156             :     virtual void SAL_CALL grabFocus(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     157             :     virtual sal_Int32 SAL_CALL getForeground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     158             :     virtual sal_Int32 SAL_CALL getBackground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     159             : 
     160             :     // XAccessibleSelection
     161             :     virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     162             :     virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     163             :     virtual void SAL_CALL clearAccessibleSelection(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     164             :     virtual void SAL_CALL selectAllAccessibleChildren(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     165             :     virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     166             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     167             :     virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     168             : 
     169             :     DECL_LINK( WindowEventListener, VclSimpleEvent* );
     170             : 
     171             : private:
     172             :     EventListenerVector mxEventListeners;
     173             :     ToolbarMenu_Impl* mpParent;
     174             :     /// The current FOCUSED state.
     175             :     bool mbIsFocused;
     176             : 
     177             :     void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent );
     178             : 
     179             :     /** Tell all listeners that the object is dying.  This callback is
     180             :         usually called from the WeakComponentImplHelper class.
     181             :     */
     182             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     183             : 
     184             :     /** Check whether or not the object has been disposed (or is in the
     185             :         state of being disposed).  If that is the case then
     186             :         DisposedException is thrown to inform the (indirect) caller of the
     187             :         foul deed.
     188             :     */
     189             :     void ThrowIfDisposed() throw (::com::sun::star::lang::DisposedException);
     190             : };
     191             : 
     192             : 
     193             : // - ToolbarMenuEntryAcc -
     194             : 
     195             : 
     196             : typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::accessibility::XAccessible,
     197             :                                                      ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
     198             :                                                      ::com::sun::star::accessibility::XAccessibleContext,
     199             :                                                      ::com::sun::star::accessibility::XAccessibleComponent > ToolbarMenuEntryAccBase;
     200             : 
     201             : class ToolbarMenuEntryAcc : public ::comphelper::OBaseMutex,
     202             :                             public ToolbarMenuEntryAccBase
     203             : {
     204             : public:
     205             :     explicit ToolbarMenuEntryAcc( ToolbarMenuEntry* pParent );
     206             :     virtual ~ToolbarMenuEntryAcc();
     207             : 
     208             :     bool    HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
     209             : 
     210             :     // XAccessible
     211             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     212             : 
     213             :     // XAccessibleEventBroadcaster
     214             :     virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     215             :     virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     216             : 
     217             :     // XAccessibleContext
     218             :     virtual sal_Int32 SAL_CALL getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     219             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     220             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     221             :     virtual sal_Int32 SAL_CALL getAccessibleIndexInParent(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     222             :     virtual sal_Int16 SAL_CALL getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     223             :     virtual OUString SAL_CALL getAccessibleDescription(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     224             :     virtual OUString SAL_CALL getAccessibleName(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     225             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     226             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     227             :     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale(  ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     228             : 
     229             :     // XAccessibleComponent
     230             :     virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     231             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     232             :     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     233             :     virtual ::com::sun::star::awt::Point SAL_CALL getLocation(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     234             :     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     235             :     virtual ::com::sun::star::awt::Size SAL_CALL getSize(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     236             :     virtual void SAL_CALL grabFocus(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     237             :     virtual sal_Int32 SAL_CALL getForeground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     238             :     virtual sal_Int32 SAL_CALL getBackground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     239             : 
     240             : private:
     241             :     EventListenerVector    mxEventListeners;
     242             :     ::osl::Mutex           maMutex;
     243             :     ToolbarMenuEntry*      mpParent;
     244             : 
     245             :     /** Tell all listeners that the object is dying.  This callback is
     246             :         usually called from the WeakComponentImplHelper class.
     247             :     */
     248             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     249             : };
     250             : 
     251             : 
     252             : 
     253             : struct ToolbarMenu_Impl
     254             : {
     255             :     ToolbarMenu& mrMenu;
     256             : 
     257             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >              mxFrame;
     258             :     rtl::Reference< svt::FrameStatusListener >                                       mxStatusListener;
     259             :     rtl::Reference< ToolbarMenuAcc >                                                 mxAccessible;
     260             :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > mxOldSelection;
     261             : 
     262             :     ToolbarMenuEntryVector  maEntryVector;
     263             : 
     264             :     int mnCheckPos;
     265             :     int mnImagePos;
     266             :     int mnTextPos;
     267             : 
     268             :     int mnHighlightedEntry;
     269             :     int mnSelectedEntry;
     270             :     int mnLastColumn;
     271             : 
     272             :     Size maSize;
     273             : 
     274             :     Link<>          maSelectHdl;
     275             : 
     276             :     ToolbarMenu_Impl( ToolbarMenu& rMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame );
     277             :     ~ToolbarMenu_Impl();
     278             : 
     279             :     void setAccessible( ToolbarMenuAcc* pAccessible );
     280             : 
     281             :     void fireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
     282             :     bool hasAccessibleListeners();
     283             : 
     284             :     sal_Int32 getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
     285             :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getAccessibleChild( sal_Int32 index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
     286             :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getAccessibleChild( Control* pControl, sal_Int32 childIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
     287             : 
     288             :     void selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
     289             :     bool isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
     290             :     void clearAccessibleSelection();
     291             : 
     292             :     ToolbarMenuEntry* implGetEntry( int nEntry ) const;
     293             :     void notifyHighlightedEntry();
     294             : 
     295             :     void implHighlightControl( sal_uInt16 nCode, Control* pControl );
     296             : };
     297             : 
     298             : }
     299             : 
     300             : #endif // INCLUDED_SVTOOLS_SOURCE_CONTROL_TOOLBARMENUIMP_HXX
     301             : 
     302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11