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