]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxtree/src/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>
26 wxStoredTree
*myTree
= NULL
;
28 // A macro needed for some compilers (AIX) that need 'main' to be defined
29 // in the application itself.
32 // The `main program' equivalent, creating the windows and returning the
36 // Create the main frame window
37 MyFrame
* frame
= new MyFrame(NULL
, "Tree Test", wxPoint(-1, -1), wxSize(400, 550));
39 // Give it a status line
40 frame
->CreateStatusBar(2);
44 wxIcon
icon("tree_icn");
49 wxMenu
*file_menu
= new wxMenu
;
50 file_menu
->Append(TEST_LEFT_RIGHT
, "&Left to right", "Redraw left to right");
51 file_menu
->Append(TEST_TOP_BOTTOM
, "&Top to bottom", "Redraw top to bottom");
52 file_menu
->AppendSeparator();
53 file_menu
->Append(TEST_QUIT
, "E&xit", "Quit program");
55 wxMenu
*help_menu
= new wxMenu
;
56 help_menu
->Append(TEST_ABOUT
, "&About", "About Tree Test");
58 wxMenuBar
* menu_bar
= new wxMenuBar
;
60 menu_bar
->Append(file_menu
, "&File");
61 menu_bar
->Append(help_menu
, "&Help");
63 // Associate the menu bar with the frame
64 frame
->SetMenuBar(menu_bar
);
66 MyCanvas
*canvas
= new MyCanvas(frame
);
68 // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
69 canvas
->SetScrollbars(20, 20, 50, 50);
70 frame
->canvas
= canvas
;
72 myTree
= new wxStoredTree();
74 wxClientDC
dc(canvas
);
75 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
77 TreeTest(*myTree
, dc
);
81 frame
->SetStatusText("Hello, tree!");
83 // Return the main frame window
87 void MyApp::TreeTest(wxStoredTree
& tree
, wxDC
& dc
)
91 tree
.AddChild("animal");
92 tree
.AddChild("mammal", "animal");
93 tree
.AddChild("insect", "animal");
94 tree
.AddChild("bird", "animal");
96 tree
.AddChild("man", "mammal");
97 tree
.AddChild("cat", "mammal");
98 tree
.AddChild("dog", "mammal");
99 tree
.AddChild("giraffe", "mammal");
100 tree
.AddChild("elephant", "mammal");
101 tree
.AddChild("donkey", "mammal");
102 tree
.AddChild("horse", "mammal");
104 tree
.AddChild("fido", "dog");
105 tree
.AddChild("domestic cat", "cat");
106 tree
.AddChild("lion", "cat");
107 tree
.AddChild("tiger", "cat");
108 tree
.AddChild("felix", "domestic cat");
109 tree
.AddChild("socks", "domestic cat");
111 tree
.AddChild("beetle", "insect");
112 tree
.AddChild("earwig", "insect");
113 tree
.AddChild("eagle", "bird");
114 tree
.AddChild("bluetit", "bird");
115 tree
.AddChild("sparrow", "bird");
116 tree
.AddChild("blackbird", "bird");
117 tree
.AddChild("emu", "bird");
118 tree
.AddChild("crow", "bird");
123 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
124 EVT_MENU(TEST_QUIT
, MyFrame::OnQuit
)
125 EVT_MENU(TEST_ABOUT
, MyFrame::OnAbout
)
126 EVT_MENU(TEST_LEFT_RIGHT
, MyFrame::OnLeftRight
)
127 EVT_MENU(TEST_TOP_BOTTOM
, MyFrame::OnTopBottom
)
128 EVT_CLOSE(MyFrame::OnCloseWindow
)
131 // Define my frame constructor
132 MyFrame::MyFrame(wxWindow
*parent
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
133 wxFrame(parent
, -1, title
, pos
, size
)
137 void MyFrame::OnQuit(wxCommandEvent
& event
)
142 void MyFrame::OnLeftRight(wxCommandEvent
& event
)
146 myTree
->SetOrientation(FALSE
);
147 wxClientDC
dc(canvas
);
148 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
150 wxGetApp().TreeTest(*myTree
, dc
);
155 void MyFrame::OnTopBottom(wxCommandEvent
& event
)
159 myTree
->SetOrientation(TRUE
);
160 wxClientDC
dc(canvas
);
161 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
163 wxGetApp().TreeTest(*myTree
, dc
);
168 void MyFrame::OnAbout(wxCommandEvent
& event
)
170 (void)wxMessageBox("wxWindows tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998", "About tree test");
173 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
178 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
179 EVT_PAINT(MyCanvas::OnPaint
)
182 // Define a constructor for my canvas
183 MyCanvas::MyCanvas(wxWindow
*parent
):
184 wxScrolledWindow(parent
, -1)
188 // Define the repainting behaviour
189 void MyCanvas::OnPaint(wxPaintEvent
& event
)
195 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);