1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _SFXTBXCTRL_HXX
20 #define _SFXTBXCTRL_HXX
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>
41 //------------------------------------------------------------------
43 class SfxToolBoxControl
;
46 class SfxUnoControllerItem
;
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
);
50 typedef SfxToolBoxControl
* (*SfxToolBoxControlCtor
)( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
52 struct SfxTbxCtrlFactory
54 SfxToolBoxControlCtor pCtor
;
58 SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor
,
59 TypeId nTheTypeId
, sal_uInt16 nTheSlotId
):
66 //------------------------------------------------------------------
68 enum SfxPopupWindowType
71 SFX_POPUPWINDOW_ONCLICK
,
72 SFX_POPUPWINDOW_ONTIMEOUT
,
73 SFX_POPUPWINDOW_ONCLICKANDMOVE
,
74 SFX_POPUPWINDOW_ONTIMEOUTANDMOVE
,
75 SFX_POPUPWINDOW_CONTEXTMENU
78 //------------------------------------------------------------------
80 class SfxFrameStatusListener
: public svt::FrameStatusListener
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();
89 virtual void SAL_CALL
statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
)
90 throw ( ::com::sun::star::uno::RuntimeException
);
93 SfxStatusListenerInterface
* m_pCallee
;
96 //------------------------------------------------------------------
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.
103 class SFX2_DLLPUBLIC SfxPopupWindow
: public FloatingWindow
, public SfxStatusListenerInterface
105 sal_Bool m_bFloating
;
106 sal_uIntPtr m_nEventId
;
107 sal_Bool m_bCascading
;
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
;
115 SfxFrameStatusListener
* GetOrCreateStatusListener();
117 SAL_DLLPRIVATE
SfxPopupWindow(SfxPopupWindow
&); // not defined
118 SAL_DLLPRIVATE
void operator =(SfxPopupWindow
&); // not defined
122 virtual void PopupModeEnd();
123 virtual sal_Bool
Close();
124 virtual void DeleteFloatingWindow();
126 sal_uInt16
GetId() const { return m_nId
; }
127 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& GetFrame() const { return m_xFrame
; }
130 void UnbindListener();
131 void AddStatusListener( const OUString
& rCommandURL
);
133 // SfxStatusListenerInterface
134 using FloatingWindow::StateChanged
;
135 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
,
136 const SfxPoolItem
* pState
);
139 SfxPopupWindow( sal_uInt16 nId
,
140 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
,
142 SfxPopupWindow( sal_uInt16 nId
,
143 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
,
145 SfxPopupWindow( sal_uInt16 nId
,
146 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
,
147 Window
* pParentWindow
,
151 virtual SfxPopupWindow
* Clone() const;
152 virtual void MouseMove( const MouseEvent
& rMEvt
);
154 void StartCascading();
155 SAL_DLLPRIVATE
void SetDeleteLink_Impl( const Link
& rLink
)
157 m_aDeleteLink
= rLink
;
161 //------------------------------------------------------------------
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)
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.
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.
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
183 friend class SfxToolbox
;
184 friend class SfxPopupWindow
;
185 friend struct SfxTbxCtrlFactory
;
187 SfxToolBoxControl_Impl
* pImpl
;
190 DECL_LINK( PopupModeEndHdl
, void * );
191 DECL_LINK( ClosePopupWindow
, SfxPopupWindow
* );
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
);
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
);
205 // Must be called by subclass to set a new popup window instance
206 void SetPopupWindow( SfxPopupWindow
* pWindow
);
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();
214 using ::cppu::OPropertySetHelper::disposing
;
215 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
218 virtual void SAL_CALL
dispose() throw (::com::sun::star::uno::RuntimeException
);
220 // new controller API
222 virtual void SAL_CALL
statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
)
223 throw ( ::com::sun::star::uno::RuntimeException
);
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
);
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
);
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
);
253 void createAndPositionSubToolBar( const OUString
& rSubToolBarResName
);
254 ::Size
getPersistentFloatingSize( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
, const OUString
& rSubToolBarResName
);
257 SFX_DECL_TOOLBOX_CONTROL();
259 SfxToolBoxControl( sal_uInt16 nSlotID
, sal_uInt16 nId
, ToolBox
& rBox
, sal_Bool bShowStrings
= sal_False
);
260 virtual ~SfxToolBoxControl();
262 ToolBox
& GetToolBox() const;
263 unsigned short GetId() const;
264 unsigned short GetSlotId() const;
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
);
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
*);
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 ) ); }
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 ) ); }
291 //=========================================================================
294 class SfxDragButton_Impl
: public FixedImage
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
);
304 class SfxDragToolBoxControl_Impl
: public SfxToolBoxControl
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
);
314 //------------------------------------------------------------------------
316 class SfxAppToolBoxControl_Impl
: public SfxToolBoxControl
320 Internal helper class for the pop-up menu <AppMenu_Impl> under new
326 SFX_DECL_TOOLBOX_CONTROL();
327 SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
328 ~SfxAppToolBoxControl_Impl();
329 void SetImage( const String
& rFacName
);
333 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> xDispatch
;
334 ::com::sun::star::util::URL aTargetURL
;
335 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs
;
338 DECL_STATIC_LINK( SfxAppToolBoxControl_Impl
, ExecuteHdl_Impl
, ExecuteInfo
* );
341 virtual void Click();
342 using SfxToolBoxControl::Select
;
343 virtual void Select( sal_Bool
);
344 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
345 virtual SfxPopupWindow
* CreatePopupWindow();
346 DECL_LINK( Activate
, Menu
* );
350 sal_uIntPtr m_nSymbolsStyle
;
351 sal_Bool m_bShowMenuImages
;
354 /** Toolbox that implements recent files menu for the Open file toolbar button.
356 To use that, the appropriate Sfx*Item (like Open, OpenFromCalc, or
357 OpenFromWriter) has to have SlotType = SfxStringItem, and the appropriate
358 module initialization has to call RegisterControl().
360 class SfxRecentFilesToolBoxControl
: public SfxToolBoxControl
363 // We don't use SFX_DECL_TOOLBOX_CONTROL() here as we need to have this
364 // RegisterControl() marked as SFX2_DLLPUBLIC
365 static SfxToolBoxControl
* CreateImpl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
&rTbx
);
366 static void SFX2_DLLPUBLIC
RegisterControl(sal_uInt16 nSlotId
= 0, SfxModule
*pMod
=NULL
);
368 SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
369 virtual ~SfxRecentFilesToolBoxControl();
372 virtual SfxPopupWindow
* CreatePopupWindow();
375 class SfxReloadToolBoxControl_Impl
: public SfxToolBoxControl
378 using SfxToolBoxControl::Select
;
379 virtual void Select( sal_uInt16 nSelectModifier
);
382 SFX_DECL_TOOLBOX_CONTROL();
383 SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
386 class SfxPopupMenuManager
;
387 class SfxAddonsToolBoxControl_Impl
: public SfxToolBoxControl
391 Internal helper class to provide the addons popup menu through the addons
398 sal_Bool m_bShowMenuImages
;
401 virtual void Click();
402 using SfxToolBoxControl::Select
;
403 virtual void Select( sal_Bool
);
404 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
405 DECL_LINK( Activate
, Menu
* );
407 SFX_DECL_TOOLBOX_CONTROL();
408 SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
409 ~SfxAddonsToolBoxControl_Impl();
411 void RefreshMenuImages( Menu
* pMenu
);
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */