]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/typetest/typetest.cpp
Fixes from Mumit Khan to allow DLL compilation; most fixes related to
[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( "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 std_file_input >> str;
182 tmp.Printf( _T("String: %s\n"), str.c_str() );
183 textCtrl.WriteText( tmp );
184
185 textCtrl.WriteText( "\nReading from wxFileInputStream:\n" );
186
187 buf_output.Sync();
188
189 wxFileInputStream file_input( "test_wx.dat" );
190 wxBufferedInputStream buf_input( file_input );
191 wxTextInputStream text_input( file_input );
192
193 text_input >> si;
194 tmp.Printf( _T("Signed int: %d\n"), si );
195 textCtrl.WriteText( tmp );
196
197 text_input >> ui;
198 tmp.Printf( _T("Unsigned int: %u\n"), ui );
199 textCtrl.WriteText( tmp );
200
201 text_input >> d;
202 tmp.Printf( _T("Double: %f\n"), d );
203 textCtrl.WriteText( tmp );
204
205 text_input >> f;
206 tmp.Printf( _T("Float: %f\n"), f );
207 textCtrl.WriteText( tmp );
208
209 text_input >> str;
210 tmp.Printf( _T("String: %s\n"), str.c_str() );
211 textCtrl.WriteText( tmp );
212
213
214 textCtrl << "\nTest for wxDataStream:\n\n";
215
216 textCtrl.WriteText( "Writing to wxDataOutputStream:\n" );
217
218 file_output.SeekO( 0 );
219 wxDataOutputStream data_output( buf_output );
220
221 wxInt16 i16 = (short)0xFFFF;
222 tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
223 textCtrl.WriteText( tmp );
224 data_output.Write16( i16 );
225
226 wxUint16 ui16 = 0xFFFF;
227 tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
228 textCtrl.WriteText( tmp );
229 data_output.Write16( ui16 );
230
231 d = 2.01234567890123456789;
232 tmp.Printf( _T("Double: %f\n"), d );
233 textCtrl.WriteText( tmp );
234 data_output.WriteDouble( d );
235
236 str = "Hello!";
237 tmp.Printf( _T("String: %s\n"), str.c_str() );
238 textCtrl.WriteText( tmp );
239 data_output.WriteString( str );
240
241 buf_output.Sync();
242
243 textCtrl.WriteText( "\nReading from wxDataInputStream:\n" );
244
245 file_input.SeekI( 0 );
246 wxDataInputStream data_input( buf_input );
247
248 i16 = data_input.Read16();
249 tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
250 textCtrl.WriteText( tmp );
251
252 ui16 = data_input.Read16();
253 tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
254 textCtrl.WriteText( tmp );
255
256 d = data_input.ReadDouble();
257 tmp.Printf( _T("Double: %f\n"), d );
258 textCtrl.WriteText( tmp );
259
260 str = data_input.ReadString();
261 tmp.Printf( _T("String: %s\n"), str.c_str() );
262 textCtrl.WriteText( tmp );
263}
264
265void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event))
266{
267 wxTextCtrl& textCtrl = * GetTextCtrl();
268
269 textCtrl.Clear();
270 textCtrl << _T("\nTesting wxBufferedStream:\n\n");
271
272 char ch,ch2;
273
274 textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
275
276 wxFileOutputStream file_output( "test_wx.dat" );
277 wxBufferedOutputStream buf_output( file_output );
278 for (ch = 0; ch < 10; ch++)
279 buf_output.Write( &ch, 1 );
280 buf_output.Sync();
281
282 wxFileInputStream file_input( "test_wx.dat" );
283 for (ch2 = 0; ch2 < 10; ch2++)
284 {
285 file_input.Read( &ch, 1 );
286 textCtrl.WriteText( (char)(ch + '0') );
287 }
288 textCtrl.WriteText( "\n\n\n" );
289
290 textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
291 textCtrl.WriteText( "seeking back to #3 and writing 3:\n\n" );
292
293 wxFileOutputStream file_output2( "test_wx2.dat" );
294 wxBufferedOutputStream buf_output2( file_output2 );
295 for (ch = 0; ch < 10; ch++)
296 buf_output2.Write( &ch, 1 );
297 buf_output2.SeekO( 3 );
298 ch = 3;
299 buf_output2.Write( &ch, 1 );
300 buf_output2.Sync();
301
302 wxFileInputStream file_input2( "test_wx2.dat" );
303 for (ch2 = 0; ch2 < 10; ch2++)
304 {
305 file_input2.Read( &ch, 1 );
306 textCtrl.WriteText( (char)(ch + '0') );
307 }
308 textCtrl.WriteText( "\n\n\n" );
309
310 // now append 2000 bytes to file (bigger than buffer)
311 buf_output2.SeekO( 0, wxFromEnd );
312 ch = 1;
313 for (int i = 0; i < 2000; i++)
314 buf_output2.Write( &ch, 1 );
315 buf_output2.Sync();
316
317 textCtrl.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
318 textCtrl.WriteText( "seeking back to #3 and reading 3:\n\n" );
319
320 wxFileInputStream file_input3( "test_wx2.dat" );
321 wxBufferedInputStream buf_input3( file_input3 );
322 for (ch2 = 0; ch2 < 10; ch2++)
323 {
324 buf_input3.Read( &ch, 1 );
325 textCtrl.WriteText( (char)(ch + '0') );
326 }
327 for (int j = 0; j < 2000; j++)
328 buf_input3.Read( &ch, 1 );
329 textCtrl.WriteText( "\n" );
330 buf_input3.SeekI( 3 );
331 buf_input3.Read( &ch, 1 );
332 textCtrl.WriteText( (char)(ch + '0') );
333 textCtrl.WriteText( "\n\n\n" );
334
335}
336
337void MyApp::DoStreamDemo3(wxCommandEvent& WXUNUSED(event))
338{
339 wxTextCtrl& textCtrl = * GetTextCtrl();
340
341 textCtrl.Clear();
342 textCtrl << "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
343
344 char ch,ch2;
345
346 textCtrl.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
347
348 wxFileOutputStream file_output( "test_wx.dat" );
349 for (ch = 0; ch < 10; ch++)
350 file_output.Write( &ch, 1 );
351
352 // Testing wxFileInputStream
353
354 textCtrl.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
355
356 wxFileInputStream file_input( "test_wx.dat" );
357 for (ch2 = 0; ch2 < 11; ch2++)
358 {
359 file_input.Read( &ch, 1 );
360 textCtrl.WriteText( "Value read: " );
361 textCtrl.WriteText( (char)(ch + '0') );
362 textCtrl.WriteText( "; stream.LastError() returns: " );
363 switch (file_input.LastError())
364 {
365 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
366 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
367 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
368 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
369 default: textCtrl.WriteText( "Huh?\n" ); break;
370 }
371 }
372 textCtrl.WriteText( "\n" );
373
374 textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " );
375 file_input.SeekI( 0 );
376 switch (file_input.LastError())
377 {
378 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
379 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
380 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
381 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
382 default: textCtrl.WriteText( "Huh?\n" ); break;
383 }
384 textCtrl.WriteText( "\n" );
385
386 file_input.Read( &ch, 1 );
387 textCtrl.WriteText( "Value read: " );
388 textCtrl.WriteText( (char)(ch + '0') );
389 textCtrl.WriteText( "; stream.LastError() returns: " );
390 switch (file_input.LastError())
391 {
392 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
393 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
394 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
395 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
396 default: textCtrl.WriteText( "Huh?\n" ); break;
397 }
398 textCtrl.WriteText( "\n\n" );
399
400
401 // Testing wxFFileInputStream
402
403 textCtrl.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
404
405 wxFFileInputStream ffile_input( "test_wx.dat" );
406 for (ch2 = 0; ch2 < 11; ch2++)
407 {
408 ffile_input.Read( &ch, 1 );
409 textCtrl.WriteText( "Value read: " );
410 textCtrl.WriteText( (char)(ch + '0') );
411 textCtrl.WriteText( "; stream.LastError() returns: " );
412 switch (ffile_input.LastError())
413 {
414 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
415 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
416 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
417 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
418 default: textCtrl.WriteText( "Huh?\n" ); break;
419 }
420 }
421 textCtrl.WriteText( "\n" );
422
423 textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " );
424 ffile_input.SeekI( 0 );
425 switch (ffile_input.LastError())
426 {
427 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
428 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
429 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
430 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
431 default: textCtrl.WriteText( "Huh?\n" ); break;
432 }
433 textCtrl.WriteText( "\n" );
434
435 ffile_input.Read( &ch, 1 );
436 textCtrl.WriteText( "Value read: " );
437 textCtrl.WriteText( (char)(ch + '0') );
438 textCtrl.WriteText( "; stream.LastError() returns: " );
439 switch (ffile_input.LastError())
440 {
441 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
442 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
443 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
444 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
445 default: textCtrl.WriteText( "Huh?\n" ); break;
446 }
447 textCtrl.WriteText( "\n\n" );
448
449 // Testing wxFFileInputStream
450
451 textCtrl.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" );
452
453 wxFFileInputStream ffile_input2( "test_wx.dat" );
454 wxBufferedInputStream buf_input( ffile_input2 );
455 for (ch2 = 0; ch2 < 11; ch2++)
456 {
457 buf_input.Read( &ch, 1 );
458 textCtrl.WriteText( "Value read: " );
459 textCtrl.WriteText( (char)(ch + '0') );
460 textCtrl.WriteText( "; stream.LastError() returns: " );
461 switch (buf_input.LastError())
462 {
463 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
464 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
465 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
466 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
467 default: textCtrl.WriteText( "Huh?\n" ); break;
468 }
469 }
470 textCtrl.WriteText( "\n" );
471
472 textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " );
473 buf_input.SeekI( 0 );
474 switch (buf_input.LastError())
475 {
476 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
477 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
478 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
479 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
480 default: textCtrl.WriteText( "Huh?\n" ); break;
481 }
482 textCtrl.WriteText( "\n" );
483
484 buf_input.Read( &ch, 1 );
485 textCtrl.WriteText( "Value read: " );
486 textCtrl.WriteText( (char)(ch + '0') );
487 textCtrl.WriteText( "; stream.LastError() returns: " );
488 switch (buf_input.LastError())
489 {
490 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
491 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
492 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
493 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
494 default: textCtrl.WriteText( "Huh?\n" ); break;
495 }
496}
497
498void MyApp::DoStreamDemo4(wxCommandEvent& WXUNUSED(event))
499{
500 wxTextCtrl& textCtrl = * GetTextCtrl();
501
502 wxString msg;
503
504 textCtrl.Clear();
505 textCtrl << "\nTesting wxStreamBuffer:\n\n";
506
507 // bigger than buffer
508 textCtrl.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" );
509
510 wxFileOutputStream file_output( "test_wx.dat" );
511 for (int i = 0; i < 2000; i++)
512 {
513 char ch = 1;
514 file_output.Write( &ch, 1 );
515 }
516
517 textCtrl.WriteText( "Opening with a buffered wxFileInputStream:\n\n" );
518
519 wxFileInputStream file_input( "test_wx.dat" );
520 wxBufferedInputStream buf_input( file_input );
521
522 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
523 switch (buf_input.LastError())
524 {
525 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
526 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
527 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
528 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
529 default: textCtrl.WriteText( "Huh?\n" ); break;
530 }
531 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
532 textCtrl.WriteText( msg );
533 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
534 textCtrl.WriteText( msg );
535 textCtrl.WriteText( "\n\n" );
536
537
538 textCtrl.WriteText( "Seeking to position 300:\n\n" );
539
540 buf_input.SeekI( 300 );
541
542 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
543 switch (buf_input.LastError())
544 {
545 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
546 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
547 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
548 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
549 default: textCtrl.WriteText( "Huh?\n" ); break;
550 }
551 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
552 textCtrl.WriteText( msg );
553 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
554 textCtrl.WriteText( msg );
555 textCtrl.WriteText( "\n\n" );
556
557
558 char buf[2000];
559
560 textCtrl.WriteText( "Reading 500 bytes:\n\n" );
561
562 buf_input.Read( buf, 500 );
563
564 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
565 switch (buf_input.LastError())
566 {
567 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
568 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
569 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
570 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
571 default: textCtrl.WriteText( "Huh?\n" ); break;
572 }
573 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
574 textCtrl.WriteText( msg );
575 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
576 textCtrl.WriteText( msg );
577 textCtrl.WriteText( "\n\n" );
578
579 textCtrl.WriteText( "Reading another 500 bytes:\n\n" );
580
581 buf_input.Read( buf, 500 );
582
583 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
584 switch (buf_input.LastError())
585 {
586 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
587 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
588 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
589 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
590 default: textCtrl.WriteText( "Huh?\n" ); break;
591 }
592 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
593 textCtrl.WriteText( msg );
594 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
595 textCtrl.WriteText( msg );
596 textCtrl.WriteText( "\n\n" );
597
598 textCtrl.WriteText( "Reading another 500 bytes:\n\n" );
599
600 buf_input.Read( buf, 500 );
601
602 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
603 switch (buf_input.LastError())
604 {
605 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
606 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
607 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
608 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
609 default: textCtrl.WriteText( "Huh?\n" ); break;
610 }
611 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
612 textCtrl.WriteText( msg );
613 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
614 textCtrl.WriteText( msg );
615 textCtrl.WriteText( "\n\n" );
616
617 textCtrl.WriteText( "Reading another 500 bytes:\n\n" );
618
619 buf_input.Read( buf, 500 );
620
621 textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " );
622 switch (buf_input.LastError())
623 {
624 case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break;
625 case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break;
626 case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
627 case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
628 default: textCtrl.WriteText( "Huh?\n" ); break;
629 }
630 msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() );
631 textCtrl.WriteText( msg );
632 msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() );
633 textCtrl.WriteText( msg );
634 textCtrl.WriteText( "\n\n" );
635}
636
637#if wxUSE_UNICODE
638void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event))
639{
640 wxTextCtrl& textCtrl = * GetTextCtrl();
641
642 textCtrl.Clear();
643 textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
644
645 wxString str;
646