]>
Commit | Line | Data |
---|---|---|
02e8b87f | 1 | ///////////////////////////////////////////////////////////////////////////// |
4aff28fc | 2 | // Name: text.cpp |
02e8b87f RR |
3 | // Purpose: TextCtrl wxWindows sample |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
4aff28fc | 7 | // Copyright: (c) Robert Roebling, Julian Smart, Vadim Zeitlin |
02e8b87f RR |
8 | // Licence: wxWindows license |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
c41ea66a | 12 | #pragma implementation "text.cpp" |
02e8b87f 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 | ||
26 | #if wxUSE_CLIPBOARD | |
27 | #include "wx/dataobj.h" | |
28 | #include "wx/clipbrd.h" | |
29 | #endif | |
30 | ||
0ddea946 | 31 | #if wxUSE_FILE |
ae3dd4a5 | 32 | #include "wx/file.h" |
0ddea946 VZ |
33 | #endif |
34 | ||
02e8b87f RR |
35 | #if wxUSE_TOOLTIPS |
36 | #include "wx/tooltip.h" | |
37 | #endif | |
38 | ||
0146a47e VZ |
39 | #include "wx/progdlg.h" |
40 | ||
b6a0d8a2 VZ |
41 | // We test for wxUSE_DRAG_AND_DROP also, because data objects may not be |
42 | // implemented for compilers that can't cope with the OLE parts in | |
43 | // wxUSE_DRAG_AND_DROP. | |
44 | #if !wxUSE_DRAG_AND_DROP | |
45 | #undef wxUSE_CLIPBOARD | |
46 | #define wxUSE_CLIPBOARD 0 | |
47 | #endif | |
48 | ||
02e8b87f RR |
49 | //---------------------------------------------------------------------- |
50 | // class definitions | |
51 | //---------------------------------------------------------------------- | |
52 | ||
53 | class MyApp: public wxApp | |
54 | { | |
55 | public: | |
56 | bool OnInit(); | |
57 | }; | |
58 | ||
59 | // a text ctrl which allows to call different wxTextCtrl functions | |
60 | // interactively by pressing function keys in it | |
61 | class MyTextCtrl : public wxTextCtrl | |
62 | { | |
63 | public: | |
64 | MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, | |
65 | const wxPoint &pos, const wxSize &size, int style = 0) | |
56c4a88b VZ |
66 | : wxTextCtrl(parent, id, value, pos, size, style) |
67 | { | |
68 | m_hasCapture = FALSE; | |
69 | } | |
02e8b87f RR |
70 | |
71 | void OnKeyDown(wxKeyEvent& event); | |
72 | void OnKeyUp(wxKeyEvent& event); | |
73 | void OnChar(wxKeyEvent& event); | |
d7eee191 | 74 | |
9ca03a57 | 75 | void OnText(wxCommandEvent& event); |
c57e3339 | 76 | void OnTextURL(wxTextUrlEvent& event); |
d7eee191 VZ |
77 | void OnTextMaxLen(wxCommandEvent& event); |
78 | ||
4aff28fc | 79 | void OnMouseEvent(wxMouseEvent& event); |
02e8b87f | 80 | |
94ccc254 VZ |
81 | void OnSetFocus(wxFocusEvent& event); |
82 | void OnKillFocus(wxFocusEvent& event); | |
83 | ||
56c4a88b VZ |
84 | static bool ms_logKey; |
85 | static bool ms_logChar; | |
86 | static bool ms_logMouse; | |
1ce58dc6 | 87 | static bool ms_logText; |
94ccc254 | 88 | static bool ms_logFocus; |
f152cf5a | 89 | |
02e8b87f RR |
90 | private: |
91 | static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); } | |
94ccc254 | 92 | void LogKeyEvent(const wxChar *name, wxKeyEvent& event) const; |
02e8b87f | 93 | |
56c4a88b VZ |
94 | bool m_hasCapture; |
95 | ||
02e8b87f RR |
96 | DECLARE_EVENT_TABLE() |
97 | }; | |
98 | ||
99 | class MyPanel: public wxPanel | |
100 | { | |
101 | public: | |
102 | MyPanel(wxFrame *frame, int x, int y, int w, int h); | |
73028c4b | 103 | virtual ~MyPanel() { delete wxLog::SetActiveTarget(m_logOld); } |
02e8b87f | 104 | |
b6a0d8a2 VZ |
105 | #if wxUSE_CLIPBOARD |
106 | void DoPasteFromClipboard(); | |
107 | void DoCopyToClipboard(); | |
108 | #endif // wxUSE_CLIPBOARD | |
109 | ||
cba1148d | 110 | void DoRemoveText(); |
b6a0d8a2 VZ |
111 | void DoMoveToEndOfText(); |
112 | void DoMoveToEndOfEntry(); | |
02e8b87f | 113 | |
89124b1a RR |
114 | void OnSize( wxSizeEvent &event ); |
115 | ||
02e8b87f RR |
116 | MyTextCtrl *m_text; |
117 | MyTextCtrl *m_password; | |
118 | MyTextCtrl *m_enter; | |
119 | MyTextCtrl *m_tab; | |
02e8b87f | 120 | MyTextCtrl *m_readonly; |
d7eee191 | 121 | MyTextCtrl *m_limited; |
bb69661b | 122 | |
02e8b87f RR |
123 | MyTextCtrl *m_multitext; |
124 | MyTextCtrl *m_horizontal; | |
02e8b87f | 125 | |
0ddea946 VZ |
126 | MyTextCtrl *m_textrich; |
127 | ||
02e8b87f | 128 | wxTextCtrl *m_log; |
89124b1a | 129 | |
d847e69a VZ |
130 | wxLog *m_logOld; |
131 | ||
89124b1a | 132 | private: |
cba1148d VZ |
133 | // get the currently focused text control or return the default one is no |
134 | // text ctrl has focus | |
135 | wxTextCtrl *GetFocusedText(wxTextCtrl *textDef); | |
136 | ||
89124b1a | 137 | DECLARE_EVENT_TABLE() |
02e8b87f RR |
138 | }; |
139 | ||
140 | class MyFrame: public wxFrame | |
141 | { | |
142 | public: | |
b6a0d8a2 | 143 | MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h); |
02e8b87f RR |
144 | |
145 | void OnQuit(wxCommandEvent& event); | |
146 | void OnAbout(wxCommandEvent& event); | |
147 | #if wxUSE_TOOLTIPS | |
148 | void OnSetTooltipDelay(wxCommandEvent& event); | |
149 | void OnToggleTooltips(wxCommandEvent& event); | |
150 | #endif // wxUSE_TOOLTIPS | |
b6a0d8a2 VZ |
151 | |
152 | #if wxUSE_CLIPBOARD | |
153 | void OnPasteFromClipboard( wxCommandEvent &event ) | |
154 | { m_panel->DoPasteFromClipboard(); } | |
155 | void OnCopyToClipboard( wxCommandEvent &event ) | |
156 | { m_panel->DoCopyToClipboard(); } | |
157 | #endif // wxUSE_CLIPBOARD | |
158 | ||
eff00523 VZ |
159 | void OnAddTextFreeze( wxCommandEvent& event ) |
160 | { DoAddText(true); } | |
161 | void OnAddText( wxCommandEvent& event ) | |
162 | { DoAddText(false); } | |
cba1148d VZ |
163 | void OnRemoveText( wxCommandEvent& event ) |
164 | { m_panel->DoRemoveText(); } | |
eff00523 | 165 | |
b6a0d8a2 VZ |
166 | void OnMoveToEndOfText( wxCommandEvent &event ) |
167 | { m_panel->DoMoveToEndOfText(); } | |
168 | void OnMoveToEndOfEntry( wxCommandEvent &event ) | |
169 | { m_panel->DoMoveToEndOfEntry(); } | |
170 | ||
22670da4 VZ |
171 | void OnScrollLineDown(wxCommandEvent& event) |
172 | { | |
173 | if ( !m_panel->m_textrich->LineDown() ) | |
174 | wxLogMessage(_T("Already at the bottom")); | |
175 | } | |
176 | ||
177 | void OnScrollLineUp(wxCommandEvent& event) | |
178 | { | |
179 | if ( !m_panel->m_textrich->LineUp() ) | |
180 | wxLogMessage(_T("Already at the top")); | |
181 | } | |
182 | ||
183 | void OnScrollPageDown(wxCommandEvent& event) | |
184 | { | |
185 | if ( !m_panel->m_textrich->PageDown() ) | |
186 | wxLogMessage(_T("Already at the bottom")); | |
187 | } | |
188 | ||
189 | void OnScrollPageUp(wxCommandEvent& event) | |
190 | { | |
191 | if ( !m_panel->m_textrich->PageUp() ) | |
192 | wxLogMessage(_T("Already at the top")); | |
193 | } | |
194 | ||
e66ad5c6 | 195 | void OnLogClear(wxCommandEvent& event); |
0ddea946 | 196 | void OnFileSave(wxCommandEvent& event); |
b6a0d8a2 VZ |
197 | void OnFileLoad(wxCommandEvent& event); |
198 | ||
f6bcfd97 BP |
199 | void OnSetEditable(wxCommandEvent& event); |
200 | void OnSetEnabled(wxCommandEvent& event); | |
201 | ||
56c4a88b VZ |
202 | void OnLogKey(wxCommandEvent& event) |
203 | { | |
204 | MyTextCtrl::ms_logKey = event.IsChecked(); | |
205 | } | |
206 | ||
207 | void OnLogChar(wxCommandEvent& event) | |
208 | { | |
209 | MyTextCtrl::ms_logChar = event.IsChecked(); | |
210 | } | |
211 | ||
212 | void OnLogMouse(wxCommandEvent& event) | |
213 | { | |
214 | MyTextCtrl::ms_logMouse = event.IsChecked(); | |
215 | } | |
216 | ||
1ce58dc6 VZ |
217 | void OnLogText(wxCommandEvent& event) |
218 | { | |
219 | MyTextCtrl::ms_logText = event.IsChecked(); | |
220 | } | |
221 | ||
94ccc254 VZ |
222 | void OnLogFocus(wxCommandEvent& event) |
223 | { | |
224 | MyTextCtrl::ms_logFocus = event.IsChecked(); | |
225 | } | |
226 | ||
60f52320 VZ |
227 | void OnSetText(wxCommandEvent& event) |
228 | { | |
229 | m_panel->m_text->SetValue(_T("Hello, world (what else did you expect)?")); | |
230 | } | |
231 | ||
02e8b87f RR |
232 | void OnIdle( wxIdleEvent& event ); |
233 | ||
234 | private: | |
eff00523 VZ |
235 | void DoAddText(bool freeze) |
236 | { | |
237 | wxTextCtrl *text = m_panel->m_textrich; | |
238 | if ( freeze ) | |
239 | text->Freeze(); | |
240 | ||
0146a47e VZ |
241 | text->Clear(); |
242 | ||
243 | wxProgressDialog dlg(_T("Wait..."), _T("Updating"), 100, this); | |
eff00523 | 244 | for ( int i = 0; i < 100; i++ ) |
0146a47e VZ |
245 | { |
246 | dlg.Update(i); | |
4693b20c | 247 | text->AppendText(wxString::Format(wxT("Line %i\n"), i)); |
0146a47e | 248 | } |
eff00523 VZ |
249 | |
250 | text->SetInsertionPoint(0); | |
251 | ||
252 | if ( freeze ) | |
253 | text->Thaw(); | |
254 | } | |
255 | ||
b6a0d8a2 VZ |
256 | MyPanel *m_panel; |
257 | ||
02e8b87f RR |
258 | DECLARE_EVENT_TABLE() |
259 | }; | |
260 | ||
261 | //---------------------------------------------------------------------- | |
262 | // main() | |
263 | //---------------------------------------------------------------------- | |
264 | ||
265 | IMPLEMENT_APP(MyApp) | |
266 | ||
267 | //---------------------------------------------------------------------- | |
268 | // MyApp | |
269 | //---------------------------------------------------------------------- | |
270 | ||
271 | enum | |
272 | { | |
b6a0d8a2 VZ |
273 | TEXT_QUIT = 100, |
274 | TEXT_ABOUT, | |
275 | TEXT_LOAD, | |
ae3dd4a5 | 276 | TEXT_SAVE, |
e66ad5c6 | 277 | TEXT_CLEAR, |
b6a0d8a2 VZ |
278 | |
279 | // clipboard menu | |
280 | TEXT_CLIPBOARD_COPY = 200, | |
281 | TEXT_CLIPBOARD_PASTE, | |
02e8b87f RR |
282 | |
283 | // tooltip menu | |
b6a0d8a2 VZ |
284 | TEXT_TOOLTIPS_SETDELAY = 300, |
285 | TEXT_TOOLTIPS_ENABLE, | |
286 | ||
f6bcfd97 | 287 | // text menu |
eff00523 VZ |
288 | TEXT_ADD_SOME = 400, |
289 | TEXT_ADD_FREEZE, | |
290 | TEXT_MOVE_ENDTEXT, | |
f6bcfd97 BP |
291 | TEXT_MOVE_ENDENTRY, |
292 | TEXT_SET_EDITABLE, | |
22670da4 VZ |
293 | TEXT_SET_ENABLED, |
294 | TEXT_LINE_DOWN, | |
295 | TEXT_LINE_UP, | |
296 | TEXT_PAGE_DOWN, | |
297 | TEXT_PAGE_UP, | |
cba1148d | 298 | TEXT_REMOVE, |
60f52320 | 299 | TEXT_SET, |
56c4a88b VZ |
300 | |
301 | // log menu | |
302 | TEXT_LOG_KEY, | |
303 | TEXT_LOG_CHAR, | |
304 | TEXT_LOG_MOUSE, | |
1ce58dc6 | 305 | TEXT_LOG_TEXT, |
94ccc254 | 306 | TEXT_LOG_FOCUS, |
56c4a88b VZ |
307 | |
308 | TEXT_END | |
02e8b87f RR |
309 | }; |
310 | ||
311 | bool MyApp::OnInit() | |
312 | { | |
313 | // Create the main frame window | |
314 | MyFrame *frame = new MyFrame((wxFrame *) NULL, | |
17665a2b | 315 | "Text wxWindows sample", 50, 50, 700, 420); |
89124b1a | 316 | frame->SetSizeHints( 500, 400 ); |
02e8b87f | 317 | |
02e8b87f | 318 | wxMenu *file_menu = new wxMenu; |
0ddea946 VZ |
319 | file_menu->Append(TEXT_SAVE, "&Save file\tCtrl-S", |
320 | "Save the text control contents to file"); | |
b6a0d8a2 VZ |
321 | file_menu->Append(TEXT_LOAD, "&Load file\tCtrl-O", |
322 | "Load the sample file into text control"); | |
323 | file_menu->AppendSeparator(); | |
324 | file_menu->Append(TEXT_ABOUT, "&About\tAlt-A"); | |
325 | file_menu->AppendSeparator(); | |
c41ea66a | 326 | file_menu->Append(TEXT_QUIT, "E&xit\tAlt-X", "Quit this sample"); |
02e8b87f RR |
327 | |
328 | wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE ); | |
329 | menu_bar->Append(file_menu, "&File"); | |
330 | ||
331 | #if wxUSE_TOOLTIPS | |
332 | wxMenu *tooltip_menu = new wxMenu; | |
b6a0d8a2 | 333 | tooltip_menu->Append(TEXT_TOOLTIPS_SETDELAY, "Set &delay\tCtrl-D"); |
02e8b87f | 334 | tooltip_menu->AppendSeparator(); |
b6a0d8a2 | 335 | tooltip_menu->Append(TEXT_TOOLTIPS_ENABLE, "&Toggle tooltips\tCtrl-T", |
02e8b87f | 336 | "enable/disable tooltips", TRUE); |
b6a0d8a2 | 337 | tooltip_menu->Check(TEXT_TOOLTIPS_ENABLE, TRUE); |
02e8b87f RR |
338 | menu_bar->Append(tooltip_menu, "&Tooltips"); |
339 | #endif // wxUSE_TOOLTIPS | |
340 | ||
b6a0d8a2 VZ |
341 | #if wxUSE_CLIPBOARD |
342 | wxMenu *menuClipboard = new wxMenu; | |
343 | menuClipboard->Append(TEXT_CLIPBOARD_COPY, "&Copy\tCtrl-C", | |
344 | "Copy the first line to the clipboard"); | |
345 | menuClipboard->Append(TEXT_CLIPBOARD_PASTE, "&Paste\tCtrl-V", | |
346 | "Paste from clipboard to the text control"); | |
347 | menu_bar->Append(menuClipboard, "&Clipboard"); | |
348 | #endif // wxUSE_CLIPBOARD | |
349 | ||
f6bcfd97 | 350 | wxMenu *menuText = new wxMenu; |
eff00523 VZ |
351 | menuText->Append(TEXT_ADD_SOME, "&Append some text\tCtrl-A"); |
352 | menuText->Append(TEXT_ADD_FREEZE, "&Append text with freeze/thaw\tShift-Ctrl-A"); | |
cba1148d | 353 | menuText->Append(TEXT_REMOVE, "&Remove first 10 characters\tCtrl-X"); |
60f52320 | 354 | menuText->Append(TEXT_SET, "&Set the first text zone value\tCtrl-E"); |
cba1148d | 355 | menuText->AppendSeparator(); |
f6bcfd97 BP |
356 | menuText->Append(TEXT_MOVE_ENDTEXT, "Move cursor to the end of &text"); |
357 | menuText->Append(TEXT_MOVE_ENDENTRY, "Move cursor to the end of &entry"); | |
358 | menuText->Append(TEXT_SET_EDITABLE, "Toggle &editable state", "", TRUE); | |
359 | menuText->Append(TEXT_SET_ENABLED, "Toggle e&nabled state", "", TRUE); | |
360 | menuText->Check(TEXT_SET_EDITABLE, TRUE); | |
361 | menuText->Check(TEXT_SET_ENABLED, TRUE); | |
22670da4 VZ |
362 | menuText->AppendSeparator(); |
363 | menuText->Append(TEXT_LINE_DOWN, "Scroll text one line down"); | |
364 | menuText->Append(TEXT_LINE_UP, "Scroll text one line up"); | |
365 | menuText->Append(TEXT_PAGE_DOWN, "Scroll text one page down"); | |
366 | menuText->Append(TEXT_PAGE_DOWN, "Scroll text one page up"); | |
56c4a88b VZ |
367 | menu_bar->Append(menuText, "Te&xt"); |
368 | ||
369 | wxMenu *menuLog = new wxMenu; | |
370 | menuLog->Append(TEXT_LOG_KEY, "Log &key events", "", TRUE); | |
371 | menuLog->Append(TEXT_LOG_CHAR, "Log &char events", "", TRUE); | |
372 | menuLog->Append(TEXT_LOG_MOUSE, "Log &mouse events", "", TRUE); | |
1ce58dc6 | 373 | menuLog->Append(TEXT_LOG_TEXT, "Log &text events", "", TRUE); |
94ccc254 | 374 | menuLog->Append(TEXT_LOG_FOCUS, "Log &focus events", "", TRUE); |
56c4a88b VZ |
375 | menuLog->AppendSeparator(); |
376 | menuLog->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C", | |
377 | "Clear the log window contents"); | |
94ccc254 VZ |
378 | |
379 | // select only the interesting events by default | |
56c4a88b VZ |
380 | menuLog->Check(TEXT_LOG_KEY, TRUE); |
381 | menuLog->Check(TEXT_LOG_CHAR, TRUE); | |
1ce58dc6 | 382 | menuLog->Check(TEXT_LOG_TEXT, TRUE); |
94ccc254 VZ |
383 | |
384 | MyTextCtrl::ms_logKey = | |
385 | MyTextCtrl::ms_logChar = | |
386 | MyTextCtrl::ms_logText = TRUE; | |
56c4a88b | 387 | menu_bar->Append(menuLog, "&Log"); |
b6a0d8a2 | 388 | |
02e8b87f RR |
389 | frame->SetMenuBar(menu_bar); |
390 | ||
391 | frame->Show(TRUE); | |
392 | ||
393 | SetTopWindow(frame); | |
394 | ||
395 | // report success | |
396 | return TRUE; | |
397 | } | |
398 | ||
399 | //---------------------------------------------------------------------- | |
400 | // MyTextCtrl | |
401 | //---------------------------------------------------------------------- | |
402 | ||
403 | BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl) | |
404 | EVT_KEY_DOWN(MyTextCtrl::OnKeyDown) | |
405 | EVT_KEY_UP(MyTextCtrl::OnKeyUp) | |
406 | EVT_CHAR(MyTextCtrl::OnChar) | |
d7eee191 | 407 | |
9ca03a57 | 408 | EVT_TEXT(-1, MyTextCtrl::OnText) |
c57e3339 | 409 | EVT_TEXT_URL(-1, MyTextCtrl::OnTextURL) |
d7eee191 VZ |
410 | EVT_TEXT_MAXLEN(-1, MyTextCtrl::OnTextMaxLen) |
411 | ||
4aff28fc | 412 | EVT_MOUSE_EVENTS(MyTextCtrl::OnMouseEvent) |
94ccc254 VZ |
413 | |
414 | EVT_SET_FOCUS(MyTextCtrl::OnSetFocus) | |
415 | EVT_KILL_FOCUS(MyTextCtrl::OnKillFocus) | |
02e8b87f RR |
416 | END_EVENT_TABLE() |
417 | ||
94ccc254 VZ |
418 | bool MyTextCtrl::ms_logKey = FALSE; |
419 | bool MyTextCtrl::ms_logChar = FALSE; | |
fb93b610 | 420 | bool MyTextCtrl::ms_logMouse = FALSE; |
94ccc254 VZ |
421 | bool MyTextCtrl::ms_logText = FALSE; |
422 | bool MyTextCtrl::ms_logFocus = FALSE; | |
56c4a88b | 423 | |
94ccc254 | 424 | void MyTextCtrl::LogKeyEvent(const wxChar *name, wxKeyEvent& event) const |
02e8b87f RR |
425 | { |
426 | wxString key; | |
427 | long keycode = event.KeyCode(); | |
02e8b87f RR |
428 | { |
429 | switch ( keycode ) | |
430 | { | |
431 | case WXK_BACK: key = "BACK"; break; | |
432 | case WXK_TAB: key = "TAB"; break; | |
433 | case WXK_RETURN: key = "RETURN"; break; | |
434 | case WXK_ESCAPE: key = "ESCAPE"; break; | |
435 | case WXK_SPACE: key = "SPACE"; break; | |
436 | case WXK_DELETE: key = "DELETE"; break; | |
437 | case WXK_START: key = "START"; break; | |
438 | case WXK_LBUTTON: key = "LBUTTON"; break; | |
439 | case WXK_RBUTTON: key = "RBUTTON"; break; | |
440 | case WXK_CANCEL: key = "CANCEL"; break; | |
441 | case WXK_MBUTTON: key = "MBUTTON"; break; | |
442 | case WXK_CLEAR: key = "CLEAR"; break; | |
443 | case WXK_SHIFT: key = "SHIFT"; break; | |
444 | case WXK_ALT: key = "ALT"; break; | |
445 | case WXK_CONTROL: key = "CONTROL"; break; | |
446 | case WXK_MENU: key = "MENU"; break; | |
447 | case WXK_PAUSE: key = "PAUSE"; break; | |
448 | case WXK_CAPITAL: key = "CAPITAL"; break; | |
449 | case WXK_PRIOR: key = "PRIOR"; break; | |
450 | case WXK_NEXT: key = "NEXT"; break; | |
451 | case WXK_END: key = "END"; break; | |
452 | case WXK_HOME: key = "HOME"; break; | |
453 | case WXK_LEFT: key = "LEFT"; break; | |
454 | case WXK_UP: key = "UP"; break; | |
455 | case WXK_RIGHT: key = "RIGHT"; break; | |
456 | case WXK_DOWN: key = "DOWN"; break; | |
457 | case WXK_SELECT: key = "SELECT"; break; | |
458 | case WXK_PRINT: key = "PRINT"; break; | |
459 | case WXK_EXECUTE: key = "EXECUTE"; break; | |
460 | case WXK_SNAPSHOT: key = "SNAPSHOT"; break; | |
461 | case WXK_INSERT: key = "INSERT"; break; | |
462 | case WXK_HELP: key = "HELP"; break; | |
463 | case WXK_NUMPAD0: key = "NUMPAD0"; break; | |
464 | case WXK_NUMPAD1: key = "NUMPAD1"; break; | |
465 | case WXK_NUMPAD2: key = "NUMPAD2"; break; | |
466 | case WXK_NUMPAD3: key = "NUMPAD3"; break; | |
467 | case WXK_NUMPAD4: key = "NUMPAD4"; break; | |
468 | case WXK_NUMPAD5: key = "NUMPAD5"; break; | |
469 | case WXK_NUMPAD6: key = "NUMPAD6"; break; | |
470 | case WXK_NUMPAD7: key = "NUMPAD7"; break; | |
471 | case WXK_NUMPAD8: key = "NUMPAD8"; break; | |
472 | case WXK_NUMPAD9: key = "NUMPAD9"; break; | |
473 | case WXK_MULTIPLY: key = "MULTIPLY"; break; | |
474 | case WXK_ADD: key = "ADD"; break; | |
475 | case WXK_SEPARATOR: key = "SEPARATOR"; break; | |
476 | case WXK_SUBTRACT: key = "SUBTRACT"; break; | |
477 | case WXK_DECIMAL: key = "DECIMAL"; break; | |
478 | case WXK_DIVIDE: key = "DIVIDE"; break; | |
479 | case WXK_F1: key = "F1"; break; | |
480 | case WXK_F2: key = "F2"; break; | |
481 | case WXK_F3: key = "F3"; break; | |
482 | case WXK_F4: key = "F4"; break; | |
483 | case WXK_F5: key = "F5"; break; | |
484 | case WXK_F6: key = "F6"; break; | |
485 | case WXK_F7: key = "F7"; break; | |
486 | case WXK_F8: key = "F8"; break; | |
487 | case WXK_F9: key = "F9"; break; | |
488 | case WXK_F10: key = "F10"; break; | |
489 | case WXK_F11: key = "F11"; break; | |
490 | case WXK_F12: key = "F12"; break; | |
491 | case WXK_F13: key = "F13"; break; | |
492 | case WXK_F14: key = "F14"; break; | |
493 | case WXK_F15: key = "F15"; break; | |
494 | case WXK_F16: key = "F16"; break; | |
495 | case WXK_F17: key = "F17"; break; | |
496 | case WXK_F18: key = "F18"; break; | |
497 | case WXK_F19: key = "F19"; break; | |
498 | case WXK_F20: key = "F20"; break; | |
499 | case WXK_F21: key = "F21"; break; | |
500 | case WXK_F22: key = "F22"; break; | |
501 | case WXK_F23: key = "F23"; break; | |
502 | case WXK_F24: key = "F24"; break; | |
503 | case WXK_NUMLOCK: key = "NUMLOCK"; break; | |
504 | case WXK_SCROLL: key = "SCROLL"; break; | |
505 | case WXK_PAGEUP: key = "PAGEUP"; break; | |
506 | case WXK_PAGEDOWN: key = "PAGEDOWN"; break; | |
507 | case WXK_NUMPAD_SPACE: key = "NUMPAD_SPACE"; break; | |
508 | case WXK_NUMPAD_TAB: key = "NUMPAD_TAB"; break; | |
509 | case WXK_NUMPAD_ENTER: key = "NUMPAD_ENTER"; break; | |
510 | case WXK_NUMPAD_F1: key = "NUMPAD_F1"; break; | |
511 | case WXK_NUMPAD_F2: key = "NUMPAD_F2"; break; | |
512 | case WXK_NUMPAD_F3: key = "NUMPAD_F3"; break; | |
513 | case WXK_NUMPAD_F4: key = "NUMPAD_F4"; break; | |
514 | case WXK_NUMPAD_HOME: key = "NUMPAD_HOME"; break; | |
515 | case WXK_NUMPAD_LEFT: key = "NUMPAD_LEFT"; break; | |
516 | case WXK_NUMPAD_UP: key = "NUMPAD_UP"; break; | |
517 | case WXK_NUMPAD_RIGHT: key = "NUMPAD_RIGHT"; break; | |
518 | case WXK_NUMPAD_DOWN: key = "NUMPAD_DOWN"; break; | |
519 | case WXK_NUMPAD_PRIOR: key = "NUMPAD_PRIOR"; break; | |
520 | case WXK_NUMPAD_PAGEUP: key = "NUMPAD_PAGEUP"; break; | |
521 | case WXK_NUMPAD_PAGEDOWN: key = "NUMPAD_PAGEDOWN"; break; | |
522 | case WXK_NUMPAD_END: key = "NUMPAD_END"; break; | |
523 | case WXK_NUMPAD_BEGIN: key = "NUMPAD_BEGIN"; break; | |
524 | case WXK_NUMPAD_INSERT: key = "NUMPAD_INSERT"; break; | |
525 | case WXK_NUMPAD_DELETE: key = "NUMPAD_DELETE"; break; | |
526 | case WXK_NUMPAD_EQUAL: key = "NUMPAD_EQUAL"; break; | |
527 | case WXK_NUMPAD_MULTIPLY: key = "NUMPAD_MULTIPLY"; break; | |
528 | case WXK_NUMPAD_ADD: key = "NUMPAD_ADD"; break; | |
529 | case WXK_NUMPAD_SEPARATOR: key = "NUMPAD_SEPARATOR"; break; | |
530 | case WXK_NUMPAD_SUBTRACT: key = "NUMPAD_SUBTRACT"; break; | |
531 | case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break; | |
532 | ||
4afd7529 | 533 | default: |
89124b1a RR |
534 | { |
535 | if ( wxIsprint((int)keycode) ) | |
1ce58dc6 VZ |
536 | key.Printf(_T("'%c'"), (char)keycode); |
537 | else if ( keycode > 0 && keycode < 27 ) | |
538 | key.Printf(_("Ctrl-%c"), _T('A') + keycode - 1); | |
89124b1a | 539 | else |
1ce58dc6 | 540 | key.Printf(_T("unknown (%ld)"), keycode); |
4afd7529 | 541 | } |
02e8b87f RR |
542 | } |
543 | } | |
544 | ||
545 | wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"), | |
546 | name, | |
547 | key.c_str(), | |
548 | GetChar( event.ControlDown(), _T('C') ), | |
549 | GetChar( event.AltDown(), _T('A') ), | |
550 | GetChar( event.ShiftDown(), _T('S') ), | |
551 | GetChar( event.MetaDown(), _T('M') ) ); | |
02e8b87f RR |
552 | } |
553 | ||
c57e3339 VZ |
554 | static wxString GetMouseEventDesc(const wxMouseEvent& ev) |
555 | { | |
556 | // click event | |
557 | wxString button; | |
558 | bool dbl, up; | |
559 | if ( ev.LeftDown() || ev.LeftUp() || ev.LeftDClick() ) | |
560 | { | |
561 | button = _T("Left"); | |
562 | dbl = ev.LeftDClick(); | |
563 | up = ev.LeftUp(); | |
564 | } | |
565 | else if ( ev.MiddleDown() || ev.MiddleUp() || ev.MiddleDClick() ) | |
566 | { | |
567 | button = _T("Middle"); | |
568 | dbl = ev.MiddleDClick(); | |
569 | up = ev.MiddleUp(); | |
570 | } | |
571 | else if ( ev.RightDown() || ev.RightUp() || ev.RightDClick() ) | |
572 | { | |
573 | button = _T("Right"); | |
574 | dbl = ev.RightDClick(); | |
575 | up = ev.RightUp(); | |
576 | } | |
577 | else | |
578 | { | |
579 | return _T("Unknown mouse event"); | |
580 | } | |
581 | ||
582 | return wxString::Format(_T("%s mouse button %s"), | |
583 | button.c_str(), | |
584 | dbl ? _T("double clicked") | |
585 | : up ? _T("released") : _T("clicked")); | |
586 | } | |
587 | ||
4aff28fc VZ |
588 | void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev) |
589 | { | |
56c4a88b VZ |
590 | ev.Skip(); |
591 | ||
1ce58dc6 | 592 | if ( !ms_logMouse ) |
56c4a88b VZ |
593 | return; |
594 | ||
4aff28fc VZ |
595 | if ( !ev.Moving() ) |
596 | { | |
597 | wxString msg; | |
598 | if ( ev.Entering() ) | |
599 | { | |
600 | msg = _T("Mouse entered the window"); | |
601 | } | |
602 | else if ( ev.Leaving() ) | |
603 | { | |
604 | msg = _T("Mouse left the window"); | |
605 | } | |
606 | else | |
607 | { | |
c57e3339 | 608 | msg = GetMouseEventDesc(ev); |
4aff28fc VZ |
609 | } |
610 | ||
611 | msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ") | |
612 | << _T("Flags: ") | |
4ed0aceb VZ |
613 | << GetChar( ev.LeftIsDown(), _T('1') ) |
614 | << GetChar( ev.MiddleIsDown(), _T('2') ) | |
615 | << GetChar( ev.RightIsDown(), _T('3') ) | |
4aff28fc VZ |
616 | << GetChar( ev.ControlDown(), _T('C') ) |
617 | << GetChar( ev.AltDown(), _T('A') ) | |
618 | << GetChar( ev.ShiftDown(), _T('S') ) | |
619 | << GetChar( ev.MetaDown(), _T('M') ); | |
620 | ||
621 | wxLogMessage(msg); | |
622 | } | |
623 | //else: we're not interested in mouse move events | |
624 | } | |
625 | ||
94ccc254 VZ |
626 | void MyTextCtrl::OnSetFocus(wxFocusEvent& event) |
627 | { | |
628 | if ( ms_logFocus ) | |
eba33006 | 629 | wxLogMessage( wxT("%p got focus."), this); |
94ccc254 VZ |
630 | |
631 | event.Skip(); | |
632 | } | |
633 | ||
634 | void MyTextCtrl::OnKillFocus(wxFocusEvent& event) | |
635 | { | |
636 | if ( ms_logFocus ) | |
eba33006 | 637 | wxLogMessage( wxT("%p lost focus"), this); |
94ccc254 VZ |
638 | |
639 | event.Skip(); | |
640 | } | |
641 | ||
9ca03a57 | 642 | void MyTextCtrl::OnText(wxCommandEvent& event) |
02e8b87f | 643 | { |
1ce58dc6 VZ |
644 | if ( !ms_logText ) |
645 | return; | |
646 | ||
9ca03a57 | 647 | MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject(); |
ae3dd4a5 VZ |
648 | const wxChar *data = (const wxChar *)(win->GetClientData()); |
649 | if ( data ) | |
650 | { | |
c41ea66a | 651 | wxLogMessage(_T("Text changed in control '%s'"), data); |
ae3dd4a5 | 652 | } |
f6bcfd97 BP |
653 | else |
654 | { | |
eba33006 | 655 | // wxLogMessage( event.GetString() ); |
f6bcfd97 BP |
656 | wxLogMessage(_T("Text changed in some control")); |
657 | } | |
9ca03a57 VZ |
658 | } |
659 | ||
d7eee191 VZ |
660 | void MyTextCtrl::OnTextMaxLen(wxCommandEvent& event) |
661 | { | |
662 | wxLogMessage(_T("You can't enter more characters into this control.")); | |
663 | } | |
664 | ||
c57e3339 VZ |
665 | void MyTextCtrl::OnTextURL(wxTextUrlEvent& event) |
666 | { | |
667 | const wxMouseEvent& ev = event.GetMouseEvent(); | |
668 | ||
669 | // filter out mouse moves, too many of them | |
670 | if ( ev.Moving() ) | |
671 | return; | |
672 | ||
673 | long start = event.GetURLStart(), | |
674 | end = event.GetURLEnd(); | |
675 | ||
676 | wxLogMessage(_T("Mouse event over URL '%s': %s"), | |
677 | GetValue().Mid(start, end - start).c_str(), | |
678 | GetMouseEventDesc(ev).c_str()); | |
679 | } | |
680 | ||
9ca03a57 VZ |
681 | void MyTextCtrl::OnChar(wxKeyEvent& event) |
682 | { | |
1ce58dc6 | 683 | if ( ms_logChar ) |
94ccc254 | 684 | LogKeyEvent( _T("Char"), event); |
3017f78d | 685 | |
3017f78d | 686 | event.Skip(); |
02e8b87f RR |
687 | } |
688 | ||
689 | void MyTextCtrl::OnKeyUp(wxKeyEvent& event) | |
690 | { | |
1ce58dc6 | 691 | if ( ms_logKey ) |
94ccc254 | 692 | LogKeyEvent( _T("Key up"), event); |
02e8b87f RR |
693 | |
694 | event.Skip(); | |
695 | } | |
696 | ||
697 | void MyTextCtrl::OnKeyDown(wxKeyEvent& event) | |
698 | { | |
699 | switch ( event.KeyCode() ) | |
700 | { | |
701 | case WXK_F1: | |
702 | // show current position and text length | |
703 | { | |
704 | long line, column, pos = GetInsertionPoint(); | |
705 | PositionToXY(pos, &column, &line); | |
706 | ||
4693b20c | 707 | wxLogMessage( _T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"), |
02e8b87f RR |
708 | pos, |
709 | line, column, | |
8b1d8f36 VZ |
710 | (long) GetNumberOfLines(), |
711 | (long) GetLineLength(line), | |
f6bcfd97 | 712 | GetValue().length(), |
02e8b87f RR |
713 | GetLastPosition()); |
714 | } | |
715 | break; | |
716 | ||
717 | case WXK_F2: | |
718 | // go to the end | |
719 | SetInsertionPointEnd(); | |
720 | break; | |
721 | ||
722 | case WXK_F3: | |
723 | // go to position 10 | |
724 | SetInsertionPoint(10); | |
725 | break; | |
4afd7529 | 726 | |
f152cf5a | 727 | case WXK_F4: |
4afd7529 VZ |
728 | if (!m_hasCapture) |
729 | { | |
f152cf5a | 730 | wxLogDebug( wxT("Now capturing mouse and events.") ); |
4afd7529 VZ |
731 | m_hasCapture = TRUE; |
732 | CaptureMouse(); | |
733 | } | |
734 | else | |
735 | { | |
f152cf5a | 736 | wxLogDebug( wxT("Stopped capturing mouse and events.") ); |
e3603065 | 737 | m_hasCapture = FALSE; |
4afd7529 VZ |
738 | ReleaseMouse(); |
739 | } | |
f152cf5a | 740 | break; |
4afd7529 VZ |
741 | |
742 | case WXK_F5: | |
743 | // insert a blank line | |
744 | WriteText("\n"); | |
ae3dd4a5 | 745 | break; |
02e8b87f | 746 | |
f6bcfd97 BP |
747 | case WXK_F6: |
748 | SetValue("F6 was just pressed."); | |
749 | break; | |
750 | ||
751 | case WXK_F7: | |
752 | ShowPosition(10); | |
753 | break; | |
18414479 | 754 | |
80695f83 VZ |
755 | case WXK_F8: |
756 | Clear(); | |
757 | break; | |
758 | ||
18414479 VZ |
759 | case WXK_F10: |
760 | { | |
761 | long from, to; | |
762 | GetSelection(&from, &to); | |
763 | ||
9a7d6121 | 764 | wxString sel = GetStringSelection(); |
18414479 VZ |
765 | |
766 | wxLogMessage(_T("Selection: from %ld to %ld."), from, to); | |
767 | wxLogMessage(_T("Selection = '%s' (len = %u)"), | |
768 | sel.c_str(), sel.length()); | |
769 | } | |
0ddea946 | 770 | } |
02e8b87f | 771 | |
1ce58dc6 | 772 | if ( ms_logKey ) |
94ccc254 | 773 | LogKeyEvent( wxT("Key down"), event); |
f6bcfd97 | 774 | |
02e8b87f RR |
775 | event.Skip(); |
776 | } | |
777 | ||
778 | //---------------------------------------------------------------------- | |
779 | // MyPanel | |
780 | //---------------------------------------------------------------------- | |
781 | ||
89124b1a RR |
782 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
783 | EVT_SIZE(MyPanel::OnSize) | |
784 | END_EVENT_TABLE() | |
785 | ||
02e8b87f RR |
786 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) |
787 | : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ) | |
788 | { | |
30982415 VZ |
789 | m_log = new wxTextCtrl( this, -1, "This is the log window.\n", |
790 | wxPoint(5,260), wxSize(630,100), | |
791 | wxTE_MULTILINE | wxTE_READONLY /* | wxTE_RICH */); | |
02e8b87f | 792 | |
d847e69a | 793 | m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); |
02e8b87f RR |
794 | |
795 | // single line text controls | |
796 | ||
bb69661b | 797 | m_text = new MyTextCtrl( this, -1, "Single line.", |
f6bcfd97 BP |
798 | wxPoint(10,10), wxSize(140,-1), |
799 | wxTE_PROCESS_ENTER); | |
4ed0aceb VZ |
800 | m_text->SetForegroundColour(*wxBLUE); |
801 | m_text->SetBackgroundColour(*wxLIGHT_GREY); | |
02e8b87f RR |
802 | (*m_text) << " Appended."; |
803 | m_text->SetInsertionPoint(0); | |
804 | m_text->WriteText( "Prepended. " ); | |
bb69661b VZ |
805 | |
806 | m_password = new MyTextCtrl( this, -1, "", | |
02e8b87f | 807 | wxPoint(10,50), wxSize(140,-1), wxTE_PASSWORD ); |
bb69661b VZ |
808 | |
809 | m_readonly = new MyTextCtrl( this, -1, "Read only", | |
02e8b87f | 810 | wxPoint(10,90), wxSize(140,-1), wxTE_READONLY ); |
bb69661b | 811 | |
d7eee191 VZ |
812 | m_limited = new MyTextCtrl(this, -1, "Max 8 ch", |
813 | wxPoint(10, 130), wxSize(140, -1)); | |
814 | m_limited->SetMaxLength(8); | |
815 | ||
02e8b87f RR |
816 | // multi line text controls |
817 | ||
bb69661b VZ |
818 | m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.", |
819 | wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL ); | |
f6bcfd97 BP |
820 | |
821 | // a little hack to use the command line argument for encoding testing | |
822 | if ( wxTheApp->argc == 2 ) | |
823 | { | |
824 | switch ( wxTheApp->argv[1][0] ) | |
825 | { | |
826 | case '2': | |
827 | m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL, | |
828 | FALSE, "", | |
829 | wxFONTENCODING_ISO8859_2)); | |
830 |