bump product version to 4.2.0.1
[LibreOffice.git] / include / sfx2 / tbxctrl.hxx
blobc859d1a2f7c0e243c7de2458aac6c6b836fdd5bb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
44 class SfxBindings;
45 class SfxModule;
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;
55 TypeId nTypeId;
56 sal_uInt16 nSlotId;
58 SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor,
59 TypeId nTheTypeId, sal_uInt16 nTheSlotId ):
60 pCtor(pTheCtor),
61 nTypeId(nTheTypeId),
62 nSlotId(nTheSlotId)
66 //------------------------------------------------------------------
68 enum SfxPopupWindowType
70 SFX_POPUPWINDOW_NONE,
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
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();
88 // XStatusListener
89 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
90 throw ( ::com::sun::star::uno::RuntimeException );
92 private:
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;
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;
114 private:
115 SfxFrameStatusListener* GetOrCreateStatusListener();
117 SAL_DLLPRIVATE SfxPopupWindow(SfxPopupWindow &); // not defined
118 SAL_DLLPRIVATE void operator =(SfxPopupWindow &); // not defined
119 void Delete();
121 protected:
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; }
129 void BindListener();
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 );
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( sal_uInt16 nId,
150 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
151 Window* pParentWindow,
152 const ResId &rId );
153 ~SfxPopupWindow();
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;
193 protected:
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 );
212 // XInterface
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();
217 // XEventListener
218 using ::cppu::OPropertySetHelper::disposing;
219 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
221 // XComponent
222 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
224 // new controller API
225 // XStatusListener
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);
256 // helper methods
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;
261 public:
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
301 public:
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
311 public:
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
329 public:
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();
338 protected:
339 virtual SfxPopupWindow* CreatePopupWindow();
342 class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl
344 protected:
345 using SfxToolBoxControl::Select;
346 virtual void Select( sal_uInt16 nSelectModifier );
348 public:
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
356 /* [Description]
358 Internal helper class to provide the addons popup menu through the addons
359 toolbox button.
363 sal_Bool bBigImages;
364 PopupMenu* pMenu;
365 sal_Bool m_bShowMenuImages;
367 protected:
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 * );
373 public:
374 SFX_DECL_TOOLBOX_CONTROL();
375 SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
376 ~SfxAddonsToolBoxControl_Impl();
378 void RefreshMenuImages( Menu* pMenu );
381 #endif
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */