]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/deprecated/treelay/treelay.cpp
Warning fixes and deprecated method elimination from ABX.
[wxWidgets.git] / contrib / samples / deprecated / treelay / treelay.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: treelay.cpp
3 // Purpose: wxTreeLayout sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 7/4/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "wx/deprecated/setup.h"
24
25 #if !wxUSE_TREELAYOUT
26 #error Please set wxUSE_TREELAYOUT to 1 in contrib/include/wx/deprecated/setup.h and recompile.
27 #endif
28
29 #include "wx/deprecated/treelay.h"
30
31 #include "treelay.h"
32
33 wxTreeLayoutStored *myTree = (wxTreeLayoutStored *) NULL;
34
35 // A macro needed for some compilers (AIX) that need 'main' to be defined
36 // in the application itself.
37 IMPLEMENT_APP(MyApp)
38
39 // The `main program' equivalent, creating the windows and returning the
40 // main frame
41 bool MyApp::OnInit()
42 {
43 // Create the main frame window
44 MyFrame* frame = new MyFrame(NULL, _T("Tree Test"), wxPoint(-1, -1), wxSize(400, 550));
45
46 // Give it a status line
47 frame->CreateStatusBar(2);
48
49 // Give it an icon
50 #ifdef __WINDOWS__
51 wxIcon icon(_T("tree_icn"));
52 frame->SetIcon(icon);
53 #endif
54
55 // Make a menubar
56 wxMenu *file_menu = new wxMenu;
57 file_menu->Append(TEST_LEFT_RIGHT, _T("&Left to right"), _T("Redraw left to right"));
58 file_menu->Append(TEST_TOP_BOTTOM, _T("&Top to bottom"), _T("Redraw top to bottom"));
59 file_menu->AppendSeparator();
60 file_menu->Append(TEST_QUIT, _T("E&xit"), _T("Quit program"));
61
62 wxMenu *help_menu = new wxMenu;
63 help_menu->Append(TEST_ABOUT, _T("&About"), _T("About Tree Test"));
64
65 wxMenuBar* menu_bar = new wxMenuBar;
66
67 menu_bar->Append(file_menu, _T("&File"));
68 menu_bar->Append(help_menu, _T("&Help"));
69
70 // Associate the menu bar with the frame
71 frame->SetMenuBar(menu_bar);
72
73 MyCanvas *canvas = new MyCanvas(frame);
74
75 // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
76 canvas->SetScrollbars(20, 20, 50, 50);
77 frame->canvas = canvas;
78
79 myTree = new wxTreeLayoutStored();
80
81 wxClientDC dc(canvas);
82 wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
83 dc.SetFont(font);
84 TreeTest(*myTree, dc);
85
86 frame->Show(TRUE);
87
88 frame->SetStatusText(_T("Hello, tree!"));
89
90 // Return the main frame window
91 return TRUE;
92 }
93
94 int MyApp::OnExit()
95 {
96 if (myTree)
97 {
98 delete myTree;
99 myTree = (wxTreeLayoutStored *) NULL;
100 }
101
102 return 0;
103 }
104
105 void MyApp::TreeTest(wxTreeLayoutStored& tree, wxDC& dc)
106 {
107 tree.Initialize(200);
108
109 tree.AddChild(_T("animal"));
110 tree.AddChild(_T("mammal"), _T("animal"));
111 tree.AddChild(_T("insect"), _T("animal"));
112 tree.AddChild(_T("bird"), _T("animal"));
113
114 tree.AddChild(_T("man"), _T("mammal"));
115 tree.AddChild(_T("cat"), _T("mammal"));
116 tree.AddChild(_T("dog"), _T("mammal"));
117 tree.AddChild(_T("giraffe"), _T("mammal"));
118 tree.AddChild(_T("elephant"), _T("mammal"));
119 tree.AddChild(_T("donkey"), _T("mammal"));
120 tree.AddChild(_T("horse"), _T("mammal"));
121
122 tree.AddChild(_T("fido"), _T("dog"));
123 tree.AddChild(_T("domestic cat"), _T("cat"));
124 tree.AddChild(_T("lion"), _T("cat"));
125 tree.AddChild(_T("tiger"), _T("cat"));
126 tree.AddChild(_T("felix"), _T("domestic cat"));
127 tree.AddChild(_T("socks"), _T("domestic cat"));
128
129 tree.AddChild(_T("beetle"), _T("insect"));
130 tree.AddChild(_T("earwig"), _T("insect"));
131 tree.AddChild(_T("eagle"), _T("bird"));
132 tree.AddChild(_T("bluetit"), _T("bird"));
133 tree.AddChild(_T("sparrow"), _T("bird"));
134 tree.AddChild(_T("blackbird"), _T("bird"));
135 tree.AddChild(_T("emu"), _T("bird"));
136 tree.AddChild(_T("crow"), _T("bird"));
137
138 tree.DoLayout(dc);
139 }
140
141 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
142 EVT_MENU(TEST_QUIT, MyFrame::OnQuit)
143 EVT_MENU(TEST_ABOUT, MyFrame::OnAbout)
144 EVT_MENU(TEST_LEFT_RIGHT, MyFrame::OnLeftRight)
145 EVT_MENU(TEST_TOP_BOTTOM, MyFrame::OnTopBottom)
146 EVT_CLOSE(MyFrame::OnCloseWindow)
147 END_EVENT_TABLE()
148
149 // Define my frame constructor
150 MyFrame::MyFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size):
151 wxFrame(parent, -1, title, pos, size)
152 {
153 }
154
155 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
156 {
157 Close(TRUE);
158 }
159
160 void MyFrame::OnLeftRight(wxCommandEvent& WXUNUSED(event))
161 {
162 if (myTree)
163 {
164 myTree->SetOrientation(FALSE);
165 wxClientDC dc(canvas);
166 wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
167 dc.SetFont(font);
168 wxGetApp().TreeTest(*myTree, dc);
169 canvas->Refresh();
170 }
171 }
172
173 void MyFrame::OnTopBottom(wxCommandEvent& WXUNUSED(event))
174 {
175 if (myTree)
176 {
177 myTree->SetOrientation(TRUE);
178 wxClientDC dc(canvas);
179 wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
180 dc.SetFont(font);
181 wxGetApp().TreeTest(*myTree, dc);
182 canvas->Refresh();
183 }
184 }
185
186 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
187 {
188 (void)wxMessageBox(_T("wxWindows tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998"), _T("About tree test"));
189 }
190
191 void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
192 {
193 Destroy();
194 }
195
196 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
197 EVT_PAINT(MyCanvas::OnPaint)
198 END_EVENT_TABLE()
199
200 // Define a constructor for my canvas
201 MyCanvas::MyCanvas(wxWindow *parent):
202 wxScrolledWindow(parent, -1)
203 {
204 SetBackgroundColour(*wxWHITE);
205 }
206
207 // Define the repainting behaviour
208 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
209 {
210 wxPaintDC dc(this);
211 PrepareDC(dc);
212 if (myTree)
213 {
214 wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
215 dc.SetFont(font);
216 myTree->Draw(dc);
217 }
218 }
219