]>
git.saurik.com Git - wxWidgets.git/blob - samples/notebook/test.cpp
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"
25 // If 1, use a dialog. Otherwise use a frame.
26 #define USE_TABBED_DIALOG 0
28 MyDialog
* dialog
= (MyDialog
*) NULL
;
29 MyFrame
* frame
= (MyFrame
*) NULL
;
33 bool MyApp::OnInit(void)
35 // Create the main window
37 dialog
= new MyDialog((wxFrame
*) NULL
, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDIALOG_MODAL
|wxDEFAULT_DIALOG_STYLE
);
41 // Quit immediately the dialog has been dismissed
44 frame
= new MyFrame((wxFrame
*) NULL
, -1, "Notebook", wxPoint(-1, -1), wxSize(365, 390) );
46 // Problem with generic wxNotebook implementation whereby it doesn't size properly unless
47 // you set the size again
48 #if defined(__WIN16__)
50 frame
->GetSize(& width
, & height
);
51 frame
->SetSize(-1, -1, width
, height
);
58 void MyApp::InitTabView(wxNotebook
* notebook
, wxWindow
* window
)
60 m_okButton
= new wxButton(window
, wxID_OK
, "Close", wxPoint(-1, -1), wxSize(80, 25));
61 m_cancelButton
= new wxButton(window
, ID_DELETE_PAGE
, "Delete page", wxPoint(-1, -1), wxSize(80, 25));
62 m_addPageButton
= new wxButton(window
, ID_ADD_PAGE
, "Add page", wxPoint(-1, -1), wxSize(80, 25));
63 m_okButton
->SetDefault();
65 wxLayoutConstraints
* c
= new wxLayoutConstraints
;
66 c
->right
.SameAs(window
, wxRight
, 4);
67 c
->bottom
.SameAs(window
, wxBottom
, 4);
70 m_addPageButton
->SetConstraints(c
);
72 c
= new wxLayoutConstraints
;
73 c
->right
.SameAs(m_addPageButton
, wxLeft
, 4);
74 c
->bottom
.SameAs(window
, wxBottom
, 4);
77 m_cancelButton
->SetConstraints(c
);
79 c
= new wxLayoutConstraints
;
80 c
->right
.SameAs(m_cancelButton
, wxLeft
, 4);
81 c
->bottom
.SameAs(window
, wxBottom
, 4);
84 m_okButton
->SetConstraints(c
);
87 wxPanel
*panel1
= new wxPanel(notebook
, -1);
88 // panel1->SetBackgroundColour(wxColour("RED"));
89 (void)new wxButton(panel1
, -1, "Press me", wxPoint(10, 10));
90 (void)new wxTextCtrl(panel1
, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
92 notebook
->AddPage(panel1
, "Cat", TRUE
);
94 wxPanel
*panel2
= new wxPanel(notebook
, -1);
95 panel2
->SetAutoLayout(TRUE
);
96 panel2
->SetBackgroundColour(wxColour("BLUE"));
98 wxString animals
[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
99 wxRadioBox
*radiobox
= new wxRadioBox(panel2
, -1, "Choose one",
100 wxDefaultPosition
, wxDefaultSize
, 5, animals
);
102 c
= new wxLayoutConstraints
;
103 c
->left
.SameAs(panel2
, wxLeft
, 4);
104 c
->top
.SameAs(panel2
, wxTop
, 4);
105 c
->height
.PercentOf(panel2
, wxHeight
, 50);
106 c
->right
.SameAs(panel2
, wxRight
, 4);
107 radiobox
->SetConstraints(c
);
109 wxRadioBox
*radiobox2
= new wxRadioBox(panel2
, -1, "Choose one",
110 wxDefaultPosition
, wxDefaultSize
,
112 2, wxRA_SPECIFY_ROWS
);
113 c
= new wxLayoutConstraints
;
114 c
->left
.SameAs(radiobox
, wxLeft
);
116 c
->top
.Below(radiobox
, 4);
117 c
->right
.SameAs(radiobox
, wxRight
);
118 radiobox2
->SetConstraints(c
);
120 notebook
->AddPage(panel2
, "Dog");
122 wxPanel
*panel3
= new wxPanel(notebook
, -1);
123 panel3
->SetBackgroundColour(wxColour("WHITE"));
124 notebook
->AddPage(panel3
, "Goat");
126 wxPanel
*panel4
= new wxPanel(notebook
, -1);
127 panel4
->SetBackgroundColour(wxColour("YELLOW"));
128 notebook
->AddPage(panel4
, "Sheep");
130 wxPanel
*panel5
= new wxPanel(notebook
, -1);
131 panel5
->SetBackgroundColour(wxColour("MAGENTA"));
132 (void)new wxStaticText(panel5
, -1, "This page has been inserted, not added", wxPoint(10, 10) );
133 notebook
->InsertPage(0, panel5
, "Sheep");
135 notebook
->SetSelection(2);
138 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
139 EVT_BUTTON(wxID_OK
, MyDialog::OnOK
)
140 EVT_BUTTON(wxID_CANCEL
, MyDialog::OnOK
)
143 MyDialog::MyDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
,
144 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
145 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
)
150 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
155 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
157 EndModal(wxID_CANCEL
);
160 void MyDialog::Init(void)
162 m_notebook
= new wxNotebook(this, ID_NOTEBOOK
);
164 wxLayoutConstraints
* c
= new wxLayoutConstraints
;
165 c
->left
.SameAs(this, wxLeft
, 4);
166 c
->right
.SameAs(this, wxRight
, 4);
167 c
->top
.SameAs(this, wxTop
, 4);
168 c
->bottom
.SameAs(this, wxBottom
, 40);
170 m_notebook
->SetConstraints(c
);
172 wxGetApp().InitTabView(m_notebook
, this);
180 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
181 EVT_BUTTON(wxID_OK
, MyFrame::OnOK
)
182 EVT_BUTTON(ID_DELETE_PAGE
, MyFrame::OnDeletePage
)
183 EVT_BUTTON(ID_ADD_PAGE
, MyFrame::OnAddPage
)
184 EVT_SIZE(MyFrame::OnSize
)
185 EVT_IDLE(MyFrame::OnIdle
)
188 MyFrame::MyFrame(wxFrame
* parent
, const wxWindowID id
, const wxString
& title
,
189 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
190 wxFrame(parent
, id
, title
, pos
, size
, windowStyle
)
192 m_panel
= (wxPanel
*) NULL
;
193 m_notebook
= (wxNotebook
*) NULL
;
197 void MyFrame::OnAddPage(wxCommandEvent
& WXUNUSED(event
))
199 wxPanel
*panel
= new wxPanel( m_notebook
, -1 );
200 (void)new wxButton( panel
, -1, "Button", wxPoint( 10,10 ), wxSize(-1,-1) );
201 m_notebook
->AddPage( panel
, "Added" );
202 // m_notebook->SetSelection( m_notebook->GetPageCount()-1 );
205 void MyFrame::OnDeletePage(wxCommandEvent
& WXUNUSED(event
))
207 m_notebook
->DeletePage( m_notebook
->GetPageCount()-1 );
210 void MyFrame::OnOK(wxCommandEvent
& WXUNUSED(event
) )
215 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
220 void MyFrame::Init(void)
222 m_panel
= new wxPanel(this, -1, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxCLIP_CHILDREN
);
224 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
225 // with the panel background, and save a bit of time.
226 m_notebook
= new wxNotebook(m_panel
, ID_NOTEBOOK
);
228 wxLayoutConstraints
* c
= new wxLayoutConstraints
;
229 c
->left
.SameAs(m_panel
, wxLeft
, 4);
230 c
->right
.SameAs(m_panel
, wxRight
, 4);
231 c
->top
.SameAs(m_panel
, wxTop
, 4);
232 c
->bottom
.SameAs(m_panel
, wxBottom
, 40);
234 m_notebook
->SetConstraints(c
);
236 wxGetApp().InitTabView(m_notebook
, m_panel
);
238 m_panel
->SetAutoLayout(TRUE
);
242 this->Centre(wxBOTH
);
247 void MyFrame::OnSize(wxSizeEvent
& event
)
249 wxFrame::OnSize(event
);
253 void MyFrame::OnIdle(wxIdleEvent
& WXUNUSED(event
))
255 static int s_nPages
= -1;
256 static int s_nSel
= -1;
258 int nPages
= m_notebook
->GetPageCount();
259 int nSel
= m_notebook
->GetSelection();
260 if ( nPages
!= s_nPages
|| nSel
!= s_nSel
)
266 title
.Printf("Notebook (%d pages, selection: %d)", nPages
, nSel
);