]>
Commit | Line | Data |
---|---|---|
1c005ff7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
dfad0599 | 2 | // Name: controls.cpp |
1c005ff7 RR |
3 | // Purpose: Controls wxWindows sample |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
c67d8618 | 7 | // Copyright: (c) Robert Roebling, Julian Smart |
1c005ff7 RR |
8 | // Licence: wxWindows license |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
e4a81a2e | 12 | #pragma implementation "controls.h" |
1c005ff7 RR |
13 | #endif |
14 | ||
15 | // For compilers that support precompilation, includes "wx/wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/wx.h" | |
24 | #endif | |
25 | ||
53b28675 | 26 | #include "wx/notebook.h" |
2cb21a45 | 27 | #include "wx/imaglist.h" |
1c005ff7 | 28 | |
4b5f3fe6 | 29 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
47908e25 | 30 | #include "mondrian.xpm" |
fc54776e RR |
31 | #include "icons/choice.xpm" |
32 | #include "icons/combo.xpm" | |
33 | #include "icons/list.xpm" | |
34 | #include "icons/radio.xpm" | |
35 | #include "icons/text.xpm" | |
c67d8618 | 36 | #include "icons/stattext.xpm" |
47908e25 RR |
37 | #endif |
38 | ||
1c005ff7 RR |
39 | //---------------------------------------------------------------------- |
40 | // class definitions | |
41 | //---------------------------------------------------------------------- | |
42 | ||
43 | class MyApp: public wxApp | |
44 | { | |
45 | public: | |
46 | bool OnInit(void); | |
47 | }; | |
48 | ||
49 | class MyPanel: public wxPanel | |
50 | { | |
51 | public: | |
52 | ||
53 | MyPanel(wxFrame *frame, int x, int y, int w, int h); | |
2cb21a45 | 54 | virtual ~MyPanel(); |
1c005ff7 RR |
55 | |
56 | void OnSize( wxSizeEvent& event ); | |
57 | void OnListBox( wxCommandEvent &event ); | |
58 | void OnListBoxButtons( wxCommandEvent &event ); | |
47908e25 RR |
59 | void OnChoice( wxCommandEvent &event ); |
60 | void OnChoiceButtons( wxCommandEvent &event ); | |
61 | void OnCombo( wxCommandEvent &event ); | |
62 | void OnComboButtons( wxCommandEvent &event ); | |
63 | void OnRadio( wxCommandEvent &event ); | |
64 | void OnRadioButtons( wxCommandEvent &event ); | |
868a2826 | 65 | void OnSetFont( wxCommandEvent &event ); |
cb43b372 | 66 | void OnPageChanged( wxNotebookEvent &event ); |
1c005ff7 RR |
67 | |
68 | wxListBox *m_listbox; | |
53010e52 RR |
69 | wxChoice *m_choice; |
70 | wxComboBox *m_combo; | |
47908e25 | 71 | wxRadioBox *m_radio; |
868a2826 | 72 | wxButton *m_fontButton; |
1c005ff7 RR |
73 | |
74 | wxTextCtrl *m_text; | |
53b28675 | 75 | wxNotebook *m_notebook; |
1c005ff7 RR |
76 | |
77 | DECLARE_EVENT_TABLE() | |
78 | }; | |
79 | ||
80 | class MyFrame: public wxFrame | |
81 | { | |
82 | public: | |
83 | ||
84 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); | |
85 | ||
86 | public: | |
87 | ||
88 | void OnQuit(wxCommandEvent& event); | |
89 | void OnAbout(wxCommandEvent& event); | |
90 | bool OnClose(void) { return TRUE; } | |
91 | ||
92 | DECLARE_EVENT_TABLE() | |
93 | }; | |
94 | ||
95 | //---------------------------------------------------------------------- | |
96 | // main() | |
97 | //---------------------------------------------------------------------- | |
98 | ||
99 | IMPLEMENT_APP (MyApp) | |
100 | ||
101 | //---------------------------------------------------------------------- | |
102 | // MyApp | |
103 | //---------------------------------------------------------------------- | |
104 | ||
c67daf87 UR |
105 | const int MINIMAL_QUIT = 100; |
106 | const int MINIMAL_TEXT = 101; | |
107 | const int MINIMAL_ABOUT = 102; | |
1c005ff7 RR |
108 | |
109 | bool MyApp::OnInit(void) | |
110 | { | |
111 | // Create the main frame window | |
d3904ceb | 112 | MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Controls wxWindows App", 50, 50, 530, 420 ); |
1c005ff7 RR |
113 | |
114 | // Give it an icon | |
2049ba38 | 115 | #ifdef __WXMSW__ |
1c005ff7 | 116 | frame->SetIcon(wxIcon("mondrian")); |
47908e25 RR |
117 | #else |
118 | frame->SetIcon(wxIcon( mondrian_xpm )); | |
1c005ff7 RR |
119 | #endif |
120 | ||
121 | wxMenu *file_menu = new wxMenu; | |
122 | ||
123 | file_menu->Append(MINIMAL_ABOUT, "&About"); | |
124 | file_menu->Append(MINIMAL_QUIT, "E&xit"); | |
125 | wxMenuBar *menu_bar = new wxMenuBar; | |
126 | menu_bar->Append(file_menu, "&File"); | |
127 | frame->SetMenuBar(menu_bar); | |
128 | ||
129 | frame->Show(TRUE); | |
130 | ||
131 | SetTopWindow(frame); | |
132 | ||
133 | return TRUE; | |
134 | } | |
135 | ||
136 | //---------------------------------------------------------------------- | |
137 | // MyPanel | |
138 | //---------------------------------------------------------------------- | |
139 | ||
30f82ea4 | 140 | const ID_NOTEBOOK = 1000; |
1c005ff7 | 141 | |
30f82ea4 RR |
142 | const ID_LISTBOX = 130; |
143 | const ID_LISTBOX_SEL_NUM = 131; | |
144 | const ID_LISTBOX_SEL_STR = 132; | |
145 | const ID_LISTBOX_CLEAR = 133; | |
146 | const ID_LISTBOX_APPEND = 134; | |
147 | const ID_LISTBOX_DELETE = 135; | |
868a2826 | 148 | const ID_LISTBOX_FONT = 136; |
d3904ceb | 149 | const ID_LISTBOX_ENABLE = 137; |
1c005ff7 | 150 | |
30f82ea4 RR |
151 | const ID_CHOICE = 120; |
152 | const ID_CHOICE_SEL_NUM = 121; | |
153 | const ID_CHOICE_SEL_STR = 122; | |
154 | const ID_CHOICE_CLEAR = 123; | |
155 | const ID_CHOICE_APPEND = 124; | |
2f6407b9 | 156 | const ID_CHOICE_DELETE = 125; |
868a2826 | 157 | const ID_CHOICE_FONT = 126; |
d3904ceb | 158 | const ID_CHOICE_ENABLE = 127; |
53010e52 | 159 | |
30f82ea4 RR |
160 | const ID_COMBO = 140; |
161 | const ID_COMBO_SEL_NUM = 141; | |
162 | const ID_COMBO_SEL_STR = 142; | |
163 | const ID_COMBO_CLEAR = 143; | |
164 | const ID_COMBO_APPEND = 144; | |
2f6407b9 | 165 | const ID_COMBO_DELETE = 145; |
868a2826 | 166 | const ID_COMBO_FONT = 146; |
d3904ceb | 167 | const ID_COMBO_ENABLE = 147; |
53010e52 | 168 | |
30f82ea4 | 169 | const ID_TEXT = 150; |
219f895a | 170 | |
30f82ea4 RR |
171 | const ID_RADIOBOX = 160; |
172 | const ID_RADIOBOX_SEL_NUM = 161; | |
173 | const ID_RADIOBOX_SEL_STR = 162; | |
868a2826 | 174 | const ID_RADIOBOX_FONT = 163; |
d3904ceb | 175 | const ID_RADIOBOX_ENABLE = 164; |
868a2826 RR |
176 | |
177 | const ID_SET_FONT = 170; | |
47908e25 | 178 | |
1c005ff7 | 179 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
cb43b372 RR |
180 | EVT_SIZE ( MyPanel::OnSize) |
181 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged) | |
182 | EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) | |
183 | EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons) | |
184 | EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons) | |
185 | EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons) | |
186 | EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons) | |
187 | EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons) | |
188 | EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons) | |
189 | EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons) | |
190 | EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice) | |
191 | EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons) | |
192 | EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons) | |
193 | EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons) | |
194 | EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons) | |
195 | EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons) | |
196 | EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons) | |
197 | EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons) | |
198 | EVT_CHOICE (ID_COMBO, MyPanel::OnCombo) | |
199 | EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons) | |
200 | EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons) | |
201 | EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons) | |
202 | EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons) | |
203 | EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons) | |
204 | EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons) | |
205 | EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons) | |
206 | EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio) | |
207 | EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons) | |
208 | EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons) | |
209 | EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons) | |
210 | EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons) | |
211 | EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) | |
1c005ff7 RR |
212 | END_EVENT_TABLE() |
213 | ||
214 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : | |
215 | wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ) | |
216 | { | |
a81258be RR |
217 | SetBackgroundColour("cadet blue"); |
218 | ||
1c005ff7 | 219 | m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); |
f96aa4d9 | 220 | m_text->SetBackgroundColour("wheat"); |
1c005ff7 | 221 | |
53b28675 | 222 | m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) ); |
1c005ff7 | 223 | |
53010e52 | 224 | wxString choices[] = |
1c005ff7 RR |
225 | { |
226 | "This", | |
c67d8618 RR |
227 | "is one of my", |
228 | "really", | |
e8435fa3 | 229 | "wonderful", |
c67d8618 | 230 | "examples.", |
1c005ff7 RR |
231 | }; |
232 | ||
2cb21a45 VZ |
233 | // image ids and names |
234 | enum | |
235 | { | |
c67d8618 | 236 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Static, Image_Max |
2cb21a45 VZ |
237 | }; |
238 | ||
fc54776e RR |
239 | // fill the image list |
240 | #ifdef __WXMSW__ | |
2cb21a45 VZ |
241 | const char *aIconNames[] = |
242 | { | |
c67d8618 | 243 | "list.xpm", "choice.xpm", "combo.xpm", "text.xpm", "radio.xpm", "stattext.xpm" |
2cb21a45 VZ |
244 | }; |
245 | ||
246 | wxASSERT( WXSIZEOF(aIconNames) == Image_Max ); // keep in sync | |
247 | ||
fc54776e RR |
248 | wxString strIconDir = "icons/"; |
249 | ||
2cb21a45 | 250 | wxImageList *imagelist = new wxImageList(32, 32); |
868a2826 RR |
251 | for ( size_t n = 0; n < Image_Max; n++ ) |
252 | { | |
2cb21a45 VZ |
253 | imagelist->Add(wxBitmap(strIconDir + aIconNames[n])); |
254 | } | |
fc54776e RR |
255 | #else |
256 | wxImageList *imagelist = new wxImageList(32, 32); | |
257 | ||
258 | imagelist-> Add( wxBitmap( list_xpm )); | |
259 | imagelist-> Add( wxBitmap( choice_xpm )); | |
260 | imagelist-> Add( wxBitmap( combo_xpm )); | |
261 | imagelist-> Add( wxBitmap( text_xpm )); | |
262 | imagelist-> Add( wxBitmap( radio_xpm )); | |
c67d8618 | 263 | imagelist-> Add( wxBitmap( stattext_xpm )); |
fc54776e | 264 | #endif |
2cb21a45 | 265 | |
a81258be RR |
266 | wxButton *button = (wxButton*)NULL; |
267 | ||
2cb21a45 | 268 | m_notebook->SetImageList(imagelist); |
a81258be | 269 | m_notebook->SetBackgroundColour("cadet blue"); |
2cb21a45 | 270 | |
4bf58c62 | 271 | wxPanel *panel = new wxPanel(m_notebook); |
f96aa4d9 | 272 | panel->SetBackgroundColour("cadet blue"); |
c67d8618 | 273 | m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices ); |
f96aa4d9 | 274 | m_listbox->SetBackgroundColour("wheat"); |
d3904ceb RR |
275 | (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
276 | (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
f96aa4d9 | 277 | (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); |
d3904ceb | 278 | (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); |
30f82ea4 | 279 | (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); |
a81258be RR |
280 | button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); |
281 | button->SetForegroundColour( "red" ); | |
d3904ceb | 282 | (void)new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); |
2cb21a45 | 283 | m_notebook->AddPage(panel, "wxList", FALSE, Image_List); |
53010e52 | 284 | |
4bf58c62 | 285 | panel = new wxPanel(m_notebook); |
f96aa4d9 | 286 | panel->SetBackgroundColour("cadet blue"); |
c67d8618 | 287 | m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices ); |
a81258be | 288 | m_choice->SetBackgroundColour("wheat"); |
d3904ceb RR |
289 | (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
290 | (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
291 | (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
292 | (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
2f6407b9 | 293 | (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); |
d3904ceb RR |
294 | (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); |
295 | (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
2cb21a45 | 296 | m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); |
53010e52 | 297 | |
4bf58c62 | 298 | panel = new wxPanel(m_notebook); |
f96aa4d9 | 299 | panel->SetBackgroundColour("cadet blue"); |
c67d8618 | 300 | m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices ); |
f96aa4d9 | 301 | m_combo->SetBackgroundColour("wheat"); |
d3904ceb RR |
302 | (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
303 | (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
304 | (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
305 | (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
2f6407b9 | 306 | (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); |
d3904ceb RR |
307 | (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); |
308 | (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
2cb21a45 | 309 | m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo); |
219f895a | 310 | |
f96aa4d9 RR |
311 | panel = new wxPanel(m_notebook); |
312 | panel->SetBackgroundColour("cadet blue"); | |
313 | wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(350,28)); | |
314 | tc->SetBackgroundColour("wheat"); | |
315 | tc = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(350,160), wxTE_MULTILINE ); | |
316 | tc->SetBackgroundColour("wheat"); | |
317 | m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text); | |
47908e25 | 318 | |
e5403d7c RR |
319 | wxString choices2[] = |
320 | { | |
321 | "Wonderful", | |
322 | "examples.", | |
323 | }; | |
324 | ||
47908e25 | 325 | panel = new wxPanel(m_notebook); |
f96aa4d9 | 326 | panel->SetBackgroundColour("cadet blue"); |
e5403d7c RR |
327 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_HORIZONTAL ); |
328 | m_radio->SetBackgroundColour("wheat"); | |
329 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_VERTICAL ); | |
a81258be | 330 | m_radio->SetBackgroundColour("wheat"); |
d3904ceb RR |
331 | (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
332 | (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); | |
333 | (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(180,130), wxSize(140,30) ); | |
e5403d7c | 334 | (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); |
d3904ceb | 335 | m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(160,30) ); |
2cb21a45 | 336 | m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); |
c67d8618 RR |
337 | |
338 | panel = new wxPanel(m_notebook); | |
339 | panel->SetBackgroundColour("cadet blue"); | |
340 | (void)new wxStaticBox( panel, -1, "StaticBox", wxPoint(10,10), wxSize(160,130) ); | |
341 | m_notebook->AddPage(panel, "wxStaticBox", FALSE, Image_Static); | |
1c005ff7 RR |
342 | } |
343 | ||
344 | void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) | |
345 | { | |
346 | int x = 0; | |
347 | int y = 0; | |
348 | GetClientSize( &x, &y ); | |
349 | ||
2f6407b9 RR |
350 | if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 ); |
351 | if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 ); | |
1c005ff7 RR |
352 | } |
353 | ||
cb43b372 RR |
354 | void MyPanel::OnPageChanged( wxNotebookEvent &event ) |
355 | { | |
356 | *m_text << "Notebook selection is " << event.GetSelection() << "\n"; | |
357 | } | |
358 | ||
1c005ff7 RR |
359 | void MyPanel::OnListBox( wxCommandEvent &event ) |
360 | { | |
1c005ff7 RR |
361 | m_text->WriteText( "ListBox selection string is: " ); |
362 | m_text->WriteText( event.GetString() ); | |
363 | m_text->WriteText( "\n" ); | |
364 | } | |
365 | ||
47908e25 RR |
366 | void MyPanel::OnListBoxButtons( wxCommandEvent &event ) |
367 | { | |
368 | switch (event.GetId()) | |
369 | { | |
d3904ceb RR |
370 | case ID_LISTBOX_ENABLE: |
371 | { | |
372 | m_listbox->Enable( !((bool)event.GetInt()) ); | |
373 | break; | |
374 | } | |
47908e25 RR |
375 | case ID_LISTBOX_SEL_NUM: |
376 | { | |
377 | m_listbox->SetSelection( 2 ); | |
378 | break; | |
379 | } | |
380 | case ID_LISTBOX_SEL_STR: | |
381 | { | |
382 | m_listbox->SetStringSelection( "This" ); | |
383 | break; | |
384 | } | |
385 | case ID_LISTBOX_CLEAR: | |
386 | { | |
387 | m_listbox->Clear(); | |
388 | break; | |
389 | } | |
390 | case ID_LISTBOX_APPEND: | |
391 | { | |
392 | m_listbox->Append( "Hi!" ); | |
393 | break; | |
394 | } | |
30f82ea4 RR |
395 | case ID_LISTBOX_DELETE: |
396 | { | |
397 | int idx = m_listbox->GetSelection(); | |
398 | m_listbox->Delete( idx ); | |
399 | break; | |
400 | } | |
868a2826 RR |
401 | case ID_LISTBOX_FONT: |
402 | { | |
403 | m_listbox->SetFont( *wxITALIC_FONT ); | |
404 | break; | |
405 | } | |
47908e25 RR |
406 | } |
407 | } | |
408 | ||
409 | void MyPanel::OnChoice( wxCommandEvent &event ) | |
410 | { | |
411 | m_text->WriteText( "Choice selection string is: " ); | |
412 | m_text->WriteText( event.GetString() ); | |
413 | m_text->WriteText( "\n" ); | |
414 | } | |
415 | ||
416 | void MyPanel::OnChoiceButtons( wxCommandEvent &event ) | |
417 | { | |
418 | switch (event.GetId()) | |
419 | { | |
d3904ceb RR |
420 | case ID_CHOICE_ENABLE: |
421 | { | |
422 | m_choice->Enable( !((bool)event.GetInt()) ); | |
423 | break; | |
424 | } | |
47908e25 RR |
425 | case ID_CHOICE_SEL_NUM: |
426 | { | |
427 | m_choice->SetSelection( 2 ); | |
428 | break; | |
429 | } | |
430 | case ID_CHOICE_SEL_STR: | |
431 | { | |
432 | m_choice->SetStringSelection( "This" ); | |
433 | break; | |
434 | } | |
435 | case ID_CHOICE_CLEAR: | |
436 | { | |
437 | m_choice->Clear(); | |
438 | break; | |
439 | } | |
440 | case ID_CHOICE_APPEND: | |
441 | { | |
442 | m_choice->Append( "Hi!" ); | |
443 | break; | |
444 | } | |
2f6407b9 RR |
445 | case ID_CHOICE_DELETE: |
446 | { | |
447 | int idx = m_choice->GetSelection(); | |
448 | m_choice->Delete( idx ); | |
449 | break; | |
450 | } | |
868a2826 RR |
451 | case ID_CHOICE_FONT: |
452 | { | |
453 | m_choice->SetFont( *wxITALIC_FONT ); | |
454 | break; | |
455 | } | |
47908e25 RR |
456 | } |
457 | } | |
458 | ||
459 | void MyPanel::OnCombo( wxCommandEvent &event ) | |
460 | { | |
461 | m_text->WriteText( "ComboBox selection string is: " ); | |
462 | m_text->WriteText( event.GetString() ); | |
463 | m_text->WriteText( "\n" ); | |
464 | } | |
465 | ||
466 | void MyPanel::OnComboButtons( wxCommandEvent &event ) | |
1c005ff7 | 467 | { |
47908e25 RR |
468 | switch (event.GetId()) |
469 | { | |
d3904ceb RR |
470 | case ID_COMBO_ENABLE: |
471 | { | |
472 | m_combo->Enable( !((bool)event.GetInt()) ); | |
473 | break; | |
474 | } | |
47908e25 RR |
475 | case ID_COMBO_SEL_NUM: |
476 | { | |
477 | m_combo->SetSelection( 2 ); | |
478 | break; | |
479 | } | |
480 | case ID_COMBO_SEL_STR: | |
481 | { | |
482 | m_combo->SetStringSelection( "This" ); | |
483 | break; | |
484 | } | |
485 | case ID_COMBO_CLEAR: | |
486 | { | |
487 | m_combo->Clear(); | |
488 | break; | |
489 | } | |
490 | case ID_COMBO_APPEND: | |
491 | { | |
492 | m_combo->Append( "Hi!" ); | |
493 | break; | |
494 | } | |
2f6407b9 RR |
495 | case ID_COMBO_DELETE: |
496 | { | |
497 | int idx = m_combo->GetSelection(); | |
498 | m_combo->Delete( idx ); | |
499 | break; | |
500 | } | |
868a2826 RR |
501 | case ID_COMBO_FONT: |
502 | { | |
503 | m_combo->SetFont( *wxITALIC_FONT ); | |
504 | break; | |
505 | } | |
47908e25 RR |
506 | } |
507 | } | |
508 | ||
509 | void MyPanel::OnRadio( wxCommandEvent &event ) | |
510 | { | |
511 | m_text->WriteText( "RadioBox selection string is: " ); | |
512 | m_text->WriteText( event.GetString() ); | |
513 | m_text->WriteText( "\n" ); | |
514 | } | |
515 | ||
516 | void MyPanel::OnRadioButtons( wxCommandEvent &event ) | |
517 | { | |
518 | switch (event.GetId()) | |
519 | { | |
d3904ceb RR |
520 | case ID_RADIOBOX_ENABLE: |
521 | { | |
522 | m_radio->Enable( !((bool)event.GetInt()) ); | |
523 | break; | |
524 | } | |
47908e25 RR |
525 | case ID_RADIOBOX_SEL_NUM: |
526 | { | |
527 | m_radio->SetSelection( 2 ); | |
528 | break; | |
529 | } | |
530 | case ID_RADIOBOX_SEL_STR: | |
531 | { | |
532 | m_radio->SetStringSelection( "This" ); | |
533 | break; | |
534 | } | |
868a2826 RR |
535 | case ID_RADIOBOX_FONT: |
536 | { | |
537 | m_radio->SetFont( *wxITALIC_FONT ); | |
538 | break; | |
539 | } | |
47908e25 | 540 | } |
1c005ff7 RR |
541 | } |
542 | ||
868a2826 RR |
543 | void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) ) |
544 | { | |
545 | m_fontButton->SetFont( *wxITALIC_FONT ); | |
546 | m_text->SetFont( *wxITALIC_FONT ); | |
547 | } | |
548 | ||
2cb21a45 VZ |
549 | MyPanel::~MyPanel() |
550 | { | |
551 | delete m_notebook->GetImageList(); | |
552 | } | |
553 | ||
1c005ff7 RR |
554 | //---------------------------------------------------------------------- |
555 | // MyFrame | |
556 | //---------------------------------------------------------------------- | |
557 | ||
558 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
559 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) | |
560 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
561 | END_EVENT_TABLE() | |
562 | ||
563 | MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): | |
564 | wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
565 | { | |
654c1d6b | 566 | (void)new MyPanel( this, 10, 10, 300, 100 ); |
1c005ff7 RR |
567 | } |
568 | ||
569 | void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) ) | |
570 | { | |
571 | Close(TRUE); | |
572 | } | |
573 | ||
574 | void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) | |
575 | { | |
576 | wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK ); | |
577 | dialog.ShowModal(); | |
578 | } |