-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathTreebook.cpp
More file actions
101 lines (87 loc) · 3.95 KB
/
Treebook.cpp
File metadata and controls
101 lines (87 loc) · 3.95 KB
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
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/settings.h>
#include <wx/treebook.h>
// Workaround : with wxWidgets version <= 3.2.0 Tree position and size are failed on macOS (and Linux)
#if defined(__APPLE__) || defined(__UNIX__)
#include <wx/treectrl.h>
class TreeBook : public wxTreebook {
public:
TreeBook(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxBK_DEFAULT, const wxString& name = wxEmptyString) : wxTreebook {parent, id, pos, size, style, name} {}
bool AddPage(wxWindow* page, const wxString& text, bool bSelect = false, int imageId = NO_IMAGE) override {
auto backup = save_context {this, bSelect};
auto result = wxTreebook::AddPage(page, text, true, imageId);
InternalFixTreeBookCreattion();
return result;
}
bool AddSubPage(wxWindow* page, const wxString& text, bool bSelect = false, int imageId = NO_IMAGE) override {
auto backup = save_context {this, bSelect};
auto result = wxTreebook::AddSubPage(page, text, true, imageId);
return result;
}
bool InsertPage(size_t pos, wxWindow* page, const wxString& text, bool bSelect = false, int imageId = NO_IMAGE) override {
auto backup = save_context {this, bSelect};
auto result = wxTreebook::InsertPage(pos, page, text, true, imageId);
InternalFixTreeBookCreattion();
return result;
}
bool InsertSubPage(size_t pos, wxWindow* page, const wxString& text, bool bSelect = false, int imageId = NO_IMAGE) override {
auto backup = save_context {this, bSelect};
auto result = wxTreebook::InsertSubPage(pos, page, text, true, imageId);
InternalFixTreeBookCreattion();
return result;
}
private:
class save_context {
public:
save_context(TreeBook* treeBook, bool bSelect) : treeBook_ {treeBook} {selection_ = !bSelect ? treeBook_->GetSelection() : wxNOT_FOUND;}
~save_context() {if (selection_ != wxNOT_FOUND) treeBook_->SetSelection(selection_);}
private:
TreeBook* treeBook_ = nullptr;
int selection_ = wxNOT_FOUND;
};
void InternalFixTreeBookCreattion() {
static auto first_ = true;
if (!first_) {
GetTreeCtrl()->SetSize({GetCurrentPage()->GetPosition().x - 7, GetSize().GetHeight()});
return;
}
GetTreeCtrl()->SetBackgroundColour({255, 255, 255});
GetTreeCtrl()->SetBackgroundColour(wxSystemSettings::GetColour(wxSystemColour::wxSYS_COLOUR_WINDOW));
GetTreeCtrl()->SetPosition({0, 0});
GetTreeCtrl()->SetSize({84, GetSize().GetHeight()});
GetCurrentPage()->SetPosition({GetCurrentPage()->GetPosition().x + 20, GetCurrentPage()->GetPosition().y});
first_ = false;
}
};
#else
using TreeBook = wxTreebook;
#endif
namespace TreebookExample {
class Frame : public wxFrame {
public:
Frame() : wxFrame {nullptr, wxID_ANY, "Treebook example"} {
SetClientSize(390, 270);
tabControl1->AddPage(tabPageRed, "Red");
tabControl1->AddSubPage(tabPageGreen, "Green");
tabControl1->AddSubPage(tabPageBlue, "Blue");
tabControl1->AddPage(tabPageYellow, "Yellow");
tabPageRed->SetBackgroundColour(wxTheColourDatabase->Find("Red"));
tabPageGreen->SetBackgroundColour(wxTheColourDatabase->Find("Green"));
tabPageBlue->SetBackgroundColour(wxTheColourDatabase->Find("Blue"));
tabPageYellow->SetBackgroundColour(wxTheColourDatabase->Find("Yellow"));
}
private:
wxPanel* panel = new wxPanel {this};
TreeBook* tabControl1 = new TreeBook {panel, wxID_ANY, {10, 10}, {370, 250}};
wxNotebookPage* tabPageRed = new wxNotebookPage {tabControl1, wxID_ANY};
wxNotebookPage* tabPageGreen = new wxNotebookPage {tabControl1, wxID_ANY};
wxNotebookPage* tabPageBlue = new wxNotebookPage {tabControl1, wxID_ANY};
wxNotebookPage* tabPageYellow = new wxNotebookPage {tabControl1, wxID_ANY};
};
class Application : public wxApp {
auto OnInit() -> bool override {return (new Frame)->Show();}
};
}
wxIMPLEMENT_APP(TreebookExample::Application);