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