]> git.saurik.com Git - wxWidgets.git/blob - samples/text/controls.cpp
a27af06ebb52be6c6056317416588b1ea32845c9
[wxWidgets.git] / samples / text / controls.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: controls.cpp
3 // Purpose: TextCtrl wxWindows sample
4 // Author: Robert Roebling
5 // Modified by:
6 // RCS-ID: $Id$
7 // Copyright: (c) Robert Roebling, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "controls.h"
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_TOOLTIPS
32 #include "wx/tooltip.h"
33 #endif
34
35 #if defined(__WXGTK__) || defined(__WXMOTIF__)
36 #include "mondrian.xpm"
37 #endif
38
39 //----------------------------------------------------------------------
40 // class definitions
41 //----------------------------------------------------------------------
42
43 class MyApp: public wxApp
44 {
45 public:
46 bool OnInit();
47 };
48
49 // a text ctrl which allows to call different wxTextCtrl functions
50 // interactively by pressing function keys in it
51 class MyTextCtrl : public wxTextCtrl
52 {
53 public:
54 MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
55 const wxPoint &pos, const wxSize &size, int style = 0)
56 : wxTextCtrl(parent, id, value, pos, size, style) { }
57
58 void OnKeyDown(wxKeyEvent& event);
59 void OnKeyUp(wxKeyEvent& event);
60 void OnChar(wxKeyEvent& event);
61
62 private:
63 static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); }
64 void LogEvent(const wxChar *name, wxKeyEvent& event) const;
65
66 DECLARE_EVENT_TABLE()
67 };
68
69 class MyPanel: public wxPanel
70 {
71 public:
72 MyPanel(wxFrame *frame, int x, int y, int w, int h);
73
74 void OnPasteFromClipboard( wxCommandEvent &event );
75 void OnCopyToClipboard( wxCommandEvent &event );
76 void OnMoveToEndOfText( wxCommandEvent &event );
77 void OnMoveToEndOfEntry( wxCommandEvent &event );
78
79 MyTextCtrl *m_text;
80 MyTextCtrl *m_password;
81 MyTextCtrl *m_enter;
82 MyTextCtrl *m_tab;
83 MyTextCtrl *m_entertab;
84 MyTextCtrl *m_readonly;
85
86 MyTextCtrl *m_multitext;
87 MyTextCtrl *m_horizontal;
88 MyTextCtrl *m_multitab;
89
90 wxTextCtrl *m_log;
91
92 private:
93 DECLARE_EVENT_TABLE()
94 };
95
96 class MyFrame: public wxFrame
97 {
98 public:
99 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
100
101 void OnQuit(wxCommandEvent& event);
102 void OnAbout(wxCommandEvent& event);
103 #if wxUSE_TOOLTIPS
104 void OnSetTooltipDelay(wxCommandEvent& event);
105 void OnToggleTooltips(wxCommandEvent& event);
106 #endif // wxUSE_TOOLTIPS
107 void OnIdle( wxIdleEvent& event );
108
109 private:
110 DECLARE_EVENT_TABLE()
111 };
112
113 //----------------------------------------------------------------------
114 // main()
115 //----------------------------------------------------------------------
116
117 IMPLEMENT_APP(MyApp)
118
119 //----------------------------------------------------------------------
120 // MyApp
121 //----------------------------------------------------------------------
122
123 enum
124 {
125 MINIMAL_QUIT = 100,
126 MINIMAL_TEXT,
127 MINIMAL_ABOUT,
128
129 // tooltip menu
130 MINIMAL_SET_TOOLTIP_DELAY = 200,
131 MINIMAL_ENABLE_TOOLTIPS
132 };
133
134 bool MyApp::OnInit()
135 {
136 // Create the main frame window
137 MyFrame *frame = new MyFrame((wxFrame *) NULL,
138 "Text wxWindows App",
139 50, 50, 640, 420);
140
141 // Give it an icon
142 // The wxICON() macros loads an icon from a resource under Windows
143 // and uses an #included XPM image under GTK+ and Motif
144
145 frame->SetIcon( wxICON(mondrian) );
146
147 wxMenu *file_menu = new wxMenu;
148 file_menu->Append(MINIMAL_ABOUT, "&About\tAlt-A");
149 file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample");
150
151 wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE );
152 menu_bar->Append(file_menu, "&File");
153
154 #if wxUSE_TOOLTIPS
155 wxMenu *tooltip_menu = new wxMenu;
156 tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
157 tooltip_menu->AppendSeparator();
158 tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCrtl-T",
159 "enable/disable tooltips", TRUE);
160 tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE);
161 menu_bar->Append(tooltip_menu, "&Tooltips");
162 #endif // wxUSE_TOOLTIPS
163
164 frame->SetMenuBar(menu_bar);
165
166 frame->Show(TRUE);
167
168 SetTopWindow(frame);
169
170 // report success
171 return TRUE;
172 }
173
174 //----------------------------------------------------------------------
175 // MyTextCtrl
176 //----------------------------------------------------------------------
177
178 BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
179 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
180 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
181 EVT_CHAR(MyTextCtrl::OnChar)
182 END_EVENT_TABLE()
183
184 void MyTextCtrl::LogEvent(const wxChar *name, wxKeyEvent& event) const
185 {
186 wxString key;
187 long keycode = event.KeyCode();
188 if ( wxIsprint((int)keycode) )
189 key.Printf( _T("'%c'") , (char)keycode);
190 else
191 {
192 switch ( keycode )
193 {
194 case WXK_BACK: key = "BACK"; break;
195 case WXK_TAB: key = "TAB"; break;
196 case WXK_RETURN: key = "RETURN"; break;
197 case WXK_ESCAPE: key = "ESCAPE"; break;
198 case WXK_SPACE: key = "SPACE"; break;
199 case WXK_DELETE: key = "DELETE"; break;
200 case WXK_START: key = "START"; break;
201 case WXK_LBUTTON: key = "LBUTTON"; break;
202 case WXK_RBUTTON: key = "RBUTTON"; break;
203 case WXK_CANCEL: key = "CANCEL"; break;
204 case WXK_MBUTTON: key = "MBUTTON"; break;
205 case WXK_CLEAR: key = "CLEAR"; break;
206 case WXK_SHIFT: key = "SHIFT"; break;
207 case WXK_ALT: key = "ALT"; break;
208 case WXK_CONTROL: key = "CONTROL"; break;
209 case WXK_MENU: key = "MENU"; break;
210 case WXK_PAUSE: key = "PAUSE"; break;
211 case WXK_CAPITAL: key = "CAPITAL"; break;
212 case WXK_PRIOR: key = "PRIOR"; break;
213 case WXK_NEXT: key = "NEXT"; break;
214 case WXK_END: key = "END"; break;
215 case WXK_HOME: key = "HOME"; break;
216 case WXK_LEFT: key = "LEFT"; break;
217 case WXK_UP: key = "UP"; break;
218 case WXK_RIGHT: key = "RIGHT"; break;
219 case WXK_DOWN: key = "DOWN"; break;
220 case WXK_SELECT: key = "SELECT"; break;
221 case WXK_PRINT: key = "PRINT"; break;
222 case WXK_EXECUTE: key = "EXECUTE"; break;
223 case WXK_SNAPSHOT: key = "SNAPSHOT"; break;
224 case WXK_INSERT: key = "INSERT"; break;
225 case WXK_HELP: key = "HELP"; break;
226 case WXK_NUMPAD0: key = "NUMPAD0"; break;
227 case WXK_NUMPAD1: key = "NUMPAD1"; break;
228 case WXK_NUMPAD2: key = "NUMPAD2"; break;
229 case WXK_NUMPAD3: key = "NUMPAD3"; break;
230 case WXK_NUMPAD4: key = "NUMPAD4"; break;
231 case WXK_NUMPAD5: key = "NUMPAD5"; break;
232 case WXK_NUMPAD6: key = "NUMPAD6"; break;
233 case WXK_NUMPAD7: key = "NUMPAD7"; break;
234 case WXK_NUMPAD8: key = "NUMPAD8"; break;
235 case WXK_NUMPAD9: key = "NUMPAD9"; break;
236 case WXK_MULTIPLY: key = "MULTIPLY"; break;
237 case WXK_ADD: key = "ADD"; break;
238 case WXK_SEPARATOR: key = "SEPARATOR"; break;
239 case WXK_SUBTRACT: key = "SUBTRACT"; break;
240 case WXK_DECIMAL: key = "DECIMAL"; break;
241 case WXK_DIVIDE: key = "DIVIDE"; break;
242 case WXK_F1: key = "F1"; break;
243 case WXK_F2: key = "F2"; break;
244 case WXK_F3: key = "F3"; break;
245 case WXK_F4: key = "F4"; break;
246 case WXK_F5: key = "F5"; break;
247 case WXK_F6: key = "F6"; break;
248 case WXK_F7: key = "F7"; break;
249 case WXK_F8: key = "F8"; break;
250 case WXK_F9: key = "F9"; break;
251 case WXK_F10: key = "F10"; break;
252 case WXK_F11: key = "F11"; break;
253 case WXK_F12: key = "F12"; break;
254 case WXK_F13: key = "F13"; break;
255 case WXK_F14: key = "F14"; break;
256 case WXK_F15: key = "F15"; break;
257 case WXK_F16: key = "F16"; break;
258 case WXK_F17: key = "F17"; break;
259 case WXK_F18: key = "F18"; break;
260 case WXK_F19: key = "F19"; break;
261 case WXK_F20: key = "F20"; break;
262 case WXK_F21: key = "F21"; break;
263 case WXK_F22: key = "F22"; break;
264 case WXK_F23: key = "F23"; break;
265 case WXK_F24: key = "F24"; break;
266 case WXK_NUMLOCK: key = "NUMLOCK"; break;
267 case WXK_SCROLL: key = "SCROLL"; break;
268 case WXK_PAGEUP: key = "PAGEUP"; break;
269 case WXK_PAGEDOWN: key = "PAGEDOWN"; break;
270 case WXK_NUMPAD_SPACE: key = "NUMPAD_SPACE"; break;
271 case WXK_NUMPAD_TAB: key = "NUMPAD_TAB"; break;
272 case WXK_NUMPAD_ENTER: key = "NUMPAD_ENTER"; break;
273 case WXK_NUMPAD_F1: key = "NUMPAD_F1"; break;
274 case WXK_NUMPAD_F2: key = "NUMPAD_F2"; break;
275 case WXK_NUMPAD_F3: key = "NUMPAD_F3"; break;
276 case WXK_NUMPAD_F4: key = "NUMPAD_F4"; break;
277 case WXK_NUMPAD_HOME: key = "NUMPAD_HOME"; break;
278 case WXK_NUMPAD_LEFT: key = "NUMPAD_LEFT"; break;
279 case WXK_NUMPAD_UP: key = "NUMPAD_UP"; break;
280 case WXK_NUMPAD_RIGHT: key = "NUMPAD_RIGHT"; break;
281 case WXK_NUMPAD_DOWN: key = "NUMPAD_DOWN"; break;
282 case WXK_NUMPAD_PRIOR: key = "NUMPAD_PRIOR"; break;
283 case WXK_NUMPAD_PAGEUP: key = "NUMPAD_PAGEUP"; break;
284 case WXK_NUMPAD_PAGEDOWN: key = "NUMPAD_PAGEDOWN"; break;
285 case WXK_NUMPAD_END: key = "NUMPAD_END"; break;
286 case WXK_NUMPAD_BEGIN: key = "NUMPAD_BEGIN"; break;
287 case WXK_NUMPAD_INSERT: key = "NUMPAD_INSERT"; break;
288 case WXK_NUMPAD_DELETE: key = "NUMPAD_DELETE"; break;
289 case WXK_NUMPAD_EQUAL: key = "NUMPAD_EQUAL"; break;
290 case WXK_NUMPAD_MULTIPLY: key = "NUMPAD_MULTIPLY"; break;
291 case WXK_NUMPAD_ADD: key = "NUMPAD_ADD"; break;
292 case WXK_NUMPAD_SEPARATOR: key = "NUMPAD_SEPARATOR"; break;
293 case WXK_NUMPAD_SUBTRACT: key = "NUMPAD_SUBTRACT"; break;
294 case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break;
295
296 default:
297 key.Printf( _T("unknown (%ld)"), keycode);
298 }
299 }
300
301 wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"),
302 name,
303 key.c_str(),
304 GetChar( event.ControlDown(), _T('C') ),
305 GetChar( event.AltDown(), _T('A') ),
306 GetChar( event.ShiftDown(), _T('S') ),
307 GetChar( event.MetaDown(), _T('M') ) );
308
309 }
310
311 void MyTextCtrl::OnChar(wxKeyEvent& event)
312 {
313 LogEvent( _T("Char"), event);
314
315 event.Skip();
316 }
317
318 void MyTextCtrl::OnKeyUp(wxKeyEvent& event)
319 {
320 LogEvent( _("Key up"), event);
321
322 event.Skip();
323 }
324
325 void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
326 {
327 switch ( event.KeyCode() )
328 {
329 case WXK_F1:
330 // show current position and text length
331 {
332 long line, column, pos = GetInsertionPoint();
333 PositionToXY(pos, &column, &line);
334
335 wxLogMessage( _T("Current position: %ld\n"
336 "Current line, column: (%ld, %ld)\n"
337 "Number of lines: %ld\n"
338 "Current line length: %ld\n"
339 "Total text length: %ld"),
340 pos,
341 line, column,
342 GetNumberOfLines(),
343 GetLineLength(line),
344 GetLastPosition());
345 }
346 break;
347
348 case WXK_F2:
349 // go to the end
350 SetInsertionPointEnd();
351 break;
352
353 case WXK_F3:
354 // go to position 10
355 SetInsertionPoint(10);
356 break;
357 }
358
359 LogEvent( _("Key down"), event);
360
361 event.Skip();
362 }
363
364 //----------------------------------------------------------------------
365 // MyPanel
366 //----------------------------------------------------------------------
367
368 const int ID_TEXT = 150;
369 const int ID_PASTE_TEXT = 151;
370 const int ID_COPY_TEXT = 152;
371 const int ID_MOVE_END_ENTRY = 153;
372 const int ID_MOVE_END_ZONE = 154;
373
374 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
375 EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
376 EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
377 EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText)
378 EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry)
379 END_EVENT_TABLE()
380
381 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
382 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
383 {
384 m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(5,260), wxSize(630,100), wxTE_MULTILINE );
385
386 delete wxLog::SetActiveTarget(new wxLogStderr);
387
388 // single line text controls
389
390 m_text = new MyTextCtrl( this, -1, "Single line.",
391 wxPoint(10,10), wxSize(140,-1), 0);
392 (*m_text) << " Appended.";
393 m_text->SetInsertionPoint(0);
394 m_text->WriteText( "Prepended. " );
395
396 m_password = new MyTextCtrl( this, -1, "",
397 wxPoint(10,50), wxSize(140,-1), wxTE_PASSWORD );
398
399 m_readonly = new MyTextCtrl( this, -1, "Read only",
400 wxPoint(10,90), wxSize(140,-1), wxTE_READONLY );
401
402 // multi line text controls
403
404 m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.",
405 wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
406 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD));
407
408 m_multitext = new MyTextCtrl( this, ID_TEXT, "Multi line.",
409 wxPoint(180,10), wxSize(240,70), wxTE_MULTILINE );
410 (*m_multitext) << " Appended.";
411 m_multitext->SetInsertionPoint(0);
412 m_multitext->WriteText( "Prepended. " );
413
414 #if wxUSE_TOOLTIPS
415 m_multitext->SetToolTip("Press F1 here.");
416 #endif
417
418 m_tab = new MyTextCtrl( this, -1, "Multiline, allow <TAB> processing.",
419 wxPoint(180,90), wxSize(240,70), wxTE_MULTILINE | wxTE_PROCESS_TAB );
420
421 m_enter = new MyTextCtrl( this, -1, "Multiline, allow <ENTER> processing.",
422 wxPoint(180,170), wxSize(240,70), wxTE_MULTILINE | wxTE_PROCESS_ENTER );
423
424 wxButton *button;
425
426 (void)new wxStaticBox( this, -1, "&Move cursor to the end of:", wxPoint(445, 10), wxSize(160, 100) );
427 button = new wxButton( this, ID_MOVE_END_ENTRY, "&Single-line", wxPoint(470, 30), wxSize(110, 30) );
428 #if wxUSE_TOOLTIPS
429 button->SetToolTip("Move cursor in single-line text control to end of line.");
430 #endif
431 button = new wxButton( this, ID_MOVE_END_ZONE, "&Multi-line", wxPoint(470, 70), wxSize(110, 30) );
432 #if wxUSE_TOOLTIPS
433 button->SetToolTip("Move cursor in multi-line text control to end of first line.");
434 #endif
435
436 (void)new wxStaticBox( this, -1, "wx&Clipboard", wxPoint(445,130), wxSize(160,100) );
437 button = new wxButton( this, ID_COPY_TEXT, "C&opy line 1", wxPoint(470,150), wxSize(110,30) );
438 #if wxUSE_TOOLTIPS
439 button->SetToolTip("Copy first line of the multi-line text control to the clipboard");
440 #endif
441 button = new wxButton( this, ID_PASTE_TEXT, "&Paste text", wxPoint(470,190), wxSize(110,30) );
442 #if wxUSE_TOOLTIPS
443 button->SetToolTip("Paste text from clipboard to the end of the multi-line text control.");
444 #endif
445 }
446
447 void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
448 {
449 // We test for wxUSE_DRAG_AND_DROP also, because data objects
450 // may not be implemented for compilers that can't cope with the OLE
451 // parts in wxUSE_DRAG_AND_DROP.
452
453 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
454
455 // On X11, we want to get the data from the primary selection instead
456 // of the normal clipboard (which isn't normal under X11 at all). This
457 // call has no effect under MSW.
458 wxTheClipboard->UsePrimarySelection();
459
460 if (!wxTheClipboard->Open())
461 {
462 *m_log << "Error opening the clipboard.\n";
463 return;
464 }
465 else
466 {
467 *m_log << "Successfully opened the clipboard.\n";
468 }
469
470 wxTextDataObject data;
471
472 if (wxTheClipboard->IsSupported( data.GetFormat() ))
473 {
474 *m_log << "Clipboard supports requested format.\n";
475
476 if (wxTheClipboard->GetData( &data ))
477 {
478 *m_log << "Successfully retrieved data from the clipboard.\n";
479 *m_multitext << data.GetText() << "\n";
480 }
481 else
482 {
483 *m_log << "Error getting data from the clipboard.\n";
484 }
485 }
486 else
487 {
488 *m_log << "Clipboard doesn't support requested format.\n";
489 }
490
491 wxTheClipboard->Close();
492
493 *m_log << "Closed the clipboard.\n";
494 #else
495 wxLogError("Your version of wxWindows is compiled without clipboard support.");
496 #endif
497 }
498
499 void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
500 {
501 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
502 wxString text( m_multitext->GetLineText(0) );
503
504 if (text.IsEmpty())
505 {
506 *m_log << "No text to copy.\n";
507
508 return;
509 }
510
511 if (!wxTheClipboard->Open())
512 {
513 *m_log << "Error opening the clipboard.\n";
514
515 return;
516 }
517 else
518 {
519 *m_log << "Successfully opened the clipboard.\n";
520 }
521
522 wxTextDataObject *data = new wxTextDataObject( text );
523
524 if (!wxTheClipboard->SetData( data ))
525 {
526 *m_log << "Error while copying to the clipboard.\n";
527 }
528 else
529 {
530 *m_log << "Successfully copied data to the clipboard.\n";
531 }
532
533 wxTheClipboard->Close();
534
535 *m_log << "Closed the clipboard.\n";
536 #else
537 wxLogError("Your version of wxWindows is compiled without clipboard support.");
538 #endif
539 }
540
541 void MyPanel::OnMoveToEndOfText( wxCommandEvent &event )
542 {
543 m_multitext->SetInsertionPointEnd();
544 m_multitext->SetFocus();
545 }
546
547 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent &event )
548 {
549 m_text->SetInsertionPointEnd();
550 m_text->SetFocus();
551 }
552
553 //----------------------------------------------------------------------
554 // MyFrame
555 //----------------------------------------------------------------------
556
557 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
558 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
559 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
560 #if wxUSE_TOOLTIPS
561 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
562 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
563 #endif // wxUSE_TOOLTIPS
564 EVT_IDLE(MyFrame::OnIdle)
565 END_EVENT_TABLE()
566
567 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
568 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h), wxCAPTION )
569 {
570 CreateStatusBar(2);
571
572 (void)new MyPanel( this, 10, 10, 300, 100 );
573 }
574
575 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
576 {
577 Close(TRUE);
578 }
579
580 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
581 {
582 wxBeginBusyCursor();
583
584 wxMessageDialog dialog(this, "This is a text control sample. It demonstrates the many different text control\n"
585 "styles, the use of the clipboard, setting and handling tooltips and intercepting\n"
586 "key and char events.\n"
587 "\n"
588 "Copyright (c) 1999, Robert Roebling, Julian Smart, Vadim Zeitlin",
589 "About Text Controls", wxOK );
590 dialog.ShowModal();
591
592 wxEndBusyCursor();
593 }
594
595 #if wxUSE_TOOLTIPS
596 void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
597 {
598 static long s_delay = 5000;
599
600 wxString delay;
601 delay.Printf( _T("%ld"), s_delay);
602
603 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
604 "Set tooltip delay",
605 delay,
606 this);
607 if ( !delay )
608 return; // cancelled
609
610 wxSscanf(delay, _T("%ld"), &s_delay);
611
612 wxToolTip::SetDelay(s_delay);
613
614 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
615 }
616
617 void MyFrame::OnToggleTooltips(wxCommandEvent& event)
618 {
619 static bool s_enabled = TRUE;
620
621 s_enabled = !s_enabled;
622
623 wxToolTip::Enable(s_enabled);
624
625 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
626 }
627 #endif // tooltips
628
629 void MyFrame::OnIdle( wxIdleEvent& event )
630 {
631 // track the window which has the focus in the status bar
632 static wxWindow *s_windowFocus = (wxWindow *)NULL;
633 wxWindow *focus = wxWindow::FindFocus();
634 if ( focus && (focus != s_windowFocus) )
635 {
636 s_windowFocus = focus;
637
638 wxString msg;
639 msg.Printf(
640 #ifdef __WXMSW__
641 _T("Focus: wxWindow = %p, HWND = %08x"),
642 #else
643 _T("Focus: wxWindow = %p"),
644 #endif
645 s_windowFocus
646 #ifdef __WXMSW__
647 , s_windowFocus->GetHWND()
648 #endif
649 );
650
651 SetStatusText(msg);
652 }
653 event.Skip();
654 }