File: clTabRenderer.h

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (292 lines) | stat: -rw-r--r-- 9,550 bytes parent folder | download | duplicates (2)
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
282
283
284
285
286
287
288
289
290
291
292
#ifndef CLTABRENDERER_H
#define CLTABRENDERER_H

#ifdef WXDLLIMPEXP_SDK
#undef WXDLLIMPEXP_SDK
#endif

#ifdef __WXMSW__
#ifdef WXMAKINGDLL_SDK
#define WXDLLIMPEXP_SDK __declspec(dllexport)
#elif defined(WXUSINGDLL_SDK)
#define WXDLLIMPEXP_SDK __declspec(dllimport)
#else // not making nor using DLL
#define WXDLLIMPEXP_SDK
#endif
#else
#define WXDLLIMPEXP_SDK
#endif

#include "clTabRenderer.h"
#include "cl_defs.h"
#include "drawingutils.h"
#include "wxStringHash.h"

#include <vector>
#include <wx/arrstr.h>
#include <wx/bitmap.h>
#include <wx/colour.h>
#include <wx/dc.h>
#include <wx/sharedptr.h>
#include <wx/window.h>

#define CHEVRON_SIZE 20

class clTabCtrl;
enum NotebookStyle {
    /// Add a "+" button for creating new empty pages
    kNotebook_NewButton = (1 << 0),

    /// Hide the tab-bar
    kNotebook_HideTabBar = (1 << 1),

    /// Allow tabs to move using DnD
    kNotebook_AllowDnD = (1 << 2),

    /// Draw X button on the active tab
    kNotebook_CloseButtonOnActiveTab = (1 << 3),

    /// Mouse middle click closes tab
    kNotebook_MouseMiddleClickClosesTab = (1 << 4),

    /// Show a drop down button for displaying all tabs list
    kNotebook_ShowFileListButton = (1 << 5),

    /// Mouse middle click on a tab fires an event
    kNotebook_MouseMiddleClickFireEvent = (1 << 6),

    /// Clicking the X button on the active button fires an event
    /// instead of closing the tab (i.e. let the container a complete control)
    kNotebook_CloseButtonOnActiveTabFireEvent = (1 << 7),

    /// Fire navigation event for Ctrl-TAB et al
    kNotebook_EnableNavigationEvent = (1 << 8),
    /// Place tabs at the bottom
    kNotebook_BottomTabs = (1 << 9),

    /// Allow DnD between different book controls
    kNotebook_AllowForeignDnD = (1 << 10),

    /// We keep this flag for backward compatability
    kNotebook_RightTabs = 0,

    /// We keep this flag for backward compatability
    kNotebook_LeftTabs = 0,

    /// The notebook colours are changing based on the current editor theme
    kNotebook_DynamicColours = (1 << 13),

    /// Underline the active tab with a 2 pixel line
    kNotebook_UnderlineActiveTab = (1 << 14),

    /// When scrolling with the mouse button when hovering the tab control, switch between tabs
    kNotebook_MouseScrollSwitchTabs = (1 << 15),

    /// Default notebook
    kNotebook_Default = kNotebook_ShowFileListButton,

};

class clTabRenderer;
class WXDLLIMPEXP_SDK clTabColours
{
public:
    // Active tab colours
    wxColour inactiveTabBgColour;
    wxColour inactiveTabPenColour;
    wxColour inactiveTabTextColour;
    wxColour inactiveTabInnerPenColour;

    // Inactive tab colours
    wxColour activeTabTextColour;
    wxColour activeTabBgColour;
    wxColour activeTabPenColour;
    wxColour activeTabInnerPenColour;

    // the tab area colours
    wxColour tabAreaColour;

    /// Marker colour
    wxColour markerColour;

    clTabColours();
    virtual ~clTabColours() {}

    /**
     * @brief update colours based on the current theme
     */
    void UpdateColours(size_t notebookStyle);

    bool IsDarkColours() const;
};

/**
 * @class clTabInfo
 * @author Eran Ifrah
 * @brief contains information (mainly for drawing purposes) about a single tab label
 */
class WXDLLIMPEXP_SDK clTabInfo
{
    int m_bitmap = wxNOT_FOUND;
    int m_disabledBitmp = wxNOT_FOUND;

public:
    clTabCtrl* m_tabCtrl = nullptr;
    wxString m_label;
    wxString m_shortLabel;
    wxString m_tooltip;
    wxWindow* m_window = nullptr;
    wxRect m_rect;
    bool m_active;
    int m_textX;
    int m_textY;
    int m_bmpX;
    int m_bmpY;
    int m_bmpCloseX;
    int m_bmpCloseY;
    int m_width;
    int m_height;
    int m_vTabsWidth;
    int m_textWidth;
    bool m_isModified = false;
    eButtonState m_xButtonState = eButtonState::kNormal;

public:
    void CalculateOffsets(size_t style);
    void CalculateOffsets(size_t style, wxDC& dc);
    const wxString& GetBestLabel(size_t style) const;

public:
    typedef wxSharedPtr<clTabInfo> Ptr_t;
    typedef std::vector<clTabInfo::Ptr_t> Vec_t;

    clTabInfo(clTabCtrl* tabCtrl);
    clTabInfo(clTabCtrl* tabCtrl, size_t style, wxWindow* page, const wxString& text, int bitmapId = wxNOT_FOUND);
    virtual ~clTabInfo() {}

