]>
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
, _T("Tree Test"), wxPoint(-1, -1), wxSize(400, 550));
40 // Give it a status line
41 frame
->CreateStatusBar(2);
45 wxIcon
icon(_T("tree_icn"));
50 wxMenu
*file_menu
= new wxMenu
;
51 file_menu
->Append(TEST_LEFT_RIGHT
, _T("&Left to right"), _T("Redraw left to right"));
52 file_menu
->Append(TEST_TOP_BOTTOM
, _T("&Top to bottom"), _T("Redraw top to bottom"));
53 file_menu
->AppendSeparator();
54 file_menu
->Append(TEST_QUIT
, _T("E&xit"), _T("Quit program"));
56 wxMenu
*help_menu
= new wxMenu
;
57 help_menu
->Append(TEST_ABOUT
, _T("&About"), _T("About Tree Test"));
59 wxMenuBar
* menu_bar
= new wxMenuBar
;
61 menu_bar
->Append(file_menu
, _T("&File"));
62 menu_bar
->Append(help_menu
, _T("&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(_T("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(_T("animal"));
104 tree
.AddChild(_T("mammal"), _T("animal"));
105 tree
.AddChild(_T("insect"), _T("animal"));
106 tree
.AddChild(_T("bird"), _T("animal"));
108 tree
.AddChild(_T("man"), _T("mammal"));
109 tree
.AddChild(_T("cat"), _T("mammal"));
110 tree
.AddChild(_T("dog"), _T("mammal"));
111 tree
.AddChild(_T("giraffe"), _T("mammal"));
112 tree
.AddChild(_T("elephant"), _T("mammal"));
113 tree
.AddChild(_T("donkey"), _T("mammal"));
114 tree
.AddChild(_T("horse"), _T("mammal"));
116 tree
.AddChild(_T("fido"), _T("dog"));
117 tree
.AddChild(_T("domestic cat"), _T("cat"));
118 tree
.AddChild(_T("lion"), _T("cat"));
119 tree
.AddChild(_T("tiger"), _T("cat"));
120 tree
.AddChild(_T("felix"), _T("domestic cat"));
121 tree
.AddChild(_T("socks"), _T("domestic cat"));
123 tree
.AddChild(_T("beetle"), _T("insect"));
124 tree
.AddChild(_T("earwig"), _T("insect"));
125 tree
.AddChild(_T("eagle"), _T("bird"));
126 tree
.AddChild(_T("bluetit"), _T("bird"));
127 tree
.AddChild(_T("sparrow"), _T("bird"));
128 tree
.AddChild(_T("blackbird"), _T("bird"));
129 tree
.AddChild(_T("emu"), _T("bird"));
130 tree
.AddChild(_T("crow"), _T("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(_T("wxWindows tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998"), _T("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
);