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 INCLUDED_SFX2_TBXCTRL_HXX
20 #define INCLUDED_SFX2_TBXCTRL_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
,
149 SfxPopupWindow( sal_uInt16 nId
,
150 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
,
151 Window
* pParentWindow
,
155 virtual SfxPopupWindow
* Clone() const;
156 virtual void MouseMove( const MouseEvent
& rMEvt
);
158 void StartCascading();
159 SAL_DLLPRIVATE
void SetDeleteLink_Impl( const Link
& rLink
)
161 m_aDeleteLink
= rLink
;
165 //------------------------------------------------------------------
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)
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.
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.
180 struct SfxToolBoxControl_Impl
;
181 class SFX2_DLLPUBLIC SfxToolBoxControl
:
182 public ::com::sun::star::awt::XDockableWindowListener
,
183 public ::com::sun::star::frame::XSubToolbarController
,
184 public svt::ToolboxController
187 friend class SfxToolbox
;
188 friend class SfxPopupWindow
;
189 friend struct SfxTbxCtrlFactory
;
191 SfxToolBoxControl_Impl
* pImpl
;
194 DECL_LINK( PopupModeEndHdl
, void * );
195 DECL_LINK( ClosePopupWindow
, SfxPopupWindow
* );
197 // old SfxToolBoxControl methods
198 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
199 virtual void Select( sal_Bool bMod1
= sal_False
);
200 virtual void Select( sal_uInt16 nModifier
);
202 virtual void DoubleClick();
203 virtual void Click();
204 virtual SfxPopupWindowType
GetPopupWindowType() const;
205 virtual SfxPopupWindow
* CreatePopupWindow();
206 virtual SfxPopupWindow
* CreatePopupWindowCascading();
207 virtual Window
* CreateItemWindow( Window
*pParent
);
209 // Must be called by subclass to set a new popup window instance
210 void SetPopupWindow( SfxPopupWindow
* pWindow
);
213 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
214 virtual void SAL_CALL
acquire() throw();
215 virtual void SAL_CALL
release() throw();
218 using ::cppu::OPropertySetHelper::disposing
;
219 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
222 virtual void SAL_CALL
dispose() throw (::com::sun::star::uno::RuntimeException
);
224 // new controller API
226 virtual void SAL_CALL
statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
)
227 throw ( ::com::sun::star::uno::RuntimeException
);
229 // XToolbarController
230 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
)
231 throw (::com::sun::star::uno::RuntimeException
);
232 virtual void SAL_CALL
click()
233 throw (::com::sun::star::uno::RuntimeException
);
234 virtual void SAL_CALL
doubleClick()
235 throw (::com::sun::star::uno::RuntimeException
);
236 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
createPopupWindow()
237 throw (::com::sun::star::uno::RuntimeException
);
238 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
)
239 throw (::com::sun::star::uno::RuntimeException
);
241 // XSubToolbarController
242 virtual ::sal_Bool SAL_CALL
opensSubToolbar( ) throw (::com::sun::star::uno::RuntimeException
);
243 virtual OUString SAL_CALL
getSubToolbarName( ) throw (::com::sun::star::uno::RuntimeException
);
244 virtual void SAL_CALL
functionSelected( const OUString
& aCommand
) throw (::com::sun::star::uno::RuntimeException
);
245 virtual void SAL_CALL
updateImage( ) throw (::com::sun::star::uno::RuntimeException
);
247 // XDockableWindowListener
248 virtual void SAL_CALL
startDocking( const ::com::sun::star::awt::DockingEvent
& e
) throw (::com::sun::star::uno::RuntimeException
);
249 virtual ::com::sun::star::awt::DockingData SAL_CALL
docking( const ::com::sun::star::awt::DockingEvent
& e
) throw (::com::sun::star::uno::RuntimeException
);
250 virtual void SAL_CALL
endDocking( const ::com::sun::star::awt::EndDockingEvent
& e
) throw (::com::sun::star::uno::RuntimeException
);
251 virtual sal_Bool SAL_CALL
prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject
& e
) throw (::com::sun::star::uno::RuntimeException
);
252 virtual void SAL_CALL
toggleFloatingMode( const ::com::sun::star::lang::EventObject
& e
) throw (::com::sun::star::uno::RuntimeException
);
253 virtual void SAL_CALL
closed( const ::com::sun::star::lang::EventObject
& e
) throw (::com::sun::star::uno::RuntimeException
);
254 virtual void SAL_CALL
endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent
& e
) throw (::com::sun::star::uno::RuntimeException
);
257 void createAndPositionSubToolBar( const OUString
& rSubToolBarResName
);
258 ::Size
getPersistentFloatingSize( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
, const OUString
& rSubToolBarResName
);
259 bool hasBigImages() const;
262 SFX_DECL_TOOLBOX_CONTROL();
264 SfxToolBoxControl( sal_uInt16 nSlotID
, sal_uInt16 nId
, ToolBox
& rBox
, sal_Bool bShowStrings
= sal_False
);
265 virtual ~SfxToolBoxControl();
267 ToolBox
& GetToolBox() const;
268 unsigned short GetId() const;
269 unsigned short GetSlotId() const;
271 void Dispatch( const OUString
& aCommand
,
272 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
);
273 static void Dispatch( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
>& rDispatchProvider
,
274 const OUString
& rCommand
,
275 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
);
277 static SfxItemState
GetItemState( const SfxPoolItem
* pState
);
278 static SfxToolBoxControl
* CreateControl( sal_uInt16 nSlotId
, sal_uInt16 nTbxId
, ToolBox
*pBox
, SfxModule
*pMod
);
279 static void RegisterToolBoxControl( SfxModule
*, SfxTbxCtrlFactory
*);
282 #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
283 SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
284 { return new Class( nSlotId, nId, rTbx ); } \
285 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
286 { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
287 Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
289 #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
290 SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
291 { return new Class( nSlotId, nId, rTbx, Arg); } \
292 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
293 { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
294 Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
296 //=========================================================================
299 class SfxDragButton_Impl
: public FixedImage
303 SfxDragButton_Impl( Window
*pParent
);
304 virtual void Command ( const CommandEvent
& rCEvt
);
305 virtual void MouseMove( const MouseEvent
& rMEvt
);
306 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
309 class SfxDragToolBoxControl_Impl
: public SfxToolBoxControl
312 SFX_DECL_TOOLBOX_CONTROL();
313 SfxDragToolBoxControl_Impl( sal_uInt16 nId
, ToolBox
& rBox
);
314 virtual Window
* CreateItemWindow( Window
*pParent
);
315 using SfxToolBoxControl::Select
;
316 virtual void Select( sal_Bool bMod1
= sal_False
);
319 //------------------------------------------------------------------------
321 /** Toolbox that implements recent files menu for the Open file toolbar button.
323 To use that, the appropriate Sfx*Item (like Open, OpenFromCalc, or
324 OpenFromWriter) has to have SlotType = SfxStringItem, and the appropriate
325 module initialization has to call RegisterControl().
327 class SfxRecentFilesToolBoxControl
: public SfxToolBoxControl
330 // We don't use SFX_DECL_TOOLBOX_CONTROL() here as we need to have this
331 // RegisterControl() marked as SFX2_DLLPUBLIC
332 static SfxToolBoxControl
* CreateImpl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
&rTbx
);
333 static void SFX2_DLLPUBLIC
RegisterControl(sal_uInt16 nSlotId
= 0, SfxModule
*pMod
=NULL
);
335 SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
336 virtual ~SfxRecentFilesToolBoxControl();
339 virtual SfxPopupWindow
* CreatePopupWindow();
342 class SfxReloadToolBoxControl_Impl
: public SfxToolBoxControl
345 using SfxToolBoxControl::Select
;
346 virtual void Select( sal_uInt16 nSelectModifier
);
349 SFX_DECL_TOOLBOX_CONTROL();
350 SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
353 class SfxPopupMenuManager
;
354 class SfxAddonsToolBoxControl_Impl
: public SfxToolBoxControl
358 Internal helper class to provide the addons popup menu through the addons
365 sal_Bool m_bShowMenuImages
;
368 virtual void Click();
369 using SfxToolBoxControl::Select
;
370 virtual void Select( sal_Bool
);
371 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
372 DECL_LINK( Activate
, Menu
* );
374 SFX_DECL_TOOLBOX_CONTROL();
375 SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
376 ~SfxAddonsToolBoxControl_Impl();
378 void RefreshMenuImages( Menu
* pMenu
);
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */