]>
git.saurik.com Git - wxWidgets.git/blob - samples/treelay/test.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/treelay.h>
27 wxTreeLayoutStored
*myTree
= NULL
;
29 // A macro needed for some compilers (AIX) that need 'main' to be defined
30 // in the application itself.
33 // The `main program' equivalent, creating the windows and returning the
37 // Create the main frame window
38 MyFrame
* frame
= new MyFrame(NULL
, "Tree Test", wxPoint(-1, -1), wxSize(400, 550));
40 // Give it a status line
41 frame
->CreateStatusBar(2);
45 wxIcon
icon("tree_icn");
50 wxMenu
*file_menu
= new wxMenu
;
51 file_menu
->Append(TEST_LEFT_RIGHT
, "&Left to right", "Redraw left to right");
52 file_menu
->Append(TEST_TOP_BOTTOM
, "&Top to bottom", "Redraw top to bottom");
53 file_menu
->AppendSeparator();
54 file_menu
->Append(TEST_QUIT
, "E&xit", "Quit program");
56 wxMenu
*help_menu
= new wxMenu
;
57 help_menu
->Append(TEST_ABOUT
, "&About", "About Tree Test");
59 wxMenuBar
* menu_bar
= new wxMenuBar
;
61 menu_bar
->Append(file_menu
, "&File");
62 menu_bar
->Append(help_menu
, "&Help");
64 // Associate the menu bar with the frame
65 frame
->SetMenuBar(menu_bar
);
67 MyCanvas
*canvas
= new MyCanvas(frame
);
69 // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
70 canvas
->SetScrollbars(20, 20, 50, 50);
71 frame
->canvas
= canvas
;
73 myTree
= new wxTreeLayoutStored();
75 wxClientDC
dc(canvas
);
76 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
78 TreeTest(*myTree
, dc
);
82 frame
->SetStatusText("Hello, tree!");
84 // Return the main frame window
88 void MyApp::TreeTest(wxTreeLayoutStored
& tree
, wxDC
& dc
)
92 tree
.AddChild("animal");
93 tree
.AddChild("mammal", "animal");
94 tree
.AddChild("insect", "animal");
95 tree
.AddChild("bird", "animal");
97 tree
.AddChild("man", "mammal");
98 tree
.AddChild("cat", "mammal");
99 tree
.AddChild("dog", "mammal");
100 tree
.AddChild("giraffe", "mammal");
101 tree
.AddChild("elephant", "mammal");
102 tree
.AddChild("donkey", "mammal");
103 tree
.AddChild("horse", "mammal");
105 tree
.AddChild("fido", "dog");
106 tree
.AddChild("domestic cat", "cat");
107 tree
.AddChild("lion", "cat");
108 tree
.AddChild("tiger", "cat");
109 tree
.AddChild("felix", "domestic cat");
110 tree
.AddChild("socks", "domestic cat");
112 tree
.AddChild("beetle", "insect");
113 tree
.AddChild("earwig", "insect");
114 tree
.AddChild("eagle", "bird");
115 tree
.AddChild("bluetit", "bird");
116 tree
.AddChild("sparrow", "bird");
117 tree
.AddChild("blackbird", "bird");
118 tree
.AddChild("emu", "bird");
119 tree
.AddChild("crow", "bird");
124 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
125 EVT_MENU(TEST_QUIT
, MyFrame::OnQuit
)
126 EVT_MENU(TEST_ABOUT
, MyFrame::OnAbout
)
127 EVT_MENU(TEST_LEFT_RIGHT
, MyFrame::OnLeftRight
)
128 EVT_MENU(TEST_TOP_BOTTOM
, MyFrame::OnTopBottom
)
129 EVT_CLOSE(MyFrame::OnCloseWindow
)
132 // Define my frame constructor
133 MyFrame::MyFrame(wxWindow
*parent
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
134 wxFrame(parent
, -1, title
, pos
, size
)
138 void MyFrame::OnQuit(wxCommandEvent
& event
)
143 void MyFrame::OnLeftRight(wxCommandEvent
& event
)
147 myTree
->SetOrientation(FALSE
);
148 wxClientDC
dc(canvas
);
149 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
151 wxGetApp().TreeTest(*myTree
, dc
);
156 void MyFrame::OnTopBottom(wxCommandEvent
& event
)
160 myTree
->SetOrientation(TRUE
);
161 wxClientDC
dc(canvas
);
162 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
164 wxGetApp().TreeTest(*myTree
, dc
);
169 void MyFrame::OnAbout(wxCommandEvent
& event
)
171 (void)wxMessageBox("wxWindows tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998", "About tree test");
174 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
179 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
180 EVT_PAINT(MyCanvas::OnPaint
)
183 // Define a constructor for my canvas
184 MyCanvas::MyCanvas(wxWindow
*parent
):
185 wxScrolledWindow(parent
, -1)
187 SetBackgroundColour(*wxWHITE
);
190 // Define the repainting behaviour
191 void MyCanvas::OnPaint(wxPaintEvent
& event
)
197 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);