]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: controls.cpp | |
3 | // Purpose: Controls wxWindows sample | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Robert Roebling, Julian Smart | |
8 | // Licence: wxWindows license | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "controls.h" | |
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 | ||
26 | #include "wx/spinbutt.h" | |
27 | #include "wx/notebook.h" | |
28 | #include "wx/imaglist.h" | |
29 | #include "wx/spinbutt.h" | |
30 | #include "wx/clipbrd.h" | |
31 | ||
32 | #ifdef __WXGTK__ | |
33 | #include "wx/tooltip.h" | |
34 | #endif | |
35 | ||
36 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
37 | #define USE_XPM | |
38 | #endif | |
39 | ||
40 | #ifdef USE_XPM | |
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" | |
48 | #endif | |
49 | ||
50 | //---------------------------------------------------------------------- | |
51 | // class definitions | |
52 | //---------------------------------------------------------------------- | |
53 | ||
54 | class MyApp: public wxApp | |
55 | { | |
56 | public: | |
57 | bool OnInit(void); | |
58 | }; | |
59 | ||
60 | // a text ctrl which allows to call different wxTextCtrl functions | |
61 | // interactively by pressing function keys in it | |
62 | class MyTextCtrl : public wxTextCtrl | |
63 | { | |
64 | public: | |
65 | MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, | |
66 | const wxPoint &pos, const wxSize &size, int style = 0) | |
67 | : wxTextCtrl(parent, id, value, pos, size, style) { } | |
68 | ||
69 | void OnChar(wxKeyEvent& event); | |
70 | ||
71 | private: | |
72 | DECLARE_EVENT_TABLE() | |
73 | }; | |
74 | ||
75 | class MyPanel: public wxPanel | |
76 | { | |
77 | public: | |
78 | ||
79 | MyPanel(wxFrame *frame, int x, int y, int w, int h); | |
80 | virtual ~MyPanel(); | |
81 | ||
82 | void OnSize( wxSizeEvent& event ); | |
83 | void OnListBox( wxCommandEvent &event ); | |
84 | void OnListBoxDoubleClick( wxCommandEvent &event ); | |
85 | void OnListBoxButtons( wxCommandEvent &event ); | |
86 | void OnChoice( wxCommandEvent &event ); | |
87 | void OnChoiceButtons( wxCommandEvent &event ); | |
88 | void OnCombo( wxCommandEvent &event ); | |
89 | void OnComboButtons( wxCommandEvent &event ); | |
90 | void OnRadio( wxCommandEvent &event ); | |
91 | void OnRadioButtons( wxCommandEvent &event ); | |
92 | void OnSetFont( wxCommandEvent &event ); | |
93 | void OnPageChanged( wxNotebookEvent &event ); | |
94 | void OnSliderUpdate( wxCommandEvent &event ); | |
95 | void OnSpinUpdate( wxSpinEvent &event ); | |
96 | void OnPasteFromClipboard( wxCommandEvent &event ); | |
97 | void OnCopyToClipboard( wxCommandEvent &event ); | |
98 | void OnMoveToEndOfText( wxCommandEvent &event ); | |
99 | void OnMoveToEndOfEntry( wxCommandEvent &event ); | |
100 | ||
101 | wxListBox *m_listbox; | |
102 | wxChoice *m_choice; | |
103 | wxComboBox *m_combo; | |
104 | wxRadioBox *m_radio; | |
105 | wxGauge *m_gauge; | |
106 | wxSlider *m_slider; | |
107 | wxButton *m_fontButton; | |
108 | wxSpinButton *m_spinbutton; | |
109 | wxTextCtrl *m_spintext; | |
110 | MyTextCtrl *m_multitext; | |
111 | MyTextCtrl *m_textentry; | |
112 | wxCheckBox *m_checkbox; | |
113 | ||
114 | wxTextCtrl *m_text; | |
115 | wxNotebook *m_notebook; | |
116 | ||
117 | DECLARE_EVENT_TABLE() | |
118 | }; | |
119 | ||
120 | class MyFrame: public wxFrame | |
121 | { | |
122 | public: | |
123 | ||
124 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); | |
125 | ||
126 | public: | |
127 | ||
128 | void OnQuit(wxCommandEvent& event); | |
129 | void OnAbout(wxCommandEvent& event); | |
130 | bool OnClose(void) { return TRUE; } | |
131 | ||
132 | DECLARE_EVENT_TABLE() | |
133 | }; | |
134 | ||
135 | //---------------------------------------------------------------------- | |
136 | // main() | |
137 | //---------------------------------------------------------------------- | |
138 | ||
139 | IMPLEMENT_APP(MyApp) | |
140 | ||
141 | //---------------------------------------------------------------------- | |
142 | // MyApp | |
143 | //---------------------------------------------------------------------- | |
144 | ||
145 | const int MINIMAL_QUIT = 100; | |
146 | const int MINIMAL_TEXT = 101; | |
147 | const int MINIMAL_ABOUT = 102; | |
148 | ||
149 | bool MyApp::OnInit(void) | |
150 | { | |
151 | // Create the main frame window | |
152 | MyFrame *frame = new MyFrame((wxFrame *) NULL, | |
153 | "Controls wxWindows App", | |
154 | 50, 50, 530, 420); | |
155 | ||
156 | // Give it an icon | |
157 | // The wxICON() macros loads an icon from a resource under Windows | |
158 | // and uses an #included XPM image under GTK+ and Motif | |
159 | ||
160 | frame->SetIcon( wxICON(mondrian) ); | |
161 | ||
162 | wxMenu *file_menu = new wxMenu; | |
163 | ||
164 | file_menu->Append(MINIMAL_ABOUT, "&About"); | |
165 | file_menu->Append(MINIMAL_QUIT, "E&xit"); | |
166 | wxMenuBar *menu_bar = new wxMenuBar; | |
167 | menu_bar->Append(file_menu, "&File"); | |
168 | frame->SetMenuBar(menu_bar); | |
169 | ||
170 | frame->Show(TRUE); | |
171 | ||
172 | SetTopWindow(frame); | |
173 | ||
174 | return TRUE; | |
175 | } | |
176 | ||
177 | //---------------------------------------------------------------------- | |
178 | // MyTextCtrl | |
179 | //---------------------------------------------------------------------- | |
180 | ||
181 | BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl) | |
182 | EVT_CHAR(MyTextCtrl::OnChar) | |
183 | END_EVENT_TABLE() | |
184 | ||
185 | void MyTextCtrl::OnChar(wxKeyEvent& event) | |
186 | { | |
187 | switch ( event.KeyCode() ) | |
188 | { | |
189 | case WXK_F1: | |
190 | // show current position and text length | |
191 | { | |
192 | long line, column, pos = GetInsertionPoint(); | |
193 | PositionToXY(pos, &column, &line); | |
194 | ||
195 | wxLogMessage("Current position: %ld\n" | |
196 | "Current line, column: (%ld, %ld)\n" | |
197 | "Number of lines: %ld\n" | |
198 | "Current line length: %ld\n" | |
199 | "Total text length: %ld", | |
200 | pos, | |
201 | line, column, | |
202 | GetNumberOfLines(), | |
203 | GetLineLength(line), | |
204 | GetLastPosition()); | |
205 | } | |
206 | break; | |
207 | ||
208 | case WXK_F2: | |
209 | // go to the end | |
210 | SetInsertionPointEnd(); | |
211 | break; | |
212 | ||
213 | case WXK_F3: | |
214 | // go to position 10 | |
215 | SetInsertionPoint(10); | |
216 | break; | |
217 | ||
218 | default: | |
219 | event.Skip(); | |
220 | } | |
221 | } | |
222 | ||
223 | //---------------------------------------------------------------------- | |
224 | // MyPanel | |
225 | //---------------------------------------------------------------------- | |
226 | ||
227 | const int ID_NOTEBOOK = 1000; | |
228 | ||
229 | const int ID_LISTBOX = 130; | |
230 | const int ID_LISTBOX_SEL_NUM = 131; | |
231 | const int ID_LISTBOX_SEL_STR = 132; | |
232 | const int ID_LISTBOX_CLEAR = 133; | |
233 | const int ID_LISTBOX_APPEND = 134; | |
234 | const int ID_LISTBOX_DELETE = 135; | |
235 | const int ID_LISTBOX_FONT = 136; | |
236 | const int ID_LISTBOX_ENABLE = 137; | |
237 | ||
238 | const int ID_CHOICE = 120; | |
239 | const int ID_CHOICE_SEL_NUM = 121; | |
240 | const int ID_CHOICE_SEL_STR = 122; | |
241 | const int ID_CHOICE_CLEAR = 123; | |
242 | const int ID_CHOICE_APPEND = 124; | |
243 | const int ID_CHOICE_DELETE = 125; | |
244 | const int ID_CHOICE_FONT = 126; | |
245 | const int ID_CHOICE_ENABLE = 127; | |
246 | ||
247 | const int ID_COMBO = 140; | |
248 | const int ID_COMBO_SEL_NUM = 141; | |
249 | const int ID_COMBO_SEL_STR = 142; | |
250 | const int ID_COMBO_CLEAR = 143; | |
251 | const int ID_COMBO_APPEND = 144; | |
252 | const int ID_COMBO_DELETE = 145; | |
253 | const int ID_COMBO_FONT = 146; | |
254 | const int ID_COMBO_ENABLE = 147; | |
255 | ||
256 | const int ID_TEXT = 150; | |
257 | const int ID_PASTE_TEXT = 151; | |
258 | const int ID_COPY_TEXT = 152; | |
259 | const int ID_MOVE_END_ENTRY = 153; | |
260 | const int ID_MOVE_END_ZONE = 154; | |
261 | ||
262 | const int ID_RADIOBOX = 160; | |
263 | const int ID_RADIOBOX_SEL_NUM = 161; | |
264 | const int ID_RADIOBOX_SEL_STR = 162; | |
265 | const int ID_RADIOBOX_FONT = 163; | |
266 | const int ID_RADIOBOX_ENABLE = 164; | |
267 | ||
268 | const int ID_RADIOBUTTON_1 = 166; | |
269 | const int ID_RADIOBUTTON_2 = 167; | |
270 | ||
271 | const int ID_SET_FONT = 170; | |
272 | ||
273 | const int ID_GAUGE = 180; | |
274 | const int ID_SLIDER = 181; | |
275 | ||
276 | const int ID_SPIN = 182; | |
277 | ||
278 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) | |
279 | EVT_SIZE ( MyPanel::OnSize) | |
280 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged) | |
281 | EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) | |
282 | EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick) | |
283 | EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons) | |
284 | EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons) | |
285 | EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons) | |
286 | EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons) | |
287 | EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons) | |
288 | EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons) | |
289 | EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons) | |
290 | EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice) | |
291 | EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons) | |
292 | EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons) | |
293 | EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons) | |
294 | EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons) | |
295 | EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons) | |
296 | EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons) | |
297 | EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons) | |
298 | EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo) | |
299 | EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons) | |
300 | EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons) | |
301 | EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons) | |
302 | EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons) | |
303 | EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons) | |
304 | EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons) | |
305 | EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons) | |
306 | EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio) | |
307 | EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons) | |
308 | EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons) | |
309 | EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons) | |
310 | EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons) | |
311 | EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) | |
312 | EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) | |
313 | EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) | |
314 | EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard) | |
315 | EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard) | |
316 | EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText) | |
317 | EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry) | |
318 | END_EVENT_TABLE() | |
319 | ||
320 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : | |
321 | wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ) | |
322 | { | |
323 | // SetBackgroundColour("cadet blue"); | |
324 | ||
325 | m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); | |
326 | // m_text->SetBackgroundColour("wheat"); | |
327 | ||
328 | m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) ); | |
329 | ||
330 | wxString choices[] = | |
331 | { | |
332 | "This", | |
333 | "is one of my", | |
334 | "really", | |
335 | "wonderful", | |
336 | "examples." | |
337 | }; | |
338 | ||
339 | #ifdef USE_XPM | |
340 | // image ids | |
341 | enum | |
342 | { | |
343 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max | |
344 | }; | |
345 | ||
346 | // fill the image list | |
347 | wxImageList *imagelist = new wxImageList(32, 32); | |
348 | ||
349 | imagelist-> Add( wxBitmap( list_xpm )); | |
350 | imagelist-> Add( wxBitmap( choice_xpm )); | |
351 | imagelist-> Add( wxBitmap( combo_xpm )); | |
352 | imagelist-> Add( wxBitmap( text_xpm )); | |
353 | imagelist-> Add( wxBitmap( radio_xpm )); | |
354 | imagelist-> Add( wxBitmap( gauge_xpm )); | |
355 | m_notebook->SetImageList(imagelist); | |
356 | #elif defined(__WXMSW__) | |
357 | // load images from resources | |
358 | enum | |
359 | { | |
360 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max | |
361 | }; | |
362 | wxImageList *imagelist = new wxImageList(32, 32, FALSE, Image_Max); | |
363 | ||
364 | static const char *s_iconNames[Image_Max] = | |
365 | { | |
366 | "list", "choice", "combo", "text", "radio", "gauge" | |
367 | }; | |
368 | ||
369 | for ( size_t n = 0; n < Image_Max; n++ ) | |
370 | { | |
371 | wxBitmap bmp(s_iconNames[n]); | |
372 | if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) ) | |
373 | { | |
374 | wxLogWarning("Couldn't load the image '%s' for the notebook page %d.", | |
375 | s_iconNames[n], n); | |
376 | } | |
377 | } | |
378 | ||
379 | m_notebook->SetImageList(imagelist); | |
380 | #else | |
381 | ||
382 | // No images for now | |
383 | #define Image_List -1 | |
384 | #define Image_Choice -1 | |
385 | #define Image_Combo -1 | |
386 | #define Image_Text -1 | |
387 | #define Image_Radio -1 | |
388 | #define Image_Gauge -1 | |
389 | #define Image_Max -1 | |
390 | ||
391 | #endif | |
392 | ||
393 | wxButton *button = (wxButton*)NULL; | |
394 | ||
395 | // m_notebook->SetBackgroundColour("cadet blue"); | |
396 | ||
397 | wxPanel *panel = (wxPanel*) NULL; | |
398 | ||
399 | panel = new wxPanel(m_notebook); | |
400 | // panel->SetBackgroundColour("cadet blue"); | |
401 | // panel->SetForegroundColour("blue"); | |
402 | m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices ); | |
403 | #ifdef __WXGTK__ | |
404 | m_listbox->SetToolTip( "This is a list box" ); | |
405 | #endif | |
406 | // m_listbox->SetBackgroundColour("wheat"); | |
407 | (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); | |
408 | (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
409 | (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
410 | (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
411 | (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
412 | button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
413 | #ifdef __WXGTK__ | |
414 | button->SetToolTip( "Press here to set italic font" ); | |
415 | #endif | |
416 | ||
417 | // button->SetForegroundColour( "red" ); | |
418 | m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
419 | m_checkbox->SetValue(FALSE); | |
420 | #ifdef __WXGTK__ | |
421 | m_checkbox->SetToolTip( "Click here to disable the listbox" ); | |
422 | #endif | |
423 | m_notebook->AddPage(panel, "wxList", TRUE, Image_List); | |
424 | ||
425 | panel = new wxPanel(m_notebook); | |
426 | // panel->SetBackgroundColour("cadet blue"); | |
427 | // panel->SetForegroundColour("blue"); | |
428 | m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices ); | |
429 | // m_choice->SetBackgroundColour("wheat"); | |
430 | (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); | |
431 | (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
432 | (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
433 | (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
434 | (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
435 | (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
436 | (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
437 | m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); | |
438 | ||
439 | panel = new wxPanel(m_notebook); | |
440 | // panel->SetBackgroundColour("cadet blue"); | |
441 | // panel->SetForegroundColour("blue"); | |
442 | m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices ); | |
443 | // m_combo->SetBackgroundColour("wheat"); | |
444 | (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); | |
445 | (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); | |
446 | (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); | |
447 | (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); | |
448 | (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); | |
449 | (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); | |
450 | (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); | |
451 | m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo); | |
452 | ||
453 | panel = new wxPanel(m_notebook); | |
454 | // panel->SetBackgroundColour("cadet blue"); | |
455 | // panel->SetForegroundColour("blue"); | |
456 | m_textentry = new MyTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28)); | |
457 | (*m_textentry) << " More text."; | |
458 | // m_textentry->SetBackgroundColour("wheat"); | |
459 | m_multitext = new MyTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE ); | |
460 | (*m_multitext) << " More text." | |
461 | << "\nPress Fn keys to test different wxTextCtrl functions"; | |
462 | // m_multitext->SetBackgroundColour("wheat"); | |
463 | (void)new wxStaticBox( panel, -1, "Move cursor to the end of:", | |
464 | wxPoint(345, 0), wxSize(160, 100) ); | |
465 | (void)new wxButton(panel, ID_MOVE_END_ENTRY, "Text entry", | |
466 | wxPoint(370, 20), wxSize(110, 30)); | |
467 | (void)new wxButton(panel, ID_MOVE_END_ZONE, "Text zone", | |
468 | wxPoint(370, 60), wxSize(110, 30)); | |
469 | (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,120), wxSize(160,100) ); | |
470 | (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,140), wxSize(110,30) ); | |
471 | (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,180), wxSize(110,30) ); | |
472 | m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text); | |
473 | ||
474 | wxString choices2[] = | |
475 | { | |
476 | "Wonderful", | |
477 | "examples.", | |
478 | }; | |
479 | ||
480 | panel = new wxPanel(m_notebook); | |
481 | // panel->SetBackgroundColour("cadet blue"); | |
482 | // panel->SetForegroundColour("blue"); | |
483 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS ); | |
484 | // m_radio->SetBackgroundColour("wheat"); | |
485 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS ); | |
486 | // m_radio->SetBackgroundColour("wheat"); | |
487 | (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); | |
488 | (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); | |
489 | m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) ); | |
490 | // m_fontButton->SetForegroundColour("blue"); | |
491 | (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) ); | |
492 | (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); | |
493 | wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) ); | |
494 | rb->SetValue( FALSE ); | |
495 | (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) ); | |
496 | m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); | |
497 | ||
498 | panel = new wxPanel(m_notebook); | |
499 | // panel->SetBackgroundColour("cadet blue"); | |
500 | // panel->SetForegroundColour("blue"); | |
501 | (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) ); | |
502 | m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) ); | |
503 | // m_gauge->SetBackgroundColour("wheat"); | |
504 | m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) ); | |
505 | // m_slider->SetBackgroundColour("wheat"); | |
506 | (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) ); | |
507 | #ifdef __WXMOTIF__ | |
508 | // No wrapping text in wxStaticText yet :-( | |
509 | (void)new wxStaticText( panel, -1, | |
510 | "Drag the slider!", | |
511 | wxPoint(208,30), | |
512 | wxSize(210, -1) | |
513 | ); | |
514 | #else | |
515 | (void)new wxStaticText( panel, -1, | |
516 | "In order see the gauge (aka progress bar)\n" | |
517 | "control do something you have to drag the\n" | |
518 | "handle of the slider to the right.\n" | |
519 | "\n" | |
520 | "This is also supposed to demonstrate how\n" | |
521 | "to use static controls.\n", | |
522 | wxPoint(208,25), | |
523 | wxSize(210, 110) | |
524 | ); | |
525 | #endif | |
526 | m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) ); | |
527 | // m_spintext->SetBackgroundColour("wheat"); | |
528 | m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) ); | |
529 | // m_spinbutton->SetBackgroundColour("wheat"); | |
530 | m_spinbutton->SetRange(0,100); | |
531 | ||
532 | m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); | |
533 | } | |
534 | ||
535 | void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) ) | |
536 | { | |
537 | #ifdef __WXGTK__ | |
538 | ||
539 | if (!wxTheClipboard->Open()) | |
540 | { | |
541 | *m_text << "Error opening the clipboard." << "\n"; | |
542 | ||
543 | return; | |
544 | } | |
545 | else | |
546 | { | |
547 | *m_text << "Successfully opened the clipboard." << "\n"; | |
548 | } | |
549 | ||
550 | wxTextDataObject *data = new wxTextDataObject(); | |
551 | ||
552 | if (wxTheClipboard->GetData( data )) | |
553 | { | |
554 | *m_text << "Successfully retrieved data from the clipboard." << "\n"; | |
555 | *m_multitext << data->GetText() << "\n"; | |
556 | } | |
557 | else | |
558 | { | |
559 | *m_text << "Error getting data from the clipboard." << "\n"; | |
560 | } | |
561 | ||
562 | wxTheClipboard->Close(); | |
563 | ||
564 | *m_text << "Closed the clipboard." << "\n"; | |
565 | ||
566 | delete data; | |
567 | ||
568 | #endif | |
569 | } | |
570 | ||
571 | void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) ) | |
572 | { | |
573 | #ifdef __WXGTK__ | |
574 | ||
575 | wxString text( m_multitext->GetLineText(0) ); | |
576 | ||
577 | if (text.IsEmpty()) return; | |
578 | ||
579 | if (!wxTheClipboard->Open()) | |
580 | { | |
581 | *m_text << "Error opening the clipboard." << "\n"; | |
582 | ||
583 | return; | |
584 | } | |
585 | else | |
586 | { | |
587 | *m_text << "Successfully opened the clipboard." << "\n"; | |
588 | } | |
589 | ||
590 | wxTextDataObject *data = new wxTextDataObject( text ); | |
591 | wxDataBroker *broker = new wxDataBroker(); | |
592 | broker->Add( data ); | |
593 | ||
594 | if (!wxTheClipboard->SetData( broker )) | |
595 | { | |
596 | *m_text << "Error while copying to the clipboard." << "\n"; | |
597 | } | |
598 | else | |
599 | { | |
600 | *m_text << "Successfully copied data to the clipboard." << "\n"; | |
601 | } | |
602 | ||
603 | wxTheClipboard->Close(); | |
604 | ||
605 | *m_text << "Closed the clipboard." << "\n"; | |
606 | ||
607 | #endif | |
608 | } | |
609 | ||
610 | void MyPanel::OnMoveToEndOfText( wxCommandEvent &event ) | |
611 | { | |
612 | m_multitext->SetInsertionPointEnd(); | |
613 | m_multitext->SetFocus(); | |
614 | } | |
615 | ||
616 | void MyPanel::OnMoveToEndOfEntry( wxCommandEvent &event ) | |
617 | { | |
618 | m_textentry->SetInsertionPointEnd(); | |
619 | m_textentry->SetFocus(); | |
620 | } | |
621 | ||
622 | void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) | |
623 | { | |
624 | int x = 0; | |
625 | int y = 0; | |
626 | GetClientSize( &x, &y ); | |
627 | ||
628 | if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 ); | |
629 | if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 ); | |
630 | } | |
631 | ||
632 | void MyPanel::OnPageChanged( wxNotebookEvent &event ) | |
633 | { | |
634 | *m_text << "Notebook selection is " << event.GetSelection() << "\n"; | |
635 | } | |
636 | ||
637 | void MyPanel::OnListBox( wxCommandEvent &event ) | |
638 | { | |
639 | m_text->WriteText( "ListBox selection string is: " ); | |
640 | m_text->WriteText( event.GetString() ); | |
641 | m_text->WriteText( "\n" ); | |
642 | } | |
643 | ||
644 | void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event ) | |
645 | { | |
646 | m_text->WriteText( "ListBox double click string is: " ); | |
647 | m_text->WriteText( event.GetString() ); | |
648 | m_text->WriteText( "\n" ); | |
649 | } | |
650 | ||
651 | void MyPanel::OnListBoxButtons( wxCommandEvent &event ) | |
652 | { | |
653 | switch (event.GetId()) | |
654 | { | |
655 | case ID_LISTBOX_ENABLE: | |
656 | { | |
657 | m_text->WriteText("Checkbox clicked.\n"); | |
658 | m_listbox->Enable( event.GetInt() == 0 ); | |
659 | break; | |
660 | } | |
661 | case ID_LISTBOX_SEL_NUM: | |
662 | { | |
663 | m_listbox->SetSelection( 2 ); | |
664 | break; | |
665 | } | |
666 | case ID_LISTBOX_SEL_STR: | |
667 | { | |
668 | m_listbox->SetStringSelection( "This" ); | |
669 | break; | |
670 | } | |
671 | case ID_LISTBOX_CLEAR: | |
672 | { | |
673 | m_listbox->Clear(); | |
674 | break; | |
675 | } | |
676 | case ID_LISTBOX_APPEND: | |
677 | { | |
678 | m_listbox->Append( "Hi!" ); | |
679 | break; | |
680 | } | |
681 | case ID_LISTBOX_DELETE: | |
682 | { | |
683 | int idx = m_listbox->GetSelection(); | |
684 | m_listbox->Delete( idx ); | |
685 | break; | |
686 | } | |
687 | case ID_LISTBOX_FONT: | |
688 | { | |
689 | m_listbox->SetFont( *wxITALIC_FONT ); | |
690 | m_checkbox->SetFont( *wxITALIC_FONT ); | |
691 | break; | |
692 | } | |
693 | } | |
694 | } | |
695 | ||
696 | void MyPanel::OnChoice( wxCommandEvent &event ) | |
697 | { | |
698 | m_text->WriteText( "Choice selection string is: " ); | |
699 | m_text->WriteText( event.GetString() ); | |
700 | m_text->WriteText( "\n" ); | |
701 | } | |
702 | ||
703 | void MyPanel::OnChoiceButtons( wxCommandEvent &event ) | |
704 | { | |
705 | switch (event.GetId()) | |
706 | { | |
707 | case ID_CHOICE_ENABLE: | |
708 | { | |
709 | m_choice->Enable( event.GetInt() == 0 ); | |
710 | break; | |
711 | } | |
712 | case ID_CHOICE_SEL_NUM: | |
713 | { | |
714 | m_choice->SetSelection( 2 ); | |
715 | break; | |
716 | } | |
717 | case ID_CHOICE_SEL_STR: | |
718 | { | |
719 | m_choice->SetStringSelection( "This" ); | |
720 | break; | |
721 | } | |
722 | case ID_CHOICE_CLEAR: | |
723 | { | |
724 | m_choice->Clear(); | |
725 | break; | |
726 | } | |
727 | case ID_CHOICE_APPEND: | |
728 | { | |
729 | m_choice->Append( "Hi!" ); | |
730 | break; | |
731 | } | |
732 | case ID_CHOICE_DELETE: | |
733 | { | |
734 | int idx = m_choice->GetSelection(); | |
735 | m_choice->Delete( idx ); | |
736 | break; | |
737 | } | |
738 | case ID_CHOICE_FONT: | |
739 | { | |
740 | m_choice->SetFont( *wxITALIC_FONT ); | |
741 | break; | |
742 | } | |
743 | } | |
744 | } | |
745 | ||
746 | void MyPanel::OnCombo( wxCommandEvent &event ) | |
747 | { | |
748 | m_text->WriteText( "ComboBox selection string is: " ); | |
749 | m_text->WriteText( event.GetString() ); | |
750 | m_text->WriteText( "\n" ); | |
751 | } | |
752 | ||
753 | void MyPanel::OnComboButtons( wxCommandEvent &event ) | |
754 | { | |
755 | switch (event.GetId()) | |
756 | { | |
757 | case ID_COMBO_ENABLE: | |
758 | { | |
759 | m_combo->Enable( event.GetInt() == 0 ); | |
760 | break; | |
761 | } | |
762 | case ID_COMBO_SEL_NUM: | |
763 | { | |
764 | m_combo->SetSelection( 2 ); | |
765 | break; | |
766 | } | |
767 | case ID_COMBO_SEL_STR: | |
768 | { | |
769 | m_combo->SetStringSelection( "This" ); | |
770 | break; | |
771 | } | |
772 | case ID_COMBO_CLEAR: | |
773 | { | |
774 | m_combo->Clear(); | |
775 | break; | |
776 | } | |
777 | case ID_COMBO_APPEND: | |
778 | { | |
779 | m_combo->Append( "Hi!" ); | |
780 | break; | |
781 | } | |
782 | case ID_COMBO_DELETE: | |
783 | { | |
784 | int idx = m_combo->GetSelection(); | |
785 | m_combo->Delete( idx ); | |
786 | break; | |
787 | } | |
788 | case ID_COMBO_FONT: | |
789 | { | |
790 | m_combo->SetFont( *wxITALIC_FONT ); | |
791 | break; | |
792 | } | |
793 | } | |
794 | } | |
795 | ||
796 | void MyPanel::OnRadio( wxCommandEvent &event ) | |
797 | { | |
798 | m_text->WriteText( "RadioBox selection string is: " ); | |
799 | m_text->WriteText( event.GetString() ); | |
800 | m_text->WriteText( "\n" ); | |
801 | } | |
802 | ||
803 | void MyPanel::OnRadioButtons( wxCommandEvent &event ) | |
804 | { | |
805 | switch (event.GetId()) | |
806 | { | |
807 | case ID_RADIOBOX_ENABLE: | |
808 | { | |
809 | m_radio->Enable( event.GetInt() == 0 ); | |
810 | break; | |
811 | } | |
812 | case ID_RADIOBOX_SEL_NUM: | |
813 | { | |
814 | m_radio->SetSelection( 2 ); | |
815 | break; | |
816 | } | |
817 | case ID_RADIOBOX_SEL_STR: | |
818 | { | |
819 | m_radio->SetStringSelection( "This" ); | |
820 | break; | |
821 | } | |
822 | case ID_RADIOBOX_FONT: | |
823 | { | |
824 | m_radio->SetFont( *wxITALIC_FONT ); | |
825 | break; | |
826 | } | |
827 | } | |
828 | } | |
829 | ||
830 | void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) ) | |
831 | { | |
832 | m_fontButton->SetFont( *wxITALIC_FONT ); | |
833 | m_text->SetFont( *wxITALIC_FONT ); | |
834 | } | |
835 | ||
836 | void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) | |
837 | { | |
838 | m_gauge->SetValue( m_slider->GetValue() ); | |
839 | } | |
840 | ||
841 | void MyPanel::OnSpinUpdate( wxSpinEvent &event ) | |
842 | { | |
843 | wxString value; | |
844 | value.sprintf( "%d", (int)event.GetPosition() ); | |
845 | m_spintext->SetValue( value ); | |
846 | } | |
847 | ||
848 | MyPanel::~MyPanel() | |
849 | { | |
850 | delete m_notebook->GetImageList(); | |
851 | } | |
852 | ||
853 | //---------------------------------------------------------------------- | |
854 | // MyFrame | |
855 | //---------------------------------------------------------------------- | |
856 | ||
857 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
858 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) | |
859 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
860 | END_EVENT_TABLE() | |
861 | ||
862 | MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): | |
863 | wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
864 | { | |
865 | (void)new MyPanel( this, 10, 10, 300, 100 ); | |
866 | } | |
867 | ||
868 | void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) ) | |
869 | { | |
870 | Close(TRUE); | |
871 | } | |
872 | ||
873 | void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) | |
874 | { | |
875 | wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK ); | |
876 | dialog.ShowModal(); | |
877 | } |