]>
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"
27 MyDialog
*dialog
= NULL
;
31 bool MyApp::OnInit(void)
33 // Create the main frame window
34 dialog
= new MyDialog(NULL
, -1, "Tabbed Dialog", wxPoint(-1, -1), wxSize(365, 390), wxDIALOG_MODAL
|wxDEFAULT_DIALOG_STYLE
);
38 // Quit immediately the dialog has been dismissed
42 BEGIN_EVENT_TABLE(MyDialog
, wxTabbedDialog
)
43 EVT_BUTTON(wxID_OK
, MyDialog::OnOK
)
44 EVT_BUTTON(wxID_CANCEL
, MyDialog::OnOK
)
45 // EVT_MENU(TEST_ABOUT, MyDialog::OnAbout)
48 MyDialog::MyDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
,
49 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
50 wxTabbedDialog(parent
, id
, title
, pos
, size
, windowStyle
)
55 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
60 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
62 EndModal(wxID_CANCEL
);
65 void MyDialog::Init(void)
67 int dialogWidth
= 365;
68 int dialogHeight
= 390;
70 wxButton
*okButton
= new wxButton(this, wxID_OK
, "Close", wxPoint(100, 330), wxSize(80, 25));
71 (void)new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(185, 330), wxSize(80, 25));
72 (void)new wxButton(this, wxID_HELP
, "Help", wxPoint(270, 330), wxSize(80, 25));
73 okButton
->SetDefault();
75 // Note, omit the wxTAB_STYLE_COLOUR_INTERIOR, so we will guarantee a match
76 // with the panel background, and save a bit of time.
77 wxPanelTabView
*view
= new wxPanelTabView((wxPanel
*)this, wxTAB_STYLE_DRAW_BOX
);
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(this, -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(this, -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
);
138 // Don't know why this is necessary under Motif...
140 this->SetSize(dialogWidth
, dialogHeight
-20);
143 view
->SetTabSelection(TEST_TAB_CAT
);
145 this->Centre(wxBOTH
);