LCOV - code coverage report
Current view: top level - include/sfx2 - tbxctrl.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 8 37.5 %
Date: 2015-06-13 12:38:46 Functions: 1 4 25.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             : #ifndef INCLUDED_SFX2_TBXCTRL_HXX
      20             : #define INCLUDED_SFX2_TBXCTRL_HXX
      21             : 
      22             : #include <sal/config.h>
      23             : #include <sfx2/dllapi.h>
      24             : #include <sal/types.h>
      25             : #include <vcl/timer.hxx>
      26             : #include <vcl/menu.hxx>
      27             : #include <vcl/fixed.hxx>
      28             : #include <vcl/floatwin.hxx>
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <sfx2/ctrlitem.hxx>
      31             : #include <sfx2/sfxstatuslistener.hxx>
      32             : #include <svtools/toolboxcontroller.hxx>
      33             : #include <svtools/framestatuslistener.hxx>
      34             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      36             : #include <com/sun/star/frame/XFrame.hpp>
      37             : #include <com/sun/star/awt/XDockableWindowListener.hpp>
      38             : #include <com/sun/star/awt/XDockableWindow.hpp>
      39             : #include <com/sun/star/frame/XSubToolbarController.hpp>
      40             : 
      41             : 
      42             : class SfxToolBoxControl;
      43             : class SfxModule;
      44             : 
      45             : svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const OUString& aCommandURL );
      46             : 
      47             : typedef SfxToolBoxControl* (*SfxToolBoxControlCtor)( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
      48             : 
      49             : struct SfxTbxCtrlFactory
      50             : {
      51             :     SfxToolBoxControlCtor   pCtor;
      52             :     TypeId                  nTypeId;
      53             :     sal_uInt16                  nSlotId;
      54             : 
      55        8760 :     SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor,
      56             :             TypeId nTheTypeId, sal_uInt16 nTheSlotId ):
      57             :         pCtor(pTheCtor),
      58             :         nTypeId(nTheTypeId),
      59        8760 :         nSlotId(nTheSlotId)
      60        8760 :     {}
      61             : };
      62             : 
      63             : 
      64             : 
      65             : enum class SfxPopupWindowType
      66             : {
      67             :     NONE,
      68             :     ONCLICK,
      69             :     ONTIMEOUT,
      70             :     ONCLICKANDMOVE,
      71             :     ONTIMEOUTANDMOVE,
      72             :     CONTEXTMENU
      73             : };
      74             : 
      75             : 
      76             : 
      77             : class SfxFrameStatusListener : public svt::FrameStatusListener
      78             : {
      79             :     public:
      80             :         SfxFrameStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
      81             :                                 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
      82             :                                 SfxStatusListenerInterface* pCallee );
      83             :         virtual ~SfxFrameStatusListener();
      84             : 
      85             :         // XStatusListener
      86             :         virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
      87             :             throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      88             : 
      89             :     private:
      90             :         SfxStatusListenerInterface* m_pCallee;
      91             : };
      92             : 
      93             : 
      94             : 
      95             : /* Floating windows that can be torn from tool boxes should be derived from
      96             :    this class. Since it is also derived from SfxControllerItem, its instances
      97             :    will also receive the StateChanged calls.
      98             : */
      99             : 
     100             : class SFX2_DLLPUBLIC SfxPopupWindow: public FloatingWindow, public SfxStatusListenerInterface
     101             : {
     102             :     bool                                                                             m_bFloating;
     103             :     bool                                                                             m_bCascading;
     104             :     Link<>                                                                           m_aDeleteLink;
     105             :     sal_uInt16                                                                       m_nId;
     106             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >              m_xFrame;
     107             :     SfxFrameStatusListener*                                                          m_pStatusListener;
     108             :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >           m_xStatusListener;
     109             : 
     110             : private:
     111             :     SfxFrameStatusListener* GetOrCreateStatusListener();
     112             : 
     113             :     SfxPopupWindow(SfxPopupWindow &) SAL_DELETED_FUNCTION;
     114             :     void operator =(SfxPopupWindow &) SAL_DELETED_FUNCTION;
     115             :     void Delete();
     116             : 
     117             : protected:
     118             :     virtual void            PopupModeEnd() SAL_OVERRIDE;
     119             :     virtual bool            Close() SAL_OVERRIDE;
     120             :     void                    DeleteFloatingWindow();
     121             : 
     122           0 :     sal_uInt16              GetId() const { return m_nId; }
     123           0 :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& GetFrame() const { return m_xFrame; }
     124             : 
     125             :     void                    BindListener();
     126             :     void                    UnbindListener();
     127             :     void                    AddStatusListener( const OUString& rCommandURL );
     128             : 
     129             :     // SfxStatusListenerInterface
     130             :     using FloatingWindow::StateChanged;
     131             :     virtual void            StateChanged( sal_uInt16 nSID, SfxItemState eState,
     132             :                                           const SfxPoolItem* pState ) SAL_OVERRIDE;
     133             : 
     134             : public:
     135             :                             SfxPopupWindow( sal_uInt16 nId,
     136             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     137             :                                             WinBits nBits );
     138             :                             SfxPopupWindow(sal_uInt16 nId,
     139             :                                            const OString& rID, const OUString& rUIXMLDescription,
     140             :                                            const css::uno::Reference<css::frame::XFrame> &rFrame =
     141             :                                                css::uno::Reference<css::frame::XFrame>());
     142             :                             SfxPopupWindow(sal_uInt16 nId, vcl::Window *pParent,
     143             :                                            const OString& rID, const OUString& rUIXMLDescription,
     144             :                                            const css::uno::Reference<css::frame::XFrame> &rFrame =
     145             :                                                css::uno::Reference<css::frame::XFrame>());
     146             :                             SfxPopupWindow( sal_uInt16 nId,
     147             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     148             :                                             vcl::Window* pParentWindow,
     149             :                                             WinBits nBits );
     150             :                             virtual ~SfxPopupWindow();
     151             :     virtual void            dispose() SAL_OVERRIDE;
     152             : 
     153             :     virtual VclPtr<SfxPopupWindow> Clone() const;
     154             :     virtual void            MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     155             : 
     156             :     void                    StartCascading();
     157           0 :     SAL_DLLPRIVATE void SetDeleteLink_Impl( const Link<>& rLink )
     158             :                             {
     159           0 :                                 m_aDeleteLink = rLink;
     160           0 :                             }
     161             : };
     162             : 
     163             : 
     164             : 
     165             : #define SFX_DECL_TOOLBOX_CONTROL() \
     166             :         static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \
     167             :         static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL)
     168             : 
     169             : /*  For special ToolBox controls, such as a font selection box or toolbox
     170             :     tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
     171             :     has to be implemented.
     172             : 
     173             :     This class has to be registered in SfxApplication:Init() with the static
     174             :     control method RegisterControl(). The SFx then automatically creates these
     175             :     controls in the toolbox, if the associated slots are of the specific type.
     176             :  */
     177             : 
     178             : struct SfxToolBoxControl_Impl;
     179             : class SFX2_DLLPUBLIC SfxToolBoxControl:
     180             :     public cppu::ImplInheritanceHelper2<
     181             :         svt::ToolboxController, css::awt::XDockableWindowListener,
     182             :         css::frame::XSubToolbarController>
     183             : {
     184             : friend class SfxToolbox;
     185             : friend class SfxPopupWindow;
     186             : friend struct SfxTbxCtrlFactory;
     187             : 
     188             :     SfxToolBoxControl_Impl*    pImpl;
     189             : 
     190             : protected:
     191             :     DECL_LINK( PopupModeEndHdl, void * );
     192             :     DECL_LINK( ClosePopupWindow, SfxPopupWindow * );
     193             : 
     194             :     // old SfxToolBoxControl methods
     195             :     virtual void               StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
     196             :     virtual void               Select( sal_uInt16 nSelectModifier );
     197             : 
     198             :     virtual void               DoubleClick();
     199             :     virtual void               Click();
     200             :     virtual SfxPopupWindowType GetPopupWindowType() const;
     201             :     virtual VclPtr<SfxPopupWindow> CreatePopupWindow();
     202             :     virtual VclPtr<vcl::Window> CreateItemWindow( vcl::Window *pParent );
     203             : 
     204             :     // Must be called by subclass to set a new popup window instance
     205             :     void                       SetPopupWindow( SfxPopupWindow* pWindow );
     206             : 
     207             :     // helper methods
     208             :     void    createAndPositionSubToolBar( const OUString& rSubToolBarResName );
     209             :     static ::Size  getPersistentFloatingSize( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const OUString& rSubToolBarResName );
     210             :     bool    hasBigImages() const;
     211             : 
     212             : public:
     213             :     // XEventListener
     214             :     using ::cppu::OPropertySetHelper::disposing;
     215             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     216             : 
     217             :     // XComponent
     218             :     virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     219             : 
     220             :     // new controller API
     221             :     // XStatusListener
     222             :     virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
     223             :         throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     224             : 
     225             :     // XToolbarController
     226             :     virtual void SAL_CALL execute( sal_Int16 KeyModifier )
     227             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     228             :     virtual void SAL_CALL click()
     229             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     230             :     virtual void SAL_CALL doubleClick()
     231             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     232             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow()
     233             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     234             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createItemWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& rParent )
     235             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     236             : 
     237             :     // XSubToolbarController
     238             :     virtual sal_Bool SAL_CALL opensSubToolbar(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     239             :     virtual OUString SAL_CALL getSubToolbarName(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     240             :     virtual void SAL_CALL functionSelected( const OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     241             :     virtual void SAL_CALL updateImage(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     242             : 
     243             :     //  XDockableWindowListener
     244             :     virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     245             :     virtual ::com::sun::star::awt::DockingData SAL_CALL docking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     246             :     virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     247             :     virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     248             :     virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     249             :     virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     250             :     virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     251             : 
     252             : public:
     253             :                                SFX_DECL_TOOLBOX_CONTROL();
     254             : 
     255             :                                SfxToolBoxControl( sal_uInt16 nSlotID, sal_uInt16 nId, ToolBox& rBox, bool bShowStrings = false );
     256             :     virtual                    ~SfxToolBoxControl();
     257             : 
     258             :     ToolBox&                   GetToolBox() const;
     259             :     unsigned short             GetId() const;
     260             :     unsigned short             GetSlotId() const;
     261             : 
     262             :     void                       Dispatch( const OUString& aCommand,
     263             :                                          ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
     264             :     static void                Dispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
     265             :                                          const OUString& rCommand,
     266             :                                          ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
     267             : 
     268             :     static SfxItemState        GetItemState( const SfxPoolItem* pState );
     269             :     static SfxToolBoxControl*  CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule *pMod );
     270             :     static void                RegisterToolBoxControl( SfxModule*, SfxTbxCtrlFactory*);
     271             : };
     272             : 
     273             : #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
     274             :         SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
     275             :                { return new Class( nSlotId, nId, rTbx ); } \
     276             :         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
     277             :                { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
     278             :                     Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
     279             : 
     280             : #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
     281             :         SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
     282             :                { return new Class( nSlotId, nId, rTbx, Arg); } \
     283             :         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
     284             :                { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
     285             :                     Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
     286             : 
     287             : 
     288             : 
     289             : 
     290             : class SfxDragButton_Impl : public FixedImage
     291             : {
     292             : public:
     293             : 
     294             :                     SfxDragButton_Impl( vcl::Window *pParent );
     295             :     virtual void    Command ( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     296             :     virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     297             :     virtual void    MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     298             : };
     299             : 
     300             : class SfxDragToolBoxControl_Impl : public SfxToolBoxControl
     301             : {
     302             : public:
     303             :                             SFX_DECL_TOOLBOX_CONTROL();
     304             :                             SfxDragToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox );
     305             :     virtual VclPtr<vcl::Window> CreateItemWindow( vcl::Window *pParent ) SAL_OVERRIDE;
     306             :     virtual void            Select(sal_uInt16 nSelectModifier) SAL_OVERRIDE;
     307             : };
     308             : 
     309             : 
     310             : 
     311             : /** Toolbox that implements recent files menu for the Open file toolbar button.
     312             : 
     313             : To use that, the appropriate Sfx*Item (like Open, OpenFromCalc, or
     314             : OpenFromWriter) has to have SlotType = SfxStringItem, and the appropriate
     315             : module initialization has to call RegisterControl().
     316             : */
     317             : class SfxRecentFilesToolBoxControl : public SfxToolBoxControl
     318             : {
     319             : public:
     320             :     // We don't use SFX_DECL_TOOLBOX_CONTROL() here as we need to have this
     321             :     // RegisterControl() marked as SFX2_DLLPUBLIC
     322             :     static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx );
     323             :     static void SFX2_DLLPUBLIC RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL);
     324             : 
     325             :     SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     326             :     virtual ~SfxRecentFilesToolBoxControl();
     327             : 
     328             : protected:
     329             :     virtual VclPtr<SfxPopupWindow> CreatePopupWindow() SAL_OVERRIDE;
     330             : };
     331             : 
     332             : class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl
     333             : {
     334             :     protected:
     335             :         virtual void Select(sal_uInt16 nSelectModifier ) SAL_OVERRIDE;
     336             : 
     337             :     public:
     338             :     SFX_DECL_TOOLBOX_CONTROL();
     339             :         SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     340             : };
     341             : 
     342             : class SfxPopupMenuManager;
     343             : class SfxAddonsToolBoxControl_Impl : public SfxToolBoxControl
     344             : 
     345             : /*  [Description]
     346             : 
     347             :     Internal helper class to provide the addons popup menu through the addons
     348             :     toolbox button.
     349             : */
     350             : 
     351             : {
     352             :     bool        bBigImages;
     353             :     PopupMenu*  pMenu;
     354             :     bool        m_bShowMenuImages;
     355             : 
     356             : protected:
     357             :     virtual void            Click() SAL_OVERRIDE;
     358             :     virtual void            Select(sal_uInt16 nSelectModifier) SAL_OVERRIDE;
     359             :     virtual void            StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) SAL_OVERRIDE;
     360             :                             DECL_LINK( Activate, Menu * );
     361             : public:
     362             :                             SFX_DECL_TOOLBOX_CONTROL();
     363             :                             SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     364             :                             virtual ~SfxAddonsToolBoxControl_Impl();
     365             : 
     366             :                             void RefreshMenuImages( Menu* pMenu );
     367             : };
     368             : 
     369             : #endif
     370             : 
     371             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11