]> git.saurik.com Git - wxWidgets.git/blob - samples/text/text.cpp
added wxPowerEvent; moved power functions stubs to common/powercmn.cpp
[wxWidgets.git] / samples / text / text.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: text.cpp
3 // Purpose: TextCtrl wxWidgets 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 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #if wxUSE_CLIPBOARD
23 #include "wx/dataobj.h"
24 #include "wx/clipbrd.h"
25 #endif
26
27 #if wxUSE_FILE
28 #include "wx/file.h"
29 #endif
30
31 #if wxUSE_TOOLTIPS
32 #include "wx/tooltip.h"
33 #endif
34
35 // We test for wxUSE_DRAG_AND_DROP also, because data objects may not be
36 // implemented for compilers that can't cope with the OLE parts in
37 // wxUSE_DRAG_AND_DROP.
38 #if !wxUSE_DRAG_AND_DROP
39 #undef wxUSE_CLIPBOARD
40 #define wxUSE_CLIPBOARD 0
41 #endif
42
43 #include "wx/colordlg.h"
44 #include "wx/fontdlg.h"
45 #include "wx/numdlg.h"
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 OnTextEnter(wxCommandEvent& event);
75 void OnTextURL(wxTextUrlEvent& event);
76 void OnTextMaxLen(wxCommandEvent& event);
77
78 void OnTextCut(wxClipboardTextEvent & event);
79 void OnTextCopy(wxClipboardTextEvent & event);
80 void OnTextPaste(wxClipboardTextEvent & event);
81
82 void OnMouseEvent(wxMouseEvent& event);
83
84 void OnSetFocus(wxFocusEvent& event);
85 void OnKillFocus(wxFocusEvent& event);
86
87 static bool ms_logKey;
88 static bool ms_logChar;
89 static bool ms_logMouse;
90 static bool ms_logText;
91 static bool ms_logFocus;
92 static bool ms_logClip;
93
94 private:
95 static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); }
96
97 void LogKeyEvent(const wxChar *name, wxKeyEvent& event) const;
98 void LogClipEvent(const wxChar *what, wxClipboardTextEvent& event);
99
100 bool m_hasCapture;
101
102 DECLARE_EVENT_TABLE()
103 };
104
105 class MyPanel: public wxPanel
106 {
107 public:
108 MyPanel(wxFrame *frame, int x, int y, int w, int h);
109 virtual ~MyPanel()
110 {
111 #if wxUSE_LOG
112 delete wxLog::SetActiveTarget(m_logOld);
113 #endif // wxUSE_LOG
114 }
115
116 #if wxUSE_CLIPBOARD
117 void DoPasteFromClipboard();
118 void DoCopyToClipboard();
119 #endif // wxUSE_CLIPBOARD
120
121 void DoRemoveText();
122 void DoReplaceText();
123 void DoSelectText();
124 void DoMoveToEndOfText();
125 void DoMoveToEndOfEntry();
126
127 // return true if currently text control has any selection
128 bool HasSelection() const
129 {
130 long from, to;
131 GetFocusedText()->GetSelection(&from, &to);
132 return from != to;
133 }
134
135 MyTextCtrl *m_text;
136 MyTextCtrl *m_password;
137 MyTextCtrl *m_enter;
138 MyTextCtrl *m_tab;
139 MyTextCtrl *m_readonly;
140 MyTextCtrl *m_limited;
141
142 MyTextCtrl *m_multitext;
143 MyTextCtrl *m_horizontal;
144
145 MyTextCtrl *m_textrich;
146
147 #if wxUSE_LOG
148 wxTextCtrl *m_log;
149 wxLog *m_logOld;
150 #endif // wxUSE_LOG
151
152 private:
153 // get the currently focused text control or return the default one
154 // (m_multitext) is no text ctrl has focus -- in any case, returns
155 // something non NULL
156 wxTextCtrl *GetFocusedText() const;
157 };
158
159 class MyFrame: public wxFrame
160 {
161 public:
162 MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h);
163
164 void OnQuit(wxCommandEvent& event);
165 void OnAbout(wxCommandEvent& event);
166 #if wxUSE_TOOLTIPS
167 void OnSetTooltipDelay(wxCommandEvent& event);
168 void OnToggleTooltips(wxCommandEvent& event);
169 #endif // wxUSE_TOOLTIPS
170
171 #if wxUSE_CLIPBOARD
172 void OnPasteFromClipboard( wxCommandEvent& WXUNUSED(event) )
173 {
174 wxLogMessage(_T("Pasting text from clipboard."));
175 m_panel->DoPasteFromClipboard();
176 }
177 void OnCopyToClipboard( wxCommandEvent& WXUNUSED(event) )
178 {
179 wxLogMessage(_T("Copying text to clipboard."));
180 m_panel->DoCopyToClipboard();
181 }
182
183 void OnUpdatePasteFromClipboard(wxUpdateUIEvent& event)
184 {
185 wxClipboardLocker lockClip;
186
187 event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) );
188 }
189
190 void OnUpdateCopyToClipboard(wxUpdateUIEvent& event)
191 {
192 event.Enable( m_panel->HasSelection() );
193 }
194 #endif // wxUSE_CLIPBOARD
195
196 void OnAddTextFreeze( wxCommandEvent& WXUNUSED(event) )
197 { DoAddText(true); }
198 void OnAddText( wxCommandEvent& WXUNUSED(event) )
199 { DoAddText(false); }
200 void OnRemoveText( wxCommandEvent& WXUNUSED(event) )
201 { m_panel->DoRemoveText(); }
202 void OnReplaceText( wxCommandEvent& WXUNUSED(event) )
203 { m_panel->DoReplaceText(); }
204 void OnSelectText( wxCommandEvent& WXUNUSED(event) )
205 { m_panel->DoSelectText(); }
206
207 void OnMoveToEndOfText( wxCommandEvent& WXUNUSED(event) )
208 { m_panel->DoMoveToEndOfText(); }
209 void OnMoveToEndOfEntry( wxCommandEvent& WXUNUSED(event) )
210 { m_panel->DoMoveToEndOfEntry(); }
211
212 void OnScrollLineDown(wxCommandEvent& WXUNUSED(event))
213 {
214 if ( !m_panel->m_textrich->LineDown() )
215 wxLogMessage(_T("Already at the bottom"));
216 }
217
218 void OnScrollLineUp(wxCommandEvent& WXUNUSED(event))
219 {
220 if ( !m_panel->m_textrich->LineUp() )
221 wxLogMessage(_T("Already at the top"));
222 }
223
224 void OnScrollPageDown(wxCommandEvent& WXUNUSED(event))
225 {
226 if ( !m_panel->m_textrich->PageDown() )
227 wxLogMessage(_T("Already at the bottom"));
228 }
229
230 void OnScrollPageUp(wxCommandEvent& WXUNUSED(event))
231 {
232 if ( !m_panel->m_textrich->PageUp() )
233 wxLogMessage(_T("Already at the top"));
234 }
235
236 void OnGetLine(wxCommandEvent& WXUNUSED(event))
237 {
238 long nLine = wxGetNumberFromUser(wxT("Which line would you like to get?"),
239 wxT("Enter which line you would like to get"),
240 wxT("Get a line from the tabbed multiline text control") );
241
242 wxMessageBox(m_panel->m_tab->GetLineText(nLine));
243 }
244
245 void OnGetLineLength(wxCommandEvent& WXUNUSED(event))
246 {
247 long nLine = wxGetNumberFromUser(wxT("Which line would you like to get?"),
248 wxT("Enter which line you would like to get"),
249 wxT("Get length of a line from the tabbed multiline text control") );
250
251 wxMessageBox(wxString::Format(wxT("Length of line %i is:%i"),
252 (int) nLine,
253 m_panel->m_tab->GetLineLength(nLine))
254 );
255 }
256
257 #if wxUSE_LOG
258 void OnLogClear(wxCommandEvent& event);
259 #endif // wxUSE_LOG
260 void OnFileSave(wxCommandEvent& event);
261 void OnFileLoad(wxCommandEvent& event);
262 void OnRichTextTest(wxCommandEvent& event);
263
264 void OnSetEditable(wxCommandEvent& event);
265 void OnSetEnabled(wxCommandEvent& event);
266
267 void OnLogKey(wxCommandEvent& event)
268 {
269 MyTextCtrl::ms_logKey = event.IsChecked();
270 }
271
272 void OnLogChar(wxCommandEvent& event)
273 {
274 MyTextCtrl::ms_logChar = event.IsChecked();
275 }
276
277 void OnLogMouse(wxCommandEvent& event)
278 {
279 MyTextCtrl::ms_logMouse = event.IsChecked();
280 }
281
282 void OnLogText(wxCommandEvent& event)
283 {
284 MyTextCtrl::ms_logText = event.IsChecked();
285 }
286
287 void OnLogFocus(wxCommandEvent& event)
288 {
289 MyTextCtrl::ms_logFocus = event.IsChecked();
290 }
291
292 void OnLogClip(wxCommandEvent& event)
293 {
294 MyTextCtrl::ms_logClip = event.IsChecked();
295 }
296
297 void OnSetText(wxCommandEvent& WXUNUSED(event))
298 {
299 m_panel->m_text->SetValue(_T("Hello, world (what else did you expect)?"));
300 }
301
302 void OnIdle( wxIdleEvent& event );
303
304 private:
305 void DoAddText(bool freeze)
306 {
307 wxTextCtrl * const text = m_panel->m_textrich;
308 text->Clear();
309
310 if ( freeze )
311 text->Freeze();
312
313 for ( int i = 0; i < 100; i++ )
314 {
315 text->AppendText(wxString::Format(wxT("Line %i\n"), i));
316 }
317
318 if ( freeze )
319 text->Thaw();
320
321 text->SetInsertionPoint(0);
322 }
323
324 MyPanel *m_panel;
325
326 DECLARE_EVENT_TABLE()
327 };
328
329 /*
330 * RichTextFrame is used to demonstrate rich text behaviour
331 */
332
333 class RichTextFrame: public wxFrame
334 {
335 public:
336 RichTextFrame(wxWindow* parent, const wxString& title);
337
338 // Event handlers
339
340 void OnClose(wxCommandEvent& event);
341 void OnIdle(wxIdleEvent& event);
342 void OnLeftAlign(wxCommandEvent& event);
343 void OnRightAlign(wxCommandEvent& event);
344 void OnJustify(wxCommandEvent& event);
345 void OnCentre(wxCommandEvent& event);
346 void OnChangeFont(wxCommandEvent& event);
347 void OnChangeTextColour(wxCommandEvent& event);
348 void OnChangeBackgroundColour(wxCommandEvent& event);
349 void OnLeftIndent(wxCommandEvent& event);
350 void OnRightIndent(wxCommandEvent& event);
351
352 private:
353 wxTextCtrl *m_textCtrl;
354 long m_currentPosition;
355
356 DECLARE_EVENT_TABLE()
357 };
358
359 //----------------------------------------------------------------------
360 // main()
361 //----------------------------------------------------------------------
362
363 IMPLEMENT_APP(MyApp)
364
365 //----------------------------------------------------------------------
366 // MyApp
367 //----------------------------------------------------------------------
368
369 enum
370 {
371 TEXT_QUIT = wxID_EXIT,
372 TEXT_ABOUT = wxID_ABOUT,
373 TEXT_LOAD = 101,
374 TEXT_SAVE,
375 TEXT_CLEAR,
376 TEXT_RICH_TEXT_TEST,
377
378 // clipboard menu
379 TEXT_CLIPBOARD_COPY = 200,
380 TEXT_CLIPBOARD_PASTE,
381 TEXT_CLIPBOARD_VETO,
382
383 // tooltip menu
384 TEXT_TOOLTIPS_SETDELAY = 300,
385 TEXT_TOOLTIPS_ENABLE,
386
387 // text menu
388 TEXT_ADD_SOME = 400,
389 TEXT_ADD_FREEZE,
390 TEXT_MOVE_ENDTEXT,
391 TEXT_MOVE_ENDENTRY,
392 TEXT_SET_EDITABLE,
393 TEXT_SET_ENABLED,
394 TEXT_LINE_DOWN,
395 TEXT_LINE_UP,
396 TEXT_PAGE_DOWN,
397 TEXT_PAGE_UP,
398
399 TEXT_GET_LINE,
400 TEXT_GET_LINELENGTH,
401
402 TEXT_REMOVE,
403 TEXT_REPLACE,
404 TEXT_SELECT,
405 TEXT_SET,
406
407 // log menu
408 TEXT_LOG_KEY,
409 TEXT_LOG_CHAR,
410 TEXT_LOG_MOUSE,
411 TEXT_LOG_TEXT,
412 TEXT_LOG_FOCUS,
413 TEXT_LOG_CLIP,
414
415 TEXT_END
416 };
417
418 bool MyApp::OnInit()
419 {
420 // Create the main frame window
421 MyFrame *frame = new MyFrame((wxFrame *) NULL,
422 _T("Text wxWidgets sample"), 50, 50, 700, 550);
423 frame->SetSizeHints( 500, 400 );
424
425 wxMenu *file_menu = new wxMenu;
426 file_menu->Append(TEXT_SAVE, _T("&Save file\tCtrl-S"),
427 _T("Save the text control contents to file"));
428 file_menu->Append(TEXT_LOAD, _T("&Load file\tCtrl-O"),
429 _T("Load the sample file into text control"));
430 file_menu->AppendSeparator();
431 file_menu->Append(TEXT_RICH_TEXT_TEST, _T("Show Rich Text Editor"));
432 file_menu->AppendSeparator();
433 file_menu->Append(TEXT_ABOUT, _T("&About\tAlt-A"));
434 file_menu->AppendSeparator();
435 file_menu->Append(TEXT_QUIT, _T("E&xit\tAlt-X"), _T("Quit this sample"));
436
437 wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE );
438 menu_bar->Append(file_menu, _T("&File"));
439
440 #if wxUSE_TOOLTIPS
441 wxMenu *tooltip_menu = new wxMenu;
442 tooltip_menu->Append(TEXT_TOOLTIPS_SETDELAY, _T("Set &delay\tCtrl-D"));
443 tooltip_menu->AppendSeparator();
444 tooltip_menu->Append(TEXT_TOOLTIPS_ENABLE, _T("&Toggle tooltips\tCtrl-T"),
445 _T("enable/disable tooltips"), true);
446 tooltip_menu->Check(TEXT_TOOLTIPS_ENABLE, true);
447 menu_bar->Append(tooltip_menu, _T("&Tooltips"));
448 #endif // wxUSE_TOOLTIPS
449
450 #if wxUSE_CLIPBOARD
451 // notice that we use non default accelerators on purpose here to compare
452 // their behaviour with the built in handling of standard Ctrl/Cmd-C/V
453 wxMenu *menuClipboard = new wxMenu;
454 menuClipboard->Append(TEXT_CLIPBOARD_COPY, _T("&Copy\tCtrl-Shift-C"),
455 _T("Copy the selection to the clipboard"));
456 menuClipboard->Append(TEXT_CLIPBOARD_PASTE, _T("&Paste\tCtrl-Shift-V"),
457 _T("Paste from clipboard to the text control"));
458 menuClipboard->AppendSeparator();
459 menuClipboard->AppendCheckItem(TEXT_CLIPBOARD_VETO, _T("Vet&o\tCtrl-Shift-O"),
460 _T("Veto all clipboard operations"));
461 menu_bar->Append(menuClipboard, _T("&Clipboard"));
462 #endif // wxUSE_CLIPBOARD
463
464 wxMenu *menuText = new wxMenu;
465 menuText->Append(TEXT_ADD_SOME, _T("&Append some text\tCtrl-A"));
466 menuText->Append(TEXT_ADD_FREEZE, _T("&Append text with freeze/thaw\tShift-Ctrl-A"));
467 menuText->Append(TEXT_REMOVE, _T("&Remove first 10 characters\tCtrl-Y"));
468 menuText->Append(TEXT_REPLACE, _T("&Replace characters 4 to 8 with ABC\tCtrl-R"));
469 menuText->Append(TEXT_SELECT, _T("&Select characters 4 to 8\tCtrl-I"));
470 menuText->Append(TEXT_SET, _T("&Set the first text zone value\tCtrl-E"));
471 menuText->AppendSeparator();
472 menuText->Append(TEXT_MOVE_ENDTEXT, _T("Move cursor to the end of &text"));
473 menuText->Append(TEXT_MOVE_ENDENTRY, _T("Move cursor to the end of &entry"));
474 menuText->AppendCheckItem(TEXT_SET_EDITABLE, _T("Toggle &editable state"));
475 menuText->AppendCheckItem(TEXT_SET_ENABLED, _T("Toggle e&nabled state"));
476 menuText->Check(TEXT_SET_EDITABLE, true);
477 menuText->Check(TEXT_SET_ENABLED, true);
478 menuText->AppendSeparator();
479 menuText->Append(TEXT_LINE_DOWN, _T("Scroll text one line down"));
480 menuText->Append(TEXT_LINE_UP, _T("Scroll text one line up"));
481 menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page down"));
482 menuText->Append(TEXT_PAGE_UP, _T("Scroll text one page up"));
483 menuText->AppendSeparator();
484 menuText->Append(TEXT_GET_LINE, _T("Get the text of a line of the tabbed multiline"));
485 menuText->Append(TEXT_GET_LINELENGTH, _T("Get the length of a line of the tabbed multiline"));
486 menu_bar->Append(menuText, _T("Te&xt"));
487
488 #if wxUSE_LOG
489 wxMenu *menuLog = new wxMenu;
490 menuLog->AppendCheckItem(TEXT_LOG_KEY, _T("Log &key events"));
491 menuLog->AppendCheckItem(TEXT_LOG_CHAR, _T("Log &char events"));
492 menuLog->AppendCheckItem(TEXT_LOG_MOUSE, _T("Log &mouse events"));
493 menuLog->AppendCheckItem(TEXT_LOG_TEXT, _T("Log &text events"));
494 menuLog->AppendCheckItem(TEXT_LOG_FOCUS, _T("Log &focus events"));
495 menuLog->AppendCheckItem(TEXT_LOG_CLIP, _T("Log clip&board events"));
496 menuLog->AppendSeparator();
497 menuLog->Append(TEXT_CLEAR, _T("&Clear the log\tCtrl-L"),
498 _T("Clear the log window contents"));
499
500 // select only the interesting events by default
501 MyTextCtrl::ms_logClip =
502 MyTextCtrl::ms_logText = true;
503
504 menuLog->Check(TEXT_LOG_KEY, MyTextCtrl::ms_logKey);
505 menuLog->Check(TEXT_LOG_CHAR, MyTextCtrl::ms_logChar);
506 menuLog->Check(TEXT_LOG_TEXT, MyTextCtrl::ms_logText);
507
508 menu_bar->Append(menuLog, _T("&Log"));
509 #endif // wxUSE_LOG
510
511 frame->SetMenuBar(menu_bar);
512
513 frame->Show(true);
514
515 SetTopWindow(frame);
516
517 // report success
518 return true;
519 }
520
521 //----------------------------------------------------------------------
522 // MyTextCtrl
523 //----------------------------------------------------------------------
524
525 BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
526 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
527 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
528 EVT_CHAR(MyTextCtrl::OnChar)
529
530 EVT_TEXT(wxID_ANY, MyTextCtrl::OnText)
531 EVT_TEXT_ENTER(wxID_ANY, MyTextCtrl::OnTextEnter)
532 EVT_TEXT_URL(wxID_ANY, MyTextCtrl::OnTextURL)
533 EVT_TEXT_MAXLEN(wxID_ANY, MyTextCtrl::OnTextMaxLen)
534 EVT_TEXT_CUT(wxID_ANY, MyTextCtrl::OnTextCut)
535 EVT_TEXT_COPY(wxID_ANY, MyTextCtrl::OnTextCopy)
536 EVT_TEXT_PASTE(wxID_ANY, MyTextCtrl::OnTextPaste)
537
538 EVT_MOUSE_EVENTS(MyTextCtrl::OnMouseEvent)
539
540 EVT_SET_FOCUS(MyTextCtrl::OnSetFocus)
541 EVT_KILL_FOCUS(MyTextCtrl::OnKillFocus)
542 END_EVENT_TABLE()
543
544 bool MyTextCtrl::ms_logKey = false;
545 bool MyTextCtrl::ms_logChar = false;
546 bool MyTextCtrl::ms_logMouse = false;
547 bool MyTextCtrl::ms_logText = false;
548 bool MyTextCtrl::ms_logFocus = false;
549 bool MyTextCtrl::ms_logClip = false;
550
551 void MyTextCtrl::LogKeyEvent(const wxChar *name, wxKeyEvent& event) const
552 {
553 wxString key;
554 long keycode = event.GetKeyCode();
555 {
556 switch ( keycode )
557 {
558 case WXK_BACK: key = _T("BACK"); break;
559 case WXK_TAB: key = _T("TAB"); break;
560 case WXK_RETURN: key = _T("RETURN"); break;
561 case WXK_ESCAPE: key = _T("ESCAPE"); break;
562 case WXK_SPACE: key = _T("SPACE"); break;
563 case WXK_DELETE: key = _T("DELETE"); break;
564 case WXK_START: key = _T("START"); break;
565 case WXK_LBUTTON: key = _T("LBUTTON"); break;
566 case WXK_RBUTTON: key = _T("RBUTTON"); break;
567 case WXK_CANCEL: key = _T("CANCEL"); break;
568 case WXK_MBUTTON: key = _T("MBUTTON"); break;
569 case WXK_CLEAR: key = _T("CLEAR"); break;
570 case WXK_SHIFT: key = _T("SHIFT"); break;
571 case WXK_ALT: key = _T("ALT"); break;
572 case WXK_CONTROL: key = _T("CONTROL"); break;
573 case WXK_MENU: key = _T("MENU"); break;
574 case WXK_PAUSE: key = _T("PAUSE"); break;
575 case WXK_CAPITAL: key = _T("CAPITAL"); break;
576 case WXK_END: key = _T("END"); break;
577 case WXK_HOME: key = _T("HOME"); break;
578 case WXK_LEFT: key = _T("LEFT"); break;
579 case WXK_UP: key = _T("UP"); break;
580 case WXK_RIGHT: key = _T("RIGHT"); break;
581 case WXK_DOWN: key = _T("DOWN"); break;
582 case WXK_SELECT: key = _T("SELECT"); break;
583 case WXK_PRINT: key = _T("PRINT"); break;
584 case WXK_EXECUTE: key = _T("EXECUTE"); break;
585 case WXK_SNAPSHOT: key = _T("SNAPSHOT"); break;
586 case WXK_INSERT: key = _T("INSERT"); break;
587 case WXK_HELP: key = _T("HELP"); break;
588 case WXK_NUMPAD0: key = _T("NUMPAD0"); break;
589 case WXK_NUMPAD1: key = _T("NUMPAD1"); break;
590 case WXK_NUMPAD2: key = _T("NUMPAD2"); break;
591 case WXK_NUMPAD3: key = _T("NUMPAD3"); break;
592 case WXK_NUMPAD4: key = _T("NUMPAD4"); break;
593 case WXK_NUMPAD5: key = _T("NUMPAD5"); break;
594 case WXK_NUMPAD6: key = _T("NUMPAD6"); break;
595 case WXK_NUMPAD7: key = _T("NUMPAD7"); break;
596 case WXK_NUMPAD8: key = _T("NUMPAD8"); break;
597 case WXK_NUMPAD9: key = _T("NUMPAD9"); break;
598 case WXK_MULTIPLY: key = _T("MULTIPLY"); break;
599 case WXK_ADD: key = _T("ADD"); break;
600 case WXK_SEPARATOR: key = _T("SEPARATOR"); break;
601 case WXK_SUBTRACT: key = _T("SUBTRACT"); break;
602 case WXK_DECIMAL: key = _T("DECIMAL"); break;
603 case WXK_DIVIDE: key = _T("DIVIDE"); break;
604 case WXK_F1: key = _T("F1"); break;
605 case WXK_F2: key = _T("F2"); break;
606 case WXK_F3: key = _T("F3"); break;
607 case WXK_F4: key = _T("F4"); break;
608 case WXK_F5: key = _T("F5"); break;
609 case WXK_F6: key = _T("F6"); break;
610 case WXK_F7: key = _T("F7"); break;
611 case WXK_F8: key = _T("F8"); break;
612 case WXK_F9: key = _T("F9"); break;
613 case WXK_F10: key = _T("F10"); break;
614 case WXK_F11: key = _T("F11"); break;
615 case WXK_F12: key = _T("F12"); break;
616 case WXK_F13: key = _T("F13"); break;
617 case WXK_F14: key = _T("F14"); break;
618 case WXK_F15: key = _T("F15"); break;
619 case WXK_F16: key = _T("F16"); break;
620 case WXK_F17: key = _T("F17"); break;
621 case WXK_F18: key = _T("F18"); break;
622 case WXK_F19: key = _T("F19"); break;
623 case WXK_F20: key = _T("F20"); break;
624 case WXK_F21: key = _T("F21"); break;
625 case WXK_F22: key = _T("F22"); break;
626 case WXK_F23: key = _T("F23"); break;
627 case WXK_F24: key = _T("F24"); break;
628 case WXK_NUMLOCK: key = _T("NUMLOCK"); break;
629 case WXK_SCROLL: key = _T("SCROLL"); break;
630 case WXK_PAGEUP: key = _T("PAGEUP"); break;
631 case WXK_PAGEDOWN: key = _T("PAGEDOWN"); break;
632 case WXK_NUMPAD_SPACE: key = _T("NUMPAD_SPACE"); break;
633 case WXK_NUMPAD_TAB: key = _T("NUMPAD_TAB"); break;
634 case WXK_NUMPAD_ENTER: key = _T("NUMPAD_ENTER"); break;
635 case WXK_NUMPAD_F1: key = _T("NUMPAD_F1"); break;
636 case WXK_NUMPAD_F2: key = _T("NUMPAD_F2"); break;
637 case WXK_NUMPAD_F3: key = _T("NUMPAD_F3"); break;
638 case WXK_NUMPAD_F4: key = _T("NUMPAD_F4"); break;
639 case WXK_NUMPAD_HOME: key = _T("NUMPAD_HOME"); break;
640 case WXK_NUMPAD_LEFT: key = _T("NUMPAD_LEFT"); break;
641 case WXK_NUMPAD_UP: key = _T("NUMPAD_UP"); break;
642 case WXK_NUMPAD_RIGHT: key = _T("NUMPAD_RIGHT"); break;
643 case WXK_NUMPAD_DOWN: key = _T("NUMPAD_DOWN"); break;
644 case WXK_NUMPAD_PAGEUP: key = _T("NUMPAD_PAGEUP"); break;
645 case WXK_NUMPAD_PAGEDOWN: key = _T("NUMPAD_PAGEDOWN"); break;
646 case WXK_NUMPAD_END: key = _T("NUMPAD_END"); break;
647 case WXK_NUMPAD_BEGIN: key = _T("NUMPAD_BEGIN"); break;
648 case WXK_NUMPAD_INSERT: key = _T("NUMPAD_INSERT"); break;
649 case WXK_NUMPAD_DELETE: key = _T("NUMPAD_DELETE"); break;
650 case WXK_NUMPAD_EQUAL: key = _T("NUMPAD_EQUAL"); break;
651 case WXK_NUMPAD_MULTIPLY: key = _T("NUMPAD_MULTIPLY"); break;
652 case WXK_NUMPAD_ADD: key = _T("NUMPAD_ADD"); break;
653 case WXK_NUMPAD_SEPARATOR: key = _T("NUMPAD_SEPARATOR"); break;
654 case WXK_NUMPAD_SUBTRACT: key = _T("NUMPAD_SUBTRACT"); break;
655 case WXK_NUMPAD_DECIMAL: key = _T("NUMPAD_DECIMAL"); break;
656
657 default:
658 {
659 if ( wxIsprint((int)keycode) )
660 key.Printf(_T("'%c'"), (char)keycode);
661 else if ( keycode > 0 && keycode < 27 )
662 key.Printf(_("Ctrl-%c"), _T('A') + keycode - 1);
663 else
664 key.Printf(_T("unknown (%ld)"), keycode);
665 }
666 }
667 }
668
669 #if wxUSE_UNICODE
670 key += wxString::Format(_T(" (Unicode: %#04x)"), event.GetUnicodeKey());
671 #endif // wxUSE_UNICODE
672
673 wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"),
674 name,
675 key.c_str(),
676 GetChar( event.ControlDown(), _T('C') ),
677 GetChar( event.AltDown(), _T('A') ),
678 GetChar( event.ShiftDown(), _T('S') ),
679 GetChar( event.MetaDown(), _T('M') ) );
680 }
681
682 static wxString GetMouseEventDesc(const wxMouseEvent& ev)
683 {
684 // click event
685 wxString button;
686 bool dbl, up;
687 if ( ev.LeftDown() || ev.LeftUp() || ev.LeftDClick() )
688 {
689 button = _T("Left");
690 dbl = ev.LeftDClick();
691 up = ev.LeftUp();
692 }
693 else if ( ev.MiddleDown() || ev.MiddleUp() || ev.MiddleDClick() )
694 {
695 button = _T("Middle");
696 dbl = ev.MiddleDClick();
697 up = ev.MiddleUp();
698 }
699 else if ( ev.RightDown() || ev.RightUp() || ev.RightDClick() )
700 {
701 button = _T("Right");
702 dbl = ev.RightDClick();
703 up = ev.RightUp();
704 }
705 else
706 {
707 return _T("Unknown mouse event");
708 }
709
710 return wxString::Format(_T("%s mouse button %s"),
711 button.c_str(),
712 dbl ? _T("double clicked")
713 : up ? _T("released") : _T("clicked"));
714 }
715
716 void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev)
717 {
718 ev.Skip();
719
720 if ( !ms_logMouse )
721 return;
722
723 if ( !ev.Moving() )
724 {
725 wxString msg;
726 if ( ev.Entering() )
727 {
728 msg = _T("Mouse entered the window");
729 }
730 else if ( ev.Leaving() )
731 {
732 msg = _T("Mouse left the window");
733 }
734 else
735 {
736 msg = GetMouseEventDesc(ev);
737 }
738
739 msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ");
740
741 long pos;
742 wxTextCtrlHitTestResult rc = HitTest(ev.GetPosition(), &pos);
743 if ( rc != wxTE_HT_UNKNOWN )
744 {
745 msg << _T("at position ") << pos << _T(' ');
746 }
747
748 msg << _T("[Flags: ")
749 << GetChar( ev.LeftIsDown(), _T('1') )
750 << GetChar( ev.MiddleIsDown(), _T('2') )
751 << GetChar( ev.RightIsDown(), _T('3') )
752 << GetChar( ev.ControlDown(), _T('C') )
753 << GetChar( ev.AltDown(), _T('A') )
754 << GetChar( ev.ShiftDown(), _T('S') )
755 << GetChar( ev.MetaDown(), _T('M') )
756 << _T(']');
757
758 wxLogMessage(msg);
759 }
760 //else: we're not interested in mouse move events
761 }
762
763 void MyTextCtrl::OnSetFocus(wxFocusEvent& event)
764 {
765 if ( ms_logFocus )
766 wxLogMessage( wxT("%p got focus."), this);
767
768 event.Skip();
769 }
770
771 void MyTextCtrl::OnKillFocus(wxFocusEvent& event)
772 {
773 if ( ms_logFocus )
774 wxLogMessage( wxT("%p lost focus"), this);
775
776 event.Skip();
777 }
778
779 void MyTextCtrl::OnText(wxCommandEvent& event)
780 {
781 if ( !ms_logText )
782 return;
783
784 MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
785 const wxChar *changeVerb = win->IsModified() ? _T("changed")
786 : _T("set by program");
787 const wxChar *data = (const wxChar *)(win->GetClientData());
788 if ( data )
789 {
790 wxLogMessage(_T("Text %s in control \"%s\""), changeVerb, data);
791 }
792 else
793 {
794 wxLogMessage(_T("Text %s in some control"), changeVerb);
795 }
796 }
797
798 void MyTextCtrl::OnTextEnter(wxCommandEvent& event)
799 {
800 if ( !ms_logText )
801 return;
802
803 MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
804 const wxChar *data = (const wxChar *)(win->GetClientData());
805 if ( data )
806 {
807 wxLogMessage(_T("Enter pressed in control '%s'"), data);
808 }
809 else
810 {
811 wxLogMessage(_T("Enter pressed in some control"));
812 }
813 }
814
815 void MyTextCtrl::OnTextMaxLen(wxCommandEvent& WXUNUSED(event))
816 {
817 wxLogMessage(_T("You can't enter more characters into this control."));
818 }
819
820
821 void MyTextCtrl::OnTextCut(wxClipboardTextEvent& event)
822 {
823 LogClipEvent(_T("cut to"), event);
824 }
825
826 void MyTextCtrl::OnTextCopy(wxClipboardTextEvent& event)
827 {
828 LogClipEvent(_T("copied to"), event);
829 }
830
831 void MyTextCtrl::OnTextPaste(wxClipboardTextEvent& event)
832 {
833 LogClipEvent(_T("pasted from"), event);
834 }
835
836 void MyTextCtrl::LogClipEvent(const wxChar *what, wxClipboardTextEvent& event)
837 {
838 wxFrame *frame = wxDynamicCast(wxGetTopLevelParent(this), wxFrame);
839 wxCHECK_RET( frame, _T("no parent frame?") );
840
841 const bool veto = frame->GetMenuBar()->IsChecked(TEXT_CLIPBOARD_VETO);
842 if ( !veto )
843 event.Skip();
844
845 if ( ms_logClip )
846 {
847 wxLogMessage(_T("Text %s%s the clipboard."),
848 veto ? _T("not ") : _T(""), what);
849 }
850 }
851
852
853 void MyTextCtrl::OnTextURL(wxTextUrlEvent& event)
854 {
855 const wxMouseEvent& ev = event.GetMouseEvent();
856
857 // filter out mouse moves, too many of them
858 if ( ev.Moving() )
859 return;
860
861 long start = event.GetURLStart(),
862 end = event.GetURLEnd();
863
864 wxLogMessage(_T("Mouse event over URL '%s': %s"),
865 GetValue().Mid(start, end - start).c_str(),
866 GetMouseEventDesc(ev).c_str());
867 }
868
869 void MyTextCtrl::OnChar(wxKeyEvent& event)
870 {
871 if ( ms_logChar )
872 LogKeyEvent( _T("Char"), event);
873
874 event.Skip();
875 }
876
877 void MyTextCtrl::OnKeyUp(wxKeyEvent& event)
878 {
879 if ( ms_logKey )
880 LogKeyEvent( _T("Key up"), event);
881
882 event.Skip();
883 }
884
885 void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
886 {
887 switch ( event.GetKeyCode() )
888 {
889 case WXK_F1:
890 // show current position and text length
891 {
892 long line, column, pos = GetInsertionPoint();
893 PositionToXY(pos, &column, &line);
894
895 wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
896 pos,
897 line, column,
898 (long) GetNumberOfLines(),
899 (long) GetLineLength(line),
900 (unsigned int) GetValue().length(),
901 GetLastPosition());
902
903 long from, to;
904 GetSelection(&from, &to);
905
906 wxString sel = GetStringSelection();
907
908 wxLogMessage(_T("Selection: from %ld to %ld."), from, to);
909 wxLogMessage(_T("Selection = '%s' (len = %u)"),
910 sel.c_str(),
911 (unsigned int) sel.length());
912 }
913 break;
914
915 case WXK_F2:
916 // go to the end
917 SetInsertionPointEnd();
918 break;
919
920 case WXK_F3:
921 // go to position 10
922 SetInsertionPoint(10);
923 break;
924
925 case WXK_F4:
926 if (!m_hasCapture)
927 {
928 wxLogDebug( wxT("Now capturing mouse and events.") );
929 m_hasCapture = true;
930 CaptureMouse();
931 }
932 else
933 {
934 wxLogDebug( wxT("Stopped capturing mouse and events.") );
935 m_hasCapture = false;
936 ReleaseMouse();
937 }
938 break;
939
940 case WXK_F5:
941 // insert a blank line
942 WriteText(_T("\n"));
943 break;
944
945 case WXK_F6:
946 wxLogMessage(_T("IsModified() before SetValue(): %d"),
947 IsModified());
948 SetValue(_T("SetValue() has been called"));
949 wxLogMessage(_T("IsModified() after SetValue(): %d"),
950 IsModified());
951 break;
952
953 case WXK_F7:
954 wxLogMessage(_T("Position 10 should be now visible."));
955 ShowPosition(10);
956 break;
957
958 case WXK_F8:
959 wxLogMessage(_T("Control has been cleared"));
960 Clear();
961 break;
962
963 case WXK_F9:
964 WriteText(_T("WriteText() has been called"));
965 break;
966
967 case WXK_F10:
968 AppendText(_T("AppendText() has been called"));
969 break;
970 }
971
972 if ( ms_logKey )
973 LogKeyEvent( wxT("Key down"), event);
974
975 event.Skip();
976 }
977
978 //----------------------------------------------------------------------
979 // MyPanel
980 //----------------------------------------------------------------------
981
982 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
983 : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
984 {
985 #if wxUSE_LOG
986 m_log = new wxTextCtrl( this, wxID_ANY, _T("This is the log window.\n"),
987 wxPoint(5,260), wxSize(630,100),
988 wxTE_MULTILINE | wxTE_READONLY /* | wxTE_RICH */);
989
990 m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
991 #endif // wxUSE_LOG
992
993 // single line text controls
994
995 m_text = new MyTextCtrl( this, wxID_ANY, _T("Single line."),
996 wxDefaultPosition, wxDefaultSize,
997 wxTE_PROCESS_ENTER);
998 m_text->SetForegroundColour(*wxBLUE);
999 m_text->SetBackgroundColour(*wxLIGHT_GREY);
1000 (*m_text) << _T(" Appended.");
1001 m_text->SetInsertionPoint(0);
1002 m_text->WriteText( _T("Prepended. ") );
1003
1004 m_password = new MyTextCtrl( this, wxID_ANY, _T(""),
1005 wxPoint(10,50), wxSize(140,wxDefaultCoord), wxTE_PASSWORD );
1006
1007 m_readonly = new MyTextCtrl( this, wxID_ANY, _T("Read only"),
1008 wxPoint(10,90), wxSize(140,wxDefaultCoord), wxTE_READONLY );
1009
1010 m_limited = new MyTextCtrl(this, wxID_ANY, _T("Max 8 ch"),
1011 wxPoint(10, 130), wxSize(140, wxDefaultCoord));
1012 m_limited->SetMaxLength(8);
1013
1014 // multi line text controls
1015
1016 m_horizontal = new MyTextCtrl( this, wxID_ANY, _T("Multiline text control with a horizontal scrollbar.\n"),
1017 wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL);
1018
1019 // a little hack to use the command line argument for encoding testing
1020 if ( wxTheApp->argc == 2 )
1021 {
1022 switch ( wxTheApp->argv[1][0] )
1023 {
1024 case '2':
1025 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
1026 false, _T(""),
1027 wxFONTENCODING_ISO8859_2));
1028 m_horizontal->AppendText(_T("\256lu\273ou\350k\375 k\371\362 zb\354sile \350e\271tina \253\273"));
1029 break;
1030
1031 case '1':
1032 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
1033 false, _T(""),
1034 wxFONTENCODING_CP1251));
1035 m_horizontal->AppendText(_T("\317\360\350\342\345\362!"));
1036 break;
1037
1038 case '8':
1039 m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
1040 false, _T(""),
1041 wxFONTENCODING_CP1251));
1042 #if wxUSE_UNICODE
1043 m_horizontal->AppendText(L"\x0412\x0430\x0434\x0438\x043c \x0426");
1044 #else
1045 m_horizontal->AppendText("\313\301\326\305\324\323\321 \325\304\301\336\316\331\315");
1046 #endif
1047 }
1048 }
1049 else
1050 {
1051 m_horizontal->AppendText(_T("Text in default encoding"));
1052 }
1053
1054 m_multitext = new MyTextCtrl( this, wxID_ANY, _T("Multi line."),
1055 wxPoint(180,10), wxSize(200,70), wxTE_MULTILINE );
1056 m_multitext->SetFont(*wxITALIC_FONT);
1057 (*m_multitext) << _T(" Appended.");
1058 m_multitext->SetInsertionPoint(0);
1059 m_multitext->WriteText( _T("Prepended. ") );
1060 m_multitext->SetForegroundColour(*wxRED);
1061 m_multitext->SetBackgroundColour(*wxLIGHT_GREY);
1062
1063 #if wxUSE_TOOLTIPS
1064 m_multitext->SetToolTip(_T("Press Fn function keys here"));
1065 #endif
1066
1067 m_tab = new MyTextCtrl( this, 100, _T("Multiline, allow <TAB> processing."),
1068 wxPoint(180,90), wxSize(200,70), wxTE_MULTILINE | wxTE_PROCESS_TAB );
1069 m_tab->SetClientData((void *)_T("tab"));
1070
1071 m_enter = new MyTextCtrl( this, 100, _T("Multiline, allow <ENTER> processing."),
1072 wxPoint(180,170), wxSize(200,70), wxTE_MULTILINE);
1073 m_enter->SetClientData((void *)_T("enter"));
1074
1075 m_textrich = new MyTextCtrl(this, wxID_ANY, _T("Allows more than 30Kb of text\n")
1076 _T("(even under broken Win9x)\n")
1077 _T("and a very very very very very ")
1078 _T("very very very long line to test ")
1079 _T("wxHSCROLL style\n")
1080 _T("\nAnd here is a link in quotation marks to ")
1081 _T("test wxTE_AUTO_URL: \"http://www.wxwidgets.org\""),
1082 wxPoint(450, 10), wxSize(200, 230),
1083 wxTE_RICH | wxTE_MULTILINE | wxTE_AUTO_URL);
1084 m_textrich->SetStyle(0, 10, *wxRED);
1085 m_textrich->SetStyle(10, 20, *wxBLUE);
1086 m_textrich->SetStyle(30, 40,
1087 wxTextAttr(*wxGREEN, wxNullColour, *wxITALIC_FONT));
1088 m_textrich->SetDefaultStyle(wxTextAttr());
1089 m_textrich->AppendText(_T("\n\nFirst 10 characters should be in red\n"));
1090 m_textrich->AppendText(_T("Next 10 characters should be in blue\n"));
1091 m_textrich->AppendText(_T("Next 10 characters should be normal\n"));
1092 m_textrich->AppendText(_T("And the next 10 characters should be green and italic\n"));
1093 m_textrich->SetDefaultStyle(wxTextAttr(*wxCYAN, *wxBLUE));
1094 m_textrich->AppendText(_T("This text should be cyan on blue\n"));
1095 m_textrich->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE));
1096 m_textrich->AppendText(_T("And this should be in blue and the text you ")
1097 _T("type should be in blue as well"));
1098
1099
1100 // lay out the controls
1101 wxBoxSizer *column1 = new wxBoxSizer(wxVERTICAL);
1102 column1->Add( m_text, 0, wxALL | wxEXPAND, 10 );
1103 column1->Add( m_password, 0, wxALL | wxEXPAND, 10 );
1104 column1->Add( m_readonly, 0, wxALL | wxEXPAND, 10 );
1105 column1->Add( m_limited, 0, wxALL | wxEXPAND, 10 );
1106 column1->Add( m_horizontal, 1, wxALL | wxEXPAND, 10 );
1107
1108 wxBoxSizer *column2 = new wxBoxSizer(wxVERTICAL);
1109 column2->Add( m_multitext, 1, wxALL | wxEXPAND, 10 );
1110 column2->Add( m_tab, 1, wxALL | wxEXPAND, 10 );
1111 column2->Add( m_enter, 1, wxALL | wxEXPAND, 10 );
1112
1113 wxBoxSizer *row1 = new wxBoxSizer(wxHORIZONTAL);
1114 row1->Add( column1, 0, wxALL | wxEXPAND, 10 );
1115 row1->Add( column2, 1, wxALL | wxEXPAND, 10 );
1116 row1->Add( m_textrich, 1, wxALL | wxEXPAND, 10 );
1117
1118 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
1119 topSizer->Add( row1, 2, wxALL | wxEXPAND, 10 );
1120
1121 #if wxUSE_LOG
1122 topSizer->Add( m_log, 1, wxALL | wxEXPAND, 10 );
1123 #endif
1124
1125 SetAutoLayout( true );
1126 SetSizer(topSizer);
1127 }
1128
1129 wxTextCtrl *MyPanel::GetFocusedText() const
1130 {
1131 wxWindow *win = FindFocus();
1132
1133 wxTextCtrl *text = win ? wxDynamicCast(win, wxTextCtrl) : NULL;
1134 return text ? text : m_multitext;
1135 }
1136
1137 #if wxUSE_CLIPBOARD
1138 void MyPanel::DoPasteFromClipboard()
1139 {
1140 // On X11, we want to get the data from the primary selection instead
1141 // of the normal clipboard (which isn't normal under X11 at all). This
1142 // call has no effect under MSW.
1143 wxTheClipboard->UsePrimarySelection();
1144
1145 if (!wxTheClipboard->Open())
1146 {
1147 #if wxUSE_LOG
1148 *m_log << _T("Error opening the clipboard.\n");
1149 #endif // wxUSE_LOG
1150 return;
1151 }
1152 else
1153 {
1154 #if wxUSE_LOG
1155 *m_log << _T("Successfully opened the clipboard.\n");
1156 #endif // wxUSE_LOG
1157 }
1158
1159 wxTextDataObject data;
1160
1161 if (wxTheClipboard->IsSupported( data.GetFormat() ))
1162 {
1163 #if wxUSE_LOG
1164 *m_log << _T("Clipboard supports requested format.\n");
1165 #endif // wxUSE_LOG
1166
1167 if (wxTheClipboard->GetData( data ))
1168 {
1169 #if wxUSE_LOG
1170 *m_log << _T("Successfully retrieved data from the clipboard.\n");
1171 #endif // wxUSE_LOG
1172 GetFocusedText()->AppendText(data.GetText());
1173 }
1174 else
1175 {
1176 #if wxUSE_LOG
1177 *m_log << _T("Error getting data from the clipboard.\n");
1178 #endif // wxUSE_LOG
1179 }
1180 }
1181 else
1182 {
1183 #if wxUSE_LOG
1184 *m_log << _T("Clipboard doesn't support requested format.\n");
1185 #endif // wxUSE_LOG
1186 }
1187
1188 wxTheClipboard->Close();
1189
1190 #if wxUSE_LOG
1191 *m_log << _T("Closed the clipboard.\n");
1192 #endif // wxUSE_LOG
1193 }
1194
1195 void MyPanel::DoCopyToClipboard()
1196 {
1197 // On X11, we want to get the data from the primary selection instead
1198 // of the normal clipboard (which isn't normal under X11 at all). This
1199 // call has no effect under MSW.
1200 wxTheClipboard->UsePrimarySelection();
1201
1202 wxString text( GetFocusedText()->GetStringSelection() );
1203
1204 if (text.IsEmpty())
1205 {
1206 #if wxUSE_LOG
1207 *m_log << _T("No text to copy.\n");
1208 #endif // wxUSE_LOG
1209
1210 return;
1211 }
1212
1213 if (!wxTheClipboard->Open())
1214 {
1215 #if wxUSE_LOG
1216 *m_log << _T("Error opening the clipboard.\n");
1217 #endif // wxUSE_LOG
1218
1219 return;
1220 }
1221 else
1222 {
1223 #if wxUSE_LOG
1224 *m_log << _T("Successfully opened the clipboard.\n");
1225 #endif // wxUSE_LOG
1226 }
1227
1228 wxTextDataObject *data = new wxTextDataObject( text );
1229
1230 if (!wxTheClipboard->SetData( data ))
1231 {
1232 #if wxUSE_LOG
1233 *m_log << _T("Error while copying to the clipboard.\n");
1234 #endif // wxUSE_LOG
1235 }
1236 else
1237 {
1238 #if wxUSE_LOG
1239 *m_log << _T("Successfully copied data to the clipboard.\n");
1240 #endif // wxUSE_LOG
1241 }
1242
1243 wxTheClipboard->Close();
1244
1245 #if wxUSE_LOG
1246 *m_log << _T("Closed the clipboard.\n");
1247 #endif // wxUSE_LOG
1248 }
1249
1250 #endif // wxUSE_CLIPBOARD
1251
1252 void MyPanel::DoMoveToEndOfText()
1253 {
1254 m_multitext->SetInsertionPointEnd();
1255 m_multitext->SetFocus();
1256 }
1257
1258 void MyPanel::DoMoveToEndOfEntry()
1259 {
1260 m_text->SetInsertionPointEnd();
1261 m_text->SetFocus();
1262 }
1263
1264 void MyPanel::DoRemoveText()
1265 {
1266 GetFocusedText()->Remove(0, 10);
1267 }
1268
1269 void MyPanel::DoReplaceText()
1270 {
1271 GetFocusedText()->Replace(3, 8, _T("ABC"));
1272 }
1273
1274 void MyPanel::DoSelectText()
1275 {
1276 GetFocusedText()->SetSelection(3, 8);
1277 }
1278
1279 //----------------------------------------------------------------------
1280 // MyFrame
1281 //----------------------------------------------------------------------
1282
1283 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1284 EVT_MENU(TEXT_QUIT, MyFrame::OnQuit)
1285 EVT_MENU(TEXT_ABOUT, MyFrame::OnAbout)
1286 EVT_MENU(TEXT_SAVE, MyFrame::OnFileSave)
1287 EVT_MENU(TEXT_LOAD, MyFrame::OnFileLoad)
1288 EVT_MENU(TEXT_RICH_TEXT_TEST, MyFrame::OnRichTextTest)
1289
1290 EVT_MENU(TEXT_LOG_KEY, MyFrame::OnLogKey)
1291 EVT_MENU(TEXT_LOG_CHAR, MyFrame::OnLogChar)
1292 EVT_MENU(TEXT_LOG_MOUSE,MyFrame::OnLogMouse)
1293 EVT_MENU(TEXT_LOG_TEXT, MyFrame::OnLogText)
1294 EVT_MENU(TEXT_LOG_FOCUS,MyFrame::OnLogFocus)
1295 EVT_MENU(TEXT_LOG_CLIP, MyFrame::OnLogClip)
1296 #if wxUSE_LOG
1297 EVT_MENU(TEXT_CLEAR, MyFrame::OnLogClear)
1298 #endif // wxUSE_LOG
1299
1300 #if wxUSE_TOOLTIPS
1301 EVT_MENU(TEXT_TOOLTIPS_SETDELAY, MyFrame::OnSetTooltipDelay)
1302 EVT_MENU(TEXT_TOOLTIPS_ENABLE, MyFrame::OnToggleTooltips)
1303 #endif // wxUSE_TOOLTIPS
1304
1305 #if wxUSE_CLIPBOARD
1306 EVT_MENU(TEXT_CLIPBOARD_PASTE, MyFrame::OnPasteFromClipboard)
1307 EVT_MENU(TEXT_CLIPBOARD_COPY, MyFrame::OnCopyToClipboard)
1308
1309 EVT_UPDATE_UI(TEXT_CLIPBOARD_PASTE, MyFrame::OnUpdatePasteFromClipboard)
1310 EVT_UPDATE_UI(TEXT_CLIPBOARD_COPY, MyFrame::OnUpdateCopyToClipboard)
1311 #endif // wxUSE_CLIPBOARD
1312
1313 EVT_MENU(TEXT_REMOVE, MyFrame::OnRemoveText)
1314 EVT_MENU(TEXT_REPLACE, MyFrame::OnReplaceText)
1315 EVT_MENU(TEXT_SELECT, MyFrame::OnSelectText)
1316 EVT_MENU(TEXT_ADD_SOME, MyFrame::OnAddText)
1317 EVT_MENU(TEXT_ADD_FREEZE, MyFrame::OnAddTextFreeze)
1318 EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText)
1319 EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry)
1320
1321 EVT_MENU(TEXT_SET_EDITABLE, MyFrame::OnSetEditable)
1322 EVT_MENU(TEXT_SET_ENABLED, MyFrame::OnSetEnabled)
1323
1324 EVT_MENU(TEXT_LINE_DOWN, MyFrame::OnScrollLineDown)
1325 EVT_MENU(TEXT_LINE_UP, MyFrame::OnScrollLineUp)
1326 EVT_MENU(TEXT_PAGE_DOWN, MyFrame::OnScrollPageDown)
1327 EVT_MENU(TEXT_PAGE_UP, MyFrame::OnScrollPageUp)
1328
1329 EVT_MENU(TEXT_GET_LINE, MyFrame::OnGetLine)
1330 EVT_MENU(TEXT_GET_LINELENGTH, MyFrame::OnGetLineLength)
1331
1332 EVT_MENU(TEXT_SET, MyFrame::OnSetText)
1333
1334 EVT_IDLE(MyFrame::OnIdle)
1335 END_EVENT_TABLE()
1336
1337 MyFrame::MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h)
1338 : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h) )
1339 {
1340 #if wxUSE_STATUSBAR
1341 CreateStatusBar(2);
1342 #endif // wxUSE_STATUSBAR
1343
1344 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1345 }
1346
1347 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1348 {
1349 Close(true);
1350 }
1351
1352 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1353 {
1354 wxBeginBusyCursor();
1355
1356 wxMessageDialog dialog(this,
1357 _T("This is a text control sample. It demonstrates the many different\n")
1358 _T("text control styles, the use of the clipboard, setting and handling\n")
1359 _T("tooltips and intercepting key and char events.\n")
1360 _T("\n")
1361 _T("Copyright (c) 1999, Robert Roebling, Julian Smart, Vadim Zeitlin"),
1362 _T("About wxTextCtrl Sample"),
1363 wxOK | wxICON_INFORMATION);
1364
1365 dialog.ShowModal();
1366
1367 wxEndBusyCursor();
1368 }
1369
1370 #if wxUSE_TOOLTIPS
1371
1372 void MyFrame::OnSetTooltipDelay(wxCommandEvent& WXUNUSED(event))
1373 {
1374 static long s_delay = 5000;
1375
1376 wxString delay;
1377 delay.Printf( _T("%ld"), s_delay);
1378
1379 delay = wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1380 _T("Set tooltip delay"),
1381 delay,
1382 this);
1383 if ( !delay )
1384 return; // cancelled
1385
1386 wxSscanf(delay, _T("%ld"), &s_delay);
1387
1388 wxToolTip::SetDelay(s_delay);
1389
1390 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1391 }
1392
1393 void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
1394 {
1395 static bool s_enabled = true;
1396
1397 s_enabled = !s_enabled;
1398
1399 wxToolTip::Enable(s_enabled);
1400
1401 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1402 }
1403 #endif // tooltips
1404
1405 #if wxUSE_LOG
1406 void MyFrame::OnLogClear(wxCommandEvent& WXUNUSED(event))
1407 {
1408 m_panel->m_log->Clear();
1409 }
1410 #endif // wxUSE_LOG
1411
1412 void MyFrame::OnSetEditable(wxCommandEvent& WXUNUSED(event))
1413 {
1414 static bool s_editable = true;
1415
1416 s_editable = !s_editable;
1417 m_panel->m_text->SetEditable(s_editable);
1418 m_panel->m_password->SetEditable(s_editable);
1419 m_panel->m_multitext->SetEditable(s_editable);
1420 m_panel->m_textrich->SetEditable(s_editable);
1421 }
1422
1423 void MyFrame::OnSetEnabled(wxCommandEvent& WXUNUSED(event))
1424 {
1425 bool enabled = m_panel->m_text->IsEnabled();
1426 enabled = !enabled;
1427
1428 m_panel->m_text->Enable(enabled);
1429 m_panel->m_password->Enable(enabled);
1430 m_panel->m_multitext->Enable(enabled);
1431 m_panel->m_readonly->Enable(enabled);
1432 m_panel->m_limited->Enable(enabled);
1433 m_panel->m_textrich->Enable(enabled);
1434 }
1435
1436 void MyFrame::OnFileSave(wxCommandEvent& WXUNUSED(event))
1437 {
1438 if ( m_panel->m_textrich->SaveFile(_T("dummy.txt")) )
1439 {
1440 #if wxUSE_FILE
1441 // verify that the fil length is correct (it wasn't under Win95)
1442 wxFile file(wxT("dummy.txt"));
1443 wxLogStatus(this,
1444 _T("Successfully saved file (text len = %lu, file size = %ld)"),
1445 (unsigned long)m_panel->m_textrich->GetValue().length(),
1446 (long) file.Length());
1447 #endif
1448 }
1449 else
1450 wxLogStatus(this, _T("Couldn't save the file"));
1451 }
1452
1453 void MyFrame::OnFileLoad(wxCommandEvent& WXUNUSED(event))
1454 {
1455 if ( m_panel->m_textrich->LoadFile(_T("dummy.txt")) )
1456 wxLogStatus(this, _T("Successfully loaded file"));
1457 else
1458 wxLogStatus(this, _T("Couldn't load the file"));
1459 }
1460
1461 void MyFrame::OnRichTextTest(wxCommandEvent& WXUNUSED(event))
1462 {
1463 RichTextFrame* frame = new RichTextFrame(this, _T("Rich Text Editor"));
1464 frame->Show(true);
1465 }
1466
1467 void MyFrame::OnIdle( wxIdleEvent& event )
1468 {
1469 // track the window which has the focus in the status bar
1470 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1471 wxWindow *focus = wxWindow::FindFocus();
1472 if ( focus && (focus != s_windowFocus) )
1473 {
1474 s_windowFocus = focus;
1475
1476 wxString msg;
1477 msg.Printf(
1478 #ifdef __WXMSW__
1479 _T("Focus: wxWindow = %p, HWND = %08x"),
1480 #else
1481 _T("Focus: wxWindow = %p"),
1482 #endif
1483 s_windowFocus
1484 #ifdef __WXMSW__
1485 , (unsigned int) s_windowFocus->GetHWND()
1486 #endif
1487 );
1488
1489 #if wxUSE_STATUSBAR
1490 SetStatusText(msg);
1491 #endif // wxUSE_STATUSBAR
1492 }
1493 event.Skip();
1494 }
1495
1496 /*
1497 * RichTextFrame is used to demonstrate rich text behaviour
1498 */
1499
1500 enum
1501 {
1502 RICHTEXT_CLOSE = 1000,
1503 RICHTEXT_LEFT_ALIGN,
1504 RICHTEXT_RIGHT_ALIGN,
1505 RICHTEXT_CENTRE,
1506 RICHTEXT_JUSTIFY,
1507 RICHTEXT_CHANGE_FONT,
1508 RICHTEXT_CHANGE_TEXT_COLOUR,
1509 RICHTEXT_CHANGE_BACKGROUND_COLOUR,
1510 RICHTEXT_LEFT_INDENT,
1511 RICHTEXT_RIGHT_INDENT
1512 };
1513
1514 BEGIN_EVENT_TABLE(RichTextFrame, wxFrame)
1515 EVT_IDLE(RichTextFrame::OnIdle)
1516 EVT_MENU(RICHTEXT_CLOSE, RichTextFrame::OnClose)
1517 EVT_MENU(RICHTEXT_LEFT_ALIGN, RichTextFrame::OnLeftAlign)
1518 EVT_MENU(RICHTEXT_RIGHT_ALIGN, RichTextFrame::OnRightAlign)
1519 EVT_MENU(RICHTEXT_CENTRE, RichTextFrame::OnCentre)
1520 EVT_MENU(RICHTEXT_JUSTIFY, RichTextFrame::OnJustify)
1521 EVT_MENU(RICHTEXT_CHANGE_FONT, RichTextFrame::OnChangeFont)
1522 EVT_MENU(RICHTEXT_CHANGE_TEXT_COLOUR, RichTextFrame::OnChangeTextColour)
1523 EVT_MENU(RICHTEXT_CHANGE_BACKGROUND_COLOUR, RichTextFrame::OnChangeBackgroundColour)
1524 EVT_MENU(RICHTEXT_LEFT_INDENT, RichTextFrame::OnLeftIndent)
1525 EVT_MENU(RICHTEXT_RIGHT_INDENT, RichTextFrame::OnRightIndent)
1526 END_EVENT_TABLE()
1527
1528 RichTextFrame::RichTextFrame(wxWindow* parent, const wxString& title):
1529 wxFrame(parent, wxID_ANY, title, wxDefaultPosition, wxSize(300, 400))
1530 {
1531 m_currentPosition = -1;
1532 m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
1533 wxDefaultSize, wxTE_MULTILINE|wxTE_RICH2);
1534
1535 wxString value;
1536 int i;
1537 for (i = 0; i < 10; i++)
1538 {
1539 int j;
1540 for (j = 0; j < 10; j++)
1541 {
1542 value << wxT("Hello, welcome to a very simple rich text editor. You can set some character and paragraph styles from the Edit menu. ");
1543 }
1544 value << wxT("\n\n");
1545 }
1546 m_textCtrl->SetValue(value);
1547
1548 wxMenuBar* menuBar = new wxMenuBar;
1549 wxMenu* fileMenu = new wxMenu;
1550 fileMenu->Append(RICHTEXT_CLOSE, _("Close\tCtrl+W"));
1551 menuBar->Append(fileMenu, _("File"));
1552
1553 wxMenu* editMenu = new wxMenu;
1554 editMenu->Append(RICHTEXT_LEFT_ALIGN, _("Left Align"));
1555 editMenu->Append(RICHTEXT_RIGHT_ALIGN, _("Right Align"));
1556 editMenu->Append(RICHTEXT_CENTRE, _("Centre"));
1557 editMenu->Append(RICHTEXT_JUSTIFY, _("Justify"));
1558 editMenu->AppendSeparator();
1559 editMenu->Append(RICHTEXT_CHANGE_FONT, _("Change Font"));
1560 editMenu->Append(RICHTEXT_CHANGE_TEXT_COLOUR, _("Change Text Colour"));
1561 editMenu->Append(RICHTEXT_CHANGE_BACKGROUND_COLOUR, _("Change Background Colour"));
1562 editMenu->AppendSeparator();
1563 editMenu->Append(RICHTEXT_LEFT_INDENT, _("Left Indent"));
1564 editMenu->Append(RICHTEXT_RIGHT_INDENT, _("Right indent"));
1565 menuBar->Append(editMenu, _("Edit"));
1566
1567 SetMenuBar(menuBar);
1568 #if wxUSE_STATUSBAR
1569 CreateStatusBar();
1570 #endif // wxUSE_STATUSBAR
1571 }
1572
1573 // Event handlers
1574
1575 void RichTextFrame::OnClose(wxCommandEvent& WXUNUSED(event))
1576 {
1577 Close(true);
1578 }
1579
1580 void RichTextFrame::OnLeftAlign(wxCommandEvent& WXUNUSED(event))
1581 {
1582 wxTextAttr attr;
1583 attr.SetAlignment(wxTEXT_ALIGNMENT_LEFT);
1584
1585 long start, end;
1586 m_textCtrl->GetSelection(& start, & end);
1587 m_textCtrl->SetStyle(start, end, attr);
1588
1589 m_currentPosition = -1;
1590 }
1591
1592 void RichTextFrame::OnRightAlign(wxCommandEvent& WXUNUSED(event))
1593 {
1594 wxTextAttr attr;
1595 attr.SetAlignment(wxTEXT_ALIGNMENT_RIGHT);
1596
1597 long start, end;
1598 m_textCtrl->GetSelection(& start, & end);
1599 m_textCtrl->SetStyle(start, end, attr);
1600
1601 m_currentPosition = -1;
1602 }
1603
1604 void RichTextFrame::OnJustify(wxCommandEvent& WXUNUSED(event))
1605 {
1606 wxTextAttr attr;
1607 attr.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED);
1608
1609 long start, end;
1610 m_textCtrl->GetSelection(& start, & end);
1611 m_textCtrl->SetStyle(start, end, attr);
1612
1613 m_currentPosition = -1;
1614 }
1615
1616 void RichTextFrame::OnCentre(wxCommandEvent& WXUNUSED(event))
1617 {
1618 wxTextAttr attr;
1619 attr.SetAlignment(wxTEXT_ALIGNMENT_CENTRE);
1620
1621 long start, end;
1622 m_textCtrl->GetSelection(& start, & end);
1623 m_textCtrl->SetStyle(start, end, attr);
1624
1625 m_currentPosition = -1;
1626 }
1627
1628 void RichTextFrame::OnChangeFont(wxCommandEvent& WXUNUSED(event))
1629 {
1630 wxFontData data;
1631
1632 wxFontDialog dialog(this, data);
1633
1634 if (dialog.ShowModal() == wxID_OK)
1635 {
1636 wxFontData retData = dialog.GetFontData();
1637 wxFont font = retData.GetChosenFont();
1638
1639 wxTextAttr attr;
1640 attr.SetFont(font);
1641
1642 long start, end;
1643 m_textCtrl->GetSelection(& start, & end);
1644 m_textCtrl->SetStyle(start, end, attr);
1645
1646 m_currentPosition = -1;
1647 }
1648 }
1649
1650 void RichTextFrame::OnChangeTextColour(wxCommandEvent& WXUNUSED(event))
1651 {
1652 wxColourData data;
1653 data.SetColour(* wxBLACK);
1654 data.SetChooseFull(true);
1655 for (int i = 0; i < 16; i++)
1656 {
1657 wxColour colour((unsigned char)(i*16), (unsigned char)(i*16), (unsigned char)(i*16));
1658 data.SetCustomColour(i, colour);
1659 }
1660
1661 wxColourDialog dialog(this, &data);
1662 dialog.SetTitle(_T("Choose the text colour"));
1663 if (dialog.ShowModal() == wxID_OK)
1664 {
1665 wxColourData retData = dialog.GetColourData();
1666 wxColour col = retData.GetColour();
1667
1668 wxTextAttr attr;
1669 attr.SetTextColour(col);
1670
1671 long start, end;
1672 m_textCtrl->GetSelection(& start, & end);
1673 m_textCtrl->SetStyle(start, end, attr);
1674
1675 m_currentPosition = -1;
1676 }
1677 }
1678
1679 void RichTextFrame::OnChangeBackgroundColour(wxCommandEvent& WXUNUSED(event))
1680 {
1681 wxColourData data;
1682 data.SetColour(* wxWHITE);
1683 data.SetChooseFull(true);
1684 for (int i = 0; i < 16; i++)
1685 {
1686 wxColour colour((unsigned char)(i*16), (unsigned char)(i*16), (unsigned char)(i*16));
1687 data.SetCustomColour(i, colour);
1688 }
1689
1690 wxColourDialog dialog(this, &data);
1691 dialog.SetTitle(_T("Choose the text background colour"));
1692 if (dialog.ShowModal() == wxID_OK)
1693 {
1694 wxColourData retData = dialog.GetColourData();
1695 wxColour col = retData.GetColour();
1696
1697 wxTextAttr attr;
1698 attr.SetBackgroundColour(col);
1699
1700 long start, end;
1701 m_textCtrl->GetSelection(& start, & end);
1702 m_textCtrl->SetStyle(start, end, attr);
1703
1704 m_currentPosition = -1;
1705 }
1706 }
1707
1708 void RichTextFrame::OnLeftIndent(wxCommandEvent& WXUNUSED(event))
1709 {
1710 wxString indentStr = wxGetTextFromUser
1711 (
1712 _("Please enter the left indent in tenths of a millimetre."),
1713 _("Left Indent"),
1714 wxEmptyString,
1715 this
1716 );
1717 if (!indentStr.IsEmpty())
1718 {
1719 int indent = wxAtoi(indentStr);
1720
1721 wxTextAttr attr;
1722 attr.SetLeftIndent(indent);
1723
1724 long start, end;
1725 m_textCtrl->GetSelection(& start, & end);
1726 m_textCtrl->SetStyle(start, end, attr);
1727
1728 m_currentPosition = -1;
1729 }
1730 }
1731
1732 void RichTextFrame::OnRightIndent(wxCommandEvent& WXUNUSED(event))
1733 {
1734 wxString indentStr = wxGetTextFromUser
1735 (
1736 _("Please enter the right indent in tenths of a millimetre."),
1737 _("Right Indent"),
1738 wxEmptyString,
1739 this
1740 );
1741 if (!indentStr.IsEmpty())
1742 {
1743 int indent = wxAtoi(indentStr);
1744
1745 wxTextAttr attr;
1746 attr.SetRightIndent(indent);
1747
1748 long start, end;
1749 m_textCtrl->GetSelection(& start, & end);
1750 m_textCtrl->SetStyle(start, end, attr);
1751
1752 m_currentPosition = -1;
1753 }
1754 }
1755
1756 void RichTextFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
1757 {
1758 long insertionPoint = m_textCtrl->GetInsertionPoint();
1759 if (insertionPoint != m_currentPosition)
1760 {
1761 #if wxUSE_STATUSBAR
1762 wxTextAttr attr;
1763 if (m_textCtrl->GetStyle(insertionPoint, attr))
1764 {
1765 wxString msg;
1766 wxString facename(wxT("unknown"));
1767 if (attr.GetFont().Ok())
1768 {
1769 facename = attr.GetFont().GetFaceName();
1770 }
1771 wxString alignment(wxT("unknown alignment"));
1772 if (attr.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
1773 alignment = wxT("centred");
1774 else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT)
1775 alignment = wxT("right-aligned");
1776 else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_LEFT)
1777 alignment = wxT("left-aligned");
1778 else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED)
1779 alignment = wxT("justified");
1780 msg.Printf(wxT("Facename: %s, wxColour(%d, %d, %d), %s"),
1781 (const wxChar*) facename,
1782 attr.GetTextColour().Red(), attr.GetTextColour().Green(), attr.GetTextColour().Blue(),
1783 (const wxChar*) alignment);
1784
1785 if (attr.HasFont())
1786 {
1787 if (attr.GetFont().GetWeight() == wxBOLD)
1788 msg += wxT(" BOLD");
1789 else if (attr.GetFont().GetWeight() == wxNORMAL)
1790 msg += wxT(" NORMAL");
1791
1792 if (attr.GetFont().GetStyle() == wxITALIC)
1793 msg += wxT(" ITALIC");
1794
1795 if (attr.GetFont().GetUnderlined())
1796 msg += wxT(" UNDERLINED");
1797 }
1798
1799 SetStatusText(msg);
1800 }
1801 #endif // wxUSE_STATUSBAR
1802 m_currentPosition = insertionPoint;
1803 }
1804 }