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 ::rtl::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 1095 : SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor,
59 : TypeId nTheTypeId, sal_uInt16 nTheSlotId ):
60 : pCtor(pTheCtor),
61 : nTypeId(nTheTypeId),
62 1095 : nSlotId(nTheSlotId)
63 1095 : {}
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::lang::XMultiServiceFactory >& rServiceManager,
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 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > GetServiceManager() const { return ::comphelper::getProcessServiceFactory(); }
129 :
130 : void BindListener();
131 : void UnbindListener();
132 : void AddStatusListener( const rtl::OUString& rCommandURL );
133 :
134 : // SfxStatusListenerInterface
135 : using FloatingWindow::StateChanged;
136 : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
137 : const SfxPoolItem* pState );
138 :
139 : public:
140 : SfxPopupWindow( sal_uInt16 nId,
141 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
142 : WinBits nBits );
143 : SfxPopupWindow( sal_uInt16 nId,
144 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
145 : const ResId &rId );
146 : SfxPopupWindow( sal_uInt16 nId,
147 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
148 : Window* pParentWindow,
149 : WinBits nBits );
150 : ~SfxPopupWindow();
151 :
152 : virtual SfxPopupWindow* Clone() const;
153 : virtual void MouseMove( const MouseEvent& rMEvt );
154 :
155 : void StartCascading();
156 0 : SAL_DLLPRIVATE void SetDeleteLink_Impl( const Link& rLink )
157 : {
158 0 : m_aDeleteLink = rLink;
159 0 : }
160 : };
161 :
162 : //------------------------------------------------------------------
163 :
164 : #define SFX_DECL_TOOLBOX_CONTROL() \
165 : static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \
166 : static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL)
167 :
168 : /* For special ToolBox controls, such as a font selection box or toolbox
169 : tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
170 : has to be implemented.
171 :
172 : This class has to be registered in SfxApplication:Init() with the static
173 : control method RegisterControl(). The SFx then automatically creates these
174 : controls in the toolbox, if the associated slots are of the specific type.
175 : */
176 :
177 : struct SfxToolBoxControl_Impl;
178 : class SFX2_DLLPUBLIC SfxToolBoxControl:
179 : public ::com::sun::star::awt::XDockableWindowListener,
180 : public ::com::sun::star::frame::XSubToolbarController,
181 : public svt::ToolboxController
182 :
183 : {
184 : friend class SfxToolbox;
185 : friend class SfxPopupWindow;
186 : friend struct SfxTbxCtrlFactory;
187 :
188 : SfxToolBoxControl_Impl* pImpl;
189 :
190 : protected:
191 : DECL_LINK( PopupModeEndHdl, void * );
192 : DECL_LINK( ClosePopupWindow, SfxPopupWindow * );
193 :
194 : // old SfxToolBoxControl methods
195 : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
196 : virtual void Select( sal_Bool bMod1 = sal_False );
197 : virtual void Select( sal_uInt16 nModifier );
198 :
199 : virtual void DoubleClick();
200 : virtual void Click();
201 : virtual SfxPopupWindowType GetPopupWindowType() const;
202 : virtual SfxPopupWindow* CreatePopupWindow();
203 : virtual SfxPopupWindow* CreatePopupWindowCascading();
204 : virtual Window* CreateItemWindow( Window *pParent );
205 :
206 : // Must be called by subclass to set a new popup window instance
207 : void SetPopupWindow( SfxPopupWindow* pWindow );
208 :
209 : // XInterface
210 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
211 : virtual void SAL_CALL acquire() throw();
212 : virtual void SAL_CALL release() throw();
213 :
214 : // XEventListener
215 : using ::cppu::OPropertySetHelper::disposing;
216 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
217 :
218 : // XComponent
219 : virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
220 :
221 : // new controller API
222 : // XStatusListener
223 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
224 : throw ( ::com::sun::star::uno::RuntimeException );
225 :
226 : // XToolbarController
227 : virtual void SAL_CALL execute( sal_Int16 KeyModifier )
228 : throw (::com::sun::star::uno::RuntimeException);
229 : virtual void SAL_CALL click()
230 : throw (::com::sun::star::uno::RuntimeException);
231 : virtual void SAL_CALL doubleClick()
232 : throw (::com::sun::star::uno::RuntimeException);
233 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow()
234 : throw (::com::sun::star::uno::RuntimeException);
235 : 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 )
236 : throw (::com::sun::star::uno::RuntimeException);
237 :
238 : // XSubToolbarController
239 : virtual ::sal_Bool SAL_CALL opensSubToolbar( ) throw (::com::sun::star::uno::RuntimeException);
240 : virtual ::rtl::OUString SAL_CALL getSubToolbarName( ) throw (::com::sun::star::uno::RuntimeException);
241 : virtual void SAL_CALL functionSelected( const ::rtl::OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException);
242 : virtual void SAL_CALL updateImage( ) throw (::com::sun::star::uno::RuntimeException);
243 :
244 : // XDockableWindowListener
245 : virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
246 : virtual ::com::sun::star::awt::DockingData SAL_CALL docking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
247 : virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
248 : virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
249 : virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
250 : virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
251 : virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException);
252 :
253 : // helper methods
254 : void createAndPositionSubToolBar( const ::rtl::OUString& rSubToolBarResName );
255 : ::Size getPersistentFloatingSize( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rSubToolBarResName );
256 :
257 : public:
258 : SFX_DECL_TOOLBOX_CONTROL();
259 :
260 : SfxToolBoxControl( sal_uInt16 nSlotID, sal_uInt16 nId, ToolBox& rBox, sal_Bool bShowStrings = sal_False );
261 : virtual ~SfxToolBoxControl();
262 :
263 : ToolBox& GetToolBox() const;
264 : unsigned short GetId() const;
265 : unsigned short GetSlotId() const;
266 :
267 : void Dispatch( const ::rtl::OUString& aCommand,
268 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
269 : static void Dispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
270 : const rtl::OUString& rCommand,
271 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
272 :
273 : static SfxItemState GetItemState( const SfxPoolItem* pState );
274 : static SfxToolBoxControl* CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule *pMod );
275 : static void RegisterToolBoxControl( SfxModule*, SfxTbxCtrlFactory*);
276 : };
277 :
278 : #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
279 : SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
280 : { return new Class( nSlotId, nId, rTbx ); } \
281 : void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
282 : { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
283 : Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
284 :
285 : #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
286 : SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
287 : { return new Class( nSlotId, nId, rTbx, Arg); } \
288 : void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
289 : { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \
290 : Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
291 :
292 : //=========================================================================
293 :
294 :
295 : class SfxDragButton_Impl : public FixedImage
296 : {
297 : public:
298 :
299 : SfxDragButton_Impl( Window *pParent );
300 : virtual void Command ( const CommandEvent& rCEvt );
301 : virtual void MouseMove( const MouseEvent& rMEvt );
302 : virtual void MouseButtonDown( const MouseEvent& rMEvt );
303 : };
304 :
305 : class SfxDragToolBoxControl_Impl : public SfxToolBoxControl
306 : {
307 : public:
308 : SFX_DECL_TOOLBOX_CONTROL();
309 : SfxDragToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox );
310 : virtual Window* CreateItemWindow( Window *pParent );
311 : using SfxToolBoxControl::Select;
312 : virtual void Select( sal_Bool bMod1 = sal_False );
313 : };
314 :
315 : //------------------------------------------------------------------------
316 :
317 : class SfxAppToolBoxControl_Impl : public SfxToolBoxControl
318 :
319 : /* [Description]
320 :
321 : Internal helper class for the pop-up menu <AppMenu_Impl> under new
322 : start in the SDT.
323 : */
324 :
325 : {
326 : public:
327 : SFX_DECL_TOOLBOX_CONTROL();
328 : SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
329 : ~SfxAppToolBoxControl_Impl();
330 : void SetImage( const String& rFacName );
331 :
332 : struct ExecuteInfo
333 : {
334 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
335 : ::com::sun::star::util::URL aTargetURL;
336 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
337 : };
338 :
339 : DECL_STATIC_LINK( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo* );
340 :
341 : protected:
342 : virtual void Click();
343 : using SfxToolBoxControl::Select;
344 : virtual void Select( sal_Bool );
345 : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
346 : virtual SfxPopupWindow* CreatePopupWindow();
347 : DECL_LINK( Activate, Menu * );
348 : private:
349 : String aLastURL;
350 : PopupMenu* pMenu;
351 : sal_uIntPtr m_nSymbolsStyle;
352 : sal_Bool m_bShowMenuImages;
353 : };
354 :
355 : class SfxHistoryToolBoxControl_Impl : public SfxToolBoxControl
356 : {
357 : Timer aTimer;
358 :
359 : private:
360 : DECL_LINK( Timeout, Timer * );
361 :
362 : protected:
363 : virtual void Click( );
364 : using SfxToolBoxControl::Select;
365 : virtual void Select( sal_Bool );
366 :
367 : public:
368 : SFX_DECL_TOOLBOX_CONTROL();
369 : SfxHistoryToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox );
370 : };
371 :
372 : class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl
373 : {
374 : protected:
375 : using SfxToolBoxControl::Select;
376 : virtual void Select( sal_uInt16 nSelectModifier );
377 :
378 : public:
379 : SFX_DECL_TOOLBOX_CONTROL();
380 : SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
381 : };
382 :
383 : class SfxPopupMenuManager;
384 : class SfxAddonsToolBoxControl_Impl : public SfxToolBoxControl
385 :
386 : /* [Description]
387 :
388 : Internal helper class to provide the addons popup menu through the addons
389 : toolbox button.
390 : */
391 :
392 : {
393 : sal_Bool bBigImages;
394 : PopupMenu* pMenu;
395 : sal_Bool m_bShowMenuImages;
396 :
397 : protected:
398 : virtual void Click();
399 : using SfxToolBoxControl::Select;
400 : virtual void Select( sal_Bool );
401 : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
402 : DECL_LINK( Activate, Menu * );
403 : public:
404 : SFX_DECL_TOOLBOX_CONTROL();
405 : SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
406 : ~SfxAddonsToolBoxControl_Impl();
407 :
408 : void RefreshMenuImages( Menu* pMenu );
409 : };
410 :
411 : #endif
412 :
413 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|