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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
|
#ifndef CLTREECTRL_H
#define CLTREECTRL_H
#include "clControlWithItems.h"
#include "clHeaderBar.h"
#include "clRowEntry.h"
#include "clScrolledPanel.h"
#include "clTreeCtrlModel.h"
#include "codelite_exports.h"
#include <wx/arrstr.h>
#include <wx/datetime.h>
#include <wx/dc.h>
#include <wx/headercol.h>
#include <wx/panel.h>
#include <wx/scrolwin.h>
#define wxTR_ENABLE_SEARCH 0x4000
#define wxTR_COLUMN_WIDTH_NEVER_SHRINKS 0x8000
// Sorting is applied for top level items (i.e. items whom their direct parent is the root item)
#define wxTR_SORT_TOP_LEVEL 0x0100
static const int wxTREE_HITTEST_ONACTIONBUTTON = 0x2000;
class clScrollBar;
enum class eRendererType {
RENDERER_DEFAULT = 0,
RENDERER_DIRECT2D,
RENDERER_CAIRO,
};
class WXDLLIMPEXP_SDK clTreeCtrl : public clControlWithItems
{
protected:
clTreeCtrlModel m_model;
bool m_needToClearDefaultHeader = true;
long m_treeStyle = 0;
int m_scrollLines = 0;
bool m_bulkInsert = false;
bool m_drawBorder = false;
clSortFunc_t m_oldSortFunc;
eRendererType m_renderer = eRendererType::RENDERER_DEFAULT;
size_t m_spacerY = clRowEntry::Y_SPACER;
size_t m_spacerX = clRowEntry::X_SPACER;
private:
wxPoint DoFixPoint(const wxPoint& pt);
wxTreeItemId DoGetSiblingVisibleItem(const wxTreeItemId& item, bool next) const;
bool IsItemVisible(clRowEntry* item) const;
bool IsItemFullyVisible(clRowEntry* item) const;
void EnsureItemVisible(clRowEntry* item, bool fromTop);
clRowEntry* GetFirstItemOnScreen() override;
void SetFirstItemOnScreen(clRowEntry* item) override;
wxTreeItemId DoScrollLines(int numLines, bool up, wxTreeItemId from, bool selectIt);
void UpdateButtonState(clRowEntry::Vec_t& lines);
/**
* @brief bitmap file was added, re-calculate the line heights
*/
void DoBitmapAdded();
/**
* @brief update the header size
*/
void DoUpdateHeader(const wxTreeItemId& item);
void DoInitialize();
clRowEntry* DoFind(clRowEntry* from, const wxString& what, size_t col, size_t searchFlags, bool next);
/**
* @brief display a colour picker dialog for the given item
*/
void ShowColourPicker(const wxTreeItemId& item, int column);
protected:
void UpdateScrollBar() override;
void DoAddHeader(const wxString& label, const wxBitmap& bmp, int width = wxCOL_WIDTH_AUTOSIZE);
void UpdateLineHeight();
public:
int GetFirstItemPosition() const override;
int GetRange() const override;
clTreeCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0);
clTreeCtrl();
virtual ~clTreeCtrl();
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0);
/**
* @brief set the upper and lower spacing between lines in the view
*/
void SetLineSpacing(size_t pixels);
void SetRendererType(eRendererType renderer)
{
m_renderer = renderer;
Refresh();
}
void SetDefaultFont(const wxFont& font) override;
/**
* @brief notify the control that we are doing bulk insert so avoid
* not needed UI updates
*/
void Begin();
/**
* @brief update the UI to the control content, use with `Begin()`
*/
void Commit();
//===--------------------
// Search support
//===--------------------
/**
* @brief search for an item from pos that matches the "what" string.
* Pass an invalid item to start the search from the root
*/
wxTreeItemId FindNext(const wxTreeItemId& from, const wxString& what, size_t col = 0,
size_t searchFlags = wxTR_SEARCH_DEFAULT);
/**
* @brief search for an item from pos that matches the "what" string.
* Pass an invalid item to start the search from the root
*/
wxTreeItemId FindPrev(const wxTreeItemId& from, const wxString& what, size_t col = 0,
size_t searchFlags = wxTR_SEARCH_DEFAULT);
/**
* @brief highlight matched string of an item. This call should be called after a successfull call to
* FindNext or FindPrev
*/
void HighlightText(const wxTreeItemId& item, bool b);
/**
* @brief clear highlighted text
*/
void ClearHighlight(const wxTreeItemId& item);
/**
* @brief clear all highlighted text from all the items
*/
void ClearAllHighlights();
/**
* @brief set highlight information for a given item
* @param item the item to highlight
* @param start_pos position within the item text
* @param len number of characters to highlight
* @param col which column text should we highlight?
*/
void SetItemHighlightInfo(const wxTreeItemId& item, size_t start_pos, size_t len, size_t col = 0);
//===--------------------
// table view support
//===--------------------
void AddHeader(const wxString& label, const wxBitmap& bmp = wxNullBitmap, int width = wxCOL_WIDTH_AUTOSIZE);
// For internal use, dont use these two methods
const clTreeCtrlModel& GetModel() const { return m_model; }
clTreeCtrlModel& GetModel() { return m_model; }
/**
* @brief set a sorting function for this tree. The function returns true if the first element should be placed
* before the second element
*/
virtual void SetSortFunction(const clSortFunc_t& CompareFunc);
/**
* @brief associate bitmap vector with this tree. The bitmaps array must exists as long as this control exists
*/
void SetBitmaps(BitmapVec_t* bitmaps) override;
/**
* @brief set image list. The control does not take ownership on the input image list
* Instead, it creates a copy of the images. It is up to the user to free any resources allocated
*/
void SetImageList(wxImageList* images) override;
/**
* @brief return the tree style
*/
long GetTreeStyle() const { return m_treeStyle; }
/**
* @brief is the root hidden?
*/
bool IsRootHidden() const { return m_treeStyle & wxTR_HIDE_ROOT; }
/**
* @brief enable style on the tree
*/
virtual void EnableStyle(int style, bool enable, bool refresh = true);
/**
* @brief does the tree has 'style' enabled?
*/
bool HasStyle(int style) const { return m_treeStyle & style; }
/**
* @brief add style to the current tree style
*/
void AddTreeStyle(int style) { m_treeStyle |= style; }
/**
* @brief set style to the tree
*/
void SetTreeStyle(int style) { m_treeStyle = style; }
/**
* @brief Calculates which (if any) item is under the given point, returning the tree item id at this point plus
* extra information flags.
* flags is a bitlist of the following (the bits are output returned by this function):
* wxTREE_HITTEST_NOWHERE: In the client area but below the last item.
* wxTREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
* wxTREE_HITTEST_ONITEM
*/
wxTreeItemId HitTest(const wxPoint& point, int& flags, int& column) const;
/**
* @brief ppends an item to the end of the branch identified by parent, return a new item id.
*/
wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selImage = -1,
wxTreeItemData* data = NULL);
/**
* @brief Adds the root node to the tree, returning the new item.
*/
wxTreeItemId AddRoot(const wxString& text, int image = -1, int selImage = -1, wxTreeItemData* data = NULL);
/**
* @brief insert item after 'previous'
*/
wxTreeItemId InsertItem(const wxTreeItemId& parent, const wxTreeItemId& previous, const wxString& text,
int image = -1, int selImage = -1, wxTreeItemData* data = NULL);
/**
* @brief return the root item
*/
wxTreeItemId GetRootItem() const;
/**
* @brief return the item's parent
*/
wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
/**
* @brief Expands the given item
*/
void Expand(const wxTreeItemId& item);
/**
* @brief check a given item (if it has checkbox)
* This method fires 'wxEVT_TREE_ITEM_VALUE_CHANGED' event
*/
void Check(const wxTreeItemId& item, bool check, size_t col = 0);
/**
* @brief is the state of an item is checked?
*/
bool IsChecked(const wxTreeItemId& item, size_t col = 0) const;
/**
* @brief Collapses the given item
*/
void Collapse(const wxTreeItemId& item);
/**
* @brief Selects the given item
*/
void SelectItem(const wxTreeItemId& item, bool select = true);
// Selection
wxTreeItemId GetSelection() const;
wxTreeItemId GetFocusedItem() const;
size_t GetSelections(wxArrayTreeItemIds& selections) const;
/**
* @brief unselect all items
*/
void UnselectAll();
/**
* @brief Scrolls and/or expands items to ensure that the given item is visible.
*/
void EnsureVisible(const wxTreeItemId& item);
/**
* @brief is item expanded?
*/
bool IsExpanded(const wxTreeItemId& item) const;
/**
* @brief Returns true if the item has children.
*/
bool ItemHasChildren(const wxTreeItemId& item) const;
bool HasChildren(const wxTreeItemId& item) const { return ItemHasChildren(item); }
/**
* @brief set the item's indent size
*/
void SetIndent(int size) override;
/**
* @brief return the current indent size
*/
virtual int GetIndent() const override;
/**
* @brief is the tree has items? (root included)
*/
bool IsEmpty() const override;
/**
* @brief return the children count of this item
*/
size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = true) const;
/**
* @brief Delete all the item's children. No events are fired
*/
void DeleteChildren(const wxTreeItemId& item);
/**
* @brief Returns the first child; call GetNextChild() for the next child.
*/
wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
/**
* @brief get the next item in tree (as if you were clicking DOWN in the keyboard)
*/
wxTreeItemId GetNextItem(const wxTreeItemId& item) const;
/**
* @brief get the prev item in tree (as if you were clicking DOWN in the keyboard)
*/
wxTreeItemId GetPrevItem(const wxTreeItemId& item) const;
/**
* @brief for compatibility, we dont really need to call this method manually
*/
void SortChildren(const wxTreeItemId& item) { wxUnusedVar(item); }
/**
* @brief set item's image index
*/
void SetItemImage(const wxTreeItemId& item, int imageId, int openImageId = wxNOT_FOUND, size_t col = 0);
/**
* @brief return the associated image id with this item
*/
int GetItemImage(const wxTreeItemId& item, bool selectedImage = false, size_t col = 0) const;
/**
* @brief Returns the first visible item
*/
wxTreeItemId GetFirstVisibleItem() const;
/**
* @brief Returns the next visible item or an invalid item if this item is the last visible one
*/
wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
/**
* @brief Returns the prev visible item or an invalid item if this item is the first visible one
*/
wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
//===--------------------------------
// Item properties
//===--------------------------------
wxTreeItemData* GetItemData(const wxTreeItemId& item) const;
void SetItemData(const wxTreeItemId& item, wxTreeItemData* data);
void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& colour, size_t col = 0);
wxColour GetItemBackgroundColour(const wxTreeItemId& item, size_t col = 0) const;
void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour, size_t col = 0);
wxColour GetItemTextColour(const wxTreeItemId& item, size_t col = 0) const;
void SetItemText(const wxTreeItemId& item, const wxString& text, size_t col = 0);
wxString GetItemText(const wxTreeItemId& item, size_t col = 0) const;
void SetItemBold(const wxTreeItemId& item, bool bold, size_t col = 0);
void SetItemFont(const wxTreeItemId& item, const wxFont& font, size_t col = 0);
wxFont GetItemFont(const wxTreeItemId& item, size_t col = 0) const;
/**
* @brief expand this item and all its children
*/
void ExpandAllChildren(const wxTreeItemId& item);
/**
* @brief expand the entire tree
*/
void ExpandAll() { ExpandAllChildren(GetRootItem()); }
/**
* @brief expand this item and all its children
*/
void CollapseAllChildren(const wxTreeItemId& item);
/**
* @brief expand the entire tree
*/
void CollapseAll() { CollapseAllChildren(GetRootItem()); }
/**
* @brief Deletes the specified item.
* A EVT_TREE_DELETE_ITEM event will be generated.
*/
void Delete(const wxTreeItemId& item);
/**
* @brief Select all the immediate children of the given parent
*/
void SelectChildren(const wxTreeItemId& item);
/**
* @brief Returns the next sibling of the specified item; call GetPrevSibling() for the previous sibling
*/
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
/**
* @brief Returns the previous sibling of the specified item; call GetNextSibling() for the next sibling
*/
wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
/**
* @brief delete all items in tree
*/
virtual void DeleteAllItems();
/**
* @brief is this item visible?
*/
bool IsVisible(const wxTreeItemId& item) const;
/**
* @brief is item selected?
*/
bool IsSelected(const wxTreeItemId& item) const;
/**
* @brief move one line up
*/
void LineUp();
/**
* @brief move one line down
*/
void LineDown();
/**
* @brief move page down
*/
void PageDown();
/**
* @brief move page up
*/
void PageUp();
protected:
bool DoKeyDown(const wxKeyEvent& event) override;
void DoEnsureVisible(const wxTreeItemId& item);
void OnPaint(wxPaintEvent& event);
void OnMouseLeftDown(wxMouseEvent& event);
void OnMouseLeftUp(wxMouseEvent& event);
void OnRightDown(wxMouseEvent& event);
void OnMouseLeftDClick(wxMouseEvent& event);
void DoMouseScroll(const wxMouseEvent& event) override;
void ProcessIdle() override;
void OnLeaveWindow(wxMouseEvent& event);
void OnEnterWindow(wxMouseEvent& event);
void OnContextMenu(wxContextMenuEvent& event);
void ScrollRows(int steps, wxDirection direction) override;
void ScrollToRow(int firstLine) override;
wxTreeItemId GetRow(const wxPoint& pt) const override;
};
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_SDK, wxEVT_TREE_ITEM_VALUE_CHANGED, wxTreeEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_SDK, wxEVT_TREE_ACTIONBUTTON_CLICKED, wxTreeEvent);
#endif // CLTREECTRL_H
|