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