]>
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) | |
f152cf5a | 64 | : wxTextCtrl(parent, id, value, pos, size, style) { m_hasCapture = FALSE; } |
02e8b87f RR |
65 | |
66 | void OnKeyDown(wxKeyEvent& event); | |
67 | void OnKeyUp(wxKeyEvent& event); | |
68 | void OnChar(wxKeyEvent& event); | |
9ca03a57 | 69 | void OnText(wxCommandEvent& event); |
4aff28fc | 70 | void OnMouseEvent(wxMouseEvent& event); |
02e8b87f | 71 | |
f6bcfd97 | 72 | bool m_hasCapture; |
f152cf5a | 73 | |
02e8b87f RR |
74 | private: |
75 | static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); } | |
76 | void LogEvent(const wxChar *name, wxKeyEvent& event) const; | |
77 | ||
78 | DECLARE_EVENT_TABLE() | |
79 | }; | |
80 | ||
81 | class MyPanel: public wxPanel | |
82 | { | |
83 | public: | |
84 | MyPanel(wxFrame *frame, int x, int y, int w, int h); | |
85 | ||
b6a0d8a2 VZ |
86 | #if wxUSE_CLIPBOARD |
87 | void DoPasteFromClipboard(); | |
88 | void DoCopyToClipboard(); | |
89 | #endif // wxUSE_CLIPBOARD | |
90 | ||
91 | void DoMoveToEndOfText(); | |
92 | void DoMoveToEndOfEntry(); | |
02e8b87f | 93 | |
89124b1a RR |
94 | void OnSize( wxSizeEvent &event ); |
95 | ||
02e8b87f RR |
96 | MyTextCtrl *m_text; |
97 | MyTextCtrl *m_password; | |
98 | MyTextCtrl *m_enter; | |
99 | MyTextCtrl *m_tab; | |
02e8b87f | 100 | MyTextCtrl *m_readonly; |
bb69661b | 101 | |
02e8b87f RR |
102 | MyTextCtrl *m_multitext; |
103 | MyTextCtrl *m_horizontal; | |
02e8b87f | 104 | |
0ddea946 VZ |
105 | MyTextCtrl *m_textrich; |
106 | ||
02e8b87f | 107 | wxTextCtrl *m_log; |
89124b1a RR |
108 | |
109 | private: | |
110 | DECLARE_EVENT_TABLE() | |
02e8b87f RR |
111 | }; |
112 | ||
113 | class MyFrame: public wxFrame | |
114 | { | |
115 | public: | |
b6a0d8a2 | 116 | MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h); |
02e8b87f RR |
117 | |
118 | void OnQuit(wxCommandEvent& event); | |
119 | void OnAbout(wxCommandEvent& event); | |
120 | #if wxUSE_TOOLTIPS | |
121 | void OnSetTooltipDelay(wxCommandEvent& event); | |
122 | void OnToggleTooltips(wxCommandEvent& event); | |
123 | #endif // wxUSE_TOOLTIPS | |
b6a0d8a2 VZ |
124 | |
125 | #if wxUSE_CLIPBOARD | |
126 | void OnPasteFromClipboard( wxCommandEvent &event ) | |
127 | { m_panel->DoPasteFromClipboard(); } | |
128 | void OnCopyToClipboard( wxCommandEvent &event ) | |
129 | { m_panel->DoCopyToClipboard(); } | |
130 | #endif // wxUSE_CLIPBOARD | |
131 | ||
132 | void OnMoveToEndOfText( wxCommandEvent &event ) | |
133 | { m_panel->DoMoveToEndOfText(); } | |
134 | void OnMoveToEndOfEntry( wxCommandEvent &event ) | |
135 | { m_panel->DoMoveToEndOfEntry(); } | |
136 | ||
e66ad5c6 | 137 | void OnLogClear(wxCommandEvent& event); |
0ddea946 | 138 | void OnFileSave(wxCommandEvent& event); |
b6a0d8a2 VZ |
139 | void OnFileLoad(wxCommandEvent& event); |
140 | ||
f6bcfd97 BP |
141 | void OnSetEditable(wxCommandEvent& event); |
142 | void OnSetEnabled(wxCommandEvent& event); | |
143 | ||
02e8b87f RR |
144 | void OnIdle( wxIdleEvent& event ); |
145 | ||
146 | private: | |
b6a0d8a2 VZ |
147 | MyPanel *m_panel; |
148 | ||
02e8b87f RR |
149 | DECLARE_EVENT_TABLE() |
150 | }; | |
151 | ||
152 | //---------------------------------------------------------------------- | |
153 | // main() | |
154 | //---------------------------------------------------------------------- | |
155 | ||
156 | IMPLEMENT_APP(MyApp) | |
157 | ||
158 | //---------------------------------------------------------------------- | |
159 | // MyApp | |
160 | //---------------------------------------------------------------------- | |
161 | ||
162 | enum | |
163 | { | |
b6a0d8a2 VZ |
164 | TEXT_QUIT = 100, |
165 | TEXT_ABOUT, | |
166 | TEXT_LOAD, | |
ae3dd4a5 | 167 | TEXT_SAVE, |
e66ad5c6 | 168 | TEXT_CLEAR, |
b6a0d8a2 VZ |
169 | |
170 | // clipboard menu | |
171 | TEXT_CLIPBOARD_COPY = 200, | |
172 | TEXT_CLIPBOARD_PASTE, | |
02e8b87f RR |
173 | |
174 | // tooltip menu | |
b6a0d8a2 VZ |
175 | TEXT_TOOLTIPS_SETDELAY = 300, |
176 | TEXT_TOOLTIPS_ENABLE, | |
177 | ||
f6bcfd97 | 178 | // text menu |
b6a0d8a2 | 179 | TEXT_MOVE_ENDTEXT = 400, |
f6bcfd97 BP |
180 | TEXT_MOVE_ENDENTRY, |
181 | TEXT_SET_EDITABLE, | |
182 | TEXT_SET_ENABLED | |
02e8b87f RR |
183 | }; |
184 | ||
185 | bool MyApp::OnInit() | |
186 | { | |
187 | // Create the main frame window | |
188 | MyFrame *frame = new MyFrame((wxFrame *) NULL, | |
17665a2b | 189 | "Text wxWindows sample", 50, 50, 700, 420); |
89124b1a | 190 | frame->SetSizeHints( 500, 400 ); |
02e8b87f | 191 | |
02e8b87f | 192 | wxMenu *file_menu = new wxMenu; |
e66ad5c6 VZ |
193 | file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C", |
194 | "Clear the log window contents"); | |
0ddea946 VZ |
195 | file_menu->Append(TEXT_SAVE, "&Save file\tCtrl-S", |
196 | "Save the text control contents to file"); | |
b6a0d8a2 VZ |
197 | file_menu->Append(TEXT_LOAD, "&Load file\tCtrl-O", |
198 | "Load the sample file into text control"); | |
199 | file_menu->AppendSeparator(); | |
200 | file_menu->Append(TEXT_ABOUT, "&About\tAlt-A"); | |
201 | file_menu->AppendSeparator(); | |
c41ea66a | 202 | file_menu->Append(TEXT_QUIT, "E&xit\tAlt-X", "Quit this sample"); |
02e8b87f RR |
203 | |
204 | wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE ); | |
205 | menu_bar->Append(file_menu, "&File"); | |
206 | ||
207 | #if wxUSE_TOOLTIPS | |
208 | wxMenu *tooltip_menu = new wxMenu; | |
b6a0d8a2 | 209 | tooltip_menu->Append(TEXT_TOOLTIPS_SETDELAY, "Set &delay\tCtrl-D"); |
02e8b87f | 210 | tooltip_menu->AppendSeparator(); |
b6a0d8a2 | 211 | tooltip_menu->Append(TEXT_TOOLTIPS_ENABLE, "&Toggle tooltips\tCtrl-T", |
02e8b87f | 212 | "enable/disable tooltips", TRUE); |
b6a0d8a2 | 213 | tooltip_menu->Check(TEXT_TOOLTIPS_ENABLE, TRUE); |
02e8b87f RR |
214 | menu_bar->Append(tooltip_menu, "&Tooltips"); |
215 | #endif // wxUSE_TOOLTIPS | |
216 | ||
b6a0d8a2 VZ |
217 | #if wxUSE_CLIPBOARD |
218 | wxMenu *menuClipboard = new wxMenu; | |
219 | menuClipboard->Append(TEXT_CLIPBOARD_COPY, "&Copy\tCtrl-C", | |
220 | "Copy the first line to the clipboard"); | |
221 | menuClipboard->Append(TEXT_CLIPBOARD_PASTE, "&Paste\tCtrl-V", | |
222 | "Paste from clipboard to the text control"); | |
223 | menu_bar->Append(menuClipboard, "&Clipboard"); | |
224 | #endif // wxUSE_CLIPBOARD | |
225 | ||
f6bcfd97 BP |
226 | wxMenu *menuText = new wxMenu; |
227 | menuText->Append(TEXT_MOVE_ENDTEXT, "Move cursor to the end of &text"); | |
228 | menuText->Append(TEXT_MOVE_ENDENTRY, "Move cursor to the end of &entry"); | |
229 | menuText->Append(TEXT_SET_EDITABLE, "Toggle &editable state", "", TRUE); | |
230 | menuText->Append(TEXT_SET_ENABLED, "Toggle e&nabled state", "", TRUE); | |
231 | menuText->Check(TEXT_SET_EDITABLE, TRUE); | |
232 | menuText->Check(TEXT_SET_ENABLED, TRUE); | |
233 | menu_bar->Append(menuText, "&Text"); | |
b6a0d8a2 | 234 | |
02e8b87f RR |
235 | frame->SetMenuBar(menu_bar); |
236 | ||
237 | frame->Show(TRUE); | |
238 | ||
239 | SetTopWindow(frame); | |
240 | ||
241 | // report success | |
242 | return TRUE; | |
243 | } | |
244 | ||
245 | //---------------------------------------------------------------------- | |
246 | // MyTextCtrl | |
247 | //---------------------------------------------------------------------- | |
248 | ||
249 | BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl) | |
250 | EVT_KEY_DOWN(MyTextCtrl::OnKeyDown) | |
251 | EVT_KEY_UP(MyTextCtrl::OnKeyUp) | |
252 | EVT_CHAR(MyTextCtrl::OnChar) | |
9ca03a57 | 253 | EVT_TEXT(-1, MyTextCtrl::OnText) |
4aff28fc | 254 | EVT_MOUSE_EVENTS(MyTextCtrl::OnMouseEvent) |
02e8b87f RR |
255 | END_EVENT_TABLE() |
256 | ||
257 | void MyTextCtrl::LogEvent(const wxChar *name, wxKeyEvent& event) const | |
258 | { | |
259 | wxString key; | |
260 | long keycode = event.KeyCode(); | |
02e8b87f RR |
261 | { |
262 | switch ( keycode ) | |
263 | { | |
264 | case WXK_BACK: key = "BACK"; break; | |
265 | case WXK_TAB: key = "TAB"; break; | |
266 | case WXK_RETURN: key = "RETURN"; break; | |
267 | case WXK_ESCAPE: key = "ESCAPE"; break; | |
268 | case WXK_SPACE: key = "SPACE"; break; | |
269 | case WXK_DELETE: key = "DELETE"; break; | |
270 | case WXK_START: key = "START"; break; | |
271 | case WXK_LBUTTON: key = "LBUTTON"; break; | |
272 | case WXK_RBUTTON: key = "RBUTTON"; break; | |
273 | case WXK_CANCEL: key = "CANCEL"; break; | |
274 | case WXK_MBUTTON: key = "MBUTTON"; break; | |
275 | case WXK_CLEAR: key = "CLEAR"; break; | |
276 | case WXK_SHIFT: key = "SHIFT"; break; | |
277 | case WXK_ALT: key = "ALT"; break; | |
278 | case WXK_CONTROL: key = "CONTROL"; break; | |
279 | case WXK_MENU: key = "MENU"; break; | |
280 | case WXK_PAUSE: key = "PAUSE"; break; | |
281 | case WXK_CAPITAL: key = "CAPITAL"; break; | |
282 | case WXK_PRIOR: key = "PRIOR"; break; | |
283 | case WXK_NEXT: key = "NEXT"; break; | |
284 | case WXK_END: key = "END"; break; | |
285 | case WXK_HOME: key = "HOME"; break; | |
286 | case WXK_LEFT: key = "LEFT"; break; | |
287 | case WXK_UP: key = "UP"; break; | |
288 | case WXK_RIGHT: key = "RIGHT"; break; | |
289 | case WXK_DOWN: key = "DOWN"; break; | |
290 | case WXK_SELECT: key = "SELECT"; break; | |
291 | case WXK_PRINT: key = "PRINT"; break; | |
292 | case WXK_EXECUTE: key = "EXECUTE"; break; | |
293 | case WXK_SNAPSHOT: key = "SNAPSHOT"; break; | |
294 | case WXK_INSERT: key = "INSERT"; break; | |
295 | case WXK_HELP: key = "HELP"; break; | |
296 | case WXK_NUMPAD0: key = "NUMPAD0"; break; | |
297 | case WXK_NUMPAD1: key = "NUMPAD1"; break; | |
298 | case WXK_NUMPAD2: key = "NUMPAD2"; break; | |
299 | case WXK_NUMPAD3: key = "NUMPAD3"; break; | |
300 | case WXK_NUMPAD4: key = "NUMPAD4"; break; | |
301 | case WXK_NUMPAD5: key = "NUMPAD5"; break; | |
302 | case WXK_NUMPAD6: key = "NUMPAD6"; break; | |
303 | case WXK_NUMPAD7: key = "NUMPAD7"; break; | |
304 | case WXK_NUMPAD8: key = "NUMPAD8"; break; | |
305 | case WXK_NUMPAD9: key = "NUMPAD9"; break; | |
306 | case WXK_MULTIPLY: key = "MULTIPLY"; break; | |
307 | case WXK_ADD: key = "ADD"; break; | |
308 | case WXK_SEPARATOR: key = "SEPARATOR"; break; | |
309 | case WXK_SUBTRACT: key = "SUBTRACT"; break; | |
310 | case WXK_DECIMAL: key = "DECIMAL"; break; | |
311 | case WXK_DIVIDE: key = "DIVIDE"; break; | |
312 | case WXK_F1: key = "F1"; break; | |
313 | case WXK_F2: key = "F2"; break; | |
314 | case WXK_F3: key = "F3"; break; | |
315 | case WXK_F4: key = "F4"; break; | |
316 | case WXK_F5: key = "F5"; break; | |
317 | case WXK_F6: key = "F6"; break; | |
318 | case WXK_F7: key = "F7"; break; | |
319 | case WXK_F8: key = "F8"; break; | |
320 | case WXK_F9: key = "F9"; break; | |
321 | case WXK_F10: key = "F10"; break; | |
322 | case WXK_F11: key = "F11"; break; | |
323 | case WXK_F12: key = "F12"; break; | |
324 | case WXK_F13: key = "F13"; break; | |
325 | case WXK_F14: key = "F14"; break; | |
326 | case WXK_F15: key = "F15"; break; | |
327 | case WXK_F16: key = "F16"; break; | |
328 | case WXK_F17: key = "F17"; break; | |
329 | case WXK_F18: key = "F18"; break; | |
330 | case WXK_F19: key = "F19"; break; | |
331 | case WXK_F20: key = "F20"; break; | |
332 | case WXK_F21: key = "F21"; break; | |
333 | case WXK_F22: key = "F22"; break; | |
334 | case WXK_F23: key = "F23"; break; | |
335 | case WXK_F24: key = "F24"; break; | |
336 | case WXK_NUMLOCK: key = "NUMLOCK"; break; | |
337 | case WXK_SCROLL: key = "SCROLL"; break; | |
338 | case WXK_PAGEUP: key = "PAGEUP"; break; | |
339 | case WXK_PAGEDOWN: key = "PAGEDOWN"; break; | |
340 | case WXK_NUMPAD_SPACE: key = "NUMPAD_SPACE"; break; | |
341 | case WXK_NUMPAD_TAB: key = "NUMPAD_TAB"; break; | |
342 | case WXK_NUMPAD_ENTER: key = "NUMPAD_ENTER"; break; | |
343 | case WXK_NUMPAD_F1: key = "NUMPAD_F1"; break; | |
344 | case WXK_NUMPAD_F2: key = "NUMPAD_F2"; break; | |
345 | case WXK_NUMPAD_F3: key = "NUMPAD_F3"; break; | |
346 | case WXK_NUMPAD_F4: key = "NUMPAD_F4"; break; | |
347 | case WXK_NUMPAD_HOME: key = "NUMPAD_HOME"; break; | |
348 | case WXK_NUMPAD_LEFT: key = "NUMPAD_LEFT"; break; | |
349 | case WXK_NUMPAD_UP: key = "NUMPAD_UP"; break; | |
350 | case WXK_NUMPAD_RIGHT: key = "NUMPAD_RIGHT"; break; | |
351 | case WXK_NUMPAD_DOWN: key = "NUMPAD_DOWN"; break; | |
352 | case WXK_NUMPAD_PRIOR: key = "NUMPAD_PRIOR"; break; | |
353 | case WXK_NUMPAD_PAGEUP: key = "NUMPAD_PAGEUP"; break; | |
354 | case WXK_NUMPAD_PAGEDOWN: key = "NUMPAD_PAGEDOWN"; break; | |
355 | case WXK_NUMPAD_END: key = "NUMPAD_END"; break; | |
356 | case WXK_NUMPAD_BEGIN: key = "NUMPAD_BEGIN"; break; | |
357 | case WXK_NUMPAD_INSERT: key = "NUMPAD_INSERT"; break; | |
358 | case WXK_NUMPAD_DELETE: key = "NUMPAD_DELETE"; break; | |
359 | case WXK_NUMPAD_EQUAL: key = "NUMPAD_EQUAL"; break; | |
360 | case WXK_NUMPAD_MULTIPLY: key = "NUMPAD_MULTIPLY"; break; | |
361 | case WXK_NUMPAD_ADD: key = "NUMPAD_ADD"; break; | |
362 | case WXK_NUMPAD_SEPARATOR: key = "NUMPAD_SEPARATOR"; break; | |
363 | case WXK_NUMPAD_SUBTRACT: key = "NUMPAD_SUBTRACT"; break; | |
364 | case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break; | |
365 | ||
4afd7529 | 366 | default: |
89124b1a RR |
367 | { |
368 | if ( wxIsprint((int)keycode) ) | |
369 | key.Printf( _T("'%c'") , (char)keycode); | |
370 | else | |
4afd7529 VZ |
371 | key.Printf( _T("unknown (%ld)"), keycode); |
372 | } | |
02e8b87f RR |
373 | } |
374 | } | |
375 | ||
376 | wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"), | |
377 | name, | |
378 | key.c_str(), | |
379 | GetChar( event.ControlDown(), _T('C') ), | |
380 | GetChar( event.AltDown(), _T('A') ), | |
381 | GetChar( event.ShiftDown(), _T('S') ), | |
382 | GetChar( event.MetaDown(), _T('M') ) ); | |
02e8b87f RR |
383 | } |
384 | ||
4aff28fc VZ |
385 | void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev) |
386 | { | |
387 | if ( !ev.Moving() ) | |
388 | { | |
389 | wxString msg; | |
390 | if ( ev.Entering() ) | |
391 | { | |
392 | msg = _T("Mouse entered the window"); | |
393 | } | |
394 | else if ( ev.Leaving() ) | |
395 | { | |
396 | msg = _T("Mouse left the window"); | |
397 | } | |
398 | else | |
399 | { | |
400 | // click event | |
401 | wxString button; | |
402 | bool dbl, up; | |
403 | if ( ev.LeftDown() || ev.LeftUp() || ev.LeftDClick() ) | |
404 | { | |
405 | button = _T("Left"); | |
406 | dbl = ev.LeftDClick(); | |
407 | up = ev.LeftUp(); | |
408 | } | |
409 | else if ( ev.MiddleDown() || ev.MiddleUp() || ev.MiddleDClick() ) | |
410 | { | |
411 | button = _T("Middle"); | |
412 | dbl = ev.MiddleDClick(); | |
413 | up = ev.MiddleUp(); | |
414 | } | |
415 | else if ( ev.RightDown() || ev.RightUp() || ev.RightDClick() ) | |
416 | { | |
417 | button = _T("Right"); | |
418 | dbl = ev.RightDClick(); | |
419 | up = ev.RightUp(); | |
420 | } | |
421 | else | |
422 | { | |
423 | wxLogStatus(_T("Unknown mouse event")); | |
424 | return; | |
425 | } | |
426 | ||
427 | msg.Printf(_T("%s mouse button %s"), | |
428 | button.c_str(), | |
429 | dbl ? _T("double clicked") | |
430 | : up ? _T("released") : _T("clicked")); | |
431 | } | |
432 | ||
433 | msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ") | |
434 | << _T("Flags: ") | |
4ed0aceb VZ |
435 | << GetChar( ev.LeftIsDown(), _T('1') ) |
436 | << GetChar( ev.MiddleIsDown(), _T('2') ) | |
437 | << GetChar( ev.RightIsDown(), _T('3') ) | |
4aff28fc VZ |
438 | << GetChar( ev.ControlDown(), _T('C') ) |
439 | << GetChar( ev.AltDown(), _T('A') ) | |
440 | << GetChar( ev.ShiftDown(), _T('S') ) | |
441 | << GetChar( ev.MetaDown(), _T('M') ); | |
442 | ||
443 | wxLogMessage(msg); | |
444 | } | |
445 | //else: we're not interested in mouse move events | |
4ed0aceb VZ |
446 | |
447 | ev.Skip(); | |
4aff28fc VZ |
448 | } |
449 | ||
9ca03a57 | 450 | void MyTextCtrl::OnText(wxCommandEvent& event) |
02e8b87f | 451 | { |
9ca03a57 | 452 | MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject(); |
ae3dd4a5 VZ |
453 | const wxChar *data = (const wxChar *)(win->GetClientData()); |
454 | if ( data ) | |
455 | { | |
c41ea66a | 456 | wxLogMessage(_T("Text changed in control '%s'"), data); |
ae3dd4a5 | 457 | } |
f6bcfd97 BP |
458 | else |
459 | { | |
460 | wxLogMessage(_T("Text changed in some control")); | |
461 | } | |
9ca03a57 VZ |
462 | } |
463 | ||
464 | void MyTextCtrl::OnChar(wxKeyEvent& event) | |
465 | { | |
466 | LogEvent( _T("Char"), event); | |
ae3dd4a5 | 467 | |
3017f78d RR |
468 | /* How are we supposed to test wxTE_PROCESS_TAB with this code? |
469 | ||
b6a0d8a2 VZ |
470 | if ( event.KeyCode() == WXK_TAB ) |
471 | { | |
472 | WriteText("\t"); | |
473 | } | |
474 | else | |
475 | { | |
476 | event.Skip(); | |
477 | } | |
3017f78d RR |
478 | */ |
479 | event.Skip(); | |
02e8b87f RR |
480 | } |
481 | ||
482 | void MyTextCtrl::OnKeyUp(wxKeyEvent& event) | |
483 | { | |
ae3dd4a5 | 484 | LogEvent( _T("Key up"), event); |
02e8b87f RR |
485 | |
486 | event.Skip(); | |
487 | } | |
488 | ||
489 | void MyTextCtrl::OnKeyDown(wxKeyEvent& event) | |
490 | { | |
491 | switch ( event.KeyCode() ) | |
492 | { | |
493 | case WXK_F1: | |
494 | // show current position and text length | |
495 | { | |
496 | long line, column, pos = GetInsertionPoint(); | |
497 | PositionToXY(pos, &column, &line); | |
498 | ||
499 | wxLogMessage( _T("Current position: %ld\n" | |
500 | "Current line, column: (%ld, %ld)\n" | |
501 | "Number of lines: %ld\n" | |
502 | "Current line length: %ld\n" | |
f6bcfd97 | 503 | "Total text length: %u (%ld)"), |
02e8b87f RR |
504 | pos, |
505 | line, column, | |
506 | GetNumberOfLines(), | |
507 | GetLineLength(line), | |
f6bcfd97 | 508 | GetValue().length(), |
02e8b87f RR |
509 | GetLastPosition()); |
510 | } | |
511 | break; | |
512 | ||
513 | case WXK_F2: | |
514 | // go to the end | |
515 | SetInsertionPointEnd(); | |
516 | break; | |
517 | ||
518 | case WXK_F3: | |
519 | // go to position 10 | |
520 | SetInsertionPoint(10); | |
521 | break; | |
4afd7529 | 522 | |
f152cf5a | 523 | case WXK_F4: |
4afd7529 VZ |
524 | if (!m_hasCapture) |
525 | { | |
f152cf5a | 526 | wxLogDebug( wxT("Now capturing mouse and events.") ); |
4afd7529 VZ |
527 | m_hasCapture = TRUE; |
528 | CaptureMouse(); | |
529 | } | |
530 | else | |
531 | { | |
f152cf5a | 532 | wxLogDebug( wxT("Stopped capturing mouse and events.") ); |
4afd7529 VZ |
533 | m_hasCapture = TRUE; |
534 | ReleaseMouse(); | |
535 | } | |
f152cf5a | 536 | break; |
4afd7529 VZ |
537 | |
538 | case WXK_F5: | |
539 | // insert a blank line | |
540 | WriteText("\n"); | |
ae3dd4a5 | 541 | break; |
02e8b87f | 542 | |
f6bcfd97 BP |
543 | case WXK_F6: |
544 | SetValue("F6 was just pressed."); | |
545 | break; | |
546 | ||
547 | case WXK_F7: | |
548 | ShowPosition(10); | |
549 | break; | |
0ddea946 | 550 | } |
02e8b87f | 551 | |
f6bcfd97 BP |
552 | LogEvent( wxT("Key down"), event); |
553 | ||
02e8b87f RR |
554 | event.Skip(); |
555 | } | |
556 | ||
557 | //---------------------------------------------------------------------- | |
558 | // MyPanel | |
559 | //---------------------------------------------------------------------- | |
560 | ||
89124b1a RR |
561 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
562 | EVT_SIZE(MyPanel::OnSize) | |
563 | END_EVENT_TABLE() | |
564 | ||
02e8b87f RR |
565 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) |
566 | : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ) | |
567 | { | |
568 | m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(5,260), wxSize(630,100), wxTE_MULTILINE ); | |
569 | ||
89124b1a RR |
570 | wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); |
571 | ||
572 | delete old_log; | |
02e8b87f RR |
573 | |
574 | // single line text controls | |
575 | ||
bb69661b | 576 | m_text = new MyTextCtrl( this, -1, "Single line.", |
f6bcfd97 BP |
577 | wxPoint(10,10), wxSize(140,-1), |
578 | wxTE_PROCESS_ENTER); | |
4ed0aceb VZ |
579 | m_text->SetForegroundColour(*wxBLUE); |
580 | m_text->SetBackgroundColour(*wxLIGHT_GREY); | |
02e8b87f RR |
581 | (*m_text) << " Appended."; |
582 | m_text->SetInsertionPoint(0); | |
583 | m_text->WriteText( "Prepended. " ); | |
bb69661b VZ |
584 | |
585 | m_password = new MyTextCtrl( this, -1, "", | |
02e8b87f | 586 | wxPoint(10,50), wxSize(140,-1), wxTE_PASSWORD ); |
bb69661b VZ |
587 | |
588 | m_readonly = new MyTextCtrl( this, -1, "Read only", | |
02e8b87f | 589 | wxPoint(10,90), wxSize(140,-1), wxTE_READONLY ); |
bb69661b | 590 | |
02e8b87f RR |
591 | // multi line text controls |
592 | ||
bb69661b VZ |
593 | m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.", |
594 | wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL ); | |
f6bcfd97 BP |
595 | |
596 | // a little hack to use the command line argument for encoding testing | |
597 | if ( wxTheApp->argc == 2 ) | |
598 | { | |
599 | switch ( wxTheApp->argv[1][0] ) | |
600 | { | |
601 | case '2': | |
602 | m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL, | |
603 | FALSE, "", | |
604 | wxFONTENCODING_ISO8859_2)); | |
605 |