File: wxCustomStatusBar.h

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (281 lines) | stat: -rw-r--r-- 9,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright            : (C) 2015 Eran Ifrah
// File name            : wxCustomStatusBar.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#ifndef WXCUSTOMSTATUSBAR_H
#define WXCUSTOMSTATUSBAR_H

#include <wx/statusbr.h>
#include <wx/colour.h>
#include <wx/sharedptr.h>
#include <wx/bitmap.h>
#include "codelite_exports.h"
#include "cl_command_event.h"
#include "wxPNGAnimation.h"
#include <wx/timer.h>
#include "clSystemSettings.h"

class wxCustomStatusBar;
class WXDLLIMPEXP_SDK wxCustomStatusBarArt : public wxEvtHandler
{
protected:
    wxString m_name;

public:
    typedef wxSharedPtr<wxCustomStatusBarArt> Ptr_t;

public:
    wxCustomStatusBarArt(const wxString& name);
    virtual ~wxCustomStatusBarArt() {}

    virtual void DrawText(wxDC& dc, wxCoord x, wxCoord y, const wxString& text);
    virtual void DrawFieldSeparator(wxDC& dc, const wxRect& fieldRect);

    virtual wxColour GetBgColour() const { return clSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); }
    virtual wxColour GetPenColour() const { return clSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); }
    virtual wxColour GetTextColour() const { return clSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT); }
    virtual wxColour GetSeparatorColour() const { return clSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); }
    void SetName(const wxString& name) { this->m_name = name; }
    const wxString& GetName() const { return m_name; }
};

//================---------------
// Base field
//================---------------
class WXDLLIMPEXP_SDK wxCustomStatusBarField : public wxEvtHandler
{
protected:
    wxRect m_rect;
    wxString m_tooltip;
    wxCustomStatusBar* m_parent;

public:
    typedef wxSharedPtr<wxCustomStatusBarField> Ptr_t;
    typedef std::vector<wxCustomStatusBarField::Ptr_t> Vect_t;

    wxCustomStatusBarField(wxCustomStatusBar* parent)
        : m_parent(parent)
    {
    }
    virtual ~wxCustomStatusBarField() {}

    /**
     * @brief render the field content
     * @param dc the device content
     * @param rect the field bounding rect
     */
    virtual void Render(wxDC& dc, const wxRect& rect, wxCustomStatusBarArt::Ptr_t art) = 0;

    /**
     * @brief return the field length
     */
    virtual size_t GetWidth() const = 0;

    /**
     * @brief return true if this field requires frequest refreshes
     * e.g. animation field needs it
     */
    virtual bool IsRequireFrequentRefresh() const { return false; }

    /**
     * @brief return true if 'point' is inside the current field
     * @param point position in parent coordinates
     */
    bool HitTest(const wxPoint& point) const;

    virtual void SetTooltip(const wxString& tooltip) { this->m_tooltip = tooltip; }
    const wxString& GetTooltip() const { return m_tooltip; }
    const wxRect& GetRect() const { return m_rect; }
    void SetRect(const wxRect& rect) { this->m_rect = rect; }
    template <typename T> T* Cast() const { return dynamic_cast<T*>(const_cast<wxCustomStatusBarField*>(this)); }
};

//================---------------
// Text field
//================---------------
class WXDLLIMPEXP_SDK wxCustomStatusBarFieldText : public wxCustomStatusBarField
{
    wxString m_text;
    size_t m_width;
    wxAlignment m_textAlign;

public:
    wxCustomStatusBarFieldText(wxCustomStatusBar* parent, size_t width)
        : wxCustomStatusBarField(parent)
        , m_width(width)
        , m_textAlign(wxALIGN_CENTER)
    {
    }
    virtual ~wxCustomStatusBarFieldText() {}
    virtual void Render(wxDC& dc, const wxRect& rect, wxCustomStatusBarArt::Ptr_t art);
    void SetText(const wxString& text);
    const wxString& GetText() const { return m_text; }
    void SetWidth(size_t width) { this->m_width = width; }
    size_t GetWidth() const { return m_width; }
    void SetTextAlignment(wxAlignment align) { m_textAlign = align; }
};

