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