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