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 <vcl/button.hxx>
15 #include <vcl/fixed.hxx>
16 #include <basegfx/color/bcolor.hxx>
17 
18 #include <sfx2/dllapi.h>
19 #include <sfx2/childwin.hxx>
20 
21 // These must match the values in offapi/com/sun/star/frame/InfobarType.idl
22 enum class InfobarType {
23     INFO = 0,
24     SUCCESS = 1,
25     WARNING = 2,
26     DANGER = 3
27 };
28 
29 class InfobarData
30 {
31     public:
32     OUString msId;
33     OUString msPrimaryMessage;
34     OUString msSecondaryMessage;
35     InfobarType maInfobarType;
36     bool mbShowCloseButton;
37 };
38 
39 /** SfxChildWindow for positioning the InfoBar in the view.
40   */
41 class SFX2_DLLPUBLIC SfxInfoBarContainerChild final : public SfxChildWindow
42 {
43     private:
44         SfxBindings* const m_pBindings;
45 
46     public:
47         SfxInfoBarContainerChild( vcl::Window* pParent,
48                                   sal_uInt16 nId,
49                                   SfxBindings* pBindings,
50                                   SfxChildWinInfo* pInfo );
51         virtual ~SfxInfoBarContainerChild() override;
52 
53         SFX_DECL_CHILDWINDOW_WITHID( SfxInfoBarContainerChild );
54 
55         void Update( );
56 };
57 
58 /** Class representing a single InfoBar to be added in a SfxInfoBarContainerWindow.
59   */
60 class SFX2_DLLPUBLIC SfxInfoBarWindow final : public vcl::Window
61 {
62     private:
63         OUString const            m_sId;
64         InfobarType m_eType;
65         VclPtr<FixedImage>        m_pImage;
66         VclPtr<FixedText> m_pPrimaryMessage;
67         VclPtr<FixedText> m_pSecondaryMessage;
68         VclPtr<Button>                m_pCloseBtn;
69         std::vector< VclPtr<PushButton> >  m_aActionBtns;
70 
71         void SetForeAndBackgroundColors( InfobarType eType );
72 
73     public:
74         SfxInfoBarWindow( vcl::Window* parent, const OUString& sId,
75                           const OUString& sPrimaryMessage,
76                           const OUString& sSecondaryMessage,
77                           InfobarType InfobarType,
78                           bool bShowCloseButton, WinBits nMessageStyle);
79         virtual ~SfxInfoBarWindow( ) override;
80         virtual void dispose() override;
81 
getId() const82         const OUString& getId() const { return m_sId; }
83         virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
84         virtual void Resize( ) override;
85         void Update(const OUString& sPrimaryMessage, const OUString& sSecondaryMessage,
86                     InfobarType eType);
87         basegfx::BColor m_aBackgroundColor;
88         basegfx::BColor                m_aForegroundColor;
89 
90         /** Add button to Infobar.
91          * Infobar takes ownership of the button so the button is
92          * destroyed when the infobar gets destroyed.
93          */
94         void addButton(PushButton* pButton);
95 
96     private:
97         DECL_LINK( CloseHandler, Button*, void );
98 };
99 
100 class SfxInfoBarContainerWindow final : public vcl::Window
101 {
102     private:
103         SfxInfoBarContainerChild*               m_pChildWin;
104         std::vector< VclPtr<SfxInfoBarWindow> > m_pInfoBars;
105 
106     public:
107         SfxInfoBarContainerWindow(SfxInfoBarContainerChild* pChildWin);
108         virtual ~SfxInfoBarContainerWindow( ) override;
109         virtual void dispose() override;
110 
111         VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId,
112                                         const OUString& sPrimaryMessage,
113                                         const OUString& sSecondaryMessage,
114                                         InfobarType ibType,
115                                         WinBits nMessageStyle,
116                                         bool bShowCloseButton);
117         VclPtr<SfxInfoBarWindow> getInfoBar(const OUString& sId);
118         bool hasInfoBarWithID(const OUString& sId);
119         void removeInfoBar(VclPtr<SfxInfoBarWindow> const & pInfoBar);
120 
121         virtual void Resize() override;
122 };
123 
124 
125 #endif
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
128