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