]>
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 |
655822f3 | 8 | // Licence: wxWindows license |
1c005ff7 RR |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifdef __GNUG__ | |
9f3362c4 | 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__ | |
9f3362c4 | 19 | #pragma hdrstop |
1c005ff7 RR |
20 | #endif |
21 | ||
22 | #ifndef WX_PRECOMP | |
9f3362c4 | 23 | #include "wx/wx.h" |
1c005ff7 RR |
24 | #endif |
25 | ||
3372145d | 26 | #if !defined( __WXMSW__ ) || defined( __WIN95__ ) |
4fabb575 | 27 | #include "wx/spinbutt.h" |
3372145d | 28 | #endif |
53b28675 | 29 | #include "wx/notebook.h" |
2cb21a45 | 30 | #include "wx/imaglist.h" |
b8653fbf VZ |
31 | |
32 | #if wxUSE_TOOLTIPS | |
33 | #include "wx/tooltip.h" | |
34 | #endif | |
1c005ff7 | 35 | |
4b5f3fe6 | 36 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
73c700fd | 37 | #define USE_XPM |
4fabb575 JS |
38 | #endif |
39 | ||
40 | #ifdef USE_XPM | |
73c700fd VZ |
41 | #include "mondrian.xpm" |
42 | #include "icons/choice.xpm" | |
43 | #include "icons/combo.xpm" | |
44 | #include "icons/list.xpm" | |
45 | #include "icons/radio.xpm" | |
46 | #include "icons/text.xpm" | |
47 | #include "icons/gauge.xpm" | |
47908e25 RR |
48 | #endif |
49 | ||
9726da4f VZ |
50 | #ifdef __WIN16__ |
51 | // Win16 doesn't have them | |
ad556aa9 | 52 | #ifdef wxUSE_SPINBTN |
0e528b99 | 53 | #undef wxUSE_SPINBTN |
ad556aa9 | 54 | #endif |
0e528b99 | 55 | #define wxUSE_SPINBTN 0 |
b782f2e0 | 56 | #else |
ad556aa9 JS |
57 | #ifndef wxUSE_SPINBTN |
58 | #define wxUSE_SPINBTN 1 | |
b782f2e0 | 59 | #endif |
9726da4f VZ |
60 | #endif // __WIN16__ |
61 | ||
62 | #include "wx/progdlg.h" | |
63 | ||
b782f2e0 | 64 | // VZ: this is a temp. hack, will remove soon |
0e528b99 | 65 | #ifndef wxUSE_SPINCTRL |
b782f2e0 | 66 | #define wxUSE_SPINCTRL 1 |
0e528b99 | 67 | #endif |
b782f2e0 VZ |
68 | |
69 | #if wxUSE_SPINCTRL | |
70 | #include "wx/spinctrl.h" | |
71 | #endif // wxUSE_SPINCTRL | |
72 | ||
1c005ff7 RR |
73 | //---------------------------------------------------------------------- |
74 | // class definitions | |
75 | //---------------------------------------------------------------------- | |
76 | ||
77 | class MyApp: public wxApp | |
655822f3 | 78 | { |
b8653fbf VZ |
79 | public: |
80 | bool OnInit(); | |
1c005ff7 RR |
81 | }; |
82 | ||
83 | class MyPanel: public wxPanel | |
84 | { | |
b8653fbf | 85 | public: |
1c005ff7 | 86 | MyPanel(wxFrame *frame, int x, int y, int w, int h); |
2cb21a45 | 87 | virtual ~MyPanel(); |
16f6dfd8 | 88 | |
1c005ff7 RR |
89 | void OnSize( wxSizeEvent& event ); |
90 | void OnListBox( wxCommandEvent &event ); | |
5b077d48 | 91 | void OnListBoxDoubleClick( wxCommandEvent &event ); |
1c005ff7 | 92 | void OnListBoxButtons( wxCommandEvent &event ); |
47908e25 RR |
93 | void OnChoice( wxCommandEvent &event ); |
94 | void OnChoiceButtons( wxCommandEvent &event ); | |
95 | void OnCombo( wxCommandEvent &event ); | |
96 | void OnComboButtons( wxCommandEvent &event ); | |
97 | void OnRadio( wxCommandEvent &event ); | |
98 | void OnRadioButtons( wxCommandEvent &event ); | |
868a2826 | 99 | void OnSetFont( wxCommandEvent &event ); |
cb43b372 | 100 | void OnPageChanged( wxNotebookEvent &event ); |
4d0f3cd6 | 101 | void OnPageChanging( wxNotebookEvent &event ); |
7bce6aec | 102 | void OnSliderUpdate( wxCommandEvent &event ); |
185fa6bf | 103 | void OnUpdateLabel( wxCommandEvent &event ); |
0e528b99 | 104 | #if wxUSE_SPINBTN |
8c3c31d4 VZ |
105 | void OnSpinUp( wxSpinEvent &event ); |
106 | void OnSpinDown( wxSpinEvent &event ); | |
e380f72b | 107 | void OnSpinUpdate( wxSpinEvent &event ); |
9726da4f VZ |
108 | void OnUpdateShowProgress( wxUpdateUIEvent& event ); |
109 | void OnShowProgress( wxCommandEvent &event ); | |
0e528b99 | 110 | #endif // wxUSE_SPINBTN |
16f6dfd8 | 111 | |
baccb514 VZ |
112 | #if wxUSE_SPINCTRL |
113 | void OnSpinCtrl(wxSpinEvent& event); | |
114 | #endif // wxUSE_SPINCTRL | |
115 | ||
87a1e308 VZ |
116 | void OnEnableAll(wxCommandEvent& event); |
117 | void OnChangeColour(wxCommandEvent& event); | |
118 | ||
6c8a980f VZ |
119 | wxListBox *m_listbox, |
120 | *m_listboxSorted; | |
b56c2246 VZ |
121 | wxChoice *m_choice, |
122 | *m_choiceSorted; | |
e380f72b RR |
123 | wxComboBox *m_combo; |
124 | wxRadioBox *m_radio; | |
125 | wxGauge *m_gauge; | |
126 | wxSlider *m_slider; | |
127 | wxButton *m_fontButton; | |
85eb36c2 RR |
128 | wxButton *m_lbSelectNum; |
129 | wxButton *m_lbSelectThis; | |
0e528b99 | 130 | #if wxUSE_SPINBTN |
e380f72b | 131 | wxSpinButton *m_spinbutton; |
9726da4f | 132 | wxButton *m_btnProgress; |
0e528b99 | 133 | #endif // wxUSE_SPINBTN |
b782f2e0 VZ |
134 | |
135 | #if wxUSE_SPINCTRL | |
136 | wxSpinCtrl *m_spinctrl; | |
137 | #endif // wxUSE_SPINCTRL | |
138 | ||
e380f72b | 139 | wxTextCtrl *m_spintext; |
ae0bdb01 | 140 | wxCheckBox *m_checkbox; |
16f6dfd8 | 141 | |
e380f72b | 142 | wxTextCtrl *m_text; |
655822f3 VZ |
143 | wxNotebook *m_notebook; |
144 | ||
185fa6bf VZ |
145 | wxStaticText *m_label; |
146 | ||
b8653fbf VZ |
147 | private: |
148 | DECLARE_EVENT_TABLE() | |
1c005ff7 RR |
149 | }; |
150 | ||
151 | class MyFrame: public wxFrame | |
152 | { | |
b8653fbf | 153 | public: |
1c005ff7 | 154 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); |
655822f3 | 155 | |
1c005ff7 RR |
156 | void OnQuit(wxCommandEvent& event); |
157 | void OnAbout(wxCommandEvent& event); | |
87a1e308 | 158 | |
16f6dfd8 VZ |
159 | #if wxUSE_TOOLTIPS |
160 | void OnSetTooltipDelay(wxCommandEvent& event); | |
161 | void OnToggleTooltips(wxCommandEvent& event); | |
162 | #endif // wxUSE_TOOLTIPS | |
87a1e308 VZ |
163 | |
164 | void OnEnableAll(wxCommandEvent& event); | |
165 | ||
9f3362c4 | 166 | void OnIdle( wxIdleEvent& event ); |
5fb9fcfc | 167 | void OnSize( wxSizeEvent& event ); |
97206645 | 168 | void OnMove( wxMoveEvent& event ); |
655822f3 | 169 | |
b8653fbf | 170 | private: |
97206645 VZ |
171 | void UpdateStatusBar(const wxPoint& pos, const wxSize& size) |
172 | { | |
173 | wxString msg; | |
174 | msg.Printf(_("pos=(%d, %d), size=%dx%d"), | |
175 | pos.x, pos.y, size.x, size.y); | |
176 | SetStatusText(msg, 1); | |
177 | } | |
178 | ||
87a1e308 VZ |
179 | wxPanel *m_panel; |
180 | ||
b8653fbf | 181 | DECLARE_EVENT_TABLE() |
1c005ff7 RR |
182 | }; |
183 | ||
184 | //---------------------------------------------------------------------- | |
6c8a980f | 185 | // other |
1c005ff7 RR |
186 | //---------------------------------------------------------------------- |
187 | ||
6c8a980f VZ |
188 | static void SetControlClientData(const char *name, |
189 | wxControlWithItems *control); | |
190 | ||
d59051dd | 191 | IMPLEMENT_APP(MyApp) |
1c005ff7 RR |
192 | |
193 | //---------------------------------------------------------------------- | |
194 | // MyApp | |
195 | //---------------------------------------------------------------------- | |
196 | ||
16f6dfd8 VZ |
197 | enum |
198 | { | |
199 | MINIMAL_QUIT = 100, | |
200 | MINIMAL_TEXT, | |
201 | MINIMAL_ABOUT, | |
202 | ||
203 | // tooltip menu | |
204 | MINIMAL_SET_TOOLTIP_DELAY = 200, | |
87a1e308 VZ |
205 | MINIMAL_ENABLE_TOOLTIPS, |
206 | ||
207 | // panel menu | |
208 | MINIMAL_ENABLE_ALL | |
16f6dfd8 | 209 | }; |
1c005ff7 | 210 | |
b8653fbf | 211 | bool MyApp::OnInit() |
1c005ff7 | 212 | { |
ec9f7884 VZ |
213 | // Create the main frame window |
214 | MyFrame *frame = new MyFrame((wxFrame *) NULL, | |
215 | "Controls wxWindows App", | |
216 | 50, 50, 530, 420); | |
655822f3 | 217 | |
ec9f7884 VZ |
218 | // Give it an icon |
219 | // The wxICON() macros loads an icon from a resource under Windows | |
220 | // and uses an #included XPM image under GTK+ and Motif | |
655822f3 | 221 | |
ec9f7884 | 222 | frame->SetIcon( wxICON(mondrian) ); |
1c005ff7 | 223 | |
934e1eda | 224 | wxMenu *file_menu = new wxMenu("", wxMENU_TEAROFF ); |
6bc8a1c8 | 225 | file_menu->Append(MINIMAL_ABOUT, "&About\tF1"); |
87a1e308 | 226 | file_menu->AppendSeparator(); |
6bc8a1c8 | 227 | file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample"); |
16f6dfd8 | 228 | |
33caefb3 | 229 | wxMenuBar *menu_bar = new wxMenuBar; |
ec9f7884 | 230 | menu_bar->Append(file_menu, "&File"); |
16f6dfd8 VZ |
231 | |
232 | #if wxUSE_TOOLTIPS | |
ec9f7884 | 233 | wxMenu *tooltip_menu = new wxMenu; |
6bc8a1c8 | 234 | tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D"); |
ec9f7884 | 235 | tooltip_menu->AppendSeparator(); |
185fa6bf | 236 | tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T", |
ec9f7884 VZ |
237 | "enable/disable tooltips", TRUE); |
238 | tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE); | |
239 | menu_bar->Append(tooltip_menu, "&Tooltips"); | |
16f6dfd8 VZ |
240 | #endif // wxUSE_TOOLTIPS |
241 | ||
87a1e308 VZ |
242 | wxMenu *panel_menu = new wxMenu; |
243 | panel_menu->Append(MINIMAL_ENABLE_ALL, "&Disable all\tCtrl-E", | |
244 | "Enable/disable all panel controls", TRUE); | |
245 | menu_bar->Append(panel_menu, "&Panel"); | |
246 | ||
ec9f7884 | 247 | frame->SetMenuBar(menu_bar); |
1c005ff7 | 248 | |
ec9f7884 | 249 | frame->Show(TRUE); |
9018abe3 | 250 | frame->SetCursor(wxCursor(wxCURSOR_HAND)); |
655822f3 | 251 | |
ec9f7884 | 252 | SetTopWindow(frame); |
1c005ff7 | 253 | |
ec9f7884 | 254 | return TRUE; |
1c005ff7 RR |
255 | } |
256 | ||
257 | //---------------------------------------------------------------------- | |
258 | // MyPanel | |
259 | //---------------------------------------------------------------------- | |
260 | ||
4fabb575 | 261 | const int ID_NOTEBOOK = 1000; |
1c005ff7 | 262 | |
4fabb575 JS |
263 | const int ID_LISTBOX = 130; |
264 | const int ID_LISTBOX_SEL_NUM = 131; | |
265 | const int ID_LISTBOX_SEL_STR = 132; | |
266 | const int ID_LISTBOX_CLEAR = 133; | |
267 | const int ID_LISTBOX_APPEND = 134; | |
268 | const int ID_LISTBOX_DELETE = 135; | |
269 | const int ID_LISTBOX_FONT = 136; | |
270 | const int ID_LISTBOX_ENABLE = 137; | |
6c8a980f | 271 | const int ID_LISTBOX_SORTED = 138; |
1c005ff7 | 272 | |
4fabb575 JS |
273 | const int ID_CHOICE = 120; |
274 | const int ID_CHOICE_SEL_NUM = 121; | |
275 | const int ID_CHOICE_SEL_STR = 122; | |
276 | const int ID_CHOICE_CLEAR = 123; | |
277 | const int ID_CHOICE_APPEND = 124; | |
278 | const int ID_CHOICE_DELETE = 125; | |
279 | const int ID_CHOICE_FONT = 126; | |
280 | const int ID_CHOICE_ENABLE = 127; | |
b56c2246 | 281 | const int ID_CHOICE_SORTED = 128; |
53010e52 | 282 | |
4fabb575 JS |
283 | const int ID_COMBO = 140; |
284 | const int ID_COMBO_SEL_NUM = 141; | |
285 | const int ID_COMBO_SEL_STR = 142; | |
286 | const int ID_COMBO_CLEAR = 143; | |
287 | const int ID_COMBO_APPEND = 144; | |
288 | const int ID_COMBO_DELETE = 145; | |
289 | const int ID_COMBO_FONT = 146; | |
290 | const int ID_COMBO_ENABLE = 147; | |
53010e52 | 291 | |
4fabb575 JS |
292 | const int ID_RADIOBOX = 160; |
293 | const int ID_RADIOBOX_SEL_NUM = 161; | |
294 | const int ID_RADIOBOX_SEL_STR = 162; | |
295 | const int ID_RADIOBOX_FONT = 163; | |
296 | const int ID_RADIOBOX_ENABLE = 164; | |
868a2826 | 297 | |
f5d29b39 RR |
298 | const int ID_RADIOBUTTON_1 = 166; |
299 | const int ID_RADIOBUTTON_2 = 167; | |
300 | ||
4fabb575 | 301 | const int ID_SET_FONT = 170; |
47908e25 | 302 | |
4fabb575 JS |
303 | const int ID_GAUGE = 180; |
304 | const int ID_SLIDER = 181; | |
58614078 | 305 | |
4fabb575 | 306 | const int ID_SPIN = 182; |
9726da4f | 307 | const int ID_BTNPROGRESS = 183; |
185fa6bf | 308 | const int ID_BUTTON_LABEL = 184; |
baccb514 | 309 | const int ID_SPINCTRL = 185; |
e380f72b | 310 | |
87a1e308 VZ |
311 | const int ID_CHANGE_COLOUR = 200; |
312 | ||
1c005ff7 | 313 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
ec9f7884 | 314 | EVT_SIZE ( MyPanel::OnSize) |
4d0f3cd6 | 315 | EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging) |
ec9f7884 VZ |
316 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged) |
317 | EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) | |
6c8a980f | 318 | EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox) |
ec9f7884 VZ |
319 | EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick) |
320 | EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons) | |
321 | EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons) | |
322 | EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons) | |
323 | EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons) | |
324 | EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons) | |
325 | EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons) | |
326 | EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons) | |
327 | EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice) | |
b56c2246 | 328 | EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice) |
ec9f7884 VZ |
329 | EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons) |
330 | EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons) | |
331 | EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons) | |
332 | EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons) | |
333 | EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons) | |
334 | EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons) | |
335 | EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons) | |
336 | EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo) | |
337 | EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons) | |
338 | EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons) | |
339 | EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons) | |
340 | EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons) | |
341 | EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons) | |
342 | EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons) | |
343 | EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons) | |
344 | EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio) | |
345 | EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons) | |
346 | EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons) | |
347 | EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons) | |
348 | EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons) | |
349 | EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) | |
350 | EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) | |
0e528b99 | 351 | #if wxUSE_SPINBTN |
ec9f7884 | 352 | EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) |
8c3c31d4 VZ |
353 | EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp) |
354 | EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown) | |
9726da4f VZ |
355 | EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress) |
356 | EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress) | |
0e528b99 | 357 | #endif // wxUSE_SPINBTN |
baccb514 VZ |
358 | #if wxUSE_SPINCTRL |
359 | EVT_SPIN (ID_SPINCTRL, MyPanel::OnSpinCtrl) | |
360 | #endif // wxUSE_SPINCTRL | |
185fa6bf | 361 | EVT_BUTTON (ID_BUTTON_LABEL, MyPanel::OnUpdateLabel) |
87a1e308 | 362 | EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour) |
1c005ff7 RR |
363 | END_EVENT_TABLE() |
364 | ||
5fb9fcfc | 365 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) |
0a772322 VZ |
366 | : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ), |
367 | m_text(NULL), m_notebook(NULL) | |
1c005ff7 | 368 | { |
ec9f7884 VZ |
369 | m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); |
370 | // m_text->SetBackgroundColour("wheat"); | |
655822f3 | 371 | |
4d0f3cd6 | 372 | delete wxLog::SetActiveTarget(new wxLogStderr); |
0a772322 | 373 | |
ec9f7884 | 374 | m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) ); |
655822f3 | 375 | |
ec9f7884 VZ |
376 | wxString choices[] = |
377 | { | |
378 | "This", | |
379 | "is one of my", | |
380 | "really", | |
381 | "wonderful", | |
382 | "examples." | |
383 | }; | |
655822f3 | 384 | |
4fabb575 | 385 | #ifdef USE_XPM |
ec9f7884 VZ |
386 | // image ids |
387 | enum | |
388 | { | |
389 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max | |
390 | }; | |
391 | ||
392 | // fill the image list | |
393 | wxImageList *imagelist = new wxImageList(32, 32); | |
394 | ||
395 | imagelist-> Add( wxBitmap( list_xpm )); | |
396 | imagelist-> Add( wxBitmap( choice_xpm )); | |
397 | imagelist-> Add( wxBitmap( combo_xpm )); | |
398 | imagelist-> Add( wxBitmap( text_xpm )); | |
399 | imagelist-> Add( wxBitmap( radio_xpm )); | |
400 | imagelist-> Add( wxBitmap( gauge_xpm )); | |
401 | m_notebook->SetImageList(imagelist); | |
73c700fd | 402 | #elif defined(__WXMSW__) |
ec9f7884 VZ |
403 | // load images from resources |
404 | enum | |
405 | { | |
406 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max | |
407 | }; | |
408 | wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max); | |
409 | ||
410 | static const char *s_iconNames[Image_Max] = | |
411 | { | |
412 | "list", "choice", "combo", "text", "radio", "gauge" | |
413 | }; | |
414 | ||
415 | for ( size_t n = 0; n < Image_Max; n++ ) | |
416 | { | |
417 | wxBitmap bmp(s_iconNames[n]); | |
418 | if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) ) | |
419 | { | |
420 | wxLogWarning("Couldn't load the image '%s' for the notebook page %d.", | |
421 | s_iconNames[n], n); | |
422 | } | |
423 | } | |
424 | ||
425 | m_notebook->SetImageList(imagelist); | |
4fabb575 JS |
426 | #else |
427 | ||
ec9f7884 | 428 | // No images for now |
4fabb575 JS |
429 | #define Image_List -1 |
430 | #define Image_Choice -1 | |
431 | #define Image_Combo -1 | |
432 | #define Image_Text -1 | |
433 | #define Image_Radio -1 | |
434 | #define Image_Gauge -1 | |
435 | #define Image_Max -1 | |
436 | ||
fc54776e | 437 | #endif |
2cb21a45 | 438 | |
6c8a980f VZ |
439 | wxPanel *panel = new wxPanel(m_notebook); |
440 | m_listbox = new wxListBox( panel, ID_LISTBOX, | |
441 | wxPoint(10,10), wxSize(120,70), | |
354aa1e3 | 442 | 5, choices, wxLB_ALWAYS_SB ); |
6c8a980f VZ |
443 | m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED, |
444 | wxPoint(10,90), wxSize(120,70), | |
354aa1e3 | 445 | 5, choices, wxLB_SORT ); |
6c8a980f VZ |
446 | |
447 | SetControlClientData("listbox", m_listbox); | |
448 | SetControlClientData("listbox", m_listboxSorted); | |
9838df2c | 449 | |
ec9f7884 | 450 | m_listbox->SetCursor(*wxCROSS_CURSOR); |
b8653fbf | 451 | #if wxUSE_TOOLTIPS |
ec9f7884 | 452 | m_listbox->SetToolTip( "This is a list box" ); |
16f6dfd8 | 453 | #endif // wxUSE_TOOLTIPS |
9f3362c4 | 454 | |
85eb36c2 RR |
455 | m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
456 | m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
ec9f7884 VZ |
457 | (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); |
458 | (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
459 | (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
6c8a980f | 460 | wxButton *button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) ); |
b8653fbf | 461 | #if wxUSE_TOOLTIPS |
ec9f7884 | 462 | button->SetToolTip( "Press here to set italic font" ); |
16f6dfd8 | 463 | #endif // wxUSE_TOOLTIPS |
b1170810 | 464 | |
6c8a980f | 465 | m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,170) ); |
ec9f7884 | 466 | m_checkbox->SetValue(FALSE); |
b8653fbf | 467 | #if wxUSE_TOOLTIPS |
ec9f7884 | 468 | m_checkbox->SetToolTip( "Click here to disable the listbox" ); |
16f6dfd8 | 469 | #endif // wxUSE_TOOLTIPS |
87a1e308 VZ |
470 | (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, "&Toggle colour", |
471 | wxPoint(110,170) ); | |
ec9f7884 VZ |
472 | m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List); |
473 | ||
474 | panel = new wxPanel(m_notebook); | |
475 | m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices ); | |
b56c2246 VZ |
476 | m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1), |
477 | 5, choices, wxCB_SORT ); | |
6c8a980f VZ |
478 | |
479 | SetControlClientData("choice", m_choice); | |
480 | SetControlClientData("choice", m_choiceSorted); | |
481 | ||
ddc8c2e3 | 482 | m_choice->SetSelection(2); |
2b07d713 | 483 | m_choice->SetBackgroundColour( "red" ); |
ec9f7884 VZ |
484 | (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
485 | (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
486 | (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
487 | (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
488 | (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
489 | (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
490 | (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
1fad4c3e | 491 | |
ec9f7884 VZ |
492 | m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); |
493 | ||
494 | panel = new wxPanel(m_notebook); | |
a260fe6a | 495 | m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices, wxCB_READONLY ); |
ec9f7884 VZ |
496 | (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
497 | (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
498 | (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
499 | (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
500 | (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
501 | (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
502 | (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
503 | m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo); | |
504 | ||
ec9f7884 VZ |
505 | wxString choices2[] = |
506 | { | |
17867d61 | 507 | "First", "Second", |
0a772322 | 508 | /* "Third", |
17867d61 RR |
509 | "Fourth", "Fifth", "Sixth", |
510 | "Seventh", "Eighth", "Nineth", "Tenth" */ | |
ec9f7884 VZ |
511 | }; |
512 | ||
513 | panel = new wxPanel(m_notebook); | |
9018abe3 VZ |
514 | (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS ); |
515 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS ); | |
ec9f7884 VZ |
516 | (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
517 | (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); | |
518 | m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) ); | |
519 | (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) ); | |
520 | (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); | |
0544bc0a | 521 | wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP ); |
ec9f7884 VZ |
522 | rb->SetValue( FALSE ); |
523 | (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) ); | |
524 | m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); | |
525 | ||
526 | panel = new wxPanel(m_notebook); | |
33961d59 | 527 | (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) ); |
ec9f7884 | 528 | m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) ); |
858b5bdd | 529 | m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS ); |
33961d59 | 530 | (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(220,10), wxSize(270,130) ); |
9838df2c | 531 | #ifdef __WXMOTIF__ |
ec9f7884 VZ |
532 | // No wrapping text in wxStaticText yet :-( |
533 | (void)new wxStaticText( panel, -1, | |
534 | "Drag the slider!", | |
33961d59 | 535 | wxPoint(228,30), |
e65cc56a | 536 | wxSize(240, -1) |
ec9f7884 | 537 | ); |
9838df2c | 538 | #else |
ec9f7884 VZ |
539 | (void)new wxStaticText( panel, -1, |
540 | "In order see the gauge (aka progress bar)\n" | |
541 | "control do something you have to drag the\n" | |
542 | "handle of the slider to the right.\n" | |
543 | "\n" | |
544 | "This is also supposed to demonstrate how\n" | |
545 | "to use static controls.\n", | |
8c3c31d4 VZ |
546 | wxPoint(228,25), |
547 | wxSize(240, 110) | |
ec9f7884 | 548 | ); |
9838df2c | 549 | #endif |
8c3c31d4 VZ |
550 | int initialSpinValue = -5; |
551 | wxString s; | |
552 | s << initialSpinValue; | |
553 | m_spintext = new wxTextCtrl( panel, -1, s, wxPoint(20,160), wxSize(80,-1) ); | |
0e528b99 | 554 | #if wxUSE_SPINBTN |
738f9e5a | 555 | m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, -1) ); |
6380910c | 556 | m_spinbutton->SetRange(-10,30); |
8c3c31d4 | 557 | m_spinbutton->SetValue(initialSpinValue); |
9726da4f VZ |
558 | |
559 | m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog", | |
738f9e5a | 560 | wxPoint(300, 160) ); |
0e528b99 | 561 | #endif // wxUSE_SPINBTN |
b782f2e0 VZ |
562 | |
563 | #if wxUSE_SPINCTRL | |
678cd6de | 564 | m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, "", wxPoint(200, 160), wxSize(80, -1) ); |
b782f2e0 VZ |
565 | m_spinctrl->SetRange(10,30); |
566 | m_spinctrl->SetValue(15); | |
567 | #endif // wxUSE_SPINCTRL | |
568 | ||
ec9f7884 | 569 | m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); |
45e41c05 VZ |
570 | |
571 | panel = new wxPanel(m_notebook); | |
b782f2e0 | 572 | |
556921dc | 573 | #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB |
45e41c05 VZ |
574 | wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION); |
575 | wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon, wxPoint(10, 10)); | |
576 | ||
577 | bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10)); | |
578 | bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION)); | |
b782f2e0 VZ |
579 | #endif // !Motif |
580 | ||
45e41c05 VZ |
581 | wxBitmap bitmap( 100, 100 ); |
582 | wxMemoryDC dc; | |
583 | dc.SelectObject( bitmap ); | |
584 | dc.SetPen(*wxGREEN_PEN); | |
585 | dc.DrawEllipse(5, 5, 90, 90); | |
586 | dc.DrawText("Bitmap", 20, 20); | |
587 | dc.SelectObject( wxNullBitmap ); | |
588 | ||
185fa6bf VZ |
589 | (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20)); |
590 | (void)new wxButton(panel, ID_BUTTON_LABEL, "Toggle label", wxPoint(250, 20)); | |
591 | m_label = new wxStaticText(panel, -1, "Label with some long text", | |
592 | wxPoint(250, 60), wxDefaultSize, | |
593 | wxALIGN_RIGHT | wxST_NO_AUTORESIZE); | |
2ac1b69a | 594 | |
45e41c05 | 595 | m_notebook->AddPage(panel, "wxBitmapXXX"); |
dcc71398 RD |
596 | |
597 | // --------------- TEST CODE ---------------------- | |
598 | ||
d7928388 RR |
599 | // layout constraints |
600 | ||
dcc71398 | 601 | panel = new wxPanel(m_notebook); |
11e1c70d | 602 | panel->SetAutoLayout( TRUE ); |
dcc71398 RD |
603 | |
604 | wxLayoutConstraints *c; | |
605 | c = new wxLayoutConstraints; | |
606 | c->top.SameAs( panel, wxTop, 10 ); | |
607 | c->height.AsIs( ); | |
608 | c->left.SameAs( panel, wxLeft, 10 ); | |
609 | c->width.PercentOf( panel, wxWidth, 40 ); | |
610 | ||
611 | wxButton *pMyButton = new wxButton(panel, -1, "Test Button" ); | |
612 | pMyButton->SetConstraints( c ); | |
613 | ||
614 | c = new wxLayoutConstraints; | |
615 | c->top.SameAs( panel, wxTop, 10 ); | |
616 | c->bottom.SameAs( panel, wxBottom, 10 ); | |
617 | c->right.SameAs( panel, wxRight, 10 ); | |
618 | c->width.PercentOf( panel, wxWidth, 40 ); | |
619 | ||
620 | wxButton *pMyButton2 = new wxButton(panel, -1, "Test Button 2" ); | |
621 | pMyButton2->SetConstraints( c ); | |
622 | ||
d7928388 RR |
623 | m_notebook->AddPage(panel, "wxLayoutConstraint"); |
624 | ||
625 | // sizer | |
626 | ||
627 | panel = new wxPanel(m_notebook); | |
11e1c70d | 628 | panel->SetAutoLayout( TRUE ); |
d7928388 RR |
629 | |
630 | wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); | |
185fa6bf | 631 | |
d7928388 RR |
632 | sizer->Add( new wxButton(panel, -1, "Test Button" ), 3, wxALL, 10 ); |
633 | sizer->Add( 20,20, 1 ); | |
634 | sizer->Add( new wxButton(panel, -1, "Test Button 2" ), 3, wxGROW|wxALL, 10 ); | |
185fa6bf | 635 | |
d7928388 RR |
636 | panel->SetSizer( sizer ); |
637 | ||
638 | m_notebook->AddPage(panel, "wxSizer"); | |
dcc71398 RD |
639 | |
640 | // --------------- TEST CODE ---------------------- | |
641 | ||
1c005ff7 RR |
642 | } |
643 | ||
644 | void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) | |
645 | { | |
ec9f7884 VZ |
646 | int x = 0; |
647 | int y = 0; | |
648 | GetClientSize( &x, &y ); | |
655822f3 | 649 | |
ec9f7884 VZ |
650 | if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 ); |
651 | if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 ); | |
1c005ff7 RR |
652 | } |
653 | ||
4d0f3cd6 VZ |
654 | void MyPanel::OnPageChanging( wxNotebookEvent &event ) |
655 | { | |
45e41c05 VZ |
656 | int selOld = event.GetOldSelection(); |
657 | if ( selOld == 2 ) | |
4d0f3cd6 | 658 | { |
65045edd RR |
659 | if ( wxMessageBox("This demonstrates how a program may prevent the\n" |
660 | "page change from taking place - if you select\n" | |
661 | "[No] the current page will stay the third one\n", | |
8c3c31d4 VZ |
662 | "Control sample", |
663 | wxICON_QUESTION | wxYES_NO) != wxYES ) | |
664 | { | |
665 | event.Veto(); | |
45e41c05 | 666 | |
8c3c31d4 VZ |
667 | return; |
668 | } | |
4d0f3cd6 | 669 | } |
45e41c05 VZ |
670 | |
671 | *m_text << "Notebook selection is being changed from " << selOld << "\n"; | |
4d0f3cd6 VZ |
672 | } |
673 | ||
cb43b372 RR |
674 | void MyPanel::OnPageChanged( wxNotebookEvent &event ) |
675 | { | |
ec9f7884 | 676 | *m_text << "Notebook selection is " << event.GetSelection() << "\n"; |
cb43b372 RR |
677 | } |
678 | ||
87a1e308 VZ |
679 | void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event)) |
680 | { | |
681 | static wxColour s_colOld; | |
682 | ||
683 | // test panel colour changing and propagation to the subcontrols | |
684 | if ( s_colOld.Ok() ) | |
685 | { | |
686 | SetBackgroundColour(s_colOld); | |
687 | s_colOld = wxNullColour; | |
688 | ||
689 | m_lbSelectThis->SetBackgroundColour("blue"); | |
690 | } | |
691 | else | |
692 | { | |
693 | s_colOld = GetBackgroundColour(); | |
694 | SetBackgroundColour("green"); | |
695 | ||
696 | m_lbSelectThis->SetBackgroundColour("red"); | |
697 | } | |
698 | ||
699 | m_lbSelectThis->Refresh(); | |
700 | Refresh(); | |
701 | } | |
702 | ||
1c005ff7 RR |
703 | void MyPanel::OnListBox( wxCommandEvent &event ) |
704 | { | |
6c8a980f VZ |
705 | wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox |
706 | : m_listboxSorted; | |
707 | ||
708 | m_text->AppendText( "ListBox event selection string is: '" ); | |
ec9f7884 | 709 | m_text->AppendText( event.GetString() ); |
6c8a980f VZ |
710 | m_text->AppendText( "'\n" ); |
711 | m_text->AppendText( "ListBox control selection string is: '" ); | |
712 | m_text->AppendText( listbox->GetStringSelection() ); | |
713 | m_text->AppendText( "'\n" ); | |
714 | ||
715 | wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject()); | |
716 | m_text->AppendText( "ListBox event client data string is: '" ); | |
6e47faf1 JS |
717 | if (obj) // BC++ doesn't like use of '? .. : .. ' in this context |
718 | m_text->AppendText( obj->GetData() ); | |
719 | else | |
720 | m_text->AppendText( wxString("none") ); | |
721 | ||
6c8a980f VZ |
722 | m_text->AppendText( "'\n" ); |
723 | m_text->AppendText( "ListBox control client data string is: '" ); | |
724 | obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection()); | |
6e47faf1 JS |
725 | if (obj) |
726 | m_text->AppendText( obj->GetData() ); | |
727 | else | |
728 | m_text->AppendText( wxString("none") ); | |
6c8a980f | 729 | m_text->AppendText( "'\n" ); |
1c005ff7 RR |
730 | } |
731 | ||
5b077d48 RR |
732 | void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event ) |
733 | { | |
ec9f7884 VZ |
734 | m_text->AppendText( "ListBox double click string is: " ); |
735 | m_text->AppendText( event.GetString() ); | |
736 | m_text->AppendText( "\n" ); | |
5b077d48 RR |
737 | } |
738 | ||
47908e25 RR |
739 | void MyPanel::OnListBoxButtons( wxCommandEvent &event ) |
740 | { | |
ec9f7884 | 741 | switch (event.GetId()) |
d3904ceb | 742 | { |
ec9f7884 VZ |
743 | case ID_LISTBOX_ENABLE: |
744 | { | |
745 | m_text->AppendText("Checkbox clicked.\n"); | |
746 | wxCheckBox *cb = (wxCheckBox*)event.GetEventObject(); | |
b8653fbf | 747 | #if wxUSE_TOOLTIPS |
ec9f7884 VZ |
748 | if (event.GetInt()) |
749 | cb->SetToolTip( "Click to enable listbox" ); | |
750 | else | |
751 | cb->SetToolTip( "Click to disable listbox" ); | |
16f6dfd8 | 752 | #endif // wxUSE_TOOLTIPS |
ec9f7884 | 753 | m_listbox->Enable( event.GetInt() == 0 ); |
6c8a980f | 754 | m_listboxSorted->Enable( event.GetInt() == 0 ); |
ec9f7884 VZ |
755 | break; |
756 | } | |
757 | case ID_LISTBOX_SEL_NUM: | |
758 | { | |
759 | m_listbox->SetSelection( 2 ); | |
6c8a980f | 760 | m_listboxSorted->SetSelection( 2 ); |
8c3c31d4 | 761 | m_lbSelectThis->WarpPointer( 40, 14 ); |
ec9f7884 VZ |
762 | break; |
763 | } | |
764 | case ID_LISTBOX_SEL_STR: | |
765 | { | |
766 | m_listbox->SetStringSelection( "This" ); | |
6c8a980f | 767 | m_listboxSorted->SetStringSelection( "This" ); |
8c3c31d4 | 768 | m_lbSelectNum->WarpPointer( 40, 14 ); |
ec9f7884 VZ |
769 | break; |
770 | } | |
771 | case ID_LISTBOX_CLEAR: | |
772 | { | |
773 | m_listbox->Clear(); | |
6c8a980f | 774 | m_listboxSorted->Clear(); |
ec9f7884 VZ |
775 | break; |
776 | } | |
777 | case ID_LISTBOX_APPEND: | |
778 | { | |
779 | m_listbox->Append( "Hi!" ); | |
6c8a980f | 780 | m_listboxSorted->Append( "Hi!" ); |
ec9f7884 VZ |
781 | break; |
782 | } | |
783 | case ID_LISTBOX_DELETE: | |
784 | { | |
6c8a980f VZ |
785 | int idx; |
786 | idx = m_listbox->GetSelection(); | |
ec9f7884 | 787 | m_listbox->Delete( idx ); |
6c8a980f VZ |
788 | idx = m_listboxSorted->GetSelection(); |
789 | m_listboxSorted->Delete( idx ); | |
ec9f7884 VZ |
790 | break; |
791 | } | |
792 | case ID_LISTBOX_FONT: | |
793 | { | |
794 | m_listbox->SetFont( *wxITALIC_FONT ); | |
6c8a980f | 795 | m_listboxSorted->SetFont( *wxITALIC_FONT ); |
ec9f7884 VZ |
796 | m_checkbox->SetFont( *wxITALIC_FONT ); |
797 | break; | |
798 | } | |
868a2826 | 799 | } |
47908e25 RR |
800 | } |
801 | ||
802 | void MyPanel::OnChoice( wxCommandEvent &event ) | |
803 | { | |
6c8a980f VZ |
804 | wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice |
805 | : m_choiceSorted; | |
806 | ||
807 | m_text->AppendText( "Choice event selection string is: '" ); | |
ec9f7884 | 808 | m_text->AppendText( event.GetString() ); |
6c8a980f | 809 | m_text->AppendText( "'\n" ); |
b56c2246 | 810 | m_text->AppendText( "Choice control selection string is: '" ); |
6c8a980f VZ |
811 | m_text->AppendText( choice->GetStringSelection() ); |
812 | m_text->AppendText( "'\n" ); | |
813 | ||
814 | wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject()); | |
815 | m_text->AppendText( "Choice event client data string is: '" ); | |
6e47faf1 JS |
816 | |
817 | if (obj) | |
818 | m_text->AppendText( obj->GetData() ); | |
819 | else | |
820 | m_text->AppendText( wxString("none") ); | |
821 | ||
6c8a980f VZ |
822 | m_text->AppendText( "'\n" ); |
823 | m_text->AppendText( "Choice control client data string is: '" ); | |
824 | obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection()); | |
6e47faf1 JS |
825 | |
826 | if (obj) | |
827 | m_text->AppendText( obj->GetData() ); | |
828 | else | |
829 | m_text->AppendText( wxString("none") ); | |
6c8a980f | 830 | m_text->AppendText( "'\n" ); |
47908e25 RR |
831 | } |
832 | ||
833 | void MyPanel::OnChoiceButtons( wxCommandEvent &event ) | |
834 | { | |
ec9f7884 | 835 | switch (event.GetId()) |
47908e25 | 836 | { |
ec9f7884 VZ |
837 | case ID_CHOICE_ENABLE: |
838 | { | |
839 | m_choice->Enable( event.GetInt() == 0 ); | |
b56c2246 | 840 | m_choiceSorted->Enable( event.GetInt() == 0 ); |
ec9f7884 VZ |
841 | break; |
842 | } | |
843 | case ID_CHOICE_SEL_NUM: | |
844 | { | |
845 | m_choice->SetSelection( 2 ); | |
b56c2246 | 846 | m_choiceSorted->SetSelection( 2 ); |
ec9f7884 VZ |
847 | break; |
848 | } | |
849 | case ID_CHOICE_SEL_STR: | |
850 | { | |
851 | m_choice->SetStringSelection( "This" ); | |
b56c2246 | 852 | m_choiceSorted->SetStringSelection( "This" ); |
ec9f7884 VZ |
853 | break; |
854 | } | |
855 | case ID_CHOICE_CLEAR: | |
856 | { | |
857 | m_choice->Clear(); | |
b56c2246 | 858 | m_choiceSorted->Clear(); |
ec9f7884 VZ |
859 | break; |
860 | } | |
861 | case ID_CHOICE_APPEND: | |
862 | { | |
863 | m_choice->Append( "Hi!" ); | |
b56c2246 | 864 | m_choiceSorted->Append( "Hi!" ); |
ec9f7884 VZ |
865 | break; |
866 | } | |
867 | case ID_CHOICE_DELETE: | |
868 | { | |
869 | int idx = m_choice->GetSelection(); | |
870 | m_choice->Delete( idx ); | |
b56c2246 VZ |
871 | idx = m_choiceSorted->GetSelection(); |
872 | m_choiceSorted->Delete( idx ); | |
ec9f7884 VZ |
873 | break; |
874 | } | |
875 | case ID_CHOICE_FONT: | |
876 | { | |
877 | m_choice->SetFont( *wxITALIC_FONT ); | |
b56c2246 | 878 | m_choiceSorted->SetFont( *wxITALIC_FONT ); |
ec9f7884 VZ |
879 | break; |
880 | } | |
868a2826 | 881 | } |
47908e25 RR |
882 | } |
883 | ||
884 | void MyPanel::OnCombo( wxCommandEvent &event ) | |
885 | { | |
19da4326 | 886 | m_text->AppendText( "ComboBox event selection string is: " ); |
ec9f7884 VZ |
887 | m_text->AppendText( event.GetString() ); |
888 | m_text->AppendText( "\n" ); | |
19da4326 RR |
889 | m_text->AppendText( "ComboBox control selection string is: " ); |
890 | m_text->AppendText( m_combo->GetStringSelection() ); | |
891 | m_text->AppendText( "\n" ); | |
47908e25 RR |
892 | } |
893 | ||
894 | void MyPanel::OnComboButtons( wxCommandEvent &event ) | |
1c005ff7 | 895 | { |
ec9f7884 | 896 | switch (event.GetId()) |
2f6407b9 | 897 | { |
ec9f7884 VZ |
898 | case ID_COMBO_ENABLE: |
899 | { | |
900 | m_combo->Enable( event.GetInt() == 0 ); | |
901 | break; | |
902 | } | |
903 | case ID_COMBO_SEL_NUM: | |
904 | { | |
905 | m_combo->SetSelection( 2 ); | |
906 | break; | |
907 | } | |
908 | case ID_COMBO_SEL_STR: | |
909 | { | |
910 | m_combo->SetStringSelection( "This" ); | |
911 | break; | |
912 | } | |
913 | case ID_COMBO_CLEAR: | |
914 | { | |
915 | m_combo->Clear(); | |
916 | break; | |
917 | } | |
918 | case ID_COMBO_APPEND: | |
919 | { | |
920 | m_combo->Append( "Hi!" ); | |
921 | break; | |
922 | } | |
923 | case ID_COMBO_DELETE: | |
924 | { | |
925 | int idx = m_combo->GetSelection(); | |
926 | m_combo->Delete( idx ); | |
927 | break; | |
928 | } | |
929 | case ID_COMBO_FONT: | |
930 | { | |
931 | m_combo->SetFont( *wxITALIC_FONT ); | |
932 | break; | |
933 | } | |
868a2826 | 934 | } |
47908e25 RR |
935 | } |
936 | ||
937 | void MyPanel::OnRadio( wxCommandEvent &event ) | |
938 | { | |
ec9f7884 VZ |
939 | m_text->AppendText( "RadioBox selection string is: " ); |
940 | m_text->AppendText( event.GetString() ); | |
941 | m_text->AppendText( "\n" ); | |
47908e25 RR |
942 | } |
943 | ||
944 | void MyPanel::OnRadioButtons( wxCommandEvent &event ) | |
945 | { | |
ec9f7884 | 946 | switch (event.GetId()) |
d3904ceb | 947 | { |
ec9f7884 VZ |
948 | case ID_RADIOBOX_ENABLE: |
949 | { | |
950 | m_radio->Enable( event.GetInt() == 0 ); | |
951 | break; | |
952 | } | |
953 | case ID_RADIOBOX_SEL_NUM: | |
954 | { | |
955 | m_radio->SetSelection( 2 ); | |
956 | break; | |
957 | } | |
958 | case ID_RADIOBOX_SEL_STR: | |
959 | { | |
960 | m_radio->SetStringSelection( "This" ); | |
961 | break; | |
962 | } | |
963 | case ID_RADIOBOX_FONT: | |
964 | { | |
965 | m_radio->SetFont( *wxITALIC_FONT ); | |
966 | break; | |
967 | } | |
868a2826 | 968 | } |
1c005ff7 RR |
969 | } |
970 | ||
868a2826 RR |
971 | void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) ) |
972 | { | |
ec9f7884 VZ |
973 | m_fontButton->SetFont( *wxITALIC_FONT ); |
974 | m_text->SetFont( *wxITALIC_FONT ); | |
868a2826 RR |
975 | } |
976 | ||
185fa6bf VZ |
977 | void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) ) |
978 | { | |
979 | static bool s_long = TRUE; | |
980 | ||
981 | s_long = !s_long; | |
982 | m_label->SetLabel(s_long ? "very very very long text" : "shorter text"); | |
983 | } | |
984 | ||
7bce6aec RR |
985 | void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) |
986 | { | |
ec9f7884 | 987 | m_gauge->SetValue( m_slider->GetValue() ); |
7bce6aec RR |
988 | } |
989 | ||
baccb514 VZ |
990 | #if wxUSE_SPINCTRL |
991 | ||
992 | void MyPanel::OnSpinCtrl(wxSpinEvent& event) | |
993 | { | |
994 | wxString s; | |
995 | s.Printf(_T("Current value of spin ctrl is %d\n"), m_spinctrl->GetValue()); | |
996 | m_text->AppendText(s); | |
997 | } | |
998 | ||
999 | #endif // wxUSE_SPINCTRL | |
1000 | ||
0e528b99 | 1001 | #if wxUSE_SPINBTN |
8c3c31d4 VZ |
1002 | void MyPanel::OnSpinUp( wxSpinEvent &event ) |
1003 | { | |
1004 | wxString value; | |
1005 | value.Printf( _T("Spin control up: current = %d\n"), | |
1006 | m_spinbutton->GetValue()); | |
1007 | ||
1008 | if ( m_spinbutton->GetValue() > 17 ) | |
1009 | { | |
1010 | value += _T("Preventing the spin button from going above 17.\n"); | |
1011 | ||
1012 | event.Veto(); | |
1013 | } | |
1014 | ||
1015 | m_text->AppendText(value); | |
1016 | } | |
1017 | ||
1018 | void MyPanel::OnSpinDown( wxSpinEvent &event ) | |
1019 | { | |
1020 | wxString value; | |
1021 | value.Printf( _T("Spin control down: current = %d\n"), | |
1022 | m_spinbutton->GetValue()); | |
1023 | ||
1024 | if ( m_spinbutton->GetValue() < -17 ) | |
1025 | { | |
1026 | value += _T("Preventing the spin button from going below -17.\n"); | |
1027 | ||
1028 | event.Veto(); | |
1029 | } | |
1030 | ||
1031 | m_text->AppendText(value); | |
1032 | } | |
1033 | ||
e380f72b RR |
1034 | void MyPanel::OnSpinUpdate( wxSpinEvent &event ) |
1035 | { | |
ec9f7884 | 1036 | wxString value; |
f70d5829 | 1037 | value.Printf( _T("%d"), event.GetPosition() ); |
ec9f7884 | 1038 | m_spintext->SetValue( value ); |
6380910c | 1039 | |
f70d5829 | 1040 | value.Printf( _T("Spin control range: (%d, %d), current = %d\n"), |
6380910c VZ |
1041 | m_spinbutton->GetMin(), m_spinbutton->GetMax(), |
1042 | m_spinbutton->GetValue()); | |
1043 | ||
1044 | m_text->AppendText(value); | |
e380f72b | 1045 | } |
9726da4f VZ |
1046 | |
1047 | void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event ) | |
1048 | { | |
1049 | event.Enable( m_spinbutton->GetValue() > 0 ); | |
1050 | } | |
1051 | ||
1052 | void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
1053 | { | |
1054 | int max = m_spinbutton->GetValue(); | |
1055 | wxProgressDialog dialog("Progress dialog example", | |
1056 | "An informative message", | |
1057 | max, // range | |
1058 | this, // parent | |
8c3c31d4 VZ |
1059 | wxPD_CAN_ABORT | |
1060 | wxPD_APP_MODAL | | |
1061 | wxPD_ELAPSED_TIME | | |
1062 | wxPD_ESTIMATED_TIME | | |
1063 | wxPD_REMAINING_TIME); | |
2ac1b69a | 1064 | |
9726da4f VZ |
1065 | |
1066 | bool cont = TRUE; | |
1067 | for ( int i = 0; i < max && cont; i++ ) | |
1068 | { | |
1069 | wxSleep(1); | |
be9abe3f VZ |
1070 | if ( i == max - 1 ) |
1071 | { | |
1072 | cont = dialog.Update(i, "That's all, folks!"); | |
1073 | } | |
1074 | else if ( i == max / 2 ) | |
9726da4f VZ |
1075 | { |
1076 | cont = dialog.Update(i, "Only a half left!"); | |
1077 | } | |
1078 | else | |
1079 | { | |
1080 | cont = dialog.Update(i); | |
1081 | } | |
1082 | } | |
1083 | ||
1084 | if ( !cont ) | |
1085 | { | |
1086 | *m_text << "Progress dialog aborted!\n"; | |
1087 | } | |
1088 | else | |
1089 | { | |
1090 | *m_text << "Countdown from " << max << " finished.\n"; | |
1091 | } | |
1092 | } | |
1093 | ||
0e528b99 | 1094 | #endif // wxUSE_SPINBTN |
e380f72b | 1095 | |
2cb21a45 VZ |
1096 | MyPanel::~MyPanel() |
1097 | { | |
ec9f7884 | 1098 | delete m_notebook->GetImageList(); |
2cb21a45 VZ |
1099 | } |
1100 | ||
1c005ff7 RR |
1101 | //---------------------------------------------------------------------- |
1102 | // MyFrame | |
1103 | //---------------------------------------------------------------------- | |
1104 | ||
1105 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
87a1e308 VZ |
1106 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) |
1107 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
16f6dfd8 | 1108 | #if wxUSE_TOOLTIPS |
87a1e308 VZ |
1109 | EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay) |
1110 | EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips) | |
16f6dfd8 | 1111 | #endif // wxUSE_TOOLTIPS |
87a1e308 VZ |
1112 | |
1113 | EVT_MENU(MINIMAL_ENABLE_ALL, MyFrame::OnEnableAll) | |
1114 | ||
1115 | EVT_SIZE(MyFrame::OnSize) | |
97206645 VZ |
1116 | EVT_MOVE(MyFrame::OnMove) |
1117 | ||
87a1e308 | 1118 | EVT_IDLE(MyFrame::OnIdle) |
1c005ff7 RR |
1119 | END_EVENT_TABLE() |
1120 | ||
9f3362c4 | 1121 | MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h) |
ec9f7884 | 1122 | : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) |
1c005ff7 | 1123 | { |
5fb9fcfc | 1124 | CreateStatusBar(2); |
9f3362c4 | 1125 | |
87a1e308 | 1126 | m_panel = new MyPanel( this, 10, 10, 300, 100 ); |
1c005ff7 RR |
1127 | } |
1128 | ||
1129 | void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) ) | |
1130 | { | |
ec9f7884 | 1131 | Close(TRUE); |
1c005ff7 RR |
1132 | } |
1133 | ||
1134 | void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) | |
1135 | { | |
ec9f7884 VZ |
1136 | wxBeginBusyCursor(); |
1137 | ||
1138 | wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK ); | |
1139 | dialog.ShowModal(); | |
1140 | ||
1141 | wxEndBusyCursor(); | |
1c005ff7 | 1142 | } |
9f3362c4 | 1143 | |
16f6dfd8 VZ |
1144 | #if wxUSE_TOOLTIPS |
1145 | void MyFrame::OnSetTooltipDelay(wxCommandEvent& event) | |
1146 | { | |
1147 | static long s_delay = 5000; | |
1148 | ||
1149 | wxString delay; | |
f70d5829 | 1150 | delay.Printf( _T("%ld"), s_delay); |
16f6dfd8 VZ |
1151 | |
1152 | delay = wxGetTextFromUser("Enter delay (in milliseconds)", | |
ec9f7884 VZ |
1153 | "Set tooltip delay", |
1154 | delay, | |
1155 | this); | |
16f6dfd8 VZ |
1156 | if ( !delay ) |
1157 | return; // cancelled | |
1158 | ||
f70d5829 | 1159 | wxSscanf(delay, _T("%ld"), &s_delay); |
16f6dfd8 VZ |
1160 | |
1161 | wxToolTip::SetDelay(s_delay); | |
1162 | ||
f70d5829 | 1163 | wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay); |
16f6dfd8 VZ |
1164 | } |
1165 | ||
1166 | void MyFrame::OnToggleTooltips(wxCommandEvent& event) | |
1167 | { | |
1168 | static bool s_enabled = TRUE; | |
1169 | ||
1170 | s_enabled = !s_enabled; | |
1171 | ||
1172 | wxToolTip::Enable(s_enabled); | |
1173 | ||
f70d5829 | 1174 | wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") ); |
16f6dfd8 VZ |
1175 | } |
1176 | #endif // tooltips | |
1177 | ||
87a1e308 VZ |
1178 | void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event)) |
1179 | { | |
1180 | static bool s_enable = TRUE; | |
1181 | ||
1182 | s_enable = !s_enable; | |
1183 | m_panel->Enable(s_enable); | |
1184 | } | |
1185 | ||
97206645 VZ |
1186 | void MyFrame::OnMove( wxMoveEvent& event ) |
1187 | { | |
1188 | UpdateStatusBar(event.GetPosition(), GetSize()); | |
1189 | ||
1190 | event.Skip(); | |
1191 | } | |
1192 | ||
5fb9fcfc VZ |
1193 | void MyFrame::OnSize( wxSizeEvent& event ) |
1194 | { | |
97206645 | 1195 | UpdateStatusBar(GetPosition(), event.GetSize()); |
5fb9fcfc VZ |
1196 | |
1197 | event.Skip(); | |
1198 | } | |
1199 | ||
9f3362c4 VZ |
1200 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
1201 | { | |
1202 | // track the window which has the focus in the status bar | |
1203 | static wxWindow *s_windowFocus = (wxWindow *)NULL; | |
1204 | wxWindow *focus = wxWindow::FindFocus(); | |
1205 | if ( focus && (focus != s_windowFocus) ) | |
1206 | { | |
1207 | s_windowFocus = focus; | |
1208 | ||
1209 | wxString msg; | |
f70d5829 | 1210 | msg.Printf( |
9f3362c4 | 1211 | #ifdef __WXMSW__ |
f70d5829 RR |
1212 | _T("Focus: wxWindow = %p, HWND = %08x"), |
1213 | #else | |
1214 | _T("Focus: wxWindow = %p"), | |
1215 | #endif | |
1216 | s_windowFocus | |
9f3362c4 | 1217 | #ifdef __WXMSW__ |
ec9f7884 | 1218 | , s_windowFocus->GetHWND() |
f70d5829 | 1219 | #endif |
9f3362c4 VZ |
1220 | ); |
1221 | ||
1222 | SetStatusText(msg); | |
1223 | } | |
341c92a8 | 1224 | } |
6c8a980f VZ |
1225 | |
1226 | static void SetControlClientData(const char *name, | |
1227 | wxControlWithItems *control) | |
1228 | { | |
1229 | size_t count = control->GetCount(); | |
1230 | for ( size_t n = 0; n < count; n++ ) | |
1231 | { | |
1232 | wxString s; | |
1233 | s.Printf("%s client data for '%s'", | |
1234 | name, control->GetString(n).c_str()); | |
1235 | ||
1236 | control->SetClientObject(n, new wxStringClientData(s)); | |
1237 | } | |
1238 | } |