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 <rtl/ref.hxx>
29 #include <vcl/vclptr.hxx>
31 namespace com::sun::star::frame
{ class XDispatchProvider
; }
32 namespace com::sun::star::frame
{ class XFrame
; }
33 namespace vcl
{ class Window
; }
35 class InterimItemWindow
;
36 class SfxToolBoxControl
;
39 rtl::Reference
<svt::ToolboxController
> SfxToolBoxControllerFactory( const css::uno::Reference
< css::frame::XFrame
>& rFrame
, ToolBox
* pToolbox
, ToolBoxItemId nID
, const OUString
& aCommandURL
);
41 typedef rtl::Reference
<SfxToolBoxControl
> (*SfxToolBoxControlCtor
)( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rBox
);
43 struct SfxTbxCtrlFactory
45 SfxToolBoxControlCtor pCtor
;
46 const std::type_info
& nTypeId
;
49 SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor
,
50 const std::type_info
& nTheTypeId
, sal_uInt16 nTheSlotId
):
58 #define SFX_DECL_TOOLBOX_CONTROL() \
59 static rtl::Reference<SfxToolBoxControl> CreateImpl( sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx ); \
60 static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=nullptr)
62 /* For special ToolBox controls, such as a font selection box or toolbox
63 tear-off floating windows, an appropriate Item-Subclass of SfxTooBoxControl
64 has to be implemented.
66 This class has to be registered in SfxApplication:Init() with the static
67 control method RegisterControl(). The SFx then automatically creates these
68 controls in the toolbox, if the associated slots are of the specific type.
71 struct SfxToolBoxControl_Impl
;
72 class SFX2_DLLPUBLIC SfxToolBoxControl
: public svt::ToolboxController
74 friend struct SfxTbxCtrlFactory
;
76 std::unique_ptr
< SfxToolBoxControl_Impl
> pImpl
;
79 // old SfxToolBoxControl methods
80 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
81 virtual void Select( sal_uInt16 nSelectModifier
);
83 virtual void DoubleClick();
85 virtual void CreatePopupWindow();
86 virtual VclPtr
<InterimItemWindow
> CreateItemWindow(vcl::Window
*pParent
);
90 virtual void SAL_CALL
dispose() override
;
94 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& Event
) override
;
97 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
98 virtual void SAL_CALL
click() override
;
99 virtual void SAL_CALL
doubleClick() override
;
100 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createPopupWindow() override
;
101 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& rParent
) override
;
104 SFX_DECL_TOOLBOX_CONTROL();
106 SfxToolBoxControl( sal_uInt16 nSlotID
, ToolBoxItemId nId
, ToolBox
& rBox
, bool bShowStrings
= false );
107 virtual ~SfxToolBoxControl() override
;
109 ToolBox
& GetToolBox() const;
110 ToolBoxItemId
GetId() const;
111 unsigned short GetSlotId() const;
113 void Dispatch( const OUString
& aCommand
,
114 css::uno::Sequence
< css::beans::PropertyValue
> const & aArgs
);
115 static void Dispatch( const css::uno::Reference
< css::frame::XDispatchProvider
>& rDispatchProvider
,
116 const OUString
& rCommand
,
117 css::uno::Sequence
< css::beans::PropertyValue
> const & aArgs
);
119 static SfxItemState
GetItemState( const SfxPoolItem
* pState
);
120 static rtl::Reference
<SfxToolBoxControl
> CreateControl( sal_uInt16 nSlotId
, ToolBoxItemId nTbxId
, ToolBox
*pBox
, SfxModule
const *pMod
);
121 static void RegisterToolBoxControl( SfxModule
*, const SfxTbxCtrlFactory
&);
124 #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \
125 rtl::Reference<SfxToolBoxControl> Class::CreateImpl( sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx ) \
126 { return new Class( nSlotId, nId, rTbx ); } \
127 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
128 { SfxToolBoxControl::RegisterToolBoxControl( pMod, SfxTbxCtrlFactory( \
129 Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
131 #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \
132 rtl::Reference<SfxToolBoxControl> Class::CreateImpl( sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx ) \
133 { return new Class( nSlotId, nId, rTbx, Arg); } \
134 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
135 { SfxToolBoxControl::RegisterToolBoxControl( pMod, SfxTbxCtrlFactory( \
136 Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */