]>
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"), wxPoint(-1, -1), wxSize(400, 550));
46 // Give it a status line
47 frame
->CreateStatusBar(2);
51 wxIcon
icon(_T("tree_icn"));
56 wxMenu
*file_menu
= new wxMenu
;
57 file_menu
->Append(TEST_LEFT_RIGHT
, _T("&Left to right"), _T("Redraw left to right"));
58 file_menu
->Append(TEST_TOP_BOTTOM
, _T("&Top to bottom"), _T("Redraw top to bottom"));
59 file_menu
->AppendSeparator();
60 file_menu
->Append(TEST_QUIT
, _T("E&xit"), _T("Quit program"));
62 wxMenu
*help_menu
= new wxMenu
;
63 help_menu
->Append(TEST_ABOUT
, _T("&About"), _T("About Tree Test"));
65 wxMenuBar
* menu_bar
= new wxMenuBar
;
67 menu_bar
->Append(file_menu
, _T("&File"));
68 menu_bar
->Append(help_menu
, _T("&Help"));
70 // Associate the menu bar with the frame
71 frame
->SetMenuBar(menu_bar
);
73 MyCanvas
*canvas
= new MyCanvas(frame
);
75 // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
76 canvas
->SetScrollbars(20, 20, 50, 50);
77 frame
->canvas
= canvas
;
79 myTree
= new wxTreeLayoutStored();
81 wxClientDC
dc(canvas
);
82 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
84 TreeTest(*myTree
, dc
);
88 frame
->SetStatusText(_T("Hello, tree!"));
90 // Return the main frame window
99 myTree
= (wxTreeLayoutStored
*) NULL
;
105 void MyApp::TreeTest(wxTreeLayoutStored
& tree
, wxDC
& dc
)
107 tree
.Initialize(200);
109 tree
.AddChild(_T("animal"));
110 tree
.AddChild(_T("mammal"), _T("animal"));
111 tree
.AddChild(_T("insect"), _T("animal"));
112 tree
.AddChild(_T("bird"), _T("animal"));
114 tree
.AddChild(_T("man"), _T("mammal"));
115 tree
.AddChild(_T("cat"), _T("mammal"));
116 tree
.AddChild(_T("dog"), _T("mammal"));
117 tree
.AddChild(_T("giraffe"), _T("mammal"));
118 tree
.AddChild(_T("elephant"), _T("mammal"));
119 tree
.AddChild(_T("donkey"), _T("mammal"));
120 tree
.AddChild(_T("horse"), _T("mammal"));
122 tree
.AddChild(_T("fido"), _T("dog"));
123 tree
.AddChild(_T("domestic cat"), _T("cat"));
124 tree
.AddChild(_T("lion"), _T("cat"));
125 tree
.AddChild(_T("tiger"), _T("cat"));
126 tree
.AddChild(_T("felix"), _T("domestic cat"));
127 tree
.AddChild(_T("socks"), _T("domestic cat"));
129 tree
.AddChild(_T("beetle"), _T("insect"));
130 tree
.AddChild(_T("earwig"), _T("insect"));
131 tree
.AddChild(_T("eagle"), _T("bird"));
132 tree
.AddChild(_T("bluetit"), _T("bird"));
133 tree
.AddChild(_T("sparrow"), _T("bird"));
134 tree
.AddChild(_T("blackbird"), _T("bird"));
135 tree
.AddChild(_T("emu"), _T("bird"));
136 tree
.AddChild(_T("crow"), _T("bird"));
141 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
142 EVT_MENU(TEST_QUIT
, MyFrame::OnQuit
)
143 EVT_MENU(TEST_ABOUT
, MyFrame::OnAbout
)
144 EVT_MENU(TEST_LEFT_RIGHT
, MyFrame::OnLeftRight
)
145 EVT_MENU(TEST_TOP_BOTTOM
, MyFrame::OnTopBottom
)
146 EVT_CLOSE(MyFrame::OnCloseWindow
)
149 // Define my frame constructor
150 MyFrame::MyFrame(wxWindow
*parent
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
151 wxFrame(parent
, -1, title
, pos
, size
)
155 void MyFrame::OnQuit(wxCommandEvent
& event
)
160 void MyFrame::OnLeftRight(wxCommandEvent
& event
)
164 myTree
->SetOrientation(FALSE
);
165 wxClientDC
dc(canvas
);
166 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
168 wxGetApp().TreeTest(*myTree
, dc
);
173 void MyFrame::OnTopBottom(wxCommandEvent
& event
)
177 myTree
->SetOrientation(TRUE
);
178 wxClientDC
dc(canvas
);
179 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);
181 wxGetApp().TreeTest(*myTree
, dc
);
186 void MyFrame::OnAbout(wxCommandEvent
& event
)
188 (void)wxMessageBox(_T("wxWindows tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998"), _T("About tree test"));
191 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
196 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
197 EVT_PAINT(MyCanvas::OnPaint
)
200 // Define a constructor for my canvas
201 MyCanvas::MyCanvas(wxWindow
*parent
):
202 wxScrolledWindow(parent
, -1)
204 SetBackgroundColour(*wxWHITE
);
207 // Define the repainting behaviour
208 void MyCanvas::OnPaint(wxPaintEvent
& event
)
214 wxFont
font(10, wxROMAN
, wxNORMAL
, wxBOLD
);