    void CreateDisabledBitmap();
    bool IsValid() const { return m_window != NULL; }
    void SetBitmap(int bitmap, size_t style);
    void SetLabel(const wxString& label, size_t style);
    void SetActive(bool active, size_t style);
    void SetRect(const wxRect& rect) { this->m_rect = rect; }
    int GetBitmap() const { return m_bitmap; }
    const wxString& GetLabel() const { return m_label; }
    const wxString& GetShortLabel() const { return m_shortLabel; }
    void SetShortLabel(const wxString& shortLabel) { this->m_shortLabel = shortLabel; }
    const wxRect& GetRect() const { return m_rect; }
    wxRect& GetRect() { return m_rect; }
    wxRect GetCloseButtonRect() const;
    wxWindow* GetWindow() { return m_window; }
    wxWindow* GetWindow() const { return m_window; }
    void SetWindow(wxWindow* window) { this->m_window = window; }
    bool IsActive() const { return m_active; }
    int GetBmpCloseX() const { return m_bmpCloseX; }
    int GetBmpCloseY() const { return m_bmpCloseY; }
    int GetHeight() const { return m_height; }
    int GetWidth() const { return m_width; }
    void SetTooltip(const wxString& tooltip) { this->m_tooltip = tooltip; }
    const wxString& GetTooltip() const { return m_tooltip; }
    int GetDisabledBitmp() const { return m_disabledBitmp; }
    const wxBitmap& GetBitmap(int index, bool disabled) const;
    bool HasDisableBitmap() const;
    bool HasBitmap() const;
    bool IsModified() const { return m_isModified; }
};

class WXDLLIMPEXP_SDK clTabRenderer
{
public:
    typedef wxSharedPtr<clTabRenderer> Ptr_t;

    // Geometry
    int bottomAreaHeight;     // BOTTOM_AREA_HEIGHT = 3;
    int majorCurveWidth;      // MAJOR_CURVE_WIDTH = 15;
    int smallCurveWidth;      // SMALL_CURVE_WIDTH = 4;
    int overlapWidth;         // OVERLAP_WIDTH = 20;
    int verticalOverlapWidth; // V_OVERLAP_WIDTH = 3;
    int xSpacer;
    int ySpacer;
    wxString m_name;
    static std::unordered_map<wxString, clTabRenderer*> ms_Renderes;
    bool use_bold_font = false;

protected:
    void ClearActiveTabExtraLine(clTabInfo::Ptr_t activeTab, wxDC& dc, const clTabColours& colours, size_t style);
    void DrawMarker(wxDC& dc, const clTabInfo& tabInfo, const clTabColours& colours, size_t style);
    void DrawMarkerLine(wxDC& dc, const wxPoint& p1, const wxPoint& p2, wxDirection direction);
    static void RegisterRenderer(clTabRenderer* renderer);
    static clTabRenderer* Create(const wxWindow* parent, const wxString& name);

public:
    clTabRenderer(const wxString& name, const wxWindow* parent);
    virtual ~clTabRenderer() {}
    virtual void Draw(wxWindow* parent, wxDC& dc, wxDC& fontDC, const clTabInfo& tabInfo, size_t tabIndex,
                      const clTabColours& colours, size_t style, eButtonState tabState, eButtonState xButtonState) = 0;
    virtual void DrawBottomRect(wxWindow* parent, clTabInfo::Ptr_t activeTab, const wxRect& clientRect, wxDC& dc,
                                const clTabColours& colours, size_t style) = 0;

    void SetUseBoldFont(bool use_bold_font) { this->use_bold_font = use_bold_font; }
    bool IsUseBoldFont() const { return use_bold_font; }

    /**
     * @brief draw the tab area background, return the colour used to actually
     * paint it
     */
    virtual wxColour DrawBackground(wxWindow* parent, wxDC& dc, const wxRect& clientRect, const clTabColours& colours,
                                    size_t style);

    /**
     * @brief finalise the background after all elements have been drawn on the tab area colour. Default is
     * to do nothing
     */
    virtual void FinaliseBackground(wxWindow* parent, wxDC& dc, const wxRect& clientRect, const wxRect& activeTabRect,
                                    const clTabColours& colours, size_t style);
    /**
     * @brief reutrn font suitable for drawing the tab label
     */
    static wxFont GetTabFont(bool bold);

    /**
     * @brief draw a button in a given state at a give location
     */
    static void DrawButton(wxWindow* win, wxDC& dc, const clTabInfo& tabInfo, const clTabColours& colours,
                           eButtonState state);

    /**
     * @brief draw cheveron button
     */
    static void DrawChevron(wxWindow* win, wxDC& dc, const wxRect& rect, const clTabColours& colours);

    static int GetXButtonSize();
    /**
     * @brief Adjust colours per renderer
     * @param colours [in/out]
     * @param style the notebook style
     */
    virtual void AdjustColours(clTabColours& colours, size_t style);
    static int GetDefaultBitmapHeight(int Y_spacer);

    /**
     * @brief allocate new renderer based on CodeLite's settings
     */
    static clTabRenderer::Ptr_t CreateRenderer(const wxWindow* win, size_t tabStyle);
    /**
     * @brief return list of availale renderers
     */
    static wxArrayString GetRenderers();

    /**
     * @brief return the marker pen width
     * @return
     */
    static int GetMarkerWidth();
    void SetName(const wxString& name) { this->m_name = name; }
    const wxString& GetName() const { return m_name; }
    virtual clTabRenderer* New(const wxWindow* parent) const = 0;
    /**
     * @brief return true if this renderer supports vertical tabs
     */
    virtual bool IsVerticalTabSupported() const = 0;
};
#endif // CLTABRENDERER_H