LCOV - code coverage report
Current view: top level - include/sfx2 - tbxctrl.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 8 0.0 %
Date: 2014-04-14 Functions: 0 4 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             : #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           0 :     SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor,
      59             :             TypeId nTheTypeId, sal_uInt16 nTheSlotId ):
      60             :         pCtor(pTheCtor),
      61             :         nTypeId(nTheTypeId),
      62           0 :         nSlotId(nTheSlotId)
      63           0 :     {}
      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 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     143             :                                             const ResId &rId );
     144             :                             SfxPopupWindow( sal_uInt16 nId,
     145             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     146             :                                             Window* pParentWindow,
     147             :                                             WinBits nBits );
     148             :                             SfxPopupWindow( sal_uInt16 nId,
     149             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     150             :                                             Window* pParentWindow,
     151             :                                             const ResId &rId );
     152             :                             virtual ~SfxPopupWindow();
     153             : 
     154             :     virtual SfxPopupWindow* Clone() const;
     155             :     virtual void            MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     156             : 
     157             :     void                    StartCascading();
     158           0 :     SAL_DLLPRIVATE void SetDeleteLink_Impl( const Link& rLink )
     159             :                             {
     160           0 :                                 m_aDeleteLink = rLink;
     161           0 :                             }
     162             : };
     163             : 
     164             : 
     165             : 
     166             : #define SFX_DECL_TOOLBOX_CONTROL() \
     167             :         static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \
     168             :         static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL)
     169             : 
     170             : /*  For special ToolBox controls, such as a font selection box or toolbox
     171             :     tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
     172             :     has to be implemented.
     173             : 
     174             :     This class has to be registered in SfxApplication:Init() with the static
     175             :     control method RegisterControl(). The SFx then automatically creates these
     176             :     controls in the toolbox, if the associated slots are of the specific type.
     177             :  */
     178             : 
     179             : struct SfxToolBoxControl_Impl;
     180             : class SFX2_DLLPUBLIC SfxToolBoxControl:
     181             :                          public ::com::sun::star::awt::XDockableWindowListener,
     182             :                          public ::com::sun::star::frame::XSubToolbarController,
     183             :                          public svt::ToolboxController
     184             : 
     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 Window*            CreateItemWindow( Window *pParent );
     206             : 
     207             :     // Must be called by subclass to set a new popup window instance
     208             :     void                       SetPopupWindow( SfxPopupWindow* pWindow );
     209             : 
     210             :     // XInterface
     211             :     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     212             :     virtual void               SAL_CALL acquire() throw() SAL_OVERRIDE;
     213             :     virtual void               SAL_CALL release() throw() SAL_OVERRIDE;
     214             : 
     215             :     // XEventListener
     216             :     using ::cppu::OPropertySetHelper::disposing;
     217             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     218             : 
     219             :     // XComponent
     220             :     virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     221             : 
     222             :     // new controller API
     223             :     // XStatusListener
     224             :     virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
     225             :         throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     226             : 
     227             :     // XToolbarController
     228             :     virtual void SAL_CALL execute( sal_Int16 KeyModifier )
     229             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     230             :     virtual void SAL_CALL click()
     231             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     232             :     virtual void SAL_CALL doubleClick()
     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 createPopupWindow()
     235             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     236             :     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 )
     237             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     238             : 
     239             :     // XSubToolbarController
     240             :     virtual sal_Bool SAL_CALL opensSubToolbar(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     241             :     virtual OUString SAL_CALL getSubToolbarName(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     242             :     virtual void SAL_CALL functionSelected( const OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     243             :     virtual void SAL_CALL updateImage(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     244             : 
     245             :     //  XDockableWindowListener
     246             :     virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     247             :     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;
     248             :     virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     249             :     virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     250             :     virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     251             :     virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     252             :     virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     253             : 
     254             :     // helper methods
     255             :     void    createAndPositionSubToolBar( const OUString& rSubToolBarResName );
     256             :     ::Size  getPersistentFloatingSize( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const OUString& rSubToolBarResName );
     257             :     bool    hasBigImages() const;
     258             : 
     259             : public:
     260             :                                SFX_DECL_TOOLBOX_CONTROL();
     261             : 
     262             :                                SfxToolBoxControl( sal_uInt16 nSlotID, sal_uInt16 nId, ToolBox& rBox, bool bShowStrings = false );
     263             :     virtual                    ~SfxToolBoxControl();
     264             : 
     265             :     ToolBox&                   GetToolBox() const;
     266             :     unsigned short             GetId() const;
     267             :     unsigned short             GetSlotId() const;
     268             : 
     269             :     void                       Dispatch( const OUString& aCommand,
     270             :                                          ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
     271             :     static void                Dispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
     272             :                                          const OUString& rCommand,
     273             :                                          ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
     274             : 
     275             :     static SfxItemState        GetItemState( const SfxPoolItem* pState );
     276             :     static SfxToolBoxControl*  CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule *pMod );
     277             :     static void                RegisterToolBoxControl( SfxModule*, SfxTbxCtrlFactory*);
     278             : };
     279             : 
     280             : #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
     281             :         SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
     282             :                { return new Class( nSlotId, nId, rTbx ); } \
     283             :         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
     284             :                { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
     285             :                     Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
     286             : 
     287             : #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
     288             :         SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
     289             :                { return new Class( nSlotId, nId, rTbx, Arg); } \
     290             :         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
     291             :                { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
     292             :                     Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
     293             : 
     294             : 
     295             : 
     296             : 
     297             : class SfxDragButton_Impl : public FixedImage
     298             : {
     299             : public:
     300             : 
     301             :                     SfxDragButton_Impl( Window *pParent );
     302             :     virtual void    Command ( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     303             :     virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     304             :     virtual void    MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     305             : };
     306             : 
     307             : class SfxDragToolBoxControl_Impl : public SfxToolBoxControl
     308             : {
     309             : public:
     310             :                             SFX_DECL_TOOLBOX_CONTROL();
     311             :                             SfxDragToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox );
     312             :     virtual Window*         CreateItemWindow( Window *pParent ) SAL_OVERRIDE;
     313             :     virtual void            Select(sal_uInt16 nSelectModifier) SAL_OVERRIDE;
     314             : };
     315             : 
     316             : 
     317             : 
     318             : /** Toolbox that implements recent files menu for the Open file toolbar button.
     319             : 
     320             : To use that, the appropriate Sfx*Item (like Open, OpenFromCalc, or
     321             : OpenFromWriter) has to have SlotType = SfxStringItem, and the appropriate
     322             : module initialization has to call RegisterControl().
     323             : */
     324             : class SfxRecentFilesToolBoxControl : public SfxToolBoxControl
     325             : {
     326             : public:
     327             :     // We don't use SFX_DECL_TOOLBOX_CONTROL() here as we need to have this
     328             :     // RegisterControl() marked as SFX2_DLLPUBLIC
     329             :     static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx );
     330             :     static void SFX2_DLLPUBLIC RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL);
     331             : 
     332             :     SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     333             :     virtual ~SfxRecentFilesToolBoxControl();
     334             : 
     335             : protected:
     336             :     virtual SfxPopupWindow* CreatePopupWindow() SAL_OVERRIDE;
     337             : };
     338             : 
     339             : class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl
     340             : {
     341             :     protected:
     342             :         virtual void Select(sal_uInt16 nSelectModifier ) SAL_OVERRIDE;
     343             : 
     344             :     public:
     345             :     SFX_DECL_TOOLBOX_CONTROL();
     346             :         SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     347             : };
     348             : 
     349             : class SfxPopupMenuManager;
     350             : class SfxAddonsToolBoxControl_Impl : public SfxToolBoxControl
     351             : 
     352             : /*  [Description]
     353             : 
     354             :     Internal helper class to provide the addons popup menu through the addons
     355             :     toolbox button.
     356             : */
     357             : 
     358             : {
     359             :     bool        bBigImages;
     360             :     PopupMenu*  pMenu;
     361             :     bool        m_bShowMenuImages;
     362             : 
     363             : protected:
     364             :     virtual void            Click() SAL_OVERRIDE;
     365             :     virtual void            Select(sal_uInt16 nSelectModifier) SAL_OVERRIDE;
     366             :     virtual void            StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) SAL_OVERRIDE;
     367             :                             DECL_LINK( Activate, Menu * );
     368             : public:
     369             :                             SFX_DECL_TOOLBOX_CONTROL();
     370             :                             SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     371             :                             virtual ~SfxAddonsToolBoxControl_Impl();
     372             : 
     373             :                             void RefreshMenuImages( Menu* pMenu );
     374             : };
     375             : 
     376             : #endif
     377             : 
     378             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10