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

Generated by: LCOV version 1.10