]>
Commit | Line | Data |
---|---|---|
1c005ff7 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: minimal.cpp | |
3 | // Purpose: Controls wxWindows sample | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Robert Roebling, Julian Smart and Markus Holzem | |
8 | // Licence: wxWindows license | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "minimal.cpp" | |
13 | #pragma interface "minimal.cpp" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/tabctrl.h" | |
28 | ||
29 | //---------------------------------------------------------------------- | |
30 | // class definitions | |
31 | //---------------------------------------------------------------------- | |
32 | ||
33 | class MyApp: public wxApp | |
34 | { | |
35 | public: | |
36 | bool OnInit(void); | |
37 | }; | |
38 | ||
39 | class MyPanel: public wxPanel | |
40 | { | |
41 | public: | |
42 | ||
43 | MyPanel(wxFrame *frame, int x, int y, int w, int h); | |
44 | ||
45 | void OnSize( wxSizeEvent& event ); | |
46 | void OnListBox( wxCommandEvent &event ); | |
47 | void OnListBoxButtons( wxCommandEvent &event ); | |
48 | ||
49 | wxListBox *m_listbox; | |
50 | ||
51 | wxTextCtrl *m_text; | |
52 | wxTabCtrl *m_tab; | |
53 | ||
54 | DECLARE_EVENT_TABLE() | |
55 | }; | |
56 | ||
57 | class MyFrame: public wxFrame | |
58 | { | |
59 | public: | |
60 | ||
61 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); | |
62 | ||
63 | public: | |
64 | ||
65 | void OnQuit(wxCommandEvent& event); | |
66 | void OnAbout(wxCommandEvent& event); | |
67 | bool OnClose(void) { return TRUE; } | |
68 | ||
69 | DECLARE_EVENT_TABLE() | |
70 | }; | |
71 | ||
72 | //---------------------------------------------------------------------- | |
73 | // main() | |
74 | //---------------------------------------------------------------------- | |
75 | ||
76 | IMPLEMENT_APP (MyApp) | |
77 | ||
78 | //---------------------------------------------------------------------- | |
79 | // MyApp | |
80 | //---------------------------------------------------------------------- | |
81 | ||
82 | const MINIMAL_QUIT = 100; | |
83 | const MINIMAL_TEXT = 101; | |
84 | const MINIMAL_ABOUT = 102; | |
85 | ||
86 | bool MyApp::OnInit(void) | |
87 | { | |
88 | // Create the main frame window | |
89 | MyFrame *frame = new MyFrame(NULL, "Controls wxWindows App", 50, 50, 500, 420 ); | |
90 | ||
91 | // Give it an icon | |
92 | #ifdef __WINDOWS__ | |
93 | frame->SetIcon(wxIcon("mondrian")); | |
94 | #endif | |
95 | #ifdef __X__ | |
96 | frame->SetIcon(wxIcon("aiai.xbm")); | |
97 | #endif | |
98 | ||
99 | wxMenu *file_menu = new wxMenu; | |
100 | ||
101 | file_menu->Append(MINIMAL_ABOUT, "&About"); | |
102 | file_menu->Append(MINIMAL_QUIT, "E&xit"); | |
103 | wxMenuBar *menu_bar = new wxMenuBar; | |
104 | menu_bar->Append(file_menu, "&File"); | |
105 | frame->SetMenuBar(menu_bar); | |
106 | ||
107 | frame->Show(TRUE); | |
108 | ||
109 | SetTopWindow(frame); | |
110 | ||
111 | return TRUE; | |
112 | } | |
113 | ||
114 | //---------------------------------------------------------------------- | |
115 | // MyPanel | |
116 | //---------------------------------------------------------------------- | |
117 | ||
118 | const MINIMAL_TAB = 1000; | |
119 | ||
120 | const ID_LISTBOX = 130; | |
121 | const ID_LISTBOX_SEL_NUM = 131; | |
122 | const ID_LISTBOX_SEL_STR = 132; | |
123 | const ID_LISTBOX_CLEAR = 133; | |
124 | const ID_LISTBOX_APPEND = 134; | |
125 | ||
126 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) | |
127 | EVT_SIZE ( MyPanel::OnSize) | |
128 | EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) | |
129 | EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons) | |
130 | EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons) | |
131 | EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons) | |
132 | EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons) | |
133 | END_EVENT_TABLE() | |
134 | ||
135 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : | |
136 | wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ) | |
137 | { | |
138 | m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); | |
139 | ||
140 | m_tab = new wxTabCtrl( this, MINIMAL_TAB, wxPoint(0,0), wxSize(200,150) ); | |
141 | ||
142 | wxString choices[4] = | |
143 | { | |
144 | "This", | |
145 | "is", | |
146 | "a", | |
147 | "wonderfull example." | |
148 | }; | |
149 | ||
150 | m_tab->InsertItem( 0, "wxList" ); | |
151 | m_listbox = new wxListBox( m_tab, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 4, choices ); | |
152 | (void)new wxButton( m_tab, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(140,30), wxSize(100,30) ); | |
153 | (void)new wxButton( m_tab, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(260,30), wxSize(100,30) ); | |
154 | (void)new wxButton( m_tab, ID_LISTBOX_CLEAR, "Clear", wxPoint(140,80), wxSize(100,30) ); | |
155 | (void)new wxButton( m_tab, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(260,80), wxSize(100,30) ); | |
156 | ||
157 | m_tab->InsertItem( 1, "wxChoice" ); | |
158 | } | |
159 | ||
160 | void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) | |
161 | { | |
162 | int x = 0; | |
163 | int y = 0; | |
164 | GetClientSize( &x, &y ); | |
165 | ||
166 | if (m_tab) m_tab->SetSize( 2, 2, x-4, y/2-4 ); | |
167 | if (m_text) m_text->SetSize( 2, y/2+2, x-4, y/2-4 ); | |
168 | } | |
169 | ||
170 | void MyPanel::OnListBox( wxCommandEvent &event ) | |
171 | { | |
172 | m_text->WriteText( "ListBox Event:\n"); | |
173 | m_text->WriteText( "ListBox selection string is: " ); | |
174 | m_text->WriteText( event.GetString() ); | |
175 | m_text->WriteText( "\n" ); | |
176 | } | |
177 | ||
178 | void MyPanel::OnListBoxButtons( wxCommandEvent &WXUNUSED(event) ) | |
179 | { | |
180 | } | |
181 | ||
182 | //---------------------------------------------------------------------- | |
183 | // MyFrame | |
184 | //---------------------------------------------------------------------- | |
185 | ||
186 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
187 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) | |
188 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
189 | END_EVENT_TABLE() | |
190 | ||
191 | MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): | |
192 | wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
193 | { | |
194 | (void*) new MyPanel( this, 10, 10, 300, 100 ); | |
195 | } | |
196 | ||
197 | void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) ) | |
198 | { | |
199 | Close(TRUE); | |
200 | } | |
201 | ||
202 | void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) | |
203 | { | |
204 | wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK ); | |
205 | dialog.ShowModal(); | |
206 | } | |
207 | ||
208 |