]>
Commit | Line | Data |
---|---|---|
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 | ||
b412f9be | 34 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
cfb88c55 JS |
35 | #include "mondrian.xpm" |
36 | #endif | |
37 | ||
38830220 RR |
38 | #include "wx/ioswrap.h" |
39 | ||
40 | #if wxUSE_IOSTREAMH | |
41 | #include <fstream.h> | |
42 | #else | |
43 | #include <fstream> | |
44 | #endif | |
45 | ||
46 | #include "wx/wfstream.h" | |
53daeada | 47 | #include "wx/datstrm.h" |
fae05df5 | 48 | #include "wx/txtstrm.h" |
38830220 | 49 | |
cfb88c55 | 50 | // Create a new application object |
8e124873 | 51 | IMPLEMENT_APP (MyApp) |
cfb88c55 | 52 | |
8e124873 | 53 | IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp) |
cfb88c55 JS |
54 | |
55 | BEGIN_EVENT_TABLE(MyApp, wxApp) | |
8e124873 VZ |
56 | EVT_MENU(TYPES_DATE, MyApp::DoDateDemo) |
57 | EVT_MENU(TYPES_TIME, MyApp::DoTimeDemo) | |
58 | EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo) | |
59 | EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo) | |
dcf924a3 | 60 | #if wxUSE_UNICODE |
8e124873 | 61 | EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo) |
dcf924a3 | 62 | #endif |
8e124873 | 63 | EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo) |
aa51b2e1 RR |
64 | EVT_MENU(TYPES_STREAM2, MyApp::DoStreamDemo2) |
65 | EVT_MENU(TYPES_STREAM3, MyApp::DoStreamDemo3) | |
2bf8e4eb | 66 | EVT_MENU(TYPES_STREAM4, MyApp::DoStreamDemo4) |
8e124873 | 67 | EVT_MENU(TYPES_MIME, MyApp::DoMIMEDemo) |
cfb88c55 JS |
68 | END_EVENT_TABLE() |
69 | ||
8e124873 | 70 | bool MyApp::OnInit() |
cfb88c55 | 71 | { |
8e124873 VZ |
72 | // Create the main frame window |
73 | MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxWindows Types Demo", | |
74 | wxPoint(50, 50), wxSize(450, 340)); | |
75 | ||
76 | // Give it an icon | |
77 | frame->SetIcon(wxICON(mondrian)); | |
78 | ||
79 | // Make a menubar | |
80 | wxMenu *file_menu = new wxMenu; | |
81 | ||
82 | file_menu->Append(TYPES_ABOUT, "&About"); | |
83 | file_menu->AppendSeparator(); | |
84 | file_menu->Append(TYPES_QUIT, "E&xit\tAlt-X"); | |
85 | ||
86 | wxMenu *test_menu = new wxMenu; | |
87 | test_menu->Append(TYPES_DATE, "&Date test"); | |
88 | test_menu->Append(TYPES_TIME, "&Time test"); | |
89 | test_menu->Append(TYPES_VARIANT, "&Variant test"); | |
90 | test_menu->Append(TYPES_BYTEORDER, "&Byteorder test"); | |
dcf924a3 | 91 | #if wxUSE_UNICODE |
8e124873 | 92 | test_menu->Append(TYPES_UNICODE, "&Unicode test"); |
dcf924a3 | 93 | #endif |
8e124873 | 94 | test_menu->Append(TYPES_STREAM, "&Stream test"); |
1b055864 | 95 | test_menu->Append(TYPES_STREAM2, "&Stream seek test"); |
aa51b2e1 | 96 | test_menu->Append(TYPES_STREAM3, "&Stream error test"); |
2bf8e4eb | 97 | test_menu->Append(TYPES_STREAM4, "&Stream buffer test"); |
8e124873 VZ |
98 | test_menu->AppendSeparator(); |
99 | test_menu->Append(TYPES_MIME, "&MIME database test"); | |
cfb88c55 | 100 | |
8e124873 VZ |
101 | wxMenuBar *menu_bar = new wxMenuBar; |
102 | menu_bar->Append(file_menu, "&File"); | |
103 | menu_bar->Append(test_menu, "&Tests"); | |
104 | frame->SetMenuBar(menu_bar); | |
cfb88c55 | 105 | |
8e124873 | 106 | m_textCtrl = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE); |
cfb88c55 | 107 | |
8e124873 VZ |
108 | // Show the frame |
109 | frame->Show(TRUE); | |
110 | ||
111 | SetTopWindow(frame); | |
112 | ||
113 | return TRUE; | |
cfb88c55 JS |
114 | } |
115 | ||
38830220 RR |
116 | void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) |
117 | { | |
118 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
8e124873 | 119 | |
38830220 | 120 | textCtrl.Clear(); |
c980c992 | 121 | textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n"); |
38830220 | 122 | |
e57e26dd | 123 | textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" ); |
8e124873 | 124 | |
38830220 RR |
125 | ofstream std_file_output( "test_std.dat" ); |
126 | wxFileOutputStream file_output( "test_wx.dat" ); | |
fae05df5 GL |
127 | wxBufferedOutputStream buf_output( file_output ); |
128 | wxTextOutputStream text_output( buf_output ); | |
38830220 | 129 | |
38830220 RR |
130 | wxString tmp; |
131 | signed int si = 0xFFFFFFFF; | |
c980c992 | 132 | tmp.Printf( _T("Signed int: %d\n"), si ); |
38830220 | 133 | textCtrl.WriteText( tmp ); |
fae05df5 | 134 | text_output << si << "\n"; |
38830220 | 135 | std_file_output << si << "\n"; |
8e124873 | 136 | |
38830220 | 137 | unsigned int ui = 0xFFFFFFFF; |
c980c992 | 138 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); |
38830220 | 139 | textCtrl.WriteText( tmp ); |
fae05df5 | 140 | text_output << ui << "\n"; |
38830220 | 141 | std_file_output << ui << "\n"; |
8e124873 | 142 | |
38830220 | 143 | double d = 2.01234567890123456789; |
c980c992 | 144 | tmp.Printf( _T("Double: %f\n"), d ); |
38830220 | 145 | textCtrl.WriteText( tmp ); |
fae05df5 | 146 | text_output << d << "\n"; |
38830220 | 147 | std_file_output << d << "\n"; |
8e124873 VZ |
148 | |
149 | float f = (float)0.00001; | |
c980c992 | 150 | tmp.Printf( _T("Float: %f\n"), f ); |
e57e26dd | 151 | textCtrl.WriteText( tmp ); |
fae05df5 | 152 | text_output << f << "\n"; |
e57e26dd | 153 | std_file_output << f << "\n"; |
8e124873 | 154 | |
c980c992 GL |
155 | wxString str( _T("Hello!") ); |
156 | tmp.Printf( _T("String: %s\n"), str.c_str() ); | |
38830220 | 157 | textCtrl.WriteText( tmp ); |
fae05df5 | 158 | text_output << str << "\n"; |
38830220 | 159 | std_file_output << str.c_str() << "\n"; |
8e124873 | 160 | |
e57e26dd | 161 | textCtrl.WriteText( "\nReading from ifstream:\n" ); |
8e124873 | 162 | |
e57e26dd RR |
163 | ifstream std_file_input( "test_std.dat" ); |
164 | ||
165 | std_file_input >> si; | |
c980c992 | 166 | tmp.Printf( _T("Signed int: %d\n"), si ); |
e57e26dd | 167 | textCtrl.WriteText( tmp ); |
8e124873 | 168 | |
e57e26dd | 169 | std_file_input >> ui; |
c980c992 | 170 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); |
e57e26dd | 171 | textCtrl.WriteText( tmp ); |
8e124873 | 172 | |
e57e26dd | 173 | std_file_input >> d; |
c980c992 | 174 | tmp.Printf( _T("Double: %f\n"), d ); |
e57e26dd | 175 | textCtrl.WriteText( tmp ); |
8e124873 | 176 | |
e57e26dd | 177 | std_file_input >> f; |
c980c992 | 178 | tmp.Printf( _T("Float: %f\n"), f ); |
e57e26dd | 179 | textCtrl.WriteText( tmp ); |
8e124873 | 180 | |
e57e26dd | 181 | std_file_input >> str; |
c980c992 | 182 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
e57e26dd | 183 | textCtrl.WriteText( tmp ); |
8e124873 | 184 | |
e57e26dd | 185 | textCtrl.WriteText( "\nReading from wxFileInputStream:\n" ); |
b6bff301 | 186 | |
fae05df5 | 187 | buf_output.Sync(); |
8e124873 | 188 | |
e57e26dd | 189 | wxFileInputStream file_input( "test_wx.dat" ); |
fae05df5 | 190 | wxBufferedInputStream buf_input( file_input ); |
78e848ca | 191 | wxTextInputStream text_input( file_input ); |
8e124873 | 192 | |
fae05df5 | 193 | text_input >> si; |
c980c992 | 194 | tmp.Printf( _T("Signed int: %d\n"), si ); |
e57e26dd | 195 | textCtrl.WriteText( tmp ); |
8e124873 | 196 | |
fae05df5 | 197 | text_input >> ui; |
c980c992 | 198 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); |
e57e26dd | 199 | textCtrl.WriteText( tmp ); |
8e124873 | 200 | |
fae05df5 | 201 | text_input >> d; |
c980c992 | 202 | tmp.Printf( _T("Double: %f\n"), d ); |
e57e26dd | 203 | textCtrl.WriteText( tmp ); |
8e124873 | 204 | |
fae05df5 | 205 | text_input >> f; |
c980c992 | 206 | tmp.Printf( _T("Float: %f\n"), f ); |
e57e26dd | 207 | textCtrl.WriteText( tmp ); |
8e124873 | 208 | |
fae05df5 | 209 | text_input >> str; |
c980c992 | 210 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
e57e26dd | 211 | textCtrl.WriteText( tmp ); |
8e124873 | 212 | |
53daeada RR |
213 | |
214 | textCtrl << "\nTest for wxDataStream:\n\n"; | |
215 | ||
216 | textCtrl.WriteText( "Writing to wxDataOutputStream:\n" ); | |
8e124873 | 217 | |
53daeada | 218 | file_output.SeekO( 0 ); |
fae05df5 | 219 | wxDataOutputStream data_output( buf_output ); |
53daeada | 220 | |
8e124873 | 221 | wxInt16 i16 = (short)0xFFFF; |
c980c992 | 222 | tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); |
53daeada | 223 | textCtrl.WriteText( tmp ); |
329e86bf | 224 | data_output.Write16( i16 ); |
8e124873 | 225 | |
329e86bf | 226 | wxUint16 ui16 = 0xFFFF; |
c980c992 | 227 | tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); |
53daeada | 228 | textCtrl.WriteText( tmp ); |
329e86bf | 229 | data_output.Write16( ui16 ); |
8e124873 | 230 | |
53daeada | 231 | d = 2.01234567890123456789; |
c980c992 | 232 | tmp.Printf( _T("Double: %f\n"), d ); |
53daeada RR |
233 | textCtrl.WriteText( tmp ); |
234 | data_output.WriteDouble( d ); | |
8e124873 | 235 | |
53daeada | 236 | str = "Hello!"; |
c980c992 | 237 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
53daeada RR |
238 | textCtrl.WriteText( tmp ); |
239 | data_output.WriteString( str ); | |
8e124873 | 240 | |
fae05df5 | 241 | buf_output.Sync(); |
8e124873 | 242 | |
53daeada | 243 | textCtrl.WriteText( "\nReading from wxDataInputStream:\n" ); |
8e124873 | 244 | |
53daeada | 245 | file_input.SeekI( 0 ); |
fae05df5 | 246 | wxDataInputStream data_input( buf_input ); |
53daeada | 247 | |
329e86bf | 248 | i16 = data_input.Read16(); |
c980c992 | 249 | tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); |
53daeada | 250 | textCtrl.WriteText( tmp ); |
8e124873 | 251 | |
329e86bf | 252 | ui16 = data_input.Read16(); |
c980c992 | 253 | tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); |
53daeada RR |
254 | textCtrl.WriteText( tmp ); |
255 | ||
256 | d = data_input.ReadDouble(); | |
c980c992 | 257 | tmp.Printf( _T("Double: %f\n"), d ); |
53daeada | 258 | textCtrl.WriteText( tmp ); |
8e124873 | 259 | |
53daeada | 260 | str = data_input.ReadString(); |
c980c992 | 261 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
53daeada | 262 | textCtrl.WriteText( tmp ); |
38830220 RR |
263 | } |
264 | ||
1b055864 RR |
265 | void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event)) |
266 | { | |
267 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
268 | ||
269 | textCtrl.Clear(); | |
aa51b2e1 | 270 | textCtrl << _T("\nTesting wxBufferedStream:\n\n"); |
1b055864 RR |
271 | |
272 | char ch,ch2; | |
273 | ||
274 | textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" ); | |
275 | ||
276 | wxFileOutputStream file_output( "test_wx.dat" ); | |
277 | wxBufferedOutputStream buf_output( file_output ); | |
278 | for (ch = 0; ch < 10; ch++) | |
279 | buf_output.Write( &ch, 1 ); | |
280 | buf_output.Sync(); | |
281 | ||
282 | wxFileInputStream file_input( "test_wx.dat" ); | |
283 | for (ch2 = 0; ch2 < 10; ch2++) | |
284 | { | |
285 | file_input.Read( &ch, 1 ); | |
286 | textCtrl.WriteText( (char)(ch + '0') ); | |
287 | } | |
288 | textCtrl.WriteText( "\n\n\n" ); | |
289 | ||
290 | textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" ); | |
291 | textCtrl.WriteText( "seeking back to #3 and writing 3:\n\n" ); | |
292 | ||
293 | wxFileOutputStream file_output2( "test_wx2.dat" ); | |
294 | wxBufferedOutputStream buf_output2( file_output2 ); | |
295 | for (ch = 0; ch < 10; ch++) | |
296 | buf_output2.Write( &ch, 1 ); | |
297 | buf_output2.SeekO( 3 ); | |
298 | ch = 3; | |
299 | buf_output2.Write( &ch, 1 ); | |
300 | buf_output2.Sync(); | |
301 | ||
302 | wxFileInputStream file_input2( "test_wx2.dat" ); | |
303 | for (ch2 = 0; ch2 < 10; ch2++) | |
304 | { | |
305 | file_input2.Read( &ch, 1 ); | |
306 | textCtrl.WriteText( (char)(ch + '0') ); | |
307 | } | |
308 | textCtrl.WriteText( "\n\n\n" ); | |
309 | ||
310 | // now append 2000 bytes to file (bigger than buffer) | |
311 | buf_output2.SeekO( 0, wxFromEnd ); | |
312 | ch = 1; | |
313 | for (int i = 0; i < 2000; i++) | |
314 | buf_output2.Write( &ch, 1 ); | |
315 | buf_output2.Sync(); | |
316 | ||
317 | textCtrl.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" ); | |
318 | textCtrl.WriteText( "seeking back to #3 and reading 3:\n\n" ); | |
319 | ||
320 | wxFileInputStream file_input3( "test_wx2.dat" ); | |
321 | wxBufferedInputStream buf_input3( file_input3 ); | |
322 | for (ch2 = 0; ch2 < 10; ch2++) | |
323 | { | |
324 | buf_input3.Read( &ch, 1 ); | |
325 | textCtrl.WriteText( (char)(ch + '0') ); | |
326 | } | |
327 | for (int j = 0; j < 2000; j++) | |
328 | buf_input3.Read( &ch, 1 ); | |
329 | textCtrl.WriteText( "\n" ); | |
330 | buf_input3.SeekI( 3 ); | |
331 | buf_input3.Read( &ch, 1 ); | |
332 | textCtrl.WriteText( (char)(ch + '0') ); | |
333 | textCtrl.WriteText( "\n\n\n" ); | |
334 | ||
335 | } | |
336 | ||
aa51b2e1 RR |
337 | void MyApp::DoStreamDemo3(wxCommandEvent& WXUNUSED(event)) |
338 | { | |
339 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
340 | ||
341 | textCtrl.Clear(); | |
342 | textCtrl << "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n"; | |
343 | ||
344 | char ch,ch2; | |
345 | ||
346 | textCtrl.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" ); | |
347 | ||
348 | wxFileOutputStream file_output( "test_wx.dat" ); | |
349 | for (ch = 0; ch < 10; ch++) | |
350 | file_output.Write( &ch, 1 ); | |
351 | ||
842d6c94 | 352 | // Testing wxFileInputStream |
aa51b2e1 RR |
353 | |
354 | textCtrl.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" ); | |
355 | ||
356 | wxFileInputStream file_input( "test_wx.dat" ); | |
357 | for (ch2 = 0; ch2 < 11; ch2++) | |
358 | { | |
359 | file_input.Read( &ch, 1 ); | |
360 | textCtrl.WriteText( "Value read: " ); | |
361 | textCtrl.WriteText( (char)(ch + '0') ); | |
362 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
363 | switch (file_input.LastError()) | |
364 | { | |
365 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
366 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
367 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
368 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
369 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
370 | } | |
371 | } | |
372 | textCtrl.WriteText( "\n" ); | |
373 | ||
374 | textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " ); | |
375 | file_input.SeekI( 0 ); | |
376 | switch (file_input.LastError()) | |
377 | { | |
378 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
379 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
380 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
381 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
382 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
383 | } | |
384 | textCtrl.WriteText( "\n" ); | |
385 | ||
386 | file_input.Read( &ch, 1 ); | |
387 | textCtrl.WriteText( "Value read: " ); | |
388 | textCtrl.WriteText( (char)(ch + '0') ); | |
389 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
390 | switch (file_input.LastError()) | |
391 | { | |
392 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
393 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
394 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
395 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
396 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
397 | } | |
398 | textCtrl.WriteText( "\n\n" ); | |
399 | ||
400 | ||
842d6c94 | 401 | // Testing wxFFileInputStream |
aa51b2e1 RR |
402 | |
403 | textCtrl.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" ); | |
404 | ||
405 | wxFFileInputStream ffile_input( "test_wx.dat" ); | |
406 | for (ch2 = 0; ch2 < 11; ch2++) | |
407 | { | |
408 | ffile_input.Read( &ch, 1 ); | |
409 | textCtrl.WriteText( "Value read: " ); | |
410 | textCtrl.WriteText( (char)(ch + '0') ); | |
411 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
412 | switch (ffile_input.LastError()) | |
413 | { | |
414 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
415 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
416 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
417 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
418 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
419 | } | |
420 | } | |
421 | textCtrl.WriteText( "\n" ); | |
422 | ||
423 | textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " ); | |
424 | ffile_input.SeekI( 0 ); | |
425 | switch (ffile_input.LastError()) | |
426 | { | |
427 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
428 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
429 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
430 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
431 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
432 | } | |
433 | textCtrl.WriteText( "\n" ); | |
434 | ||
435 | ffile_input.Read( &ch, 1 ); | |
436 | textCtrl.WriteText( "Value read: " ); | |
437 | textCtrl.WriteText( (char)(ch + '0') ); | |
438 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
439 | switch (ffile_input.LastError()) | |
440 | { | |
842d6c94 RR |
441 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; |
442 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
443 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
444 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
445 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
446 | } | |
447 | textCtrl.WriteText( "\n\n" ); | |
448 | ||
449 | // Testing wxFFileInputStream | |
450 | ||
451 | textCtrl.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" ); | |
452 | ||
453 | wxFFileInputStream ffile_input2( "test_wx.dat" ); | |
454 | wxBufferedInputStream buf_input( ffile_input2 ); | |
455 | for (ch2 = 0; ch2 < 11; ch2++) | |
456 | { | |
457 | buf_input.Read( &ch, 1 ); | |
458 | textCtrl.WriteText( "Value read: " ); | |
459 | textCtrl.WriteText( (char)(ch + '0') ); | |
460 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
461 | switch (buf_input.LastError()) | |
462 | { | |
463 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
464 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
465 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
466 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
467 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
468 | } | |
469 | } | |
470 | textCtrl.WriteText( "\n" ); | |
471 | ||
472 | textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " ); | |
473 | buf_input.SeekI( 0 ); | |
474 | switch (buf_input.LastError()) | |
475 | { | |
476 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
477 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
478 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
479 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
480 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
481 | } | |
482 | textCtrl.WriteText( "\n" ); | |
483 | ||
484 | buf_input.Read( &ch, 1 ); | |
485 | textCtrl.WriteText( "Value read: " ); | |
486 | textCtrl.WriteText( (char)(ch + '0') ); | |
487 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
488 | switch (buf_input.LastError()) | |
489 | { | |
aa51b2e1 RR |
490 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; |
491 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
492 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
493 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
494 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
495 | } | |
2bf8e4eb RR |
496 | } |
497 | ||
498 | void MyApp::DoStreamDemo4(wxCommandEvent& WXUNUSED(event)) | |
499 | { | |
500 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
501 | ||
502 | wxString msg; | |
503 | ||
504 | textCtrl.Clear(); | |
505 | textCtrl << "\nTesting wxStreamBuffer:\n\n"; | |
506 | ||
507 | // bigger than buffer | |
508 | textCtrl.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" ); | |
509 | ||
510 | wxFileOutputStream file_output( "test_wx.dat" ); | |
511 | for (int i = 0; i < 2000; i++) | |
512 | { | |
513 | char ch = 1; | |
514 | file_output.Write( &ch, 1 ); | |
515 | } | |
516 | ||
517 | textCtrl.WriteText( "Opening with a buffered wxFileInputStream:\n\n" ); | |
518 | ||
519 | wxFileInputStream file_input( "test_wx.dat" ); | |
520 | wxBufferedInputStream buf_input( file_input ); | |
521 | ||
522 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
523 | switch (buf_input.LastError()) | |
524 | { | |
525 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
526 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
527 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
528 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
529 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
530 | } | |
531 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
532 | textCtrl.WriteText( msg ); | |
533 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
534 | textCtrl.WriteText( msg ); | |
535 | textCtrl.WriteText( "\n\n" ); | |
536 | ||
537 | ||
538 | textCtrl.WriteText( "Seeking to position 300:\n\n" ); | |
539 | ||
540 | buf_input.SeekI( 300 ); | |
541 | ||
542 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
543 | switch (buf_input.LastError()) | |
544 | { | |
545 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
546 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
547 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
548 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
549 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
550 | } | |
551 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
552 | textCtrl.WriteText( msg ); | |
553 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
554 | textCtrl.WriteText( msg ); | |
555 | textCtrl.WriteText( "\n\n" ); | |
556 | ||
557 | ||
558 | char buf[2000]; | |
559 | ||
560 | textCtrl.WriteText( "Reading 500 bytes:\n\n" ); | |
aa51b2e1 | 561 | |
2bf8e4eb RR |
562 | buf_input.Read( buf, 500 ); |
563 | ||
564 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
565 | switch (buf_input.LastError()) | |
566 | { | |
567 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
568 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
569 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
570 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
571 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
572 | } | |
573 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
574 | textCtrl.WriteText( msg ); | |
575 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
576 | textCtrl.WriteText( msg ); | |
577 | textCtrl.WriteText( "\n\n" ); | |
578 | ||
579 | textCtrl.WriteText( "Reading another 500 bytes:\n\n" ); | |
580 | ||
581 | buf_input.Read( buf, 500 ); | |
582 | ||
583 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
584 | switch (buf_input.LastError()) | |
585 | { | |
586 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
587 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
588 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
589 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
590 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
591 | } | |
592 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
593 | textCtrl.WriteText( msg ); | |
594 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
595 | textCtrl.WriteText( msg ); | |
596 | textCtrl.WriteText( "\n\n" ); | |
597 | ||
598 | textCtrl.WriteText( "Reading another 500 bytes:\n\n" ); | |
599 | ||
600 | buf_input.Read( buf, 500 ); | |
601 | ||
602 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
603 | switch (buf_input.LastError()) | |
604 | { | |
605 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
606 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
607 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
608 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
609 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
610 | } | |
611 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
612 | textCtrl.WriteText( msg ); | |
613 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
614 | textCtrl.WriteText( msg ); | |
615 | textCtrl.WriteText( "\n\n" ); | |
616 | ||
617 | textCtrl.WriteText( "Reading another 500 bytes:\n\n" ); | |
618 | ||
619 | buf_input.Read( buf, 500 ); | |
620 | ||
621 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
622 | switch (buf_input.LastError()) | |
623 | { | |
624 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
625 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
626 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
627 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
628 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
629 | } | |
630 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
631 | textCtrl.WriteText( msg ); | |
632 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
633 | textCtrl.WriteText( msg ); | |
634 | textCtrl.WriteText( "\n\n" ); | |
aa51b2e1 RR |
635 | } |
636 | ||
dcf924a3 RR |
637 | #if wxUSE_UNICODE |
638 | void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event)) | |
639 | { | |
640 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
8e124873 | 641 | |
dcf924a3 RR |
642 | textCtrl.Clear(); |
643 | textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:"; | |
644 | ||
645 | wxString str; | |
646 |