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  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_STATUS_HXX
21 #define INCLUDED_VCL_STATUS_HXX
22 
23 #include <tools/solar.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/window.hxx>
26 #include <o3tl/typed_flags_set.hxx>
27 #include <memory>
28 #include <vector>
29 
30 class DataChangedEvent;
31 class HelpEvent;
32 class MouseEvent;
33 class UserDrawEvent;
34 struct ImplStatusItem;
35 
36 void DrawProgress(vcl::Window* pWindow, vcl::RenderContext& rRenderContext, const Point& rPos,
37                                 tools::Long nOffset, tools::Long nPrgsWidth, tools::Long nPrgsHeight,
38                                 sal_uInt16 nPercent1, sal_uInt16 nPercent2, sal_uInt16 nPercentCount,
39                                 const tools::Rectangle& rFramePosSize);
40 
41 
42 enum class StatusBarItemBits {
43     NONE            = 0x0000,
44     Left            = 0x0001,
45     Center          = 0x0002,
46     Right           = 0x0004,
47     In              = 0x0008,
48     Out             = 0x0010,
49     Flat            = 0x0020,
50     AutoSize        = 0x0040,
51     UserDraw        = 0x0080,
52     Mandatory       = 0x0100,
53 };
54 namespace o3tl
55 {
56     template<> struct typed_flags<StatusBarItemBits> : is_typed_flags<StatusBarItemBits, 0x01ff> {};
57 }
58 
59 #define STATUSBAR_APPEND            (sal_uInt16(0xFFFF))
60 #define STATUSBAR_ITEM_NOTFOUND     (sal_uInt16(0xFFFF))
61 #define STATUSBAR_OFFSET            (tools::Long(5))
62 
63 
64 class VCL_DLLPUBLIC StatusBar : public vcl::Window
65 {
66     class SAL_DLLPRIVATE ImplData;
67 private:
68     std::vector<std::unique_ptr<ImplStatusItem>> mvItemList;
69     std::unique_ptr<ImplData> mpImplData;
70     OUString            maPrgsTxt;
71     Point               maPrgsTxtPos;
72     tools::Rectangle           maPrgsFrameRect;
73     tools::Long                mnPrgsSize;
74     tools::Long                mnItemsWidth;
75     tools::Long                mnDX;
76     tools::Long                mnDY;
77     tools::Long                mnCalcHeight;
78     tools::Long                mnTextY;
79     sal_uInt16          mnCurItemId;
80     sal_uInt16          mnPercent;
81     sal_uInt16          mnPercentCount;
82     sal_uInt32          mnLastProgressPaint_ms;
83     bool                mbFormat;
84     bool                mbProgressMode;
85     bool                mbInUserDraw;
86     bool                mbAdjustHiDPI;
87     Link<StatusBar*,void>  maClickHdl;
88     Link<StatusBar*,void>  maDoubleClickHdl;
89 
90     using Window::ImplInit;
91     SAL_DLLPRIVATE void      ImplInit( vcl::Window* pParent, WinBits nStyle );
92     SAL_DLLPRIVATE void      ImplInitSettings();
93     SAL_DLLPRIVATE void      ImplFormat();
94     SAL_DLLPRIVATE bool      ImplIsItemUpdate();
95 
96     SAL_DLLPRIVATE void      ImplDrawText(vcl::RenderContext& rRenderContext);
97     SAL_DLLPRIVATE void      ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen,
98                                           sal_uInt16 nPos);
99     SAL_DLLPRIVATE void      ImplDrawProgress(vcl::RenderContext& rRenderContext, sal_uInt16 nNewPerc);
100     SAL_DLLPRIVATE void      ImplCalcProgressRect();
101     SAL_DLLPRIVATE tools::Rectangle ImplGetItemRectPos( sal_uInt16 nPos ) const;
102     SAL_DLLPRIVATE sal_uInt16    ImplGetFirstVisiblePos() const;
103 
104 protected:
105     virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
106 
107 public:
108                         StatusBar( vcl::Window* pParent,
109                                    WinBits nWinStyle = WB_BORDER | WB_RIGHT );
110     virtual             ~StatusBar() override;
111     virtual void        dispose() override;
112 
113     void                AdjustItemWidthsForHiDPI();
114 
115     virtual void        MouseButtonDown( const MouseEvent& rMEvt ) override;
116     virtual void        Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
117     virtual void        Resize() override;
118     virtual void        RequestHelp( const HelpEvent& rHEvt ) override;
119     virtual void        StateChanged( StateChangedType nType ) override;
120     virtual void        DataChanged( const DataChangedEvent& rDCEvt ) override;
121 
122     void                Click();
123     void                DoubleClick();
124     virtual void        UserDraw( const UserDrawEvent& rUDEvt );
125 
126     void                InsertItem( sal_uInt16 nItemId, sal_uLong nWidth,
127                                     StatusBarItemBits nBits = StatusBarItemBits::Center | StatusBarItemBits::In,
128                                     tools::Long nOffset = STATUSBAR_OFFSET,
129                                     sal_uInt16 nPos = STATUSBAR_APPEND );
130     void                RemoveItem( sal_uInt16 nItemId );
131 
132     void                ShowItem( sal_uInt16 nItemId );
133     void                HideItem( sal_uInt16 nItemId );
134     bool                IsItemVisible( sal_uInt16 nItemId ) const;
135 
136     void                RedrawItem( sal_uInt16 nItemId );
137 
138     void                Clear();
139 
140     sal_uInt16          GetItemCount() const;
141     sal_uInt16          GetItemId( sal_uInt16 nPos ) const;
142     sal_uInt16          GetItemId( const Point& rPos ) const;
143     sal_uInt16          GetItemPos( sal_uInt16 nItemId ) const;
144     tools::Rectangle           GetItemRect( sal_uInt16 nItemId ) const;
145     Point               GetItemTextPos( sal_uInt16 nItemId ) const;
GetCurItemId() const146     sal_uInt16          GetCurItemId() const { return mnCurItemId; }
147 
148     sal_uLong           GetItemWidth( sal_uInt16 nItemId ) const;
149     StatusBarItemBits   GetItemBits( sal_uInt16 nItemId ) const;
150 
151     tools::Long                GetItemOffset( sal_uInt16 nItemId ) const;
152 
153     /// @param nCharsWidth, if not -1, overrides the normal width calculation
154     void                SetItemText( sal_uInt16 nItemId, const OUString& rText, int nCharsWidth = -1 );
155     const OUString&     GetItemText( sal_uInt16 nItemId ) const;
156 
157     void                SetItemData( sal_uInt16 nItemId, void* pNewData );
158     void*               GetItemData( sal_uInt16 nItemId ) const;
159 
160     void                SetItemCommand( sal_uInt16 nItemId, const OUString& rCommand );
161     OUString            GetItemCommand( sal_uInt16 nItemId );
162 
163     void                SetHelpText( sal_uInt16 nItemId, const OUString& rText );
164     const OUString&     GetHelpText( sal_uInt16 nItemId ) const;
165 
166     using Window::SetQuickHelpText;
167     void                SetQuickHelpText( sal_uInt16 nItemId, const OUString& rText );
168     using Window::GetQuickHelpText;
169     const OUString&     GetQuickHelpText( sal_uInt16 nItemId ) const;
170 
171     void                SetHelpId( sal_uInt16 nItemId, const OString& rHelpId );
172 
173     void                StartProgressMode( const OUString& rText );
174     void                SetProgressValue( sal_uInt16 nPercent );
175     void                EndProgressMode();
IsProgressMode() const176     bool                IsProgressMode() const { return mbProgressMode; }
177 
178     void                SetText( const OUString& rText ) override;
179 
180     Size                CalcWindowSizePixel() const;
181 
SetClickHdl(const Link<StatusBar *,void> & rLink)182     void                SetClickHdl( const Link<StatusBar*,void>& rLink ) { maClickHdl = rLink; }
SetDoubleClickHdl(const Link<StatusBar *,void> & rLink)183     void                SetDoubleClickHdl( const Link<StatusBar*,void>& rLink ) { maDoubleClickHdl = rLink; }
184 
185     using Window::SetAccessibleName;
186     void                SetAccessibleName( sal_uInt16 nItemId, const OUString& rName );
187     using Window::GetAccessibleName;
188     const OUString&     GetAccessibleName( sal_uInt16 nItemId ) const;
189 };
190 
191 #endif // INCLUDED_VCL_STATUS_HXX
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
194