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