]>
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__ | |
e4a81a2e | 12 | #pragma implementation "controls.h" |
1c005ff7 RR |
13 | #endif |
14 | ||
15 | // For compilers that support precompilation, includes "wx/wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/wx.h" | |
24 | #endif | |
25 | ||
4fabb575 | 26 | #include "wx/spinbutt.h" |
53b28675 | 27 | #include "wx/notebook.h" |
2cb21a45 | 28 | #include "wx/imaglist.h" |
655822f3 | 29 | #include "wx/spinbutt.h" |
b527aac5 | 30 | #include "wx/clipbrd.h" |
c330a2cf JS |
31 | |
32 | #ifdef __WXGTK__ | |
90b1b133 | 33 | #include "wx/tooltip.h" |
c330a2cf | 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 | ||
1c005ff7 RR |
50 | //---------------------------------------------------------------------- |
51 | // class definitions | |
52 | //---------------------------------------------------------------------- | |
53 | ||
54 | class MyApp: public wxApp | |
655822f3 | 55 | { |
1c005ff7 RR |
56 | public: |
57 | bool OnInit(void); | |
58 | }; | |
59 | ||
6085b116 VZ |
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 | ||
1c005ff7 RR |
75 | class MyPanel: public wxPanel |
76 | { | |
77 | public: | |
655822f3 | 78 | |
1c005ff7 | 79 | MyPanel(wxFrame *frame, int x, int y, int w, int h); |
2cb21a45 | 80 | virtual ~MyPanel(); |
655822f3 | 81 | |
1c005ff7 RR |
82 | void OnSize( wxSizeEvent& event ); |
83 | void OnListBox( wxCommandEvent &event ); | |
5b077d48 | 84 | void OnListBoxDoubleClick( wxCommandEvent &event ); |
1c005ff7 | 85 | void OnListBoxButtons( wxCommandEvent &event ); |
47908e25 RR |
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 ); | |
868a2826 | 92 | void OnSetFont( wxCommandEvent &event ); |
cb43b372 | 93 | void OnPageChanged( wxNotebookEvent &event ); |
7bce6aec | 94 | void OnSliderUpdate( wxCommandEvent &event ); |
e380f72b | 95 | void OnSpinUpdate( wxSpinEvent &event ); |
b527aac5 RR |
96 | void OnPasteFromClipboard( wxCommandEvent &event ); |
97 | void OnCopyToClipboard( wxCommandEvent &event ); | |
d59051dd VZ |
98 | void OnMoveToEndOfText( wxCommandEvent &event ); |
99 | void OnMoveToEndOfEntry( wxCommandEvent &event ); | |
655822f3 | 100 | |
e380f72b RR |
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; | |
6085b116 VZ |
110 | MyTextCtrl *m_multitext; |
111 | MyTextCtrl *m_textentry; | |
ae0bdb01 | 112 | wxCheckBox *m_checkbox; |
655822f3 | 113 | |
e380f72b | 114 | wxTextCtrl *m_text; |
655822f3 VZ |
115 | wxNotebook *m_notebook; |
116 | ||
117 | DECLARE_EVENT_TABLE() | |
1c005ff7 RR |
118 | }; |
119 | ||
120 | class MyFrame: public wxFrame | |
121 | { | |
122 | public: | |
655822f3 | 123 | |
1c005ff7 | 124 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); |
655822f3 | 125 | |
1c005ff7 | 126 | public: |
655822f3 | 127 | |
1c005ff7 RR |
128 | void OnQuit(wxCommandEvent& event); |
129 | void OnAbout(wxCommandEvent& event); | |
130 | bool OnClose(void) { return TRUE; } | |
655822f3 VZ |
131 | |
132 | DECLARE_EVENT_TABLE() | |
1c005ff7 RR |
133 | }; |
134 | ||
135 | //---------------------------------------------------------------------- | |
136 | // main() | |
137 | //---------------------------------------------------------------------- | |
138 | ||
d59051dd | 139 | IMPLEMENT_APP(MyApp) |
1c005ff7 RR |
140 | |
141 | //---------------------------------------------------------------------- | |
142 | // MyApp | |
143 | //---------------------------------------------------------------------- | |
144 | ||
c67daf87 UR |
145 | const int MINIMAL_QUIT = 100; |
146 | const int MINIMAL_TEXT = 101; | |
147 | const int MINIMAL_ABOUT = 102; | |
1c005ff7 RR |
148 | |
149 | bool MyApp::OnInit(void) | |
150 | { | |
151 | // Create the main frame window | |
655822f3 VZ |
152 | MyFrame *frame = new MyFrame((wxFrame *) NULL, |
153 | "Controls wxWindows App", | |
154 | 50, 50, 530, 420); | |
155 | ||
1c005ff7 | 156 | // Give it an icon |
e52f60e6 RR |
157 | // The wxICON() macros loads an icon from a resource under Windows |
158 | // and uses an #included XPM image under GTK+ and Motif | |
655822f3 | 159 | |
e52f60e6 | 160 | frame->SetIcon( wxICON(mondrian) ); |
1c005ff7 RR |
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); | |
655822f3 | 171 | |
1c005ff7 RR |
172 | SetTopWindow(frame); |
173 | ||
174 | return TRUE; | |
175 | } | |
176 | ||
6085b116 VZ |
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 | ||
1c005ff7 RR |
223 | //---------------------------------------------------------------------- |
224 | // MyPanel | |
225 | //---------------------------------------------------------------------- | |
226 | ||
4fabb575 | 227 | const int ID_NOTEBOOK = 1000; |
1c005ff7 | 228 | |
4fabb575 JS |
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; | |
1c005ff7 | 237 | |
4fabb575 JS |
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; | |
53010e52 | 246 | |
4fabb575 JS |
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; | |
53010e52 | 255 | |
4fabb575 | 256 | const int ID_TEXT = 150; |
b527aac5 RR |
257 | const int ID_PASTE_TEXT = 151; |
258 | const int ID_COPY_TEXT = 152; | |
d59051dd VZ |
259 | const int ID_MOVE_END_ENTRY = 153; |
260 | const int ID_MOVE_END_ZONE = 154; | |
219f895a | 261 | |
4fabb575 JS |
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; | |
868a2826 | 267 | |
f5d29b39 RR |
268 | const int ID_RADIOBUTTON_1 = 166; |
269 | const int ID_RADIOBUTTON_2 = 167; | |
270 | ||
4fabb575 | 271 | const int ID_SET_FONT = 170; |
47908e25 | 272 | |
4fabb575 JS |
273 | const int ID_GAUGE = 180; |
274 | const int ID_SLIDER = 181; | |
58614078 | 275 | |
4fabb575 | 276 | const int ID_SPIN = 182; |
e380f72b | 277 | |
1c005ff7 | 278 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
cb43b372 | 279 | EVT_SIZE ( MyPanel::OnSize) |
655822f3 | 280 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged) |
cb43b372 | 281 | EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) |
5b077d48 | 282 | EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick) |
cb43b372 RR |
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) | |
b1170810 | 298 | EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo) |
cb43b372 RR |
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) | |
7bce6aec | 312 | EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) |
e380f72b | 313 | EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) |
b527aac5 RR |
314 | EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard) |
315 | EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard) | |
d59051dd VZ |
316 | EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText) |
317 | EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry) | |
1c005ff7 RR |
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 | { | |
5b077d48 | 323 | // SetBackgroundColour("cadet blue"); |
a81258be | 324 | |
1c005ff7 | 325 | m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); |
5b077d48 | 326 | // m_text->SetBackgroundColour("wheat"); |
655822f3 | 327 | |
53b28675 | 328 | m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) ); |
655822f3 | 329 | |
53010e52 | 330 | wxString choices[] = |
1c005ff7 RR |
331 | { |
332 | "This", | |
c67d8618 RR |
333 | "is one of my", |
334 | "really", | |
e8435fa3 | 335 | "wonderful", |
9838df2c | 336 | "examples." |
1c005ff7 | 337 | }; |
655822f3 | 338 | |
4fabb575 | 339 | #ifdef USE_XPM |
73c700fd | 340 | // image ids |
2cb21a45 VZ |
341 | enum |
342 | { | |
58614078 | 343 | Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max |
2cb21a45 | 344 | }; |
655822f3 | 345 | |
fc54776e | 346 | // fill the image list |
2cb21a45 | 347 | wxImageList *imagelist = new wxImageList(32, 32); |
4fabb575 | 348 | |
35178437 RR |
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 )); | |
73c700fd VZ |
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 | ||
4fabb575 JS |
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 | ||
fc54776e | 391 | #endif |
2cb21a45 | 392 | |
a81258be RR |
393 | wxButton *button = (wxButton*)NULL; |
394 | ||
5b077d48 | 395 | // m_notebook->SetBackgroundColour("cadet blue"); |
2cb21a45 | 396 | |
58614078 | 397 | wxPanel *panel = (wxPanel*) NULL; |
9838df2c | 398 | |
58614078 | 399 | panel = new wxPanel(m_notebook); |
5b077d48 RR |
400 | // panel->SetBackgroundColour("cadet blue"); |
401 | // panel->SetForegroundColour("blue"); | |
c67d8618 | 402 | m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices ); |
b1170810 RR |
403 | #ifdef __WXGTK__ |
404 | m_listbox->SetToolTip( "This is a list box" ); | |
405 | #endif | |
5b077d48 | 406 | // m_listbox->SetBackgroundColour("wheat"); |
d3904ceb RR |
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) ); | |
f96aa4d9 | 409 | (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); |
d3904ceb | 410 | (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); |
30f82ea4 | 411 | (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); |
a81258be | 412 | button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); |
c330a2cf | 413 | #ifdef __WXGTK__ |
b1170810 | 414 | button->SetToolTip( "Press here to set italic font" ); |
c330a2cf | 415 | #endif |
b1170810 | 416 | |
5b077d48 | 417 | // button->SetForegroundColour( "red" ); |
ae0bdb01 | 418 | m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); |
8bf45ed1 | 419 | m_checkbox->SetValue(FALSE); |
b1170810 RR |
420 | #ifdef __WXGTK__ |
421 | m_checkbox->SetToolTip( "Click here to disable the listbox" ); | |
422 | #endif | |
9838df2c | 423 | m_notebook->AddPage(panel, "wxList", TRUE, Image_List); |
655822f3 | 424 | |
4bf58c62 | 425 | panel = new wxPanel(m_notebook); |
5b077d48 RR |
426 | // panel->SetBackgroundColour("cadet blue"); |
427 | // panel->SetForegroundColour("blue"); | |
c67d8618 | 428 | m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices ); |
5b077d48 | 429 | // m_choice->SetBackgroundColour("wheat"); |
d3904ceb RR |
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) ); | |
2f6407b9 | 434 | (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); |
d3904ceb RR |
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) ); | |
2cb21a45 | 437 | m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); |
655822f3 | 438 | |
4bf58c62 | 439 | panel = new wxPanel(m_notebook); |
5b077d48 RR |
440 | // panel->SetBackgroundColour("cadet blue"); |
441 | // panel->SetForegroundColour("blue"); | |
c67d8618 | 442 | m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices ); |
5b077d48 | 443 | // m_combo->SetBackgroundColour("wheat"); |
d3904ceb RR |
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) ); | |
2f6407b9 | 448 | (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); |
d3904ceb RR |
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) ); | |
2cb21a45 | 451 | m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo); |
655822f3 | 452 | |
f96aa4d9 | 453 | panel = new wxPanel(m_notebook); |
5b077d48 RR |
454 | // panel->SetBackgroundColour("cadet blue"); |
455 | // panel->SetForegroundColour("blue"); | |
6085b116 | 456 | m_textentry = new MyTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28)); |
d59051dd VZ |
457 | (*m_textentry) << " More text."; |
458 | // m_textentry->SetBackgroundColour("wheat"); | |
6085b116 VZ |
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"; | |
b1170810 | 462 | // m_multitext->SetBackgroundColour("wheat"); |
d59051dd VZ |
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) ); | |
f96aa4d9 | 472 | m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text); |
655822f3 | 473 | |
e5403d7c RR |
474 | wxString choices2[] = |
475 | { | |
476 | "Wonderful", | |
477 | "examples.", | |
478 | }; | |
655822f3 | 479 | |
47908e25 | 480 | panel = new wxPanel(m_notebook); |
5b077d48 RR |
481 | // panel->SetBackgroundColour("cadet blue"); |
482 | // panel->SetForegroundColour("blue"); | |
94b49b93 | 483 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS ); |
5b077d48 | 484 | // m_radio->SetBackgroundColour("wheat"); |
94b49b93 | 485 | m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS ); |
5b077d48 | 486 | // m_radio->SetBackgroundColour("wheat"); |
d3904ceb RR |
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) ); | |
b527aac5 | 489 | m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) ); |
5b077d48 | 490 | // m_fontButton->SetForegroundColour("blue"); |
b527aac5 | 491 | (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) ); |
e5403d7c | 492 | (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); |
f5d29b39 RR |
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) ); | |
2cb21a45 | 496 | m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); |
655822f3 | 497 | |
c67d8618 | 498 | panel = new wxPanel(m_notebook); |
5b077d48 RR |
499 | // panel->SetBackgroundColour("cadet blue"); |
500 | // panel->SetForegroundColour("blue"); | |
58614078 | 501 | (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) ); |
9838df2c | 502 | m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) ); |
5b077d48 | 503 | // m_gauge->SetBackgroundColour("wheat"); |
7bce6aec | 504 | m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) ); |
5b077d48 | 505 | // m_slider->SetBackgroundColour("wheat"); |
7bce6aec | 506 | (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) ); |
9838df2c JS |
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 | |
655822f3 VZ |
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" | |
7bce6aec RR |
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", | |
9838df2c JS |
522 | wxPoint(208,25), |
523 | wxSize(210, 110) | |
a93109d5 | 524 | ); |
9838df2c | 525 | #endif |
e380f72b | 526 | m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) ); |
5b077d48 | 527 | // m_spintext->SetBackgroundColour("wheat"); |
e380f72b | 528 | m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) ); |
5b077d48 | 529 | // m_spinbutton->SetBackgroundColour("wheat"); |
655822f3 VZ |
530 | m_spinbutton->SetRange(0,100); |
531 | ||
58614078 | 532 | m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); |
1c005ff7 RR |
533 | } |
534 | ||
b527aac5 RR |
535 | void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) ) |
536 | { | |
537 | #ifdef __WXGTK__ | |
538 | ||
8b53e5a2 RR |
539 | if (!wxTheClipboard->Open()) |
540 | { | |
541 | *m_text << "Error opening the clipboard." << "\n"; | |
655822f3 | 542 | |
8b53e5a2 RR |
543 | return; |
544 | } | |
545 | else | |
546 | { | |
547 | *m_text << "Successfully opened the clipboard." << "\n"; | |
548 | } | |
549 | ||
550 | wxTextDataObject *data = new wxTextDataObject(); | |
655822f3 | 551 | |
8b53e5a2 RR |
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 | } | |
655822f3 | 561 | |
8b53e5a2 | 562 | wxTheClipboard->Close(); |
655822f3 | 563 | |
8b53e5a2 | 564 | *m_text << "Closed the clipboard." << "\n"; |
655822f3 | 565 | |
8b53e5a2 | 566 | delete data; |
b527aac5 RR |
567 | |
568 | #endif | |
569 | } | |
570 | ||
571 | void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) ) | |
572 | { | |
3069ac4e | 573 | #ifdef __WXGTK__ |
655822f3 | 574 | |
3069ac4e RR |
575 | wxString text( m_multitext->GetLineText(0) ); |
576 | ||
577 | if (text.IsEmpty()) return; | |
655822f3 | 578 | |
8b53e5a2 RR |
579 | if (!wxTheClipboard->Open()) |
580 | { | |
581 | *m_text << "Error opening the clipboard." << "\n"; | |
655822f3 | 582 | |
8b53e5a2 RR |
583 | return; |
584 | } | |
585 | else | |
586 | { | |
587 | *m_text << "Successfully opened the clipboard." << "\n"; | |
588 | } | |
3069ac4e | 589 | |
0d2a2b60 RR |
590 | wxTextDataObject *data = new wxTextDataObject( text ); |
591 | wxDataBroker *broker = new wxDataBroker(); | |
592 | broker->Add( data ); | |
593 | ||
594 | if (!wxTheClipboard->SetData( broker )) | |
8b53e5a2 RR |
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(); | |
655822f3 | 604 | |
8b53e5a2 | 605 | *m_text << "Closed the clipboard." << "\n"; |
655822f3 | 606 | |
3069ac4e | 607 | #endif |
b527aac5 RR |
608 | } |
609 | ||
d59051dd VZ |
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 | ||
1c005ff7 RR |
622 | void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) |
623 | { | |
624 | int x = 0; | |
625 | int y = 0; | |
626 | GetClientSize( &x, &y ); | |
655822f3 | 627 | |
2f6407b9 RR |
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 ); | |
1c005ff7 RR |
630 | } |
631 | ||
cb43b372 RR |
632 | void MyPanel::OnPageChanged( wxNotebookEvent &event ) |
633 | { | |
634 | *m_text << "Notebook selection is " << event.GetSelection() << "\n"; | |
635 | } | |
636 | ||
1c005ff7 RR |
637 | void MyPanel::OnListBox( wxCommandEvent &event ) |
638 | { | |
1c005ff7 RR |
639 | m_text->WriteText( "ListBox selection string is: " ); |
640 | m_text->WriteText( event.GetString() ); | |
641 | m_text->WriteText( "\n" ); | |
642 | } | |
643 | ||
5b077d48 RR |
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 | ||
47908e25 RR |
651 | void MyPanel::OnListBoxButtons( wxCommandEvent &event ) |
652 | { | |
653 | switch (event.GetId()) | |
654 | { | |
d3904ceb RR |
655 | case ID_LISTBOX_ENABLE: |
656 | { | |
8bf45ed1 | 657 | m_text->WriteText("Checkbox clicked.\n"); |
655822f3 | 658 | m_listbox->Enable( event.GetInt() == 0 ); |
d3904ceb RR |
659 | break; |
660 | } | |
47908e25 RR |
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 | } | |
30f82ea4 RR |
681 | case ID_LISTBOX_DELETE: |
682 | { | |
683 | int idx = m_listbox->GetSelection(); | |
684 | m_listbox->Delete( idx ); | |
685 | break; | |
686 | } | |
868a2826 RR |
687 | case ID_LISTBOX_FONT: |
688 | { | |
689 | m_listbox->SetFont( *wxITALIC_FONT ); | |
ae0bdb01 | 690 | m_checkbox->SetFont( *wxITALIC_FONT ); |
868a2826 RR |
691 | break; |
692 | } | |
47908e25 RR |
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 | { | |
d3904ceb RR |
707 | case ID_CHOICE_ENABLE: |
708 | { | |
655822f3 | 709 | m_choice->Enable( event.GetInt() == 0 ); |
d3904ceb RR |
710 | break; |
711 | } | |
47908e25 RR |
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 | } | |
2f6407b9 RR |
732 | case ID_CHOICE_DELETE: |
733 | { | |
734 | int idx = m_choice->GetSelection(); | |
735 | m_choice->Delete( idx ); | |
736 | break; | |
737 | } | |
868a2826 RR |
738 | case ID_CHOICE_FONT: |
739 | { | |
740 | m_choice->SetFont( *wxITALIC_FONT ); | |
741 | break; | |
742 | } | |
47908e25 RR |
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 ) | |
1c005ff7 | 754 | { |
47908e25 RR |
755 | switch (event.GetId()) |
756 | { | |
d3904ceb RR |
757 | case ID_COMBO_ENABLE: |
758 | { | |
655822f3 | 759 | m_combo->Enable( event.GetInt() == 0 ); |
d3904ceb RR |
760 | break; |
761 | } | |
47908e25 RR |
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 | } | |
2f6407b9 RR |
782 | case ID_COMBO_DELETE: |
783 | { | |
784 | int idx = m_combo->GetSelection(); | |
785 | m_combo->Delete( idx ); | |
786 | break; | |
787 | } | |
868a2826 RR |
788 | case ID_COMBO_FONT: |
789 | { | |
790 | m_combo->SetFont( *wxITALIC_FONT ); | |
791 | break; | |
792 | } | |
47908e25 RR |
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 | { | |
d3904ceb RR |
807 | case ID_RADIOBOX_ENABLE: |
808 | { | |
655822f3 | 809 | m_radio->Enable( event.GetInt() == 0 ); |
d3904ceb RR |
810 | break; |
811 | } | |
47908e25 RR |
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 | } | |
868a2826 RR |
822 | case ID_RADIOBOX_FONT: |
823 | { | |
824 | m_radio->SetFont( *wxITALIC_FONT ); | |
825 | break; | |
826 | } | |
47908e25 | 827 | } |
1c005ff7 RR |
828 | } |
829 | ||
868a2826 RR |
830 | void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) ) |
831 | { | |
832 | m_fontButton->SetFont( *wxITALIC_FONT ); | |
833 | m_text->SetFont( *wxITALIC_FONT ); | |
834 | } | |
835 | ||
7bce6aec RR |
836 | void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) |
837 | { | |
838 | m_gauge->SetValue( m_slider->GetValue() ); | |
839 | } | |
840 | ||
e380f72b RR |
841 | void MyPanel::OnSpinUpdate( wxSpinEvent &event ) |
842 | { | |
843 | wxString value; | |
844 | value.sprintf( "%d", (int)event.GetPosition() ); | |
845 | m_spintext->SetValue( value ); | |
846 | } | |
847 | ||
2cb21a45 VZ |
848 | MyPanel::~MyPanel() |
849 | { | |
850 | delete m_notebook->GetImageList(); | |
851 | } | |
852 | ||
1c005ff7 RR |
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 | { | |
654c1d6b | 865 | (void)new MyPanel( this, 10, 10, 300, 100 ); |
1c005ff7 RR |
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 | } |