]>
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 | 125 | ofstream std_file_output( "test_std.dat" ); |
56b79cb9 | 126 | wxFileOutputStream file_output( wxString("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 | |
69d16e3e JS |
181 | // This doesn't compile (at least with VC++ 4) |
182 | #if 0 | |
e57e26dd | 183 | std_file_input >> str; |
c980c992 | 184 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
e57e26dd | 185 | textCtrl.WriteText( tmp ); |
69d16e3e | 186 | #endif |
8e124873 | 187 | |
e57e26dd | 188 | textCtrl.WriteText( "\nReading from wxFileInputStream:\n" ); |
b6bff301 | 189 | |
fae05df5 | 190 | buf_output.Sync(); |
8e124873 | 191 | |
56b79cb9 | 192 | wxFileInputStream file_input( wxString("test_wx.dat") ); |
fae05df5 | 193 | wxBufferedInputStream buf_input( file_input ); |
78e848ca | 194 | wxTextInputStream text_input( file_input ); |
8e124873 | 195 | |
fae05df5 | 196 | text_input >> si; |
c980c992 | 197 | tmp.Printf( _T("Signed int: %d\n"), si ); |
e57e26dd | 198 | textCtrl.WriteText( tmp ); |
8e124873 | 199 | |
fae05df5 | 200 | text_input >> ui; |
c980c992 | 201 | tmp.Printf( _T("Unsigned int: %u\n"), ui ); |
e57e26dd | 202 | textCtrl.WriteText( tmp ); |
8e124873 | 203 | |
fae05df5 | 204 | text_input >> d; |
c980c992 | 205 | tmp.Printf( _T("Double: %f\n"), d ); |
e57e26dd | 206 | textCtrl.WriteText( tmp ); |
8e124873 | 207 | |
fae05df5 | 208 | text_input >> f; |
c980c992 | 209 | tmp.Printf( _T("Float: %f\n"), f ); |
e57e26dd | 210 | textCtrl.WriteText( tmp ); |
8e124873 | 211 | |
fae05df5 | 212 | text_input >> str; |
c980c992 | 213 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
e57e26dd | 214 | textCtrl.WriteText( tmp ); |
8e124873 | 215 | |
53daeada RR |
216 | |
217 | textCtrl << "\nTest for wxDataStream:\n\n"; | |
218 | ||
219 | textCtrl.WriteText( "Writing to wxDataOutputStream:\n" ); | |
8e124873 | 220 | |
53daeada | 221 | file_output.SeekO( 0 ); |
fae05df5 | 222 | wxDataOutputStream data_output( buf_output ); |
53daeada | 223 | |
8e124873 | 224 | wxInt16 i16 = (short)0xFFFF; |
c980c992 | 225 | tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); |
53daeada | 226 | textCtrl.WriteText( tmp ); |
329e86bf | 227 | data_output.Write16( i16 ); |
8e124873 | 228 | |
329e86bf | 229 | wxUint16 ui16 = 0xFFFF; |
c980c992 | 230 | tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); |
53daeada | 231 | textCtrl.WriteText( tmp ); |
329e86bf | 232 | data_output.Write16( ui16 ); |
8e124873 | 233 | |
53daeada | 234 | d = 2.01234567890123456789; |
c980c992 | 235 | tmp.Printf( _T("Double: %f\n"), d ); |
53daeada RR |
236 | textCtrl.WriteText( tmp ); |
237 | data_output.WriteDouble( d ); | |
8e124873 | 238 | |
53daeada | 239 | str = "Hello!"; |
c980c992 | 240 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
53daeada RR |
241 | textCtrl.WriteText( tmp ); |
242 | data_output.WriteString( str ); | |
8e124873 | 243 | |
fae05df5 | 244 | buf_output.Sync(); |
8e124873 | 245 | |
53daeada | 246 | textCtrl.WriteText( "\nReading from wxDataInputStream:\n" ); |
8e124873 | 247 | |
53daeada | 248 | file_input.SeekI( 0 ); |
fae05df5 | 249 | wxDataInputStream data_input( buf_input ); |
53daeada | 250 | |
329e86bf | 251 | i16 = data_input.Read16(); |
c980c992 | 252 | tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); |
53daeada | 253 | textCtrl.WriteText( tmp ); |
8e124873 | 254 | |
329e86bf | 255 | ui16 = data_input.Read16(); |
c980c992 | 256 | tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); |
53daeada RR |
257 | textCtrl.WriteText( tmp ); |
258 | ||
259 | d = data_input.ReadDouble(); | |
c980c992 | 260 | tmp.Printf( _T("Double: %f\n"), d ); |
53daeada | 261 | textCtrl.WriteText( tmp ); |
8e124873 | 262 | |
53daeada | 263 | str = data_input.ReadString(); |
c980c992 | 264 | tmp.Printf( _T("String: %s\n"), str.c_str() ); |
53daeada | 265 | textCtrl.WriteText( tmp ); |
38830220 RR |
266 | } |
267 | ||
1b055864 RR |
268 | void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event)) |
269 | { | |
270 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
271 | ||
272 | textCtrl.Clear(); | |
aa51b2e1 | 273 | textCtrl << _T("\nTesting wxBufferedStream:\n\n"); |
1b055864 RR |
274 | |
275 | char ch,ch2; | |
276 | ||
277 | textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" ); | |
278 | ||
56b79cb9 | 279 | wxFileOutputStream file_output( wxString("test_wx.dat") ); |
1b055864 RR |
280 | wxBufferedOutputStream buf_output( file_output ); |
281 | for (ch = 0; ch < 10; ch++) | |
282 | buf_output.Write( &ch, 1 ); | |
283 | buf_output.Sync(); | |
284 | ||
56b79cb9 | 285 | wxFileInputStream file_input( wxString("test_wx.dat") ); |
1b055864 RR |
286 | for (ch2 = 0; ch2 < 10; ch2++) |
287 | { | |
288 | file_input.Read( &ch, 1 ); | |
289 | textCtrl.WriteText( (char)(ch + '0') ); | |
290 | } | |
291 | textCtrl.WriteText( "\n\n\n" ); | |
292 | ||
293 | textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" ); | |
294 | textCtrl.WriteText( "seeking back to #3 and writing 3:\n\n" ); | |
295 | ||
56b79cb9 | 296 | wxFileOutputStream file_output2( wxString("test_wx2.dat") ); |
1b055864 RR |
297 | wxBufferedOutputStream buf_output2( file_output2 ); |
298 | for (ch = 0; ch < 10; ch++) | |
299 | buf_output2.Write( &ch, 1 ); | |
300 | buf_output2.SeekO( 3 ); | |
301 | ch = 3; | |
302 | buf_output2.Write( &ch, 1 ); | |
303 | buf_output2.Sync(); | |
304 | ||
56b79cb9 | 305 | wxFileInputStream file_input2( wxString("test_wx2.dat") ); |
1b055864 RR |
306 | for (ch2 = 0; ch2 < 10; ch2++) |
307 | { | |
308 | file_input2.Read( &ch, 1 ); | |
309 | textCtrl.WriteText( (char)(ch + '0') ); | |
310 | } | |
311 | textCtrl.WriteText( "\n\n\n" ); | |
312 | ||
313 | // now append 2000 bytes to file (bigger than buffer) | |
314 | buf_output2.SeekO( 0, wxFromEnd ); | |
315 | ch = 1; | |
316 | for (int i = 0; i < 2000; i++) | |
317 | buf_output2.Write( &ch, 1 ); | |
318 | buf_output2.Sync(); | |
319 | ||
320 | textCtrl.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" ); | |
321 | textCtrl.WriteText( "seeking back to #3 and reading 3:\n\n" ); | |
322 | ||
56b79cb9 | 323 | wxFileInputStream file_input3( wxString("test_wx2.dat") ); |
1b055864 RR |
324 | wxBufferedInputStream buf_input3( file_input3 ); |
325 | for (ch2 = 0; ch2 < 10; ch2++) | |
326 | { | |
327 | buf_input3.Read( &ch, 1 ); | |
328 | textCtrl.WriteText( (char)(ch + '0') ); | |
329 | } | |
330 | for (int j = 0; j < 2000; j++) | |
331 | buf_input3.Read( &ch, 1 ); | |
332 | textCtrl.WriteText( "\n" ); | |
333 | buf_input3.SeekI( 3 ); | |
334 | buf_input3.Read( &ch, 1 ); | |
335 | textCtrl.WriteText( (char)(ch + '0') ); | |
336 | textCtrl.WriteText( "\n\n\n" ); | |
337 | ||
338 | } | |
339 | ||
aa51b2e1 RR |
340 | void MyApp::DoStreamDemo3(wxCommandEvent& WXUNUSED(event)) |
341 | { | |
342 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
343 | ||
344 | textCtrl.Clear(); | |
345 | textCtrl << "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n"; | |
346 | ||
347 | char ch,ch2; | |
348 | ||
349 | textCtrl.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" ); | |
350 | ||
56b79cb9 | 351 | wxFileOutputStream file_output( wxString("test_wx.dat") ); |
aa51b2e1 RR |
352 | for (ch = 0; ch < 10; ch++) |
353 | file_output.Write( &ch, 1 ); | |
354 | ||
842d6c94 | 355 | // Testing wxFileInputStream |
aa51b2e1 RR |
356 | |
357 | textCtrl.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" ); | |
358 | ||
56b79cb9 | 359 | wxFileInputStream file_input( wxString("test_wx.dat") ); |
aa51b2e1 RR |
360 | for (ch2 = 0; ch2 < 11; ch2++) |
361 | { | |
362 | file_input.Read( &ch, 1 ); | |
363 | textCtrl.WriteText( "Value read: " ); | |
364 | textCtrl.WriteText( (char)(ch + '0') ); | |
365 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
366 | switch (file_input.LastError()) | |
367 | { | |
368 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
369 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
370 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
371 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
372 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
373 | } | |
374 | } | |
375 | textCtrl.WriteText( "\n" ); | |
376 | ||
377 | textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " ); | |
378 | file_input.SeekI( 0 ); | |
379 | switch (file_input.LastError()) | |
380 | { | |
381 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
382 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
383 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
384 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
385 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
386 | } | |
387 | textCtrl.WriteText( "\n" ); | |
388 | ||
389 | file_input.Read( &ch, 1 ); | |
390 | textCtrl.WriteText( "Value read: " ); | |
391 | textCtrl.WriteText( (char)(ch + '0') ); | |
392 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
393 | switch (file_input.LastError()) | |
394 | { | |
395 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
396 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
397 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
398 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
399 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
400 | } | |
401 | textCtrl.WriteText( "\n\n" ); | |
402 | ||
403 | ||
842d6c94 | 404 | // Testing wxFFileInputStream |
aa51b2e1 RR |
405 | |
406 | textCtrl.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" ); | |
407 | ||
56b79cb9 | 408 | wxFFileInputStream ffile_input( wxString("test_wx.dat") ); |
aa51b2e1 RR |
409 | for (ch2 = 0; ch2 < 11; ch2++) |
410 | { | |
411 | ffile_input.Read( &ch, 1 ); | |
412 | textCtrl.WriteText( "Value read: " ); | |
413 | textCtrl.WriteText( (char)(ch + '0') ); | |
414 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
415 | switch (ffile_input.LastError()) | |
416 | { | |
417 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
418 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
419 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
420 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
421 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
422 | } | |
423 | } | |
424 | textCtrl.WriteText( "\n" ); | |
425 | ||
426 | textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " ); | |
427 | ffile_input.SeekI( 0 ); | |
428 | switch (ffile_input.LastError()) | |
429 | { | |
430 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
431 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
432 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
433 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
434 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
435 | } | |
436 | textCtrl.WriteText( "\n" ); | |
437 | ||
438 | ffile_input.Read( &ch, 1 ); | |
439 | textCtrl.WriteText( "Value read: " ); | |
440 | textCtrl.WriteText( (char)(ch + '0') ); | |
441 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
442 | switch (ffile_input.LastError()) | |
443 | { | |
842d6c94 RR |
444 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; |
445 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
446 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
447 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
448 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
449 | } | |
450 | textCtrl.WriteText( "\n\n" ); | |
451 | ||
452 | // Testing wxFFileInputStream | |
453 | ||
454 | textCtrl.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" ); | |
455 | ||
56b79cb9 | 456 | wxFFileInputStream ffile_input2( wxString("test_wx.dat") ); |
842d6c94 RR |
457 | wxBufferedInputStream buf_input( ffile_input2 ); |
458 | for (ch2 = 0; ch2 < 11; ch2++) | |
459 | { | |
460 | buf_input.Read( &ch, 1 ); | |
461 | textCtrl.WriteText( "Value read: " ); | |
462 | textCtrl.WriteText( (char)(ch + '0') ); | |
463 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
464 | switch (buf_input.LastError()) | |
465 | { | |
466 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
467 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
468 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
469 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
470 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
471 | } | |
472 | } | |
473 | textCtrl.WriteText( "\n" ); | |
474 | ||
475 | textCtrl.WriteText( "Seeking to 0; stream.LastError() returns: " ); | |
476 | buf_input.SeekI( 0 ); | |
477 | switch (buf_input.LastError()) | |
478 | { | |
479 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
480 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
481 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
482 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
483 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
484 | } | |
485 | textCtrl.WriteText( "\n" ); | |
486 | ||
487 | buf_input.Read( &ch, 1 ); | |
488 | textCtrl.WriteText( "Value read: " ); | |
489 | textCtrl.WriteText( (char)(ch + '0') ); | |
490 | textCtrl.WriteText( "; stream.LastError() returns: " ); | |
491 | switch (buf_input.LastError()) | |
492 | { | |
aa51b2e1 RR |
493 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; |
494 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
495 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
496 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
497 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
498 | } | |
2bf8e4eb RR |
499 | } |
500 | ||
501 | void MyApp::DoStreamDemo4(wxCommandEvent& WXUNUSED(event)) | |
502 | { | |
503 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
504 | ||
505 | wxString msg; | |
506 | ||
507 | textCtrl.Clear(); | |
508 | textCtrl << "\nTesting wxStreamBuffer:\n\n"; | |
509 | ||
510 | // bigger than buffer | |
511 | textCtrl.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" ); | |
512 | ||
56b79cb9 | 513 | wxFileOutputStream file_output( wxString("test_wx.dat") ); |
2bf8e4eb RR |
514 | for (int i = 0; i < 2000; i++) |
515 | { | |
516 | char ch = 1; | |
517 | file_output.Write( &ch, 1 ); | |
518 | } | |
519 | ||
520 | textCtrl.WriteText( "Opening with a buffered wxFileInputStream:\n\n" ); | |
521 | ||
56b79cb9 | 522 | wxFileInputStream file_input( wxString("test_wx.dat") ); |
2bf8e4eb RR |
523 | wxBufferedInputStream buf_input( file_input ); |
524 | ||
525 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
526 | switch (buf_input.LastError()) | |
527 | { | |
528 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
529 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
530 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
531 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
532 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
533 | } | |
534 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
535 | textCtrl.WriteText( msg ); | |
536 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
537 | textCtrl.WriteText( msg ); | |
538 | textCtrl.WriteText( "\n\n" ); | |
539 | ||
540 | ||
541 | textCtrl.WriteText( "Seeking to position 300:\n\n" ); | |
542 | ||
543 | buf_input.SeekI( 300 ); | |
544 | ||
545 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
546 | switch (buf_input.LastError()) | |
547 | { | |
548 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
549 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
550 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
551 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
552 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
553 | } | |
554 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
555 | textCtrl.WriteText( msg ); | |
556 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
557 | textCtrl.WriteText( msg ); | |
558 | textCtrl.WriteText( "\n\n" ); | |
559 | ||
560 | ||
561 | char buf[2000]; | |
562 | ||
563 | textCtrl.WriteText( "Reading 500 bytes:\n\n" ); | |
aa51b2e1 | 564 | |
2bf8e4eb RR |
565 | buf_input.Read( buf, 500 ); |
566 | ||
567 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
568 | switch (buf_input.LastError()) | |
569 | { | |
570 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
571 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
572 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
573 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
574 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
575 | } | |
576 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
577 | textCtrl.WriteText( msg ); | |
578 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
579 | textCtrl.WriteText( msg ); | |
580 | textCtrl.WriteText( "\n\n" ); | |
581 | ||
582 | textCtrl.WriteText( "Reading another 500 bytes:\n\n" ); | |
583 | ||
584 | buf_input.Read( buf, 500 ); | |
585 | ||
586 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
587 | switch (buf_input.LastError()) | |
588 | { | |
589 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
590 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
591 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
592 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
593 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
594 | } | |
595 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
596 | textCtrl.WriteText( msg ); | |
597 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
598 | textCtrl.WriteText( msg ); | |
599 | textCtrl.WriteText( "\n\n" ); | |
600 | ||
601 | textCtrl.WriteText( "Reading another 500 bytes:\n\n" ); | |
602 | ||
603 | buf_input.Read( buf, 500 ); | |
604 | ||
605 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
606 | switch (buf_input.LastError()) | |
607 | { | |
608 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
609 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
610 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
611 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
612 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
613 | } | |
614 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
615 | textCtrl.WriteText( msg ); | |
616 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
617 | textCtrl.WriteText( msg ); | |
618 | textCtrl.WriteText( "\n\n" ); | |
619 | ||
620 | textCtrl.WriteText( "Reading another 500 bytes:\n\n" ); | |
621 | ||
622 | buf_input.Read( buf, 500 ); | |
623 | ||
624 | textCtrl.WriteText( "wxBufferedInputStream.LastError() returns: " ); | |
625 | switch (buf_input.LastError()) | |
626 | { | |
627 | case wxSTREAM_NOERROR: textCtrl.WriteText( "wxSTREAM_NOERROR\n" ); break; | |
628 | case wxSTREAM_EOF: textCtrl.WriteText( "wxSTREAM_EOF\n" ); break; | |
629 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( "wxSTREAM_READ_ERROR\n" ); break; | |
630 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break; | |
631 | default: textCtrl.WriteText( "Huh?\n" ); break; | |
632 | } | |
633 | msg.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input.LastRead() ); | |
634 | textCtrl.WriteText( msg ); | |
635 | msg.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input.TellI() ); | |
636 | textCtrl.WriteText( msg ); | |
637 | textCtrl.WriteText( "\n\n" ); | |
aa51b2e1 RR |
638 | } |
639 | ||
dcf924a3 RR |
640 | #if wxUSE_UNICODE |
641 | void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event)) | |
642 | { | |
643 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
8e124873 | 644 | |
dcf924a3 RR |
645 | textCtrl.Clear(); |
646 | textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:"; | |
647 | ||
648 | wxString str; | |
649 |