]> git.saurik.com Git - wxWidgets.git/blob - samples/text/text.cpp
Mentioned: Applied patch [ 701238 ] Added BLOB support to dbtable.
[wxWidgets.git] / samples / text / text.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: text.cpp
3 // Purpose: TextCtrl wxWindows sample
4 // Author: Robert Roebling
5 // Modified by:
6 // RCS-ID: $Id$
7 // Copyright: (c) Robert Roebling, Julian Smart, Vadim Zeitlin
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "text.cpp"
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
31 #if wxUSE_FILE
32 #include "wx/file.h"
33 #endif
34
35 #if wxUSE_TOOLTIPS
36 #include "wx/tooltip.h"
37 #endif
38
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
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)
64 : wxTextCtrl(parent, id, value, pos, size, style)
65 {
66 m_hasCapture = FALSE;
67 }
68
69 void OnKeyDown(wxKeyEvent& event);
70 void OnKeyUp(wxKeyEvent& event);
71 void OnChar(wxKeyEvent& event);
72
73 void OnText(wxCommandEvent& event);
74 void OnTextURL(wxTextUrlEvent& event);
75 void OnTextMaxLen(wxCommandEvent& event);
76
77 void OnMouseEvent(wxMouseEvent& event);
78
79 void OnSetFocus(wxFocusEvent& event);
80 void OnKillFocus(wxFocusEvent& event);
81
82 static bool ms_logKey;
83 static bool ms_logChar;
84 static bool ms_logMouse;
85 static bool ms_logText;
86 static bool ms_logFocus;
87
88 private:
89 static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); }
90 void LogKeyEvent(const wxChar *name, wxKeyEvent& event) const;
91
92 bool m_hasCapture;
93
94 DECLARE_EVENT_TABLE()
95 };
96
97 class MyPanel: public wxPanel
98 {
99 public:
100 MyPanel(wxFrame *frame, int x, int y, int w, int h);
101 virtual ~MyPanel() { delete wxLog::SetActiveTarget(m_logOld); }
102
103 #if wxUSE_CLIPBOARD
104 void DoPasteFromClipboard();
105 void DoCopyToClipboard();
106 #endif // wxUSE_CLIPBOARD
107
108 void DoRemoveText();
109 void DoReplaceText();
110 void DoSelectText();
111 void DoMoveToEndOfText();
112 void DoMoveToEndOfEntry();
113
114 void OnSize( wxSizeEvent &event );
115
116 MyTextCtrl *m_text;
117 MyTextCtrl *m_password;
118 MyTextCtrl *m_enter;
119 MyTextCtrl *m_tab;
120 MyTextCtrl *m_readonly;
121 MyTextCtrl *m_limited;
122
123 MyTextCtrl *m_multitext;
124 MyTextCtrl *m_horizontal;
125
126 MyTextCtrl *m_textrich;
127
128 wxTextCtrl *m_log;
129
130 wxLog *m_logOld;
131
132 private:
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
137 DECLARE_EVENT_TABLE()
138 };
139
140 class MyFrame: public wxFrame
141 {
142 public:
143 MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h);
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
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
159 void OnAddTextFreeze( wxCommandEvent& event )
160 { DoAddText(true); }
161 void OnAddText( wxCommandEvent& event )
162 { DoAddText(false); }
163 void OnRemoveText( wxCommandEvent& event )
164 { m_panel->DoRemoveText(); }
165 void OnReplaceText( wxCommandEvent& event )
166 { m_panel->DoReplaceText(); }
167 void OnSelectText( wxCommandEvent& event )
168 { m_panel->DoSelectText(); }
169
170 void OnMoveToEndOfText( wxCommandEvent &event )
171 { m_panel->DoMoveToEndOfText(); }
172 void OnMoveToEndOfEntry( wxCommandEvent &event )
173 { m_panel->DoMoveToEndOfEntry(); }
174
175 void OnScrollLineDown(wxCommandEvent& event)
176 {
177 if ( !m_panel->m_textrich->LineDown() )
178 wxLogMessage(_T("Already at the bottom"));
179 }
180
181 void OnScrollLineUp(wxCommandEvent& event)
182 {
183 if ( !m_panel->m_textrich->LineUp() )
184 wxLogMessage(_T("Already at the top"));
185 }
186
187 void OnScrollPageDown(wxCommandEvent& event)
188 {
189 if ( !m_panel->m_textrich->PageDown() )
190 wxLogMessage(_T("Already at the bottom"));
191 }
192
193 void OnScrollPageUp(wxCommandEvent& event)
194 {
195 if ( !m_panel->m_textrich->PageUp() )
196 wxLogMessage(_T("Already at the top"));
197 }
198
199 void OnLogClear(wxCommandEvent& event);
200 void OnFileSave(wxCommandEvent& event);
201 void OnFileLoad(wxCommandEvent& event);
202
203 void OnSetEditable(wxCommandEvent& event);
204 void OnSetEnabled(wxCommandEvent& event);
205
206 void OnLogKey(wxCommandEvent& event)
207 {
208 MyTextCtrl::ms_logKey = event.IsChecked();
209 }
210
211 void OnLogChar(wxCommandEvent& event)
212 {
213 MyTextCtrl::ms_logChar = event.IsChecked();
214 }
215
216 void OnLogMouse(wxCommandEvent& event)
217 {
218 MyTextCtrl::ms_logMouse = event.IsChecked();
219 }
220
221 void OnLogText(wxCommandEvent& event)
222 {
223 MyTextCtrl::ms_logText = event.IsChecked();
224 }
225
226 void OnLogFocus(wxCommandEvent& event)
227 {
228 MyTextCtrl::ms_logFocus = event.IsChecked();
229 }
230
231 void OnSetText(wxCommandEvent& event)
232 {
233 m_panel->m_text->SetValue(_T("Hello, world (what else did you expect)?"));
234 }
235
236 void OnIdle( wxIdleEvent& event );
237
238 private:
239 void DoAddText(bool freeze)
240 {
241 wxTextCtrl * const text = m_panel->m_textrich;
242 text->Clear();
243
244 if ( freeze )
245 text->Freeze();
246
247 for ( int i = 0; i < 100; i++ )
248 {
249 text->AppendText(wxString::Format(wxT("Line %i\n"), i));
250 }
251
252 if ( freeze )
253 text->Thaw();
254
255 text->SetInsertionPoint(0);
256 }
257
258 MyPanel *m_panel;
259
260 DECLARE_EVENT_TABLE()
261 };
262
263 //----------------------------------------------------------------------
264 // main()
265 //----------------------------------------------------------------------
266
267 IMPLEMENT_APP(MyApp)
268
269 //----------------------------------------------------------------------
270 // MyApp
271 //----------------------------------------------------------------------
272
273 enum
274 {
275 TEXT_QUIT = 100,
276 TEXT_ABOUT,
277 TEXT_LOAD,
278 TEXT_SAVE,
279 TEXT_CLEAR,
280
281 // clipboard menu
282 TEXT_CLIPBOARD_COPY = 200,
283 TEXT_CLIPBOARD_PASTE,
284
285 // tooltip menu
286 TEXT_TOOLTIPS_SETDELAY = 300,
287 TEXT_TOOLTIPS_ENABLE,
288
289 // text menu
290 TEXT_ADD_SOME = 400,
291 TEXT_ADD_FREEZE,
292 TEXT_MOVE_ENDTEXT,
293 TEXT_MOVE_ENDENTRY,
294 TEXT_SET_EDITABLE,
295 TEXT_SET_ENABLED,
296 TEXT_LINE_DOWN,
297 TEXT_LINE_UP,
298 TEXT_PAGE_DOWN,
299 TEXT_PAGE_UP,
300 TEXT_REMOVE,
301 TEXT_REPLACE,
302 TEXT_SELECT,
303 TEXT_SET,
304
305 // log menu
306 TEXT_LOG_KEY,
307 TEXT_LOG_CHAR,
308 TEXT_LOG_MOUSE,
309 TEXT_LOG_TEXT,
310 TEXT_LOG_FOCUS,
311
312 TEXT_END
313 };
314
315 bool MyApp::OnInit()
316 {
317 // Create the main frame window
318 MyFrame *frame = new MyFrame((wxFrame *) NULL,
319 _T("Text wxWindows sample"), 50, 50, 700, 420);
320 frame->SetSizeHints( 500, 400 );
321
322 wxMenu *file_menu = new wxMenu;
323 file_menu->Append(TEXT_SAVE, _T("&Save file\tCtrl-S"),
324 _T("Save the text control contents to file"));
325 file_menu->Append(TEXT_LOAD, _T("&Load file\tCtrl-O"),
326 _T("Load the sample file into text control"));
327 file_menu->AppendSeparator();
328 file_menu->Append(TEXT_ABOUT, _T("&About\tAlt-A"));
329 file_menu->AppendSeparator();
330 file_menu->Append(TEXT_QUIT, _T("E&xit\tAlt-X"), _T("Quit this sample"));
331
332 wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE );
333 menu_bar->Append(file_menu, _T("&File"));
334
335 #if wxUSE_TOOLTIPS
336 wxMenu *tooltip_menu = new wxMenu;
337 tooltip_menu->Append(TEXT_TOOLTIPS_SETDELAY, _T("Set &delay\tCtrl-D"));
338 tooltip_menu->AppendSeparator();
339 tooltip_menu->Append(TEXT_TOOLTIPS_ENABLE, _T("&Toggle tooltips\tCtrl-T"),
340 _T("enable/disable tooltips"), TRUE);
341 tooltip_menu->Check(TEXT_TOOLTIPS_ENABLE, TRUE);
342 menu_bar->Append(tooltip_menu, _T("&Tooltips"));
343 #endif // wxUSE_TOOLTIPS
344
345 #if wxUSE_CLIPBOARD
346 wxMenu *menuClipboard = new wxMenu;
347 menuClipboard->Append(TEXT_CLIPBOARD_COPY, _T("&Copy\tCtrl-C"),
348 _T("Copy the first line to the clipboard"));
349 menuClipboard->Append(TEXT_CLIPBOARD_PASTE, _T("&Paste\tCtrl-V"),
350 _T("Paste from clipboard to the text control"));
351 menu_bar->Append(menuClipboard, _T("&Clipboard"));
352 #endif // wxUSE_CLIPBOARD
353
354 wxMenu *menuText = new wxMenu;
355 menuText->Append(TEXT_ADD_SOME, _T("&Append some text\tCtrl-A"));
356 menuText->Append(TEXT_ADD_FREEZE, _T("&Append text with freeze/thaw\tShift-Ctrl-A"));
357 menuText->Append(TEXT_REMOVE, _T("&Remove first 10 characters\tCtrl-Y"));
358 menuText->Append(TEXT_REPLACE, _T("&Replace characters 4 to 8 with ABC\tCtrl-R"));
359 menuText->Append(TEXT_SELECT, _T("&Select characters 4 to 8\tCtrl-I"));
360 menuText->Append(TEXT_SET, _T("&Set the first text zone value\tCtrl-E"));
361 menuText->AppendSeparator();
362 menuText->Append(TEXT_MOVE_ENDTEXT, _T("Move cursor to the end of &text"));
363 menuText->Append(TEXT_MOVE_ENDENTRY, _T("Move cursor to the end of &entry"));
364 menuText->Append(TEXT_SET_EDITABLE, _T("Toggle &editable state"), _T(""), TRUE);
365 menuText->Append(TEXT_SET_ENABLED, _T("Toggle e&nabled state"), _T(""), TRUE);
366 menuText->Check(TEXT_SET_EDITABLE, TRUE);
367 menuText->Check(TEXT_SET_ENABLED, TRUE);
368 menuText->AppendSeparator();
369 menuText->Append(TEXT_LINE_DOWN, _T("Scroll text one line down"));
370 menuText->Append(TEXT_LINE_UP, _T("Scroll text one line up"));
371 menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page down"));
372 menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page up"));
373 menu_bar->Append(menuText, _T("Te&xt"));
374
375 wxMenu *menuLog = new wxMenu;
376 menuLog->Append(TEXT_LOG_KEY, _T("Log &key events"), _T(""), TRUE);
377 menuLog->Append(TEXT_LOG_CHAR, _T("Log &char events"), _T(""), TRUE);
378 menuLog->Append(TEXT_LOG_MOUSE, _T("Log &mouse events"), _T(""), TRUE);
379 menuLog->Append(TEXT_LOG_TEXT, _T("Log &text events"), _T(""), TRUE);
380 menuLog->Append(TEXT_LOG_FOCUS, _T("Log &focus events"), _T(""), TRUE);
381 menuLog->AppendSeparator();
382 menuLog->Append(TEXT_CLEAR, _T("&Clear the log\tCtrl-C"),
383 _T("Clear the log window contents"));
384
385 // select only the interesting events by default
386 menuLog->Check(TEXT_LOG_KEY, TRUE);
387 menuLog->Check(TEXT_LOG_CHAR, TRUE);
388 menuLog->Check(TEXT_LOG_TEXT, TRUE);
389
390 MyTextCtrl::ms_logKey =
391 MyTextCtrl::ms_logChar =
392 MyTextCtrl::ms_logText = TRUE;
393 menu_bar->Append(menuLog, _T("&Log"));
394
395 frame->SetMenuBar(menu_bar);
396
397 frame->Show(TRUE);
398
399 SetTopWindow(frame);
400
401 // report success
402 return TRUE;
403 }
404
405 //----------------------------------------------------------------------
406 // MyTextCtrl
407 //----------------------------------------------------------------------
408
409 BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
410 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
411 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
412 EVT_CHAR(MyTextCtrl::OnChar)
413
414 EVT_TEXT(-1, MyTextCtrl::OnText)
415 EVT_TEXT_URL(-1, MyTextCtrl::OnTextURL)
416 EVT_TEXT_MAXLEN(-1, MyTextCtrl::OnTextMaxLen)
417
418 EVT_MOUSE_EVENTS(MyTextCtrl::OnMouseEvent)
419
420 EVT_SET_FOCUS(MyTextCtrl::OnSetFocus)
421 EVT_KILL_FOCUS(MyTextCtrl::OnKillFocus)
422 END_EVENT_TABLE()
423
424 bool MyTextCtrl::ms_logKey = FALSE;
425 bool MyTextCtrl::ms_logChar = FALSE;
426 bool MyTextCtrl::ms_logMouse = FALSE;
427 bool MyTextCtrl::ms_logText = FALSE;
428 bool MyTextCtrl::ms_logFocus = FALSE;
429
430 void MyTextCtrl::LogKeyEvent(const wxChar *name, wxKeyEvent& event) const
431 {
432 wxString key;
433 long keycode = event.GetKeyCode();
434 {
435 switch ( keycode )
436 {
437 case WXK_BACK: key = _T("BACK"); break;
438 case WXK_TAB: key = _T("TAB"); break;
439 case WXK_RETURN: key = _T("RETURN"); break;
440 case WXK_ESCAPE: key = _T("ESCAPE"); break;
441 case WXK_SPACE: key = _T("SPACE"); break;
442 case WXK_DELETE: key = _T("DELETE"); break;
443 case WXK_START: key = _T("START"); break;
444 case WXK_LBUTTON: key = _T("LBUTTON"); break;
445 case WXK_RBUTTON: key = _T("RBUTTON"); break;
446 case WXK_CANCEL: key = _T("CANCEL"); break;
447 case WXK_MBUTTON: key = _T("MBUTTON"); break;
448 case WXK_CLEAR: key = _T("CLEAR"); break;
449 case WXK_SHIFT: key = _T("SHIFT"); break;
450 case WXK_ALT: key = _T("ALT"); break;
451 case WXK_CONTROL: key = _T("CONTROL"); break;
452 case WXK_MENU: key = _T("MENU"); break;
453 case WXK_PAUSE: key = _T("PAUSE"); break;
454 case WXK_CAPITAL: key = _T("CAPITAL"); break;
455 case WXK_PRIOR: key = _T("PRIOR"); break;
456 case WXK_NEXT: key = _T("NEXT"); break;
457 case WXK_END: key = _T("END"); break;
458 case WXK_HOME: key = _T("HOME"); break;
459 case WXK_LEFT: key = _T("LEFT"); break;
460 case WXK_UP: key = _T("UP"); break;
461 case WXK_RIGHT: key = _T("RIGHT"); break;
462 case WXK_DOWN: key = _T("DOWN"); break;
463 case WXK_SELECT: key = _T("SELECT"); break;
464 case WXK_PRINT: key = _T("PRINT"); break;
465 case WXK_EXECUTE: key = _T("EXECUTE"); break;
466 case WXK_SNAPSHOT: key = _T("SNAPSHOT"); break;
467 case WXK_INSERT: key = _T("INSERT"); break;
468 case WXK_HELP: key = _T("HELP"); break;
469 case WXK_NUMPAD0: key = _T("NUMPAD0"); break;
470 case WXK_NUMPAD1: key = _T("NUMPAD1"); break;
471 case WXK_NUMPAD2: key = _T("NUMPAD2"); break;
472 case WXK_NUMPAD3: key = _T("NUMPAD3"); break;
473 case WXK_NUMPAD4: key = _T("NUMPAD4"); break;
474 case WXK_NUMPAD5: key = _T("NUMPAD5"); break;
475 case WXK_NUMPAD6: key = _T("NUMPAD6"); break;
476 case WXK_NUMPAD7: key = _T("NUMPAD7"); break;
477 case WXK_NUMPAD8: key = _T("NUMPAD8"); break;
478 case WXK_NUMPAD9: key = _T("NUMPAD9"); break;
479 case WXK_MULTIPLY: key = _T("MULTIPLY"); break;
480 case WXK_ADD: key = _T("ADD"); break;
481 case WXK_SEPARATOR: key = _T("SEPARATOR"); break;
482 case WXK_SUBTRACT: key = _T("SUBTRACT"); break;
483 case WXK_DECIMAL: key = _T("DECIMAL"); break;
484 case WXK_DIVIDE: key = _T("DIVIDE"); break;
485 case WXK_F1: key = _T("F1"); break;
486 case WXK_F2: key = _T("F2"); break;
487 case WXK_F3: key = _T("F3"); break;
488 case WXK_F4: key = _T("F4"); break;
489 case WXK_F5: key = _T("F5"); break;
490 case WXK_F6: key = _T("F6"); break;
491 case WXK_F7: key = _T("F7"); break;
492 case WXK_F8: key = _T("F8"); break;
493 case WXK_F9: key = _T("F9"); break;
494 case WXK_F10: key = _T("F10"); break;
495 case WXK_F11: key = _T("F11"); break;
496 case WXK_F12: key = _T("F12"); break;
497 case WXK_F13: key = _T("F13"); break;
498 case WXK_F14: key = _T("F14"); break;
499 case WXK_F15: key = _T("F15"); break;
500 case WXK_F16: key = _T("F16"); break;
501 case WXK_F17: key = _T("F17"); break;
502 case WXK_F18: key = _T("F18"); break;
503 case WXK_F19: key = _T("F19"); break;
504 case WXK_F20: key = _T("F20"); break;
505 case WXK_F21: key = _T("F21"); break;
506 case WXK_F22: key = _T("F22"); break;
507 case WXK_F23: key = _T("F23"); break;
508 case WXK_F24: key = _T("F24"); break;
509 case WXK_NUMLOCK: key = _T("NUMLOCK"); break;
510 case WXK_SCROLL: key = _T("SCROLL"); break;
511 case WXK_PAGEUP: key = _T("PAGEUP"); break;
512 case WXK_PAGEDOWN: key = _T("PAGEDOWN"); break;
513 case WXK_NUMPAD_SPACE: key = _T("NUMPAD_SPACE"); break;
514 case WXK_NUMPAD_TAB: key = _T("NUMPAD_TAB"); break;
515 case WXK_NUMPAD_ENTER: key = _T("NUMPAD_ENTER"); break;
516 case WXK_NUMPAD_F1: key = _T("NUMPAD_F1"); break;
517 case WXK_NUMPAD_F2: key = _T("NUMPAD_F2"); break;
518 case WXK_NUMPAD_F3: key = _T("NUMPAD_F3"); break;
519 case WXK_NUMPAD_F4: key = _T("NUMPAD_F4"); break;
520 case WXK_NUMPAD_HOME: key = _T("NUMPAD_HOME"); break;
521 case WXK_NUMPAD_LEFT: key = _T("NUMPAD_LEFT"); break;
522 case WXK_NUMPAD_UP: key = _T("NUMPAD_UP"); break;
523 case WXK_NUMPAD_RIGHT: key = _T("NUMPAD_RIGHT"); break;
524 case WXK_NUMPAD_DOWN: key = _T("NUMPAD_DOWN"); break;
525 case WXK_NUMPAD_PRIOR: key = _T("NUMPAD_PRIOR"); break;
526 case WXK_NUMPAD_PAGEUP: key = _T("NUMPAD_PAGEUP"); break;
527 case WXK_NUMPAD_PAGEDOWN: key = _T("NUMPAD_PAGEDOWN"); break;
528 case WXK_NUMPAD_END: key = _T("NUMPAD_END"); break;
529 case WXK_NUMPAD_BEGIN: key = _T("NUMPAD_BEGIN"); break;
530 case WXK_NUMPAD_INSERT: key = _T("NUMPAD_INSERT"); break;
531 case WXK_NUMPAD_DELETE: key = _T("NUMPAD_DELETE"); break;
532 case WXK_NUMPAD_EQUAL: key = _T("NUMPAD_EQUAL"); break;
533 case WXK_NUMPAD_MULTIPLY: key = _T("NUMPAD_MULTIPLY"); break;
534 case WXK_NUMPAD_ADD: key = _T("NUMPAD_ADD"); break;
535 case WXK_NUMPAD_SEPARATOR: key = _T("NUMPAD_SEPARATOR"); break;
536 case WXK_NUMPAD_SUBTRACT: key = _T("NUMPAD_SUBTRACT"); break;
537 case WXK_NUMPAD_DECIMAL: key = _T("NUMPAD_DECIMAL"); break;
538
539 default:
540 {
541 if ( wxIsprint((int)keycode) )
542 key.Printf(_T("'%c'"), (char)keycode);
543 else if ( keycode > 0 && keycode < 27 )
544 key.Printf(_("Ctrl-%c"), _T('A') + keycode - 1);
545 else
546 key.Printf(_T("unknown (%ld)"), keycode);
547 }
548 }
549 }
550
551 wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"),
552 name,
553 key.c_str(),
554 GetChar( event.ControlDown(), _T('C') ),
555 GetChar( event.AltDown(), _T('A') ),
556 GetChar( event.ShiftDown(), _T('S') ),
557 GetChar( event.MetaDown(), _T('M') ) );
558 }
559
560 static wxString GetMouseEventDesc(const wxMouseEvent& ev)
561 {
562 // click event
563 wxString button;
564 bool dbl, up;
565 if ( ev.LeftDown() || ev.LeftUp() || ev.LeftDClick() )
566 {
567 button = _T("Left");
568 dbl = ev.LeftDClick();
569 up = ev.LeftUp();
570 }
571 else if ( ev.MiddleDown() || ev.MiddleUp() || ev.MiddleDClick() )
572 {
573 button = _T("Middle");
574 dbl = ev.MiddleDClick();
575 up = ev.MiddleUp();
576 }
577 else if ( ev.RightDown() || ev.RightUp() || ev.RightDClick() )
578 {
579 button = _T("Right");
580 dbl = ev.RightDClick();
581 up = ev.RightUp();
582 }
583 else
584 {
585 return _T("Unknown mouse event");
586 }
587
588 return wxString::Format(_T("%s mouse button %s"),
589 button.c_str(),
590 dbl ? _T("double clicked")
591 : up ? _T("released") : _T("clicked"));
592 }
593
594 void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev)
595 {
596 ev.Skip();
597
598 if ( !ms_logMouse )
599 return;
600
601 if ( !ev.Moving() )
602 {
603 wxString msg;
604 if ( ev.Entering() )
605 {
606 msg = _T("Mouse entered the window");
607 }
608 else if ( ev.Leaving() )
609 {
610 msg = _T("Mouse left the window");
611 }
612 else
613 {
614 msg = GetMouseEventDesc(ev);
615 }
616
617 msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ")
618 << _T("Flags: ")
619 << GetChar( ev.LeftIsDown(), _T('1') )
620 << GetChar( ev.MiddleIsDown(), _T('2') )
621 << GetChar( ev.RightIsDown(), _T('3') )
622 << GetChar( ev.ControlDown(), _T('C') )
623 << GetChar( ev.AltDown(), _T('A') )
624 << GetChar( ev.ShiftDown(), _T('S') )
625 << GetChar( ev.MetaDown(), _T('M') );
626
627 wxLogMessage(msg);
628 }
629 //else: we're not interested in mouse move events
630 }
631
632 void MyTextCtrl::OnSetFocus(wxFocusEvent& event)
633 {
634 if ( ms_logFocus )
635 wxLogMessage( wxT("%p got focus."), this);
636
637 event.Skip();
638 }
639
640 void MyTextCtrl::OnKillFocus(wxFocusEvent& event)
641 {
642 if ( ms_logFocus )
643 wxLogMessage( wxT("%p lost focus"), this);
644
645 event.Skip();
646 }
647
648 void MyTextCtrl::OnText(wxCommandEvent& event)
649 {
650 if ( !ms_logText )
651 return;
652
653 MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
654 const wxChar *data = (const wxChar *)(win->GetClientData());
655 if ( data )
656 {
657 wxLogMessage(_T("Text changed in control '%s'"), data);
658 }
659 else
660 {
661 // wxLogMessage( event.GetString() );
662 wxLogMessage(_T("Text changed in some control"));
663 }
664 }
665
666 void MyTextCtrl::OnTextMaxLen(wxCommandEvent& event)
667 {
668 wxLogMessage(_T("You can't enter more characters into this control."));
669 }
670
671 void MyTextCtrl::OnTextURL(wxTextUrlEvent& event)
672 {
673 const wxMouseEvent& ev = event.GetMouseEvent();
674
675 // filter out mouse moves, too many of them
676 if ( ev.Moving() )
677 return;
678
679 long start = event.GetURLStart(),
680 end = event.GetURLEnd();
681
682 wxLogMessage(_T("Mouse event over URL '%s': %s"),
683 GetValue().Mid(start, end - start).c_str(),
684 GetMouseEventDesc(ev).c_str());
685 }
686
687 void MyTextCtrl::OnChar(wxKeyEvent& event)
688 {
689 if ( ms_logChar )
690 LogKeyEvent( _T("Char"), event);
691
692 event.Skip();
693 }
694
695 void MyTextCtrl::OnKeyUp(wxKeyEvent& event)
696 {
697 if ( ms_logKey )
698 LogKeyEvent( _T("Key up"), event);
699
700 event.Skip();
701 }
702
703 void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
704 {
705 switch ( event.GetKeyCode() )
706 {
707 case WXK_F1:
708 // show current position and text length
709 {
710 long line, column, pos = GetInsertionPoint();
711 PositionToXY(pos, &column, &line);
712
713 wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
714 pos,
715 line, column,
716 (long) GetNumberOfLines(),
717 (long) GetLineLength(line),
718 GetValue().length(),
719 GetLastPosition());
720
721 long from, to;
722 GetSelection(&from, &to);
723
724 wxString sel = GetStringSelection();
725
726 wxLogMessage(_T("Selection: from %ld to %ld."), from, to);
727 wxLogMessage(_T("Selection = '%s' (len = %u)"),
728 sel.c_str(), sel.length());
729 }
730 break;
731
732 case WXK_F2:
733 // go to the end
734 SetInsertionPointEnd();
735 break;
736
737 case WXK_F3:
738 // go to position 10
739 SetInsertionPoint(10);
740 break;
741
742 case WXK_F4:
743 if (!m_hasCapture)
744 {
745 wxLogDebug( wxT("Now capturing mouse and events.") );
746 m_hasCapture = TRUE;
747 CaptureMouse();
748 }
749 else
750 {
751 wxLogDebug( wxT("Stopped capturing mouse and events.") );
752 m_hasCapture = FALSE;
753 ReleaseMouse();
754 }
755 break;
756
757 case WXK_F5:
758 // insert a blank line
759 WriteText(_T("\n"));
760 break;
761
762 case WXK_F6:
763 wxLogMessage(_T("IsModified() before SetValue(): %d"),
764 IsModified());
765 SetValue(_T("SetValue() has been called"));
766 wxLogMessage(_T("IsModified() after SetValue(): %d"),
767 IsModified());
768 break;
769
770 case WXK_F7:
771 wxLogMessage(_T("Position 10 should be now visible."));
772 ShowPosition(10);
773 break;
774
775 case WXK_F8:
776 wxLogMessage(_T("Control has been cleared"));
777 Clear();
778 break;
779
780 case WXK_F9:
781 WriteText(_T("WriteText() has been called"));
782 break;
783
784 case WXK_F10:
785 AppendText(_T("AppendText() has been called"));
786 break;
787 }
788
789 if ( ms_logKey )
790 LogKeyEvent( wxT("Key down"), event);
791
792 event.Skip();
793 }
794
795 //----------------------------------------------------------------------
796 // MyPanel
797 //----------------------------------------------------------------------
798
799 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
800 EVT_SIZE(MyPanel::OnSize)
801 END_EVENT_TABLE()
802
803 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
804 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
805 {
806 m_log = new wxTextCtrl( this, -1, _T("This is the log window.\n"),
807 wxPoint(5,260), wxSize(630,100),
808 wxTE_MULTILINE | wxTE_READONLY /* | wxTE_RICH */);
809
810 m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
811
812 // single line text controls
813
814 m_text = new MyTextCtrl( this, -1, _T("Single line."),
815 wxPoint(10,10), wxSize(140,-1),
816 wxTE_PROCESS_ENTER);
817 m_text->SetForegroundColour(*wxBLUE);
818 m_text->SetBackgroundColour(*wxLIGHT_GREY);
819 (*m_text) << _T(" Appended.");
820 m_text->SetInsertionPoint(0);
821 m_text->WriteText( _T("Prepended. ") );
822
823 m_password = new MyTextCtrl( this, -1, _T(""),
824 wxPoint(10,50), wxSize(140,-1), wxTE_PASSWORD );
825
826 m_readonly = new MyTextCtrl( this, -1, _T("Read only"),
827 wxPoint(10,90), wxSize(140,-1), wxTE_READONLY );
828
829 m_limited = new MyTextCtrl(this, -1, _T("Max 8 ch"),
830 wxPoint(10, 130), wxSize(140, -1));
831 m_limited->SetMaxLength(8);
832
833 // multi line text controls
834
835 m_horizontal = new MyTextCtrl( this, -1, _T("Multiline text control with a horizontal scrollbar."),
836 wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
837
838 // a little hack to use the command line argument for encoding testing
839 if ( wxTheApp->argc == 2 )
840 {
841 switch ( wxTheApp->argv[1][0] )
842 {
843 case '2':
844 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
845 FALSE, _T(""),
846 wxFONTENCODING_ISO8859_2));
847 m_horizontal->SetValue(_T("®lu»ouèký kùò zbìsile èe¹tina «»"));
848 break;
849
850 case '1':
851 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
852 FALSE, _T(""),
853 wxFONTENCODING_CP1251));
854 m_horizontal->SetValue(_T("Ïðèâåò!"));
855 break;
856
857 case '8':
858 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
859 FALSE, _T(""),
860 wxFONTENCODING_CP1251));
861 #if wxUSE_UNICODE
862 m_horizontal->SetValue(L"\x0412\x0430\x0434\x0438\x043c \x0426");
863 #else
864 m_horizontal->SetValue("ËÁÖÅÔÓÑ ÕÄÁÞÎÙÍ");
865 #endif
866 }
867 }
868 else
869 {
870 m_horizontal->SetValue(_T("Text in default encoding"));
871 }
872
873 m_multitext = new MyTextCtrl( this, -1, _T("Multi line."),
874 wxPoint(180,10), wxSize(240,70), wxTE_MULTILINE );
875 m_multitext->SetFont(*wxITALIC_FONT);
876 (*m_multitext) << _T(" Appended.");
877 m_multitext->SetInsertionPoint(0);
878 m_multitext->WriteText( _T("Prepended. ") );
879 m_multitext->SetForegroundColour(*wxRED);
880 m_multitext->SetBackgroundColour(*wxLIGHT_GREY);
881
882 #if wxUSE_TOOLTIPS
883 m_multitext->SetToolTip(_T("Press Fn function keys here"));
884 #endif
885
886 m_tab = new MyTextCtrl( this, 100, _T("Multiline, allow <TAB> processing."),
887 wxPoint(180,90), wxSize(240,70), wxTE_MULTILINE | wxTE_PROCESS_TAB );
888 m_tab->SetClientData((void *)_T("tab"));
889
890 m_enter = new MyTextCtrl( this, 100, _T("Multiline, allow <ENTER> processing."),
891 wxPoint(180,170), wxSize(240,70), wxTE_MULTILINE);
892 m_enter->SetClientData((void *)_T("enter"));
893
894 #if 0
895 m_textrich = new MyTextCtrl(this, -1, _T("Allows more than 30Kb of text\n")
896 _T("(even under broken Win9x)\n")
897 _T("and a very very very very very ")
898 _T("very very very long line to test ")
899 _T("wxHSCROLL style"),
900 wxPoint(450, 10), wxSize(230, 230),
901 wxTE_RICH2 |
902 wxTE_MULTILINE |
903 // wxTE_AUTO_URL |
904 wxHSCROLL);
905 m_textrich->SetStyle(0, 10, *wxRED);
906 m_textrich->SetStyle(10, 20, *wxBLUE);
907 m_textrich->SetStyle(30, 40,
908 wxTextAttr(*wxGREEN, wxNullColour, *wxITALIC_FONT));
909 m_textrich->SetDefaultStyle(wxTextAttr());
910 m_textrich->AppendText(_T("\n\nFirst 10 characters should be in red\n"));
911 m_textrich->AppendText(_T("Next 10 characters should be in blue\n"));
912 m_textrich->AppendText(_T("Next 10 characters should be normal\n"));
913 m_textrich->AppendText(_T("And the next 10 characters should be green and italic\n"));
914 m_textrich->SetDefaultStyle(wxTextAttr(*wxCYAN, *wxBLUE));
915 m_textrich->AppendText(_T("This text should be cyan on blue\n"));
916 m_textrich->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE));
917 m_textrich->AppendText(_T("And this should be in blue and the text you ")
918 _T("type should be in blue as well"));
919 #else
920 m_textrich = new MyTextCtrl(this, -1, _T(""),
921 wxPoint(450, 10), wxSize(230, 230),
922 wxTE_RICH2 |
923 wxTE_MULTILINE |
924 wxHSCROLL);
925 #endif
926 }
927
928 void MyPanel::OnSize( wxSizeEvent &event )
929 {
930 wxSize client_area( GetClientSize() );
931 m_log->SetSize( 0, 260, client_area.x, client_area.y - 260 );
932 event.Skip();
933 }
934
935 wxTextCtrl *MyPanel::GetFocusedText(wxTextCtrl *textDef)
936 {
937 wxWindow *win = FindFocus();
938
939 wxTextCtrl *text = win ? wxDynamicCast(win, wxTextCtrl) : NULL;
940 return text ? text : textDef;
941 }
942
943 #if wxUSE_CLIPBOARD
944 void MyPanel::DoPasteFromClipboard()
945 {
946 // On X11, we want to get the data from the primary selection instead
947 // of the normal clipboard (which isn't normal under X11 at all). This
948 // call has no effect under MSW.
949 wxTheClipboard->UsePrimarySelection();
950
951 if (!wxTheClipboard->Open())
952 {
953 *m_log << _T("Error opening the clipboard.\n");
954 return;
955 }
956 else
957 {
958 *m_log << _T("Successfully opened the clipboard.\n");
959 }
960
961 wxTextDataObject data;
962
963 if (wxTheClipboard->IsSupported( data.GetFormat() ))
964 {
965 *m_log << _T("Clipboard supports requested format.\n");
966
967 if (wxTheClipboard->GetData( data ))
968 {
969 *m_log << _T("Successfully retrieved data from the clipboard.\n");
970 *m_multitext << data.GetText() << _T("\n");
971 }
972 else
973 {
974 *m_log << _T("Error getting data from the clipboard.\n");
975 }
976 }
977 else
978 {
979 *m_log << _T("Clipboard doesn't support requested format.\n");
980 }
981
982 wxTheClipboard->Close();
983
984 *m_log << _T("Closed the clipboard.\n");
985 }
986
987 void MyPanel::DoCopyToClipboard()
988 {
989 // On X11, we want to get the data from the primary selection instead
990 // of the normal clipboard (which isn't normal under X11 at all). This
991 // call has no effect under MSW.
992 wxTheClipboard->UsePrimarySelection();
993
994 wxString text( m_multitext->GetLineText(0) );
995
996 if (text.IsEmpty())
997 {
998 *m_log << _T("No text to copy.\n");
999
1000 return;
1001 }
1002
1003 if (!wxTheClipboard->Open())
1004 {
1005 *m_log << _T("Error opening the clipboard.\n");
1006
1007 return;
1008 }
1009 else
1010 {
1011 *m_log << _T("Successfully opened the clipboard.\n");
1012 }
1013
1014 wxTextDataObject *data = new wxTextDataObject( text );
1015
1016 if (!wxTheClipboard->SetData( data ))
1017 {
1018 *m_log << _T("Error while copying to the clipboard.\n");
1019 }
1020 else
1021 {
1022 *m_log << _T("Successfully copied data to the clipboard.\n");
1023 }
1024
1025 wxTheClipboard->Close();
1026
1027 *m_log << _T("Closed the clipboard.\n");
1028 }
1029
1030 #endif // wxUSE_CLIPBOARD
1031
1032 void MyPanel::DoMoveToEndOfText()
1033 {
1034 m_multitext->SetInsertionPointEnd();
1035 m_multitext->SetFocus();
1036 }
1037
1038 void MyPanel::DoMoveToEndOfEntry()
1039 {
1040 m_text->SetInsertionPointEnd();
1041 m_text->SetFocus();
1042 }
1043
1044 void MyPanel::DoRemoveText()
1045 {
1046 GetFocusedText(m_multitext)->Remove(0, 10);
1047 }
1048
1049 void MyPanel::DoReplaceText()
1050 {
1051 GetFocusedText(m_multitext)->Replace(3, 8, _T("ABC"));
1052 }
1053
1054 void MyPanel::DoSelectText()
1055 {
1056 GetFocusedText(m_multitext)->SetSelection(3, 8);
1057 }
1058
1059 //----------------------------------------------------------------------
1060 // MyFrame
1061 //----------------------------------------------------------------------
1062
1063 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1064 EVT_MENU(TEXT_QUIT, MyFrame::OnQuit)
1065 EVT_MENU(TEXT_ABOUT, MyFrame::OnAbout)
1066 EVT_MENU(TEXT_SAVE, MyFrame::OnFileSave)
1067 EVT_MENU(TEXT_LOAD, MyFrame::OnFileLoad)
1068
1069 EVT_MENU(TEXT_LOG_KEY, MyFrame::OnLogKey)
1070 EVT_MENU(TEXT_LOG_CHAR, MyFrame::OnLogChar)
1071 EVT_MENU(TEXT_LOG_MOUSE,MyFrame::OnLogMouse)
1072 EVT_MENU(TEXT_LOG_TEXT, MyFrame::OnLogText)
1073 EVT_MENU(TEXT_LOG_FOCUS,MyFrame::OnLogFocus)
1074 EVT_MENU(TEXT_CLEAR, MyFrame::OnLogClear)
1075
1076 #if wxUSE_TOOLTIPS
1077 EVT_MENU(TEXT_TOOLTIPS_SETDELAY, MyFrame::OnSetTooltipDelay)
1078 EVT_MENU(TEXT_TOOLTIPS_ENABLE, MyFrame::OnToggleTooltips)
1079 #endif // wxUSE_TOOLTIPS
1080
1081 #if wxUSE_CLIPBOARD
1082 EVT_MENU(TEXT_CLIPBOARD_PASTE, MyFrame::OnPasteFromClipboard)
1083 EVT_MENU(TEXT_CLIPBOARD_COPY, MyFrame::OnCopyToClipboard)
1084 #endif // wxUSE_CLIPBOARD
1085
1086 EVT_MENU(TEXT_REMOVE, MyFrame::OnRemoveText)
1087 EVT_MENU(TEXT_REPLACE, MyFrame::OnReplaceText)
1088 EVT_MENU(TEXT_SELECT, MyFrame::OnSelectText)
1089 EVT_MENU(TEXT_ADD_SOME, MyFrame::OnAddText)
1090 EVT_MENU(TEXT_ADD_FREEZE, MyFrame::OnAddTextFreeze)
1091 EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText)
1092 EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry)
1093
1094 EVT_MENU(TEXT_SET_EDITABLE, MyFrame::OnSetEditable)
1095 EVT_MENU(TEXT_SET_ENABLED, MyFrame::OnSetEnabled)
1096
1097 EVT_MENU(TEXT_LINE_DOWN, MyFrame::OnScrollLineDown)
1098 EVT_MENU(TEXT_LINE_UP, MyFrame::OnScrollLineUp)
1099 EVT_MENU(TEXT_PAGE_DOWN, MyFrame::OnScrollPageDown)
1100 EVT_MENU(TEXT_PAGE_UP, MyFrame::OnScrollPageUp)
1101
1102 EVT_MENU(TEXT_SET, MyFrame::OnSetText)
1103
1104 EVT_IDLE(MyFrame::OnIdle)
1105 END_EVENT_TABLE()
1106
1107 MyFrame::MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h)
1108 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h) )
1109 {
1110 CreateStatusBar(2);
1111
1112 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1113 }
1114
1115 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1116 {
1117 Close(TRUE);
1118 }
1119
1120 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1121 {
1122 wxBeginBusyCursor();
1123
1124 wxMessageDialog dialog(this,
1125 _T("This is a text control sample. It demonstrates the many different\n")
1126 _T("text control styles, the use of the clipboard, setting and handling\n")
1127 _T("tooltips and intercepting key and char events.\n")
1128 _T("\n")
1129 _T("Copyright (c) 1999, Robert Roebling, Julian Smart, Vadim Zeitlin"),
1130 _T("About wxTextCtrl Sample"),
1131 wxOK | wxICON_INFORMATION);
1132
1133 dialog.ShowModal();
1134
1135 wxEndBusyCursor();
1136 }
1137
1138 #if wxUSE_TOOLTIPS
1139 void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
1140 {
1141 static long s_delay = 5000;
1142
1143 wxString delay;
1144 delay.Printf( _T("%ld"), s_delay);
1145
1146 delay = wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1147 _T("Set tooltip delay"),
1148 delay,
1149 this);
1150 if ( !delay )
1151 return; // cancelled
1152
1153 wxSscanf(delay, _T("%ld"), &s_delay);
1154
1155 wxToolTip::SetDelay(s_delay);
1156
1157 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1158 }
1159
1160 void MyFrame::OnToggleTooltips(wxCommandEvent& event)
1161 {
1162 static bool s_enabled = TRUE;
1163
1164 s_enabled = !s_enabled;
1165
1166 wxToolTip::Enable(s_enabled);
1167
1168 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1169 }
1170 #endif // tooltips
1171
1172 void MyFrame::OnLogClear(wxCommandEvent& WXUNUSED(event))
1173 {
1174 m_panel->m_log->Clear();
1175 }
1176
1177 void MyFrame::OnSetEditable(wxCommandEvent& WXUNUSED(event))
1178 {
1179 static bool s_editable = TRUE;
1180
1181 s_editable = !s_editable;
1182 m_panel->m_text->SetEditable(s_editable);
1183 m_panel->m_password->SetEditable(s_editable);
1184 m_panel->m_multitext->SetEditable(s_editable);
1185 m_panel->m_textrich->SetEditable(s_editable);
1186 }
1187
1188 void MyFrame::OnSetEnabled(wxCommandEvent& WXUNUSED(event))
1189 {
1190 bool enabled = m_panel->m_text->IsEnabled();
1191 enabled = !enabled;
1192
1193 m_panel->m_text->Enable(enabled);
1194 m_panel->m_password->Enable(enabled);
1195 m_panel->m_multitext->Enable(enabled);
1196 m_panel->m_readonly->Enable(enabled);
1197 m_panel->m_limited->Enable(enabled);
1198 m_panel->m_textrich->Enable(enabled);
1199 }
1200
1201 void MyFrame::OnFileSave(wxCommandEvent& event)
1202 {
1203 if ( m_panel->m_textrich->SaveFile(_T("dummy.txt")) )
1204 {
1205 #if wxUSE_FILE
1206 // verify that the fil length is correct (it wasn't under Win95)
1207 wxFile file(wxT("dummy.txt"));
1208 wxLogStatus(this,
1209 _T("Successfully saved file (text len = %lu, file size = %ld)"),
1210 (unsigned long)m_panel->m_textrich->GetValue().length(),
1211 (long) file.Length());
1212 #endif
1213 }
1214 else
1215 wxLogStatus(this, _T("Couldn't save the file"));
1216 }
1217
1218 void MyFrame::OnFileLoad(wxCommandEvent& event)
1219 {
1220 if ( m_panel->m_textrich->LoadFile(_T("dummy.txt")) )
1221 wxLogStatus(this, _T("Successfully loaded file"));
1222 else
1223 wxLogStatus(this, _T("Couldn't load the file"));
1224 }
1225
1226 void MyFrame::OnIdle( wxIdleEvent& event )
1227 {
1228 // track the window which has the focus in the status bar
1229 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1230 wxWindow *focus = wxWindow::FindFocus();
1231 if ( focus && (focus != s_windowFocus) )
1232 {
1233 s_windowFocus = focus;
1234
1235 wxString msg;
1236 msg.Printf(
1237 #ifdef __WXMSW__
1238 _T("Focus: wxWindow = %p, HWND = %08x"),
1239 #else
1240 _T("Focus: wxWindow = %p"),
1241 #endif
1242 s_windowFocus
1243 #ifdef __WXMSW__
1244 , (unsigned int) s_windowFocus->GetHWND()
1245 #endif
1246 );
1247
1248 SetStatusText(msg);
1249 }
1250 event.Skip();
1251 }