]>
git.saurik.com Git - wxWidgets.git/blob - samples/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/treelay.h"
27 wxTreeLayoutStored
*myTree
= (wxTreeLayoutStored
*) 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
93 myTree
= (wxTreeLayoutStored
*) NULL
;
99 void MyApp::TreeTest(wxTreeLayoutStored
& tree
, wxDC
& dc
)
101 tree
.Initialize(200);
103 tree
.AddChild("animal");
104 tree
.AddChild("mammal", "animal");
105 tree
.AddChild("insect", "animal");
106 tree
.AddChild("bird", "animal");
108 tree
.AddChild("man", "mammal");
109 tree
.AddChild("cat", "mammal");
110 tree
.AddChild("dog", "mammal");
111 tree
.AddChild("giraffe", "mammal");
112 tree
.AddChild("elephant", "mammal");
113 tree
.AddChild("donkey", "mammal");
114 tree
.AddChild("horse", "mammal");
116 tree
.AddChild("fido", "dog");
117 tree
.AddChild("domestic cat", "cat");
118 tree
.AddChild("lion", "cat");
119 tree
.AddChild("tiger", "cat");
120 tree
.AddChild("felix", "domestic cat");
121 tree
.AddChild("socks", "domestic cat");
123 tree
.AddChild("beetle", "insect");
124 tree
.AddChild("earwig", "insect");
125 tree
.AddChild("eagle", "bird");
126 tree
.AddChild("bluetit", "bird");
127 tree
.AddChild("sparrow", "bird");
128 tree
.AddChild("blackbird", "bird");
129 tree
.AddChild("emu", "bird");
130 tree
.AddChild("crow", "bird");
135 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
136 EVT_MENU(TEST_QUIT
, MyFrame::OnQuit
)
137 EVT_MENU(TEST_ABOUT
, MyFrame::OnAbout
)
138 EVT_MENU(TEST_LEFT_RIGHT
, MyFrame::OnLeftRight
)
139 EVT_MENU(TEST_TOP_BOTTOM
, MyFrame::OnTopBottom
)
140 EVT_CLOSE(MyFrame::OnCloseWindow
)
143 // Define my frame constructor
144 MyFrame::MyFrame(wxWindow
*parent
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
145 wxFrame(parent
, -1, title
, pos
, size
)
149 void MyFrame::OnQuit(wxCommandEvent
& event
)
154 void MyFrame::OnLeftRight(wxCommandEvent
& event
)
158 myTree
->SetOrientation(FALSE
);
159 wxClientDC
dc(canvas
);
160 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
162 wxGetApp().TreeTest(*myTree
, dc
);
167 void MyFrame::OnTopBottom(wxCommandEvent
& event
)
171 myTree
->SetOrientation(TRUE
);
172 wxClientDC
dc(canvas
);
173 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
175 wxGetApp().TreeTest(*myTree
, dc
);
180 void MyFrame::OnAbout(wxCommandEvent
& event
)
182 (void)wxMessageBox("wxWindows tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998", "About tree test");
185 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
190 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
191 EVT_PAINT(MyCanvas::OnPaint
)
194 // Define a constructor for my canvas
195 MyCanvas::MyCanvas(wxWindow
*parent
):
196 wxScrolledWindow(parent
, -1)
198 SetBackgroundColour(*wxWHITE
);
201 // Define the repainting behaviour
202 void MyCanvas::OnPaint(wxPaintEvent
& event
)
208 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);