LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/sfx2 - tbxctrl.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 8 37.5 %
Date: 2013-07-09 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 _SFXTBXCTRL_HXX
      20             : #define _SFXTBXCTRL_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        4854 :     SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor,
      59             :             TypeId nTheTypeId, sal_uInt16 nTheSlotId ):
      60             :         pCtor(pTheCtor),
      61             :         nTypeId(nTheTypeId),
      62        4854 :         nSlotId(nTheSlotId)
      63        4854 :     {}
      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 );
      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             :     sal_Bool                                                                             m_bFloating;
     106             :     sal_uIntPtr                                                                            m_nEventId;
     107             :     sal_Bool                                                                             m_bCascading;
     108             :     Link                                                                             m_aDeleteLink;
     109             :     sal_uInt16                                                                           m_nId;
     110             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >              m_xFrame;
     111             :     SfxFrameStatusListener*                                                          m_pStatusListener;
     112             :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >           m_xStatusListener;
     113             : 
     114             : private:
     115             :     SfxFrameStatusListener* GetOrCreateStatusListener();
     116             : 
     117             :     SAL_DLLPRIVATE SfxPopupWindow(SfxPopupWindow &); // not defined
     118             :     SAL_DLLPRIVATE void operator =(SfxPopupWindow &); // not defined
     119             :     void Delete();
     120             : 
     121             : protected:
     122             :     virtual void            PopupModeEnd();
     123             :     virtual sal_Bool            Close();
     124             :     virtual void            DeleteFloatingWindow();
     125             : 
     126           0 :     sal_uInt16                  GetId() const { return m_nId; }
     127           0 :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& GetFrame() const { return m_xFrame; }
     128             : 
     129             :     void                    BindListener();
     130             :     void                    UnbindListener();
     131             :     void                    AddStatusListener( const OUString& rCommandURL );
     132             : 
     133             :     // SfxStatusListenerInterface
     134             :     using FloatingWindow::StateChanged;
     135             :     virtual void            StateChanged( sal_uInt16 nSID, SfxItemState eState,
     136             :                                           const SfxPoolItem* pState );
     137             : 
     138             : public:
     139             :                             SfxPopupWindow( sal_uInt16 nId,
     140             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     141             :                                             WinBits nBits );
     142             :                             SfxPopupWindow( sal_uInt16 nId,
     143             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     144             :                                             const ResId &rId );
     145             :                             SfxPopupWindow( sal_uInt16 nId,
     146             :                                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     147             :                                             Window* pParentWindow,
     148             :                                             WinBits nBits );
     149             :                             ~SfxPopupWindow();
     150             : 
     151             :     virtual SfxPopupWindow* Clone() const;
     152             :     virtual void            MouseMove( const MouseEvent& rMEvt );
     153             : 
     154             :     void                    StartCascading();
     155           0 :     SAL_DLLPRIVATE void SetDeleteLink_Impl( const Link& rLink )
     156             :                             {
     157           0 :                                 m_aDeleteLink = rLink;
     158           0 :                             }
     159             : };
     160             : 
     161             : //------------------------------------------------------------------
     162             : 
     163             : #define SFX_DECL_TOOLBOX_CONTROL() \
     164             :         static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \
     165             :         static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL)
     166             : 
     167             : /*  For special ToolBox controls, such as a font selection box or toolbox
     168             :     tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
     169             :     has to be implemented.
     170             : 
     171             :     This class has to be registered in SfxApplication:Init() with the static
     172             :     control method RegisterControl(). The SFx then automatically creates these
     173             :     controls in the toolbox, if the associated slots are of the specific type.
     174             :  */
     175             : 
     176             : struct SfxToolBoxControl_Impl;
     177             : class SFX2_DLLPUBLIC SfxToolBoxControl:
     178             :                          public ::com::sun::star::awt::XDockableWindowListener,
     179             :                          public ::com::sun::star::frame::XSubToolbarController,
     180             :                          public svt::ToolboxController
     181             : 
     182             : {
     183             : friend class SfxToolbox;
     184             : friend class SfxPopupWindow;
     185             : friend struct SfxTbxCtrlFactory;
     186             : 
     187             :     SfxToolBoxControl_Impl*    pImpl;
     188             : 
     189             : protected:
     190             :     DECL_LINK( PopupModeEndHdl, void * );
     191             :     DECL_LINK( ClosePopupWindow, SfxPopupWindow * );
     192             : 
     193             :     // old SfxToolBoxControl methods
     194             :     virtual void               StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
     195             :     virtual void               Select( sal_Bool bMod1 = sal_False );
     196             :     virtual void               Select( sal_uInt16 nModifier );
     197             : 
     198             :     virtual void               DoubleClick();
     199             :     virtual void               Click();
     200             :     virtual SfxPopupWindowType GetPopupWindowType() const;
     201             :     virtual SfxPopupWindow*    CreatePopupWindow();
     202             :     virtual SfxPopupWindow*    CreatePopupWindowCascading();
     203             :     virtual Window*            CreateItemWindow( Window *pParent );
     204             : 
     205             :     // Must be called by subclass to set a new popup window instance
     206             :     void                       SetPopupWindow( SfxPopupWindow* pWindow );
     207             : 
     208             :     // XInterface
     209             :     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
     210             :     virtual void               SAL_CALL acquire() throw();
     211             :     virtual void               SAL_CALL release() throw();
     212             : 
     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 );
     216             : 
     217             :     // XComponent
     218             :     virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
     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 );
     224             : 
     225             :     // XToolbarController
     226             :     virtual void SAL_CALL execute( sal_Int16 KeyModifier )
     227             :         throw (::com::sun::star::uno::RuntimeException);
     228             :     virtual void SAL_CALL click()
     229             :         throw (::com::sun::star::uno::RuntimeException);
     230             :     virtual void SAL_CALL doubleClick()
     231             :         throw (::com::sun::star::uno::RuntimeException);
     232             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow()
     233             :         throw (::com::sun::star::uno::RuntimeException);
     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);
     236             : 
     237             :     // XSubToolbarController
     238             :     virtual ::sal_Bool SAL_CALL opensSubToolbar(  ) throw (::com::sun::star::uno::RuntimeException);
     239             :     virtual OUString SAL_CALL getSubToolbarName(  ) throw (::com::sun::star::uno::RuntimeException);
     240             :     virtual void SAL_CALL functionSelected( const OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException);
     241             :     virtual void SAL_CALL updateImage(  ) throw (::com::sun::star::uno::RuntimeException);
     242             : 
     243             :     //  XDockableWindowListener
     244             :     virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
     245             :     virtual ::com::sun::star::awt::DockingData SAL_CALL docking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
     246             :     virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
     247             :     virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
     248             :     virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
     249             :     virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
     250             :     virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException);
     251             : 
     252             :     // helper methods
     253             :     void    createAndPositionSubToolBar( const OUString& rSubToolBarResName );
     254             :     ::Size  getPersistentFloatingSize( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const OUString& rSubToolBarResName );
     255             : 
     256             : public:
     257             :                                SFX_DECL_TOOLBOX_CONTROL();
     258             : 
     259             :                                SfxToolBoxControl( sal_uInt16 nSlotID, sal_uInt16 nId, ToolBox& rBox, sal_Bool bShowStrings = sal_False );
     260             :     virtual                    ~SfxToolBoxControl();
     261             : 
     262             :     ToolBox&                   GetToolBox() const;
     263             :     unsigned short             GetId() const;
     264             :     unsigned short             GetSlotId() const;
     265             : 
     266             :     void                       Dispatch( const OUString& aCommand,
     267             :                                          ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
     268             :     static void                Dispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
     269             :                                          const OUString& rCommand,
     270             :                                          ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
     271             : 
     272             :     static SfxItemState        GetItemState( const SfxPoolItem* pState );
     273             :     static SfxToolBoxControl*  CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule *pMod );
     274             :     static void                RegisterToolBoxControl( SfxModule*, SfxTbxCtrlFactory*);
     275             : };
     276             : 
     277             : #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
     278             :         SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
     279             :                { return new Class( nSlotId, nId, rTbx ); } \
     280             :         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
     281             :                { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
     282             :                     Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
     283             : 
     284             : #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
     285             :         SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
     286             :                { return new Class( nSlotId, nId, rTbx, Arg); } \
     287             :         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
     288             :                { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
     289             :                     Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
     290             : 
     291             : //=========================================================================
     292             : 
     293             : 
     294             : class SfxDragButton_Impl : public FixedImage
     295             : {
     296             : public:
     297             : 
     298             :                     SfxDragButton_Impl( Window *pParent );
     299             :     virtual void    Command ( const CommandEvent& rCEvt );
     300             :     virtual void    MouseMove( const MouseEvent& rMEvt );
     301             :     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
     302             : };
     303             : 
     304             : class SfxDragToolBoxControl_Impl : public SfxToolBoxControl
     305             : {
     306             : public:
     307             :                             SFX_DECL_TOOLBOX_CONTROL();
     308             :                             SfxDragToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox );
     309             :     virtual Window*         CreateItemWindow( Window *pParent );
     310             :     using SfxToolBoxControl::Select;
     311             :     virtual void            Select( sal_Bool bMod1 = sal_False );
     312             : };
     313             : 
     314             : //------------------------------------------------------------------------
     315             : 
     316             : /** Toolbox that implements recent files menu for the Open file toolbar button.
     317             : 
     318             : To use that, the appropriate Sfx*Item (like Open, OpenFromCalc, or
     319             : OpenFromWriter) has to have SlotType = SfxStringItem, and the appropriate
     320             : module initialization has to call RegisterControl().
     321             : */
     322             : class SfxRecentFilesToolBoxControl : public SfxToolBoxControl
     323             : {
     324             : public:
     325             :     // We don't use SFX_DECL_TOOLBOX_CONTROL() here as we need to have this
     326             :     // RegisterControl() marked as SFX2_DLLPUBLIC
     327             :     static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx );
     328             :     static void SFX2_DLLPUBLIC RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL);
     329             : 
     330             :     SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     331             :     virtual ~SfxRecentFilesToolBoxControl();
     332             : 
     333             : protected:
     334             :     virtual SfxPopupWindow* CreatePopupWindow();
     335             : };
     336             : 
     337             : class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl
     338             : {
     339             :     protected:
     340             :         using SfxToolBoxControl::Select;
     341             :         virtual void Select( sal_uInt16 nSelectModifier );
     342             : 
     343             :     public:
     344             :     SFX_DECL_TOOLBOX_CONTROL();
     345             :         SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     346             : };
     347             : 
     348             : class SfxPopupMenuManager;
     349             : class SfxAddonsToolBoxControl_Impl : public SfxToolBoxControl
     350             : 
     351             : /*  [Description]
     352             : 
     353             :     Internal helper class to provide the addons popup menu through the addons
     354             :     toolbox button.
     355             : */
     356             : 
     357             : {
     358             :     sal_Bool        bBigImages;
     359             :     PopupMenu*  pMenu;
     360             :     sal_Bool        m_bShowMenuImages;
     361             : 
     362             : protected:
     363             :     virtual void            Click();
     364             :     using SfxToolBoxControl::Select;
     365             :     virtual void            Select( sal_Bool );
     366             :     virtual void            StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
     367             :                             DECL_LINK( Activate, Menu * );
     368             : public:
     369             :                             SFX_DECL_TOOLBOX_CONTROL();
     370             :                             SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
     371             :                             ~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