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