tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / include / sfx2 / infobar.hxx
blob675a8fb0182dcc873f04b5e85ef53b2bf70f08a0
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/.
8 */
9 #ifndef INCLUDED_SFX2_INFOBAR_HXX
10 #define INCLUDED_SFX2_INFOBAR_HXX
12 #include <vector>
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
23 INFO = 0,
24 SUCCESS = 1,
25 WARNING = 2,
26 DANGER = 3
29 class InfobarData
31 public:
32 OUString msId;
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
43 private:
44 SfxBindings* m_pBindings;
46 public:
47 SfxInfoBarContainerChild(vcl::Window* pParent, sal_uInt16 nId, SfxBindings* pBindings,
48 SfxChildWinInfo* pInfo);
49 virtual ~SfxInfoBarContainerChild() override;
51 SFX_DECL_CHILDWINDOW_WITHID(SfxInfoBarContainerChild);
53 void Update();
56 class ExtraButton;
58 /** Class representing a single InfoBar to be added in a SfxInfoBarContainerWindow.
60 class SFX2_DLLPUBLIC SfxInfoBarWindow final : public InterimItemWindow
62 private:
63 OUString m_sId;
64 InfobarType m_eType;
65 Size m_aMessageSize;
66 Size m_aOrigMessageSize;
67 bool m_bLayingOut;
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();
80 public:
81 SfxInfoBarWindow(vcl::Window* parent, OUString sId, const OUString& sPrimaryMessage,
82 const OUString& sSecondaryMessage, InfobarType InfobarType,
83 bool bShowCloseButton);
84 Size DoLayout();
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,
91 InfobarType eType);
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);
106 private:
107 DECL_DLLPRIVATE_LINK(CloseHandler, const OUString&, void);
110 class SfxInfoBarContainerWindow final : public vcl::Window
112 private:
113 SfxInfoBarContainerChild* m_pChildWin;
114 std::vector<VclPtr<SfxInfoBarWindow>> m_pInfoBars;
115 Idle m_aLayoutIdle;
116 bool m_bResizing;
118 DECL_LINK(DoUpdateLayout, Timer*, void);
120 public:
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;
138 #endif
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */