]>
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 | |
6aa89a22 | 7 | // Copyright: (c) Julian Smart |
526954c5 | 8 | // Licence: wxWindows licence |
cfb88c55 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
cfb88c55 JS |
11 | // For compilers that support precompilation, includes "wx/wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/wx.h" | |
20 | #endif | |
21 | ||
cfb88c55 | 22 | #include "wx/variant.h" |
8e124873 | 23 | #include "wx/mimetype.h" |
cfb88c55 JS |
24 | |
25 | #include "typetest.h" | |
26 | ||
e7092398 | 27 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
3cb332c1 | 28 | #include "../sample.xpm" |
cfb88c55 JS |
29 | #endif |
30 | ||
3f1802b5 JS |
31 | #ifdef new |
32 | #undef new | |
33 | #endif | |
34 | ||
38830220 RR |
35 | #include "wx/ioswrap.h" |
36 | ||
37 | #if wxUSE_IOSTREAMH | |
38 | #include <fstream.h> | |
39 | #else | |
40 | #include <fstream> | |
41 | #endif | |
42 | ||
43 | #include "wx/wfstream.h" | |
53daeada | 44 | #include "wx/datstrm.h" |
fae05df5 | 45 | #include "wx/txtstrm.h" |
f6bcfd97 | 46 | #include "wx/mstream.h" |
38830220 | 47 | |
cfb88c55 | 48 | // Create a new application object |
8e124873 | 49 | IMPLEMENT_APP (MyApp) |
cfb88c55 | 50 | |
8e124873 | 51 | IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp) |
cfb88c55 JS |
52 | |
53 | BEGIN_EVENT_TABLE(MyApp, wxApp) | |
8e124873 VZ |
54 | EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo) |
55 | EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo) | |
dcf924a3 | 56 | #if wxUSE_UNICODE |
8e124873 | 57 | EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo) |
3409ae17 | 58 | #endif // wxUSE_UNICODE |
8e124873 | 59 | EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo) |
aa51b2e1 RR |
60 | EVT_MENU(TYPES_STREAM2, MyApp::DoStreamDemo2) |
61 | EVT_MENU(TYPES_STREAM3, MyApp::DoStreamDemo3) | |
2bf8e4eb | 62 | EVT_MENU(TYPES_STREAM4, MyApp::DoStreamDemo4) |
f6bcfd97 | 63 | EVT_MENU(TYPES_STREAM5, MyApp::DoStreamDemo5) |
cbc906ce RR |
64 | EVT_MENU(TYPES_STREAM6, MyApp::DoStreamDemo6) |
65 | EVT_MENU(TYPES_STREAM7, MyApp::DoStreamDemo7) | |
8e124873 | 66 | EVT_MENU(TYPES_MIME, MyApp::DoMIMEDemo) |
cfb88c55 JS |
67 | END_EVENT_TABLE() |
68 | ||
9a83f860 VZ |
69 | wxString file_name = wxT("test_wx.dat"); |
70 | wxString file_name2 = wxString(wxT("test_wx2.dat")); | |
925e9792 | 71 | |
8e124873 | 72 | bool MyApp::OnInit() |
cfb88c55 | 73 | { |
45e6e6f8 VZ |
74 | if ( !wxApp::OnInit() ) |
75 | return false; | |
76 | ||
8e124873 | 77 | // Create the main frame window |
9a83f860 | 78 | MyFrame *frame = new MyFrame((wxFrame *) NULL, wxT("wxWidgets Types Demo"), |
8e124873 VZ |
79 | wxPoint(50, 50), wxSize(450, 340)); |
80 | ||
81 | // Give it an icon | |
3cb332c1 | 82 | frame->SetIcon(wxICON(sample)); |
8e124873 VZ |
83 | |
84 | // Make a menubar | |
85 | wxMenu *file_menu = new wxMenu; | |
86 | ||
9a83f860 | 87 | file_menu->Append(TYPES_ABOUT, wxT("&About")); |
8e124873 | 88 | file_menu->AppendSeparator(); |
9a83f860 | 89 | file_menu->Append(TYPES_QUIT, wxT("E&xit\tAlt-X")); |
8e124873 VZ |
90 | |
91 | wxMenu *test_menu = new wxMenu; | |
9a83f860 VZ |
92 | test_menu->Append(TYPES_VARIANT, wxT("&Variant test")); |
93 | test_menu->Append(TYPES_BYTEORDER, wxT("&Byteorder test")); | |
dcf924a3 | 94 | #if wxUSE_UNICODE |
9a83f860 | 95 | test_menu->Append(TYPES_UNICODE, wxT("&Unicode test")); |
3409ae17 | 96 | #endif // wxUSE_UNICODE |
9a83f860 VZ |
97 | test_menu->Append(TYPES_STREAM, wxT("&Stream test")); |
98 | test_menu->Append(TYPES_STREAM2, wxT("&Stream seek test")); | |
99 | test_menu->Append(TYPES_STREAM3, wxT("&Stream error test")); | |
100 | test_menu->Append(TYPES_STREAM4, wxT("&Stream buffer test")); | |
101 | test_menu->Append(TYPES_STREAM5, wxT("&Stream peek test")); | |
102 | test_menu->Append(TYPES_STREAM6, wxT("&Stream ungetch test")); | |
103 | test_menu->Append(TYPES_STREAM7, wxT("&Stream ungetch test for a buffered stream")); | |
8e124873 | 104 | test_menu->AppendSeparator(); |
9a83f860 | 105 | test_menu->Append(TYPES_MIME, wxT("&MIME database test")); |
cfb88c55 | 106 | |
8e124873 | 107 | wxMenuBar *menu_bar = new wxMenuBar; |
9a83f860 VZ |
108 | menu_bar->Append(file_menu, wxT("&File")); |
109 | menu_bar->Append(test_menu, wxT("&Tests")); | |
8e124873 | 110 | frame->SetMenuBar(menu_bar); |
cfb88c55 | 111 | |
206d3a16 JS |
112 | m_textCtrl = new wxTextCtrl(frame, wxID_ANY, wxEmptyString, |
113 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); | |
cfb88c55 | 114 | |
8e124873 | 115 | // Show the frame |
206d3a16 | 116 | frame->Show(true); |
8e124873 | 117 | |
206d3a16 | 118 | return true; |
cfb88c55 JS |
119 | } |
120 | ||
38830220 RR |
121 | void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) |
122 | { | |
123 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
8e124873 | 124 | |
38830220 | 125 | textCtrl.Clear(); |
9a83f860 | 126 | textCtrl << wxT("\nTest fstream vs. wxFileStream:\n\n"); |
38830220 | 127 | |
9a83f860 | 128 | textCtrl.WriteText( wxT("Writing to ofstream and wxFileOutputStream:\n") ); |
8e124873 | 129 | |
dd107c50 | 130 | wxSTD ofstream std_file_output( "test_std.dat" ); |
925e9792 | 131 | wxFileOutputStream file_output( file_name ); |
fae05df5 GL |
132 | wxBufferedOutputStream buf_output( file_output ); |
133 | wxTextOutputStream text_output( buf_output ); | |
38830220 | 134 | |
38830220 RR |
135 | wxString tmp; |
136 | signed int si = 0xFFFFFFFF; | |
9a83f860 | 137 | tmp.Printf( wxT("Signed int: %d\n"), si ); |
38830220 | 138 | textCtrl.WriteText( tmp ); |
9a83f860 | 139 | text_output << si << wxT("\n"); |
19b44116 | 140 | std_file_output << si << "\n"; |
8e124873 | 141 | |
38830220 | 142 | unsigned int ui = 0xFFFFFFFF; |
9a83f860 | 143 | tmp.Printf( wxT("Unsigned int: %u\n"), ui ); |
38830220 | 144 | textCtrl.WriteText( tmp ); |
9a83f860 | 145 | text_output << ui << wxT("\n"); |
19b44116 | 146 | std_file_output << ui << "\n"; |
8e124873 | 147 | |
38830220 | 148 | double d = 2.01234567890123456789; |
9a83f860 | 149 | tmp.Printf( wxT("Double: %f\n"), d ); |
38830220 | 150 | textCtrl.WriteText( tmp ); |
9a83f860 | 151 | text_output << d << wxT("\n"); |
19b44116 | 152 | std_file_output << d << "\n"; |
8e124873 VZ |
153 | |
154 | float f = (float)0.00001; | |
9a83f860 | 155 | tmp.Printf( wxT("Float: %f\n"), f ); |
e57e26dd | 156 | textCtrl.WriteText( tmp ); |
9a83f860 | 157 | text_output << f << wxT("\n"); |
19b44116 | 158 | std_file_output << f << "\n"; |
8e124873 | 159 | |
9a83f860 VZ |
160 | wxString str( wxT("Hello!") ); |
161 | tmp.Printf( wxT("String: %s\n"), str.c_str() ); | |
38830220 | 162 | textCtrl.WriteText( tmp ); |
9a83f860 | 163 | text_output << str << wxT("\n"); |
19b44116 | 164 | std_file_output << str.ToAscii() << "\n"; |
2b5f62a0 | 165 | |
b6e2aaac VS |
166 | std_file_output.close(); |
167 | ||
9a83f860 | 168 | textCtrl.WriteText( wxT("\nReading from ifstream:\n") ); |
8e124873 | 169 | |
dd107c50 | 170 | wxSTD ifstream std_file_input( "test_std.dat" ); |
e57e26dd RR |
171 | |
172 | std_file_input >> si; | |
9a83f860 | 173 | tmp.Printf( wxT("Signed int: %d\n"), si ); |
e57e26dd | 174 | textCtrl.WriteText( tmp ); |
8e124873 | 175 | |
e57e26dd | 176 | std_file_input >> ui; |
9a83f860 | 177 | tmp.Printf( wxT("Unsigned int: %u\n"), ui ); |
e57e26dd | 178 | textCtrl.WriteText( tmp ); |
8e124873 | 179 | |
e57e26dd | 180 | std_file_input >> d; |
9a83f860 | 181 | tmp.Printf( wxT("Double: %f\n"), d ); |
e57e26dd | 182 | textCtrl.WriteText( tmp ); |
8e124873 | 183 | |
e57e26dd | 184 | std_file_input >> f; |
9a83f860 | 185 | tmp.Printf( wxT("Float: %f\n"), f ); |
e57e26dd | 186 | textCtrl.WriteText( tmp ); |
8e124873 | 187 | |
f6bcfd97 BP |
188 | char std_buf[200]; |
189 | std_file_input >> std_buf; | |
2a1f999f | 190 | str = wxString::FromAscii(std_buf); |
9a83f860 | 191 | tmp.Printf( wxT("String: %s\n"), str.c_str() ); |
e57e26dd | 192 | textCtrl.WriteText( tmp ); |
8e124873 | 193 | |
9a83f860 | 194 | textCtrl.WriteText( wxT("\nReading from wxFileInputStream:\n") ); |
b6bff301 | 195 | |
fae05df5 | 196 | buf_output.Sync(); |
8e124873 | 197 | |
925e9792 | 198 | wxFileInputStream file_input( file_name ); |
fae05df5 | 199 | wxBufferedInputStream buf_input( file_input ); |
78e848ca | 200 | wxTextInputStream text_input( file_input ); |
8e124873 | 201 | |
fae05df5 | 202 | text_input >> si; |
9a83f860 | 203 | tmp.Printf( wxT("Signed int: %d\n"), si ); |
e57e26dd | 204 | textCtrl.WriteText( tmp ); |
8e124873 | 205 | |
fae05df5 | 206 | text_input >> ui; |
9a83f860 | 207 | tmp.Printf( wxT("Unsigned int: %u\n"), ui ); |
e57e26dd | 208 | textCtrl.WriteText( tmp ); |
8e124873 | 209 | |
fae05df5 | 210 | text_input >> d; |
9a83f860 | 211 | tmp.Printf( wxT("Double: %f\n"), d ); |
e57e26dd | 212 | textCtrl.WriteText( tmp ); |
8e124873 | 213 | |
fae05df5 | 214 | text_input >> f; |
9a83f860 | 215 | tmp.Printf( wxT("Float: %f\n"), f ); |
e57e26dd | 216 | textCtrl.WriteText( tmp ); |
8e124873 | 217 | |
fae05df5 | 218 | text_input >> str; |
9a83f860 | 219 | tmp.Printf( wxT("String: %s\n"), str.c_str() ); |
e57e26dd | 220 | textCtrl.WriteText( tmp ); |
8e124873 | 221 | |
53daeada | 222 | |
f6bcfd97 | 223 | |
9a83f860 | 224 | textCtrl << wxT("\nTest for wxDataStream:\n\n"); |
53daeada | 225 | |
9a83f860 | 226 | textCtrl.WriteText( wxT("Writing to wxDataOutputStream:\n") ); |
8e124873 | 227 | |
53daeada | 228 | file_output.SeekO( 0 ); |
fae05df5 | 229 | wxDataOutputStream data_output( buf_output ); |
53daeada | 230 | |
364f80ef | 231 | wxInt16 i16 = (unsigned short)0xFFFF; |
9a83f860 | 232 | tmp.Printf( wxT("Signed int16: %d\n"), (int)i16 ); |
53daeada | 233 | textCtrl.WriteText( tmp ); |
329e86bf | 234 | data_output.Write16( i16 ); |
8e124873 | 235 | |
329e86bf | 236 | wxUint16 ui16 = 0xFFFF; |
9a83f860 | 237 | tmp.Printf( wxT("Unsigned int16: %u\n"), (unsigned int) ui16 ); |
53daeada | 238 | textCtrl.WriteText( tmp ); |
329e86bf | 239 | data_output.Write16( ui16 ); |
8e124873 | 240 | |
53daeada | 241 | d = 2.01234567890123456789; |
9a83f860 | 242 | tmp.Printf( wxT("Double: %f\n"), d ); |
53daeada RR |
243 | textCtrl.WriteText( tmp ); |
244 | data_output.WriteDouble( d ); | |
8e124873 | 245 | |
9a83f860 VZ |
246 | str = wxT("Hello!"); |
247 | tmp.Printf( wxT("String: %s\n"), str.c_str() ); | |
53daeada RR |
248 | textCtrl.WriteText( tmp ); |
249 | data_output.WriteString( str ); | |
8e124873 | 250 | |
fae05df5 | 251 | buf_output.Sync(); |
8e124873 | 252 | |
9a83f860 | 253 | textCtrl.WriteText( wxT("\nReading from wxDataInputStream:\n") ); |
8e124873 | 254 | |
53daeada | 255 | file_input.SeekI( 0 ); |
fae05df5 | 256 | wxDataInputStream data_input( buf_input ); |
53daeada | 257 | |
329e86bf | 258 | i16 = data_input.Read16(); |
9a83f860 | 259 | tmp.Printf( wxT("Signed int16: %d\n"), (int)i16 ); |
53daeada | 260 | textCtrl.WriteText( tmp ); |
8e124873 | 261 | |
329e86bf | 262 | ui16 = data_input.Read16(); |
9a83f860 | 263 | tmp.Printf( wxT("Unsigned int16: %u\n"), (unsigned int) ui16 ); |
53daeada RR |
264 | textCtrl.WriteText( tmp ); |
265 | ||
266 | d = data_input.ReadDouble(); | |
9a83f860 | 267 | tmp.Printf( wxT("Double: %f\n"), d ); |
53daeada | 268 | textCtrl.WriteText( tmp ); |
8e124873 | 269 | |
53daeada | 270 | str = data_input.ReadString(); |
9a83f860 | 271 | tmp.Printf( wxT("String: %s\n"), str.c_str() ); |
53daeada | 272 | textCtrl.WriteText( tmp ); |
38830220 RR |
273 | } |
274 | ||
1b055864 RR |
275 | void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event)) |
276 | { | |
277 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
278 | ||
279 | textCtrl.Clear(); | |
9a83f860 | 280 | textCtrl << wxT("\nTesting wxBufferedStream:\n\n"); |
1b055864 RR |
281 | |
282 | char ch,ch2; | |
283 | ||
9a83f860 | 284 | textCtrl.WriteText( wxT("Writing number 0 to 9 to buffered wxFileOutputStream:\n\n") ); |
1b055864 | 285 | |
925e9792 | 286 | wxFileOutputStream file_output( file_name ); |
1b055864 RR |
287 | wxBufferedOutputStream buf_output( file_output ); |
288 | for (ch = 0; ch < 10; ch++) | |
289 | buf_output.Write( &ch, 1 ); | |
290 | buf_output.Sync(); | |
2b5f62a0 | 291 | |
925e9792 | 292 | wxFileInputStream file_input( file_name ); |
1b055864 RR |
293 | for (ch2 = 0; ch2 < 10; ch2++) |
294 | { | |
295 | file_input.Read( &ch, 1 ); | |
9a83f860 | 296 | textCtrl.WriteText( (wxChar)(ch + wxT('0')) ); |
1b055864 | 297 | } |
9a83f860 | 298 | textCtrl.WriteText( wxT("\n\n\n") ); |
2b5f62a0 | 299 | |
9a83f860 VZ |
300 | textCtrl.WriteText( wxT("Writing number 0 to 9 to buffered wxFileOutputStream, then\n") ); |
301 | textCtrl.WriteText( wxT("seeking back to #3 and writing 0:\n\n") ); | |
1b055864 | 302 | |
925e9792 | 303 | wxFileOutputStream file_output2( file_name2 ); |
1b055864 RR |
304 | wxBufferedOutputStream buf_output2( file_output2 ); |
305 | for (ch = 0; ch < 10; ch++) | |
306 | buf_output2.Write( &ch, 1 ); | |
307 | buf_output2.SeekO( 3 ); | |
cbc906ce | 308 | ch = 0; |
1b055864 RR |
309 | buf_output2.Write( &ch, 1 ); |
310 | buf_output2.Sync(); | |
2b5f62a0 | 311 | |
925e9792 | 312 | wxFileInputStream file_input2( file_name2 ); |
1b055864 RR |
313 | for (ch2 = 0; ch2 < 10; ch2++) |
314 | { | |
315 | file_input2.Read( &ch, 1 ); | |
9a83f860 | 316 | textCtrl.WriteText( (wxChar)(ch + wxT('0')) ); |
1b055864 | 317 | } |
9a83f860 | 318 | textCtrl.WriteText( wxT("\n\n\n") ); |
2b5f62a0 | 319 | |
1b055864 RR |
320 | // now append 2000 bytes to file (bigger than buffer) |
321 | buf_output2.SeekO( 0, wxFromEnd ); | |
322 | ch = 1; | |
323 | for (int i = 0; i < 2000; i++) | |
324 | buf_output2.Write( &ch, 1 ); | |
325 | buf_output2.Sync(); | |
2b5f62a0 | 326 | |
9a83f860 VZ |
327 | textCtrl.WriteText( wxT("Reading number 0 to 9 from buffered wxFileInputStream, then\n") ); |
328 | textCtrl.WriteText( wxT("seeking back to #3 and reading the 0:\n\n") ); | |
1b055864 | 329 | |
925e9792 | 330 | wxFileInputStream file_input3( file_name2 ); |
1b055864 RR |
331 | wxBufferedInputStream buf_input3( file_input3 ); |
332 | for (ch2 = 0; ch2 < 10; ch2++) | |
333 | { | |
334 | buf_input3.Read( &ch, 1 ); | |
9a83f860 | 335 | textCtrl.WriteText( (wxChar)(ch + wxT('0')) ); |
1b055864 RR |
336 | } |
337 | for (int j = 0; j < 2000; j++) | |
338 | buf_input3.Read( &ch, 1 ); | |
9a83f860 | 339 | textCtrl.WriteText( wxT("\n") ); |
1b055864 RR |
340 | buf_input3.SeekI( 3 ); |
341 | buf_input3.Read( &ch, 1 ); | |
9a83f860 VZ |
342 | textCtrl.WriteText( (wxChar)(ch + wxT('0')) ); |
343 | textCtrl.WriteText( wxT("\n\n\n") ); | |
2b5f62a0 | 344 | |
1b055864 RR |
345 | } |
346 | ||
aa51b2e1 RR |
347 | void MyApp::DoStreamDemo3(wxCommandEvent& WXUNUSED(event)) |
348 | { | |
349 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
350 | ||
351 | textCtrl.Clear(); | |
9a83f860 | 352 | textCtrl << wxT("\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n"); |
aa51b2e1 RR |
353 | |
354 | char ch,ch2; | |
355 | ||
9a83f860 | 356 | textCtrl.WriteText( wxT("Writing number 0 to 9 to wxFileOutputStream:\n\n") ); |
aa51b2e1 | 357 | |
925e9792 | 358 | wxFileOutputStream file_output( file_name ); |
aa51b2e1 RR |
359 | for (ch = 0; ch < 10; ch++) |
360 | file_output.Write( &ch, 1 ); | |
361 | ||
842d6c94 | 362 | // Testing wxFileInputStream |
2b5f62a0 | 363 | |
9a83f860 | 364 | textCtrl.WriteText( wxT("Reading 0 to 10 to wxFileInputStream:\n\n") ); |
aa51b2e1 | 365 | |
925e9792 | 366 | wxFileInputStream file_input( file_name ); |
aa51b2e1 RR |
367 | for (ch2 = 0; ch2 < 11; ch2++) |
368 | { | |
369 | file_input.Read( &ch, 1 ); | |
9a83f860 | 370 | textCtrl.WriteText( wxT("Value read: ") ); |
4693b20c | 371 | textCtrl.WriteText( (wxChar)(ch + '0') ); |
9a83f860 | 372 | textCtrl.WriteText( wxT("; stream.GetLastError() returns: ") ); |
2b5f62a0 | 373 | switch (file_input.GetLastError()) |
f6bcfd97 | 374 | { |
9a83f860 VZ |
375 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
376 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
377 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
378 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
379 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
f6bcfd97 | 380 | } |
aa51b2e1 | 381 | } |
9a83f860 | 382 | textCtrl.WriteText( wxT("\n") ); |
2b5f62a0 | 383 | |
9a83f860 | 384 | textCtrl.WriteText( wxT("Seeking to 0; stream.GetLastError() returns: ") ); |
aa51b2e1 | 385 | file_input.SeekI( 0 ); |
2b5f62a0 | 386 | switch (file_input.GetLastError()) |
aa51b2e1 | 387 | { |
9a83f860 VZ |
388 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
389 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
390 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
391 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
392 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
aa51b2e1 | 393 | } |
9a83f860 | 394 | textCtrl.WriteText( wxT("\n") ); |
2b5f62a0 | 395 | |
aa51b2e1 | 396 | file_input.Read( &ch, 1 ); |
9a83f860 VZ |
397 | textCtrl.WriteText( wxT("Value read: ") ); |
398 | textCtrl.WriteText( (wxChar)(ch + wxT('0')) ); | |
399 | textCtrl.WriteText( wxT("; stream.GetLastError() returns: ") ); | |
2b5f62a0 | 400 | switch (file_input.GetLastError()) |
aa51b2e1 | 401 | { |
9a83f860 VZ |
402 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
403 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
404 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
405 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
406 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
aa51b2e1 | 407 | } |
9a83f860 | 408 | textCtrl.WriteText( wxT("\n\n") ); |
aa51b2e1 | 409 | |
2b5f62a0 | 410 | |
842d6c94 | 411 | // Testing wxFFileInputStream |
2b5f62a0 | 412 | |
9a83f860 | 413 | textCtrl.WriteText( wxT("Reading 0 to 10 to wxFFileInputStream:\n\n") ); |
aa51b2e1 | 414 | |
925e9792 | 415 | wxFFileInputStream ffile_input( file_name ); |
aa51b2e1 RR |
416 | for (ch2 = 0; ch2 < 11; ch2++) |
417 | { | |
418 | ffile_input.Read( &ch, 1 ); | |
9a83f860 | 419 | textCtrl.WriteText( wxT("Value read: ") ); |
4693b20c | 420 | textCtrl.WriteText( (wxChar)(ch + '0') ); |
9a83f860 | 421 | textCtrl.WriteText( wxT("; stream.GetLastError() returns: ") ); |
2b5f62a0 | 422 | switch (ffile_input.GetLastError()) |
f6bcfd97 | 423 | { |
9a83f860 VZ |
424 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
425 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
426 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
427 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
428 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2f6c54eb | 429 | } |
aa51b2e1 | 430 | } |
9a83f860 | 431 | textCtrl.WriteText( wxT("\n") ); |
2b5f62a0 | 432 | |
9a83f860 | 433 | textCtrl.WriteText( wxT("Seeking to 0; stream.GetLastError() returns: ") ); |
aa51b2e1 | 434 | ffile_input.SeekI( 0 ); |
2b5f62a0 | 435 | switch (ffile_input.GetLastError()) |
aa51b2e1 | 436 | { |
9a83f860 VZ |
437 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
438 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
439 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
440 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
441 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
aa51b2e1 | 442 | } |
9a83f860 | 443 | textCtrl.WriteText( wxT("\n") ); |
2b5f62a0 | 444 | |
aa51b2e1 | 445 | ffile_input.Read( &ch, 1 ); |
9a83f860 | 446 | textCtrl.WriteText( wxT("Value read: ") ); |
4693b20c | 447 | textCtrl.WriteText( (wxChar)(ch + '0') ); |
9a83f860 | 448 | textCtrl.WriteText( wxT("; stream.GetLastError() returns: ") ); |
2b5f62a0 | 449 | switch (ffile_input.GetLastError()) |
aa51b2e1 | 450 | { |
9a83f860 VZ |
451 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
452 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
453 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
454 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
455 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
842d6c94 | 456 | } |
9a83f860 | 457 | textCtrl.WriteText( wxT("\n\n") ); |
842d6c94 RR |
458 | |
459 | // Testing wxFFileInputStream | |
2b5f62a0 | 460 | |
9a83f860 | 461 | textCtrl.WriteText( wxT("Reading 0 to 10 to buffered wxFFileInputStream:\n\n") ); |
842d6c94 | 462 | |
925e9792 | 463 | wxFFileInputStream ffile_input2( file_name ); |
842d6c94 RR |
464 | wxBufferedInputStream buf_input( ffile_input2 ); |
465 | for (ch2 = 0; ch2 < 11; ch2++) | |
466 | { | |
467 | buf_input.Read( &ch, 1 ); | |
9a83f860 | 468 | textCtrl.WriteText( wxT("Value read: ") ); |
4693b20c | 469 | textCtrl.WriteText( (wxChar)(ch + '0') ); |
9a83f860 | 470 | textCtrl.WriteText( wxT("; stream.GetLastError() returns: ") ); |
2b5f62a0 | 471 | switch (buf_input.GetLastError()) |
f6bcfd97 | 472 | { |
9a83f860 VZ |
473 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
474 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
475 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
476 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
477 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
f6bcfd97 | 478 | } |
842d6c94 | 479 | } |
9a83f860 | 480 | textCtrl.WriteText( wxT("\n") ); |
2b5f62a0 | 481 | |
9a83f860 | 482 | textCtrl.WriteText( wxT("Seeking to 0; stream.GetLastError() returns: ") ); |
842d6c94 | 483 | buf_input.SeekI( 0 ); |
2b5f62a0 | 484 | switch (buf_input.GetLastError()) |
842d6c94 | 485 | { |
9a83f860 VZ |
486 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
487 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
488 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
489 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
490 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
842d6c94 | 491 | } |
9a83f860 | 492 | textCtrl.WriteText( wxT("\n") ); |
2b5f62a0 | 493 | |
842d6c94 | 494 | buf_input.Read( &ch, 1 ); |
9a83f860 | 495 | textCtrl.WriteText( wxT("Value read: ") ); |
4693b20c | 496 | textCtrl.WriteText( (wxChar)(ch + '0') ); |
9a83f860 | 497 | textCtrl.WriteText( wxT("; stream.GetLastError() returns: ") ); |
2b5f62a0 | 498 | switch (buf_input.GetLastError()) |
842d6c94 | 499 | { |
9a83f860 VZ |
500 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
501 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
502 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
503 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
504 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
aa51b2e1 | 505 | } |
2bf8e4eb RR |
506 | } |
507 | ||
508 | void MyApp::DoStreamDemo4(wxCommandEvent& WXUNUSED(event)) | |
509 | { | |
510 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
511 | ||
512 | wxString msg; | |
2b5f62a0 | 513 | |
2bf8e4eb | 514 | textCtrl.Clear(); |
9a83f860 | 515 | textCtrl << wxT("\nTesting wxStreamBuffer:\n\n"); |
2bf8e4eb RR |
516 | |
517 | // bigger than buffer | |
9a83f860 | 518 | textCtrl.WriteText( wxT("Writing 2000x 1 to wxFileOutputStream.\n\n") ); |
2bf8e4eb | 519 | |
925e9792 | 520 | wxFileOutputStream file_output( file_name ); |
2bf8e4eb RR |
521 | for (int i = 0; i < 2000; i++) |
522 | { | |
523 | char ch = 1; | |
524 | file_output.Write( &ch, 1 ); | |
525 | } | |
526 | ||
9a83f860 | 527 | textCtrl.WriteText( wxT("Opening with a buffered wxFileInputStream:\n\n") ); |
2bf8e4eb | 528 | |
925e9792 | 529 | wxFileInputStream file_input( file_name ); |
2bf8e4eb | 530 | wxBufferedInputStream buf_input( file_input ); |
2b5f62a0 | 531 | |
9a83f860 | 532 | textCtrl.WriteText( wxT("wxBufferedInputStream.GetLastError() returns: ") ); |
2b5f62a0 | 533 | switch (buf_input.GetLastError()) |
2bf8e4eb | 534 | { |
9a83f860 VZ |
535 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
536 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
537 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
538 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
539 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2bf8e4eb | 540 | } |
4693b20c | 541 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); |
2bf8e4eb | 542 | textCtrl.WriteText( msg ); |
4693b20c | 543 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); |
2bf8e4eb | 544 | textCtrl.WriteText( msg ); |
9a83f860 | 545 | textCtrl.WriteText( wxT("\n\n") ); |
2b5f62a0 | 546 | |
2bf8e4eb | 547 | |
9a83f860 | 548 | textCtrl.WriteText( wxT("Seeking to position 300:\n\n") ); |
2bf8e4eb RR |
549 | |
550 | buf_input.SeekI( 300 ); | |
2b5f62a0 | 551 | |
9a83f860 | 552 | textCtrl.WriteText( wxT("wxBufferedInputStream.GetLastError() returns: ") ); |
2b5f62a0 | 553 | switch (buf_input.GetLastError()) |
2bf8e4eb | 554 | { |
9a83f860 VZ |
555 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
556 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
557 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
558 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
559 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2bf8e4eb | 560 | } |
4693b20c | 561 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); |
2bf8e4eb | 562 | textCtrl.WriteText( msg ); |
4693b20c | 563 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); |
2bf8e4eb | 564 | textCtrl.WriteText( msg ); |
9a83f860 | 565 | textCtrl.WriteText( wxT("\n\n") ); |
2b5f62a0 | 566 | |
2bf8e4eb RR |
567 | |
568 | char buf[2000]; | |
569 | ||
9a83f860 | 570 | textCtrl.WriteText( wxT("Reading 500 bytes:\n\n") ); |
aa51b2e1 | 571 | |
2bf8e4eb | 572 | buf_input.Read( buf, 500 ); |
2b5f62a0 | 573 | |
9a83f860 | 574 | textCtrl.WriteText( wxT("wxBufferedInputStream.GetLastError() returns: ") ); |
2b5f62a0 | 575 | switch (buf_input.GetLastError()) |
2bf8e4eb | 576 | { |
9a83f860 VZ |
577 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
578 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
579 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
580 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
581 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2bf8e4eb | 582 | } |
4693b20c | 583 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); |
2bf8e4eb | 584 | textCtrl.WriteText( msg ); |
4693b20c | 585 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); |
2bf8e4eb | 586 | textCtrl.WriteText( msg ); |
9a83f860 | 587 | textCtrl.WriteText( wxT("\n\n") ); |
2b5f62a0 | 588 | |
9a83f860 | 589 | textCtrl.WriteText( wxT("Reading another 500 bytes:\n\n") ); |
2bf8e4eb RR |
590 | |
591 | buf_input.Read( buf, 500 ); | |
2b5f62a0 | 592 | |
9a83f860 | 593 | textCtrl.WriteText( wxT("wxBufferedInputStream.GetLastError() returns: ") ); |
2b5f62a0 | 594 | switch (buf_input.GetLastError()) |
2bf8e4eb | 595 | { |
9a83f860 VZ |
596 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
597 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
598 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
599 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
600 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2bf8e4eb | 601 | } |
4693b20c | 602 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); |
2bf8e4eb | 603 | textCtrl.WriteText( msg ); |
4693b20c | 604 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); |
2bf8e4eb | 605 | textCtrl.WriteText( msg ); |
9a83f860 | 606 | textCtrl.WriteText( wxT("\n\n") ); |
2bf8e4eb | 607 | |
9a83f860 | 608 | textCtrl.WriteText( wxT("Reading another 500 bytes:\n\n") ); |
2bf8e4eb RR |
609 | |
610 | buf_input.Read( buf, 500 ); | |
2b5f62a0 | 611 | |
9a83f860 | 612 | textCtrl.WriteText( wxT("wxBufferedInputStream.GetLastError() returns: ") ); |
2b5f62a0 | 613 | switch (buf_input.GetLastError()) |
2bf8e4eb | 614 | { |
9a83f860 VZ |
615 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
616 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
617 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
618 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
619 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2bf8e4eb | 620 | } |
4693b20c | 621 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); |
2bf8e4eb | 622 | textCtrl.WriteText( msg ); |
4693b20c | 623 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); |
2bf8e4eb | 624 | textCtrl.WriteText( msg ); |
9a83f860 | 625 | textCtrl.WriteText( wxT("\n\n") ); |
2bf8e4eb | 626 | |
9a83f860 | 627 | textCtrl.WriteText( wxT("Reading another 500 bytes:\n\n") ); |
2bf8e4eb RR |
628 | |
629 | buf_input.Read( buf, 500 ); | |
2b5f62a0 | 630 | |
9a83f860 | 631 | textCtrl.WriteText( wxT("wxBufferedInputStream.GetLastError() returns: ") ); |
2b5f62a0 | 632 | switch (buf_input.GetLastError()) |
2bf8e4eb | 633 | { |
9a83f860 VZ |
634 | case wxSTREAM_NO_ERROR: textCtrl.WriteText( wxT("wxSTREAM_NO_ERROR\n") ); break; |
635 | case wxSTREAM_EOF: textCtrl.WriteText( wxT("wxSTREAM_EOF\n") ); break; | |
636 | case wxSTREAM_READ_ERROR: textCtrl.WriteText( wxT("wxSTREAM_READ_ERROR\n") ); break; | |
637 | case wxSTREAM_WRITE_ERROR: textCtrl.WriteText( wxT("wxSTREAM_WRITE_ERROR\n") ); break; | |
638 | default: textCtrl.WriteText( wxT("Huh?\n") ); break; | |
2bf8e4eb | 639 | } |
4693b20c | 640 | msg.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input.LastRead() ); |
2bf8e4eb | 641 | textCtrl.WriteText( msg ); |
4693b20c | 642 | msg.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input.TellI() ); |
2bf8e4eb | 643 | textCtrl.WriteText( msg ); |
9a83f860 | 644 | textCtrl.WriteText( wxT("\n\n") ); |
aa51b2e1 RR |
645 | } |
646 | ||
f6bcfd97 BP |
647 | void MyApp::DoStreamDemo5(wxCommandEvent& WXUNUSED(event)) |
648 | { | |
649 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
650 | ||
651 | textCtrl.Clear(); | |
9a83f860 | 652 | textCtrl << wxT("\nTesting wxFileInputStream's Peek():\n\n"); |
f6bcfd97 BP |
653 | |
654 | char ch; | |
655 | wxString str; | |
656 | ||
9a83f860 | 657 | textCtrl.WriteText( wxT("Writing number 0 to 9 to wxFileOutputStream:\n\n") ); |
f6bcfd97 | 658 | |
925e9792 | 659 | wxFileOutputStream file_output( file_name ); |
f6bcfd97 BP |
660 | for (ch = 0; ch < 10; ch++) |
661 | file_output.Write( &ch, 1 ); | |
2b5f62a0 | 662 | |
f6bcfd97 | 663 | file_output.Sync(); |
2b5f62a0 | 664 | |
925e9792 | 665 | wxFileInputStream file_input( file_name ); |
2b5f62a0 | 666 | |
f6bcfd97 | 667 | ch = file_input.Peek(); |
4693b20c | 668 | str.Printf( wxT("First char peeked: %d\n"), (int) ch ); |
f6bcfd97 | 669 | textCtrl.WriteText( str ); |
2b5f62a0 | 670 | |
f6bcfd97 | 671 | ch = file_input.GetC(); |
4693b20c | 672 | str.Printf( wxT("First char read: %d\n"), (int) ch ); |
f6bcfd97 | 673 | textCtrl.WriteText( str ); |
2b5f62a0 | 674 | |
f6bcfd97 | 675 | ch = file_input.Peek(); |
4693b20c | 676 | str.Printf( wxT("Second char peeked: %d\n"), (int) ch ); |
f6bcfd97 | 677 | textCtrl.WriteText( str ); |
2b5f62a0 | 678 | |
f6bcfd97 | 679 | ch = file_input.GetC(); |
4693b20c | 680 | str.Printf( wxT("Second char read: %d\n"), (int) ch ); |
f6bcfd97 | 681 | textCtrl.WriteText( str ); |
2b5f62a0 | 682 | |
f6bcfd97 | 683 | ch = file_input.Peek(); |
4693b20c | 684 | str.Printf( wxT("Third char peeked: %d\n"), (int) ch ); |
f6bcfd97 | 685 | textCtrl.WriteText( str ); |
2b5f62a0 | 686 | |
f6bcfd97 | 687 | ch = file_input.GetC(); |
4693b20c | 688 | str.Printf( wxT("Third char read: %d\n"), (int) ch ); |
f6bcfd97 | 689 | textCtrl.WriteText( str ); |
2b5f62a0 VZ |
690 | |
691 | ||
9a83f860 | 692 | textCtrl << wxT("\n\n\nTesting wxMemoryInputStream's Peek():\n\n"); |
2b5f62a0 | 693 | |
f6bcfd97 BP |
694 | char buf[] = { 0,1,2,3,4,5,6,7,8,9,10 }; |
695 | wxMemoryInputStream input( buf, 10 ); | |
2b5f62a0 | 696 | |
f6bcfd97 | 697 | ch = input.Peek(); |
4693b20c | 698 | str.Printf( wxT("First char peeked: %d\n"), (int) ch ); |
f6bcfd97 | 699 | textCtrl.WriteText( str ); |
2b5f62a0 | 700 | |
f6bcfd97 | 701 | ch = input.GetC(); |
4693b20c | 702 | str.Printf( wxT("First char read: %d\n"), (int) ch ); |
f6bcfd97 | 703 | textCtrl.WriteText( str ); |
2b5f62a0 | 704 | |
f6bcfd97 | 705 | ch = input.Peek(); |
4693b20c | 706 | str.Printf( wxT("Second char peeked: %d\n"), (int) ch ); |
f6bcfd97 | 707 | textCtrl.WriteText( str ); |
2b5f62a0 | 708 | |
f6bcfd97 | 709 | ch = input.GetC(); |
4693b20c | 710 | str.Printf( wxT("Second char read: %d\n"), (int) ch ); |
f6bcfd97 | 711 | textCtrl.WriteText( str ); |
2b5f62a0 | 712 | |
f6bcfd97 | 713 | ch = input.Peek(); |
4693b20c | 714 | str.Printf( wxT("Third char peeked: %d\n"), (int) ch ); |
f6bcfd97 | 715 | textCtrl.WriteText( str ); |
2b5f62a0 | 716 | |
f6bcfd97 | 717 | ch = input.GetC(); |
4693b20c | 718 | str.Printf( wxT("Third char read: %d\n"), (int) ch ); |
f6bcfd97 BP |
719 | textCtrl.WriteText( str ); |
720 | } | |
721 | ||
cbc906ce RR |
722 | void MyApp::DoStreamDemo6(wxCommandEvent& WXUNUSED(event)) |
723 | { | |
724 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
725 | ||
726 | textCtrl.Clear(); | |
9a83f860 | 727 | textCtrl.WriteText( wxT("\nTesting Ungetch():\n\n") ); |
2b5f62a0 | 728 | |
cbc906ce | 729 | char ch = 0; |
cbc906ce RR |
730 | wxString str; |
731 | ||
9a83f860 | 732 | textCtrl.WriteText( wxT("Writing number 0 to 9 to wxFileOutputStream...\n\n") ); |
cbc906ce | 733 | |
925e9792 | 734 | wxFileOutputStream file_output( file_name ); |
cbc906ce RR |
735 | for (ch = 0; ch < 10; ch++) |
736 | file_output.Write( &ch, 1 ); | |
2b5f62a0 | 737 | |
cbc906ce | 738 | file_output.Sync(); |
2b5f62a0 | 739 | |
9a83f860 | 740 | textCtrl.WriteText( wxT("Reading char from wxFileInputStream:\n\n") ); |
cbc906ce | 741 | |
925e9792 | 742 | wxFileInputStream file_input( file_name ); |
2b5f62a0 | 743 | |
cbc906ce | 744 | ch = file_input.GetC(); |
925e9792 | 745 | size_t pos = (size_t)file_input.TellI(); |
cbc906ce RR |
746 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
747 | textCtrl.WriteText( str ); | |
2b5f62a0 | 748 | |
9a83f860 | 749 | textCtrl.WriteText( wxT("Reading another char from wxFileInputStream:\n\n") ); |
cbc906ce RR |
750 | |
751 | ch = file_input.GetC(); | |
925e9792 | 752 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
753 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
754 | textCtrl.WriteText( str ); | |
2b5f62a0 | 755 | |
9a83f860 | 756 | textCtrl.WriteText( wxT("Reading yet another char from wxFileInputStream:\n\n") ); |
cbc906ce RR |
757 | |
758 | ch = file_input.GetC(); | |
925e9792 | 759 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
760 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
761 | textCtrl.WriteText( str ); | |
2b5f62a0 | 762 | |
9a83f860 | 763 | textCtrl.WriteText( wxT("Now calling Ungetch( 5 ) from wxFileInputStream...\n\n") ); |
cbc906ce RR |
764 | |
765 | file_input.Ungetch( 5 ); | |
925e9792 | 766 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
767 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); |
768 | textCtrl.WriteText( str ); | |
2b5f62a0 | 769 | |
9a83f860 | 770 | textCtrl.WriteText( wxT("Reading char from wxFileInputStream:\n\n") ); |
cbc906ce RR |
771 | |
772 | ch = file_input.GetC(); | |
925e9792 | 773 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
774 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
775 | textCtrl.WriteText( str ); | |
2b5f62a0 | 776 | |
9a83f860 | 777 | textCtrl.WriteText( wxT("Reading another char from wxFileInputStream:\n\n") ); |
cbc906ce RR |
778 | |
779 | ch = file_input.GetC(); | |
925e9792 | 780 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
781 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
782 | textCtrl.WriteText( str ); | |
2b5f62a0 | 783 | |
9a83f860 | 784 | textCtrl.WriteText( wxT("Now calling Ungetch( 5 ) from wxFileInputStream again...\n\n") ); |
cbc906ce RR |
785 | |
786 | file_input.Ungetch( 5 ); | |
925e9792 | 787 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
788 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); |
789 | textCtrl.WriteText( str ); | |
2b5f62a0 | 790 | |
9a83f860 | 791 | textCtrl.WriteText( wxT("Seeking to pos 3 in wxFileInputStream. This invalidates the writeback buffer.\n\n") ); |
2b5f62a0 | 792 | |
cbc906ce RR |
793 | file_input.SeekI( 3 ); |
794 | ||
795 | ch = file_input.GetC(); | |
925e9792 | 796 | pos = (size_t)file_input.TellI(); |
cbc906ce RR |
797 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
798 | textCtrl.WriteText( str ); | |
799 | } | |
800 | ||
801 | void MyApp::DoStreamDemo7(wxCommandEvent& WXUNUSED(event)) | |
802 | { | |
803 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
804 | ||
805 | textCtrl.Clear(); | |
9a83f860 | 806 | textCtrl.WriteText( wxT("\nTesting Ungetch() in buffered input stream:\n\n") ); |
2b5f62a0 | 807 | |
cbc906ce | 808 | char ch = 0; |
cbc906ce RR |
809 | wxString str; |
810 | ||
9a83f860 | 811 | textCtrl.WriteText( wxT("Writing number 0 to 9 to wxFileOutputStream...\n\n") ); |
cbc906ce | 812 | |
925e9792 | 813 | wxFileOutputStream file_output( file_name ); |
cbc906ce RR |
814 | for (ch = 0; ch < 10; ch++) |
815 | file_output.Write( &ch, 1 ); | |
2b5f62a0 | 816 | |
cbc906ce | 817 | file_output.Sync(); |
2b5f62a0 | 818 | |
9a83f860 | 819 | textCtrl.WriteText( wxT("Reading char from wxBufferedInputStream via wxFileInputStream:\n\n") ); |
cbc906ce | 820 | |
925e9792 | 821 | wxFileInputStream file_input( file_name ); |
cbc906ce | 822 | wxBufferedInputStream buf_input( file_input ); |
2b5f62a0 | 823 | |
cbc906ce | 824 | ch = buf_input.GetC(); |
925e9792 | 825 | size_t pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
826 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
827 | textCtrl.WriteText( str ); | |
2b5f62a0 | 828 | |
9a83f860 | 829 | textCtrl.WriteText( wxT("Reading another char from wxBufferedInputStream:\n\n") ); |
cbc906ce RR |
830 | |
831 | ch = buf_input.GetC(); | |
925e9792 | 832 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
833 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
834 | textCtrl.WriteText( str ); | |
2b5f62a0 | 835 | |
9a83f860 | 836 | textCtrl.WriteText( wxT("Reading yet another char from wxBufferedInputStream:\n\n") ); |
cbc906ce RR |
837 | |
838 | ch = buf_input.GetC(); | |
925e9792 | 839 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
840 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
841 | textCtrl.WriteText( str ); | |
2b5f62a0 | 842 | |
9a83f860 | 843 | textCtrl.WriteText( wxT("Now calling Ungetch( 5 ) from wxBufferedInputStream...\n\n") ); |
cbc906ce RR |
844 | |
845 | buf_input.Ungetch( 5 ); | |
925e9792 | 846 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
847 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); |
848 | textCtrl.WriteText( str ); | |
2b5f62a0 | 849 | |
9a83f860 | 850 | textCtrl.WriteText( wxT("Reading char from wxBufferedInputStream:\n\n") ); |
cbc906ce RR |
851 | |
852 | ch = buf_input.GetC(); | |
925e9792 | 853 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
854 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
855 | textCtrl.WriteText( str ); | |
2b5f62a0 | 856 | |
9a83f860 | 857 | textCtrl.WriteText( wxT("Reading another char from wxBufferedInputStream:\n\n") ); |
cbc906ce RR |
858 | |
859 | ch = buf_input.GetC(); | |
925e9792 | 860 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
861 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
862 | textCtrl.WriteText( str ); | |
2b5f62a0 | 863 | |
9a83f860 | 864 | textCtrl.WriteText( wxT("Now calling Ungetch( 5 ) from wxBufferedInputStream again...\n\n") ); |
cbc906ce RR |
865 | |
866 | buf_input.Ungetch( 5 ); | |
925e9792 | 867 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
868 | str.Printf( wxT("Now at position %d\n\n"), (int) pos ); |
869 | textCtrl.WriteText( str ); | |
2b5f62a0 | 870 | |
9a83f860 | 871 | textCtrl.WriteText( wxT("Seeking to pos 3 in wxBufferedInputStream. This invalidates the writeback buffer.\n\n") ); |
2b5f62a0 | 872 | |
cbc906ce RR |
873 | buf_input.SeekI( 3 ); |
874 | ||
875 | ch = buf_input.GetC(); | |
925e9792 | 876 | pos = (size_t)buf_input.TellI(); |
cbc906ce RR |
877 | str.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch, (int) pos ); |
878 | textCtrl.WriteText( str ); | |
879 | } | |
880 | ||
dcf924a3 RR |
881 | #if wxUSE_UNICODE |
882 | void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event)) | |
883 | { | |
884 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
8e124873 | 885 | |
dcf924a3 | 886 | textCtrl.Clear(); |
9a83f860 | 887 | textCtrl << wxT("\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:"); |
dcf924a3 RR |
888 | |
889 | wxString str; | |
9a83f860 | 890 | str = wxT("Robert R\366bling\n"); |
8e124873 | 891 | |
dcf924a3 RR |
892 | printf( "\n\nConversion with wxConvLocal:\n" ); |
893 | wxConvCurrent = &wxConvLocal; | |
a0b13884 | 894 | puts( str.mbc_str() ); |
dcf924a3 RR |
895 | printf( "\n\nConversion with wxConvLibc:\n" ); |
896 | wxConvCurrent = &wxConvLibc; | |
a0b13884 | 897 | puts( str.mbc_str() ); |
8e124873 | 898 | |
dcf924a3 RR |
899 | } |
900 | #endif | |
901 | ||
8e124873 VZ |
902 | void MyApp::DoMIMEDemo(wxCommandEvent& WXUNUSED(event)) |
903 | { | |
9a83f860 | 904 | static wxString s_defaultExt = wxT("xyz"); |
8e124873 | 905 | |
9a83f860 VZ |
906 | wxString ext = wxGetTextFromUser(wxT("Enter a file extension: "), |
907 | wxT("MIME database test"), | |
8e124873 VZ |
908 | s_defaultExt); |
909 | if ( !!ext ) | |
910 | { | |
911 | s_defaultExt = ext; | |
912 | ||
913 | // init MIME database if not done yet | |
914 | if ( !m_mimeDatabase ) | |
915 | { | |
916 | m_mimeDatabase = new wxMimeTypesManager; | |
917 | ||
918 | static const wxFileTypeInfo fallbacks[] = | |
919 | { | |
9a83f860 VZ |
920 | wxFileTypeInfo(wxT("application/xyz"), |
921 | wxT("XyZ %s"), | |
922 | wxT("XyZ -p %s"), | |
923 | wxT("The one and only XYZ format file"), | |
924 | wxT("xyz"), wxT("123"), wxNullPtr), | |
925 | wxFileTypeInfo(wxT("text/html"), | |
926 | wxT("lynx %s"), | |
927 | wxT("lynx -dump %s | lpr"), | |
928 | wxT("HTML document (from fallback)"), | |
929 | wxT("htm"), wxT("html"), wxNullPtr), | |
8e124873 VZ |
930 | |
931 | // must terminate the table with this! | |
932 | wxFileTypeInfo() | |
933 | }; | |
934 | ||
935 | m_mimeDatabase->AddFallbacks(fallbacks); | |
936 | } | |
937 | ||
938 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
939 | ||
940 | wxFileType *filetype = m_mimeDatabase->GetFileTypeFromExtension(ext); | |
941 | if ( !filetype ) | |
942 | { | |
9a83f860 | 943 | textCtrl << wxT("Unknown extension '") << ext << wxT("'\n"); |
8e124873 VZ |
944 | } |
945 | else | |
946 | { | |
947 | wxString type, desc, open; | |
948 | filetype->GetMimeType(&type); | |
949 | filetype->GetDescription(&desc); | |
950 | ||
9a83f860 VZ |
951 | wxString filename = wxT("filename"); |
952 | filename << wxT(".") << ext; | |
8e124873 VZ |
953 | wxFileType::MessageParameters params(filename, type); |
954 | filetype->GetOpenCommand(&open, params); | |
955 | ||
9a83f860 VZ |
956 | textCtrl << wxT("MIME information about extension '") << ext << wxT('\n') |
957 | << wxT("\tMIME type: ") << ( !type ? wxString("unknown") : type ) << wxT('\n') | |
958 | << wxT("\tDescription: ") << ( !desc ? wxString(wxEmptyString) : desc ) | |
959 | << wxT('\n') | |
960 | << wxT("\tCommand to open: ") << ( !open ? wxString("no") : open ) | |
961 | << wxT('\n'); | |
8e124873 VZ |
962 | |
963 | delete filetype; | |
964 | } | |
965 | } | |
966 | //else: cancelled by user | |
967 | } | |
968 | ||
7e2c43b8 RR |
969 | void MyApp::DoByteOrderDemo(wxCommandEvent& WXUNUSED(event)) |
970 | { | |
971 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
972 | ||
973 | textCtrl.Clear(); | |
9a83f860 | 974 | textCtrl << wxT("\nTest byte order macros:\n\n"); |
8e124873 | 975 | |
dacaa6f1 | 976 | #if wxBYTE_ORDER == wxLITTLE_ENDIAN |
9a83f860 | 977 | textCtrl << wxT("This is a little endian system.\n\n"); |
dacaa6f1 | 978 | #else |
9a83f860 | 979 | textCtrl << wxT("This is a big endian system.\n\n"); |
dacaa6f1 | 980 | #endif |
8e124873 | 981 | |
7e2c43b8 | 982 | wxString text; |
8e124873 | 983 | |
7e2c43b8 | 984 | wxInt32 var = 0xF1F2F3F4; |
206d3a16 | 985 | text = wxEmptyString; |
9a83f860 | 986 | text.Printf( wxT("Value of wxInt32 is now: %#x.\n\n"), var ); |
7e2c43b8 | 987 | textCtrl.WriteText( text ); |
8e124873 | 988 | |
206d3a16 | 989 | text = wxEmptyString; |
9a83f860 | 990 | text.Printf( wxT("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var ) ); |
7e2c43b8 | 991 | textCtrl.WriteText( text ); |
8e124873 | 992 | |
206d3a16 | 993 | text = wxEmptyString; |
9a83f860 | 994 | text.Printf( wxT("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var ) ); |
7e2c43b8 | 995 | textCtrl.WriteText( text ); |
8e124873 | 996 | |
206d3a16 | 997 | text = wxEmptyString; |
9a83f860 | 998 | text.Printf( wxT("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var ) ); |
7e2c43b8 RR |
999 | textCtrl.WriteText( text ); |
1000 | } | |
1001 | ||
bbf73190 | 1002 | void MyApp::DoVariantDemo(wxCommandEvent& WXUNUSED(event) ) |
cfb88c55 JS |
1003 | { |
1004 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
1005 | ||
9a83f860 VZ |
1006 | wxVariant var1 = wxT("String value"); |
1007 | textCtrl << wxT("var1 = ") << var1.MakeString() << wxT("\n"); | |
cfb88c55 | 1008 | |
62448488 JS |
1009 | // Conversion |
1010 | wxString str = var1.MakeString(); | |
cfb88c55 JS |
1011 | |
1012 | var1 = 123.456; | |
9a83f860 | 1013 | textCtrl << wxT("var1 = ") << var1.GetReal() << wxT("\n"); |
cfb88c55 JS |
1014 | |
1015 | // Implicit conversion | |
1016 | double v = var1; | |
1017 | ||
1018 | var1 = 9876L; | |
9a83f860 | 1019 | textCtrl << wxT("var1 = ") << var1.GetLong() << wxT("\n"); |
cfb88c55 JS |
1020 | |
1021 | // Implicit conversion | |
1022 | long l = var1; | |
1023 | ||
8e124873 | 1024 | // suppress compile warnings about unused variables |
206d3a16 JS |
1025 | wxUnusedVar(l); |
1026 | wxUnusedVar(v); | |
8e124873 | 1027 | |
21fe01e2 | 1028 | wxArrayString stringArray; |
9a83f860 | 1029 | stringArray.Add(wxT("one")); stringArray.Add(wxT("two")); stringArray.Add(wxT("three")); |
21fe01e2 | 1030 | var1 = stringArray; |
9a83f860 | 1031 | textCtrl << wxT("var1 = ") << var1.MakeString() << wxT("\n"); |
cfb88c55 JS |
1032 | |
1033 | var1.ClearList(); | |
1034 | var1.Append(wxVariant(1.2345)); | |
9a83f860 | 1035 | var1.Append(wxVariant(wxT("hello"))); |
cfb88c55 JS |
1036 | var1.Append(wxVariant(54321L)); |
1037 | ||
9a83f860 | 1038 | textCtrl << wxT("var1 = ") << var1.MakeString() << wxT("\n"); |
cfb88c55 JS |
1039 | |
1040 | size_t n = var1.GetCount(); | |
1041 | size_t i; | |
1042 | for (i = (size_t) 0; i < n; i++) | |
1043 | { | |
9a83f860 | 1044 | textCtrl << wxT("var1[") << (int) i << wxT("] (type ") << var1[i].GetType() << wxT(") = ") << var1[i].MakeString() << wxT("\n"); |
cfb88c55 | 1045 | } |
cf6ae290 RG |
1046 | |
1047 | var1 = wxVariant(new wxFont(wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT))); | |
9a83f860 | 1048 | textCtrl << wxT("var1 = (wxfont)\""); |
cf6ae290 | 1049 | wxFont* font = wxGetVariantCast(var1,wxFont); |
206d3a16 JS |
1050 | if (font) |
1051 | { | |
9a83f860 | 1052 | textCtrl << font->GetNativeFontInfoDesc() << wxT("\"\n"); |
206d3a16 JS |
1053 | } |
1054 | else | |
1055 | { | |
9a83f860 | 1056 | textCtrl << wxT("(null)\"\n"); |
cf6ae290 | 1057 | } |
cfb88c55 JS |
1058 | } |
1059 | ||
1060 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
8e124873 VZ |
1061 | EVT_MENU(TYPES_QUIT, MyFrame::OnQuit) |
1062 | EVT_MENU(TYPES_ABOUT, MyFrame::OnAbout) | |
cfb88c55 JS |
1063 | END_EVENT_TABLE() |
1064 | ||
1065 | // My frame constructor | |
1066 | MyFrame::MyFrame(wxFrame *parent, const wxString& title, | |
206d3a16 JS |
1067 | const wxPoint& pos, const wxSize& size) |
1068 | : wxFrame(parent, wxID_ANY, title, pos, size) | |
cfb88c55 JS |
1069 | {} |
1070 | ||
1071 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) | |
1072 | { | |
206d3a16 | 1073 | Close(true); |
cfb88c55 JS |
1074 | } |
1075 | ||
1076 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) | |
1077 | { | |
9a83f860 VZ |
1078 | wxMessageDialog dialog(this, wxT("Tests various wxWidgets types"), |
1079 | wxT("About Types"), wxYES_NO|wxCANCEL); | |
cfb88c55 | 1080 | |
206d3a16 | 1081 | dialog.ShowModal(); |
cfb88c55 JS |
1082 | } |
1083 | ||
1084 |