]> git.saurik.com Git - wxWidgets.git/blob - samples/notebook/test.cpp
3358e3655211e7759359f8c3abd653086e22fcc8
[wxWidgets.git] / samples / notebook / test.cpp
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
29 MyDialog* dialog = (MyDialog *) NULL;
30 MyFrame* frame = (MyFrame *) NULL;
31
32 IMPLEMENT_APP(MyApp)
33
34 bool 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
51 void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window)
52 {
53 int dialogWidth = 365;
54 int dialogHeight = 390;
55
56 m_okButton = new wxButton(window, wxID_OK, "Close", wxPoint(-1, -1), wxSize(80, 25));
57 m_cancelButton = new wxButton(window, wxID_CANCEL, "Cancel", wxPoint(-1, -1), wxSize(80, 25));
58 m_helpButton = new wxButton(window, wxID_HELP, "Help", wxPoint(-1, -1), wxSize(80, 25));
59 m_okButton->SetDefault();
60
61 wxLayoutConstraints* c = new wxLayoutConstraints;
62 c->right.SameAs(window, wxRight, 4);
63 c->bottom.SameAs(window, wxBottom, 4);
64 c->height.AsIs();
65 c->width.AsIs();
66 m_helpButton->SetConstraints(c);
67
68 c = new wxLayoutConstraints;
69 c->right.SameAs(m_helpButton, wxLeft, 4);
70 c->bottom.SameAs(window, wxBottom, 4);
71 c->height.AsIs();
72 c->width.AsIs();
73 m_cancelButton->SetConstraints(c);
74
75 c = new wxLayoutConstraints;
76 c->right.SameAs(m_cancelButton, wxLeft, 4);
77 c->bottom.SameAs(window, wxBottom, 4);
78 c->height.AsIs();
79 c->width.AsIs();
80 m_okButton->SetConstraints(c);
81
82 // Add some panels
83 wxPanel *panel1 = new wxPanel(notebook, -1);
84 (void)new wxButton(panel1, -1, "Press me", wxPoint(10, 10));
85 (void)new wxTextCtrl(panel1, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
86
87 notebook->AddPage(panel1, "Cat");
88
89 wxPanel *panel2 = new wxPanel(notebook, -1);
90
91 wxString animals[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
92 (void)new wxListBox(panel2, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals);
93
94 (void)new wxTextCtrl(panel2, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100),
95 wxTE_MULTILINE);
96
97 notebook->AddPage(panel2, "Dog");
98 }
99
100 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
101 EVT_BUTTON(wxID_OK, MyDialog::OnOK)
102 EVT_BUTTON(wxID_CANCEL, MyDialog::OnOK)
103 END_EVENT_TABLE()
104
105 MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
106 const wxPoint& pos, const wxSize& size, const long windowStyle):
107 wxDialog(parent, id, title, pos, size, windowStyle)
108 {
109 Init();
110 }
111
112 void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
113 {
114 EndModal(wxID_OK);
115 }
116
117 void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
118 {
119 EndModal(wxID_CANCEL);
120 }
121
122 void MyDialog::Init(void)
123 {
124 int dialogWidth = 365;
125 int dialogHeight = 390;
126
127 m_notebook = new wxNotebook(this, ID_NOTEBOOK);
128
129 wxLayoutConstraints* c = new wxLayoutConstraints;
130 c->left.SameAs(this, wxLeft, 4);
131 c->right.SameAs(this, wxRight, 4);
132 c->top.SameAs(this, wxTop, 4);
133 c->bottom.SameAs(this, wxBottom, 40);
134
135 m_notebook->SetConstraints(c);
136
137 wxGetApp().InitTabView(m_notebook, this);
138
139 SetAutoLayout(TRUE);
140 Layout();
141
142 this->Centre(wxBOTH);
143 }
144
145 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
146 EVT_BUTTON(wxID_OK, MyFrame::OnOK)
147 EVT_BUTTON(wxID_CANCEL, MyFrame::OnOK)
148 EVT_SIZE(MyFrame::OnSize)
149 END_EVENT_TABLE()
150
151 MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title,
152 const wxPoint& pos, const wxSize& size, const long windowStyle):
153 wxFrame(parent, id, title, pos, size, windowStyle)
154 {
155 m_panel = (wxPanel*) NULL;
156 m_notebook = (wxNotebook*) NULL;
157 Init();
158 }
159
160 void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) )
161 {
162 this->Destroy();
163 }
164
165 void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
166 {
167 this->Destroy();
168 }
169
170 void MyFrame::Init(void)
171 {
172 int dialogWidth = 365;
173 int dialogHeight = 390;
174
175 m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxCLIP_CHILDREN);
176
177 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
178 // with the panel background, and save a bit of time.
179 m_notebook = new wxNotebook(m_panel, ID_NOTEBOOK);
180
181 wxLayoutConstraints* c = new wxLayoutConstraints;
182 c->left.SameAs(m_panel, wxLeft, 4);
183 c->right.SameAs(m_panel, wxRight, 4);
184 c->top.SameAs(m_panel, wxTop, 4);
185 c->bottom.SameAs(m_panel, wxBottom, 40);
186
187 m_notebook->SetConstraints(c);
188
189 wxGetApp().InitTabView(m_notebook, m_panel);
190
191 m_panel->SetAutoLayout(TRUE);
192
193 m_panel->Layout();
194
195 this->Centre(wxBOTH);
196
197 Show(TRUE);
198 }
199
200 void MyFrame::OnSize(wxSizeEvent& event)
201 {
202 wxFrame::OnSize(event);
203 m_panel->Layout();
204 }
205