]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/typetest/typetest.cpp
Fix for VA 4.0
[wxWidgets.git] / samples / typetest / typetest.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: typetest.cpp
3// Purpose: Types wxWindows sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
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/time.h"
28#include "wx/date.h"
29#include "wx/variant.h"
30#include "wx/mimetype.h"
31
32#include "typetest.h"
33
34#if defined(__WXGTK__) || defined(__WXMOTIF__)
35#include "mondrian.xpm"
36#endif
37
38#include "wx/ioswrap.h"
39
40#if wxUSE_IOSTREAMH
41 #include <fstream.h>
42#else
43 #include <fstream>
44#endif
45
46#include "wx/wfstream.h"
47#include "wx/datstrm.h"
48#include "wx/txtstrm.h"
49
50// Create a new application object
51IMPLEMENT_APP (MyApp)
52
53IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp)
54
55BEGIN_EVENT_TABLE(MyApp, wxApp)
56 EVT_MENU(TYPES_DATE, MyApp::DoDateDemo)
57 EVT_MENU(TYPES_TIME, MyApp::DoTimeDemo)
58 EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo)
59 EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo)
60#if wxUSE_UNICODE
61 EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo)
62#endif
63 EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo)
64 EVT_MENU(TYPES_STREAM2, MyApp::DoStreamDemo2)
65 EVT_MENU(TYPES_STREAM3, MyApp::DoStreamDemo3)
66 EVT_MENU(TYPES_STREAM4, MyApp::DoStreamDemo4)
67 EVT_MENU(TYPES_MIME, MyApp::DoMIMEDemo)
68END_EVENT_TABLE()
69
70bool MyApp::OnInit()
71{
72 // Create the main frame window
73 MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxWindows Types Demo",
74 wxPoint(50, 50), wxSize(450, 340));
75
76 // Give it an icon
77 frame->SetIcon(wxICON(mondrian));
78
79 // Make a menubar
80 wxMenu *file_menu = new wxMenu;
81
82 file_menu->Append(TYPES_ABOUT, "&About");
83 file_menu->AppendSeparator();
84 file_menu->Append(TYPES_QUIT, "E&xit\tAlt-X");
85
86 wxMenu *test_menu = new wxMenu;
87 test_menu->Append(TYPES_DATE, "&Date test");
88 test_menu->Append(TYPES_TIME, "&Time test");
89 test_menu->Append(TYPES_VARIANT, "&Variant test");
90 test_menu->Append(TYPES_BYTEORDER, "&Byteorder test");
91#if wxUSE_UNICODE
92 test_menu->Append(TYPES_UNICODE, "&Unicode test");
93#endif
94 test_menu->Append(TYPES_STREAM, "&Stream test");
95 test_menu->Append(TYPES_STREAM2, "&Stream seek test");
96 test_menu->Append(TYPES_STREAM3, "&Stream error test");
97 test_menu->Append(TYPES_STREAM4, "&Stream buffer test");
98 test_menu->AppendSeparator();
99 test_menu->Append(TYPES_MIME, "&MIME database test");
100
101 wxMenuBar *menu_bar = new wxMenuBar;
102 menu_bar->Append(file_menu, "&File");
103 menu_bar->Append(test_menu, "&Tests");
104 frame->SetMenuBar(menu_bar);
105
106 m_textCtrl = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE);
107
108 // Show the frame
109 frame->Show(TRUE);
110
111 SetTopWindow(frame);
112
113 return TRUE;
114}
115
116void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
117{
118 wxTextCtrl& textCtrl = * GetTextCtrl();
119
120 textCtrl.Clear();
121 textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n");
122
123 textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
124
125 ofstream std_file_output( "test_std.dat" );
126 wxFileOutputStream file_output( wxString("test_wx.dat") );
127 wxBufferedOutputStream buf_output( file_output );
128 wxTextOutputStream text_output( buf_output );
129
130 wxString tmp;
131 signed int si = 0xFFFFFFFF;
132 tmp.Printf( _T("Signed int: %d\n"), si );
133 textCtrl.WriteText( tmp );
134 text_output << si << "\n";
135 std_file_output << si << "\n";
136
137 unsigned int ui = 0xFFFFFFFF;
138 tmp.Printf( _T("Unsigned int: %u\n"), ui );
139 textCtrl.WriteText( tmp );
140 text_output << ui << "\n";
141 std_file_output << ui << "\n";
142
143 double d = 2.01234567890123456789;
144 tmp.Printf( _T("Double: %f\n"), d );
145 textCtrl.WriteText( tmp );
146 text_output << d << "\n";
147 std_file_output << d << "\n";
148
149 float f = (float)0.00001;
150 tmp.Printf( _T("Float: %f\n"), f );
151 textCtrl.WriteText( tmp );
152 text_output << f << "\n";
153 std_file_output << f << "\n";
154
155 wxString str( _T("Hello!") );
156 tmp.Printf( _T("String: %s\n"), str.c_str() );
157 textCtrl.WriteText( tmp );
158 text_output << str << "\n";
159 std_file_output << str.c_str() << "\n";
160
161 textCtrl.WriteText( "\nReading from ifstream:\n" );
162
163 ifstream std_file_input( "test_std.dat" );
164
165 std_file_input >> si;
166 tmp.Printf( _T("Signed int: %d\n"), si );
167 textCtrl.WriteText( tmp );
168
169 std_file_input >> ui;
170 tmp.Printf( _T("Unsigned int: %u\n"), ui );
171 textCtrl.WriteText( tmp );
172
173 std_file_input >> d;
174 tmp.Printf( _T("Double: %f\n"), d );
175 textCtrl.WriteText( tmp );
176
177 std_file_input >> f;
178 tmp.Printf( _T("Float: %f\n"), f );
179 textCtrl.WriteText( tmp );
180
181 // This doesn't compile (at least with VC++ 4)
182#if 0
183 std_file_input >> str;
184 tmp.Printf( _T("String: %s\n"), str.c_str() );
185 textCtrl.WriteText( tmp );
186#endif
187
188 textCtrl.WriteText( "\nReading from wxFileInputStream:\n" );
189
190 buf_output.Sync();
191
192 wxFileInputStream file_input( wxString("test_wx.dat") );
193 wxBufferedInputStream buf_input( file_input );
194 wxTextInputStream text_input( file_input );
195
196 text_input >> si;
197 tmp.Printf( _T("Signed int: %d\n"), si );
198 textCtrl.WriteText( tmp );
199
200 text_input >> ui;
201 tmp.Printf( _T("Unsigned int: %u\n"), ui );
202 textCtrl.WriteText( tmp );
203
204 text_input >> d;
205 tmp.Printf( _T("Double: %f\n"), d );
206 textCtrl.WriteText( tmp );
207
208 text_input >> f;
209 tmp.Printf( _T("Float: %f\n"), f );
210 textCtrl.WriteText( tmp );
211
212 text_input >> str;
213 tmp.Printf( _T("String: %s\n"), str.c_str() );
214 textCtrl.WriteText( tmp );
215
216
217 textCtrl << "\nTest for wxDataStream:\n\n";
218
219 textCtrl.WriteText( "Writing to wxDataOutputStream:\n" );
220
221 file_output.SeekO( 0 );
222 wxDataOutputStream data_output( buf_output );
223
224 wxInt16 i16 = (short)0xFFFF;
225 tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
226 textCtrl.WriteText( tmp );
227 data_output.Write16( i16 );
228
229 wxUint16 ui16 = 0xFFFF;
230 tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
231 textCtrl.WriteText( tmp );
232 data_output.Write16( ui16 );
233
234 d = 2.01234567890123456789;
235 tmp.Printf( _T("Double: %f\n"), d );
236 textCtrl.WriteText( tmp );
237 data_output.WriteDouble( d );
238
239 str = "Hello!";
240 tmp.Printf( _T("String: %s\n"), str.c_str() );
241 textCtrl.WriteText( tmp );
242 data_output.WriteString( str );
243
244 buf_output.Sync();
245
246 textCtrl.WriteText( "\nReading from wxDataInputStream:\n" );
247
248 file_input.SeekI( 0 );
249 wxDataInputStream data_input( buf_input );
250
251 i16 = data_input.Read16();
252 tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
253 textCtrl.WriteText( tmp );
254
255 ui16 = data_input.Read16();
256 tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
257 textCtrl.WriteText( tmp );
258
259 d = data_input.ReadDouble();
260 tmp.Printf( _T("Double: %f\n"), d );
261 textCtrl.WriteText( tmp );
262
263 str = data_input.ReadString();
264 tmp.Printf( _T("String: %s\n"), str.c_str() );
265 textCtrl.WriteText( tmp );
266}
267
268void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event))
269{
270 wxTextCtrl& textCtrl = * GetTextCtrl();
271
272 textCtrl.Clear();
273 textCtrl << _T("\nTesting wxBufferedStream:\n\n");
274
275 char ch,ch2;
276
277 textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
278
279 wxFileOutputStream file_output( wxString("test_wx.dat") );
280 wxBufferedOutputStream buf_output( file_output );
281 for (ch = 0; ch < 10; ch++)
282 buf_output.Write( &ch, 1 );
283 buf_output.Sync();
284
285 wxFileInputStream file_input( wxString("test_wx.dat") );
286 for (ch2 = 0; ch2 < 10; ch2++)
287 {
288 file_input.Read( &ch, 1 );
289 textCtrl.WriteText( (char)(ch + '0') );
290 }
291 textCtrl.WriteText( "\n\n\n" );
292
293 textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
294 textCtrl.WriteText( "seeking back to #3 and writing 3:\n\n" );
295
296 wxFileOutputStream file_output2( wxString("test_wx2.dat") );
297 wxBufferedOutputStream buf_output2( file_output2 );
298 for (ch = 0; ch < 10; ch++)
299 buf_output2.Write( &ch, 1 );
300 buf_output2.SeekO( 3 );
301 ch = 3;
302 buf_output2.Write( &ch, 1 );
303 buf_output2.Sync();
304
305 wxFileInputStream file_input2( wxString("test_wx2.dat") );
306 for (ch2 = 0; ch2 < 10; ch2++)
307 {
308 file_input2.Read( &ch, 1 );
309 textCtrl.WriteText( (char)(ch + '0') );
310 }
311 textCtrl.WriteText( "\n\n\n" );
312
313 // now append 2000 bytes to file (bigger than buffer)
314 buf_output2.SeekO( 0, wxFromEnd );
315 ch = 1;
316 for (int i = 0; i < 2000; i++)
317 buf_output2.Write( &ch, 1 );
318 buf_output2.Sync();
319
320 textCtrl.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
321 textCtrl.WriteText( "seeking back to #3 and reading 3:\n\n" );
322
323 wxFileInputStream file_input3( wxString("test_wx2.dat") );
324 wxBufferedInputStream buf_input3( file_input3 );
325 for (ch2 = 0; ch2 < 10; ch2++)
326 {
327 buf_input3.Read( &ch, 1 );
328 textCtrl.WriteText( (char)(ch + '0') );
329 }
330 for (int j = 0; j < 2000; j++)
331 buf_input3.Read( &ch, 1 );
332 textCtrl.WriteText( "\n" );
333 buf_input3.SeekI( 3 );
334 buf_input3.Read( &ch, 1 );
335 textCtrl.WriteText( (char)(ch + '0') );
336 textCtrl.WriteText( "\n\n\n" );
337
338}
339
340void MyApp::DoStreamDemo3(wxCommandEvent& WXUNUSED(event))
341{
342 wxTextCtrl& textCtrl = * GetTextCtrl();
343
344 textCtrl.Clear();
345 textCtrl << "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
346
347 char ch,ch2;
348
349 textCtrl.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
350
351 wxFileOutputStream file_output( wxString("test_wx.dat") );
352 for (ch = 0; ch < 10; ch++)
353 file_output.Write( &ch, 1 );
354
355 // Testing wxFileInputStream
356
357 textCtrl.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
358
359 wxFileInputStream file_input( wxString("test_wx.dat") );
360 for (ch2 = 0; ch2 < 11; ch2++)
361 {
362 file_input.Read( &ch, 1 );
363 textCtrl.WriteText( "Value read: " );
364 textCtrl.WriteText( (char)(ch + '0') );
365 textCtrl.WriteText( "; stream.LastError() returns: " );
366 switch (file_input.LastError())
367 {
368 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
369 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
370 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
371 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
372 default: textCtrl.WriteText( "Huh?\n" ); break;
373 }
374 }
375 textCtrl.WriteText( "\n" );
376
377 textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " );
378 file_input.SeekI( 0 );
379 switch (file_input.LastError())
380 {
381 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
382 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
383 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
384 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
385 default: textCtrl.WriteText( "Huh?\n" ); break;
386 }
387 textCtrl.WriteText( "\n" );
388
389 file_input.Read( &ch, 1 );
390 textCtrl.WriteText( "Value read: " );
391 textCtrl.WriteText( (char)(ch + '0') );
392 textCtrl.WriteText( "; stream.LastError() returns: " );
393 switch (file_input.LastError())
394 {
395 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
396 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
397 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
398 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
399 default: textCtrl.WriteText( "Huh?\n" ); break;
400 }
401 textCtrl.WriteText( "\n\n" );
402
403
404 // Testing wxFFileInputStream
405
406 textCtrl.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
407
408 wxFFileInputStream ffile_input( wxString("test_wx.dat") );
409 for (ch2 = 0; ch2 < 11; ch2++)
410 {
411 ffile_input.Read( &ch, 1 );
412 textCtrl.WriteText( "Value read: " );
413 textCtrl.WriteText( (char)(ch + '0') );
414 textCtrl.WriteText( "; stream.LastError() returns: " );
415 switch (ffile_input.LastError())
416 {
417 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
418 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
419 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
420 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
421 default: textCtrl.WriteText( "Huh?\n" ); break;
422 }
423 }
424 textCtrl.WriteText( "\n" );
425
426 textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " );
427 ffile_input.SeekI( 0 );
428 switch (ffile_input.LastError())
429 {
430 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
431 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
432 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
433 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
434 default: textCtrl.WriteText( "Huh?\n" ); break;
435 }
436 textCtrl.WriteText( "\n" );
437
438 ffile_input.Read( &ch, 1 );
439 textCtrl.WriteText( "Value read: " );
440 textCtrl.WriteText( (char)(ch + '0') );
441 textCtrl.WriteText( "; stream.LastError() returns: " );
442 switch (ffile_input.LastError())
443 {
444 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
445 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
446 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
447 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
448 default: textCtrl.WriteText( "Huh?\n" ); break;
449 }
450 textCtrl.WriteText( "\n\n" );
451
452 // Testing wxFFileInputStream
453
454 textCtrl.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" );
455
456 wxFFileInputStream ffile_input2( wxString("test_wx.dat") );
457 wxBufferedInputStream buf_input( ffile_input2 );
458 for (ch2 = 0; ch2 < 11; ch2++)
459 {
460 buf_input.Read( &ch, 1 );
461 textCtrl.WriteText( "Value read: " );
462 textCtrl.WriteText( (char)(ch + '0') );
463 textCtrl.WriteText( "; stream.LastError() returns: " );
464 switch (buf_input.LastError())
465 {
466 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
467 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
468 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
469 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
470 default: textCtrl.WriteText( "Huh?\n" ); break;
471 }
472 }
473 textCtrl.WriteText( "\n" );
474
475 textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " );
476 buf_input.SeekI( 0 );
477 switch (buf_input.LastError())
478 {
479 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
480 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
481 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
482 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
483 default: textCtrl.WriteText( "Huh?\n" ); break;
484 }
485 textCtrl.WriteText( "\n" );
486
487 buf_input.Read( &ch, 1 );
488 textCtrl.WriteText( "Value read: " );
489 textCtrl.WriteText( (char)(ch + '0') );
490 textCtrl.WriteText( "; stream.LastError() returns: " );
491 switch (buf_input.LastError())
492 {
493 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
494 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
495 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
496 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
497 default: textCtrl.WriteText( "Huh?\n" ); break;
498 }
499}
500
501void MyApp::DoStreamDemo4(wxCommandEvent& WXUNUSED(event))
502{
503 wxTextCtrl& textCtrl = * GetTextCtrl();
504
505 wxString msg;
506
507 textCtrl.Clear();
508 textCtrl << "\nTesting wxStreamBuffer:\n\n";
509
510 // bigger than buffer
511 textCtrl.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" );
512
513 wxFileOutputStream file_output( wxString("test_wx.dat") );
514 for (int i = 0; i < 2000; i++)
515 {
516 char ch = 1;
517 file_output.Write( &ch, 1 );
518 }
519
520 textCtrl.WriteText( "Opening with a buffered wxFileInputStream:\n\n" );
521
522 wxFileInputStream file_input( wxString("test_wx.dat") );
523 wxBufferedInputStream buf_input( file_input );
524
525 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
526 switch (buf_input.LastError())
527 {
528 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
529 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
530 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
531 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
532 default: textCtrl.WriteText( "Huh?\n" ); break;
533 }
534 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
535 textCtrl.WriteText( msg );
536 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
537 textCtrl.WriteText( msg );
538 textCtrl.WriteText( "\n\n" );
539
540
541 textCtrl.WriteText( "Seeking to position 300:\n\n" );
542
543 buf_input.SeekI( 300 );
544
545 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
546 switch (buf_input.LastError())
547 {
548 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
549 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
550 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
551 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
552 default: textCtrl.WriteText( "Huh?\n" ); break;
553 }
554 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
555 textCtrl.WriteText( msg );
556 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
557 textCtrl.WriteText( msg );
558 textCtrl.WriteText( "\n\n" );
559
560
561 char buf[2000];
562
563 textCtrl.WriteText( "Reading 500 bytes:\n\n" );
564
565 buf_input.Read( buf, 500 );
566
567 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
568 switch (buf_input.LastError())
569 {
570 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
571 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
572 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
573 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
574 default: textCtrl.WriteText( "Huh?\n" ); break;
575 }
576 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
577 textCtrl.WriteText( msg );
578 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
579 textCtrl.WriteText( msg );
580 textCtrl.WriteText( "\n\n" );
581
582 textCtrl.WriteText( "Reading another 500 bytes:\n\n" );
583
584 buf_input.Read( buf, 500 );
585
586 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
587 switch (buf_input.LastError())
588 {
589 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
590 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
591 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
592 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
593 default: textCtrl.WriteText( "Huh?\n" ); break;
594 }
595 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
596 textCtrl.WriteText( msg );
597 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
598 textCtrl.WriteText( msg );
599 textCtrl.WriteText( "\n\n" );
600
601 textCtrl.WriteText( "Reading another 500 bytes:\n\n" );
602
603 buf_input.Read( buf, 500 );
604
605 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
606 switch (buf_input.LastError())
607 {
608 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
609 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
610 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
611 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
612 default: textCtrl.WriteText( "Huh?\n" ); break;
613 }
614 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
615 textCtrl.WriteText( msg );
616 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
617 textCtrl.WriteText( msg );
618 textCtrl.WriteText( "\n\n" );
619
620 textCtrl.WriteText( "Reading another 500 bytes:\n\n" );
621
622 buf_input.Read( buf, 500 );
623
624 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
625 switch (buf_input.LastError())
626 {
627 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
628 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
629 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
630 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
631 default: textCtrl.WriteText( "Huh?\n" ); break;
632 }
633 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
634 textCtrl.WriteText( msg );
635 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
636 textCtrl.WriteText( msg );
637 textCtrl.WriteText( "\n\n" );
638}
639
640#if wxUSE_UNICODE
641void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event))
642{
643 wxTextCtrl& textCtrl = * GetTextCtrl();
644
645 textCtrl.Clear();
646 textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
647
648 wxString str;
649