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