1 #ifndef FILEZILLA_INTERFACE_TREECTRLEX_HEADER 2 #define FILEZILLA_INTERFACE_TREECTRLEX_HEADER 3 4 #include <wx/dnd.h> 5 #include "filelistctrl.h" 6 7 #ifndef __WXMAC__ 8 #define DEFAULT_TREE_STYLE wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT 9 #else 10 #define DEFAULT_TREE_STYLE wxTR_HAS_BUTTONS | wxTR_NO_LINES 11 #endif 12 13 class wxTreeCtrlEx : public wxNavigationEnabled<wxTreeCtrl> 14 { 15 wxDECLARE_CLASS(wxTreeCtrlEx); // Needed for OnCompareItems to work on Windows. Bad library design, why not use normal RTTI? 16 public: 17 typedef wxTreeItemId Item; 18 19 wxTreeCtrlEx(); 20 wxTreeCtrlEx(wxWindow *parent, wxWindowID id = wxID_ANY, 21 const wxPoint& pos = wxDefaultPosition, 22 const wxSize& size = wxDefaultSize, 23 long style = DEFAULT_TREE_STYLE); 24 void SafeSelectItem(wxTreeItemId const& item, bool clearSelection = true); 25 26 // Small wrappers to make wxTreeCtrl(Ex) API more similar to wxListCtrl(ex). GetItemCount()27 int GetItemCount() const { return GetCount(); } GetTopItem()28 wxTreeItemId GetTopItem() const { return GetFirstVisibleItem(); } GetItemRect(wxTreeItemId const & item,wxRect & rect)29 bool GetItemRect(wxTreeItemId const& item, wxRect &rect) const { return GetBoundingRect(item, rect); } 30 GetActualClientRect()31 wxRect GetActualClientRect() const { return GetClientRect(); } 32 Valid(wxTreeItemId const & i)33 bool Valid(wxTreeItemId const& i) const { return i.IsOk(); } 34 GetMainWindow()35 wxWindow* GetMainWindow() { return this; } 36 37 virtual wxTreeItemId GetSelection() const override; 38 39 // wxTreeCtrl::GetSelections has an atrocious interface 40 std::vector<wxTreeItemId> GetAllSelections() const; 41 42 // Items with a collapsed ancestor are not included 43 wxTreeItemId GetFirstItem() const; 44 wxTreeItemId GetLastItem() const; 45 wxTreeItemId GetBottomItem() const; 46 47 wxTreeItemId GetNextItemSimple(wxTreeItemId const& item, bool includeCollapsed = false) const; 48 wxTreeItemId GetPrevItemSimple(wxTreeItemId const& item) const; 49 InPrefixSearch()50 bool InPrefixSearch() const { return inPrefixSearch_; } 51 52 void Resort(); 53 ShouldIgnoreChangeEvent()54 bool ShouldIgnoreChangeEvent() const { return ignore_change_event_ != 0; } 55 56 virtual void Delete(wxTreeItemId const& item) override; 57 virtual void DeleteAllItems() override; 58 59 bool IsRelated(wxTreeItemId const& ancestor, wxTreeItemId child) const; 60 61 wxTreeItemId GetHit(wxPoint const& point); 62 63 wxTreeItemId DisplayDropHighlight(wxPoint const& p); 64 wxTreeItemId DisplayDropHighlight(wxTreeItemId const& item); 65 void ClearDropHighlight(); 66 67 protected: 68 69 bool inPrefixSearch_{}; 70 71 int m_setSelection{}; 72 int ignore_change_event_{}; 73 74 #ifdef __WXMAC__ 75 wxDECLARE_EVENT_TABLE(); 76 void OnChar(wxKeyEvent& event); 77 #endif 78 79 virtual int OnCompareItems(wxTreeItemId const& item1, wxTreeItemId const& item2) override; 80 81 typedef int (*CompareFunction)(std::wstring_view const&, std::wstring_view const&); 82 CompareFunction sortFunction_{}; 83 84 wxTreeItemId m_dropHighlight; 85 }; 86 87 #endif 88