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