]>
Commit | Line | Data |
---|---|---|
02e8b87f | 1 | ///////////////////////////////////////////////////////////////////////////// |
4aff28fc | 2 | // Name: text.cpp |
be5a51fb | 3 | // Purpose: TextCtrl wxWidgets sample |
02e8b87f RR |
4 | // Author: Robert Roebling |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
4aff28fc | 7 | // Copyright: (c) Robert Roebling, Julian Smart, Vadim Zeitlin |
02e8b87f RR |
8 | // Licence: wxWindows license |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
02e8b87f RR |
11 | // For compilers that support precompilation, includes "wx/wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/wx.h" | |
20 | #endif | |
21 | ||
22 | #if wxUSE_CLIPBOARD | |
23 | #include "wx/dataobj.h" | |
24 | #include "wx/clipbrd.h" | |
25 | #endif | |
26 | ||
0ddea946 | 27 | #if wxUSE_FILE |
ae3dd4a5 | 28 | #include "wx/file.h" |
0ddea946 VZ |
29 | #endif |
30 | ||
02e8b87f RR |
31 | #if wxUSE_TOOLTIPS |
32 | #include "wx/tooltip.h" | |
33 | #endif | |
34 | ||
b6a0d8a2 VZ |
35 | // We test for wxUSE_DRAG_AND_DROP also, because data objects may not be |
36 | // implemented for compilers that can't cope with the OLE parts in | |
37 | // wxUSE_DRAG_AND_DROP. | |
38 | #if !wxUSE_DRAG_AND_DROP | |
39 | #undef wxUSE_CLIPBOARD | |
40 | #define wxUSE_CLIPBOARD 0 | |
41 | #endif | |
42 | ||
e00a5d3c JS |
43 | #include "wx/colordlg.h" |
44 | #include "wx/fontdlg.h" | |
ea180b18 | 45 | #include "wx/numdlg.h" |
e00a5d3c | 46 | |
02e8b87f RR |
47 | //---------------------------------------------------------------------- |
48 | // class definitions | |
49 | //---------------------------------------------------------------------- | |
50 | ||
51 | class MyApp: public wxApp | |
52 | { | |
53 | public: | |
54 | bool OnInit(); | |
55 | }; | |
56 | ||
57 | // a text ctrl which allows to call different wxTextCtrl functions | |
58 | // interactively by pressing function keys in it | |
59 | class MyTextCtrl : public wxTextCtrl | |
60 | { | |
61 | public: | |
62 | MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, | |
63 | const wxPoint &pos, const wxSize &size, int style = 0) | |
56c4a88b VZ |
64 | : wxTextCtrl(parent, id, value, pos, size, style) |
65 | { | |
effbd41d | 66 | m_hasCapture = false; |
56c4a88b | 67 | } |
02e8b87f RR |
68 | |
69 | void OnKeyDown(wxKeyEvent& event); | |
70 | void OnKeyUp(wxKeyEvent& event); | |
71 | void OnChar(wxKeyEvent& event); | |
d7eee191 | 72 | |
9ca03a57 | 73 | void OnText(wxCommandEvent& event); |
c57e3339 | 74 | void OnTextURL(wxTextUrlEvent& event); |
d7eee191 VZ |
75 | void OnTextMaxLen(wxCommandEvent& event); |
76 | ||
4aff28fc | 77 | void OnMouseEvent(wxMouseEvent& event); |
02e8b87f | 78 | |
94ccc254 VZ |
79 | void OnSetFocus(wxFocusEvent& event); |
80 | void OnKillFocus(wxFocusEvent& event); | |
81 | ||
56c4a88b VZ |
82 | static bool ms_logKey; |
83 | static bool ms_logChar; | |
84 | static bool ms_logMouse; | |
1ce58dc6 | 85 | static bool ms_logText; |
94ccc254 | 86 | static bool ms_logFocus; |
f152cf5a | 87 | |
02e8b87f RR |
88 | private: |
89 | static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); } | |
94ccc254 | 90 | void LogKeyEvent(const wxChar *name, wxKeyEvent& event) const; |
02e8b87f | 91 | |
56c4a88b VZ |
92 | bool m_hasCapture; |
93 | ||
02e8b87f RR |
94 | DECLARE_EVENT_TABLE() |
95 | }; | |
96 | ||
97 | class MyPanel: public wxPanel | |
98 | { | |
99 | public: | |
100 | MyPanel(wxFrame *frame, int x, int y, int w, int h); | |
925e9792 WS |
101 | virtual ~MyPanel() |
102 | { | |
b29903d4 | 103 | #if wxUSE_LOG |
925e9792 | 104 | delete wxLog::SetActiveTarget(m_logOld); |
b29903d4 WS |
105 | #endif // wxUSE_LOG |
106 | } | |
02e8b87f | 107 | |
b6a0d8a2 VZ |
108 | #if wxUSE_CLIPBOARD |
109 | void DoPasteFromClipboard(); | |
110 | void DoCopyToClipboard(); | |
111 | #endif // wxUSE_CLIPBOARD | |
112 | ||
cba1148d | 113 | void DoRemoveText(); |
cdd732de | 114 | void DoReplaceText(); |
29676ca0 | 115 | void DoSelectText(); |
b6a0d8a2 VZ |
116 | void DoMoveToEndOfText(); |
117 | void DoMoveToEndOfEntry(); | |
02e8b87f | 118 | |
89124b1a RR |
119 | void OnSize( wxSizeEvent &event ); |
120 | ||
02e8b87f RR |
121 | MyTextCtrl *m_text; |
122 | MyTextCtrl *m_password; | |
123 | MyTextCtrl *m_enter; | |
124 | MyTextCtrl *m_tab; | |
02e8b87f | 125 | MyTextCtrl *m_readonly; |
d7eee191 | 126 | MyTextCtrl *m_limited; |
bb69661b | 127 | |
02e8b87f RR |
128 | MyTextCtrl *m_multitext; |
129 | MyTextCtrl *m_horizontal; | |
02e8b87f | 130 | |
0ddea946 VZ |
131 | MyTextCtrl *m_textrich; |
132 | ||
b29903d4 | 133 | #if wxUSE_LOG |
02e8b87f | 134 | wxTextCtrl *m_log; |
d847e69a | 135 | wxLog *m_logOld; |
b29903d4 | 136 | #endif // wxUSE_LOG |
d847e69a | 137 | |
89124b1a | 138 | private: |
cba1148d VZ |
139 | // get the currently focused text control or return the default one is no |
140 | // text ctrl has focus | |
141 | wxTextCtrl *GetFocusedText(wxTextCtrl *textDef); | |
142 | ||
89124b1a | 143 | DECLARE_EVENT_TABLE() |
02e8b87f RR |
144 | }; |
145 | ||
146 | class MyFrame: public wxFrame | |
147 | { | |
148 | public: | |
ab1ca7b3 | 149 | MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h); |
02e8b87f RR |
150 | |
151 | void OnQuit(wxCommandEvent& event); | |
152 | void OnAbout(wxCommandEvent& event); | |
153 | #if wxUSE_TOOLTIPS | |
154 | void OnSetTooltipDelay(wxCommandEvent& event); | |
155 | void OnToggleTooltips(wxCommandEvent& event); | |
156 | #endif // wxUSE_TOOLTIPS | |
b6a0d8a2 VZ |
157 | |
158 | #if wxUSE_CLIPBOARD | |
656562d8 | 159 | void OnPasteFromClipboard( wxCommandEvent& WXUNUSED(event) ) |
b6a0d8a2 | 160 | { m_panel->DoPasteFromClipboard(); } |
656562d8 | 161 | void OnCopyToClipboard( wxCommandEvent& WXUNUSED(event) ) |
b6a0d8a2 VZ |
162 | { m_panel->DoCopyToClipboard(); } |
163 | #endif // wxUSE_CLIPBOARD | |
164 | ||
656562d8 | 165 | void OnAddTextFreeze( wxCommandEvent& WXUNUSED(event) ) |
eff00523 | 166 | { DoAddText(true); } |
656562d8 | 167 | void OnAddText( wxCommandEvent& WXUNUSED(event) ) |
eff00523 | 168 | { DoAddText(false); } |
656562d8 | 169 | void OnRemoveText( wxCommandEvent& WXUNUSED(event) ) |
cba1148d | 170 | { m_panel->DoRemoveText(); } |
656562d8 | 171 | void OnReplaceText( wxCommandEvent& WXUNUSED(event) ) |
cdd732de | 172 | { m_panel->DoReplaceText(); } |
656562d8 | 173 | void OnSelectText( wxCommandEvent& WXUNUSED(event) ) |
29676ca0 | 174 | { m_panel->DoSelectText(); } |
eff00523 | 175 | |
656562d8 | 176 | void OnMoveToEndOfText( wxCommandEvent& WXUNUSED(event) ) |
b6a0d8a2 | 177 | { m_panel->DoMoveToEndOfText(); } |
656562d8 | 178 | void OnMoveToEndOfEntry( wxCommandEvent& WXUNUSED(event) ) |
b6a0d8a2 VZ |
179 | { m_panel->DoMoveToEndOfEntry(); } |
180 | ||
656562d8 | 181 | void OnScrollLineDown(wxCommandEvent& WXUNUSED(event)) |
22670da4 VZ |
182 | { |
183 | if ( !m_panel->m_textrich->LineDown() ) | |
184 | wxLogMessage(_T("Already at the bottom")); | |
185 | } | |
186 | ||
656562d8 | 187 | void OnScrollLineUp(wxCommandEvent& WXUNUSED(event)) |
22670da4 VZ |
188 | { |
189 | if ( !m_panel->m_textrich->LineUp() ) | |
190 | wxLogMessage(_T("Already at the top")); | |
191 | } | |
192 | ||
656562d8 | 193 | void OnScrollPageDown(wxCommandEvent& WXUNUSED(event)) |
22670da4 VZ |
194 | { |
195 | if ( !m_panel->m_textrich->PageDown() ) | |
196 | wxLogMessage(_T("Already at the bottom")); | |
197 | } | |
198 | ||
656562d8 | 199 | void OnScrollPageUp(wxCommandEvent& WXUNUSED(event)) |
22670da4 VZ |
200 | { |
201 | if ( !m_panel->m_textrich->PageUp() ) | |
202 | wxLogMessage(_T("Already at the top")); | |
203 | } | |
925e9792 | 204 | |
ae25e5cc RN |
205 | void OnGetLine(wxCommandEvent& WXUNUSED(event)) |
206 | { | |
207 | long nLine = wxGetNumberFromUser(wxT("Which line would you like to get?"), | |
208 | wxT("Enter which line you would like to get"), | |
209 | wxT("Get a line from the tabbed multiline text control") ); | |
925e9792 | 210 | |
ae25e5cc RN |
211 | wxMessageBox(m_panel->m_tab->GetLineText(nLine)); |
212 | } | |
213 | ||
214 | void OnGetLineLength(wxCommandEvent& WXUNUSED(event)) | |
215 | { | |
216 | long nLine = wxGetNumberFromUser(wxT("Which line would you like to get?"), | |
217 | wxT("Enter which line you would like to get"), | |
218 | wxT("Get length of a line from the tabbed multiline text control") ); | |
925e9792 WS |
219 | |
220 | wxMessageBox(wxString::Format(wxT("Length of line %i is:%i"), | |
ae25e5cc RN |
221 | (int) nLine, |
222 | m_panel->m_tab->GetLineLength(nLine)) | |
223 | ); | |
224 | } | |
22670da4 | 225 | |
b29903d4 | 226 | #if wxUSE_LOG |
e66ad5c6 | 227 | void OnLogClear(wxCommandEvent& event); |
b29903d4 | 228 | #endif // wxUSE_LOG |
0ddea946 | 229 | void OnFileSave(wxCommandEvent& event); |
b6a0d8a2 | 230 | void OnFileLoad(wxCommandEvent& event); |
e00a5d3c | 231 | void OnRichTextTest(wxCommandEvent& event); |
b6a0d8a2 | 232 | |
f6bcfd97 BP |
233 | void OnSetEditable(wxCommandEvent& event); |
234 | void OnSetEnabled(wxCommandEvent& event); | |
235 | ||
56c4a88b VZ |
236 | void OnLogKey(wxCommandEvent& event) |
237 | { | |
238 | MyTextCtrl::ms_logKey = event.IsChecked(); | |
239 | } | |
240 | ||
241 | void OnLogChar(wxCommandEvent& event) | |
242 | { | |
243 | MyTextCtrl::ms_logChar = event.IsChecked(); | |
244 | } | |
245 | ||
246 | void OnLogMouse(wxCommandEvent& event) | |
247 | { | |
248 | MyTextCtrl::ms_logMouse = event.IsChecked(); | |
249 | } | |
250 | ||
1ce58dc6 VZ |
251 | void OnLogText(wxCommandEvent& event) |
252 | { | |
253 | MyTextCtrl::ms_logText = event.IsChecked(); | |
254 | } | |
255 | ||
94ccc254 VZ |
256 | void OnLogFocus(wxCommandEvent& event) |
257 | { | |
258 | MyTextCtrl::ms_logFocus = event.IsChecked(); | |
259 | } | |
260 | ||
656562d8 | 261 | void OnSetText(wxCommandEvent& WXUNUSED(event)) |
60f52320 VZ |
262 | { |
263 | m_panel->m_text->SetValue(_T("Hello, world (what else did you expect)?")); | |
264 | } | |
265 | ||
02e8b87f RR |
266 | void OnIdle( wxIdleEvent& event ); |
267 | ||
268 | private: | |
eff00523 VZ |
269 | void DoAddText(bool freeze) |
270 | { | |
cdd732de VZ |
271 | wxTextCtrl * const text = m_panel->m_textrich; |
272 | text->Clear(); | |
273 | ||
eff00523 VZ |
274 | if ( freeze ) |
275 | text->Freeze(); | |
276 | ||
277 | for ( int i = 0; i < 100; i++ ) | |
0146a47e | 278 | { |
4693b20c | 279 | text->AppendText(wxString::Format(wxT("Line %i\n"), i)); |
0146a47e | 280 | } |
eff00523 | 281 | |
eff00523 VZ |
282 | if ( freeze ) |
283 | text->Thaw(); | |
cdd732de VZ |
284 | |
285 | text->SetInsertionPoint(0); | |
eff00523 VZ |
286 | } |
287 | ||
b6a0d8a2 VZ |
288 | MyPanel *m_panel; |
289 | ||
02e8b87f RR |
290 | DECLARE_EVENT_TABLE() |
291 | }; | |
292 | ||
e00a5d3c JS |
293 | /* |
294 | * RichTextFrame is used to demonstrate rich text behaviour | |
295 | */ | |
296 | ||
297 | class RichTextFrame: public wxFrame | |
298 | { | |
299 | public: | |
300 | RichTextFrame(wxWindow* parent, const wxString& title); | |
301 | ||
302 | // Event handlers | |
303 | ||
304 | void OnClose(wxCommandEvent& event); | |
80185c6c | 305 | void OnIdle(wxIdleEvent& event); |
e00a5d3c JS |
306 | void OnLeftAlign(wxCommandEvent& event); |
307 | void OnRightAlign(wxCommandEvent& event); | |
308 | void OnJustify(wxCommandEvent& event); | |
309 | void OnCentre(wxCommandEvent& event); | |
310 | void OnChangeFont(wxCommandEvent& event); | |
311 | void OnChangeTextColour(wxCommandEvent& event); | |
312 | void OnChangeBackgroundColour(wxCommandEvent& event); | |
313 | void OnLeftIndent(wxCommandEvent& event); | |
314 | void OnRightIndent(wxCommandEvent& event); | |
315 | ||
316 | private: | |
317 | wxTextCtrl *m_textCtrl; | |
80185c6c | 318 | long m_currentPosition; |
e00a5d3c JS |
319 | |
320 | DECLARE_EVENT_TABLE() | |
321 | }; | |
322 | ||
02e8b87f RR |
323 | //---------------------------------------------------------------------- |
324 | // main() | |
325 | //---------------------------------------------------------------------- | |
326 | ||
327 | IMPLEMENT_APP(MyApp) | |
328 | ||
329 | //---------------------------------------------------------------------- | |
330 | // MyApp | |
331 | //---------------------------------------------------------------------- | |
332 | ||
333 | enum | |
334 | { | |
b6a0d8a2 VZ |
335 | TEXT_QUIT = 100, |
336 | TEXT_ABOUT, | |
337 | TEXT_LOAD, | |
ae3dd4a5 | 338 | TEXT_SAVE, |
e66ad5c6 | 339 | TEXT_CLEAR, |
e00a5d3c | 340 | TEXT_RICH_TEXT_TEST, |
b6a0d8a2 VZ |
341 | |
342 | // clipboard menu | |
343 | TEXT_CLIPBOARD_COPY = 200, | |
344 | TEXT_CLIPBOARD_PASTE, | |
02e8b87f RR |
345 | |
346 | // tooltip menu | |
b6a0d8a2 VZ |
347 | TEXT_TOOLTIPS_SETDELAY = 300, |
348 | TEXT_TOOLTIPS_ENABLE, | |
349 | ||
f6bcfd97 | 350 | // text menu |
eff00523 VZ |
351 | TEXT_ADD_SOME = 400, |
352 | TEXT_ADD_FREEZE, | |
353 | TEXT_MOVE_ENDTEXT, | |
f6bcfd97 BP |
354 | TEXT_MOVE_ENDENTRY, |
355 | TEXT_SET_EDITABLE, | |
22670da4 VZ |
356 | TEXT_SET_ENABLED, |
357 | TEXT_LINE_DOWN, | |
358 | TEXT_LINE_UP, | |
359 | TEXT_PAGE_DOWN, | |
360 | TEXT_PAGE_UP, | |
925e9792 | 361 | |
ae25e5cc RN |
362 | TEXT_GET_LINE, |
363 | TEXT_GET_LINELENGTH, | |
925e9792 | 364 | |
cba1148d | 365 | TEXT_REMOVE, |
cdd732de | 366 | TEXT_REPLACE, |
29676ca0 | 367 | TEXT_SELECT, |
60f52320 | 368 | TEXT_SET, |
56c4a88b VZ |
369 | |
370 | // log menu | |
371 | TEXT_LOG_KEY, | |
372 | TEXT_LOG_CHAR, | |
373 | TEXT_LOG_MOUSE, | |
1ce58dc6 | 374 | TEXT_LOG_TEXT, |
94ccc254 | 375 | TEXT_LOG_FOCUS, |
56c4a88b VZ |
376 | |
377 | TEXT_END | |
02e8b87f RR |
378 | }; |
379 | ||
380 | bool MyApp::OnInit() | |
381 | { | |
382 | // Create the main frame window | |
383 | MyFrame *frame = new MyFrame((wxFrame *) NULL, | |
be5a51fb | 384 | _T("Text wxWidgets sample"), 50, 50, 700, 420); |
89124b1a | 385 | frame->SetSizeHints( 500, 400 ); |
02e8b87f | 386 | |
02e8b87f | 387 | wxMenu *file_menu = new wxMenu; |
ab1ca7b3 MB |
388 | file_menu->Append(TEXT_SAVE, _T("&Save file\tCtrl-S"), |
389 | _T("Save the text control contents to file")); | |
390 | file_menu->Append(TEXT_LOAD, _T("&Load file\tCtrl-O"), | |
391 | _T("Load the sample file into text control")); | |
b6a0d8a2 | 392 | file_menu->AppendSeparator(); |
e00a5d3c JS |
393 | file_menu->Append(TEXT_RICH_TEXT_TEST, _T("Show Rich Text Editor")); |
394 | file_menu->AppendSeparator(); | |
ab1ca7b3 | 395 | file_menu->Append(TEXT_ABOUT, _T("&About\tAlt-A")); |
b6a0d8a2 | 396 | file_menu->AppendSeparator(); |
ab1ca7b3 | 397 | file_menu->Append(TEXT_QUIT, _T("E&xit\tAlt-X"), _T("Quit this sample")); |
02e8b87f RR |
398 | |
399 | wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE ); | |
ab1ca7b3 | 400 | menu_bar->Append(file_menu, _T("&File")); |
02e8b87f RR |
401 | |
402 | #if wxUSE_TOOLTIPS | |
403 | wxMenu *tooltip_menu = new wxMenu; | |
ab1ca7b3 | 404 | tooltip_menu->Append(TEXT_TOOLTIPS_SETDELAY, _T("Set &delay\tCtrl-D")); |
02e8b87f | 405 | tooltip_menu->AppendSeparator(); |
ab1ca7b3 | 406 | tooltip_menu->Append(TEXT_TOOLTIPS_ENABLE, _T("&Toggle tooltips\tCtrl-T"), |
effbd41d WS |
407 | _T("enable/disable tooltips"), true); |
408 | tooltip_menu->Check(TEXT_TOOLTIPS_ENABLE, true); | |
ab1ca7b3 | 409 | menu_bar->Append(tooltip_menu, _T("&Tooltips")); |
02e8b87f RR |
410 | #endif // wxUSE_TOOLTIPS |
411 | ||
b6a0d8a2 VZ |
412 | #if wxUSE_CLIPBOARD |
413 | wxMenu *menuClipboard = new wxMenu; | |
ab1ca7b3 MB |
414 | menuClipboard->Append(TEXT_CLIPBOARD_COPY, _T("&Copy\tCtrl-C"), |
415 | _T("Copy the first line to the clipboard")); | |
416 | menuClipboard->Append(TEXT_CLIPBOARD_PASTE, _T("&Paste\tCtrl-V"), | |
417 | _T("Paste from clipboard to the text control")); | |
418 | menu_bar->Append(menuClipboard, _T("&Clipboard")); | |
b6a0d8a2 VZ |
419 | #endif // wxUSE_CLIPBOARD |
420 | ||
f6bcfd97 | 421 | wxMenu *menuText = new wxMenu; |
ab1ca7b3 MB |
422 | menuText->Append(TEXT_ADD_SOME, _T("&Append some text\tCtrl-A")); |
423 | menuText->Append(TEXT_ADD_FREEZE, _T("&Append text with freeze/thaw\tShift-Ctrl-A")); | |
cdd732de VZ |
424 | menuText->Append(TEXT_REMOVE, _T("&Remove first 10 characters\tCtrl-Y")); |
425 | menuText->Append(TEXT_REPLACE, _T("&Replace characters 4 to 8 with ABC\tCtrl-R")); | |
29676ca0 | 426 | menuText->Append(TEXT_SELECT, _T("&Select characters 4 to 8\tCtrl-I")); |
ab1ca7b3 | 427 | menuText->Append(TEXT_SET, _T("&Set the first text zone value\tCtrl-E")); |
cba1148d | 428 | menuText->AppendSeparator(); |
ab1ca7b3 MB |
429 | menuText->Append(TEXT_MOVE_ENDTEXT, _T("Move cursor to the end of &text")); |
430 | menuText->Append(TEXT_MOVE_ENDENTRY, _T("Move cursor to the end of &entry")); | |
2153bf89 DS |
431 | menuText->AppendCheckItem(TEXT_SET_EDITABLE, _T("Toggle &editable state")); |
432 | menuText->AppendCheckItem(TEXT_SET_ENABLED, _T("Toggle e&nabled state")); | |
effbd41d WS |
433 | menuText->Check(TEXT_SET_EDITABLE, true); |
434 | menuText->Check(TEXT_SET_ENABLED, true); | |
22670da4 | 435 | menuText->AppendSeparator(); |
ab1ca7b3 MB |
436 | menuText->Append(TEXT_LINE_DOWN, _T("Scroll text one line down")); |
437 | menuText->Append(TEXT_LINE_UP, _T("Scroll text one line up")); | |
438 | menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page down")); | |
01edebd0 | 439 | menuText->Append(TEXT_PAGE_UP, _T("Scroll text one page up")); |
ae25e5cc RN |
440 | menuText->AppendSeparator(); |
441 | menuText->Append(TEXT_GET_LINE, _T("Get the text of a line of the tabbed multiline")); | |
442 | menuText->Append(TEXT_GET_LINELENGTH, _T("Get the length of a line of the tabbed multiline")); | |
ab1ca7b3 | 443 | menu_bar->Append(menuText, _T("Te&xt")); |
56c4a88b | 444 | |
b29903d4 | 445 | #if wxUSE_LOG |
56c4a88b | 446 | wxMenu *menuLog = new wxMenu; |
2153bf89 DS |
447 | menuLog->AppendCheckItem(TEXT_LOG_KEY, _T("Log &key events")); |
448 | menuLog->AppendCheckItem(TEXT_LOG_CHAR, _T("Log &char events")); | |
449 | menuLog->AppendCheckItem(TEXT_LOG_MOUSE, _T("Log &mouse events")); | |
450 | menuLog->AppendCheckItem(TEXT_LOG_TEXT, _T("Log &text events")); | |
451 | menuLog->AppendCheckItem(TEXT_LOG_FOCUS, _T("Log &focus events")); | |
56c4a88b | 452 | menuLog->AppendSeparator(); |
ab1ca7b3 MB |
453 | menuLog->Append(TEXT_CLEAR, _T("&Clear the log\tCtrl-C"), |
454 | _T("Clear the log window contents")); | |
94ccc254 VZ |
455 | |
456 | // select only the interesting events by default | |
effbd41d WS |
457 | menuLog->Check(TEXT_LOG_KEY, true); |
458 | menuLog->Check(TEXT_LOG_CHAR, true); | |
459 | menuLog->Check(TEXT_LOG_TEXT, true); | |
94ccc254 VZ |
460 | |
461 | MyTextCtrl::ms_logKey = | |
462 | MyTextCtrl::ms_logChar = | |
effbd41d | 463 | MyTextCtrl::ms_logText = true; |
b29903d4 | 464 | |
ab1ca7b3 | 465 | menu_bar->Append(menuLog, _T("&Log")); |
b29903d4 | 466 | #endif // wxUSE_LOG |
b6a0d8a2 | 467 | |
02e8b87f RR |
468 | frame->SetMenuBar(menu_bar); |
469 | ||
effbd41d | 470 | frame->Show(true); |
02e8b87f RR |
471 | |
472 | SetTopWindow(frame); | |
473 | ||
474 | // report success | |
effbd41d | 475 | return true; |
02e8b87f RR |
476 | } |
477 | ||
478 | //---------------------------------------------------------------------- | |
479 | // MyTextCtrl | |
480 | //---------------------------------------------------------------------- | |
481 | ||
482 | BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl) | |
483 | EVT_KEY_DOWN(MyTextCtrl::OnKeyDown) | |
484 | EVT_KEY_UP(MyTextCtrl::OnKeyUp) | |
485 | EVT_CHAR(MyTextCtrl::OnChar) | |
d7eee191 | 486 | |
effbd41d WS |
487 | EVT_TEXT(wxID_ANY, MyTextCtrl::OnText) |
488 | EVT_TEXT_URL(wxID_ANY, MyTextCtrl::OnTextURL) | |
489 | EVT_TEXT_MAXLEN(wxID_ANY, MyTextCtrl::OnTextMaxLen) | |
d7eee191 | 490 | |
4aff28fc | 491 | EVT_MOUSE_EVENTS(MyTextCtrl::OnMouseEvent) |
94ccc254 VZ |
492 | |
493 | EVT_SET_FOCUS(MyTextCtrl::OnSetFocus) | |
494 | EVT_KILL_FOCUS(MyTextCtrl::OnKillFocus) | |
02e8b87f RR |
495 | END_EVENT_TABLE() |
496 | ||
effbd41d WS |
497 | bool MyTextCtrl::ms_logKey = false; |
498 | bool MyTextCtrl::ms_logChar = false; | |
499 | bool MyTextCtrl::ms_logMouse = false; | |
500 | bool MyTextCtrl::ms_logText = false; | |
501 | bool MyTextCtrl::ms_logFocus = false; | |
56c4a88b | 502 | |
94ccc254 | 503 | void MyTextCtrl::LogKeyEvent(const wxChar *name, wxKeyEvent& event) const |
02e8b87f RR |
504 | { |
505 | wxString key; | |
b1d4dd7a | 506 | long keycode = event.GetKeyCode(); |
02e8b87f RR |
507 | { |
508 | switch ( keycode ) | |
509 | { | |
ab1ca7b3 MB |
510 | case WXK_BACK: key = _T("BACK"); break; |
511 | case WXK_TAB: key = _T("TAB"); break; | |
512 | case WXK_RETURN: key = _T("RETURN"); break; | |
513 | case WXK_ESCAPE: key = _T("ESCAPE"); break; | |
514 | case WXK_SPACE: key = _T("SPACE"); break; | |
515 | case WXK_DELETE: key = _T("DELETE"); break; | |
516 | case WXK_START: key = _T("START"); break; | |
517 | case WXK_LBUTTON: key = _T("LBUTTON"); break; | |
518 | case WXK_RBUTTON: key = _T("RBUTTON"); break; | |
519 | case WXK_CANCEL: key = _T("CANCEL"); break; | |
520 | case WXK_MBUTTON: key = _T("MBUTTON"); break; | |
521 | case WXK_CLEAR: key = _T("CLEAR"); break; | |
522 | case WXK_SHIFT: key = _T("SHIFT"); break; | |
523 | case WXK_ALT: key = _T("ALT"); break; | |
524 | case WXK_CONTROL: key = _T("CONTROL"); break; | |
525 | case WXK_MENU: key = _T("MENU"); break; | |
526 | case WXK_PAUSE: key = _T("PAUSE"); break; | |
527 | case WXK_CAPITAL: key = _T("CAPITAL"); break; | |
528 | case WXK_PRIOR: key = _T("PRIOR"); break; | |
529 | case WXK_NEXT: key = _T("NEXT"); break; | |
530 | case WXK_END: key = _T("END"); break; | |
531 | case WXK_HOME: key = _T("HOME"); break; | |
532 | case WXK_LEFT: key = _T("LEFT"); break; | |
533 | case WXK_UP: key = _T("UP"); break; | |
534 | case WXK_RIGHT: key = _T("RIGHT"); break; | |
535 | case WXK_DOWN: key = _T("DOWN"); break; | |
536 | case WXK_SELECT: key = _T("SELECT"); break; | |
537 | case WXK_PRINT: key = _T("PRINT"); break; | |
538 | case WXK_EXECUTE: key = _T("EXECUTE"); break; | |
539 | case WXK_SNAPSHOT: key = _T("SNAPSHOT"); break; | |
540 | case WXK_INSERT: key = _T("INSERT"); break; | |
541 | case WXK_HELP: key = _T("HELP"); break; | |
542 | case WXK_NUMPAD0: key = _T("NUMPAD0"); break; | |
543 | case WXK_NUMPAD1: key = _T("NUMPAD1"); break; | |
544 | case WXK_NUMPAD2: key = _T("NUMPAD2"); break; | |
545 | case WXK_NUMPAD3: key = _T("NUMPAD3"); break; | |
546 | case WXK_NUMPAD4: key = _T("NUMPAD4"); break; | |
547 | case WXK_NUMPAD5: key = _T("NUMPAD5"); break; | |
548 | case WXK_NUMPAD6: key = _T("NUMPAD6"); break; | |
549 | case WXK_NUMPAD7: key = _T("NUMPAD7"); break; | |
550 | case WXK_NUMPAD8: key = _T("NUMPAD8"); break; | |
551 | case WXK_NUMPAD9: key = _T("NUMPAD9"); break; | |
552 | case WXK_MULTIPLY: key = _T("MULTIPLY"); break; | |
553 | case WXK_ADD: key = _T("ADD"); break; | |
554 | case WXK_SEPARATOR: key = _T("SEPARATOR"); break; | |
555 | case WXK_SUBTRACT: key = _T("SUBTRACT"); break; | |
556 | case WXK_DECIMAL: key = _T("DECIMAL"); break; | |
557 | case WXK_DIVIDE: key = _T("DIVIDE"); break; | |
558 | case WXK_F1: key = _T("F1"); break; | |
559 | case WXK_F2: key = _T("F2"); break; | |
560 | case WXK_F3: key = _T("F3"); break; | |
561 | case WXK_F4: key = _T("F4"); break; | |
562 | case WXK_F5: key = _T("F5"); break; | |
563 | case WXK_F6: key = _T("F6"); break; | |
564 | case WXK_F7: key = _T("F7"); break; | |
565 | case WXK_F8: key = _T("F8"); break; | |
566 | case WXK_F9: key = _T("F9"); break; | |
567 | case WXK_F10: key = _T("F10"); break; | |
568 | case WXK_F11: key = _T("F11"); break; | |
569 | case WXK_F12: key = _T("F12"); break; | |
570 | case WXK_F13: key = _T("F13"); break; | |
571 | case WXK_F14: key = _T("F14"); break; | |
572 | case WXK_F15: key = _T("F15"); break; | |
573 | case WXK_F16: key = _T("F16"); break; | |
574 | case WXK_F17: key = _T("F17"); break; | |
575 | case WXK_F18: key = _T("F18"); break; | |
576 | case WXK_F19: key = _T("F19"); break; | |
577 | case WXK_F20: key = _T("F20"); break; | |
578 | case WXK_F21: key = _T("F21"); break; | |
579 | case WXK_F22: key = _T("F22"); break; | |
580 | case WXK_F23: key = _T("F23"); break; | |
581 | case WXK_F24: key = _T("F24"); break; | |
582 | case WXK_NUMLOCK: key = _T("NUMLOCK"); break; | |
583 | case WXK_SCROLL: key = _T("SCROLL"); break; | |
584 | case WXK_PAGEUP: key = _T("PAGEUP"); break; | |
585 | case WXK_PAGEDOWN: key = _T("PAGEDOWN"); break; | |
586 | case WXK_NUMPAD_SPACE: key = _T("NUMPAD_SPACE"); break; | |
587 | case WXK_NUMPAD_TAB: key = _T("NUMPAD_TAB"); break; | |
588 | case WXK_NUMPAD_ENTER: key = _T("NUMPAD_ENTER"); break; | |
589 | case WXK_NUMPAD_F1: key = _T("NUMPAD_F1"); break; | |
590 | case WXK_NUMPAD_F2: key = _T("NUMPAD_F2"); break; | |
591 | case WXK_NUMPAD_F3: key = _T("NUMPAD_F3"); break; | |
592 | case WXK_NUMPAD_F4: key = _T("NUMPAD_F4"); break; | |
593 | case WXK_NUMPAD_HOME: key = _T("NUMPAD_HOME"); break; | |
594 | case WXK_NUMPAD_LEFT: key = _T("NUMPAD_LEFT"); break; | |
595 | case WXK_NUMPAD_UP: key = _T("NUMPAD_UP"); break; | |
596 | case WXK_NUMPAD_RIGHT: key = _T("NUMPAD_RIGHT"); break; | |
597 | case WXK_NUMPAD_DOWN: key = _T("NUMPAD_DOWN"); break; | |
598 | case WXK_NUMPAD_PRIOR: key = _T("NUMPAD_PRIOR"); break; | |
599 | case WXK_NUMPAD_PAGEUP: key = _T("NUMPAD_PAGEUP"); break; | |
600 | case WXK_NUMPAD_PAGEDOWN: key = _T("NUMPAD_PAGEDOWN"); break; | |
601 | case WXK_NUMPAD_END: key = _T("NUMPAD_END"); break; | |
602 | case WXK_NUMPAD_BEGIN: key = _T("NUMPAD_BEGIN"); break; | |
603 | case WXK_NUMPAD_INSERT: key = _T("NUMPAD_INSERT"); break; | |
604 | case WXK_NUMPAD_DELETE: key = _T("NUMPAD_DELETE"); break; | |
605 | case WXK_NUMPAD_EQUAL: key = _T("NUMPAD_EQUAL"); break; | |
606 | case WXK_NUMPAD_MULTIPLY: key = _T("NUMPAD_MULTIPLY"); break; | |
607 | case WXK_NUMPAD_ADD: key = _T("NUMPAD_ADD"); break; | |
608 | case WXK_NUMPAD_SEPARATOR: key = _T("NUMPAD_SEPARATOR"); break; | |
609 | case WXK_NUMPAD_SUBTRACT: key = _T("NUMPAD_SUBTRACT"); break; | |
610 | case WXK_NUMPAD_DECIMAL: key = _T("NUMPAD_DECIMAL"); break; | |
02e8b87f | 611 | |
4afd7529 | 612 | default: |
89124b1a RR |
613 | { |
614 | if ( wxIsprint((int)keycode) ) | |
1ce58dc6 VZ |
615 | key.Printf(_T("'%c'"), (char)keycode); |
616 | else if ( keycode > 0 && keycode < 27 ) | |
617 | key.Printf(_("Ctrl-%c"), _T('A') + keycode - 1); | |
89124b1a | 618 | else |
1ce58dc6 | 619 | key.Printf(_T("unknown (%ld)"), keycode); |
4afd7529 | 620 | } |
02e8b87f RR |
621 | } |
622 | } | |
623 | ||
0d9b2c16 VZ |
624 | #if wxUSE_UNICODE |
625 | key += wxString::Format(_T(" (Unicode: %#04x)"), event.GetUnicodeKey()); | |
626 | #endif // wxUSE_UNICODE | |
627 | ||
02e8b87f RR |
628 | wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"), |
629 | name, | |
630 | key.c_str(), | |
631 | GetChar( event.ControlDown(), _T('C') ), | |
632 | GetChar( event.AltDown(), _T('A') ), | |
633 | GetChar( event.ShiftDown(), _T('S') ), | |
634 | GetChar( event.MetaDown(), _T('M') ) ); | |
02e8b87f RR |
635 | } |
636 | ||
c57e3339 VZ |
637 | static wxString GetMouseEventDesc(const wxMouseEvent& ev) |
638 | { | |
639 | // click event | |
640 | wxString button; | |
641 | bool dbl, up; | |
642 | if ( ev.LeftDown() || ev.LeftUp() || ev.LeftDClick() ) | |
643 | { | |
644 | button = _T("Left"); | |
645 | dbl = ev.LeftDClick(); | |
646 | up = ev.LeftUp(); | |
647 | } | |
648 | else if ( ev.MiddleDown() || ev.MiddleUp() || ev.MiddleDClick() ) | |
649 | { | |
650 | button = _T("Middle"); | |
651 | dbl = ev.MiddleDClick(); | |
652 | up = ev.MiddleUp(); | |
653 | } | |
654 | else if ( ev.RightDown() || ev.RightUp() || ev.RightDClick() ) | |
655 | { | |
656 | button = _T("Right"); | |
657 | dbl = ev.RightDClick(); | |
658 | up = ev.RightUp(); | |
659 | } | |
660 | else | |
661 | { | |
662 | return _T("Unknown mouse event"); | |
663 | } | |
664 | ||
665 | return wxString::Format(_T("%s mouse button %s"), | |
666 | button.c_str(), | |
667 | dbl ? _T("double clicked") | |
668 | : up ? _T("released") : _T("clicked")); | |
669 | } | |
670 | ||
4aff28fc VZ |
671 | void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev) |
672 | { | |
56c4a88b VZ |
673 | ev.Skip(); |
674 | ||
1ce58dc6 | 675 | if ( !ms_logMouse ) |
56c4a88b VZ |
676 | return; |
677 | ||
4aff28fc VZ |
678 | if ( !ev.Moving() ) |
679 | { | |
680 | wxString msg; | |
681 | if ( ev.Entering() ) | |
682 | { | |
683 | msg = _T("Mouse entered the window"); | |
684 | } | |
685 | else if ( ev.Leaving() ) | |
686 | { | |
687 | msg = _T("Mouse left the window"); | |
688 | } | |
689 | else | |
690 | { | |
c57e3339 | 691 | msg = GetMouseEventDesc(ev); |
4aff28fc VZ |
692 | } |
693 | ||
692c9b86 VZ |
694 | msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") "); |
695 | ||
696 | long pos; | |
697 | wxTextCtrlHitTestResult rc = HitTest(ev.GetPosition(), &pos); | |
698 | if ( rc != wxTE_HT_UNKNOWN ) | |
699 | { | |
95390291 | 700 | msg << _T("at position ") << pos << _T(' '); |
692c9b86 VZ |
701 | } |
702 | ||
703 | msg << _T("[Flags: ") | |
4ed0aceb VZ |
704 | << GetChar( ev.LeftIsDown(), _T('1') ) |
705 | << GetChar( ev.MiddleIsDown(), _T('2') ) | |
706 | << GetChar( ev.RightIsDown(), _T('3') ) | |
4aff28fc VZ |
707 | << GetChar( ev.ControlDown(), _T('C') ) |
708 | << GetChar( ev.AltDown(), _T('A') ) | |
709 | << GetChar( ev.ShiftDown(), _T('S') ) | |
692c9b86 VZ |
710 | << GetChar( ev.MetaDown(), _T('M') ) |
711 | << _T(']'); | |
4aff28fc VZ |
712 | |
713 | wxLogMessage(msg); | |
714 | } | |
715 | //else: we're not interested in mouse move events | |
716 | } | |
717 | ||
94ccc254 VZ |
718 | void MyTextCtrl::OnSetFocus(wxFocusEvent& event) |
719 | { | |
720 | if ( ms_logFocus ) | |
eba33006 | 721 | wxLogMessage( wxT("%p got focus."), this); |
94ccc254 VZ |
722 | |
723 | event.Skip(); | |
724 | } | |
725 | ||
726 | void MyTextCtrl::OnKillFocus(wxFocusEvent& event) | |
727 | { | |
728 | if ( ms_logFocus ) | |
eba33006 | 729 | wxLogMessage( wxT("%p lost focus"), this); |
94ccc254 VZ |
730 | |
731 | event.Skip(); | |
732 | } | |
733 | ||
9ca03a57 | 734 | void MyTextCtrl::OnText(wxCommandEvent& event) |
02e8b87f | 735 | { |
1ce58dc6 VZ |
736 | if ( !ms_logText ) |
737 | return; | |
738 | ||
9ca03a57 | 739 | MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject(); |
ae3dd4a5 VZ |
740 | const wxChar *data = (const wxChar *)(win->GetClientData()); |
741 | if ( data ) | |
742 | { | |
c41ea66a | 743 | wxLogMessage(_T("Text changed in control '%s'"), data); |
ae3dd4a5 | 744 | } |
f6bcfd97 BP |
745 | else |
746 | { | |
eba33006 | 747 | // wxLogMessage( event.GetString() ); |
f6bcfd97 BP |
748 | wxLogMessage(_T("Text changed in some control")); |
749 | } | |
9ca03a57 VZ |
750 | } |
751 | ||
656562d8 | 752 | void MyTextCtrl::OnTextMaxLen(wxCommandEvent& WXUNUSED(event)) |
d7eee191 VZ |
753 | { |
754 | wxLogMessage(_T("You can't enter more characters into this control.")); | |
755 | } | |
756 | ||
c57e3339 VZ |
757 | void MyTextCtrl::OnTextURL(wxTextUrlEvent& event) |
758 | { | |
759 | const wxMouseEvent& ev = event.GetMouseEvent(); | |
760 | ||
761 | // filter out mouse moves, too many of them | |
762 | if ( ev.Moving() ) | |
763 | return; | |
764 | ||
765 | long start = event.GetURLStart(), | |
766 | end = event.GetURLEnd(); | |
767 | ||
768 | wxLogMessage(_T("Mouse event over URL '%s': %s"), | |
769 | GetValue().Mid(start, end - start).c_str(), | |
770 | GetMouseEventDesc(ev).c_str()); | |
771 | } | |
772 | ||
9ca03a57 VZ |
773 | void MyTextCtrl::OnChar(wxKeyEvent& event) |
774 | { | |
1ce58dc6 | 775 | if ( ms_logChar ) |
94ccc254 | 776 | LogKeyEvent( _T("Char"), event); |
3017f78d | 777 | |
3017f78d | 778 | event.Skip(); |
02e8b87f RR |
779 | } |
780 | ||
781 | void MyTextCtrl::OnKeyUp(wxKeyEvent& event) | |
782 | { | |
1ce58dc6 | 783 | if ( ms_logKey ) |
94ccc254 | 784 | LogKeyEvent( _T("Key up"), event); |
02e8b87f RR |
785 | |
786 | event.Skip(); | |
787 | } | |
788 | ||
789 | void MyTextCtrl::OnKeyDown(wxKeyEvent& event) | |
790 | { | |
b1d4dd7a | 791 | switch ( event.GetKeyCode() ) |
02e8b87f RR |
792 | { |
793 | case WXK_F1: | |
794 | // show current position and text length | |
795 | { | |
796 | long line, column, pos = GetInsertionPoint(); | |
797 | PositionToXY(pos, &column, &line); | |
798 | ||
2b5f62a0 | 799 | 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 |
800 | pos, |
801 | line, column, | |
8b1d8f36 VZ |
802 | (long) GetNumberOfLines(), |
803 | (long) GetLineLength(line), | |
d4964163 | 804 | (unsigned int) GetValue().length(), |
02e8b87f | 805 | GetLastPosition()); |
2b5f62a0 VZ |
806 | |
807 | long from, to; | |
808 | GetSelection(&from, &to); | |
809 | ||
810 | wxString sel = GetStringSelection(); | |
811 | ||
812 | wxLogMessage(_T("Selection: from %ld to %ld."), from, to); | |
813 | wxLogMessage(_T("Selection = '%s' (len = %u)"), | |
ce709481 RN |
814 | sel.c_str(), |
815 | (unsigned int) sel.length()); | |
02e8b87f RR |
816 | } |
817 | break; | |
818 | ||
819 | case WXK_F2: | |
820 | // go to the end | |
821 | SetInsertionPointEnd(); | |
822 | break; | |
823 | ||
824 | case WXK_F3: | |
825 | // go to position 10 | |
826 | SetInsertionPoint(10); | |
827 | break; | |
4afd7529 | 828 | |
f152cf5a | 829 | case WXK_F4: |
4afd7529 VZ |
830 | if (!m_hasCapture) |
831 | { | |
f152cf5a | 832 | wxLogDebug( wxT("Now capturing mouse and events.") ); |
effbd41d | 833 | m_hasCapture = true; |
4afd7529 VZ |
834 | CaptureMouse(); |
835 | } | |
836 | else | |
837 | { | |
f152cf5a | 838 | wxLogDebug( wxT("Stopped capturing mouse and events.") ); |
effbd41d | 839 | m_hasCapture = false; |
4afd7529 VZ |
840 | ReleaseMouse(); |
841 | } | |
f152cf5a | 842 | break; |
4afd7529 VZ |
843 | |
844 | case WXK_F5: | |
845 | // insert a blank line | |
ab1ca7b3 | 846 | WriteText(_T("\n")); |
ae3dd4a5 | 847 | break; |
02e8b87f | 848 | |
f6bcfd97 | 849 | case WXK_F6: |
2b5f62a0 VZ |
850 | wxLogMessage(_T("IsModified() before SetValue(): %d"), |
851 | IsModified()); | |
852 | SetValue(_T("SetValue() has been called")); | |
853 | wxLogMessage(_T("IsModified() after SetValue(): %d"), | |
854 | IsModified()); | |
f6bcfd97 BP |
855 | break; |
856 | ||
857 | case WXK_F7: | |
2b5f62a0 | 858 | wxLogMessage(_T("Position 10 should be now visible.")); |
f6bcfd97 BP |
859 | ShowPosition(10); |
860 | break; | |
18414479 | 861 | |
80695f83 | 862 | case WXK_F8: |
2b5f62a0 | 863 | wxLogMessage(_T("Control has been cleared")); |
80695f83 VZ |
864 | Clear(); |
865 | break; | |
866 | ||
2b5f62a0 | 867 | case WXK_F9: |
ab1ca7b3 | 868 | WriteText(_T("WriteText() has been called")); |
2b5f62a0 | 869 | break; |
18414479 | 870 | |
2b5f62a0 | 871 | case WXK_F10: |
ab1ca7b3 | 872 | AppendText(_T("AppendText() has been called")); |
2b5f62a0 | 873 | break; |
0ddea946 | 874 | } |
02e8b87f | 875 | |
1ce58dc6 | 876 | if ( ms_logKey ) |
94ccc254 | 877 | LogKeyEvent( wxT("Key down"), event); |
f6bcfd97 | 878 | |
02e8b87f RR |
879 | event.Skip(); |
880 | } | |
881 | ||
882 | //---------------------------------------------------------------------- | |
883 | // MyPanel | |
884 | //---------------------------------------------------------------------- | |
885 | ||
89124b1a RR |
886 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) |
887 | EVT_SIZE(MyPanel::OnSize) | |
888 | END_EVENT_TABLE() | |
889 | ||
02e8b87f | 890 | MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) |
effbd41d | 891 | : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) ) |
02e8b87f | 892 | { |
b29903d4 | 893 | #if wxUSE_LOG |
effbd41d | 894 | m_log = new wxTextCtrl( this, wxID_ANY, _T("This is the log window.\n"), |
30982415 VZ |
895 | wxPoint(5,260), wxSize(630,100), |
896 | wxTE_MULTILINE | wxTE_READONLY /* | wxTE_RICH */); | |
02e8b87f | 897 | |
d847e69a | 898 | m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); |
b29903d4 | 899 | #endif // wxUSE_LOG |
02e8b87f RR |
900 | |
901 | // single line text controls | |
902 | ||
effbd41d | 903 | m_text = new MyTextCtrl( this, wxID_ANY, _T("Single line."), |
b29903d4 | 904 | wxDefaultPosition, wxDefaultSize, |
f6bcfd97 | 905 | wxTE_PROCESS_ENTER); |
4ed0aceb VZ |
906 | m_text->SetForegroundColour(*wxBLUE); |
907 | m_text->SetBackgroundColour(*wxLIGHT_GREY); | |
ab1ca7b3 | 908 | (*m_text) << _T(" Appended."); |
02e8b87f | 909 | m_text->SetInsertionPoint(0); |
ab1ca7b3 | 910 | m_text->WriteText( _T("Prepended. ") ); |
bb69661b | 911 | |
effbd41d | 912 | m_password = new MyTextCtrl( this, wxID_ANY, _T(""), |
422d0ff0 | 913 | wxPoint(10,50), wxSize(140,wxDefaultCoord), wxTE_PASSWORD ); |
bb69661b | 914 | |
effbd41d | 915 | m_readonly = new MyTextCtrl( this, wxID_ANY, _T("Read only"), |
422d0ff0 | 916 | wxPoint(10,90), wxSize(140,wxDefaultCoord), wxTE_READONLY ); |
bb69661b | 917 | |
effbd41d | 918 | m_limited = new MyTextCtrl(this, wxID_ANY, _T("Max 8 ch"), |
422d0ff0 | 919 | wxPoint(10, 130), wxSize(140, wxDefaultCoord)); |
d7eee191 VZ |
920 | m_limited->SetMaxLength(8); |
921 | ||
02e8b87f RR |
922 | // multi line text controls |
923 | ||
b7f5f3cc VZ |
924 | m_horizontal = new MyTextCtrl( this, wxID_ANY, _T("Multiline text control with a horizontal scrollbar.\n"), |
925 | wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL); | |
f6bcfd97 BP |
926 | |
927 | // a little hack to use the command line argument for encoding testing | |
928 | if ( wxTheApp->argc == 2 ) | |
929 | { | |
930 | switch ( wxTheApp->argv[1][0] ) | |
931 | { | |
932 | case '2': | |
933 | m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL, | |
effbd41d | 934 | false, _T(""), |
f6bcfd97 | 935 | wxFONTENCODING_ISO8859_2)); |
b7f5f3cc | 936 |