2003-03-30 14:36:46 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: treelay.cpp
|
|
|
|
// Purpose: wxTreeLayout sample
|
|
|
|
// Author: Julian Smart
|
2004-09-27 15:24:45 -04:00
|
|
|
// Modified by:
|
2003-03-30 14:36:46 -05:00
|
|
|
// Created: 7/4/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2003-03-31 05:24:36 -05:00
|
|
|
#include "wx/deprecated/setup.h"
|
|
|
|
|
|
|
|
#if !wxUSE_TREELAYOUT
|
|
|
|
#error Please set wxUSE_TREELAYOUT to 1 in contrib/include/wx/deprecated/setup.h and recompile.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/deprecated/treelay.h"
|
2003-03-30 14:36:46 -05:00
|
|
|
|
|
|
|
#include "treelay.h"
|
|
|
|
|
|
|
|
wxTreeLayoutStored *myTree = (wxTreeLayoutStored *) NULL;
|
|
|
|
|
|
|
|
// A macro needed for some compilers (AIX) that need 'main' to be defined
|
|
|
|
// in the application itself.
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// The `main program' equivalent, creating the windows and returning the
|
|
|
|
// main frame
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
// Create the main frame window
|
2004-07-30 11:28:32 -04:00
|
|
|
MyFrame* frame = new MyFrame(NULL, _T("Tree Test"), wxDefaultPosition, wxSize(400, 550));
|
2003-03-30 14:36:46 -05:00
|
|
|
|
2004-07-19 11:14:07 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2003-03-30 14:36:46 -05:00
|
|
|
// Give it a status line
|
|
|
|
frame->CreateStatusBar(2);
|
2004-07-19 11:14:07 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2003-03-30 14:36:46 -05:00
|
|
|
|
|
|
|
// Give it an icon
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
wxIcon icon(_T("tree_icn"));
|
|
|
|
frame->SetIcon(icon);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
file_menu->Append(TEST_LEFT_RIGHT, _T("&Left to right"), _T("Redraw left to right"));
|
|
|
|
file_menu->Append(TEST_TOP_BOTTOM, _T("&Top to bottom"), _T("Redraw top to bottom"));
|
|
|
|
file_menu->AppendSeparator();
|
|
|
|
file_menu->Append(TEST_QUIT, _T("E&xit"), _T("Quit program"));
|
|
|
|
|
|
|
|
wxMenu *help_menu = new wxMenu;
|
|
|
|
help_menu->Append(TEST_ABOUT, _T("&About"), _T("About Tree Test"));
|
|
|
|
|
|
|
|
wxMenuBar* menu_bar = new wxMenuBar;
|
|
|
|
|
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
|
|
|
menu_bar->Append(help_menu, _T("&Help"));
|
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
frame->SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
MyCanvas *canvas = new MyCanvas(frame);
|
|
|
|
|
|
|
|
// Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
|
|
|
|
canvas->SetScrollbars(20, 20, 50, 50);
|
|
|
|
frame->canvas = canvas;
|
|
|
|
|
|
|
|
myTree = new wxTreeLayoutStored();
|
|
|
|
|
|
|
|
wxClientDC dc(canvas);
|
|
|
|
wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
|
|
|
|
dc.SetFont(font);
|
|
|
|
TreeTest(*myTree, dc);
|
|
|
|
|
2004-07-30 11:28:32 -04:00
|
|
|
frame->Show(true);
|
2003-03-30 14:36:46 -05:00
|
|
|
|
2004-07-19 11:14:07 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2003-03-30 14:36:46 -05:00
|
|
|
frame->SetStatusText(_T("Hello, tree!"));
|
2004-07-19 11:14:07 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2003-03-30 14:36:46 -05:00
|
|
|
|
|
|
|
// Return the main frame window
|
2004-07-30 11:28:32 -04:00
|
|
|
return true;
|
2003-03-30 14:36:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int MyApp::OnExit()
|
|
|
|
{
|
|
|
|
if (myTree)
|
|
|
|
{
|
|
|
|
delete myTree;
|
|
|
|
myTree = (wxTreeLayoutStored *) NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyApp::TreeTest(wxTreeLayoutStored& tree, wxDC& dc)
|
|
|
|
{
|
|
|
|
tree.Initialize(200);
|
2004-09-27 15:24:45 -04:00
|
|
|
|
2003-03-30 14:36:46 -05:00
|
|
|
tree.AddChild(_T("animal"));
|
|
|
|
tree.AddChild(_T("mammal"), _T("animal"));
|
|
|
|
tree.AddChild(_T("insect"), _T("animal"));
|
|
|
|
tree.AddChild(_T("bird"), _T("animal"));
|
|
|
|
|
|
|
|
tree.AddChild(_T("man"), _T("mammal"));
|
|
|
|
tree.AddChild(_T("cat"), _T("mammal"));
|
|
|
|
tree.AddChild(_T("dog"), _T("mammal"));
|
|
|
|
tree.AddChild(_T("giraffe"), _T("mammal"));
|
|
|
|
tree.AddChild(_T("elephant"), _T("mammal"));
|
|
|
|
tree.AddChild(_T("donkey"), _T("mammal"));
|
|
|
|
tree.AddChild(_T("horse"), _T("mammal"));
|
|
|
|
|
|
|
|
tree.AddChild(_T("fido"), _T("dog"));
|
|
|
|
tree.AddChild(_T("domestic cat"), _T("cat"));
|
|
|
|
tree.AddChild(_T("lion"), _T("cat"));
|
|
|
|
tree.AddChild(_T("tiger"), _T("cat"));
|
|
|
|
tree.AddChild(_T("felix"), _T("domestic cat"));
|
|
|
|
tree.AddChild(_T("socks"), _T("domestic cat"));
|
|
|
|
|
|
|
|
tree.AddChild(_T("beetle"), _T("insect"));
|
|
|
|
tree.AddChild(_T("earwig"), _T("insect"));
|
|
|
|
tree.AddChild(_T("eagle"), _T("bird"));
|
|
|
|
tree.AddChild(_T("bluetit"), _T("bird"));
|
|
|
|
tree.AddChild(_T("sparrow"), _T("bird"));
|
|
|
|
tree.AddChild(_T("blackbird"), _T("bird"));
|
|
|
|
tree.AddChild(_T("emu"), _T("bird"));
|
|
|
|
tree.AddChild(_T("crow"), _T("bird"));
|
|
|
|
|
|
|
|
tree.DoLayout(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(TEST_QUIT, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(TEST_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(TEST_LEFT_RIGHT, MyFrame::OnLeftRight)
|
|
|
|
EVT_MENU(TEST_TOP_BOTTOM, MyFrame::OnTopBottom)
|
|
|
|
EVT_CLOSE(MyFrame::OnCloseWindow)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size):
|
2004-07-30 11:28:32 -04:00
|
|
|
wxFrame(parent, wxID_ANY, title, pos, size)
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-11-09 16:40:34 -05:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
2004-07-30 11:28:32 -04:00
|
|
|
Close(true);
|
2003-03-30 14:36:46 -05:00
|
|
|
}
|
|
|
|
|
2003-11-09 16:40:34 -05:00
|
|
|
void MyFrame::OnLeftRight(wxCommandEvent& WXUNUSED(event))
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
|
|
|
if (myTree)
|
|
|
|
{
|
2004-07-30 11:28:32 -04:00
|
|
|
myTree->SetOrientation(false);
|
2003-03-30 14:36:46 -05:00
|
|
|
wxClientDC dc(canvas);
|
|
|
|
wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
|
|
|
|
dc.SetFont(font);
|
|
|
|
wxGetApp().TreeTest(*myTree, dc);
|
|
|
|
canvas->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-09 16:40:34 -05:00
|
|
|
void MyFrame::OnTopBottom(wxCommandEvent& WXUNUSED(event))
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
|
|
|
if (myTree)
|
|
|
|
{
|
2004-07-30 11:28:32 -04:00
|
|
|
myTree->SetOrientation(true);
|
2003-03-30 14:36:46 -05:00
|
|
|
wxClientDC dc(canvas);
|
|
|
|
wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
|
|
|
|
dc.SetFont(font);
|
|
|
|
wxGetApp().TreeTest(*myTree, dc);
|
|
|
|
canvas->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-09 16:40:34 -05:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
2004-05-25 07:20:37 -04:00
|
|
|
(void)wxMessageBox(_T("wxWidgets tree library demo Vsn 2.0\nAuthor: Julian Smart (c) 1998"), _T("About tree test"));
|
2003-03-30 14:36:46 -05:00
|
|
|
}
|
|
|
|
|
2003-11-09 16:40:34 -05:00
|
|
|
void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_PAINT(MyCanvas::OnPaint)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// Define a constructor for my canvas
|
|
|
|
MyCanvas::MyCanvas(wxWindow *parent):
|
2004-07-30 11:28:32 -04:00
|
|
|
wxScrolledWindow(parent, wxID_ANY)
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
|
|
|
SetBackgroundColour(*wxWHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define the repainting behaviour
|
2003-11-09 16:40:34 -05:00
|
|
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
2003-03-30 14:36:46 -05:00
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
PrepareDC(dc);
|
|
|
|
if (myTree)
|
|
|
|
{
|
|
|
|
wxFont font(10, wxROMAN, wxNORMAL, wxBOLD);
|
|
|
|
dc.SetFont(font);
|
|
|
|
myTree->Draw(dc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|