File: clTreeCtrlModel.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 (154 lines) | stat: -rw-r--r-- 5,576 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
#ifndef CLTREECTRLMODEL_H
#define CLTREECTRLMODEL_H

#include "clRowEntry.h"
#include "codelite_exports.h"

#include <functional>
#include <vector>
#include <wx/colour.h>
#include <wx/sharedptr.h>
#include <wx/string.h>
#include <wx/treebase.h>

class clTreeCtrl;
typedef std::function<bool(clRowEntry*, clRowEntry*)> clSortFunc_t;
class WXDLLIMPEXP_SDK clTreeCtrlModel
{
    clTreeCtrl* m_tree = nullptr;
    clRowEntry* m_root = nullptr;
    clRowEntry::Vec_t m_selectedItems;
    clRowEntry::Vec_t m_onScreenItems;
    clRowEntry* m_firstItemOnScreen = nullptr;
    int m_indentSize = 16;
    bool m_shutdown = false;
    clSortFunc_t m_shouldInsertBeforeFunc = nullptr;

protected:
    void DoExpandAllChildren(const wxTreeItemId& item, bool expand);
    bool IsSingleSelection() const;
    bool IsMultiSelection() const;
    bool SendEvent(wxEvent& event);

public:
    clTreeCtrlModel(clTreeCtrl* tree);
    ~clTreeCtrlModel();

    void SetFirstItemOnScreen(clRowEntry* firstItemOnScreen) { this->m_firstItemOnScreen = firstItemOnScreen; }
    clRowEntry* GetFirstItemOnScreen() const { return m_firstItemOnScreen; }

    void SetSortFunction(const clSortFunc_t& CompareFunc) { m_shouldInsertBeforeFunc = CompareFunc; }
    clSortFunc_t GetSortFunction() const { return m_shouldInsertBeforeFunc; }

    void ExpandAllChildren(const wxTreeItemId& item);
    void CollapseAllChildren(const wxTreeItemId& item);

    // Notifications from the node
    void NodeDeleted(clRowEntry* node);
    void NodeExpanded(clRowEntry* node, bool expanded);
    bool NodeExpanding(clRowEntry* node, bool expanding);

    void GetNextItems(clRowEntry* from, int count, clRowEntry::Vec_t& items, bool selfIncluded = true) const;
    void GetPrevItems(clRowEntry* from, int count, clRowEntry::Vec_t& items, bool selfIncluded = true) const;
    wxTreeItemId AddRoot(const wxString& text, int image, int selImage, wxTreeItemData* data);
    wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image, int selImage,
                            wxTreeItemData* data);
    wxTreeItemId InsertItem(const wxTreeItemId& parent, const wxTreeItemId& previous, const wxString& text, int image,
                            int selImage, wxTreeItemData* data);
    wxTreeItemId GetRootItem() const;

    void SetIndentSize(int indentSize) { this->m_indentSize = indentSize; }
    int GetIndentSize() const { return m_indentSize; }

    /**
     * @brief clear the selection from all the items
     */
    void UnselectAll();

    wxTreeItemId GetItemBefore(const wxTreeItemId& item, bool visibleItem) const;
    wxTreeItemId GetItemAfter(const wxTreeItemId& item, bool visibleItem) const;
    clRowEntry* GetRowBefore(clRowEntry* item, bool visibleItem) const;
    clRowEntry* GetRowAfter(clRowEntry* item, bool visibleItem) const;
    clRowEntry* ToPtr(const wxTreeItemId& item) const
    {
        if(!m_root || !item.IsOk()) {
            return nullptr;
        }
        return reinterpret_cast<clRowEntry*>(item.GetID());
    }

    /**
     * @brief select a given item
     */
    void SelectItem(const wxTreeItemId& item, bool select = true, bool addSelection = false,
                    bool clear_old_selection = false);
    /**
     * @brief add an item to the selection list
     * this function fires an event
     */
    void AddSelection(const wxTreeItemId& item);

    /**
     * @brief clear all selections, return true on sucess, this function fires the changing event
     */
    bool ClearSelections(bool notify);

    bool IsItemSelected(const wxTreeItemId& item) const { return IsItemSelected(ToPtr(item)); }
    bool IsItemSelected(const clRowEntry* item) const;

    bool IsVisible(const wxTreeItemId& item) const;

    /**
     * @brief select the children of 'item' this functin fires the changing and changed events
     */
    void SelectChildren(const wxTreeItemId& item);

    void Clear();

    void SetOnScreenItems(const clRowEntry::Vec_t& items);

    const clRowEntry::Vec_t& GetOnScreenItems() const { return m_onScreenItems; }
    clRowEntry::Vec_t& GetOnScreenItems() { return m_onScreenItems; }
    const clRowEntry::Vec_t& GetSelections() const { return m_selectedItems; }
    bool ExpandToItem(const wxTreeItemId& item);
    wxTreeItemId GetSingleSelection() const;
    size_t GetSelectionsCount() const { return m_selectedItems.size(); }

    /**
     * @brief do we have items in this tree? (root included)
     */
    bool IsEmpty() const { return m_root == nullptr; }

    clRowEntry* GetRoot() const { return m_root; }

    /**
     * @brief delete subtree starting from 'item', including item
     * fires event wxEVT_TREE_DELETE_ITEM
     * @param item
     */
    void DeleteItem(const wxTreeItemId& item);
    int GetItemIndex(clRowEntry* item) const;
    clRowEntry* GetItemFromIndex(int index) const;

    /**
     * @brief return the last visible item
     * NOTE: this does not check if the item is actually is displayed on the screen
     * it only checks if the item is a state that allows it to be displayed on screen
     */
    clRowEntry* GetLastVisibleItem() const;

    /**
     * @brief get range of items from -> to
     * Or from: to->from (incase 'to' has a lower index)
     */
    bool GetRange(clRowEntry* from, clRowEntry* to, clRowEntry::Vec_t& items) const;

    size_t GetExpandedLines() const;

    clRowEntry* GetNextSibling(clRowEntry* item) const;
    clRowEntry* GetPrevSibling(clRowEntry* item) const;

    void EnableEvents(bool enable) { m_shutdown = !enable; }
};

#endif // CLTREECTRLMODEL_H