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