]> git.saurik.com Git - wxWidgets.git/blame - samples/tab/test.cpp
Attempting to check in this wretched cursor again. Also added SetAcceleratorTable
[wxWidgets.git] / samples / tab / test.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: test.cpp
3// Purpose: Tab demo
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
23#include "wx/tab.h"
24#include "test.h"
25
26// Declare two frames
27MyDialog *dialog = NULL;
28
29IMPLEMENT_APP(MyApp)
30
31bool MyApp::OnInit(void)
32{
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);
35
36 dialog->ShowModal();
37
38 // Quit immediately the dialog has been dismissed
39 return FALSE;
40}
41
42BEGIN_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)
46END_EVENT_TABLE()
47
48MyDialog::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)
51{
52 Init();
53}
54
e3e65dac 55void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
56{
57 EndModal(wxID_OK);
58}
59
e3e65dac 60void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
c801d85f
KB
61{
62 EndModal(wxID_CANCEL);
63}
64
65void MyDialog::Init(void)
66{
67 int dialogWidth = 365;
68 int dialogHeight = 390;
69
70 wxButton *okButton = new wxButton(this, wxID_OK, "Close", wxPoint(100, 330), wxSize(80, 25));
e3e65dac
RR
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));
c801d85f
KB
73 okButton->SetDefault();
74
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);
78
79 wxRectangle rect;
80 rect.x = 5;
81 rect.y = 70;
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();
85 rect.width = 326;
86 rect.height = 250;
87
88 view->SetViewRect(rect);
89
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
92 // the tabs.
93 view->CalculateTabWidth(4, TRUE);
94
95 if (!view->AddTab(TEST_TAB_CAT, wxString("Cat")))
96 return;
97
98 if (!view->AddTab(TEST_TAB_DOG, wxString("Dog")))
99 return;
100 if (!view->AddTab(TEST_TAB_GUINEAPIG, wxString("Guinea Pig")))
101 return;
102 if (!view->AddTab(TEST_TAB_GOAT, wxString("Goat")))
103 return;
104 if (!view->AddTab(TEST_TAB_ANTEATER, wxString("Ant-eater")))
105 return;
106 if (!view->AddTab(TEST_TAB_SHEEP, wxString("Sheep")))
107 return;
108 if (!view->AddTab(TEST_TAB_COW, wxString("Cow")))
109 return;
110 if (!view->AddTab(TEST_TAB_HORSE, wxString("Horse")))
111 return;
112 if (!view->AddTab(TEST_TAB_PIG, wxString("Pig")))
113 return;
114 if (!view->AddTab(TEST_TAB_OSTRICH, wxString("Ostrich")))
115 return;
116 if (!view->AddTab(TEST_TAB_AARDVARK, wxString("Aardvark")))
117 return;
118 if (!view->AddTab(TEST_TAB_HUMMINGBIRD,wxString("Hummingbird")))
119 return;
120
121 // Add some panels
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));
125
126 view->AddTabWindow(TEST_TAB_CAT, panel1);
127
128 wxPanel *panel2 = new wxPanel(this, -1, wxPoint(rect.x + 20, rect.y + 10), wxSize(290, 220));
129
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);
132
133 (void)new wxTextCtrl(panel2, -1, "Some notes about the animals in this house", wxPoint(5, 100), wxSize(170, 100)),
134 wxTE_MULTILINE;
135
136 view->AddTabWindow(TEST_TAB_DOG, panel2);
137
138 // Don't know why this is necessary under Motif...
e3e65dac 139#ifndef __WXMSW__
c801d85f
KB
140 this->SetSize(dialogWidth, dialogHeight-20);
141#endif
142
143 view->SetTabSelection(TEST_TAB_CAT);
144
145 this->Centre(wxBOTH);
146}
147