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

Generated by: LCOV version 1.10