]>
git.saurik.com Git - wxWidgets.git/blob - samples/typetest/typetest.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Types wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "typetest.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/variant.h"
30 #include "wx/mimetype.h"
34 #if defined(__WXGTK__) || defined(__WXMOTIF__)
35 #include "mondrian.xpm"
38 #include "wx/ioswrap.h"
46 #include "wx/wfstream.h"
47 #include "wx/datstrm.h"
48 #include "wx/txtstrm.h"
49 #include "wx/mstream.h"
51 // Create a new application object
54 IMPLEMENT_DYNAMIC_CLASS (MyApp
, wxApp
)
56 BEGIN_EVENT_TABLE(MyApp
, wxApp
)
57 EVT_MENU(TYPES_DATE
, MyApp::DoDateDemo
)
58 EVT_MENU(TYPES_TIME
, MyApp::DoTimeDemo
)
59 EVT_MENU(TYPES_VARIANT
, MyApp::DoVariantDemo
)
60 EVT_MENU(TYPES_BYTEORDER
, MyApp::DoByteOrderDemo
)
62 EVT_MENU(TYPES_UNICODE
, MyApp::DoUnicodeDemo
)
64 EVT_MENU(TYPES_STREAM
, MyApp::DoStreamDemo
)
65 EVT_MENU(TYPES_STREAM2
, MyApp::DoStreamDemo2
)
66 EVT_MENU(TYPES_STREAM3
, MyApp::DoStreamDemo3
)
67 EVT_MENU(TYPES_STREAM4
, MyApp::DoStreamDemo4
)
68 EVT_MENU(TYPES_STREAM5
, MyApp::DoStreamDemo5
)
69 EVT_MENU(TYPES_MIME
, MyApp::DoMIMEDemo
)
74 // Create the main frame window
75 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "wxWindows Types Demo",
76 wxPoint(50, 50), wxSize(450, 340));
79 frame
->SetIcon(wxICON(mondrian
));
82 wxMenu
*file_menu
= new wxMenu
;
84 file_menu
->Append(TYPES_ABOUT
, "&About");
85 file_menu
->AppendSeparator();
86 file_menu
->Append(TYPES_QUIT
, "E&xit\tAlt-X");
88 wxMenu
*test_menu
= new wxMenu
;
89 test_menu
->Append(TYPES_DATE
, "&Date test");
90 test_menu
->Append(TYPES_TIME
, "&Time test");
91 test_menu
->Append(TYPES_VARIANT
, "&Variant test");
92 test_menu
->Append(TYPES_BYTEORDER
, "&Byteorder test");
94 test_menu
->Append(TYPES_UNICODE
, "&Unicode test");
96 test_menu
->Append(TYPES_STREAM
, "&Stream test");
97 test_menu
->Append(TYPES_STREAM2
, "&Stream seek test");
98 test_menu
->Append(TYPES_STREAM3
, "&Stream error test");
99 test_menu
->Append(TYPES_STREAM4
, "&Stream buffer test");
100 test_menu
->Append(TYPES_STREAM5
, "&Stream peek test");
101 test_menu
->AppendSeparator();
102 test_menu
->Append(TYPES_MIME
, "&MIME database test");
104 wxMenuBar
*menu_bar
= new wxMenuBar
;
105 menu_bar
->Append(file_menu
, "&File");
106 menu_bar
->Append(test_menu
, "&Tests");
107 frame
->SetMenuBar(menu_bar
);
109 m_textCtrl
= new wxTextCtrl(frame
, -1, "", wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
119 void MyApp::DoStreamDemo(wxCommandEvent
& WXUNUSED(event
))
121 wxTextCtrl
& textCtrl
= * GetTextCtrl();
124 textCtrl
<< _T("\nTest fstream vs. wxFileStream:\n\n");
126 textCtrl
.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
128 wxSTD ofstream
std_file_output( "test_std.dat" );
129 wxFileOutputStream
file_output( wxString("test_wx.dat") );
130 wxBufferedOutputStream
buf_output( file_output
);
131 wxTextOutputStream
text_output( buf_output
);
134 signed int si
= 0xFFFFFFFF;
135 tmp
.Printf( _T("Signed int: %d\n"), si
);
136 textCtrl
.WriteText( tmp
);
137 text_output
<< si
<< "\n";
138 std_file_output
<< si
<< "\n";
140 unsigned int ui
= 0xFFFFFFFF;
141 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
142 textCtrl
.WriteText( tmp
);
143 text_output
<< ui
<< "\n";
144 std_file_output
<< ui
<< "\n";
146 double d
= 2.01234567890123456789;
147 tmp
.Printf( _T("Double: %f\n"), d
);
148 textCtrl
.WriteText( tmp
);
149 text_output
<< d
<< "\n";
150 std_file_output
<< d
<< "\n";
152 float f
= (float)0.00001;
153 tmp
.Printf( _T("Float: %f\n"), f
);
154 textCtrl
.WriteText( tmp
);
155 text_output
<< f
<< "\n";
156 std_file_output
<< f
<< "\n";
158 wxString
str( _T("Hello!") );
159 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
160 textCtrl
.WriteText( tmp
);
161 text_output
<< str
<< "\n";
162 std_file_output
<< str
.c_str() << "\n";
164 textCtrl
.WriteText( "\nReading from ifstream:\n" );
166 wxSTD ifstream
std_file_input( "test_std.dat" );
168 std_file_input
>> si
;
169 tmp
.Printf( _T("Signed int: %d\n"), si
);
170 textCtrl
.WriteText( tmp
);
172 std_file_input
>> ui
;
173 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
174 textCtrl
.WriteText( tmp
);
177 tmp
.Printf( _T("Double: %f\n"), d
);
178 textCtrl
.WriteText( tmp
);
181 tmp
.Printf( _T("Float: %f\n"), f
);
182 textCtrl
.WriteText( tmp
);
184 // Why doesn't this work?
187 std_file_input
>> std_buf
;
188 tmp
.Printf( _T("String: %s\n"), std_buf
);
189 textCtrl
.WriteText( tmp
);
192 textCtrl
.WriteText( "\nReading from wxFileInputStream:\n" );
196 wxFileInputStream
file_input( wxString("test_wx.dat") );
197 wxBufferedInputStream
buf_input( file_input
);
198 wxTextInputStream
text_input( file_input
);
201 tmp
.Printf( _T("Signed int: %d\n"), si
);
202 textCtrl
.WriteText( tmp
);
205 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
206 textCtrl
.WriteText( tmp
);
209 tmp
.Printf( _T("Double: %f\n"), d
);
210 textCtrl
.WriteText( tmp
);
213 tmp
.Printf( _T("Float: %f\n"), f
);
214 textCtrl
.WriteText( tmp
);
217 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
218 textCtrl
.WriteText( tmp
);
222 textCtrl
<< "\nTest for wxDataStream:\n\n";
224 textCtrl
.WriteText( "Writing to wxDataOutputStream:\n" );
226 file_output
.SeekO( 0 );
227 wxDataOutputStream
data_output( buf_output
);
229 wxInt16 i16
= (short)0xFFFF;
230 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
231 textCtrl
.WriteText( tmp
);
232 data_output
.Write16( i16
);
234 wxUint16 ui16
= 0xFFFF;
235 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
236 textCtrl
.WriteText( tmp
);
237 data_output
.Write16( ui16
);
239 d
= 2.01234567890123456789;
240 tmp
.Printf( _T("Double: %f\n"), d
);
241 textCtrl
.WriteText( tmp
);
242 data_output
.WriteDouble( d
);
245 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
246 textCtrl
.WriteText( tmp
);
247 data_output
.WriteString( str
);
251 textCtrl
.WriteText( "\nReading from wxDataInputStream:\n" );
253 file_input
.SeekI( 0 );
254 wxDataInputStream
data_input( buf_input
);
256 i16
= data_input
.Read16();
257 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
258 textCtrl
.WriteText( tmp
);
260 ui16
= data_input
.Read16();
261 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
262 textCtrl
.WriteText( tmp
);
264 d
= data_input
.ReadDouble();
265 tmp
.Printf( _T("Double: %f\n"), d
);
266 textCtrl
.WriteText( tmp
);
268 str
= data_input
.ReadString();
269 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
270 textCtrl
.WriteText( tmp
);
273 void MyApp::DoStreamDemo2(wxCommandEvent
& WXUNUSED(event
))
275 wxTextCtrl
& textCtrl
= * GetTextCtrl();
278 textCtrl
<< _T("\nTesting wxBufferedStream:\n\n");
282 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
284 wxFileOutputStream
file_output( wxString("test_wx.dat") );
285 wxBufferedOutputStream
buf_output( file_output
);
286 for (ch
= 0; ch
< 10; ch
++)
287 buf_output
.Write( &ch
, 1 );
290 wxFileInputStream
file_input( wxString("test_wx.dat") );
291 for (ch2
= 0; ch2
< 10; ch2
++)
293 file_input
.Read( &ch
, 1 );
294 textCtrl
.WriteText( (char)(ch
+ '0') );
296 textCtrl
.WriteText( "\n\n\n" );
298 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
299 textCtrl
.WriteText( "seeking back to #3 and writing 3:\n\n" );
301 wxFileOutputStream
file_output2( wxString("test_wx2.dat") );
302 wxBufferedOutputStream
buf_output2( file_output2
);
303 for (ch
= 0; ch
< 10; ch
++)
304 buf_output2
.Write( &ch
, 1 );
305 buf_output2
.SeekO( 3 );
307 buf_output2
.Write( &ch
, 1 );
310 wxFileInputStream
file_input2( wxString("test_wx2.dat") );
311 for (ch2
= 0; ch2
< 10; ch2
++)
313 file_input2
.Read( &ch
, 1 );
314 textCtrl
.WriteText( (char)(ch
+ '0') );
316 textCtrl
.WriteText( "\n\n\n" );
318 // now append 2000 bytes to file (bigger than buffer)
319 buf_output2
.SeekO( 0, wxFromEnd
);
321 for (int i
= 0; i
< 2000; i
++)
322 buf_output2
.Write( &ch
, 1 );
325 textCtrl
.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
326 textCtrl
.WriteText( "seeking back to #3 and reading 3:\n\n" );
328 wxFileInputStream
file_input3( wxString("test_wx2.dat") );
329 wxBufferedInputStream
buf_input3( file_input3
);
330 for (ch2
= 0; ch2
< 10; ch2
++)
332 buf_input3
.Read( &ch
, 1 );
333 textCtrl
.WriteText( (char)(ch
+ '0') );
335 for (int j
= 0; j
< 2000; j
++)
336 buf_input3
.Read( &ch
, 1 );
337 textCtrl
.WriteText( "\n" );
338 buf_input3
.SeekI( 3 );
339 buf_input3
.Read( &ch
, 1 );
340 textCtrl
.WriteText( (char)(ch
+ '0') );
341 textCtrl
.WriteText( "\n\n\n" );
345 void MyApp::DoStreamDemo3(wxCommandEvent
& WXUNUSED(event
))
347 wxTextCtrl
& textCtrl
= * GetTextCtrl();
350 textCtrl
<< "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
354 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
356 wxFileOutputStream
file_output( wxString("test_wx.dat") );
357 for (ch
= 0; ch
< 10; ch
++)
358 file_output
.Write( &ch
, 1 );
360 // Testing wxFileInputStream
362 textCtrl
.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
364 wxFileInputStream
file_input( wxString("test_wx.dat") );
365 for (ch2
= 0; ch2
< 11; ch2
++)
367 file_input
.Read( &ch
, 1 );
368 textCtrl
.WriteText( "Value read: " );
369 textCtrl
.WriteText( (char)(ch
+ '0') );
370 textCtrl
.WriteText( "; stream.LastError() returns: " );
371 switch (file_input
.LastError())
373 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
374 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
375 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
376 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
377 default: textCtrl
.WriteText( "Huh?\n" ); break;
380 textCtrl
.WriteText( "\n" );
382 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
383 file_input
.SeekI( 0 );
384 switch (file_input
.LastError())
386 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
387 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
388 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
389 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
390 default: textCtrl
.WriteText( "Huh?\n" ); break;
392 textCtrl
.WriteText( "\n" );
394 file_input
.Read( &ch
, 1 );
395 textCtrl
.WriteText( "Value read: " );
396 textCtrl
.WriteText( (char)(ch
+ '0') );
397 textCtrl
.WriteText( "; stream.LastError() returns: " );
398 switch (file_input
.LastError())
400 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
401 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
402 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
403 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
404 default: textCtrl
.WriteText( "Huh?\n" ); break;
406 textCtrl
.WriteText( "\n\n" );
409 // Testing wxFFileInputStream
411 textCtrl
.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
413 wxFFileInputStream
ffile_input( wxString("test_wx.dat") );
414 for (ch2
= 0; ch2
< 11; ch2
++)
416 ffile_input
.Read( &ch
, 1 );
417 textCtrl
.WriteText( "Value read: " );
418 textCtrl
.WriteText( (char)(ch
+ '0') );
419 textCtrl
.WriteText( "; stream.LastError() returns: " );
420 switch (ffile_input
.LastError())
422 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
423 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
424 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
425 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
426 default: textCtrl
.WriteText( "Huh?\n" ); break;
429 textCtrl
.WriteText( "\n" );
431 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
432 ffile_input
.SeekI( 0 );
433 switch (ffile_input
.LastError())
435 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
436 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
437 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
438 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
439 default: textCtrl
.WriteText( "Huh?\n" ); break;
441 textCtrl
.WriteText( "\n" );
443 ffile_input
.Read( &ch
, 1 );
444 textCtrl
.WriteText( "Value read: " );
445 textCtrl
.WriteText( (char)(ch
+ '0') );
446 textCtrl
.WriteText( "; stream.LastError() returns: " );
447 switch (ffile_input
.LastError())
449 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
450 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
451 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
452 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
453 default: textCtrl
.WriteText( "Huh?\n" ); break;
455 textCtrl
.WriteText( "\n\n" );
457 // Testing wxFFileInputStream
459 textCtrl
.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" );
461 wxFFileInputStream
ffile_input2( wxString("test_wx.dat") );
462 wxBufferedInputStream
buf_input( ffile_input2
);
463 for (ch2
= 0; ch2
< 11; ch2
++)
465 buf_input
.Read( &ch
, 1 );
466 textCtrl
.WriteText( "Value read: " );
467 textCtrl
.WriteText( (char)(ch
+ '0') );
468 textCtrl
.WriteText( "; stream.LastError() returns: " );
469 switch (buf_input
.LastError())
471 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
472 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
473 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
474 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
475 default: textCtrl
.WriteText( "Huh?\n" ); break;
478 textCtrl
.WriteText( "\n" );
480 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
481 buf_input
.SeekI( 0 );
482 switch (buf_input
.LastError())
484 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
485 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
486 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
487 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
488 default: textCtrl
.WriteText( "Huh?\n" ); break;
490 textCtrl
.WriteText( "\n" );
492 buf_input
.Read( &ch
, 1 );
493 textCtrl
.WriteText( "Value read: " );
494 textCtrl
.WriteText( (char)(ch
+ '0') );
495 textCtrl
.WriteText( "; stream.LastError() returns: " );
496 switch (buf_input
.LastError())
498 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
499 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
500 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
501 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
502 default: textCtrl
.WriteText( "Huh?\n" ); break;
506 void MyApp::DoStreamDemo4(wxCommandEvent
& WXUNUSED(event
))
508 wxTextCtrl
& textCtrl
= * GetTextCtrl();
513 textCtrl
<< "\nTesting wxStreamBuffer:\n\n";
515 // bigger than buffer
516 textCtrl
.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" );
518 wxFileOutputStream
file_output( wxString("test_wx.dat") );
519 for (int i
= 0; i
< 2000; i
++)
522 file_output
.Write( &ch
, 1 );
525 textCtrl
.WriteText( "Opening with a buffered wxFileInputStream:\n\n" );
527 wxFileInputStream
file_input( wxString("test_wx.dat") );
528 wxBufferedInputStream
buf_input( file_input
);
530 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
531 switch (buf_input
.LastError())
533 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
534 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
535 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
536 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
537 default: textCtrl
.WriteText( "Huh?\n" ); break;
539 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
540 textCtrl
.WriteText( msg
);
541 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
542 textCtrl
.WriteText( msg
);
543 textCtrl
.WriteText( "\n\n" );
546 textCtrl
.WriteText( "Seeking to position 300:\n\n" );
548 buf_input
.SeekI( 300 );
550 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
551 switch (buf_input
.LastError())
553 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
554 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
555 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
556 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
557 default: textCtrl
.WriteText( "Huh?\n" ); break;
559 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
560 textCtrl
.WriteText( msg
);
561 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
562 textCtrl
.WriteText( msg
);
563 textCtrl
.WriteText( "\n\n" );
568 textCtrl
.WriteText( "Reading 500 bytes:\n\n" );
570 buf_input
.Read( buf
, 500 );
572 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
573 switch (buf_input
.LastError())
575 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
576 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
577 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
578 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
579 default: textCtrl
.WriteText( "Huh?\n" ); break;
581 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
582 textCtrl
.WriteText( msg
);
583 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
584 textCtrl
.WriteText( msg
);
585 textCtrl
.WriteText( "\n\n" );
587 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
589 buf_input
.Read( buf
, 500 );
591 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
592 switch (buf_input
.LastError())
594 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
595 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
596 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
597 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
598 default: textCtrl
.WriteText( "Huh?\n" ); break;
600 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
601 textCtrl
.WriteText( msg
);
602 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
603 textCtrl
.WriteText( msg
);
604 textCtrl
.WriteText( "\n\n" );
606 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
608 buf_input
.Read( buf
, 500 );
610 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
611 switch (buf_input
.LastError())
613 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
614 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
615 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
616 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
617 default: textCtrl
.WriteText( "Huh?\n" ); break;
619 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
620 textCtrl
.WriteText( msg
);
621 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
622 textCtrl
.WriteText( msg
);
623 textCtrl
.WriteText( "\n\n" );
625 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
627 buf_input
.Read( buf
, 500 );
629 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
630 switch (buf_input
.LastError())
632 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
633 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
634 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
635 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
636 default: textCtrl
.WriteText( "Huh?\n" ); break;
638 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
639 textCtrl
.WriteText( msg
);
640 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
641 textCtrl
.WriteText( msg
);
642 textCtrl
.WriteText( "\n\n" );
645 void MyApp::DoStreamDemo5(wxCommandEvent
& WXUNUSED(event
))
647 wxTextCtrl
& textCtrl
= * GetTextCtrl();
650 textCtrl
<< "\nTesting wxFileInputStream's Peek():\n\n";
655 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
657 wxFileOutputStream
file_output( wxString("test_wx.dat") );
658 for (ch
= 0; ch
< 10; ch
++)
659 file_output
.Write( &ch
, 1 );
663 wxFileInputStream
file_input( wxString("test_wx.dat") );
665 ch
= file_input
.Peek();
666 str
.Printf( "First char peeked: %d\n", (int) ch
);
667 textCtrl
.WriteText( str
);
669 ch
= file_input
.GetC();
670 str
.Printf( "First char read: %d\n", (int) ch
);
671 textCtrl
.WriteText( str
);
673 ch
= file_input
.Peek();
674 str
.Printf( "Second char peeked: %d\n", (int) ch
);
675 textCtrl
.WriteText( str
);
677 ch
= file_input
.GetC();
678 str
.Printf( "Second char read: %d\n", (int) ch
);
679 textCtrl
.WriteText( str
);
681 ch
= file_input
.Peek();
682 str
.Printf( "Third char peeked: %d\n", (int) ch
);
683 textCtrl
.WriteText( str
);
685 ch
= file_input
.GetC();
686 str
.Printf( "Third char read: %d\n", (int) ch
);
687 textCtrl
.WriteText( str
);
690 textCtrl
<< "\n\n\nTesting wxMemoryInputStream's Peek():\n\n";
692 char buf
[] = { 0,1,2,3,4,5,6,7,8,9,10 };
693 wxMemoryInputStream
input( buf
, 10 );
696 str
.Printf( "First char peeked: %d\n", (int) ch
);
697 textCtrl
.WriteText( str
);
700 str
.Printf( "First char read: %d\n", (int) ch
);
701 textCtrl
.WriteText( str
);
704 str
.Printf( "Second char peeked: %d\n", (int) ch
);
705 textCtrl
.WriteText( str
);
708 str
.Printf( "Second char read: %d\n", (int) ch
);
709 textCtrl
.WriteText( str
);
712 str
.Printf( "Third char peeked: %d\n", (int) ch
);
713 textCtrl
.WriteText( str
);
716 str
.Printf( "Third char read: %d\n", (int) ch
);
717 textCtrl
.WriteText( str
);
721 void MyApp::DoUnicodeDemo(wxCommandEvent
& WXUNUSED(event
))
723 wxTextCtrl
& textCtrl
= * GetTextCtrl();
726 textCtrl
<< "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
729 str
= _T("Robert Röbling\n");
731 printf( "\n\nConversion with wxConvLocal:\n" );
732 wxConvCurrent
= &wxConvLocal
;
733 printf( (const char*) str
.mbc_str() );
735 printf( "\n\nConversion with wxConvGdk:\n" );
736 wxConvCurrent
= &wxConvGdk
;
737 printf( (const char*) str
.mbc_str() );
739 printf( "\n\nConversion with wxConvLibc:\n" );
740 wxConvCurrent
= &wxConvLibc
;
741 printf( (const char*) str
.mbc_str() );
746 void MyApp::DoMIMEDemo(wxCommandEvent
& WXUNUSED(event
))
748 static wxString s_defaultExt
= "xyz";
750 wxString ext
= wxGetTextFromUser("Enter a file extension: ",
751 "MIME database test",
757 // init MIME database if not done yet
758 if ( !m_mimeDatabase
)
760 m_mimeDatabase
= new wxMimeTypesManager
;
762 static const wxFileTypeInfo fallbacks
[] =
764 wxFileTypeInfo("application/xyz",
767 "The one and only XYZ format file",
769 wxFileTypeInfo("text/html",
771 "lynx -dump %s | lpr",
772 "HTML document (from fallback)",
773 "htm", "html", NULL
),
775 // must terminate the table with this!
779 m_mimeDatabase
->AddFallbacks(fallbacks
);
782 wxTextCtrl
& textCtrl
= * GetTextCtrl();
784 wxFileType
*filetype
= m_mimeDatabase
->GetFileTypeFromExtension(ext
);
787 textCtrl
<< "Unknown extension '" << ext
<< "'\n";
791 wxString type
, desc
, open
;
792 filetype
->GetMimeType(&type
);
793 filetype
->GetDescription(&desc
);
795 wxString filename
= "filename";
796 filename
<< "." << ext
;
797 wxFileType::MessageParameters
params(filename
, type
);
798 filetype
->GetOpenCommand(&open
, params
);
800 textCtrl
<< "MIME information about extension '" << ext
<< "'\n"
801 << "\tMIME type: " << ( !type
? "unknown"
802 : type
.c_str() ) << '\n'
803 << "\tDescription: " << ( !desc
? "" : desc
.c_str() )
805 << "\tCommand to open: " << ( !open
? "no" : open
.c_str() )
811 //else: cancelled by user
814 void MyApp::DoByteOrderDemo(wxCommandEvent
& WXUNUSED(event
))
816 wxTextCtrl
& textCtrl
= * GetTextCtrl();
819 textCtrl
<< "\nTest byte order macros:\n\n";
821 if (wxBYTE_ORDER
== wxLITTLE_ENDIAN
)
822 textCtrl
<< "This is a little endian system.\n\n";
824 textCtrl
<< "This is a big endian system.\n\n";
828 wxInt32 var
= 0xF1F2F3F4;
830 text
.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var
);
831 textCtrl
.WriteText( text
);
834 text
.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var
) );
835 textCtrl
.WriteText( text
);
838 text
.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var
) );
839 textCtrl
.WriteText( text
);
842 text
.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var
) );
843 textCtrl
.WriteText( text
);
846 void MyApp::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
848 wxTextCtrl
& textCtrl
= * GetTextCtrl();
851 textCtrl
<< "\nTest class wxTime:\n";
853 textCtrl
<< "It is now " << (wxString
) now
<< "\n";
856 void MyApp::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
858 wxTextCtrl
& textCtrl
= * GetTextCtrl();
861 textCtrl
<< "\nTest class wxDate" << "\n";
863 // Various versions of the constructors
864 // and various output
866 wxDate
x(10,20,1962);
868 textCtrl
<< x
.FormatDate(wxFULL
) << " (full)\n";
870 // constuctor with a string, just printing the day of the week
871 wxDate
y("8/8/1988");
873 textCtrl
<< y
.FormatDate(wxDAY
) << " (just day)\n";
875 // constructor with a julian
876 wxDate
z( 2450000L );
877 textCtrl
<< z
.FormatDate(wxFULL
) << " (full)\n";
879 // using date addition and subtraction
881 textCtrl
<< a
.FormatDate(wxFULL
) << " (full)\n";
883 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << " (European)\n";
885 // Using subtraction of two date objects
886 wxDate a1
= wxString("7/13/1991");
888 textCtrl
<< (a1
-a2
) << "\n";
889 textCtrl
<< (a2
+=10) << "\n";
892 textCtrl
<< "Tomorrow= " << a1
.FormatDate(wxFULL
) << "\n";
894 wxDate
tmpDate1("08/01/1991");
895 wxDate
tmpDate2("07/14/1991");
896 textCtrl
<< "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1
< tmpDate1
) ? "TRUE" : "FALSE") << "\n";
897 textCtrl
<< "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1
> tmpDate1
) ? "TRUE" : "FALSE") << "\n";
898 textCtrl
<< "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1
==tmpDate2
) ? "TRUE" : "FALSE") << "\n";
901 textCtrl
<< "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1
==a3
) ? "TRUE" : "FALSE") << "\n";
903 textCtrl
<< "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1
==++a4
) ? "TRUE" : "FALSE") << "\n";
905 wxDate a5
= wxString("today");
906 textCtrl
<< "Today is: " << a5
<< "\n";
908 textCtrl
<< "Today (a4) is: " << a4
<< "\n";
910 textCtrl
<< "Today + 4 is: " << (a4
+=4) << "\n";
912 textCtrl
<< "Today - 4 is: " << (a4
-=4) << "\n";
914 textCtrl
<< "=========== Leap Year Test ===========\n";
916 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
917 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
920 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
921 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
923 textCtrl
<< "================== string assignment test ====================\n";
924 wxString date_string
=a1
;
925 textCtrl
<< "a1 as a string (s/b 2/16/1993) ==> " << date_string
<< "\n";
927 textCtrl
<< "================== SetFormat test ============================\n";
928 a1
.SetFormat(wxFULL
);
929 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
930 a1
.SetFormat(wxEUROPEAN
);
931 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
933 textCtrl
<< "================== SetOption test ============================\n";
934 textCtrl
<< "Date abbreviation ON\n";
936 a1
.SetOption(wxDATE_ABBR
);
937 a1
.SetFormat(wxMONTH
);
938 textCtrl
<< "a1 (s/b MONTH format) ==> " << a1
<< "\n";
940 textCtrl
<< "a1 (s/b DAY format) ==> " << a1
<< "\n";
941 a1
.SetFormat(wxFULL
);
942 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
943 a1
.SetFormat(wxEUROPEAN
);
944 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
945 textCtrl
<< "Century suppression ON\n";
946 a1
.SetOption(wxNO_CENTURY
);
948 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
949 textCtrl
<< "Century suppression OFF\n";
950 a1
.SetOption(wxNO_CENTURY
,FALSE
);
951 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
952 textCtrl
<< "Century suppression ON\n";
953 a1
.SetOption(wxNO_CENTURY
);
954 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
955 a1
.SetFormat(wxFULL
);
956 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
958 textCtrl
<< "\n=============== Version 4.0 Enhancement Test =================\n";
960 wxDate
v4("11/26/1966");
961 textCtrl
<< "\n---------- Set Stuff -----------\n";
962 textCtrl
<< "First, 'Set' to today..." << "\n";
963 textCtrl
<< "Before 'Set' => " << v4
<< "\n";
964 textCtrl
<< "After 'Set' => " << v4
.Set() << "\n\n";
966 textCtrl
<< "Set to 11/26/66 => " << v4
.Set(11,26,1966) << "\n";
967 textCtrl
<< "Current Julian => " << v4
.GetJulianDate() << "\n";
968 textCtrl
<< "Set to Julian 2450000L => " << v4
.Set(2450000L) << "\n";
969 textCtrl
<< "See! => " << v4
.GetJulianDate() << "\n";
971 textCtrl
<< "---------- Add Stuff -----------\n";
972 textCtrl
<< "Start => " << v4
<< "\n";
973 textCtrl
<< "Add 4 Weeks => " << v4
.AddWeeks(4) << "\n";
974 textCtrl
<< "Sub 1 Month => " << v4
.AddMonths(-1) << "\n";
975 textCtrl
<< "Add 2 Years => " << v4
.AddYears(2) << "\n";
977 textCtrl
<< "---------- Misc Stuff -----------\n";
978 textCtrl
<< "The date aboves' day of the month is => " << v4
.GetDay() << "\n";
979 textCtrl
<< "There are " << v4
.GetDaysInMonth() << " days in this month.\n";
980 textCtrl
<< "The first day of this month lands on " << v4
.GetFirstDayOfMonth() << "\n";
981 textCtrl
<< "This day happens to be " << v4
.GetDayOfWeekName() << "\n";
982 textCtrl
<< "the " << v4
.GetDayOfWeek() << " day of the week," << "\n";
983 textCtrl
<< "on the " << v4
.GetWeekOfYear() << " week of the year," << "\n";
984 textCtrl
<< "on the " << v4
.GetWeekOfMonth() << " week of the month, " << "\n";
985 textCtrl
<< "(which is " << v4
.GetMonthName() << ")\n";
986 textCtrl
<< "the "<< v4
.GetMonth() << "th month in the year.\n";
987 textCtrl
<< "The year alone is " << v4
.GetYear() << "\n";
989 textCtrl
<< "---------- First and Last Stuff -----------\n";
991 textCtrl
<< "The first date of this month is " << v4
.GetMonthStart() << "\n";
992 textCtrl
<< "The last date of this month is " << v4
.GetMonthEnd() << "\n";
993 textCtrl
<< "The first date of this year is " << v4
.GetYearStart() << "\n";
994 textCtrl
<< "The last date of this year is " << v4
.GetYearEnd() << "\n";
997 void MyApp::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
999 wxTextCtrl
& textCtrl
= * GetTextCtrl();
1001 wxVariant var1
= "String value";
1002 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
1005 wxString str
= var1
.MakeString();
1008 textCtrl
<< "var1 = " << var1
.GetReal() << "\n";
1010 // Implicit conversion
1014 textCtrl
<< "var1 = " << var1
.GetLong() << "\n";
1016 // Implicit conversion
1019 // suppress compile warnings about unused variables
1025 wxStringList stringList
;
1026 stringList
.Add(_T("one")); stringList
.Add(_T("two")); stringList
.Add(_T("three"));
1028 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
1031 var1
.Append(wxVariant(1.2345));
1032 var1
.Append(wxVariant("hello"));
1033 var1
.Append(wxVariant(54321L));
1035 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
1037 size_t n
= var1
.GetCount();
1039 for (i
= (size_t) 0; i
< n
; i
++)
1041 textCtrl
<< "var1[" << (int) i
<< "] (type " << var1
[i
].GetType() << ") = " << var1
[i
].MakeString() << "\n";
1045 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1046 EVT_MENU(TYPES_QUIT
, MyFrame::OnQuit
)
1047 EVT_MENU(TYPES_ABOUT
, MyFrame::OnAbout
)
1050 // My frame constructor
1051 MyFrame::MyFrame(wxFrame
*parent
, const wxString
& title
,
1052 const wxPoint
& pos
, const wxSize
& size
):
1053 wxFrame(parent
, -1, title
, pos
, size
)
1056 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
1061 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
1063 wxMessageDialog
dialog(this, "Tests various wxWindows types",
1064 "About Types", wxYES_NO
|wxCANCEL
);