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