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