]> git.saurik.com Git - wxWidgets.git/blame - samples/notebook/test.cpp
1. Empty() now doesn't free memory - Clear() does
[wxWidgets.git] / samples / notebook / test.cpp
CommitLineData
0b4d4194
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: test.cpp
3// Purpose: wxNotebook demo
4// Author: Julian Smart
5// Modified by:
6// Created: 26/10/98
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
23#include "wx/tab.h"
24#include "test.h"
25
26// If 1, use a dialog. Otherwise use a frame.
27#define USE_TABBED_DIALOG 0
28
29MyDialog* dialog = (MyDialog *) NULL;
30MyFrame* frame = (MyFrame *) NULL;
31
32IMPLEMENT_APP(MyApp)
33
34bool MyApp::OnInit(void)
35{
36 // Create the main window
37#if USE_TABBED_DIALOG
38 dialog = new MyDialog((wxFrame *) NULL, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE);
39
40 dialog->ShowModal();
41
42 // Quit immediately the dialog has been dismissed
43 return FALSE;
44#else
45 frame = new MyFrame((wxFrame*) NULL, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDEFAULT_FRAME_STYLE);
46
47 return TRUE;
48#endif
49}
50
51void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window)
52{
0b4d4194
JS
53 m_okButton = new wxButton(window, wxID_OK, "Close", wxPoint(-1, -1), wxSize(80, 25));
54 m_cancelButton = new wxButton(window, wxID_CANCEL, "Cancel", wxPoint(-1, -1), wxSize(80, 25));
55 m_helpButton = new wxButton(window, wxID_HELP, "Help", wxPoint(-1, -1), wxSize(80, 25));
56 m_okButton->SetDefault();
57
58 wxLayoutConstraints* c = new wxLayoutConstraints;
59 c->right.SameAs(window, wxRight, 4);
60 c->bottom.SameAs(window, wxBottom, 4);
61 c->height.AsIs();
62 c->width.AsIs();
63 m_helpButton->SetConstraints(c);
64
65 c = new wxLayoutConstraints;
66 c->right.SameAs(m_helpButton, wxLeft, 4);
67 c->bottom.SameAs(window, wxBottom, 4);
68 c->height.AsIs();
69 c->width.AsIs();
70 m_cancelButton->SetConstraints(c);
71
72 c = new wxLayoutConstraints;
73 c->right.SameAs(m_cancelButton, wxLeft, 4);
74 c->bottom.SameAs(window, wxBottom, 4);
75 c->height.AsIs();
76 c->width.AsIs();
77 m_okButton->SetConstraints(c);
78
79 // Add some panels
80 wxPanel *panel1 = new wxPanel(notebook, -1);
02800301 81 // panel1->SetBackgroundColour(wxColour("RED"));
0b4d4194
JS
82 (void)new wxButton(panel1, -1, "Press me", wxPoint(10, 10));
83 (void)new wxTextCtrl(panel1, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
84
85 notebook->AddPage(panel1, "Cat");
86
87 wxPanel *panel2 = new wxPanel(notebook, -1);
02800301 88 panel2->SetBackgroundColour(wxColour("BLUE"));
0b4d4194
JS
89
90 wxString animals[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
91 (void)new wxListBox(panel2, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals);
92
93 (void)new wxTextCtrl(panel2, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100),
94 wxTE_MULTILINE);
95
96 notebook->AddPage(panel2, "Dog");
02800301
JS
97
98 wxPanel *panel3 = new wxPanel(notebook, -1);
99 panel3->SetBackgroundColour(wxColour("WHITE"));
100 notebook->AddPage(panel3, "Goat");
101
102 wxPanel *panel4 = new wxPanel(notebook, -1);
103 panel4->SetBackgroundColour(wxColour("YELLOW"));
104 notebook->AddPage(panel4, "Sheep");
0b4d4194
JS
105}
106
107BEGIN_EVENT_TABLE(MyDialog, wxDialog)
108 EVT_BUTTON(wxID_OK, MyDialog::OnOK)
109 EVT_BUTTON(wxID_CANCEL, MyDialog::OnOK)
110END_EVENT_TABLE()
111
112MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
113 const wxPoint& pos, const wxSize& size, const long windowStyle):
114 wxDialog(parent, id, title, pos, size, windowStyle)
115{
116 Init();
117}
118
119void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
120{
121 EndModal(wxID_OK);
122}
123
124void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
125{
126 EndModal(wxID_CANCEL);
127}
128
129void MyDialog::Init(void)
130{
0b4d4194
JS
131 m_notebook = new wxNotebook(this, ID_NOTEBOOK);
132
133 wxLayoutConstraints* c = new wxLayoutConstraints;
134 c->left.SameAs(this, wxLeft, 4);
135 c->right.SameAs(this, wxRight, 4);
136 c->top.SameAs(this, wxTop, 4);
137 c->bottom.SameAs(this, wxBottom, 40);
138
139 m_notebook->SetConstraints(c);
140
141 wxGetApp().InitTabView(m_notebook, this);
142
143 SetAutoLayout(TRUE);
144 Layout();
145
146 this->Centre(wxBOTH);
147}
148
149BEGIN_EVENT_TABLE(MyFrame, wxFrame)
150 EVT_BUTTON(wxID_OK, MyFrame::OnOK)
151 EVT_BUTTON(wxID_CANCEL, MyFrame::OnOK)
152 EVT_SIZE(MyFrame::OnSize)
153END_EVENT_TABLE()
154
155MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title,
156 const wxPoint& pos, const wxSize& size, const long windowStyle):
157 wxFrame(parent, id, title, pos, size, windowStyle)
158{
159 m_panel = (wxPanel*) NULL;
160 m_notebook = (wxNotebook*) NULL;
161 Init();
162}
163
164void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) )
165{
166 this->Destroy();
167}
168
169void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
170{
171 this->Destroy();
172}
173
174void MyFrame::Init(void)
175{
0b4d4194
JS
176 m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxCLIP_CHILDREN);
177
178 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
179 // with the panel background, and save a bit of time.
180 m_notebook = new wxNotebook(m_panel, ID_NOTEBOOK);
181
182 wxLayoutConstraints* c = new wxLayoutConstraints;
183 c->left.SameAs(m_panel, wxLeft, 4);
184 c->right.SameAs(m_panel, wxRight, 4);
185 c->top.SameAs(m_panel, wxTop, 4);
186 c->bottom.SameAs(m_panel, wxBottom, 40);
187
188 m_notebook->SetConstraints(c);
189
190 wxGetApp().InitTabView(m_notebook, m_panel);
191
192 m_panel->SetAutoLayout(TRUE);
193
194 m_panel->Layout();
195
196 this->Centre(wxBOTH);
197
198 Show(TRUE);
199}
200
201void MyFrame::OnSize(wxSizeEvent& event)
202{
203 wxFrame::OnSize(event);
204 m_panel->Layout();
205}
206