]>
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 | ||
4fabb575 | 26 | #include "wx/spinbutt.h" |
53b28675 | 27 | #include "wx/notebook.h" |
2cb21a45 | 28 | #include "wx/imaglist.h" |
655822f3 | 29 | #include "wx/spinbutt.h" |
b8653fbf VZ |
30 | |
31 | #if wxUSE_CLIPBOARD | |
32 | #include "wx/dataobj.h" | |
33 | #include "wx/clipbrd.h" | |
34 | #endif | |
35 | ||
36 | #if wxUSE_TOOLTIPS | |
37 | #include "wx/tooltip.h" | |
38 | #endif | |
1c005ff7 | 39 | |
4b5f3fe6 | 40 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
73c700fd | 41 | #define USE_XPM |
4fabb575 JS |
42 | #endif |
43 | ||
44 | #ifdef USE_XPM | |
73c700fd VZ |
45 | #include "mondrian.xpm" |
46 | #include "icons/choice.xpm" | |
47 | #include "icons/combo.xpm" | |
48 | #include "icons/list.xpm" | |
49 | #include "icons/radio.xpm" | |
50 | #include "icons/text.xpm" | |
51 | #include "icons/gauge.xpm" | |
47908e25 RR |
52 | #endif |
53 | ||
1c005ff7 RR |
54 | //---------------------------------------------------------------------- |
55 | // class definitions | |
56 | //---------------------------------------------------------------------- | |
57 | ||
58 | class MyApp: public wxApp | |
655822f3 | 59 | { |
b8653fbf VZ |
60 | public: |
61 | bool OnInit(); | |
1c005ff7 RR |
62 | }; |
63 | ||
6085b116 VZ |
64 | // a text ctrl which allows to call different wxTextCtrl functions |
65 | // interactively by pressing function keys in it | |
66 | class MyTextCtrl : public wxTextCtrl | |
67 | { | |
68 | public: | |
69 | MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, | |
70 | const wxPoint &pos, const wxSize &size, int style = 0) | |
71 | : wxTextCtrl(parent, id, value, pos, size, style) { } | |
72 | ||
5fb9fcfc | 73 | void OnKeyDown(wxKeyEvent& event); |
14531b30 | 74 | void OnChar(wxKeyEvent& event); |
6085b116 VZ |
75 | |
76 | private: | |
77 | DECLARE_EVENT_TABLE() | |
78 | }; | |
79 | ||
1c005ff7 RR |
80 | class MyPanel: public wxPanel |
81 | { | |
b8653fbf | 82 | public: |
1c005ff7 | 83 | MyPanel(wxFrame *frame, int x, int y, int w, int h); |
2cb21a45 | 84 | virtual ~MyPanel(); |
16f6dfd8 | 85 | |
1c005ff7 RR |
86 | void OnSize( wxSizeEvent& event ); |
87 | void OnListBox( wxCommandEvent &event ); | |
5b077d48 | 88 | void OnListBoxDoubleClick( wxCommandEvent &event ); |
1c005ff7 | 89 | void OnListBoxButtons( wxCommandEvent &event ); |
47908e25 RR |
90 | void OnChoice( wxCommandEvent &event ); |
91 | void OnChoiceButtons( wxCommandEvent &event ); | |
92 | void OnCombo( wxCommandEvent &event ); | |
93 | void OnComboButtons( wxCommandEvent &event ); | |
94 | void OnRadio( wxCommandEvent &event ); | |
95 | void OnRadioButtons( wxCommandEvent &event ); | |
868a2826 | 96 | void OnSetFont( wxCommandEvent &event ); |
cb43b372 | 97 | void OnPageChanged( wxNotebookEvent &event ); |
7bce6aec | 98 | void OnSliderUpdate( wxCommandEvent &event ); |
2a47d3c1 | 99 | #ifndef __WIN16__ |
e380f72b | 100 | void OnSpinUpdate( wxSpinEvent &event ); |
2a47d3c1 | 101 | #endif |
b527aac5 RR |
102 | void OnPasteFromClipboard( wxCommandEvent &event ); |
103 | void OnCopyToClipboard( wxCommandEvent &event ); | |
d59051dd VZ |
104 | void OnMoveToEndOfText( wxCommandEvent &event ); |
105 | void OnMoveToEndOfEntry( wxCommandEvent &event ); | |
16f6dfd8 | 106 | |
e380f72b RR |
107 | wxListBox *m_listbox; |
108 | wxChoice *m_choice; | |
109 | wxComboBox *m_combo; | |
110 | wxRadioBox *m_radio; | |
111 | wxGauge *m_gauge; | |
112 | wxSlider *m_slider; | |
113 | wxButton *m_fontButton; | |
2a47d3c1 | 114 | #ifndef __WIN16__ |
e380f72b | 115 | wxSpinButton *m_spinbutton; |
2a47d3c1 | 116 | #endif |
e380f72b | 117 | wxTextCtrl *m_spintext; |
6085b116 VZ |
118 | MyTextCtrl *m_multitext; |
119 | MyTextCtrl *m_textentry; | |
ae0bdb01 | 120 | wxCheckBox *m_checkbox; |
16f6dfd8 | 121 | |
e380f72b | 122 | wxTextCtrl *m_text; |
655822f3 VZ |
123 | wxNotebook *m_notebook; |
124 | ||
b8653fbf VZ |
125 | private: |
126 | DECLARE_EVENT_TABLE() | |
1c005ff7 RR |
127 | }; |
128 | ||
129 | class MyFrame: public wxFrame | |
130 | { | |
b8653fbf | 131 | public: |
1c005ff7 | 132 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); |
655822f3 | 133 | |
1c005ff7 RR |
134 | void OnQuit(wxCommandEvent& event); |
135 | void OnAbout(wxCommandEvent& event); | |
16f6dfd8 VZ |
136 | #if wxUSE_TOOLTIPS |
137 | void OnSetTooltipDelay(wxCommandEvent& event); | |
138 | void OnToggleTooltips(wxCommandEvent& event); | |
139 | #endif // wxUSE_TOOLTIPS | |
9f3362c4 | 140 | void OnIdle( wxIdleEvent& event ); |
5fb9fcfc | 141 | void OnSize( wxSizeEvent& event ); |
655822f3 | 142 | |
b8653fbf VZ |
143 | private: |
144 | DECLARE_EVENT_TABLE() | |
1c005ff7 RR |
145 | }; |
146 | ||
147 | //---------------------------------------------------------------------- | |
148 | // main() | |
149 | //---------------------------------------------------------------------- | |
150 | ||
d59051dd | 151 | IMPLEMENT_APP(MyApp) |
1c005ff7 RR |
152 | |
153 | //---------------------------------------------------------------------- | |
154 | // MyApp | |
155 | //---------------------------------------------------------------------- | |
156 | ||
16f6dfd8 VZ |
157 | enum |
158 | { | |
159 | MINIMAL_QUIT = 100, | |
160 | MINIMAL_TEXT, | |
161 | MINIMAL_ABOUT, | |
162 | ||
163 | // tooltip menu | |
164 | MINIMAL_SET_TOOLTIP_DELAY = 200, | |
165 | MINIMAL_ENABLE_TOOLTIPS | |
166 | }; | |
1c005ff7 | 167 | |
b8653fbf | 168 | bool MyApp::OnInit() |
1c005ff7 | 169 | { |
ec9f7884 VZ |
170 | // Create the main frame window |
171 | MyFrame *frame = new MyFrame((wxFrame *) NULL, | |
172 | "Controls wxWindows App", | |
173 | 50, 50, 530, 420); | |
655822f3 | 174 | |
ec9f7884 VZ |
175 | // Give it an icon |
176 | // The wxICON() macros loads an icon from a resource under Windows | |
177 | // and uses an #included XPM image under GTK+ and Motif | |
655822f3 | 178 | |
ec9f7884 | 179 | frame->SetIcon( wxICON(mondrian) ); |
1c005ff7 | 180 | |
ec9f7884 VZ |
181 | wxMenu *file_menu = new wxMenu; |
182 | file_menu->Append(MINIMAL_ABOUT, "&About"); | |
183 | file_menu->Append(MINIMAL_QUIT, "E&xit"); | |
16f6dfd8 | 184 | |
ba0730de | 185 | wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE ); |
ec9f7884 | 186 | menu_bar->Append(file_menu, "&File"); |
16f6dfd8 VZ |
187 | |
188 | #if wxUSE_TOOLTIPS | |
ec9f7884 VZ |
189 | wxMenu *tooltip_menu = new wxMenu; |
190 | tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay"); | |
191 | tooltip_menu->AppendSeparator(); | |
192 | tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips", | |
193 | "enable/disable tooltips", TRUE); | |
194 | tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE); | |
195 | menu_bar->Append(tooltip_menu, "&Tooltips"); | |
16f6dfd8 VZ |
196 | #endif // wxUSE_TOOLTIPS |
197 | ||
ec9f7884 | 198 | frame->SetMenuBar(menu_bar); |
1c005ff7 | 199 | |
ec9f7884 | 200 | frame->Show(TRUE); |
9018abe3 | 201 | frame->SetCursor(wxCursor(wxCURSOR_HAND)); |
655822f3 | 202 | |
ec9f7884 | 203 | SetTopWindow(frame); |
1c005ff7 | 204 | |
ec9f7884 | 205 | return TRUE; |
1c005ff7 RR |
206 | } |
207 | ||
6085b116 VZ |
208 | //---------------------------------------------------------------------- |
209 | // MyTextCtrl | |
210 | //---------------------------------------------------------------------- | |
211 | ||
212 | BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl) | |
14531b30 VZ |
213 | EVT_KEY_DOWN(MyTextCtrl::OnKeyDown) |
214 | EVT_CHAR(MyTextCtrl::OnChar) | |
6085b116 VZ |
215 | END_EVENT_TABLE() |
216 | ||
14531b30 VZ |
217 | void MyTextCtrl::OnChar(wxKeyEvent& event) |
218 | { | |
219 | static int s_keycode = 0; | |
220 | static size_t s_repeatCount = 0; | |
221 | ||
222 | int keycode = event.KeyCode(); | |
223 | if ( keycode == s_keycode ) | |
224 | s_repeatCount++; | |
225 | else | |
226 | { | |
227 | s_keycode = keycode; | |
228 | s_repeatCount = 1; | |
229 | } | |
230 | ||
f70d5829 | 231 | wxLogStatus( _T("Key event: %d (x%u), at position %ld"), |
14531b30 VZ |
232 | s_keycode, s_repeatCount, GetInsertionPoint()); |
233 | ||
234 | event.Skip(); | |
235 | } | |
236 | ||
5fb9fcfc | 237 | void MyTextCtrl::OnKeyDown(wxKeyEvent& event) |
6085b116 VZ |
238 | { |
239 | switch ( event.KeyCode() ) | |
240 | { | |
241 | case WXK_F1: | |
242 | // show current position and text length | |
243 | { | |
244 | long line, column, pos = GetInsertionPoint(); | |
245 | PositionToXY(pos, &column, &line); | |
246 | ||
f70d5829 | 247 | wxLogMessage( _T("Current position: %ld\n" |
ec9f7884 VZ |
248 | "Current line, column: (%ld, %ld)\n" |
249 | "Number of lines: %ld\n" | |
250 | "Current line length: %ld\n" | |
f70d5829 | 251 | "Total text length: %ld"), |
ec9f7884 VZ |
252 | pos, |
253 | line, column, | |
254 | GetNumberOfLines(), | |
255 | GetLineLength(line), | |
256 | GetLastPosition()); | |
6085b116 VZ |
257 | } |
258 | break; | |
259 | ||
260 | case WXK_F2: | |
261 | // go to the end | |
262 | SetInsertionPointEnd(); | |
263 | break; | |
264 | ||
265 | case WXK_F3: | |
266 | // go to position 10 | |
267 | SetInsertionPoint(10); | |
268 | break; | |
269 | ||
270 | default: | |
271 | event.Skip(); | |
272 | } | |
273 | } | |
274 | ||
1c005ff7 RR |
275 | //---------------------------------------------------------------------- |
276 | // MyPanel | |
277 | //---------------------------------------------------------------------- | |
278 | ||
4fabb575 | 279 | const int ID_NOTEBOOK = 1000; |
1c005ff7 | 280 | |
4fabb575 JS |
281 | const int ID_LISTBOX = 130; |
282 | const int ID_LISTBOX_SEL_NUM = 131; | |
283 | const int ID_LISTBOX_SEL_STR = 132; | |
284 | const int ID_LISTBOX_CLEAR = 133; | |
285 | const int ID_LISTBOX_APPEND = 134; | |
286 | const int ID_LISTBOX_DELETE = 135; | |
287 | const int ID_LISTBOX_FONT = 136; | |
288 | const int ID_LISTBOX_ENABLE = 137; | |
1c005ff7 | 289 | |
4fabb575 JS |
290 | const int ID_CHOICE = 120; |
291 | const int ID_CHOICE_SEL_NUM = 121; | |
292 | const int ID_CHOICE_SEL_STR = 122; | |
293 | const int ID_CHOICE_CLEAR = 123; | |
294 | const int ID_CHOICE_APPEND = 124; | |
295 | const int ID_CHOICE_DELETE = 125; | |
296 | const int ID_CHOICE_FONT = 126; | |
297 | const int ID_CHOICE_ENABLE = 127; | |
53010e52 | 298 | |
4fabb575 JS |
299 | const int ID_COMBO = 140; |
300 | const int ID_COMBO_SEL_NUM = 141; | |
301 | const int ID_COMBO_SEL_STR = 142; | |
302 | const int ID_COMBO_CLEAR = 143; | |
303 | const int ID_COMBO_APPEND = 144; | |
304 | const int ID_COMBO_DELETE = 145; | |
305 | const int ID_COMBO_FONT = 146; | |
306 | const int ID_COMBO_ENABLE = 147; | |
53010e52 | 307 | |
4fabb575 | 308 | const int ID_TEXT = 150; |
b527aac5 RR |
309 | const int ID_PASTE_TEXT = 151; |
310 | const int ID_COPY_TEXT = 152; | |
d59051dd VZ |
311 | const int ID_MOVE_END_ENTRY = 153; |
312 | const int ID_MOVE_END_ZONE = 154; | |
219f895a | 313 | |
4fabb575 JS |
314 | const int ID_RADIOBOX = 160; |
315 | const int ID_RADIOBOX_SEL_NUM = 161; | |
316 | const int ID_RADIOBOX_SEL_STR = 162; | |
317 | const int ID_RADIOBOX_FONT = 163; | |
318 | const int ID_RADIOBOX_ENABLE = 164; | |
868a2826 | 319 | |
f5d29b39 RR |
320 | const int ID_RADIOBUTTON_1 = 166; |
321 | const int ID_RADIOBUTTON_2 = 167; | |
322 | ||
4fabb575 | 323 | const int ID_SET_FONT = 170; |
47908e25 | 324 | |
4fabb575 JS |
325 | const int ID_GAUGE = 180; |
326 | const int ID_SLIDER = 181; | |
58614078 | 327 | |
4fabb575 | 328 | const int ID_SPIN = 182; |
e380f72b | 329 | |
1c005ff7 | 330 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
ec9f7884 VZ |
331 | EVT_SIZE ( MyPanel::OnSize) |
332 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged) | |
333 | EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) | |
334 | EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick) | |
335 | EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons) | |
336 | EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons) | |
337 | EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons) | |
338 | EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons) | |
339 | EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons) | |
340 | EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons) | |
341 | EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons) | |
342 | EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice) | |
343 | EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons) | |
344 | EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons) | |
345 | EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons) | |
346 | EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons) | |
347 | EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons) | |
348 | EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons) | |
349 | EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons) | |
350 | EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo) | |
351 | EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons) | |
352 | EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons) | |
353 | EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons) | |
354 | EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons) | |
355 | EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons) | |
356 | EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons) | |
357 | EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons) | |
358 | EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio) | |
359 | EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons) | |
360 | EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons) | |
361 | EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons) | |
362 | EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons) | |
363 | EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) | |
364 | EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) | |
2a47d3c1 | 365 | #ifndef __WIN16__ |
ec9f7884 | 366 | EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) |
2a47d3c1 | 367 | #endif |
ec9f7884 VZ |
368 | EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard) |
369 | EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard) | |
370 | EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText) | |
371 | EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry) | |
1c005ff7 RR |
372 | END_EVENT_TABLE() |
373 | ||
5fb9fcfc | 374 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) |
ec9f7884 VZ |
375 | : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ), |
376 | m_text(NULL), m_notebook(NULL) | |
1c005ff7 | 377 | { |
ec9f7884 | 378 | // SetBackgroundColour("cadet blue"); |
a81258be | 379 | |
ec9f7884 VZ |
380 | m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); |
381 | // m_text->SetBackgroundColour("wheat"); | |
655822f3 | 382 | |
ec9f7884 | 383 | m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) ); |
655822f3 | 384 | |
ec9f7884 VZ |
385 | wxString choices[] = |
386 | { | |
387 | "This", | |
388 | "is one of my", | |
389 | "really", | |
390 | "wonderful", | |
391 | "examples." | |
392 | }; | |
655822f3 | 393 | |
4fabb575 | 394 | #ifdef USE_XPM |
ec9f7884 VZ |
395 | // image ids |
396 | enum | |
397 | { | |
398 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max | |
399 | }; | |
400 | ||
401 | // fill the image list | |
402 | wxImageList *imagelist = new wxImageList(32, 32); | |
403 | ||
404 | imagelist-> Add( wxBitmap( list_xpm )); | |
405 | imagelist-> Add( wxBitmap( choice_xpm )); | |
406 | imagelist-> Add( wxBitmap( combo_xpm )); | |
407 | imagelist-> Add( wxBitmap( text_xpm )); | |
408 | imagelist-> Add( wxBitmap( radio_xpm )); | |
409 | imagelist-> Add( wxBitmap( gauge_xpm )); | |
410 | m_notebook->SetImageList(imagelist); | |
73c700fd | 411 | #elif defined(__WXMSW__) |
ec9f7884 VZ |
412 | // load images from resources |
413 | enum | |
414 | { | |
415 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max | |
416 | }; | |
417 | wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max); | |
418 | ||
419 | static const char *s_iconNames[Image_Max] = | |
420 | { | |
421 | "list", "choice", "combo", "text", "radio", "gauge" | |
422 | }; | |
423 | ||
424 | for ( size_t n = 0; n < Image_Max; n++ ) | |
425 | { | |
426 | wxBitmap bmp(s_iconNames[n]); | |
427 | if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) ) | |
428 | { | |
429 | wxLogWarning("Couldn't load the image '%s' for the notebook page %d.", | |
430 | s_iconNames[n], n); | |
431 | } | |
432 | } | |
433 | ||
434 | m_notebook->SetImageList(imagelist); | |
4fabb575 JS |
435 | #else |
436 | ||
ec9f7884 | 437 | // No images for now |
4fabb575 JS |
438 | #define Image_List -1 |
439 | #define Image_Choice -1 | |
440 | #define Image_Combo -1 | |
441 | #define Image_Text -1 | |
442 | #define Image_Radio -1 | |
443 | #define Image_Gauge -1 | |
444 | #define Image_Max -1 | |
445 | ||
fc54776e | 446 | #endif |
2cb21a45 | 447 | |
ec9f7884 VZ |
448 | wxButton *button = (wxButton*) NULL; /* who did this ? */ |
449 | wxPanel *panel = (wxPanel*) NULL; | |
9838df2c | 450 | |
ec9f7884 | 451 | panel = new wxPanel(m_notebook); |
034be888 | 452 | m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices, wxLB_ALWAYS_SB ); |
ec9f7884 | 453 | m_listbox->SetCursor(*wxCROSS_CURSOR); |
b8653fbf | 454 | #if wxUSE_TOOLTIPS |
ec9f7884 | 455 | m_listbox->SetToolTip( "This is a list box" ); |
16f6dfd8 | 456 | #endif // wxUSE_TOOLTIPS |
9f3362c4 | 457 | |
ec9f7884 VZ |
458 | (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
459 | (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
460 | (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
461 | (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
462 | (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
034be888 | 463 | button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) ); |
b8653fbf | 464 | #if wxUSE_TOOLTIPS |
ec9f7884 | 465 | button->SetToolTip( "Press here to set italic font" ); |
16f6dfd8 | 466 | #endif // wxUSE_TOOLTIPS |
b1170810 | 467 | |
ec9f7884 VZ |
468 | m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); |
469 | m_checkbox->SetValue(FALSE); | |
b8653fbf | 470 | #if wxUSE_TOOLTIPS |
ec9f7884 | 471 | m_checkbox->SetToolTip( "Click here to disable the listbox" ); |
16f6dfd8 | 472 | #endif // wxUSE_TOOLTIPS |
ec9f7884 VZ |
473 | m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List); |
474 | ||
475 | panel = new wxPanel(m_notebook); | |
476 | m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices ); | |
2b07d713 | 477 | m_choice->SetBackgroundColour( "red" ); |
ec9f7884 VZ |
478 | (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
479 | (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
480 | (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
481 | (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
482 | (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
483 | (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
484 | (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
485 | m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); | |
486 | ||
487 | panel = new wxPanel(m_notebook); | |
a260fe6a | 488 | m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices, wxCB_READONLY ); |
ec9f7884 VZ |
489 | (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
490 | (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
491 | (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
492 | (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
493 | (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
494 | (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
495 | (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
496 | m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo); | |
497 | ||
498 | panel = new wxPanel(m_notebook); | |
499 | m_textentry = new MyTextCtrl( panel, -1, "Some text.", wxPoint(10,10), wxSize(320,28), //0); | |
500 | wxTE_PROCESS_ENTER); | |
501 | (*m_textentry) << " Appended."; | |
502 | m_textentry->SetInsertionPoint(0); | |
503 | m_textentry->WriteText( "Prepended. " ); | |
504 | ||
505 | m_multitext = new MyTextCtrl( panel, ID_TEXT, "Some text.", wxPoint(10,50), wxSize(320,70), wxTE_MULTILINE ); | |
506 | (*m_multitext) << " Appended."; | |
507 | m_multitext->SetInsertionPoint(0); | |
508 | m_multitext->WriteText( "Prepended. " ); | |
ab46dc18 | 509 | m_multitext->AppendText( "\nPress function keys for test different tests." ); |
ec9f7884 VZ |
510 | |
511 | (*m_multitext) << "\nDoes it have cross cursor?"; | |
512 | m_multitext->SetCursor(*wxCROSS_CURSOR); | |
513 | ||
514 | new MyTextCtrl( panel, -1, "This one is with wxTE_PROCESS_TAB style.", wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE | wxTE_PROCESS_TAB); | |
16f6dfd8 | 515 | #if wxUSE_TOOLTIPS |
ec9f7884 VZ |
516 | m_multitext->AppendText( "\nThis ctrl has a tooltip. " ); |
517 | m_multitext->SetToolTip("Press F1 here."); | |
16f6dfd8 | 518 | #endif // wxUSE_TOOLTIPS |
9f3362c4 | 519 | |
ec9f7884 VZ |
520 | (void)new wxStaticBox( panel, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) ); |
521 | (void)new wxButton( panel, ID_MOVE_END_ENTRY, "Text &entry", wxPoint(370, 20), wxSize(110, 30) ); | |
522 | (void)new wxButton( panel, ID_MOVE_END_ZONE, "Text &zone", wxPoint(370, 60), wxSize(110, 30) ); | |
523 | (void)new wxStaticBox( panel, -1, "wx&Clipboard", wxPoint(345,100), wxSize(160,100) ); | |
524 | (void)new wxButton( panel, ID_COPY_TEXT, "C&opy line 1", wxPoint(370,120), wxSize(110,30) ); | |
525 | (void)new wxButton( panel, ID_PASTE_TEXT, "&Paste text", wxPoint(370,160), wxSize(110,30) ); | |
526 | m_notebook->AddPage( panel, "wxTextCtrl" , FALSE, Image_Text ); | |
527 | ||
528 | wxString choices2[] = | |
529 | { | |
17867d61 RR |
530 | "First", "Second", |
531 | /* "Third", | |
532 | "Fourth", "Fifth", "Sixth", | |
533 | "Seventh", "Eighth", "Nineth", "Tenth" */ | |
ec9f7884 VZ |
534 | }; |
535 | ||
536 | panel = new wxPanel(m_notebook); | |
9018abe3 VZ |
537 | (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS ); |
538 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS ); | |
ec9f7884 VZ |
539 | (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); |
540 | (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); | |
541 | m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) ); | |
542 | (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) ); | |
543 | (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); | |
544 | wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) ); | |
545 | rb->SetValue( FALSE ); | |
546 | (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) ); | |
547 | m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); | |
548 | ||
549 | panel = new wxPanel(m_notebook); | |
550 | (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) ); | |
551 | m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) ); | |
858b5bdd | 552 | m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS ); |
ec9f7884 | 553 | (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) ); |
9838df2c | 554 | #ifdef __WXMOTIF__ |
ec9f7884 VZ |
555 | // No wrapping text in wxStaticText yet :-( |
556 | (void)new wxStaticText( panel, -1, | |
557 | "Drag the slider!", | |
558 | wxPoint(208,30), | |
559 | wxSize(210, -1) | |
560 | ); | |
9838df2c | 561 | #else |
ec9f7884 VZ |
562 | (void)new wxStaticText( panel, -1, |
563 | "In order see the gauge (aka progress bar)\n" | |
564 | "control do something you have to drag the\n" | |
565 | "handle of the slider to the right.\n" | |
566 | "\n" | |
567 | "This is also supposed to demonstrate how\n" | |
568 | "to use static controls.\n", | |
569 | wxPoint(208,25), | |
570 | wxSize(250, 110) | |
571 | ); | |
9838df2c | 572 | #endif |
ec9f7884 | 573 | m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) ); |
2a47d3c1 | 574 | #ifndef __WIN16__ |
ec9f7884 | 575 | m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) ); |
6380910c VZ |
576 | m_spinbutton->SetRange(-10,30); |
577 | m_spinbutton->SetValue(-5); | |
2a47d3c1 | 578 | #endif |
ec9f7884 | 579 | m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); |
1c005ff7 RR |
580 | } |
581 | ||
b527aac5 RR |
582 | void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) ) |
583 | { | |
ec9f7884 VZ |
584 | // We test for wxUSE_DRAG_AND_DROP also, because data objects |
585 | // may not be implemented for compilers that can't cope with the OLE | |
586 | // parts in wxUSE_DRAG_AND_DROP. | |
8e0080ee JS |
587 | |
588 | #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP | |
ec9f7884 VZ |
589 | if (!wxTheClipboard->Open()) |
590 | { | |
591 | *m_text << "Error opening the clipboard.\n"; | |
592 | ||
593 | return; | |
594 | } | |
595 | else | |
596 | { | |
597 | *m_text << "Successfully opened the clipboard.\n"; | |
598 | } | |
599 | ||
600 | wxTextDataObject data; | |
601 | ||
602 | if (wxTheClipboard->IsSupported( data.GetFormat() )) | |
603 | { | |
604 | *m_text << "Clipboard supports requested format.\n"; | |
605 | ||
606 | if (wxTheClipboard->GetData( &data )) | |
607 | { | |
608 | *m_text << "Successfully retrieved data from the clipboard.\n"; | |
609 | *m_multitext << data.GetText() << "\n"; | |
610 | } | |
611 | else | |
612 | { | |
613 | *m_text << "Error getting data from the clipboard.\n"; | |
614 | } | |
615 | } | |
616 | else | |
617 | { | |
618 | *m_text << "Clipboard doesn't support requested format.\n"; | |
619 | } | |
620 | ||
621 | wxTheClipboard->Close(); | |
622 | ||
623 | *m_text << "Closed the clipboard.\n"; | |
341c92a8 | 624 | #else |
ec9f7884 | 625 | wxLogError("Your version of wxWindows is compiled without clipboard support."); |
b527aac5 RR |
626 | #endif |
627 | } | |
628 | ||
629 | void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) ) | |
630 | { | |
8e0080ee | 631 | #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP |
ec9f7884 | 632 | wxString text( m_multitext->GetLineText(0) ); |
3069ac4e | 633 | |
ec9f7884 VZ |
634 | if (text.IsEmpty()) |
635 | { | |
636 | *m_text << "No text to copy.\n"; | |
b8653fbf | 637 | |
ec9f7884 VZ |
638 | return; |
639 | } | |
655822f3 | 640 | |
ec9f7884 VZ |
641 | if (!wxTheClipboard->Open()) |
642 | { | |
643 | *m_text << "Error opening the clipboard.\n"; | |
655822f3 | 644 | |
ec9f7884 VZ |
645 | return; |
646 | } | |
647 | else | |
648 | { | |
649 | *m_text << "Successfully opened the clipboard.\n"; | |
650 | } | |
3069ac4e | 651 | |
ec9f7884 | 652 | wxTextDataObject *data = new wxTextDataObject( text ); |
0d2a2b60 | 653 | |
ec9f7884 VZ |
654 | if (!wxTheClipboard->SetData( data )) |
655 | { | |
656 | *m_text << "Error while copying to the clipboard.\n"; | |
657 | } | |
658 | else | |
659 | { | |
660 | *m_text << "Successfully copied data to the clipboard.\n"; | |
661 | } | |
8b53e5a2 | 662 | |
ec9f7884 | 663 | wxTheClipboard->Close(); |
655822f3 | 664 | |
ec9f7884 | 665 | *m_text << "Closed the clipboard.\n"; |
b8653fbf | 666 | #else |
ec9f7884 | 667 | wxLogError("Your version of wxWindows is compiled without clipboard support."); |
3069ac4e | 668 | #endif |
b527aac5 RR |
669 | } |
670 | ||
d59051dd VZ |
671 | void MyPanel::OnMoveToEndOfText( wxCommandEvent &event ) |
672 | { | |
673 | m_multitext->SetInsertionPointEnd(); | |
674 | m_multitext->SetFocus(); | |
675 | } | |
676 | ||
677 | void MyPanel::OnMoveToEndOfEntry( wxCommandEvent &event ) | |
678 | { | |
679 | m_textentry->SetInsertionPointEnd(); | |
680 | m_textentry->SetFocus(); | |
681 | } | |
682 | ||
1c005ff7 RR |
683 | void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) |
684 | { | |
ec9f7884 VZ |
685 | int x = 0; |
686 | int y = 0; | |
687 | GetClientSize( &x, &y ); | |
655822f3 | 688 | |
ec9f7884 VZ |
689 | if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 ); |
690 | if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 ); | |
1c005ff7 RR |
691 | } |
692 | ||
cb43b372 RR |
693 | void MyPanel::OnPageChanged( wxNotebookEvent &event ) |
694 | { | |
ec9f7884 | 695 | *m_text << "Notebook selection is " << event.GetSelection() << "\n"; |
cb43b372 RR |
696 | } |
697 | ||
1c005ff7 RR |
698 | void MyPanel::OnListBox( wxCommandEvent &event ) |
699 | { | |
19da4326 | 700 | m_text->AppendText( "ListBox event selection string is: " ); |
ec9f7884 VZ |
701 | m_text->AppendText( event.GetString() ); |
702 | m_text->AppendText( "\n" ); | |
19da4326 RR |
703 | m_text->AppendText( "ListBox control selection string is: " ); |
704 | m_text->AppendText( m_listbox->GetStringSelection() ); | |
705 | m_text->AppendText( "\n" ); | |
1c005ff7 RR |
706 | } |
707 | ||
5b077d48 RR |
708 | void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event ) |
709 | { | |
ec9f7884 VZ |
710 | m_text->AppendText( "ListBox double click string is: " ); |
711 | m_text->AppendText( event.GetString() ); | |
712 | m_text->AppendText( "\n" ); | |
5b077d48 RR |
713 | } |
714 | ||
47908e25 RR |
715 | void MyPanel::OnListBoxButtons( wxCommandEvent &event ) |
716 | { | |
ec9f7884 | 717 | switch (event.GetId()) |
d3904ceb | 718 | { |
ec9f7884 VZ |
719 | case ID_LISTBOX_ENABLE: |
720 | { | |
721 | m_text->AppendText("Checkbox clicked.\n"); | |
722 | wxCheckBox *cb = (wxCheckBox*)event.GetEventObject(); | |
b8653fbf | 723 | #if wxUSE_TOOLTIPS |
ec9f7884 VZ |
724 | if (event.GetInt()) |
725 | cb->SetToolTip( "Click to enable listbox" ); | |
726 | else | |
727 | cb->SetToolTip( "Click to disable listbox" ); | |
16f6dfd8 | 728 | #endif // wxUSE_TOOLTIPS |
ec9f7884 VZ |
729 | m_listbox->Enable( event.GetInt() == 0 ); |
730 | break; | |
731 | } | |
732 | case ID_LISTBOX_SEL_NUM: | |
733 | { | |
734 | m_listbox->SetSelection( 2 ); | |
735 | break; | |
736 | } | |
737 | case ID_LISTBOX_SEL_STR: | |
738 | { | |
739 | m_listbox->SetStringSelection( "This" ); | |
740 | break; | |
741 | } | |
742 | case ID_LISTBOX_CLEAR: | |
743 | { | |
744 | m_listbox->Clear(); | |
745 | break; | |
746 | } | |
747 | case ID_LISTBOX_APPEND: | |
748 | { | |
749 | m_listbox->Append( "Hi!" ); | |
750 | break; | |
751 | } | |
752 | case ID_LISTBOX_DELETE: | |
753 | { | |
754 | int idx = m_listbox->GetSelection(); | |
755 | m_listbox->Delete( idx ); | |
756 | break; | |
757 | } | |
758 | case ID_LISTBOX_FONT: | |
759 | { | |
760 | m_listbox->SetFont( *wxITALIC_FONT ); | |
761 | m_checkbox->SetFont( *wxITALIC_FONT ); | |
762 | break; | |
763 | } | |
868a2826 | 764 | } |
47908e25 RR |
765 | } |
766 | ||
767 | void MyPanel::OnChoice( wxCommandEvent &event ) | |
768 | { | |
19da4326 | 769 | m_text->AppendText( "Choice event selection string is: " ); |
ec9f7884 VZ |
770 | m_text->AppendText( event.GetString() ); |
771 | m_text->AppendText( "\n" ); | |
19da4326 RR |
772 | m_text->AppendText( "Choice control selection string is: " ); |
773 | m_text->AppendText( m_choice->GetStringSelection() ); | |
774 | m_text->AppendText( "\n" ); | |
47908e25 RR |
775 | } |
776 | ||
777 | void MyPanel::OnChoiceButtons( wxCommandEvent &event ) | |
778 | { | |
ec9f7884 | 779 | switch (event.GetId()) |
47908e25 | 780 | { |
ec9f7884 VZ |
781 | case ID_CHOICE_ENABLE: |
782 | { | |
783 | m_choice->Enable( event.GetInt() == 0 ); | |
784 | break; | |
785 | } | |
786 | case ID_CHOICE_SEL_NUM: | |
787 | { | |
788 | m_choice->SetSelection( 2 ); | |
789 | break; | |
790 | } | |
791 | case ID_CHOICE_SEL_STR: | |
792 | { | |
793 | m_choice->SetStringSelection( "This" ); | |
794 | break; | |
795 | } | |
796 | case ID_CHOICE_CLEAR: | |
797 | { | |
798 | m_choice->Clear(); | |
799 | break; | |
800 | } | |
801 | case ID_CHOICE_APPEND: | |
802 | { | |
803 | m_choice->Append( "Hi!" ); | |
804 | break; | |
805 | } | |
806 | case ID_CHOICE_DELETE: | |
807 | { | |
808 | int idx = m_choice->GetSelection(); | |
809 | m_choice->Delete( idx ); | |
810 | break; | |
811 | } | |
812 | case ID_CHOICE_FONT: | |
813 | { | |
814 | m_choice->SetFont( *wxITALIC_FONT ); | |
815 | break; | |
816 | } | |
868a2826 | 817 | } |
47908e25 RR |
818 | } |
819 | ||
820 | void MyPanel::OnCombo( wxCommandEvent &event ) | |
821 | { | |
19da4326 | 822 | m_text->AppendText( "ComboBox event selection string is: " ); |
ec9f7884 VZ |
823 | m_text->AppendText( event.GetString() ); |
824 | m_text->AppendText( "\n" ); | |
19da4326 RR |
825 | m_text->AppendText( "ComboBox control selection string is: " ); |
826 | m_text->AppendText( m_combo->GetStringSelection() ); | |
827 | m_text->AppendText( "\n" ); | |
47908e25 RR |
828 | } |
829 | ||
830 | void MyPanel::OnComboButtons( wxCommandEvent &event ) | |
1c005ff7 | 831 | { |
ec9f7884 | 832 | switch (event.GetId()) |
2f6407b9 | 833 | { |
ec9f7884 VZ |
834 | case ID_COMBO_ENABLE: |
835 | { | |
836 | m_combo->Enable( event.GetInt() == 0 ); | |
837 | break; | |
838 | } | |
839 | case ID_COMBO_SEL_NUM: | |
840 | { | |
841 | m_combo->SetSelection( 2 ); | |
842 | break; | |
843 | } | |
844 | case ID_COMBO_SEL_STR: | |
845 | { | |
846 | m_combo->SetStringSelection( "This" ); | |
847 | break; | |
848 | } | |
849 | case ID_COMBO_CLEAR: | |
850 | { | |
851 | m_combo->Clear(); | |
852 | break; | |
853 | } | |
854 | case ID_COMBO_APPEND: | |
855 | { | |
856 | m_combo->Append( "Hi!" ); | |
857 | break; | |
858 | } | |
859 | case ID_COMBO_DELETE: | |
860 | { | |
861 | int idx = m_combo->GetSelection(); | |
862 | m_combo->Delete( idx ); | |
863 | break; | |
864 | } | |
865 | case ID_COMBO_FONT: | |
866 | { | |
867 | m_combo->SetFont( *wxITALIC_FONT ); | |
868 | break; | |
869 | } | |
868a2826 | 870 | } |
47908e25 RR |
871 | } |
872 | ||
873 | void MyPanel::OnRadio( wxCommandEvent &event ) | |
874 | { | |
ec9f7884 VZ |
875 | m_text->AppendText( "RadioBox selection string is: " ); |
876 | m_text->AppendText( event.GetString() ); | |
877 | m_text->AppendText( "\n" ); | |
47908e25 RR |
878 | } |
879 | ||
880 | void MyPanel::OnRadioButtons( wxCommandEvent &event ) | |
881 | { | |
ec9f7884 | 882 | switch (event.GetId()) |
d3904ceb | 883 | { |
ec9f7884 VZ |
884 | case ID_RADIOBOX_ENABLE: |
885 | { | |
886 | m_radio->Enable( event.GetInt() == 0 ); | |
887 | break; | |
888 | } | |
889 | case ID_RADIOBOX_SEL_NUM: | |
890 | { | |
891 | m_radio->SetSelection( 2 ); | |
892 | break; | |
893 | } | |
894 | case ID_RADIOBOX_SEL_STR: | |
895 | { | |
896 | m_radio->SetStringSelection( "This" ); | |
897 | break; | |
898 | } | |
899 | case ID_RADIOBOX_FONT: | |
900 | { | |
901 | m_radio->SetFont( *wxITALIC_FONT ); | |
902 | break; | |
903 | } | |
868a2826 | 904 | } |
1c005ff7 RR |
905 | } |
906 | ||
868a2826 RR |
907 | void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) ) |
908 | { | |
ec9f7884 VZ |
909 | m_fontButton->SetFont( *wxITALIC_FONT ); |
910 | m_text->SetFont( *wxITALIC_FONT ); | |
868a2826 RR |
911 | } |
912 | ||
7bce6aec RR |
913 | void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) |
914 | { | |
ec9f7884 | 915 | m_gauge->SetValue( m_slider->GetValue() ); |
7bce6aec RR |
916 | } |
917 | ||
2a47d3c1 | 918 | #ifndef __WIN16__ |
e380f72b RR |
919 | void MyPanel::OnSpinUpdate( wxSpinEvent &event ) |
920 | { | |
ec9f7884 | 921 | wxString value; |
f70d5829 | 922 | value.Printf( _T("%d"), event.GetPosition() ); |
ec9f7884 | 923 | m_spintext->SetValue( value ); |
6380910c | 924 | |
f70d5829 | 925 | value.Printf( _T("Spin control range: (%d, %d), current = %d\n"), |
6380910c VZ |
926 | m_spinbutton->GetMin(), m_spinbutton->GetMax(), |
927 | m_spinbutton->GetValue()); | |
928 | ||
929 | m_text->AppendText(value); | |
e380f72b | 930 | } |
2a47d3c1 | 931 | #endif |
e380f72b | 932 | |
2cb21a45 VZ |
933 | MyPanel::~MyPanel() |
934 | { | |
ec9f7884 | 935 | delete m_notebook->GetImageList(); |
2cb21a45 VZ |
936 | } |
937 | ||
1c005ff7 RR |
938 | //---------------------------------------------------------------------- |
939 | // MyFrame | |
940 | //---------------------------------------------------------------------- | |
941 | ||
942 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
ec9f7884 VZ |
943 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) |
944 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
16f6dfd8 | 945 | #if wxUSE_TOOLTIPS |
ec9f7884 VZ |
946 | EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay) |
947 | EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips) | |
16f6dfd8 | 948 | #endif // wxUSE_TOOLTIPS |
ec9f7884 VZ |
949 | EVT_SIZE(MyFrame::OnSize) |
950 | EVT_IDLE(MyFrame::OnIdle) | |
1c005ff7 RR |
951 | END_EVENT_TABLE() |
952 | ||
9f3362c4 | 953 | MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h) |
ec9f7884 | 954 | : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) |
1c005ff7 | 955 | { |
5fb9fcfc | 956 | CreateStatusBar(2); |
9f3362c4 VZ |
957 | |
958 | (void)new MyPanel( this, 10, 10, 300, 100 ); | |
1c005ff7 RR |
959 | } |
960 | ||
961 | void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) ) | |
962 | { | |
ec9f7884 | 963 | Close(TRUE); |
1c005ff7 RR |
964 | } |
965 | ||
966 | void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) | |
967 | { | |
ec9f7884 VZ |
968 | wxBeginBusyCursor(); |
969 | ||
970 | wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK ); | |
971 | dialog.ShowModal(); | |
972 | ||
973 | wxEndBusyCursor(); | |
1c005ff7 | 974 | } |
9f3362c4 | 975 | |
16f6dfd8 VZ |
976 | #if wxUSE_TOOLTIPS |
977 | void MyFrame::OnSetTooltipDelay(wxCommandEvent& event) | |
978 | { | |
979 | static long s_delay = 5000; | |
980 | ||
981 | wxString delay; | |
f70d5829 | 982 | delay.Printf( _T("%ld"), s_delay); |
16f6dfd8 VZ |
983 | |
984 | delay = wxGetTextFromUser("Enter delay (in milliseconds)", | |
ec9f7884 VZ |
985 | "Set tooltip delay", |
986 | delay, | |
987 | this); | |
16f6dfd8 VZ |
988 | if ( !delay ) |
989 | return; // cancelled | |
990 | ||
f70d5829 | 991 | wxSscanf(delay, _T("%ld"), &s_delay); |
16f6dfd8 VZ |
992 | |
993 | wxToolTip::SetDelay(s_delay); | |
994 | ||
f70d5829 | 995 | wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay); |
16f6dfd8 VZ |
996 | } |
997 | ||
998 | void MyFrame::OnToggleTooltips(wxCommandEvent& event) | |
999 | { | |
1000 | static bool s_enabled = TRUE; | |
1001 | ||
1002 | s_enabled = !s_enabled; | |
1003 | ||
1004 | wxToolTip::Enable(s_enabled); | |
1005 | ||
f70d5829 | 1006 | wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") ); |
16f6dfd8 VZ |
1007 | } |
1008 | #endif // tooltips | |
1009 | ||
5fb9fcfc VZ |
1010 | void MyFrame::OnSize( wxSizeEvent& event ) |
1011 | { | |
1012 | wxString msg; | |
f70d5829 | 1013 | msg.Printf( _("%dx%d"), event.GetSize().x, event.GetSize().y); |
5fb9fcfc VZ |
1014 | SetStatusText(msg, 1); |
1015 | ||
1016 | event.Skip(); | |
1017 | } | |
1018 | ||
9f3362c4 VZ |
1019 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
1020 | { | |
1021 | // track the window which has the focus in the status bar | |
1022 | static wxWindow *s_windowFocus = (wxWindow *)NULL; | |
1023 | wxWindow *focus = wxWindow::FindFocus(); | |
1024 | if ( focus && (focus != s_windowFocus) ) | |
1025 | { | |
1026 | s_windowFocus = focus; | |
1027 | ||
1028 | wxString msg; | |
f70d5829 | 1029 | msg.Printf( |
9f3362c4 | 1030 | #ifdef __WXMSW__ |
f70d5829 RR |
1031 | _T("Focus: wxWindow = %p, HWND = %08x"), |
1032 | #else | |
1033 | _T("Focus: wxWindow = %p"), | |
1034 | #endif | |
1035 | s_windowFocus | |
9f3362c4 | 1036 | #ifdef __WXMSW__ |
ec9f7884 | 1037 | , s_windowFocus->GetHWND() |
f70d5829 | 1038 | #endif |
9f3362c4 VZ |
1039 | ); |
1040 | ||
1041 | SetStatusText(msg); | |
1042 | } | |
341c92a8 | 1043 | } |