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