]>
Commit | Line | Data |
---|---|---|
58580a7e JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tree.cpp | |
be5a51fb | 3 | // Purpose: Minimal wxWidgets sample |
58580a7e JS |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
58580a7e JS |
19 | |
20 | // For compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | // for all others, include the necessary headers (this file is usually all you | |
be5a51fb | 28 | // need because it includes almost all "standard" wxWidgets headers) |
58580a7e JS |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/wx.h" | |
31 | #endif | |
32 | ||
352d44d2 JS |
33 | #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW |
34 | /* Closed folder */ | |
35 | static char * icon1_xpm[] = { | |
36 | /* width height ncolors chars_per_pixel */ | |
37 | "16 16 6 1", | |
38 | /* colors */ | |
39 | " s None c None", | |
40 | ". c #000000", | |
41 | "+ c #c0c0c0", | |
42 | "@ c #808080", | |
43 | "# c #ffff00", | |
44 | "$ c #ffffff", | |
45 | /* pixels */ | |
46 | " ", | |
47 | " @@@@@ ", | |
48 | " @#+#+#@ ", | |
49 | " @#+#+#+#@@@@@@ ", | |
50 | " @$$$$$$$$$$$$@.", | |
51 | " @$#+#+#+#+#+#@.", | |
52 | " @$+#+#+#+#+#+@.", | |
53 | " @$#+#+#+#+#+#@.", | |
54 | " @$+#+#+#+#+#+@.", | |
55 | " @$#+#+#+#+#+#@.", | |
56 | " @$+#+#+#+#+#+@.", | |
57 | " @$#+#+#+#+#+#@.", | |
58 | " @@@@@@@@@@@@@@.", | |
59 | " ..............", | |
60 | " ", | |
61 | " "}; | |
62 | ||
63 | /* File */ | |
64 | static char * icon2_xpm[] = { | |
65 | /* width height ncolors chars_per_pixel */ | |
66 | "16 16 3 1", | |
67 | /* colors */ | |
68 | " s None c None", | |
69 | ". c #000000", | |
70 | "+ c #ffffff", | |
71 | /* pixels */ | |
72 | " ", | |
73 | " ........ ", | |
74 | " .++++++.. ", | |
75 | " .+.+.++.+. ", | |
76 | " .++++++.... ", | |
77 | " .+.+.+++++. ", | |
78 | " .+++++++++. ", | |
79 | " .+.+.+.+.+. ", | |
80 | " .+++++++++. ", | |
81 | " .+.+.+.+.+. ", | |
82 | " .+++++++++. ", | |
83 | " .+.+.+.+.+. ", | |
84 | " .+++++++++. ", | |
85 | " ........... ", | |
86 | " ", | |
87 | " "}; | |
88 | #endif | |
89 | ||
58580a7e JS |
90 | #include "wx/imaglist.h" |
91 | #include "tree.h" | |
92 | ||
93 | // ---------------------------------------------------------------------------- | |
94 | // resources | |
95 | // ---------------------------------------------------------------------------- | |
96 | // the application icon | |
618f2efa | 97 | #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) |
58580a7e JS |
98 | #include "mondrian.xpm" |
99 | #endif | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
be5a51fb | 102 | // event tables and other macros for wxWidgets |
58580a7e JS |
103 | // ---------------------------------------------------------------------------- |
104 | ||
be5a51fb | 105 | // the event tables connect the wxWidgets events with the functions (event |
58580a7e JS |
106 | // handlers) which process them. It can be also done at run-time, but for the |
107 | // simple menu events like this the static method is much simpler. | |
108 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
109 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
110 | EVT_MENU(Minimal_About, MyFrame::OnAbout) | |
111 | END_EVENT_TABLE() | |
112 | ||
be5a51fb | 113 | // Create a new application object: this macro will allow wxWidgets to create |
58580a7e JS |
114 | // the application object during program execution (it's better than using a |
115 | // static object for many reasons) and also declares the accessor function | |
116 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
117 | // not wxApp) | |
118 | IMPLEMENT_APP(MyApp) | |
119 | ||
120 | // ============================================================================ | |
121 | // implementation | |
122 | // ============================================================================ | |
123 | ||
124 | // ---------------------------------------------------------------------------- | |
125 | // the application class | |
126 | // ---------------------------------------------------------------------------- | |
127 | ||
128 | // 'Main program' equivalent: the program execution "starts" here | |
129 | bool MyApp::OnInit() | |
130 | { | |
131 | // create the main application window | |
019abbf2 | 132 | MyFrame *frame = new MyFrame(wxT("Tree Testing"), |
58580a7e JS |
133 | wxPoint(50, 50), wxSize(450, 340)); |
134 | ||
135 | // and show it (the frames, unlike simple controls, are not shown when | |
136 | // created initially) | |
a2d49353 | 137 | frame->Show(true); |
58580a7e JS |
138 | |
139 | // success: wxApp::OnRun() will be called which will enter the main message | |
a2d49353 | 140 | // loop and the application will run. If we returned false here, the |
58580a7e | 141 | // application would exit immediately. |
a2d49353 | 142 | return true; |
58580a7e JS |
143 | } |
144 | ||
145 | // ---------------------------------------------------------------------------- | |
146 | // main frame | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
149 | // frame constructor | |
150 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
151 | : wxFrame((wxFrame *)NULL, idMAIN_FRAME, title, pos, size) | |
152 | { | |
153 | m_splitter = NULL; | |
a2d49353 | 154 | m_scrolledWindow = NULL; |
58580a7e JS |
155 | m_tree = NULL; |
156 | m_valueWindow = NULL; | |
157 | #ifdef __WXMAC__ | |
158 | // we need this in order to allow the about menu relocation, since ABOUT is | |
159 | // not the default id of the about menu | |
160 | wxApp::s_macAboutMenuItemId = Minimal_About; | |
161 | #endif | |
162 | ||
163 | m_scrolledWindow = new wxSplitterScrolledWindow(this, idSCROLLED_WINDOW, wxDefaultPosition, | |
a2d49353 | 164 | wxSize(300, 400), wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL); |
58580a7e | 165 | m_splitter = new wxThinSplitterWindow(m_scrolledWindow, idSPLITTER_WINDOW, wxDefaultPosition, |
a2d49353 WS |
166 | wxDefaultSize, wxSP_3DBORDER | wxCLIP_CHILDREN /* | wxSP_LIVE_UPDATE */); |
167 | m_splitter->SetSashSize(2); | |
a18b162d | 168 | |
a2d49353 | 169 | /* Note the wxTR_ROW_LINES style: draws horizontal lines between items */ |
a18b162d | 170 | m_tree = new TestTree(m_splitter , idTREE_CTRL, wxDefaultPosition, |
a2d49353 | 171 | wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER | wxTR_ROW_LINES ); |
58580a7e | 172 | m_valueWindow = new TestValueWindow(m_splitter, idVALUE_WINDOW, wxDefaultPosition, |
a2d49353 | 173 | wxDefaultSize, wxNO_BORDER); |
58580a7e | 174 | m_splitter->SplitVertically(m_tree, m_valueWindow); |
a2d49353 WS |
175 | //m_splitter->AdjustScrollbars(); |
176 | m_splitter->SetSashPosition(200); | |
177 | m_scrolledWindow->SetTargetWindow(m_tree); | |
58580a7e | 178 | |
a2d49353 | 179 | m_scrolledWindow->EnableScrolling(false, false); |
58580a7e | 180 | |
a2d49353 WS |
181 | // Let the two controls know about each other |
182 | m_valueWindow->SetTreeCtrl(m_tree); | |
183 | m_tree->SetCompanionWindow(m_valueWindow); | |
1a584f14 | 184 | |
58580a7e JS |
185 | // set the frame icon |
186 | SetIcon(wxICON(mondrian)); | |
187 | ||
188 | // create a menu bar | |
019abbf2 | 189 | wxMenu *menuFile = new wxMenu(wxT(""), wxMENU_TEAROFF); |
58580a7e JS |
190 | |
191 | // the "About" item should be in the help menu | |
192 | wxMenu *helpMenu = new wxMenu; | |
019abbf2 | 193 | helpMenu->Append(Minimal_About, wxT("&About...\tCtrl-A"), wxT("Show about dialog")); |
58580a7e | 194 | |
019abbf2 | 195 | menuFile->Append(Minimal_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program")); |
58580a7e JS |
196 | |
197 | // now append the freshly created menu to the menu bar... | |
198 | wxMenuBar *menuBar = new wxMenuBar(); | |
019abbf2 VZ |
199 | menuBar->Append(menuFile, wxT("&File")); |
200 | menuBar->Append(helpMenu, wxT("&Help")); | |
58580a7e JS |
201 | |
202 | // ... and attach this menu bar to the frame | |
203 | SetMenuBar(menuBar); | |
204 | } | |
205 | ||
206 | ||
207 | // event handlers | |
208 | ||
209 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
210 | { | |
a2d49353 WS |
211 | // true is to force the frame to close |
212 | Close(true); | |
58580a7e JS |
213 | } |
214 | ||
215 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
216 | { | |
217 | wxString msg; | |
019abbf2 VZ |
218 | msg.Printf( wxT("This is the about dialog of splittree sample.\n") |
219 | wxT("Welcome to %s"), wxVERSION_STRING); | |
58580a7e | 220 | |
019abbf2 | 221 | wxMessageBox(msg, wxT("About Tree Test"), wxOK | wxICON_INFORMATION, this); |
58580a7e JS |
222 | } |
223 | ||
224 | /* | |
225 | * TesTree | |
226 | */ | |
227 | ||
228 | IMPLEMENT_CLASS(TestTree, wxRemotelyScrolledTreeCtrl) | |
229 | ||
230 | BEGIN_EVENT_TABLE(TestTree, wxRemotelyScrolledTreeCtrl) | |
231 | END_EVENT_TABLE() | |
232 | ||
233 | TestTree::TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt, | |
234 | const wxSize& sz, long style): | |
235 | wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style) | |
236 | { | |
a2d49353 | 237 | m_imageList = new wxImageList(16, 16, true); |
58580a7e JS |
238 | #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW |
239 | m_imageList->Add(wxIcon(icon1_xpm)); | |
240 | m_imageList->Add(wxIcon(icon2_xpm)); | |
58580a7e JS |
241 | #elif defined(__WXMSW__) |
242 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
58580a7e | 243 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE)); |
58580a7e JS |
244 | #else |
245 | #error "Sorry, we don't have icons available for this platforms." | |
246 | #endif | |
247 | SetImageList(m_imageList); | |
248 | ||
a2d49353 WS |
249 | |
250 | // Add some dummy items | |
251 | wxTreeItemId rootId = AddRoot(_("Root"), -1, -1); | |
252 | int i; | |
253 | for (i = 1; i <= 20; i++) | |
254 | { | |
255 | wxString label; | |
256 | label.Printf(wxT("Item %d"), i); | |
257 | wxTreeItemId id = AppendItem(rootId, label, 0); | |
258 | //SetItemImage( id, 1, wxTreeItemIcon_Expanded ); | |
259 | ||
260 | int j; | |
261 | for (j = 0; j < 10; j++) | |
262 | AppendItem(id, _("Child"), 1); | |
263 | } | |
264 | Expand(rootId); | |
58580a7e JS |
265 | } |
266 | ||
267 | TestTree::~TestTree() | |
268 | { | |
a2d49353 WS |
269 | SetImageList(NULL); |
270 | delete m_imageList; | |
58580a7e JS |
271 | } |
272 | ||
273 | /* | |
274 | * TestValueWindow | |
275 | */ | |
276 | ||
277 | //IMPLEMENT_CLASS(TestValueWindow, wxWindow) | |
278 | ||
1a584f14 | 279 | BEGIN_EVENT_TABLE(TestValueWindow, wxTreeCompanionWindow) |
58580a7e JS |
280 | END_EVENT_TABLE() |
281 | ||
282 | TestValueWindow::TestValueWindow(wxWindow* parent, wxWindowID id, | |
283 | const wxPoint& pos, | |
284 | const wxSize& sz, | |
285 | long style): | |
1a584f14 | 286 | wxTreeCompanionWindow(parent, id, pos, sz, style) |
58580a7e | 287 | { |
a2d49353 | 288 | SetBackgroundColour(* wxWHITE); |
58580a7e | 289 | } |