Don't search for old (<= 2.0) .NET SDK anymore
[LibreOffice.git] / include / sfx2 / tbxctrl.hxx
blobc46c8b42fa6f94c3506da2555a35c287f295e162
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 <memory>
23 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sal/types.h>
26 #include <vcl/timer.hxx>
27 #include <vcl/menu.hxx>
28 #include <vcl/fixed.hxx>
29 #include <vcl/floatwin.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 <rtl/ref.hxx>
40 class SfxToolBoxControl;
41 class SfxModule;
43 svt::ToolboxController* SfxToolBoxControllerFactory( const css::uno::Reference< css::frame::XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const OUString& aCommandURL );
45 typedef SfxToolBoxControl* (*SfxToolBoxControlCtor)( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
47 struct SfxTbxCtrlFactory
49 SfxToolBoxControlCtor pCtor;
50 const std::type_info& nTypeId;
51 sal_uInt16 nSlotId;
53 SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor,
54 const std::type_info& nTheTypeId, sal_uInt16 nTheSlotId ):
55 pCtor(pTheCtor),
56 nTypeId(nTheTypeId),
57 nSlotId(nTheSlotId)
62 /* Floating windows that can be torn from tool boxes should be derived from
63 this class. Since it is also derived from SfxControllerItem, its instances
64 will also receive the StateChanged calls.
66 class SfxFrameStatusListener;
67 class SFX2_DLLPUBLIC SfxPopupWindow: public FloatingWindow
69 friend class SfxFrameStatusListener;
70 bool m_bFloating;
71 bool m_bCascading;
72 Link<SfxPopupWindow*,void> m_aDeleteLink;
73 sal_uInt16 m_nId;
74 css::uno::Reference< css::frame::XFrame > const m_xFrame;
75 rtl::Reference<SfxFrameStatusListener> m_xStatusListener;
77 private:
78 SfxPopupWindow(SfxPopupWindow &) = delete;
79 void operator =(SfxPopupWindow &) = delete;
80 void Delete();
82 protected:
83 virtual void PopupModeEnd() override;
84 virtual bool Close() override;
86 sal_uInt16 GetId() const { return m_nId; }
87 const css::uno::Reference< css::frame::XFrame >& GetFrame() const { return m_xFrame; }
89 void AddStatusListener( const OUString& rCommandURL );
91 virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent );
93 public:
94 SfxPopupWindow(sal_uInt16 nId, vcl::Window *pParent,
95 const css::uno::Reference< css::frame::XFrame >& rFrame,
96 WinBits nBits );
97 SfxPopupWindow(sal_uInt16 nId, vcl::Window *pParent,
98 const OString& rID, const OUString& rUIXMLDescription,
99 const css::uno::Reference<css::frame::XFrame> &rFrame =
100 css::uno::Reference<css::frame::XFrame>());
101 virtual ~SfxPopupWindow() override;
102 virtual void dispose() override;
104 virtual void MouseMove( const MouseEvent& rMEvt ) override;
106 void StartCascading();
107 SAL_DLLPRIVATE void SetDeleteLink_Impl( const Link<SfxPopupWindow*,void>& rLink )
109 m_aDeleteLink = rLink;
114 #define SFX_DECL_TOOLBOX_CONTROL() \
115 static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \
116 static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=nullptr)
118 /* For special ToolBox controls, such as a font selection box or toolbox
119 tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
120 has to be implemented.
122 This class has to be registered in SfxApplication:Init() with the static
123 control method RegisterControl(). The SFx then automatically creates these
124 controls in the toolbox, if the associated slots are of the specific type.
127 struct SfxToolBoxControl_Impl;
128 class SFX2_DLLPUBLIC SfxToolBoxControl: public svt::ToolboxController
130 friend class SfxPopupWindow;
131 friend struct SfxTbxCtrlFactory;
133 std::unique_ptr< SfxToolBoxControl_Impl> pImpl;
135 protected:
136 DECL_LINK( PopupModeEndHdl, FloatingWindow*, void );
137 DECL_LINK( ClosePopupWindow, SfxPopupWindow *, void );
139 // old SfxToolBoxControl methods
140 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
141 virtual void Select( sal_uInt16 nSelectModifier );
143 virtual void DoubleClick();
144 virtual void Click();
145 virtual VclPtr<SfxPopupWindow> CreatePopupWindow();
146 virtual VclPtr<vcl::Window> CreateItemWindow( vcl::Window *pParent );
148 // Must be called by subclass to set a new popup window instance
149 void SetPopupWindow( SfxPopupWindow* pWindow );
151 public:
152 // XComponent
153 virtual void SAL_CALL dispose() override;
155 // new controller API
156 // XStatusListener
157 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
159 // XToolbarController
160 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
161 virtual void SAL_CALL click() override;
162 virtual void SAL_CALL doubleClick() override;
163 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override;
164 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& rParent ) override;
166 public:
167 SFX_DECL_TOOLBOX_CONTROL();
169 SfxToolBoxControl( sal_uInt16 nSlotID, sal_uInt16 nId, ToolBox& rBox, bool bShowStrings = false );
170 virtual ~SfxToolBoxControl() override;
172 ToolBox& GetToolBox() const;
173 unsigned short GetId() const;
174 unsigned short GetSlotId() const;
176 void Dispatch( const OUString& aCommand,
177 css::uno::Sequence< css::beans::PropertyValue > const & aArgs );
178 static void Dispatch( const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
179 const OUString& rCommand,
180 css::uno::Sequence< css::beans::PropertyValue > const & aArgs );
182 static SfxItemState GetItemState( const SfxPoolItem* pState );
183 static SfxToolBoxControl* CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule const *pMod );
184 static void RegisterToolBoxControl( SfxModule*, const SfxTbxCtrlFactory&);
187 #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
188 SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
189 { return new Class( nSlotId, nId, rTbx ); } \
190 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
191 { SfxToolBoxControl::RegisterToolBoxControl( pMod, SfxTbxCtrlFactory( \
192 Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
194 #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
195 SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
196 { return new Class( nSlotId, nId, rTbx, Arg); } \
197 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
198 { SfxToolBoxControl::RegisterToolBoxControl( pMod, SfxTbxCtrlFactory( \
199 Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
202 #endif
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */