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