]>
Commit | Line | Data |
---|---|---|
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 | ||
28 | MyDialog* dialog = (MyDialog *) NULL; | |
29 | MyFrame* frame = (MyFrame *) NULL; | |
30 | ||
31 | IMPLEMENT_APP(MyApp) | |
32 | ||
33 | bool 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 | 46 | // Problem with generic wxNotebook implementation whereby it doesn't size properly unless |
ee4c6942 JS |
47 | // you set the size again |
48 | #if defined(__WIN16__) | |
49 | int width, height; | |
50 | frame->GetSize(& width, & height); | |
51 | frame->SetSize(-1, -1, width, height); | |
5dcf05ae JS |
52 | #endif |
53 | ||
0b4d4194 JS |
54 | return TRUE; |
55 | #endif | |
56 | } | |
57 | ||
58 | void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window) | |
59 | { | |
0b4d4194 JS |
60 | m_okButton = new wxButton(window, wxID_OK, "Close", wxPoint(-1, -1), wxSize(80, 25)); |
61 | m_cancelButton = new wxButton(window, wxID_CANCEL, "Cancel", wxPoint(-1, -1), wxSize(80, 25)); | |
326f9654 | 62 | m_addPageButton = new wxButton(window, ID_ADD_PAGE, "Add page", wxPoint(-1, -1), wxSize(80, 25)); |
0b4d4194 JS |
63 | m_okButton->SetDefault(); |
64 | ||
65 | wxLayoutConstraints* c = new wxLayoutConstraints; | |
66 | c->right.SameAs(window, wxRight, 4); | |
67 | c->bottom.SameAs(window, wxBottom, 4); | |
68 | c->height.AsIs(); | |
69 | c->width.AsIs(); | |
326f9654 | 70 | m_addPageButton->SetConstraints(c); |
0b4d4194 JS |
71 | |
72 | c = new wxLayoutConstraints; | |
326f9654 | 73 | c->right.SameAs(m_addPageButton, wxLeft, 4); |
0b4d4194 JS |
74 | c->bottom.SameAs(window, wxBottom, 4); |
75 | c->height.AsIs(); | |
76 | c->width.AsIs(); | |
77 | m_cancelButton->SetConstraints(c); | |
78 | ||
79 | c = new wxLayoutConstraints; | |
80 | c->right.SameAs(m_cancelButton, wxLeft, 4); | |
81 | c->bottom.SameAs(window, wxBottom, 4); | |
82 | c->height.AsIs(); | |
83 | c->width.AsIs(); | |
84 | m_okButton->SetConstraints(c); | |
85 | ||
86 | // Add some panels | |
87 | wxPanel *panel1 = new wxPanel(notebook, -1); | |
02800301 | 88 | // panel1->SetBackgroundColour(wxColour("RED")); |
0b4d4194 JS |
89 | (void)new wxButton(panel1, -1, "Press me", wxPoint(10, 10)); |
90 | (void)new wxTextCtrl(panel1, -1, "1234", wxPoint(10, 40), wxSize(120, 150)); | |
91 | ||
5dcf05ae | 92 | notebook->AddPage(panel1, "Cat", TRUE); |
0b4d4194 JS |
93 | |
94 | wxPanel *panel2 = new wxPanel(notebook, -1); | |
02800301 | 95 | panel2->SetBackgroundColour(wxColour("BLUE")); |
0b4d4194 JS |
96 | |
97 | wxString animals[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" }; | |
98 | (void)new wxListBox(panel2, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals); | |
99 | ||
100 | (void)new wxTextCtrl(panel2, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100), | |
101 | wxTE_MULTILINE); | |
102 | ||
103 | notebook->AddPage(panel2, "Dog"); | |
02800301 JS |
104 | wxPanel *panel3 = new wxPanel(notebook, -1); |
105 | panel3->SetBackgroundColour(wxColour("WHITE")); | |
106 | notebook->AddPage(panel3, "Goat"); | |
107 | ||
108 | wxPanel *panel4 = new wxPanel(notebook, -1); | |
109 | panel4->SetBackgroundColour(wxColour("YELLOW")); | |
110 | notebook->AddPage(panel4, "Sheep"); | |
0b4d4194 JS |
111 | } |
112 | ||
113 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) | |
114 | EVT_BUTTON(wxID_OK, MyDialog::OnOK) | |
115 | EVT_BUTTON(wxID_CANCEL, MyDialog::OnOK) | |
116 | END_EVENT_TABLE() | |
117 | ||
118 | MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title, | |
119 | const wxPoint& pos, const wxSize& size, const long windowStyle): | |
120 | wxDialog(parent, id, title, pos, size, windowStyle) | |
121 | { | |
122 | Init(); | |
123 | } | |
124 | ||
125 | void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) | |
126 | { | |
127 | EndModal(wxID_OK); | |
128 | } | |
129 | ||
130 | void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) ) | |
131 | { | |
132 | EndModal(wxID_CANCEL); | |
133 | } | |
134 | ||
135 | void MyDialog::Init(void) | |
136 | { | |
0b4d4194 JS |
137 | m_notebook = new wxNotebook(this, ID_NOTEBOOK); |
138 | ||
139 | wxLayoutConstraints* c = new wxLayoutConstraints; | |
140 | c->left.SameAs(this, wxLeft, 4); | |
141 | c->right.SameAs(this, wxRight, 4); | |
142 | c->top.SameAs(this, wxTop, 4); | |
143 | c->bottom.SameAs(this, wxBottom, 40); | |
144 | ||
145 | m_notebook->SetConstraints(c); | |
146 | ||
147 | wxGetApp().InitTabView(m_notebook, this); | |
148 | ||
149 | SetAutoLayout(TRUE); | |
150 | Layout(); | |
151 | ||
152 | this->Centre(wxBOTH); | |
153 | } | |
154 | ||
155 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
156 | EVT_BUTTON(wxID_OK, MyFrame::OnOK) | |
157 | EVT_BUTTON(wxID_CANCEL, MyFrame::OnOK) | |
326f9654 | 158 | EVT_BUTTON(ID_ADD_PAGE, MyFrame::OnAddPage) |
0b4d4194 JS |
159 | EVT_SIZE(MyFrame::OnSize) |
160 | END_EVENT_TABLE() | |
161 | ||
162 | MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title, | |
163 | const wxPoint& pos, const wxSize& size, const long windowStyle): | |
164 | wxFrame(parent, id, title, pos, size, windowStyle) | |
165 | { | |
166 | m_panel = (wxPanel*) NULL; | |
167 | m_notebook = (wxNotebook*) NULL; | |
168 | Init(); | |
169 | } | |
170 | ||
326f9654 RR |
171 | void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event)) |
172 | { | |
173 | wxPanel *panel = new wxPanel( m_notebook, -1 ); | |
174 | (void)new wxButton( panel, -1, "Button", wxPoint( 10,10 ), wxSize(-1,-1) ); | |
175 | m_notebook->AddPage( panel, "Added" ); | |
176 | m_notebook->SetSelection( m_notebook->GetPageCount()-1 ); | |
177 | } | |
178 | ||
0b4d4194 JS |
179 | void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) ) |
180 | { | |
181 | this->Destroy(); | |
182 | } | |
183 | ||
184 | void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) ) | |
185 | { | |
186 | this->Destroy(); | |
187 | } | |
188 | ||
189 | void MyFrame::Init(void) | |
190 | { | |
0b4d4194 JS |
191 | m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxCLIP_CHILDREN); |
192 | ||
193 | // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match | |
194 | // with the panel background, and save a bit of time. | |
195 | m_notebook = new wxNotebook(m_panel, ID_NOTEBOOK); | |
196 | ||
197 | wxLayoutConstraints* c = new wxLayoutConstraints; | |
198 | c->left.SameAs(m_panel, wxLeft, 4); | |
199 | c->right.SameAs(m_panel, wxRight, 4); | |
200 | c->top.SameAs(m_panel, wxTop, 4); | |
201 | c->bottom.SameAs(m_panel, wxBottom, 40); | |
202 | ||
203 | m_notebook->SetConstraints(c); | |
204 | ||
205 | wxGetApp().InitTabView(m_notebook, m_panel); | |
206 | ||
207 | m_panel->SetAutoLayout(TRUE); | |
208 | ||
209 | m_panel->Layout(); | |
210 | ||
211 | this->Centre(wxBOTH); | |
212 | ||
213 | Show(TRUE); | |
214 | } | |
215 | ||
216 | void MyFrame::OnSize(wxSizeEvent& event) | |
217 | { | |
218 | wxFrame::OnSize(event); | |
219 | m_panel->Layout(); | |
220 | } | |
221 |