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