Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/sfx2/infobar.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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
11
12
#include <vector>
13
14
#include <basegfx/color/bcolor.hxx>
15
16
#include <sfx2/childwin.hxx>
17
#include <sfx2/dllapi.h>
18
#include <vcl/InterimItemWindow.hxx>
19
20
namespace weld
21
{
22
class Button;
23
}
24
namespace weld
25
{
26
class Image;
27
}
28
namespace weld
29
{
30
class Label;
31
}
32
namespace weld
33
{
34
class TextView;
35
}
36
namespace weld
37
{
38
class Toolbar;
39
}
40
41
// These must match the values in offapi/com/sun/star/frame/InfobarType.idl
42
enum class InfobarType
43
{
44
    INFO = 0,
45
    SUCCESS = 1,
46
    WARNING = 2,
47
    DANGER = 3
48
};
49
50
class InfobarData
51
{
52
public:
53
    OUString msId;
54
    OUString msPrimaryMessage;
55
    OUString msSecondaryMessage;
56
    InfobarType maInfobarType;
57
    bool mbShowCloseButton;
58
};
59
60
/** SfxChildWindow for positioning the InfoBar in the view.
61
  */
62
class SFX2_DLLPUBLIC SfxInfoBarContainerChild final : public SfxChildWindow
63
{
64
private:
65
    SfxBindings& m_rBindings;
66
67
public:
68
    SfxInfoBarContainerChild(vcl::Window* pParent, sal_uInt16 nId, SfxBindings& rBindings,
69
                             SfxChildWinInfo& rInfo);
70
    virtual ~SfxInfoBarContainerChild() override;
71
72
    SFX_DECL_CHILDWINDOW_WITHID(SfxInfoBarContainerChild);
73
74
    void Update();
75
};
76
77
class ExtraButton;
78
79
/** Class representing a single InfoBar to be added in a SfxInfoBarContainerWindow.
80
  */
81
class SFX2_DLLPUBLIC SfxInfoBarWindow final : public InterimItemWindow
82
{
83
private:
84
    OUString m_sId;
85
    InfobarType m_eType;
86
    Size m_aMessageSize;
87
    Size m_aOrigMessageSize;
88
    bool m_bLayingOut;
89
    std::unique_ptr<weld::Image> m_xImage;
90
    std::unique_ptr<weld::Label> m_xPrimaryMessage;
91
    std::unique_ptr<weld::TextView> m_xSecondaryMessage;
92
    std::unique_ptr<weld::Container> m_xButtonBox;
93
    std::unique_ptr<weld::Toolbar> m_xCloseBtn;
94
    std::vector<std::unique_ptr<ExtraButton>> m_aActionBtns;
95
96
    DECL_DLLPRIVATE_LINK(SizeAllocHdl, const Size&, void);
97
98
    void SetForeAndBackgroundColors(InfobarType eType);
99
    void SetCloseButtonImage();
100
101
public:
102
    SfxInfoBarWindow(vcl::Window* parent, OUString sId, const OUString& sPrimaryMessage,
103
                     const OUString& sSecondaryMessage, InfobarType InfobarType,
104
                     bool bShowCloseButton);
105
    Size DoLayout();
106
    virtual void Layout() override;
107
    virtual bool EventNotify(NotifyEvent& rEvent) override;
108
    virtual ~SfxInfoBarWindow() override;
109
    virtual void dispose() override;
110
111
0
    const OUString& getId() const { return m_sId; }
112
    void Update(const OUString& sPrimaryMessage, const OUString& sSecondaryMessage,
113
                InfobarType eType);
114
    basegfx::BColor m_aBackgroundColor;
115
    basegfx::BColor m_aForegroundColor;
116
117
    /** Add button to Infobar.
118
      * Infobar takes ownership of the button so the button is
119
      * destroyed when the infobar gets destroyed.
120
      *
121
      * The optional "pCommand" is used by extensions, via XInfobarProvider, to
122
      * dispatch pCommand on click.
123
      */
124
    weld::Button& addButton(const OUString* pCommand = nullptr);
125
126
    void SetCommandHandler(weld::Button& rBtn, const OUString& aCommand);
127
128
private:
129
    DECL_DLLPRIVATE_LINK(CloseHandler, const OUString&, void);
130
};
131
132
class SfxInfoBarContainerWindow final : public vcl::Window
133
{
134
private:
135
    SfxInfoBarContainerChild* m_pChildWin;
136
    std::vector<VclPtr<SfxInfoBarWindow>> m_pInfoBars;
137
    Idle m_aLayoutIdle;
138
    bool m_bResizing;
139
140
    DECL_LINK(DoUpdateLayout, Timer*, void);
141
142
public:
143
    SfxInfoBarContainerWindow(SfxInfoBarContainerChild* pChildWin);
144
    virtual ~SfxInfoBarContainerWindow() override;
145
    virtual void dispose() override;
146
147
    VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId, const OUString& sPrimaryMessage,
148
                                           const OUString& sSecondaryMessage, InfobarType ibType,
149
                                           bool bShowCloseButton);
150
    VclPtr<SfxInfoBarWindow> getInfoBar(std::u16string_view sId);
151
    bool hasInfoBarWithID(std::u16string_view sId);
152
    void removeInfoBar(VclPtr<SfxInfoBarWindow> const& pInfoBar);
153
    static bool isInfobarEnabled(std::u16string_view sId);
154
155
    void TriggerUpdateLayout();
156
157
    virtual void Resize() override;
158
};
159
160
#endif
161
162
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */