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
|
#ifndef CLTREECTRLNODE_H
#define CLTREECTRLNODE_H
#include "clCellValue.h"
#include "clColours.h"
#include "codelite_exports.h"
#include <array>
#include <unordered_map>
#include <vector>
#include <wx/colour.h>
#include <wx/gdicmn.h>
#include <wx/sharedptr.h>
#include <wx/string.h>
#include <wx/treebase.h>
class clSearchText;
class clTreeCtrlModel;
class clTreeCtrl;
enum clTreeCtrlNodeFlags {
kNF_FontBold = (1 << 0),
kNF_FontItalic = (1 << 1),
kNF_SortItems = (1 << 2),
kNF_Expanded = (1 << 3),
kNF_Selected = (1 << 4),
kNF_Hovered = (1 << 5),
kNF_Hidden = (1 << 6),
kNF_LisItem = (1 << 7),
kNF_HighlightText = (1 << 8),
};
typedef std::array<wxString, 3> Str3Arr_t;
struct WXDLLIMPEXP_SDK clMatchResult {
std::unordered_map<size_t, Str3Arr_t> matches;
bool Get(size_t col, Str3Arr_t& arr) const
{
if(matches.count(col) == 0) {
return false;
}
arr = matches.find(col)->second;
return true;
}
void Add(size_t col, const Str3Arr_t& arr)
{
matches.erase(col);
matches[col] = arr;
}
void Clear() { matches.clear(); }
};
class WXDLLIMPEXP_SDK clRowEntry
{
public:
typedef std::vector<clRowEntry*> Vec_t;
static int Y_SPACER;
static int X_SPACER;
protected:
clTreeCtrl* m_tree = nullptr;
clTreeCtrlModel* m_model = nullptr;
clCellValue::Vect_t m_cells;
size_t m_flags = 0;
wxTreeItemData* m_clientObject = nullptr;
wxUIntPtr m_data = 0;
clRowEntry* m_parent = nullptr;
clRowEntry::Vec_t m_children;
clRowEntry* m_next = nullptr;
clRowEntry* m_prev = nullptr;
int m_indentsCount = 0;
wxRect m_rowRect;
wxRect m_buttonRect;
clMatchResult m_higlightInfo;
protected:
void SetFlag(clTreeCtrlNodeFlags flag, bool b)
{
if(b) {
m_flags |= flag;
} else {
m_flags &= ~flag;
}
}
bool HasFlag(clTreeCtrlNodeFlags flag) const { return m_flags & flag; }
/**
* @brief return the nth visible item
*/
clRowEntry* GetVisibleItem(int index);
void DrawSimpleSelection(wxWindow* win, wxDC& dc, const wxRect& rect, const clColours& colours);
void RenderText(wxWindow* win, wxDC& dc, const clColours& colours, const wxString& text, int x, int y, size_t col);
void RenderTextSimple(wxWindow* win, wxDC& dc, const clColours& colours, const wxString& text, int x, int y,
size_t col);
void RenderCheckBox(wxWindow* win, wxDC& dc, const clColours& colours, const wxRect& rect, bool checked);
int GetCheckBoxWidth(wxWindow* win);
public:
clRowEntry* GetLastChild() const;
clRowEntry* GetFirstChild() const;
size_t GetColumnCount() const { return m_cells.size(); }
const clCellValue& GetColumn(size_t col = 0) const;
clCellValue& GetColumn(size_t col = 0);
clRowEntry(clTreeCtrl* tree, const wxString& label, int bitmapIndex = wxNOT_FOUND,
int bitmapSelectedIndex = wxNOT_FOUND);
clRowEntry(clTreeCtrl* tree, bool checked, const wxString& label, int bitmapIndex = wxNOT_FOUND,
int bitmapSelectedIndex = wxNOT_FOUND);
~clRowEntry();
/**
* @brief return the item rectangle
* @return
*/
wxRect GetCellRect(size_t col = 0) const;
clRowEntry* GetNext() const { return m_next; }
clRowEntry* GetPrev() const { return m_prev; }
void SetNext(clRowEntry* next) { this->m_next = next; }
void SetPrev(clRowEntry* prev) { this->m_prev = prev; }
void SetHighlightInfo(const clMatchResult& info) { m_higlightInfo = info; }
const clMatchResult& GetHighlightInfo() const { return m_higlightInfo; }
void SetHidden(bool b);
bool IsHidden() const { return HasFlag(kNF_Hidden); }
void SetHighlight(bool b) { SetFlag(kNF_HighlightText, b); }
bool IsHighlight() const { return HasFlag(kNF_HighlightText); }
void SetData(wxUIntPtr data) { this->m_data = data; }
wxUIntPtr GetData() { return m_data; }
/**
* @brief using wxDC, calculate the item's width
*/
int CalcItemWidth(wxDC& dc, int rowHeight, size_t col = 0);
bool IsListItem() const { return m_flags & kNF_LisItem; }
void SetListItem(bool b) { SetFlag(kNF_LisItem, b); }
bool IsVisible() const;
void SetBgColour(const wxColour& bgColour, size_t col = 0);
void SetFont(const wxFont& font, size_t col = 0);
void SetTextColour(const wxColour& textColour, size_t col = 0);
const wxColour& GetBgColour(size_t col = 0) const;
const wxFont& GetFont(size_t col = 0) const;
const wxColour& GetTextColour(size_t col = 0) const;
/**
* @brief remove and delete a single child
* @param child
*/
void DeleteChild(clRowEntry* child);
/**
* @brief remove all children items
*/
void DeleteAllChildren();
void Render(wxWindow* win, wxDC& dc, const clColours& c, int row_index, clSearchText* searcher);
void RenderBackground(wxDC& dc, long tree_style, const clColours& c, int row_index);
std::vector<size_t> GetColumnWidths(wxWindow* win, wxDC& dc);
void SetHovered(bool b) { SetFlag(kNF_Hovered, b); }
bool IsHovered() const { return m_flags & kNF_Hovered; }
void ClearRects();
void SetRects(const wxRect& rect, const wxRect& buttonRect)
{
m_rowRect = rect;
m_buttonRect = buttonRect;
}
const wxRect& GetItemRect() const { return m_rowRect; }
const wxRect& GetButtonRect() const { return m_buttonRect; }
const wxRect& GetCheckboxRect(size_t col = 0) const;
const wxRect& GetCellButtonRect(size_t col) const;
void AddChild(clRowEntry* child);
/**
* @brief insert item at 'where'. The new item is placed after 'prev'
*/
void InsertChild(clRowEntry* child, clRowEntry* prev);
/**
* @brief insert this node between first and second
*/
void ConnectNodes(clRowEntry* first, clRowEntry* second);
bool IsBold() const { return HasFlag(kNF_FontBold); }
void SetBold(bool b) { SetFlag(kNF_FontBold, b); }
bool IsItalic() const { return HasFlag(kNF_FontItalic); }
void SetItalic(bool b) { SetFlag(kNF_FontItalic, b); }
bool IsExpanded() const { return HasFlag(kNF_Expanded) || HasFlag(kNF_Hidden); }
bool SetExpanded(bool b);
bool IsRoot() const { return GetParent() == nullptr; }
// Cell accessors
void SetBitmapIndex(int bitmapIndex, size_t col = 0);
void SetBitmapSelectedIndex(int bitmapIndex, size_t col = 0);
void SetLabel(const wxString& label, size_t col = 0);
/**
* @brief add button to the right of the cell
*/
void SetHasButton(eCellButtonType button_type, const wxString& unicode_symbol, size_t col = 0);
bool HasButton(size_t col) const;
/**
* @brief mark cell at column as a button cell
* @param label the button label
*/
void SetIsButton(const wxString& label, size_t col = 0);
/**
* @brief is cell at given column is a button?
*/
bool IsButton(size_t col) const;
void SetColour(const wxColour& colour, size_t col = 0);
bool IsColour(size_t col) const;
// Set this cell as "checkable" cell with possible label
void SetChecked(bool checked, int bitmapIndex, const wxString& label, size_t col = 0);
bool IsChecked(size_t col = 0) const;
int GetBitmapIndex(size_t col = 0) const;
int GetBitmapSelectedIndex(size_t col = 0) const;
const wxString& GetLabel(size_t col = 0) const;
const std::vector<clRowEntry*>& GetChildren() const { return m_children; }
std::vector<clRowEntry*>& GetChildren() { return m_children; }
wxTreeItemData* GetClientObject() const { return m_clientObject; }
void SetParent(clRowEntry* parent);
clRowEntry* GetParent() const { return m_parent; }
bool HasChildren() const { return !m_children.empty(); }
void SetClientData(wxTreeItemData* clientData)
{
wxDELETE(m_clientObject);
this->m_clientObject = clientData;
}
size_t GetChildrenCount(bool recurse) const;
int GetExpandedLines() const;
void GetNextItems(int count, clRowEntry::Vec_t& items, bool selfIncluded = true);
void GetPrevItems(int count, clRowEntry::Vec_t& items, bool selfIncluded = true);
void SetIndentsCount(int count) { this->m_indentsCount = count; }
int GetIndentsCount() const { return m_indentsCount; }
bool IsSelected() const { return HasFlag(kNF_Selected); }
void SetSelected(bool b) { SetFlag(kNF_Selected, b); }
void UnselectAll();
bool IsSorted() const { return HasFlag(kNF_SortItems); }
};
#endif // CLTREECTRLNODE_H
|