]> git.saurik.com Git - wxWidgets.git/blame - samples/notebook/test.cpp
Fixed a layout bug in MyFixed
[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 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
58void 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));
62 m_helpButton = new wxButton(window, wxID_HELP, "Help", wxPoint(-1, -1), wxSize(80, 25));
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();
70 m_helpButton->SetConstraints(c);
71
72 c = new wxLayoutConstraints;
73 c->right.SameAs(m_helpButton, wxLeft, 4);
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
105 wxPanel *panel3 = new wxPanel(notebook, -1);
106 panel3->SetBackgroundColour(wxColour("WHITE"));
107 notebook->AddPage(panel3, "Goat");
108
109 wxPanel *panel4 = new wxPanel(notebook, -1);
110 panel4->SetBackgroundColour(wxColour("YELLOW"));
111 notebook->AddPage(panel4, "Sheep");
0b4d4194
JS
112}
113
114BEGIN_EVENT_TABLE(MyDialog, wxDialog)
115 EVT_BUTTON(wxID_OK, MyDialog::OnOK)
116 EVT_BUTTON(wxID_CANCEL, MyDialog::OnOK)
117END_EVENT_TABLE()
118
119MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
120 const wxPoint& pos, const wxSize& size, const long windowStyle):
121 wxDialog(parent, id, title, pos, size, windowStyle)
122{
123 Init();
124}
125
126void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
127{
128 EndModal(wxID_OK);
129}
130
131void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
132{
133 EndModal(wxID_CANCEL);
134}
135
136void MyDialog::Init(void)
137{
0b4d4194
JS
138 m_notebook = new wxNotebook(this, ID_NOTEBOOK);
139
140 wxLayoutConstraints* c = new wxLayoutConstraints;
141 c->left.SameAs(this, wxLeft, 4);
142 c->right.SameAs(this, wxRight, 4);
143 c->top.SameAs(this, wxTop, 4);
144 c->bottom.SameAs(this, wxBottom, 40);
145
146 m_notebook->SetConstraints(c);
147
148 wxGetApp().InitTabView(m_notebook, this);
149
150 SetAutoLayout(TRUE);
151 Layout();
152
153 this->Centre(wxBOTH);
154}
155
156BEGIN_EVENT_TABLE(MyFrame, wxFrame)
157 EVT_BUTTON(wxID_OK, MyFrame::OnOK)
158 EVT_BUTTON(wxID_CANCEL, MyFrame::OnOK)
159 EVT_SIZE(MyFrame::OnSize)
160END_EVENT_TABLE()
161
162MyFrame::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
171void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) )
172{
173 this->Destroy();
174}
175
176void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
177{
178 this->Destroy();
179}
180
181void MyFrame::Init(void)
182{
0b4d4194
JS
183 m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxCLIP_CHILDREN);
184
185 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
186 // with the panel background, and save a bit of time.
187 m_notebook = new wxNotebook(m_panel, ID_NOTEBOOK);
188
189 wxLayoutConstraints* c = new wxLayoutConstraints;
190 c->left.SameAs(m_panel, wxLeft, 4);
191 c->right.SameAs(m_panel, wxRight, 4);
192 c->top.SameAs(m_panel, wxTop, 4);
193 c->bottom.SameAs(m_panel, wxBottom, 40);
194
195 m_notebook->SetConstraints(c);
196
197 wxGetApp().InitTabView(m_notebook, m_panel);
198
199 m_panel->SetAutoLayout(TRUE);
200
201 m_panel->Layout();
202
203 this->Centre(wxBOTH);
204
205 Show(TRUE);
206}
207
208void MyFrame::OnSize(wxSizeEvent& event)
209{
210 wxFrame::OnSize(event);
211 m_panel->Layout();
212}
213