]>
git.saurik.com Git - wxWidgets.git/blob - samples/tab/test.cpp
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 1
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 m_okButton
= new wxButton(window
, wxID_OK
, "Close", wxPoint(-1, -1), wxSize(80, 25));
54 m_cancelButton
= new wxButton(window
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(80, 25));
55 m_helpButton
= new wxButton(window
, wxID_HELP
, "Help", wxPoint(-1, -1), wxSize(80, 25));
56 m_okButton
->SetDefault();
58 wxLayoutConstraints
* c
= new wxLayoutConstraints
;
59 c
->right
.SameAs(window
, wxRight
, 4);
60 c
->bottom
.SameAs(window
, wxBottom
, 4);
63 m_helpButton
->SetConstraints(c
);
65 c
= new wxLayoutConstraints
;
66 c
->right
.SameAs(m_helpButton
, wxLeft
, 4);
67 c
->bottom
.SameAs(window
, wxBottom
, 4);
70 m_cancelButton
->SetConstraints(c
);
72 c
= new wxLayoutConstraints
;
73 c
->right
.SameAs(m_cancelButton
, wxLeft
, 4);
74 c
->bottom
.SameAs(window
, wxBottom
, 4);
77 m_okButton
->SetConstraints(c
);
82 // Could calculate the view width from the tab width and spacing,
83 // as below, but let's assume we have a fixed view width.
84 // rect.width = view->GetTabWidth()*4 + 3*view->GetHorizontalTabSpacing();
88 view
->SetViewRect(rect
);
90 // Calculate the tab width for 4 tabs, based on a view width of 326 and
91 // the current horizontal spacing. Adjust the view width to exactly fit
93 view
->CalculateTabWidth(4, TRUE
);
95 if (!view
->AddTab(TEST_TAB_CAT
, wxString("Cat")))
98 if (!view
->AddTab(TEST_TAB_DOG
, wxString("Dog")))
100 if (!view
->AddTab(TEST_TAB_GUINEAPIG
, wxString("Guinea Pig")))
102 if (!view
->AddTab(TEST_TAB_GOAT
, wxString("Goat")))
104 if (!view
->AddTab(TEST_TAB_ANTEATER
, wxString("Ant-eater")))
106 if (!view
->AddTab(TEST_TAB_SHEEP
, wxString("Sheep")))
108 if (!view
->AddTab(TEST_TAB_COW
, wxString("Cow")))
110 if (!view
->AddTab(TEST_TAB_HORSE
, wxString("Horse")))
112 if (!view
->AddTab(TEST_TAB_PIG
, wxString("Pig")))
114 if (!view
->AddTab(TEST_TAB_OSTRICH
, wxString("Ostrich")))
116 if (!view
->AddTab(TEST_TAB_AARDVARK
, wxString("Aardvark")))
118 if (!view
->AddTab(TEST_TAB_HUMMINGBIRD
,wxString("Hummingbird")))
122 wxPanel
*panel1
= new wxPanel(window
, -1, wxPoint(rect
.x
+ 20, rect
.y
+ 10), wxSize(290, 220), wxTAB_TRAVERSAL
);
123 (void)new wxButton(panel1
, -1, "Press me", wxPoint(10, 10));
124 (void)new wxTextCtrl(panel1
, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
126 view
->AddTabWindow(TEST_TAB_CAT
, panel1
);
128 wxPanel
*panel2
= new wxPanel(window
, -1, wxPoint(rect
.x
+ 20, rect
.y
+ 10), wxSize(290, 220));
130 wxString animals
[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
131 (void)new wxListBox(panel2
, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals
);
133 (void)new wxTextCtrl(panel2
, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100),
136 view
->AddTabWindow(TEST_TAB_DOG
, panel2
);
137 view
->SetTabSelection(TEST_TAB_CAT
);
140 BEGIN_EVENT_TABLE(MyDialog
, wxTabbedDialog
)
141 EVT_BUTTON(wxID_OK
, MyDialog::OnOK
)
142 EVT_BUTTON(wxID_CANCEL
, MyDialog::OnOK
)
145 MyDialog::MyDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
,
146 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
147 wxTabbedDialog(parent
, id
, title
, pos
, size
, windowStyle
)
152 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
157 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
159 EndModal(wxID_CANCEL
);
162 void MyDialog::Init(void)
164 int dialogWidth
= 365;
165 int dialogHeight
= 390;
167 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
168 // with the panel background, and save a bit of time.
169 wxPanelTabView
*view
= new wxPanelTabView(this, wxTAB_STYLE_DRAW_BOX
);
171 wxGetApp().InitTabView(view
, this);
173 // Don't know why this is necessary under Motif...
175 this->SetSize(dialogWidth
, dialogHeight
-20);
180 this->Centre(wxBOTH
);
183 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
184 EVT_BUTTON(wxID_OK
, MyFrame::OnOK
)
185 EVT_BUTTON(wxID_CANCEL
, MyFrame::OnOK
)
186 EVT_SIZE(MyFrame::OnSize
)
189 MyFrame::MyFrame(wxFrame
* parent
, const wxWindowID id
, const wxString
& title
,
190 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
191 wxFrame(parent
, id
, title
, pos
, size
, windowStyle
)
193 m_panel
= (wxTabbedPanel
*) NULL
;
194 m_view
= (wxPanelTabView
*) NULL
;
198 void MyFrame::OnOK(wxCommandEvent
& WXUNUSED(event
) )
203 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
208 void MyFrame::Init(void)
210 m_panel
= new wxTabbedPanel(this, -1);
212 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
213 // with the panel background, and save a bit of time.
214 m_view
= new wxPanelTabView(m_panel
, wxTAB_STYLE_DRAW_BOX
);
216 wxGetApp().InitTabView(m_view
, m_panel
);
218 this->Centre(wxBOTH
);
223 void MyFrame::OnSize(wxSizeEvent
& event
)
225 wxFrame::OnSize(event
);
228 GetClientSize(& cw
, & ch
);
230 if (m_view
&& m_panel
)
234 int tabHeight
= m_view
->GetTotalTabHeight();
237 rect
.y
= tabHeight
+ 4;
239 rect
.height
= ch
- 4 - rect
.y
- 30; // 30 for buttons
241 m_view
->SetViewRect(rect
);
245 // Need to do it a 2nd time to get the tab height with
246 // the new view width
247 tabHeight
= m_view
->GetTotalTabHeight();
249 rect
.y
= tabHeight
+ 4;
251 rect
.height
= ch
- 4 - rect
.y
- 30; // 30 for buttons
253 m_view
->SetViewRect(rect
);
257 // Move all the panels to the new view position and size
258 wxNode
* node
= m_view
->GetWindows().First();
261 wxWindow
* win
= (wxWindow
*) node
->Data();
262 win
->SetSize(rect
.x
+2, rect
.y
+2, rect
.width
-4, rect
.height
-4);