//================---------------
// Bitmap field
//================---------------
class WXDLLIMPEXP_SDK wxCustomStatusBarBitmapField : public wxCustomStatusBarField
{
    size_t m_width;
    wxBitmap m_bitmap;

public:
    wxCustomStatusBarBitmapField(wxCustomStatusBar* parent, size_t width)
        : wxCustomStatusBarField(parent)
        , m_width(width)
    {
    }
    virtual ~wxCustomStatusBarBitmapField() {}
    virtual void Render(wxDC& dc, const wxRect& rect, wxCustomStatusBarArt::Ptr_t art);
    void SetWidth(size_t width) { this->m_width = width; }
    size_t GetWidth() const { return m_width; }
    void SetBitmap(const wxBitmap& bitmap) { this->m_bitmap = bitmap; }
    const wxBitmap& GetBitmap() const { return m_bitmap; }
};

//================---------------
// Animation field
//================---------------
class WXDLLIMPEXP_SDK wxCustomStatusBarAnimationField : public wxCustomStatusBarField
{
    size_t m_width;
    wxPNGAnimation* m_animation;

protected:
    void OnAnimationClicked(wxMouseEvent& event);

public:
    /**
     * @brief construct animation field.
     */
    wxCustomStatusBarAnimationField(
        wxCustomStatusBar* parent, const wxBitmap& sprite, wxOrientation spriteOrientation, const wxSize& animSize);

    virtual ~wxCustomStatusBarAnimationField();
    virtual void Render(wxDC& dc, const wxRect& rect, wxCustomStatusBarArt::Ptr_t art);
    void SetWidth(size_t width) { this->m_width = width; }
    size_t GetWidth() const { return m_width; }
    /**
     * @brief start the animation with a given refresh rate (milliseconds)
     */
    void Start(long refreshRate = 50);
    void Stop();
    /**
     * @brief is the animation running?
     */
    bool IsRunning() const { return m_animation->IsRunning(); }

    /**
     * @brief set the tooltip to the animation as well
     */
    virtual void SetTooltip(const wxString& tooltip)
    {
        this->m_tooltip = tooltip;
        if(m_animation) {
            m_animation->SetToolTip(tooltip);
        }
    }
};

//================---------------
// Custom status bar
//================---------------
class WXDLLIMPEXP_SDK wxCustomStatusBar : public wxStatusBar
{
    wxCustomStatusBarArt::Ptr_t m_art;
    wxCustomStatusBarField::Vect_t m_fields;
    wxString m_text;
    wxString m_lastArtNameUsedForPaint;
    wxCustomStatusBarField::Ptr_t m_mainText;
    wxTimer* m_timer;

protected:
    size_t DoGetFieldsWidth();

    // Event handlers
    void OnPaint(wxPaintEvent& event);
    void OnEraseBackround(wxEraseEvent& event);
    void OnLeftDown(wxMouseEvent& event);
    void OnMouseMotion(wxMouseEvent& event);
    void OnTimer(wxTimerEvent& event);
    wxRect DoGetMainFieldRect();

public:
    /**
     * @brief animation control owned by 'field' was clicked
     */
    void AnimationClicked(wxCustomStatusBarField* field);

    void SetLastArtNameUsedForPaint(const wxString& lastArtNameUsedForPaint)
    {
        this->m_lastArtNameUsedForPaint = lastArtNameUsedForPaint;
    }
    const wxString& GetLastArtNameUsedForPaint() const { return m_lastArtNameUsedForPaint; }

public:
    wxCustomStatusBar(wxWindow* parent, wxWindowID id = wxID_ANY, long style = 0);
    virtual ~wxCustomStatusBar();

    void SetArt(wxCustomStatusBarArt::Ptr_t art);

    wxCustomStatusBarArt::Ptr_t GetArt() { return m_art; }

    void AddField(wxCustomStatusBarField::Ptr_t field) { m_fields.push_back(field); }

    /**
     * @brief set text in the main status bar text area
     */
    void SetText(const wxString& message, int secondsToLive = wxNOT_FOUND);
    
    /**
     * @brief return the main status bar area text message
     */
    const wxString& GetText() const { return m_text; }
    
    /**
     * @brief clear the main text
     */
    void ClearText();
    /**
     * @brief return pointer to the field at given index
     * if index is out of bounds, return NULL
     */
    wxCustomStatusBarField::Ptr_t GetField(size_t index);

    /**
     * @brief remove status bar field by index
     */
    void RemoveField(size_t index);

    /**
     * @brief return the number of fields
     */
    size_t GetFieldsCount() const { return m_fields.size(); }
};
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_SDK, wxEVT_STATUSBAR_CLICKED, clCommandEvent);
#endif // WXCUSTOMSTATUSBAR_H