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