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
23 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sal/types.h>
26 #include <svl/poolitem.hxx>
27 #include <svtools/toolboxcontroller.hxx>
28 #include <vcl/window.hxx>
30 namespace com::sun::star::frame
{ class XDispatchProvider
; }
31 namespace com::sun::star::frame
{ class XFrame
; }
33 class InterimItemWindow
;
34 class SfxToolBoxControl
;
37 svt::ToolboxController
* SfxToolBoxControllerFactory( const css::uno::Reference
< css::frame::XFrame
>& rFrame
, ToolBox
* pToolbox
, unsigned short nID
, const OUString
& aCommandURL
);
39 typedef SfxToolBoxControl
* (*SfxToolBoxControlCtor
)( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
);
41 struct SfxTbxCtrlFactory
43 SfxToolBoxControlCtor pCtor
;
44 const std::type_info
& nTypeId
;
47 SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor
,
48 const std::type_info
& nTheTypeId
, sal_uInt16 nTheSlotId
):
56 #define SFX_DECL_TOOLBOX_CONTROL() \
57 static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \
58 static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=nullptr)
60 /* For special ToolBox controls, such as a font selection box or toolbox
61 tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
62 has to be implemented.
64 This class has to be registered in SfxApplication:Init() with the static
65 control method RegisterControl(). The SFx then automatically creates these
66 controls in the toolbox, if the associated slots are of the specific type.
69 struct SfxToolBoxControl_Impl
;
70 class SFX2_DLLPUBLIC SfxToolBoxControl
: public svt::ToolboxController
72 friend struct SfxTbxCtrlFactory
;
74 std::unique_ptr
< SfxToolBoxControl_Impl
> pImpl
;
77 // old SfxToolBoxControl methods
78 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
79 virtual void Select( sal_uInt16 nSelectModifier
);
81 virtual void DoubleClick();
83 virtual void CreatePopupWindow();
84 virtual VclPtr
<InterimItemWindow
> CreateItemWindow(vcl::Window
*pParent
);
88 virtual void SAL_CALL
dispose() override
;
92 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& Event
) override
;
95 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
96 virtual void SAL_CALL
click() override
;
97 virtual void SAL_CALL
doubleClick() override
;
98 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createPopupWindow() override
;
99 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& rParent
) override
;
102 SFX_DECL_TOOLBOX_CONTROL();
104 SfxToolBoxControl( sal_uInt16 nSlotID
, sal_uInt16 nId
, ToolBox
& rBox
, bool bShowStrings
= false );
105 virtual ~SfxToolBoxControl() override
;
107 ToolBox
& GetToolBox() const;
108 unsigned short GetId() const;
109 unsigned short GetSlotId() const;
111 void Dispatch( const OUString
& aCommand
,
112 css::uno::Sequence
< css::beans::PropertyValue
> const & aArgs
);
113 static void Dispatch( const css::uno::Reference
< css::frame::XDispatchProvider
>& rDispatchProvider
,
114 const OUString
& rCommand
,
115 css::uno::Sequence
< css::beans::PropertyValue
> const & aArgs
);
117 static SfxItemState
GetItemState( const SfxPoolItem
* pState
);
118 static SfxToolBoxControl
* CreateControl( sal_uInt16 nSlotId
, sal_uInt16 nTbxId
, ToolBox
*pBox
, SfxModule
const *pMod
);
119 static void RegisterToolBoxControl( SfxModule
*, const SfxTbxCtrlFactory
&);
122 #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
123 SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
124 { return new Class( nSlotId, nId, rTbx ); } \
125 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
126 { SfxToolBoxControl::RegisterToolBoxControl( pMod, SfxTbxCtrlFactory( \
127 Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
129 #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
130 SfxToolBoxControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \
131 { return new Class( nSlotId, nId, rTbx, Arg); } \
132 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
133 { SfxToolBoxControl::RegisterToolBoxControl( pMod, SfxTbxCtrlFactory( \
134 Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */