]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: typetest.cpp | |
3 | // Purpose: Types wxWidgets sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "typetest.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/variant.h" | |
28 | #include "wx/mimetype.h" | |
29 | ||
30 | #include "typetest.h" | |
31 | ||
32 | #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) | |
33 | #include "mondrian.xpm" | |
34 | #endif | |
35 | ||
36 | #ifdef new | |
37 | #undef new | |
38 | #endif | |
39 | ||
40 | #include "wx/ioswrap.h" | |
41 | ||
42 | #if wxUSE_IOSTREAMH | |
43 | #include <fstream.h> | |
44 | #else | |
45 | #include <fstream> | |
46 | #endif | |
47 | ||
48 | #include "wx/wfstream.h" | |
49 | #include "wx/datstrm.h" | |
50 | #include "wx/txtstrm.h" | |
51 | #include "wx/mstream.h" | |
52 | ||
53 | // Create a new application object | |
54 | IMPLEMENT_APP (MyApp) | |
55 | ||
56 | IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp) | |
57 | ||
58 | BEGIN_EVENT_TABLE(MyApp, wxApp) | |
59 | EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo) | |
60 | EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo) | |
61 | #if wxUSE_UNICODE | |
62 | EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo) | |
63 | #endif // wxUSE_UNICODE | |
64 | EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo) | |
65 | EVT_MENU(TYPES_STREAM2, MyApp::DoStreamDemo2) | |
66 | EVT_MENU(TYPES_STREAM3, MyApp::DoStreamDemo3) | |
67 | EVT_MENU(TYPES_STREAM4, MyApp::DoStreamDemo4) | |
68 | EVT_MENU(TYPES_STREAM5, MyApp::DoStreamDemo5) | |
69 | EVT_MENU(TYPES_STREAM6, MyApp::DoStreamDemo6) | |
70 | EVT_MENU(TYPES_STREAM7, MyApp::DoStreamDemo7) | |
71 | EVT_MENU(TYPES_MIME, MyApp::DoMIMEDemo) | |
72 | END_EVENT_TABLE() | |
73 | ||
74 | bool MyApp::OnInit() | |
75 | { | |
76 | // Create the main frame window | |
77 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets Types Demo"), | |
78 | wxPoint(50, 50), wxSize(450, 340)); | |
79 | ||
80 | // Give it an icon | |
81 | frame->SetIcon(wxICON(mondrian)); | |
82 | ||
83 | // Make a menubar | |
84 | wxMenu *file_menu = new wxMenu; | |
85 | ||
86 | file_menu->Append(TYPES_ABOUT, _T("&About")); | |
87 | file_menu->AppendSeparator(); | |
88 | file_menu->Append(TYPES_QUIT, _T("E&xit\tAlt-X")); | |
89 | ||
90 | wxMenu *test_menu = new wxMenu; | |
91 | test_menu->Append(TYPES_VARIANT, _T("&Variant test")); | |
92 | test_menu->Append(TYPES_BYTEORDER, _T("&Byteorder test")); | |
93 | #if wxUSE_UNICODE | |
94 | test_menu->Append(TYPES_UNICODE, _T("&Unicode test")); | |
95 | #endif // wxUSE_UNICODE | |
96 | test_menu->Append(TYPES_STREAM, _T("&Stream test")); | |
97 | test_menu->Append(TYPES_STREAM2, _T("&Stream seek test")); | |
98 | test_menu->Append(TYPES_STREAM3, _T("&Stream error test")); | |
99 | test_menu->Append(TYPES_STREAM4, _T("&Stream buffer test")); | |
100 | test_menu->Append(TYPES_STREAM5, _T("&Stream peek test")); | |
101 | test_menu->Append(TYPES_STREAM6, _T("&Stream ungetch test")); | |
102 | test_menu->Append(TYPES_STREAM7, _T("&Stream ungetch test for a buffered stream")); | |
103 | test_menu->AppendSeparator(); | |
104 | test_menu->Append(TYPES_MIME, _T("&MIME database test")); | |
105 | ||
106 | wxMenuBar *menu_bar = new wxMenuBar; | |
107 | menu_bar->Append(file_menu, _T("&File")); | |
108 | menu_bar->Append(test_menu, _T("&Tests")); | |
109 | frame->SetMenuBar(menu_bar); | |
110 | ||
111 | m_textCtrl = new wxTextCtrl(frame, wxID_ANY, wxEmptyString, | |
112 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); | |
113 | ||
114 | // Show the frame | |
115 | frame->Show(true); | |
116 | ||
117 | SetTopWindow(frame); | |
118 | ||
119 | return true; | |
120 | } | |
121 | ||
122 | void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) | |
123 | { | |
124 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
125 | ||
126 | textCtrl.Clear(); | |
127 | textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n"); | |
128 | ||
129 | textCtrl.WriteText( _T("Writing to ofstream and wxFileOutputStream:\n") ); | |
130 | ||
131 | wxSTD ofstream std_file_output( "test_std.dat" ); | |
132 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
133 | wxBufferedOutputStream buf_output( file_output ); | |
134 | wxTextOutputStream text_output( buf_output ); | |
135 | ||
136 | wxString tmp; | |
137 | signed int si = 0xFFFFFFFF; | |
138 | tmp.Printf( _T("Signed int: %d\n"), si ); | |
139 | textCtrl.WriteText( tmp ); | |
140 | text_output << si << _T("\n"); | |
141 | std_file_output << si << "\n"; | |
142 | ||
143 | unsigned int ui = 0xFFFFFFFF; | |
144 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); | |
145 | textCtrl.WriteText( tmp ); | |
146 | text_output << ui << _T("\n"); | |
147 | std_file_output << ui << "\n"; | |
148 | ||
149 | double d = 2.01234567890123456789; | |
150 | tmp.Printf( _T("Double: %f\n"), d ); | |
151 | textCtrl.WriteText( tmp ); | |
152 | text_output << d << _T("\n"); | |
153 | std_file_output << d << "\n"; | |
154 | ||
155 | float f = (float)0.00001; | |
156 | tmp.Printf( _T("Float: %f\n"), f ); | |
157 | textCtrl.WriteText( tmp ); | |
158 | text_output << f << _T("\n"); | |
159 | std_file_output << f << "\n"; | |
160 | ||
161 | wxString str( _T("Hello!") ); | |
162 | tmp.Printf( _T("String: %s\n"), str.c_str() ); | |
163 | textCtrl.WriteText( tmp ); | |
164 | text_output << str << _T("\n"); | |
165 | std_file_output << str.ToAscii() << "\n"; | |
166 | ||
167 | textCtrl.WriteText( _T("\nReading from ifstream:\n") ); | |
168 | ||
169 | wxSTD ifstream std_file_input( "test_std.dat" ); | |
170 | ||
171 | std_file_input >> si; | |
172 | tmp.Printf( _T("Signed int: %d\n"), si ); | |
173 | textCtrl.WriteText( tmp ); | |
174 | ||
175 | std_file_input >> ui; | |
176 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); | |
177 | textCtrl.WriteText( tmp ); | |
178 | ||
179 | std_file_input >> d; | |
180 | tmp.Printf( _T("Double: %f\n"), d ); | |
181 | textCtrl.WriteText( tmp ); | |
182 | ||
183 | std_file_input >> f; | |
184 | tmp.Printf( _T("Float: %f\n"), f ); | |
185 | textCtrl.WriteText( tmp ); | |
186 | ||
187 | char std_buf[200]; | |
188 | std_file_input >> std_buf; | |
189 | str.FromAscii(std_buf); | |
190 | tmp.Printf( _T("String: %s\n"), str.c_str() ); | |
191 | textCtrl.WriteText( tmp ); | |
192 | ||
193 | textCtrl.WriteText( _T("\nReading from wxFileInputStream:\n") ); | |
194 | ||
195 | buf_output.Sync(); | |
196 | ||
197 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
198 | wxBufferedInputStream buf_input( file_input ); | |
199 | wxTextInputStream text_input( file_input ); | |
200 | ||
201 | text_input >> si; | |
202 | tmp.Printf( _T("Signed int: %d\n"), si ); | |
203 | textCtrl.WriteText( tmp ); | |
204 | ||
205 | text_input >> ui; | |
206 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); | |
207 | textCtrl.WriteText( tmp ); | |
208 | ||
209 | text_input >> d; | |
210 | tmp.Printf( _T("Double: %f\n"), d ); | |
211 | textCtrl.WriteText( tmp ); | |
212 | ||
213 | text_input >> f; | |
214 | tmp.Printf( _T("Float: %f\n"), f ); | |
215 | textCtrl.WriteText( tmp ); | |
216 | ||
217 | text_input >> str; | |
218 | tmp.Printf( _T("String: %s\n"), str.c_str() ); | |
219 | textCtrl.WriteText( tmp ); | |
220 | ||
221 | ||
222 | ||
223 | textCtrl << _T("\nTest for wxDataStream:\n\n"); | |
224 | ||
225 | textCtrl.WriteText( _T("Writing to wxDataOutputStream:\n") ); | |
226 | ||
227 | file_output.SeekO( 0 ); | |
228 | wxDataOutputStream data_output( buf_output ); | |
229 | ||
230 | wxInt16 i16 = (unsigned short)0xFFFF; | |
231 | tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); | |
232 | textCtrl.WriteText( tmp ); | |
233 | data_output.Write16( i16 ); | |
234 | ||
235 | wxUint16 ui16 = 0xFFFF; | |
236 | tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); | |
237 | textCtrl.WriteText( tmp ); | |
238 | data_output.Write16( ui16 ); | |
239 | ||
240 | d = 2.01234567890123456789; | |
241 | tmp.Printf( _T("Double: %f\n"), d ); | |
242 | textCtrl.WriteText( tmp ); | |
243 | data_output.WriteDouble( d ); | |
244 | ||
245 | str = _T("Hello!"); | |
246 | tmp.Printf( _T("String: %s\n"), str.c_str() ); | |
247 | textCtrl.WriteText( tmp ); | |
248 | data_output.WriteString( str ); | |
249 | ||
250 | buf_output.Sync(); | |
251 | ||
252 | textCtrl.WriteText( _T("\nReading from wxDataInputStream:\n") ); | |
253 | ||
254 | file_input.SeekI( 0 ); | |
255 | wxDataInputStream data_input( buf_input ); | |
256 | ||
257 | i16 = data_input.Read16(); | |
258 | tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); | |
259 | textCtrl.WriteText( tmp ); | |
260 | ||
261 | ui16 = data_input.Read16(); | |
262 | tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); | |
263 | textCtrl.WriteText( tmp ); | |
264 | ||
265 | d = data_input.ReadDouble(); | |
266 | tmp.Printf( _T("Double: %f\n"), d ); | |
267 | textCtrl.WriteText( tmp ); | |
268 | ||
269 | str = data_input.ReadString(); | |
270 | tmp.Printf( _T("String: %s\n"), str.c_str() ); | |
271 | textCtrl.WriteText( tmp ); | |
272 | } | |
273 | ||
274 | void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event)) | |
275 | { | |
276 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
277 | ||
278 | textCtrl.Clear(); | |
279 | textCtrl << _T("\nTesting wxBufferedStream:\n\n"); | |
280 | ||
281 | char ch,ch2; | |
282 | ||
283 | textCtrl.WriteText( _T("Writing number 0 to 9 to buffered wxFileOutputStream:\n\n") ); | |
284 | ||
285 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
286 | wxBufferedOutputStream buf_output( file_output ); | |
287 | for (ch = 0; ch < 10; ch++) | |
288 | buf_output.Write( &ch, 1 ); | |
289 | buf_output.Sync(); | |
290 | ||
291 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
292 | for (ch2 = 0; ch2 < 10; ch2++) | |
293 | { | |
294 | file_input.Read( &ch, 1 ); | |
295 | textCtrl.WriteText( (wxChar)(ch + _T('0')) ); | |
296 | } | |
297 | textCtrl.WriteText( _T("\n\n\n") ); | |
298 | ||
299 | textCtrl.WriteText( _T("Writing number 0 to 9 to buffered wxFileOutputStream, then\n") ); | |
300 | textCtrl.WriteText( _T("seeking back to #3 and writing 0:\n\n") ); | |
301 | ||
302 | wxFileOutputStream file_output2( wxString(_T("test_wx2.dat")) ); | |
303 | wxBufferedOutputStream buf_output2( file_output2 ); | |
304 | for (ch = 0; ch < 10; ch++) | |
305 | buf_output2.Write( &ch, 1 ); | |
306 | buf_output2.SeekO( 3 ); | |
307 | ch = 0; | |
308 | buf_output2.Write( &ch, 1 ); | |
309 | buf_output2.Sync(); | |
310 | ||
311 | wxFileInputStream file_input2( wxString(_T("test_wx2.dat")) ); | |
312 | for (ch2 = 0; ch2 < 10; ch2++) | |
313 | { | |
314 | file_input2.Read( &ch, 1 ); | |
315 | textCtrl.WriteText( (wxChar)(ch + _T('0')) ); | |
316 | } | |
317 | textCtrl.WriteText( _T("\n\n\n") ); | |
318 | ||
319 | // now append 2000 bytes to file (bigger than buffer) | |
320 | buf_output2.SeekO( 0, wxFromEnd ); | |
321 | ch = 1; | |
322 | for (int i = 0; i < 2000; i++) | |
323 | buf_output2.Write( &ch, 1 ); | |
324 | buf_output2.Sync(); | |
325 | ||
326 | textCtrl.WriteText( _T("Reading number 0 to 9 from buffered wxFileInputStream, then\n") ); | |
327 | textCtrl.WriteText( _T("seeking back to #3 and reading the 0:\n\n") ); | |
328 | ||
329 | wxFileInputStream file_input3( wxString(_T("test_wx2.dat")) ); | |
330 | wxBufferedInputStream buf_input3( file_input3 ); | |
331 | for (ch2 = 0; ch2 < 10; ch2++) | |
332 | { | |
333 | buf_input3.Read( &ch, 1 ); | |
334 | textCtrl.WriteText( (wxChar)(ch + _T('0')) ); | |
335 | } | |
336 | for (int j = 0; j < 2000; j++) | |
337 | buf_input3.Read( &ch, 1 ); | |
338 | textCtrl.WriteText( _T("\n") ); | |
339 | buf_input3.SeekI( 3 ); | |
340 | buf_input3.Read( &ch, 1 ); | |
341 | textCtrl.WriteText( (wxChar)(ch + _T('0')) ); | |
342 | textCtrl.WriteText( _T("\n\n\n") ); | |
343 | ||
344 | } | |
345 | ||
346 | void MyApp::DoStreamDemo3(wxCommandEvent& WXUNUSED(event)) | |
347 | { | |
348 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
349 | ||
350 | textCtrl.Clear(); | |
351 | textCtrl << _T("\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n"); | |
352 | ||
353 | char ch,ch2; | |
354 | ||
355 | textCtrl.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream:\n\n") ); | |
356 | ||
357 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
358 | for (ch = 0; ch < 10; ch++) | |
359 | file_output.Write( &ch, 1 ); | |
360 | ||
361 | // Testing wxFileInputStream | |
362 | ||
363 | textCtrl.WriteText( _T("Reading 0 to 10 to wxFileInputStream:\n\n") ); | |
364 | ||
365 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
366 | for (ch2 = 0; ch2 < 11; ch2++) | |
367 | { | |
368 | file_input.Read( &ch, 1 ); | |
369 | textCtrl.WriteText( _T("Value read: ") ); | |
370 | textCtrl.WriteText( (wxChar)(ch + '0') ); | |
371 | textCtrl.WriteText( _T("; stream.GetLastError() returns: ") ); | |
372 | switch (file_input.GetLastError()) | |
373 | { | |
374 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
375 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
376 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
377 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
378 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
379 | } | |
380 | } | |
381 | textCtrl.WriteText( _T("\n") ); | |
382 | ||
383 | textCtrl.WriteText( _T("Seeking to 0; stream.GetLastError() returns: ") ); | |
384 | file_input.SeekI( 0 ); | |
385 | switch (file_input.GetLastError()) | |
386 | { | |
387 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
388 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
389 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
390 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
391 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
392 | } | |
393 | textCtrl.WriteText( _T("\n") ); | |
394 | ||
395 | file_input.Read( &ch, 1 ); | |
396 | textCtrl.WriteText( _T("Value read: ") ); | |
397 | textCtrl.WriteText( (wxChar)(ch + _T('0')) ); | |
398 | textCtrl.WriteText( _T("; stream.GetLastError() returns: ") ); | |
399 | switch (file_input.GetLastError()) | |
400 | { | |
401 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
402 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
403 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
404 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
405 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
406 | } | |
407 | textCtrl.WriteText( _T("\n\n") ); | |
408 | ||
409 | ||
410 | // Testing wxFFileInputStream | |
411 | ||
412 | textCtrl.WriteText( _T("Reading 0 to 10 to wxFFileInputStream:\n\n") ); | |
413 | ||
414 | wxFFileInputStream ffile_input( wxString(_T("test_wx.dat")) ); | |
415 | for (ch2 = 0; ch2 < 11; ch2++) | |
416 | { | |
417 | ffile_input.Read( &ch, 1 ); | |
418 | textCtrl.WriteText( _T("Value read: ") ); | |
419 | textCtrl.WriteText( (wxChar)(ch + '0') ); | |
420 | textCtrl.WriteText( _T("; stream.GetLastError() returns: ") ); | |
421 | switch (ffile_input.GetLastError()) | |
422 | { | |
423 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
424 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
425 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
426 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
427 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
428 | } | |
429 | } | |
430 | textCtrl.WriteText( _T("\n") ); | |
431 | ||
432 | textCtrl.WriteText( _T("Seeking to 0; stream.GetLastError() returns: ") ); | |
433 | ffile_input.SeekI( 0 ); | |
434 | switch (ffile_input.GetLastError()) | |
435 | { | |
436 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
437 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
438 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
439 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
440 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
441 | } | |
442 | textCtrl.WriteText( _T("\n") ); | |
443 | ||
444 | ffile_input.Read( &ch, 1 ); | |
445 | textCtrl.WriteText( _T("Value read: ") ); | |
446 | textCtrl.WriteText( (wxChar)(ch + '0') ); | |
447 | textCtrl.WriteText( _T("; stream.GetLastError() returns: ") ); | |
448 | switch (ffile_input.GetLastError()) | |
449 | { | |
450 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
451 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
452 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
453 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
454 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
455 | } | |
456 | textCtrl.WriteText( _T("\n\n") ); | |
457 | ||
458 | // Testing wxFFileInputStream | |
459 | ||
460 | textCtrl.WriteText( _T("Reading 0 to 10 to buffered wxFFileInputStream:\n\n") ); | |
461 | ||
462 | wxFFileInputStream ffile_input2( wxString(_T("test_wx.dat")) ); | |
463 | wxBufferedInputStream buf_input( ffile_input2 ); | |
464 | for (ch2 = 0; ch2 < 11; ch2++) | |
465 | { | |
466 | buf_input.Read( &ch, 1 ); | |
467 | textCtrl.WriteText( _T("Value read: ") ); | |
468 | textCtrl.WriteText( (wxChar)(ch + '0') ); | |
469 | textCtrl.WriteText( _T("; stream.GetLastError() returns: ") ); | |
470 | switch (buf_input.GetLastError()) | |
471 | { | |
472 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
473 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
474 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
475 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
476 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
477 | } | |
478 | } | |
479 | textCtrl.WriteText( _T("\n") ); | |
480 | ||
481 | textCtrl.WriteText( _T("Seeking to 0; stream.GetLastError() returns: ") ); | |
482 | buf_input.SeekI( 0 ); | |
483 | switch (buf_input.GetLastError()) | |
484 | { | |
485 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
486 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
487 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
488 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
489 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
490 | } | |
491 | textCtrl.WriteText( _T("\n") ); | |
492 | ||
493 | buf_input.Read( &ch, 1 ); | |
494 | textCtrl.WriteText( _T("Value read: ") ); | |
495 | textCtrl.WriteText( (wxChar)(ch + '0') ); | |
496 | textCtrl.WriteText( _T("; stream.GetLastError() returns: ") ); | |
497 | switch (buf_input.GetLastError()) | |
498 | { | |
499 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
500 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
501 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
502 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
503 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
504 | } | |
505 | } | |
506 | ||
507 | void MyApp::DoStreamDemo4(wxCommandEvent& WXUNUSED(event)) | |
508 | { | |
509 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
510 | ||
511 | wxString msg; | |
512 | ||
513 | textCtrl.Clear(); | |
514 | textCtrl << _T("\nTesting wxStreamBuffer:\n\n"); | |
515 | ||
516 | // bigger than buffer | |
517 | textCtrl.WriteText( _T("Writing 2000x 1 to wxFileOutputStream.\n\n") ); | |
518 | ||
519 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
520 | for (int i = 0; i < 2000; i++) | |
521 | { | |
522 | char ch = 1; | |
523 | file_output.Write( &ch, 1 ); | |
524 | } | |
525 | ||
526 | textCtrl.WriteText( _T("Opening with a buffered wxFileInputStream:\n\n") ); | |
527 | ||
528 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
529 | wxBufferedInputStream buf_input( file_input ); | |
530 | ||
531 | textCtrl.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") ); | |
532 | switch (buf_input.GetLastError()) | |
533 | { | |
534 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
535 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
536 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
537 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
538 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
539 | } | |
540 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); | |
541 | textCtrl.WriteText( msg ); | |
542 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); | |
543 | textCtrl.WriteText( msg ); | |
544 | textCtrl.WriteText( _T("\n\n") ); | |
545 | ||
546 | ||
547 | textCtrl.WriteText( _T("Seeking to position 300:\n\n") ); | |
548 | ||
549 | buf_input.SeekI( 300 ); | |
550 | ||
551 | textCtrl.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") ); | |
552 | switch (buf_input.GetLastError()) | |
553 | { | |
554 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
555 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
556 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
557 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
558 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
559 | } | |
560 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); | |
561 | textCtrl.WriteText( msg ); | |
562 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); | |
563 | textCtrl.WriteText( msg ); | |
564 | textCtrl.WriteText( _T("\n\n") ); | |
565 | ||
566 | ||
567 | char buf[2000]; | |
568 | ||
569 | textCtrl.WriteText( _T("Reading 500 bytes:\n\n") ); | |
570 | ||
571 | buf_input.Read( buf, 500 ); | |
572 | ||
573 | textCtrl.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") ); | |
574 | switch (buf_input.GetLastError()) | |
575 | { | |
576 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
577 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
578 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
579 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
580 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
581 | } | |
582 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); | |
583 | textCtrl.WriteText( msg ); | |
584 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); | |
585 | textCtrl.WriteText( msg ); | |
586 | textCtrl.WriteText( _T("\n\n") ); | |
587 | ||
588 | textCtrl.WriteText( _T("Reading another 500 bytes:\n\n") ); | |
589 | ||
590 | buf_input.Read( buf, 500 ); | |
591 | ||
592 | textCtrl.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") ); | |
593 | switch (buf_input.GetLastError()) | |
594 | { | |
595 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
596 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
597 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
598 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
599 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
600 | } | |
601 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); | |
602 | textCtrl.WriteText( msg ); | |
603 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); | |
604 | textCtrl.WriteText( msg ); | |
605 | textCtrl.WriteText( _T("\n\n") ); | |
606 | ||
607 | textCtrl.WriteText( _T("Reading another 500 bytes:\n\n") ); | |
608 | ||
609 | buf_input.Read( buf, 500 ); | |
610 | ||
611 | textCtrl.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") ); | |
612 | switch (buf_input.GetLastError()) | |
613 | { | |
614 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
615 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
616 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
617 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
618 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
619 | } | |
620 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); | |
621 | textCtrl.WriteText( msg ); | |
622 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); | |
623 | textCtrl.WriteText( msg ); | |
624 | textCtrl.WriteText( _T("\n\n") ); | |
625 | ||
626 | textCtrl.WriteText( _T("Reading another 500 bytes:\n\n") ); | |
627 | ||
628 | buf_input.Read( buf, 500 ); | |
629 | ||
630 | textCtrl.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") ); | |
631 | switch (buf_input.GetLastError()) | |
632 | { | |
633 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break; | |
634 | case wxSTREAM_EOF: textCtrl.WriteText( _T("wxSTREAM_EOF\n") ); break; | |
635 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break; | |
636 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break; | |
637 | default: textCtrl.WriteText( _T("Huh?\n") ); break; | |
638 | } | |
639 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); | |
640 | textCtrl.WriteText( msg ); | |
641 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); | |
642 | textCtrl.WriteText( msg ); | |
643 | textCtrl.WriteText( _T("\n\n") ); | |
644 | } | |
645 | ||
646 | void MyApp::DoStreamDemo5(wxCommandEvent& WXUNUSED(event)) | |
647 | { | |
648 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
649 | ||
650 | textCtrl.Clear(); | |
651 | textCtrl << _T("\nTesting wxFileInputStream's Peek():\n\n"); | |
652 | ||
653 | char ch; | |
654 | wxString str; | |
655 | ||
656 | textCtrl.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream:\n\n") ); | |
657 | ||
658 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
659 | for (ch = 0; ch < 10; ch++) | |
660 | file_output.Write( &ch, 1 ); | |
661 | ||
662 | file_output.Sync(); | |
663 | ||
664 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
665 | ||
666 | ch = file_input.Peek(); | |
667 | str.Printf( wxT("First char peeked: %d\n"), (int) ch ); | |
668 | textCtrl.WriteText( str ); | |
669 | ||
670 | ch = file_input.GetC(); | |
671 | str.Printf( wxT("First char read: %d\n"), (int) ch ); | |
672 | textCtrl.WriteText( str ); | |
673 | ||
674 | ch = file_input.Peek(); | |
675 | str.Printf( wxT("Second char peeked: %d\n"), (int) ch ); | |
676 | textCtrl.WriteText( str ); | |
677 | ||
678 | ch = file_input.GetC(); | |
679 | str.Printf( wxT("Second char read: %d\n"), (int) ch ); | |
680 | textCtrl.WriteText( str ); | |
681 | ||
682 | ch = file_input.Peek(); | |
683 | str.Printf( wxT("Third char peeked: %d\n"), (int) ch ); | |
684 | textCtrl.WriteText( str ); | |
685 | ||
686 | ch = file_input.GetC(); | |
687 | str.Printf( wxT("Third char read: %d\n"), (int) ch ); | |
688 | textCtrl.WriteText( str ); | |
689 | ||
690 | ||
691 | textCtrl << _T("\n\n\nTesting wxMemoryInputStream's Peek():\n\n"); | |
692 | ||
693 | char buf[] = { 0,1,2,3,4,5,6,7,8,9,10 }; | |
694 | wxMemoryInputStream input( buf, 10 ); | |
695 | ||
696 | ch = input.Peek(); | |
697 | str.Printf( wxT("First char peeked: %d\n"), (int) ch ); | |
698 | textCtrl.WriteText( str ); | |
699 | ||
700 | ch = input.GetC(); | |
701 | str.Printf( wxT("First char read: %d\n"), (int) ch ); | |
702 | textCtrl.WriteText( str ); | |
703 | ||
704 | ch = input.Peek(); | |
705 | str.Printf( wxT("Second char peeked: %d\n"), (int) ch ); | |
706 | textCtrl.WriteText( str ); | |
707 | ||
708 | ch = input.GetC(); | |
709 | str.Printf( wxT("Second char read: %d\n"), (int) ch ); | |
710 | textCtrl.WriteText( str ); | |
711 | ||
712 | ch = input.Peek(); | |
713 | str.Printf( wxT("Third char peeked: %d\n"), (int) ch ); | |
714 | textCtrl.WriteText( str ); | |
715 | ||
716 | ch = input.GetC(); | |
717 | str.Printf( wxT("Third char read: %d\n"), (int) ch ); | |
718 | textCtrl.WriteText( str ); | |
719 | } | |
720 | ||
721 | void MyApp::DoStreamDemo6(wxCommandEvent& WXUNUSED(event)) | |
722 | { | |
723 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
724 | ||
725 | textCtrl.Clear(); | |
726 | textCtrl.WriteText( _T("\nTesting Ungetch():\n\n") ); | |
727 | ||
728 | char ch = 0; | |
729 | wxString str; | |
730 | ||
731 | textCtrl.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream...\n\n") ); | |
732 | ||
733 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
734 | for (ch = 0; ch < 10; ch++) | |
735 | file_output.Write( &ch, 1 ); | |
736 | ||
737 | file_output.Sync(); | |
738 | ||
739 | textCtrl.WriteText( _T("Reading char from wxFileInputStream:\n\n") ); | |
740 | ||
741 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
742 | ||
743 | ch = file_input.GetC(); | |
744 | size_t pos = file_input.TellI(); | |
745 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
746 | textCtrl.WriteText( str ); | |
747 | ||
748 | textCtrl.WriteText( _T("Reading another char from wxFileInputStream:\n\n") ); | |
749 | ||
750 | ch = file_input.GetC(); | |
751 | pos = file_input.TellI(); | |
752 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
753 | textCtrl.WriteText( str ); | |
754 | ||
755 | textCtrl.WriteText( _T("Reading yet another char from wxFileInputStream:\n\n") ); | |
756 | ||
757 | ch = file_input.GetC(); | |
758 | pos = file_input.TellI(); | |
759 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
760 | textCtrl.WriteText( str ); | |
761 | ||
762 | textCtrl.WriteText( _T("Now calling Ungetch( 5 ) from wxFileInputStream...\n\n") ); | |
763 | ||
764 | file_input.Ungetch( 5 ); | |
765 | pos = file_input.TellI(); | |
766 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); | |
767 | textCtrl.WriteText( str ); | |
768 | ||
769 | textCtrl.WriteText( _T("Reading char from wxFileInputStream:\n\n") ); | |
770 | ||
771 | ch = file_input.GetC(); | |
772 | pos = file_input.TellI(); | |
773 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
774 | textCtrl.WriteText( str ); | |
775 | ||
776 | textCtrl.WriteText( _T("Reading another char from wxFileInputStream:\n\n") ); | |
777 | ||
778 | ch = file_input.GetC(); | |
779 | pos = file_input.TellI(); | |
780 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
781 | textCtrl.WriteText( str ); | |
782 | ||
783 | textCtrl.WriteText( _T("Now calling Ungetch( 5 ) from wxFileInputStream again...\n\n") ); | |
784 | ||
785 | file_input.Ungetch( 5 ); | |
786 | pos = file_input.TellI(); | |
787 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); | |
788 | textCtrl.WriteText( str ); | |
789 | ||
790 | textCtrl.WriteText( _T("Seeking to pos 3 in wxFileInputStream. This invalidates the writeback buffer.\n\n") ); | |
791 | ||
792 | file_input.SeekI( 3 ); | |
793 | ||
794 | ch = file_input.GetC(); | |
795 | pos = file_input.TellI(); | |
796 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
797 | textCtrl.WriteText( str ); | |
798 | } | |
799 | ||
800 | void MyApp::DoStreamDemo7(wxCommandEvent& WXUNUSED(event)) | |
801 | { | |
802 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
803 | ||
804 | textCtrl.Clear(); | |
805 | textCtrl.WriteText( _T("\nTesting Ungetch() in buffered input stream:\n\n") ); | |
806 | ||
807 | char ch = 0; | |
808 | wxString str; | |
809 | ||
810 | textCtrl.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream...\n\n") ); | |
811 | ||
812 | wxFileOutputStream file_output( wxString(_T("test_wx.dat")) ); | |
813 | for (ch = 0; ch < 10; ch++) | |
814 | file_output.Write( &ch, 1 ); | |
815 | ||
816 | file_output.Sync(); | |
817 | ||
818 | textCtrl.WriteText( _T("Reading char from wxBufferedInputStream via wxFileInputStream:\n\n") ); | |
819 | ||
820 | wxFileInputStream file_input( wxString(_T("test_wx.dat")) ); | |
821 | wxBufferedInputStream buf_input( file_input ); | |
822 | ||
823 | ch = buf_input.GetC(); | |
824 | size_t pos = buf_input.TellI(); | |
825 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
826 | textCtrl.WriteText( str ); | |
827 | ||
828 | textCtrl.WriteText( _T("Reading another char from wxBufferedInputStream:\n\n") ); | |
829 | ||
830 | ch = buf_input.GetC(); | |
831 | pos = buf_input.TellI(); | |
832 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
833 | textCtrl.WriteText( str ); | |
834 | ||
835 | textCtrl.WriteText( _T("Reading yet another char from wxBufferedInputStream:\n\n") ); | |
836 | ||
837 | ch = buf_input.GetC(); | |
838 | pos = buf_input.TellI(); | |
839 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
840 | textCtrl.WriteText( str ); | |
841 | ||
842 | textCtrl.WriteText( _T("Now calling Ungetch( 5 ) from wxBufferedInputStream...\n\n") ); | |
843 | ||
844 | buf_input.Ungetch( 5 ); | |
845 | pos = buf_input.TellI(); | |
846 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); | |
847 | textCtrl.WriteText( str ); | |
848 | ||
849 | textCtrl.WriteText( _T("Reading char from wxBufferedInputStream:\n\n") ); | |
850 | ||
851 | ch = buf_input.GetC(); | |
852 | pos = buf_input.TellI(); | |
853 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
854 | textCtrl.WriteText( str ); | |
855 | ||
856 | textCtrl.WriteText( _T("Reading another char from wxBufferedInputStream:\n\n") ); | |
857 | ||
858 | ch = buf_input.GetC(); | |
859 | pos = buf_input.TellI(); | |
860 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
861 | textCtrl.WriteText( str ); | |
862 | ||
863 | textCtrl.WriteText( _T("Now calling Ungetch( 5 ) from wxBufferedInputStream again...\n\n") ); | |
864 | ||
865 | buf_input.Ungetch( 5 ); | |
866 | pos = buf_input.TellI(); | |
867 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); | |
868 | textCtrl.WriteText( str ); | |
869 | ||
870 | textCtrl.WriteText( _T("Seeking to pos 3 in wxBufferedInputStream. This invalidates the writeback buffer.\n\n") ); | |
871 | ||
872 | buf_input.SeekI( 3 ); | |
873 | ||
874 | ch = buf_input.GetC(); | |
875 | pos = buf_input.TellI(); | |
876 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); | |
877 | textCtrl.WriteText( str ); | |
878 | } | |
879 | ||
880 | #if wxUSE_UNICODE | |
881 | void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event)) | |
882 | { | |
883 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
884 | ||
885 | textCtrl.Clear(); | |
886 | textCtrl << _T("\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:"); | |
887 | ||
888 | wxString str; | |
889 |