]>
git.saurik.com Git - wxWidgets.git/blob - samples/notebook/test.cpp
f86b14b7971669b05eaef24c513e3a917985f45c
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxNotebook demo
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
26 // If 1, use a dialog. Otherwise use a frame.
27 #define USE_TABBED_DIALOG 0
29 MyDialog
* dialog
= (MyDialog
*) NULL
;
30 MyFrame
* frame
= (MyFrame
*) NULL
;
34 bool MyApp::OnInit(void)
36 // Create the main window
38 dialog
= new MyDialog((wxFrame
*) NULL
, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDIALOG_MODAL
|wxDEFAULT_DIALOG_STYLE
);
42 // Quit immediately the dialog has been dismissed
45 frame
= new MyFrame((wxFrame
*) NULL
, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDEFAULT_FRAME_STYLE
);
51 void MyApp::InitTabView(wxNotebook
* notebook
, wxWindow
* window
)
53 int dialogWidth
= 365;
54 int dialogHeight
= 390;
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();
61 wxLayoutConstraints
* c
= new wxLayoutConstraints
;
62 c
->right
.SameAs(window
, wxRight
, 4);
63 c
->bottom
.SameAs(window
, wxBottom
, 4);
66 m_helpButton
->SetConstraints(c
);
68 c
= new wxLayoutConstraints
;
69 c
->right
.SameAs(m_helpButton
, wxLeft
, 4);
70 c
->bottom
.SameAs(window
, wxBottom
, 4);
73 m_cancelButton
->SetConstraints(c
);
75 c
= new wxLayoutConstraints
;
76 c
->right
.SameAs(m_cancelButton
, wxLeft
, 4);
77 c
->bottom
.SameAs(window
, wxBottom
, 4);
80 m_okButton
->SetConstraints(c
);
83 wxPanel
*panel1
= new wxPanel(notebook
, -1);
84 // panel1->SetBackgroundColour(wxColour("RED"));
85 (void)new wxButton(panel1
, -1, "Press me", wxPoint(10, 10));
86 (void)new wxTextCtrl(panel1
, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
88 notebook
->AddPage(panel1
, "Cat");
90 wxPanel
*panel2
= new wxPanel(notebook
, -1);
91 panel2
->SetBackgroundColour(wxColour("BLUE"));
93 wxString animals
[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
94 (void)new wxListBox(panel2
, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals
);
96 (void)new wxTextCtrl(panel2
, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100),
99 notebook
->AddPage(panel2
, "Dog");
101 wxPanel
*panel3
= new wxPanel(notebook
, -1);
102 panel3
->SetBackgroundColour(wxColour("WHITE"));
103 notebook
->AddPage(panel3
, "Goat");
105 wxPanel
*panel4
= new wxPanel(notebook
, -1);
106 panel4
->SetBackgroundColour(wxColour("YELLOW"));
107 notebook
->AddPage(panel4
, "Sheep");
110 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
111 EVT_BUTTON(wxID_OK
, MyDialog::OnOK
)
112 EVT_BUTTON(wxID_CANCEL
, MyDialog::OnOK
)
115 MyDialog::MyDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
,
116 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
117 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
)
122 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
127 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
129 EndModal(wxID_CANCEL
);
132 void MyDialog::Init(void)
134 int dialogWidth
= 365;
135 int dialogHeight
= 390;
137 m_notebook
= new wxNotebook(this, ID_NOTEBOOK
);
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);
145 m_notebook
->SetConstraints(c
);
147 wxGetApp().InitTabView(m_notebook
, this);
152 this->Centre(wxBOTH
);
155 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
156 EVT_BUTTON(wxID_OK
, MyFrame::OnOK
)
157 EVT_BUTTON(wxID_CANCEL
, MyFrame::OnOK
)
158 EVT_SIZE(MyFrame::OnSize
)
161 MyFrame::MyFrame(wxFrame
* parent
, const wxWindowID id
, const wxString
& title
,
162 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
163 wxFrame(parent
, id
, title
, pos
, size
, windowStyle
)
165 m_panel
= (wxPanel
*) NULL
;
166 m_notebook
= (wxNotebook
*) NULL
;
170 void MyFrame::OnOK(wxCommandEvent
& WXUNUSED(event
) )
175 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
180 void MyFrame::Init(void)
182 int dialogWidth
= 365;
183 int dialogHeight
= 390;
185 m_panel
= new wxPanel(this, -1, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxCLIP_CHILDREN
);
187 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
188 // with the panel background, and save a bit of time.
189 m_notebook
= new wxNotebook(m_panel
, ID_NOTEBOOK
);
191 wxLayoutConstraints
* c
= new wxLayoutConstraints
;
192 c
->left
.SameAs(m_panel
, wxLeft
, 4);
193 c
->right
.SameAs(m_panel
, wxRight
, 4);
194 c
->top
.SameAs(m_panel
, wxTop
, 4);
195 c
->bottom
.SameAs(m_panel
, wxBottom
, 40);
197 m_notebook
->SetConstraints(c
);
199 wxGetApp().InitTabView(m_notebook
, m_panel
);
201 m_panel
->SetAutoLayout(TRUE
);
205 this->Centre(wxBOTH
);
210 void MyFrame::OnSize(wxSizeEvent
& event
)
212 wxFrame::OnSize(event
);