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