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
|
#ifndef CLTOOLBAR_H
#define CLTOOLBAR_H
#include "bitmap_loader.h"
#include "cl_command_event.h"
#include "codelite_exports.h"
#include "wxCustomControls.hpp"
#include <unordered_map>
#include <vector>
#include <wx/menu.h>
#include <wx/panel.h>
#include <wx/toolbar.h>
#define INVALID_BITMAP_ID wxString::npos
#define USE_NATIVE_TOOLBAR 1
class clToolBarButtonBase;
#if wxUSE_NATIVE_TOOLBAR
class WXDLLIMPEXP_SDK clToolBarNative : public wxToolBar
{
clBitmapList* m_bitmaps = nullptr;
bool m_ownedBitmaps = false;
public:
clToolBarNative(wxWindow* parent, wxWindowID winid = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = "clToolBarNative");
virtual ~clToolBarNative();
void SetMiniToolBar(bool) {}
wxToolBarToolBase* AddTool(wxWindowID id, const wxString& label, size_t bitmapIndex,
const wxString& helpString = "", wxItemKind kind = wxITEM_NORMAL);
void AddSpacer() { AddSeparator(); }
wxToolBarToolBase* AddToggleButton(wxWindowID id, size_t bitmapIndex, const wxString& label = "")
{
return AddTool(id, label, bitmapIndex, wxEmptyString, wxITEM_CHECK);
}
wxToolBarToolBase* AddButton(wxWindowID id, size_t bitmapIndex, const wxString& label = "")
{
return AddTool(id, label, bitmapIndex, wxEmptyString, wxITEM_NORMAL);
}
bool DeleteById(wxWindowID toolId) { return DeleteTool(toolId); }
/**
* @brief return a pointer to the bitmaps list. Create one if no such bitmap list exists
*/
clBitmapList* GetBitmapsCreateIfNeeded();
/**
* @brief set a bitmaps pointer. the caller is still the owner (i.e. he is responsible for deleting it)
* the pointer must be in scope as long as this class exists
*/
void SetBitmaps(clBitmapList* bitmaps);
clBitmapList* GetBitmaps() const { return m_bitmaps; }
/**
* @brief assign bitmap list to the toolbar. the toolbar is the owner
*/
void AssignBitmaps(clBitmapList* bitmaps);
const wxBitmap& GetBitmap(size_t index) const;
/**
* @brief show a drop down menu for a button
*/
void ShowMenuForButton(wxWindowID buttonID, wxMenu* menu);
/**
* @brief display a menu for a button and return the user selected menu item ID
*/
int GetMenuSelectionFromUser(wxWindowID buttonID, wxMenu* menu);
void SetGroupSpacing(int) {}
void EnableCustomisation(bool) {}
};
#endif
class WXDLLIMPEXP_SDK clToolBarGeneric : public wxPanel
{
public:
typedef std::vector<clToolBarButtonBase*> ToolVect_t;
private:
ToolVect_t m_buttons;
ToolVect_t m_overflowButtons;
ToolVect_t m_visibleButtons;
bool m_popupShown = false;
size_t m_flags = 0;
wxRect m_chevronRect;
int m_groupSpacing;
wxColour m_bgColour;
bool m_useCustomBgColour = false;
clBitmapList* m_bitmaps = nullptr;
bool m_ownedBitmaps = false;
public:
enum eFlags {
kShowLabels = (1 << 0),
kThemedColour = (1 << 1),
kShowCustomiseMenu = (1 << 2),
kMiniToolBar = (1 << 3),
};
protected:
void OnPaint(wxPaintEvent& event);
void OnEraseBackground(wxEraseEvent& event);
void OnLeftUp(wxMouseEvent& event);
void OnLeftDown(wxMouseEvent& event);
void OnMotion(wxMouseEvent& event);
void OnEnterWindow(wxMouseEvent& event);
void OnLeaveWindow(wxMouseEvent& event);
void OnOverflowItem(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) override;
void DoIdleUpdate();
wxRect CalculateRect(wxDC& dc) const;
void DoShowOverflowMenu();
void PrepareForDrawings(wxDC& dc, std::vector<ToolVect_t>& G, const wxRect& rect);
void RenderGroup(int& xx, const clToolBarGeneric::ToolVect_t& G, wxDC& gcdc, bool isLastGroup);
void OnColoursChanged(clCommandEvent& event);
public:
clToolBarGeneric(wxWindow* parent, wxWindowID winid = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = "clToolBarGeneric");
virtual ~clToolBarGeneric();
const wxBitmap& GetBitmap(size_t index) const;
/**
* @brief set a bitmaps pointer. the caller is still the owner (i.e. he is responsible for deleting it)
* the pointer must be in scope as long as this class exists
*/
void SetBitmaps(clBitmapList* bitmaps);
clBitmapList* GetBitmaps() const { return m_bitmaps; }
/**
* @brief return a pointer to the bitmaps list. Create one if no such bitmap list exists
*/
clBitmapList* GetBitmapsCreateIfNeeded();
/**
* @brief assign bitmap list to the toolbar. the toolbar is the owner
*/
void AssignBitmaps(clBitmapList* bitmaps);
void EnableFlag(eFlags f, bool b)
{
if(b) {
m_flags |= f;
} else {
m_flags &= ~f;
}
}
bool HasFlag(eFlags flag) const { return m_flags & flag; }
int GetXSpacer() const;
int GetYSpacer() const;
/**
* @brief set a drop down menu for a button
*/
void SetDropdownMenu(wxWindowID buttonID, wxMenu* menu);
/**
* @brief find the menu for a given button
*/
wxMenu* FindMenuById(wxWindowID buttonID) const;
/**
* @brief return all the buttons
*/
ToolVect_t& GetButtons() { return m_buttons; };
const ToolVect_t& GetButtons() const { return m_buttons; }
/**
* @brief display labels next to the bitmap icon
*/
void ShowLabels(bool show) { EnableFlag(kShowLabels, show); }
bool IsShowLabels() const { return m_flags & kShowLabels; }
void EnableCustomisation(bool b) { EnableFlag(kShowCustomiseMenu, b); }
bool IsCustomisationEnabled() const { return HasFlag(kShowCustomiseMenu); }
void SetMiniToolBar(bool b) { EnableFlag(kMiniToolBar, b); }
bool IsMiniToolBar() const { return HasFlag(kMiniToolBar); }
void SetGroupSpacing(int spacing);
int GetGroupSpacing() const { return m_groupSpacing; }
/**
* @brief add toolbar button
*/
clToolBarButtonBase* Add(clToolBarButtonBase* button);
/**
* @brief insert a button after the button identified by 'otherButton'
* @param where insert the button after this button.
* if where can not be found, this function returns null
*/
clToolBarButtonBase* InsertBefore(wxWindowID where, clToolBarButtonBase* button);
/**
* @brief insert a button before the button identified by 'otherButton'
* @param where insert the button after this button.
* if where can not be found, this function returns null */
clToolBarButtonBase* InsertAfter(wxWindowID where, clToolBarButtonBase* button);
clToolBarButtonBase* AddButton(wxWindowID id, size_t bitmapIndex, const wxString& label = "");
clToolBarButtonBase* AddMenuButton(wxWindowID id, size_t bitmapIndex, const wxString& label = "");
clToolBarButtonBase* AddToggleButton(wxWindowID id, size_t bitmapIndex, const wxString& label = "");
clToolBarButtonBase* AddSeparator();
clToolBarButtonBase* AddStretchableSpace();
clToolBarButtonBase* AddSpacer();
/**
* @brief add control to the toolbar
* @param control
*/
clToolBarButtonBase* AddControl(wxWindow* control);
// Compatibility API with wxToolBar
clToolBarButtonBase* AddTool(wxWindowID id, const wxString& label, size_t bitmapIndex,
const wxString& helpString = "", wxItemKind kind = wxITEM_NORMAL)
{
wxUnusedVar(helpString);
switch(kind) {
case wxITEM_DROPDOWN:
return AddMenuButton(id, bitmapIndex, label);
case wxITEM_CHECK:
return AddToggleButton(id, bitmapIndex, label);
case wxITEM_NORMAL:
default:
return AddButton(id, bitmapIndex, label);
}
}
clToolBarButtonBase* AddTool(wxWindowID id, const wxString& label, size_t bitmapIndex, size_t bitmapIndexDisabled,
wxItemKind kind = wxITEM_NORMAL, const wxString& shortHelp = wxEmptyString,
const wxString& longHelp = wxEmptyString, wxObject* data = NULL)
{
wxUnusedVar(bitmapIndexDisabled);
wxUnusedVar(longHelp);
wxUnusedVar(data);
return AddTool(id, label, bitmapIndex, shortHelp, kind);
}
void SetToolBitmapSize(const wxSize& size) { wxUnusedVar(size); }
void ToggleTool(wxWindowID buttonID, bool toggle);
/**
* @brief This function should be called after you have added tools.
*/
void Realize();
/**
* @brief show a drop down menu for a button
*/
void ShowMenuForButton(wxWindowID buttonID, wxMenu* menu);
/**
* @brief display a menu for a button and return the user selected menu item ID
*/
int GetMenuSelectionFromUser(wxWindowID buttonID, wxMenu* menu);
/**
* @brief find a button by ID
*/
clToolBarButtonBase* FindById(wxWindowID id) const;
/**
* @brief delete a button identified by 'id'
* @param id the button id
* @return true on success, false otherwise
*/
bool DeleteById(wxWindowID id);
// Compatibility API
bool DeleteTool(wxWindowID id) { return DeleteById(id); }
};
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_SDK, wxEVT_TOOLBAR_CUSTOMISE, wxCommandEvent);
#if !wxUSE_NATIVE_TOOLBAR
// use the generic version, always
typedef clToolBarGeneric clToolBar;
typedef clToolBarGeneric clToolBarNative;
#else
typedef clToolBarGeneric clToolBar;
#endif
#endif // CLTOOLBAR_H
|