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 #ifndef INCLUDED_SFX2_INFOBAR_HXX
10 #define INCLUDED_SFX2_INFOBAR_HXX
14 #include <basegfx/color/bcolor.hxx>
16 #include <sfx2/childwin.hxx>
17 #include <sfx2/dllapi.h>
18 #include <vcl/InterimItemWindow.hxx>
20 // These must match the values in offapi/com/sun/star/frame/InfobarType.idl
21 enum class InfobarType
33 OUString msPrimaryMessage
;
34 OUString msSecondaryMessage
;
35 InfobarType maInfobarType
;
36 bool mbShowCloseButton
;
39 /** SfxChildWindow for positioning the InfoBar in the view.
41 class SFX2_DLLPUBLIC SfxInfoBarContainerChild final
: public SfxChildWindow
44 SfxBindings
* m_pBindings
;
47 SfxInfoBarContainerChild(vcl::Window
* pParent
, sal_uInt16 nId
, SfxBindings
* pBindings
,
48 SfxChildWinInfo
* pInfo
);
49 virtual ~SfxInfoBarContainerChild() override
;
51 SFX_DECL_CHILDWINDOW_WITHID(SfxInfoBarContainerChild
);
58 /** Class representing a single InfoBar to be added in a SfxInfoBarContainerWindow.
60 class SFX2_DLLPUBLIC SfxInfoBarWindow final
: public InterimItemWindow
66 Size m_aOrigMessageSize
;
68 std::unique_ptr
<weld::Image
> m_xImage
;
69 std::unique_ptr
<weld::Label
> m_xPrimaryMessage
;
70 std::unique_ptr
<weld::TextView
> m_xSecondaryMessage
;
71 std::unique_ptr
<weld::Container
> m_xButtonBox
;
72 std::unique_ptr
<weld::Toolbar
> m_xCloseBtn
;
73 std::vector
<std::unique_ptr
<ExtraButton
>> m_aActionBtns
;
75 DECL_DLLPRIVATE_LINK(SizeAllocHdl
, const Size
&, void);
77 void SetForeAndBackgroundColors(InfobarType eType
);
78 void SetCloseButtonImage();
81 SfxInfoBarWindow(vcl::Window
* parent
, OUString sId
, const OUString
& sPrimaryMessage
,
82 const OUString
& sSecondaryMessage
, InfobarType InfobarType
,
83 bool bShowCloseButton
);
85 virtual void Layout() override
;
86 virtual ~SfxInfoBarWindow() override
;
87 virtual void dispose() override
;
89 const OUString
& getId() const { return m_sId
; }
90 void Update(const OUString
& sPrimaryMessage
, const OUString
& sSecondaryMessage
,
92 basegfx::BColor m_aBackgroundColor
;
93 basegfx::BColor m_aForegroundColor
;
95 /** Add button to Infobar.
96 * Infobar takes ownership of the button so the button is
97 * destroyed when the infobar gets destroyed.
99 * The optional "pCommand" is used by extensions, via XInfobarProvider, to
100 * dispatch pCommand on click.
102 weld::Button
& addButton(const OUString
* pCommand
= nullptr);
104 void SetCommandHandler(weld::Button
& rBtn
, const OUString
& aCommand
);
107 DECL_DLLPRIVATE_LINK(CloseHandler
, const OUString
&, void);
110 class SfxInfoBarContainerWindow final
: public vcl::Window
113 SfxInfoBarContainerChild
* m_pChildWin
;
114 std::vector
<VclPtr
<SfxInfoBarWindow
>> m_pInfoBars
;
118 DECL_LINK(DoUpdateLayout
, Timer
*, void);
121 SfxInfoBarContainerWindow(SfxInfoBarContainerChild
* pChildWin
);
122 virtual ~SfxInfoBarContainerWindow() override
;
123 virtual void dispose() override
;
125 VclPtr
<SfxInfoBarWindow
> appendInfoBar(const OUString
& sId
, const OUString
& sPrimaryMessage
,
126 const OUString
& sSecondaryMessage
, InfobarType ibType
,
127 bool bShowCloseButton
);
128 VclPtr
<SfxInfoBarWindow
> getInfoBar(std::u16string_view sId
);
129 bool hasInfoBarWithID(std::u16string_view sId
);
130 void removeInfoBar(VclPtr
<SfxInfoBarWindow
> const& pInfoBar
);
131 static bool isInfobarEnabled(std::u16string_view sId
);
133 void TriggerUpdateLayout();
135 virtual void Resize() override
;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */