]> git.saurik.com Git - wxWidgets.git/blame - samples/text/text.cpp
Added some WXDLLEXPORTs
[wxWidgets.git] / samples / text / text.cpp
CommitLineData
02e8b87f 1/////////////////////////////////////////////////////////////////////////////
4aff28fc 2// Name: text.cpp
02e8b87f
RR
3// Purpose: TextCtrl wxWindows sample
4// Author: Robert Roebling
5// Modified by:
6// RCS-ID: $Id$
4aff28fc 7// Copyright: (c) Robert Roebling, Julian Smart, Vadim Zeitlin
02e8b87f
RR
8// Licence: wxWindows license
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
c41ea66a 12 #pragma implementation "text.cpp"
02e8b87f
RR
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
0ddea946 31#if wxUSE_FILE
ae3dd4a5 32 #include "wx/file.h"
0ddea946
VZ
33#endif
34
02e8b87f
RR
35#if wxUSE_TOOLTIPS
36 #include "wx/tooltip.h"
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)
f152cf5a 64 : wxTextCtrl(parent, id, value, pos, size, style) { m_hasCapture = FALSE; }
02e8b87f
RR
65
66 void OnKeyDown(wxKeyEvent& event);
67 void OnKeyUp(wxKeyEvent& event);
68 void OnChar(wxKeyEvent& event);
9ca03a57 69 void OnText(wxCommandEvent& event);
4aff28fc 70 void OnMouseEvent(wxMouseEvent& event);
02e8b87f 71
f6bcfd97 72 bool m_hasCapture;
f152cf5a 73
02e8b87f
RR
74private:
75 static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); }
76 void LogEvent(const wxChar *name, wxKeyEvent& event) const;
77
78 DECLARE_EVENT_TABLE()
79};
80
81class MyPanel: public wxPanel
82{
83public:
84 MyPanel(wxFrame *frame, int x, int y, int w, int h);
85
b6a0d8a2
VZ
86#if wxUSE_CLIPBOARD
87 void DoPasteFromClipboard();
88 void DoCopyToClipboard();
89#endif // wxUSE_CLIPBOARD
90
91 void DoMoveToEndOfText();
92 void DoMoveToEndOfEntry();
02e8b87f 93
89124b1a
RR
94 void OnSize( wxSizeEvent &event );
95
02e8b87f
RR
96 MyTextCtrl *m_text;
97 MyTextCtrl *m_password;
98 MyTextCtrl *m_enter;
99 MyTextCtrl *m_tab;
02e8b87f 100 MyTextCtrl *m_readonly;
bb69661b 101
02e8b87f
RR
102 MyTextCtrl *m_multitext;
103 MyTextCtrl *m_horizontal;
02e8b87f 104
0ddea946
VZ
105 MyTextCtrl *m_textrich;
106
02e8b87f 107 wxTextCtrl *m_log;
89124b1a
RR
108
109private:
110 DECLARE_EVENT_TABLE()
02e8b87f
RR
111};
112
113class MyFrame: public wxFrame
114{
115public:
b6a0d8a2 116 MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h);
02e8b87f
RR
117
118 void OnQuit(wxCommandEvent& event);
119 void OnAbout(wxCommandEvent& event);
120#if wxUSE_TOOLTIPS
121 void OnSetTooltipDelay(wxCommandEvent& event);
122 void OnToggleTooltips(wxCommandEvent& event);
123#endif // wxUSE_TOOLTIPS
b6a0d8a2
VZ
124
125#if wxUSE_CLIPBOARD
126 void OnPasteFromClipboard( wxCommandEvent &event )
127 { m_panel->DoPasteFromClipboard(); }
128 void OnCopyToClipboard( wxCommandEvent &event )
129 { m_panel->DoCopyToClipboard(); }
130#endif // wxUSE_CLIPBOARD
131
eff00523
VZ
132 void OnAddTextFreeze( wxCommandEvent& event )
133 { DoAddText(true); }
134 void OnAddText( wxCommandEvent& event )
135 { DoAddText(false); }
136
b6a0d8a2
VZ
137 void OnMoveToEndOfText( wxCommandEvent &event )
138 { m_panel->DoMoveToEndOfText(); }
139 void OnMoveToEndOfEntry( wxCommandEvent &event )
140 { m_panel->DoMoveToEndOfEntry(); }
141
e66ad5c6 142 void OnLogClear(wxCommandEvent& event);
0ddea946 143 void OnFileSave(wxCommandEvent& event);
b6a0d8a2
VZ
144 void OnFileLoad(wxCommandEvent& event);
145
f6bcfd97
BP
146 void OnSetEditable(wxCommandEvent& event);
147 void OnSetEnabled(wxCommandEvent& event);
148
02e8b87f
RR
149 void OnIdle( wxIdleEvent& event );
150
151private:
eff00523
VZ
152 void DoAddText(bool freeze)
153 {
154 wxTextCtrl *text = m_panel->m_textrich;
155 if ( freeze )
156 text->Freeze();
157
158 for ( int i = 0; i < 100; i++ )
159 text->AppendText(wxString::Format("Line %i\n", i));
160
161 text->SetInsertionPoint(0);
162
163 if ( freeze )
164 text->Thaw();
165 }
166
b6a0d8a2
VZ
167 MyPanel *m_panel;
168
02e8b87f
RR
169 DECLARE_EVENT_TABLE()
170};
171
172//----------------------------------------------------------------------
173// main()
174//----------------------------------------------------------------------
175
176IMPLEMENT_APP(MyApp)
177
178//----------------------------------------------------------------------
179// MyApp
180//----------------------------------------------------------------------
181
182enum
183{
b6a0d8a2
VZ
184 TEXT_QUIT = 100,
185 TEXT_ABOUT,
186 TEXT_LOAD,
ae3dd4a5 187 TEXT_SAVE,
e66ad5c6 188 TEXT_CLEAR,
b6a0d8a2
VZ
189
190 // clipboard menu
191 TEXT_CLIPBOARD_COPY = 200,
192 TEXT_CLIPBOARD_PASTE,
02e8b87f
RR
193
194 // tooltip menu
b6a0d8a2
VZ
195 TEXT_TOOLTIPS_SETDELAY = 300,
196 TEXT_TOOLTIPS_ENABLE,
197
f6bcfd97 198 // text menu
eff00523
VZ
199 TEXT_ADD_SOME = 400,
200 TEXT_ADD_FREEZE,
201 TEXT_MOVE_ENDTEXT,
f6bcfd97
BP
202 TEXT_MOVE_ENDENTRY,
203 TEXT_SET_EDITABLE,
204 TEXT_SET_ENABLED
02e8b87f
RR
205};
206
207bool MyApp::OnInit()
208{
209 // Create the main frame window
210 MyFrame *frame = new MyFrame((wxFrame *) NULL,
17665a2b 211 "Text wxWindows sample", 50, 50, 700, 420);
89124b1a 212 frame->SetSizeHints( 500, 400 );
02e8b87f 213
02e8b87f 214 wxMenu *file_menu = new wxMenu;
e66ad5c6
VZ
215 file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C",
216 "Clear the log window contents");
0ddea946
VZ
217 file_menu->Append(TEXT_SAVE, "&Save file\tCtrl-S",
218 "Save the text control contents to file");
b6a0d8a2
VZ
219 file_menu->Append(TEXT_LOAD, "&Load file\tCtrl-O",
220 "Load the sample file into text control");
221 file_menu->AppendSeparator();
222 file_menu->Append(TEXT_ABOUT, "&About\tAlt-A");
223 file_menu->AppendSeparator();
c41ea66a 224 file_menu->Append(TEXT_QUIT, "E&xit\tAlt-X", "Quit this sample");
02e8b87f
RR
225
226 wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE );
227 menu_bar->Append(file_menu, "&File");
228
229#if wxUSE_TOOLTIPS
230 wxMenu *tooltip_menu = new wxMenu;
b6a0d8a2 231 tooltip_menu->Append(TEXT_TOOLTIPS_SETDELAY, "Set &delay\tCtrl-D");
02e8b87f 232 tooltip_menu->AppendSeparator();
b6a0d8a2 233 tooltip_menu->Append(TEXT_TOOLTIPS_ENABLE, "&Toggle tooltips\tCtrl-T",
02e8b87f 234 "enable/disable tooltips", TRUE);
b6a0d8a2 235 tooltip_menu->Check(TEXT_TOOLTIPS_ENABLE, TRUE);
02e8b87f
RR
236 menu_bar->Append(tooltip_menu, "&Tooltips");
237#endif // wxUSE_TOOLTIPS
238
b6a0d8a2
VZ
239#if wxUSE_CLIPBOARD
240 wxMenu *menuClipboard = new wxMenu;
241 menuClipboard->Append(TEXT_CLIPBOARD_COPY, "&Copy\tCtrl-C",
242 "Copy the first line to the clipboard");
243 menuClipboard->Append(TEXT_CLIPBOARD_PASTE, "&Paste\tCtrl-V",
244 "Paste from clipboard to the text control");
245 menu_bar->Append(menuClipboard, "&Clipboard");
246#endif // wxUSE_CLIPBOARD
247
f6bcfd97 248 wxMenu *menuText = new wxMenu;
eff00523
VZ
249 menuText->Append(TEXT_ADD_SOME, "&Append some text\tCtrl-A");
250 menuText->Append(TEXT_ADD_FREEZE, "&Append text with freeze/thaw\tShift-Ctrl-A");
f6bcfd97
BP
251 menuText->Append(TEXT_MOVE_ENDTEXT, "Move cursor to the end of &text");
252 menuText->Append(TEXT_MOVE_ENDENTRY, "Move cursor to the end of &entry");
253 menuText->Append(TEXT_SET_EDITABLE, "Toggle &editable state", "", TRUE);
254 menuText->Append(TEXT_SET_ENABLED, "Toggle e&nabled state", "", TRUE);
255 menuText->Check(TEXT_SET_EDITABLE, TRUE);
256 menuText->Check(TEXT_SET_ENABLED, TRUE);
257 menu_bar->Append(menuText, "&Text");
b6a0d8a2 258
02e8b87f
RR
259 frame->SetMenuBar(menu_bar);
260
261 frame->Show(TRUE);
262
263 SetTopWindow(frame);
264
265 // report success
266 return TRUE;
267}
268
269//----------------------------------------------------------------------
270// MyTextCtrl
271//----------------------------------------------------------------------
272
273BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
274 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
275 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
276 EVT_CHAR(MyTextCtrl::OnChar)
9ca03a57 277 EVT_TEXT(-1, MyTextCtrl::OnText)
4aff28fc 278 EVT_MOUSE_EVENTS(MyTextCtrl::OnMouseEvent)
02e8b87f
RR
279END_EVENT_TABLE()
280
281void MyTextCtrl::LogEvent(const wxChar *name, wxKeyEvent& event) const
282{
283 wxString key;
284 long keycode = event.KeyCode();
02e8b87f
RR
285 {
286 switch ( keycode )
287 {
288 case WXK_BACK: key = "BACK"; break;
289 case WXK_TAB: key = "TAB"; break;
290 case WXK_RETURN: key = "RETURN"; break;
291 case WXK_ESCAPE: key = "ESCAPE"; break;
292 case WXK_SPACE: key = "SPACE"; break;
293 case WXK_DELETE: key = "DELETE"; break;
294 case WXK_START: key = "START"; break;
295 case WXK_LBUTTON: key = "LBUTTON"; break;
296 case WXK_RBUTTON: key = "RBUTTON"; break;
297 case WXK_CANCEL: key = "CANCEL"; break;
298 case WXK_MBUTTON: key = "MBUTTON"; break;
299 case WXK_CLEAR: key = "CLEAR"; break;
300 case WXK_SHIFT: key = "SHIFT"; break;
301 case WXK_ALT: key = "ALT"; break;
302 case WXK_CONTROL: key = "CONTROL"; break;
303 case WXK_MENU: key = "MENU"; break;
304 case WXK_PAUSE: key = "PAUSE"; break;
305 case WXK_CAPITAL: key = "CAPITAL"; break;
306 case WXK_PRIOR: key = "PRIOR"; break;
307 case WXK_NEXT: key = "NEXT"; break;
308 case WXK_END: key = "END"; break;
309 case WXK_HOME: key = "HOME"; break;
310 case WXK_LEFT: key = "LEFT"; break;
311 case WXK_UP: key = "UP"; break;
312 case WXK_RIGHT: key = "RIGHT"; break;
313 case WXK_DOWN: key = "DOWN"; break;
314 case WXK_SELECT: key = "SELECT"; break;
315 case WXK_PRINT: key = "PRINT"; break;
316 case WXK_EXECUTE: key = "EXECUTE"; break;
317 case WXK_SNAPSHOT: key = "SNAPSHOT"; break;
318 case WXK_INSERT: key = "INSERT"; break;
319 case WXK_HELP: key = "HELP"; break;
320 case WXK_NUMPAD0: key = "NUMPAD0"; break;
321 case WXK_NUMPAD1: key = "NUMPAD1"; break;
322 case WXK_NUMPAD2: key = "NUMPAD2"; break;
323 case WXK_NUMPAD3: key = "NUMPAD3"; break;
324 case WXK_NUMPAD4: key = "NUMPAD4"; break;
325 case WXK_NUMPAD5: key = "NUMPAD5"; break;
326 case WXK_NUMPAD6: key = "NUMPAD6"; break;
327 case WXK_NUMPAD7: key = "NUMPAD7"; break;
328 case WXK_NUMPAD8: key = "NUMPAD8"; break;
329 case WXK_NUMPAD9: key = "NUMPAD9"; break;
330 case WXK_MULTIPLY: key = "MULTIPLY"; break;
331 case WXK_ADD: key = "ADD"; break;
332 case WXK_SEPARATOR: key = "SEPARATOR"; break;
333 case WXK_SUBTRACT: key = "SUBTRACT"; break;
334 case WXK_DECIMAL: key = "DECIMAL"; break;
335 case WXK_DIVIDE: key = "DIVIDE"; break;
336 case WXK_F1: key = "F1"; break;
337 case WXK_F2: key = "F2"; break;
338 case WXK_F3: key = "F3"; break;
339 case WXK_F4: key = "F4"; break;
340 case WXK_F5: key = "F5"; break;
341 case WXK_F6: key = "F6"; break;
342 case WXK_F7: key = "F7"; break;
343 case WXK_F8: key = "F8"; break;
344 case WXK_F9: key = "F9"; break;
345 case WXK_F10: key = "F10"; break;
346 case WXK_F11: key = "F11"; break;
347 case WXK_F12: key = "F12"; break;
348 case WXK_F13: key = "F13"; break;
349 case WXK_F14: key = "F14"; break;
350 case WXK_F15: key = "F15"; break;
351 case WXK_F16: key = "F16"; break;
352 case WXK_F17: key = "F17"; break;
353 case WXK_F18: key = "F18"; break;
354 case WXK_F19: key = "F19"; break;
355 case WXK_F20: key = "F20"; break;
356 case WXK_F21: key = "F21"; break;
357 case WXK_F22: key = "F22"; break;
358 case WXK_F23: key = "F23"; break;
359 case WXK_F24: key = "F24"; break;
360 case WXK_NUMLOCK: key = "NUMLOCK"; break;
361 case WXK_SCROLL: key = "SCROLL"; break;
362 case WXK_PAGEUP: key = "PAGEUP"; break;
363 case WXK_PAGEDOWN: key = "PAGEDOWN"; break;
364 case WXK_NUMPAD_SPACE: key = "NUMPAD_SPACE"; break;
365 case WXK_NUMPAD_TAB: key = "NUMPAD_TAB"; break;
366 case WXK_NUMPAD_ENTER: key = "NUMPAD_ENTER"; break;
367 case WXK_NUMPAD_F1: key = "NUMPAD_F1"; break;
368 case WXK_NUMPAD_F2: key = "NUMPAD_F2"; break;
369 case WXK_NUMPAD_F3: key = "NUMPAD_F3"; break;
370 case WXK_NUMPAD_F4: key = "NUMPAD_F4"; break;
371 case WXK_NUMPAD_HOME: key = "NUMPAD_HOME"; break;
372 case WXK_NUMPAD_LEFT: key = "NUMPAD_LEFT"; break;
373 case WXK_NUMPAD_UP: key = "NUMPAD_UP"; break;
374 case WXK_NUMPAD_RIGHT: key = "NUMPAD_RIGHT"; break;
375 case WXK_NUMPAD_DOWN: key = "NUMPAD_DOWN"; break;
376 case WXK_NUMPAD_PRIOR: key = "NUMPAD_PRIOR"; break;
377 case WXK_NUMPAD_PAGEUP: key = "NUMPAD_PAGEUP"; break;
378 case WXK_NUMPAD_PAGEDOWN: key = "NUMPAD_PAGEDOWN"; break;
379 case WXK_NUMPAD_END: key = "NUMPAD_END"; break;
380 case WXK_NUMPAD_BEGIN: key = "NUMPAD_BEGIN"; break;
381 case WXK_NUMPAD_INSERT: key = "NUMPAD_INSERT"; break;
382 case WXK_NUMPAD_DELETE: key = "NUMPAD_DELETE"; break;
383 case WXK_NUMPAD_EQUAL: key = "NUMPAD_EQUAL"; break;
384 case WXK_NUMPAD_MULTIPLY: key = "NUMPAD_MULTIPLY"; break;
385 case WXK_NUMPAD_ADD: key = "NUMPAD_ADD"; break;
386 case WXK_NUMPAD_SEPARATOR: key = "NUMPAD_SEPARATOR"; break;
387 case WXK_NUMPAD_SUBTRACT: key = "NUMPAD_SUBTRACT"; break;
388 case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break;
389
4afd7529 390 default:
89124b1a
RR
391 {
392 if ( wxIsprint((int)keycode) )
393 key.Printf( _T("'%c'") , (char)keycode);
394 else
4afd7529
VZ
395 key.Printf( _T("unknown (%ld)"), keycode);
396 }
02e8b87f
RR
397 }
398 }
399
400 wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"),
401 name,
402 key.c_str(),
403 GetChar( event.ControlDown(), _T('C') ),
404 GetChar( event.AltDown(), _T('A') ),
405 GetChar( event.ShiftDown(), _T('S') ),
406 GetChar( event.MetaDown(), _T('M') ) );
02e8b87f
RR
407}
408
4aff28fc
VZ
409void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev)
410{
411 if ( !ev.Moving() )
412 {
413 wxString msg;
414 if ( ev.Entering() )
415 {
416 msg = _T("Mouse entered the window");
417 }
418 else if ( ev.Leaving() )
419 {
420 msg = _T("Mouse left the window");
421 }
422 else
423 {
424 // click event
425 wxString button;
426 bool dbl, up;
427 if ( ev.LeftDown() || ev.LeftUp() || ev.LeftDClick() )
428 {
429 button = _T("Left");
430 dbl = ev.LeftDClick();
431 up = ev.LeftUp();
432 }
433 else if ( ev.MiddleDown() || ev.MiddleUp() || ev.MiddleDClick() )
434 {
435 button = _T("Middle");
436 dbl = ev.MiddleDClick();
437 up = ev.MiddleUp();
438 }
439 else if ( ev.RightDown() || ev.RightUp() || ev.RightDClick() )
440 {
441 button = _T("Right");
442 dbl = ev.RightDClick();
443 up = ev.RightUp();
444 }
445 else
446 {
447 wxLogStatus(_T("Unknown mouse event"));
448 return;
449 }
450
451 msg.Printf(_T("%s mouse button %s"),
452 button.c_str(),
453 dbl ? _T("double clicked")
454 : up ? _T("released") : _T("clicked"));
455 }
456
457 msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ")
458 << _T("Flags: ")
4ed0aceb
VZ
459 << GetChar( ev.LeftIsDown(), _T('1') )
460 << GetChar( ev.MiddleIsDown(), _T('2') )
461 << GetChar( ev.RightIsDown(), _T('3') )
4aff28fc
VZ
462 << GetChar( ev.ControlDown(), _T('C') )
463 << GetChar( ev.AltDown(), _T('A') )
464 << GetChar( ev.ShiftDown(), _T('S') )
465 << GetChar( ev.MetaDown(), _T('M') );
466
467 wxLogMessage(msg);
468 }
469 //else: we're not interested in mouse move events
4ed0aceb
VZ
470
471 ev.Skip();
4aff28fc
VZ
472}
473
9ca03a57 474void MyTextCtrl::OnText(wxCommandEvent& event)
02e8b87f 475{
9ca03a57 476 MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
ae3dd4a5
VZ
477 const wxChar *data = (const wxChar *)(win->GetClientData());
478 if ( data )
479 {
c41ea66a 480 wxLogMessage(_T("Text changed in control '%s'"), data);
ae3dd4a5 481 }
f6bcfd97
BP
482 else
483 {
484 wxLogMessage(_T("Text changed in some control"));
485 }
9ca03a57
VZ
486}
487
488void MyTextCtrl::OnChar(wxKeyEvent& event)
489{
490 LogEvent( _T("Char"), event);
ae3dd4a5 491
3017f78d
RR
492/* How are we supposed to test wxTE_PROCESS_TAB with this code?
493
b6a0d8a2
VZ
494 if ( event.KeyCode() == WXK_TAB )
495 {
496 WriteText("\t");
497 }
498 else
499 {
500 event.Skip();
501 }
3017f78d
RR
502*/
503 event.Skip();
02e8b87f
RR
504}
505
506void MyTextCtrl::OnKeyUp(wxKeyEvent& event)
507{
ae3dd4a5 508 LogEvent( _T("Key up"), event);
02e8b87f
RR
509
510 event.Skip();
511}
512
513void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
514{
515 switch ( event.KeyCode() )
516 {
517 case WXK_F1:
518 // show current position and text length
519 {
520 long line, column, pos = GetInsertionPoint();
521 PositionToXY(pos, &column, &line);
522
523 wxLogMessage( _T("Current position: %ld\n"
524 "Current line, column: (%ld, %ld)\n"
525 "Number of lines: %ld\n"
526 "Current line length: %ld\n"
f6bcfd97 527 "Total text length: %u (%ld)"),
02e8b87f
RR
528 pos,
529 line, column,
530 GetNumberOfLines(),
531 GetLineLength(line),
f6bcfd97 532 GetValue().length(),
02e8b87f
RR
533 GetLastPosition());
534 }
535 break;
536
537 case WXK_F2:
538 // go to the end
539 SetInsertionPointEnd();
540 break;
541
542 case WXK_F3:
543 // go to position 10
544 SetInsertionPoint(10);
545 break;
4afd7529 546
f152cf5a 547 case WXK_F4:
4afd7529
VZ
548 if (!m_hasCapture)
549 {
f152cf5a 550 wxLogDebug( wxT("Now capturing mouse and events.") );
4afd7529
VZ
551 m_hasCapture = TRUE;
552 CaptureMouse();
553 }
554 else
555 {
f152cf5a 556 wxLogDebug( wxT("Stopped capturing mouse and events.") );
4afd7529
VZ
557 m_hasCapture = TRUE;
558 ReleaseMouse();
559 }
f152cf5a 560 break;
4afd7529
VZ
561
562 case WXK_F5:
563 // insert a blank line
564 WriteText("\n");
ae3dd4a5 565 break;
02e8b87f 566
f6bcfd97
BP
567 case WXK_F6:
568 SetValue("F6 was just pressed.");
569 break;
570
571 case WXK_F7:
572 ShowPosition(10);
573 break;
0ddea946 574 }
02e8b87f 575
f6bcfd97
BP
576 LogEvent( wxT("Key down"), event);
577
02e8b87f
RR
578 event.Skip();
579}
580
581//----------------------------------------------------------------------
582// MyPanel
583//----------------------------------------------------------------------
584
89124b1a
RR
585BEGIN_EVENT_TABLE(MyPanel, wxPanel)
586 EVT_SIZE(MyPanel::OnSize)
587END_EVENT_TABLE()
588
02e8b87f
RR
589MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
590 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
591{
592 m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(5,260), wxSize(630,100), wxTE_MULTILINE );
593
89124b1a
RR
594 wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
595
596 delete old_log;
02e8b87f
RR
597
598 // single line text controls
599
bb69661b 600 m_text = new MyTextCtrl( this, -1, "Single line.",
f6bcfd97
BP
601 wxPoint(10,10), wxSize(140,-1),
602 wxTE_PROCESS_ENTER);
4ed0aceb
VZ
603 m_text->SetForegroundColour(*wxBLUE);
604 m_text->SetBackgroundColour(*wxLIGHT_GREY);
02e8b87f
RR
605 (*m_text) << " Appended.";
606 m_text->SetInsertionPoint(0);
607 m_text->WriteText( "Prepended. " );
bb69661b
VZ
608
609 m_password = new MyTextCtrl( this, -1, "",
02e8b87f 610 wxPoint(10,50), wxSize(140,-1), wxTE_PASSWORD );
bb69661b
VZ
611
612 m_readonly = new MyTextCtrl( this, -1, "Read only",
02e8b87f 613 wxPoint(10,90), wxSize(140,-1), wxTE_READONLY );
bb69661b 614
02e8b87f
RR
615 // multi line text controls
616
bb69661b
VZ
617 m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.",
618 wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
f6bcfd97
BP
619
620 // a little hack to use the command line argument for encoding testing
621 if ( wxTheApp->argc == 2 )
622 {
623 switch ( wxTheApp->argv[1][0] )
624 {
625 case '2':
626 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
627 FALSE, "",
628 wxFONTENCODING_ISO8859_2));
629