]>
git.saurik.com Git - wxWidgets.git/blob - samples/tab/test.cpp
734025be6c83a3ce92a7ba657e076e7fec400009
1 /////////////////////////////////////////////////////////////////////////////
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 *) "Tabbed Dialog", 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 *) "Tabbed Panel", wxPoint(-1, -1), wxSize(365, 390), wxDEFAULT_FRAME_STYLE
);
51 void MyApp::InitTabView(wxPanelTabView
* view
, 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
);
85 // Could calculate the view width from the tab width and spacing,
86 // as below, but let's assume we have a fixed view width.
87 // rect.width = view->GetTabWidth()*4 + 3*view->GetHorizontalTabSpacing();
91 view
->SetViewRect(rect
);
93 // Calculate the tab width for 4 tabs, based on a view width of 326 and
94 // the current horizontal spacing. Adjust the view width to exactly fit
96 view
->CalculateTabWidth(4, TRUE
);
98 if (!view
->AddTab(TEST_TAB_CAT
, wxString("Cat")))
101 if (!view
->AddTab(TEST_TAB_DOG
, wxString("Dog")))
103 if (!view
->AddTab(TEST_TAB_GUINEAPIG
, wxString("Guinea Pig")))
105 if (!view
->AddTab(TEST_TAB_GOAT
, wxString("Goat")))
107 if (!view
->AddTab(TEST_TAB_ANTEATER
, wxString("Ant-eater")))
109 if (!view
->AddTab(TEST_TAB_SHEEP
, wxString("Sheep")))
111 if (!view
->AddTab(TEST_TAB_COW
, wxString("Cow")))
113 if (!view
->AddTab(TEST_TAB_HORSE
, wxString("Horse")))
115 if (!view
->AddTab(TEST_TAB_PIG
, wxString("Pig")))
117 if (!view
->AddTab(TEST_TAB_OSTRICH
, wxString("Ostrich")))
119 if (!view
->AddTab(TEST_TAB_AARDVARK
, wxString("Aardvark")))
121 if (!view
->AddTab(TEST_TAB_HUMMINGBIRD
,wxString("Hummingbird")))
125 wxPanel
*panel1
= new wxPanel(window
, -1, wxPoint(rect
.x
+ 20, rect
.y
+ 10), wxSize(290, 220), wxTAB_TRAVERSAL
);
126 (void)new wxButton(panel1
, -1, "Press me", wxPoint(10, 10));
127 (void)new wxTextCtrl(panel1
, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
129 view
->AddTabWindow(TEST_TAB_CAT
, panel1
);
131 wxPanel
*panel2
= new wxPanel(window
, -1, wxPoint(rect
.x
+ 20, rect
.y
+ 10), wxSize(290, 220));
133 wxString animals
[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
134 (void)new wxListBox(panel2
, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals
);
136 (void)new wxTextCtrl(panel2
, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100),
139 view
->AddTabWindow(TEST_TAB_DOG
, panel2
);
140 view
->SetTabSelection(TEST_TAB_CAT
);
143 BEGIN_EVENT_TABLE(MyDialog
, wxTabbedDialog
)
144 EVT_BUTTON(wxID_OK
, MyDialog::OnOK
)
145 EVT_BUTTON(wxID_CANCEL
, MyDialog::OnOK
)
148 MyDialog::MyDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
,
149 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
150 wxTabbedDialog(parent
, id
, title
, pos
, size
, windowStyle
)
155 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
160 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
162 EndModal(wxID_CANCEL
);
165 void MyDialog::Init(void)
167 int dialogWidth
= 365;
168 int dialogHeight
= 390;
170 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
171 // with the panel background, and save a bit of time.
172 wxPanelTabView
*view
= new wxPanelTabView(this, wxTAB_STYLE_DRAW_BOX
);
174 wxGetApp().InitTabView(view
, this);
176 // Don't know why this is necessary under Motif...
178 this->SetSize(dialogWidth
, dialogHeight
-20);
183 this->Centre(wxBOTH
);
186 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
187 EVT_BUTTON(wxID_OK
, MyFrame::OnOK
)
188 EVT_BUTTON(wxID_CANCEL
, MyFrame::OnOK
)
189 EVT_SIZE(MyFrame::OnSize
)
192 MyFrame::MyFrame(wxFrame
* parent
, const wxWindowID id
, const wxString
& title
,
193 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
194 wxFrame(parent
, id
, title
, pos
, size
, windowStyle
)
196 m_panel
= (wxTabbedPanel
*) NULL
;
197 m_view
= (wxPanelTabView
*) NULL
;
201 void MyFrame::OnOK(wxCommandEvent
& WXUNUSED(event
) )
206 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
211 void MyFrame::Init(void)
213 int dialogWidth
= 365;
214 int dialogHeight
= 390;
216 m_panel
= new wxTabbedPanel(this, -1);
218 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
219 // with the panel background, and save a bit of time.
220 m_view
= new wxPanelTabView(m_panel
, wxTAB_STYLE_DRAW_BOX
);
222 wxGetApp().InitTabView(m_view
, m_panel
);
224 this->Centre(wxBOTH
);
229 void MyFrame::OnSize(wxSizeEvent
& event
)
231 wxFrame::OnSize(event
);
234 GetClientSize(& cw
, & ch
);
236 if (m_view
&& m_panel
)
240 int tabHeight
= m_view
->GetTotalTabHeight();
243 rect
.y
= tabHeight
+ 4;
245 rect
.height
= ch
- 4 - rect
.y
- 30; // 30 for buttons
247 m_view
->SetViewRect(rect
);
251 // Need to do it a 2nd time to get the tab height with
252 // the new view width
253 tabHeight
= m_view
->GetTotalTabHeight();
255 rect
.y
= tabHeight
+ 4;
257 rect
.height
= ch
- 4 - rect
.y
- 30; // 30 for buttons
259 m_view
->SetViewRect(rect
);
263 // Move all the panels to the new view position and size
264 wxNode
* node
= m_view
->GetWindows().First();
267 wxWindow
* win
= (wxWindow
*) node
->Data();
268 win
->SetSize(rect
.x
+2, rect
.y
+2, rect
.width
-4, rect
.height
-4);