]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/deprecated/treelay/treelay.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeLayout sample
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/deprecated/setup.h"
26 #error Please set wxUSE_TREELAYOUT to 1 in contrib/include/wx/deprecated/setup.h and recompile.
29 #include "wx/deprecated/treelay.h"
33 wxTreeLayoutStored
*myTree
= (wxTreeLayoutStored
*) NULL
;
35 // A macro needed for some compilers (AIX) that need 'main' to be defined
36 // in the application itself.
39 // The `main program' equivalent, creating the windows and returning the
43 // Create the main frame window
44 MyFrame
* frame
= new MyFrame(NULL
, _T("Tree Test"), wxDefaultPosition
, wxSize(400, 550));
47 // Give it a status line
48 frame
->CreateStatusBar(2);
49 #endif // wxUSE_STATUSBAR
53 wxIcon
icon(_T("tree_icn"));
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"));
64 wxMenu
*help_menu
= new wxMenu
;
65 help_menu
->Append(TEST_ABOUT
, _T("&About"), _T("About Tree Test"));
67 wxMenuBar
* menu_bar
= new wxMenuBar
;
69 menu_bar
->Append(file_menu
, _T("&File"));
70 menu_bar
->Append(help_menu
, _T("&Help"));
72 // Associate the menu bar with the frame
73 frame
->SetMenuBar(menu_bar
);
75 MyCanvas
*canvas
= new MyCanvas(frame
);
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
;
81 myTree
= new wxTreeLayoutStored();
83 wxClientDC
dc(canvas
);
84 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
86 TreeTest(*myTree
, dc
);
91 frame
->SetStatusText(_T("Hello, tree!"));
92 #endif // wxUSE_STATUSBAR
94 // Return the main frame window
103 myTree
= (wxTreeLayoutStored
*) NULL
;
109 void MyApp::TreeTest(wxTreeLayoutStored
& tree
, wxDC
& dc
)
111 tree
.Initialize(200);
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"));
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"));
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"));
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"));
145 BEGIN_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
)
153 // Define my frame constructor
154 MyFrame::MyFrame(wxWindow
*parent
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
155 wxFrame(parent
, wxID_ANY
, title
, pos
, size
)
159 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
164 void MyFrame::OnLeftRight(wxCommandEvent
& WXUNUSED(event
))
168 myTree
->SetOrientation(false);
169 wxClientDC
dc(canvas
);
170 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
172 wxGetApp().TreeTest(*myTree
, dc
);
177 void MyFrame::OnTopBottom(wxCommandEvent
& WXUNUSED(event
))
181 myTree
->SetOrientation(true);
182 wxClientDC
dc(canvas
);
183 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
185 wxGetApp().TreeTest(*myTree
, dc
);
190 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
192 (void)wxMessageBox(_T("wxWidgets tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998"), _T("About tree test"));
195 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
200 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
201 EVT_PAINT(MyCanvas::OnPaint
)
204 // Define a constructor for my canvas
205 MyCanvas::MyCanvas(wxWindow
*parent
):
206 wxScrolledWindow(parent
, wxID_ANY
)
208 SetBackgroundColour(*wxWHITE
);
211 // Define the repainting behaviour
212 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
218 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);