]>
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"
50 // Create a new application object
53 IMPLEMENT_DYNAMIC_CLASS (MyApp
, wxApp
)
55 BEGIN_EVENT_TABLE(MyApp
, wxApp
)
56 EVT_MENU(TYPES_DATE
, MyApp::DoDateDemo
)
57 EVT_MENU(TYPES_TIME
, MyApp::DoTimeDemo
)
58 EVT_MENU(TYPES_VARIANT
, MyApp::DoVariantDemo
)
59 EVT_MENU(TYPES_BYTEORDER
, MyApp::DoByteOrderDemo
)
61 EVT_MENU(TYPES_UNICODE
, MyApp::DoUnicodeDemo
)
63 EVT_MENU(TYPES_STREAM
, MyApp::DoStreamDemo
)
64 EVT_MENU(TYPES_STREAM2
, MyApp::DoStreamDemo2
)
65 EVT_MENU(TYPES_STREAM3
, MyApp::DoStreamDemo3
)
66 EVT_MENU(TYPES_STREAM4
, MyApp::DoStreamDemo4
)
67 EVT_MENU(TYPES_MIME
, MyApp::DoMIMEDemo
)
72 // Create the main frame window
73 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "wxWindows Types Demo",
74 wxPoint(50, 50), wxSize(450, 340));
77 frame
->SetIcon(wxICON(mondrian
));
80 wxMenu
*file_menu
= new wxMenu
;
82 file_menu
->Append(TYPES_ABOUT
, "&About");
83 file_menu
->AppendSeparator();
84 file_menu
->Append(TYPES_QUIT
, "E&xit\tAlt-X");
86 wxMenu
*test_menu
= new wxMenu
;
87 test_menu
->Append(TYPES_DATE
, "&Date test");
88 test_menu
->Append(TYPES_TIME
, "&Time test");
89 test_menu
->Append(TYPES_VARIANT
, "&Variant test");
90 test_menu
->Append(TYPES_BYTEORDER
, "&Byteorder test");
92 test_menu
->Append(TYPES_UNICODE
, "&Unicode test");
94 test_menu
->Append(TYPES_STREAM
, "&Stream test");
95 test_menu
->Append(TYPES_STREAM2
, "&Stream seek test");
96 test_menu
->Append(TYPES_STREAM3
, "&Stream error test");
97 test_menu
->Append(TYPES_STREAM4
, "&Stream buffer test");
98 test_menu
->AppendSeparator();
99 test_menu
->Append(TYPES_MIME
, "&MIME database test");
101 wxMenuBar
*menu_bar
= new wxMenuBar
;
102 menu_bar
->Append(file_menu
, "&File");
103 menu_bar
->Append(test_menu
, "&Tests");
104 frame
->SetMenuBar(menu_bar
);
106 m_textCtrl
= new wxTextCtrl(frame
, -1, "", wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
116 void MyApp::DoStreamDemo(wxCommandEvent
& WXUNUSED(event
))
118 wxTextCtrl
& textCtrl
= * GetTextCtrl();
121 textCtrl
<< _T("\nTest fstream vs. wxFileStream:\n\n");
123 textCtrl
.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
125 ofstream
std_file_output( "test_std.dat" );
126 wxFileOutputStream
file_output( wxString("test_wx.dat") );
127 wxBufferedOutputStream
buf_output( file_output
);
128 wxTextOutputStream
text_output( buf_output
);
131 signed int si
= 0xFFFFFFFF;
132 tmp
.Printf( _T("Signed int: %d\n"), si
);
133 textCtrl
.WriteText( tmp
);
134 text_output
<< si
<< "\n";
135 std_file_output
<< si
<< "\n";
137 unsigned int ui
= 0xFFFFFFFF;
138 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
139 textCtrl
.WriteText( tmp
);
140 text_output
<< ui
<< "\n";
141 std_file_output
<< ui
<< "\n";
143 double d
= 2.01234567890123456789;
144 tmp
.Printf( _T("Double: %f\n"), d
);
145 textCtrl
.WriteText( tmp
);
146 text_output
<< d
<< "\n";
147 std_file_output
<< d
<< "\n";
149 float f
= (float)0.00001;
150 tmp
.Printf( _T("Float: %f\n"), f
);
151 textCtrl
.WriteText( tmp
);
152 text_output
<< f
<< "\n";
153 std_file_output
<< f
<< "\n";
155 wxString
str( _T("Hello!") );
156 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
157 textCtrl
.WriteText( tmp
);
158 text_output
<< str
<< "\n";
159 std_file_output
<< str
.c_str() << "\n";
161 textCtrl
.WriteText( "\nReading from ifstream:\n" );
163 ifstream
std_file_input( "test_std.dat" );
165 std_file_input
>> si
;
166 tmp
.Printf( _T("Signed int: %d\n"), si
);
167 textCtrl
.WriteText( tmp
);
169 std_file_input
>> ui
;
170 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
171 textCtrl
.WriteText( tmp
);
174 tmp
.Printf( _T("Double: %f\n"), d
);
175 textCtrl
.WriteText( tmp
);
178 tmp
.Printf( _T("Float: %f\n"), f
);
179 textCtrl
.WriteText( tmp
);
181 // This doesn't compile (at least with VC++ 4)
183 std_file_input
>> str
;
184 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
185 textCtrl
.WriteText( tmp
);
188 textCtrl
.WriteText( "\nReading from wxFileInputStream:\n" );
192 wxFileInputStream
file_input( wxString("test_wx.dat") );
193 wxBufferedInputStream
buf_input( file_input
);
194 wxTextInputStream
text_input( file_input
);
197 tmp
.Printf( _T("Signed int: %d\n"), si
);
198 textCtrl
.WriteText( tmp
);
201 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
202 textCtrl
.WriteText( tmp
);
205 tmp
.Printf( _T("Double: %f\n"), d
);
206 textCtrl
.WriteText( tmp
);
209 tmp
.Printf( _T("Float: %f\n"), f
);
210 textCtrl
.WriteText( tmp
);
213 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
214 textCtrl
.WriteText( tmp
);
217 textCtrl
<< "\nTest for wxDataStream:\n\n";
219 textCtrl
.WriteText( "Writing to wxDataOutputStream:\n" );
221 file_output
.SeekO( 0 );
222 wxDataOutputStream
data_output( buf_output
);
224 wxInt16 i16
= (short)0xFFFF;
225 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
226 textCtrl
.WriteText( tmp
);
227 data_output
.Write16( i16
);
229 wxUint16 ui16
= 0xFFFF;
230 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
231 textCtrl
.WriteText( tmp
);
232 data_output
.Write16( ui16
);
234 d
= 2.01234567890123456789;
235 tmp
.Printf( _T("Double: %f\n"), d
);
236 textCtrl
.WriteText( tmp
);
237 data_output
.WriteDouble( d
);
240 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
241 textCtrl
.WriteText( tmp
);
242 data_output
.WriteString( str
);
246 textCtrl
.WriteText( "\nReading from wxDataInputStream:\n" );
248 file_input
.SeekI( 0 );
249 wxDataInputStream
data_input( buf_input
);
251 i16
= data_input
.Read16();
252 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
253 textCtrl
.WriteText( tmp
);
255 ui16
= data_input
.Read16();
256 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
257 textCtrl
.WriteText( tmp
);
259 d
= data_input
.ReadDouble();
260 tmp
.Printf( _T("Double: %f\n"), d
);
261 textCtrl
.WriteText( tmp
);
263 str
= data_input
.ReadString();
264 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
265 textCtrl
.WriteText( tmp
);
268 void MyApp::DoStreamDemo2(wxCommandEvent
& WXUNUSED(event
))
270 wxTextCtrl
& textCtrl
= * GetTextCtrl();
273 textCtrl
<< _T("\nTesting wxBufferedStream:\n\n");
277 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
279 wxFileOutputStream
file_output( wxString("test_wx.dat") );
280 wxBufferedOutputStream
buf_output( file_output
);
281 for (ch
= 0; ch
< 10; ch
++)
282 buf_output
.Write( &ch
, 1 );
285 wxFileInputStream
file_input( wxString("test_wx.dat") );
286 for (ch2
= 0; ch2
< 10; ch2
++)
288 file_input
.Read( &ch
, 1 );
289 textCtrl
.WriteText( (char)(ch
+ '0') );
291 textCtrl
.WriteText( "\n\n\n" );
293 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
294 textCtrl
.WriteText( "seeking back to #3 and writing 3:\n\n" );
296 wxFileOutputStream
file_output2( wxString("test_wx2.dat") );
297 wxBufferedOutputStream
buf_output2( file_output2
);
298 for (ch
= 0; ch
< 10; ch
++)
299 buf_output2
.Write( &ch
, 1 );
300 buf_output2
.SeekO( 3 );
302 buf_output2
.Write( &ch
, 1 );
305 wxFileInputStream
file_input2( wxString("test_wx2.dat") );
306 for (ch2
= 0; ch2
< 10; ch2
++)
308 file_input2
.Read( &ch
, 1 );
309 textCtrl
.WriteText( (char)(ch
+ '0') );
311 textCtrl
.WriteText( "\n\n\n" );
313 // now append 2000 bytes to file (bigger than buffer)
314 buf_output2
.SeekO( 0, wxFromEnd
);
316 for (int i
= 0; i
< 2000; i
++)
317 buf_output2
.Write( &ch
, 1 );
320 textCtrl
.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
321 textCtrl
.WriteText( "seeking back to #3 and reading 3:\n\n" );
323 wxFileInputStream
file_input3( wxString("test_wx2.dat") );
324 wxBufferedInputStream
buf_input3( file_input3
);
325 for (ch2
= 0; ch2
< 10; ch2
++)
327 buf_input3
.Read( &ch
, 1 );
328 textCtrl
.WriteText( (char)(ch
+ '0') );
330 for (int j
= 0; j
< 2000; j
++)
331 buf_input3
.Read( &ch
, 1 );
332 textCtrl
.WriteText( "\n" );
333 buf_input3
.SeekI( 3 );
334 buf_input3
.Read( &ch
, 1 );
335 textCtrl
.WriteText( (char)(ch
+ '0') );
336 textCtrl
.WriteText( "\n\n\n" );
340 void MyApp::DoStreamDemo3(wxCommandEvent
& WXUNUSED(event
))
342 wxTextCtrl
& textCtrl
= * GetTextCtrl();
345 textCtrl
<< "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
349 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
351 wxFileOutputStream
file_output( wxString("test_wx.dat") );
352 for (ch
= 0; ch
< 10; ch
++)
353 file_output
.Write( &ch
, 1 );
355 // Testing wxFileInputStream
357 textCtrl
.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
359 wxFileInputStream
file_input( wxString("test_wx.dat") );
360 for (ch2
= 0; ch2
< 11; ch2
++)
362 file_input
.Read( &ch
, 1 );
363 textCtrl
.WriteText( "Value read: " );
364 textCtrl
.WriteText( (char)(ch
+ '0') );
365 textCtrl
.WriteText( "; stream.LastError() returns: " );
366 switch (file_input
.LastError())
368 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
369 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
370 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
371 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
372 default: textCtrl
.WriteText( "Huh?\n" ); break;
375 textCtrl
.WriteText( "\n" );
377 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
378 file_input
.SeekI( 0 );
379 switch (file_input
.LastError())
381 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
382 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
383 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
384 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
385 default: textCtrl
.WriteText( "Huh?\n" ); break;
387 textCtrl
.WriteText( "\n" );
389 file_input
.Read( &ch
, 1 );
390 textCtrl
.WriteText( "Value read: " );
391 textCtrl
.WriteText( (char)(ch
+ '0') );
392 textCtrl
.WriteText( "; stream.LastError() returns: " );
393 switch (file_input
.LastError())
395 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
396 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
397 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
398 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
399 default: textCtrl
.WriteText( "Huh?\n" ); break;
401 textCtrl
.WriteText( "\n\n" );
404 // Testing wxFFileInputStream
406 textCtrl
.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
408 wxFFileInputStream
ffile_input( wxString("test_wx.dat") );
409 for (ch2
= 0; ch2
< 11; ch2
++)
411 ffile_input
.Read( &ch
, 1 );
412 textCtrl
.WriteText( "Value read: " );
413 textCtrl
.WriteText( (char)(ch
+ '0') );
414 textCtrl
.WriteText( "; stream.LastError() returns: " );
415 switch (ffile_input
.LastError())
417 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
418 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
419 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
420 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
421 default: textCtrl
.WriteText( "Huh?\n" ); break;
424 textCtrl
.WriteText( "\n" );
426 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
427 ffile_input
.SeekI( 0 );
428 switch (ffile_input
.LastError())
430 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
431 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
432 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
433 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
434 default: textCtrl
.WriteText( "Huh?\n" ); break;
436 textCtrl
.WriteText( "\n" );
438 ffile_input
.Read( &ch
, 1 );
439 textCtrl
.WriteText( "Value read: " );
440 textCtrl
.WriteText( (char)(ch
+ '0') );
441 textCtrl
.WriteText( "; stream.LastError() returns: " );
442 switch (ffile_input
.LastError())
444 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
445 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
446 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
447 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
448 default: textCtrl
.WriteText( "Huh?\n" ); break;
450 textCtrl
.WriteText( "\n\n" );
452 // Testing wxFFileInputStream
454 textCtrl
.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" );
456 wxFFileInputStream
ffile_input2( wxString("test_wx.dat") );
457 wxBufferedInputStream
buf_input( ffile_input2
);
458 for (ch2
= 0; ch2
< 11; ch2
++)
460 buf_input
.Read( &ch
, 1 );
461 textCtrl
.WriteText( "Value read: " );
462 textCtrl
.WriteText( (char)(ch
+ '0') );
463 textCtrl
.WriteText( "; stream.LastError() returns: " );
464 switch (buf_input
.LastError())
466 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
467 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
468 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
469 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
470 default: textCtrl
.WriteText( "Huh?\n" ); break;
473 textCtrl
.WriteText( "\n" );
475 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
476 buf_input
.SeekI( 0 );
477 switch (buf_input
.LastError())
479 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
480 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
481 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
482 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
483 default: textCtrl
.WriteText( "Huh?\n" ); break;
485 textCtrl
.WriteText( "\n" );
487 buf_input
.Read( &ch
, 1 );
488 textCtrl
.WriteText( "Value read: " );
489 textCtrl
.WriteText( (char)(ch
+ '0') );
490 textCtrl
.WriteText( "; stream.LastError() returns: " );
491 switch (buf_input
.LastError())
493 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
494 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
495 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
496 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
497 default: textCtrl
.WriteText( "Huh?\n" ); break;
501 void MyApp::DoStreamDemo4(wxCommandEvent
& WXUNUSED(event
))
503 wxTextCtrl
& textCtrl
= * GetTextCtrl();
508 textCtrl
<< "\nTesting wxStreamBuffer:\n\n";
510 // bigger than buffer
511 textCtrl
.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" );
513 wxFileOutputStream
file_output( wxString("test_wx.dat") );
514 for (int i
= 0; i
< 2000; i
++)
517 file_output
.Write( &ch
, 1 );
520 textCtrl
.WriteText( "Opening with a buffered wxFileInputStream:\n\n" );
522 wxFileInputStream
file_input( wxString("test_wx.dat") );
523 wxBufferedInputStream
buf_input( file_input
);
525 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
526 switch (buf_input
.LastError())
528 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
529 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
530 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
531 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
532 default: textCtrl
.WriteText( "Huh?\n" ); break;
534 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
535 textCtrl
.WriteText( msg
);
536 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
537 textCtrl
.WriteText( msg
);
538 textCtrl
.WriteText( "\n\n" );
541 textCtrl
.WriteText( "Seeking to position 300:\n\n" );
543 buf_input
.SeekI( 300 );
545 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
546 switch (buf_input
.LastError())
548 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
549 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
550 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
551 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
552 default: textCtrl
.WriteText( "Huh?\n" ); break;
554 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
555 textCtrl
.WriteText( msg
);
556 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
557 textCtrl
.WriteText( msg
);
558 textCtrl
.WriteText( "\n\n" );
563 textCtrl
.WriteText( "Reading 500 bytes:\n\n" );
565 buf_input
.Read( buf
, 500 );
567 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
568 switch (buf_input
.LastError())
570 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
571 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
572 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
573 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
574 default: textCtrl
.WriteText( "Huh?\n" ); break;
576 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
577 textCtrl
.WriteText( msg
);
578 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
579 textCtrl
.WriteText( msg
);
580 textCtrl
.WriteText( "\n\n" );
582 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
584 buf_input
.Read( buf
, 500 );
586 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
587 switch (buf_input
.LastError())
589 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
590 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
591 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
592 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
593 default: textCtrl
.WriteText( "Huh?\n" ); break;
595 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
596 textCtrl
.WriteText( msg
);
597 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
598 textCtrl
.WriteText( msg
);
599 textCtrl
.WriteText( "\n\n" );
601 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
603 buf_input
.Read( buf
, 500 );
605 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
606 switch (buf_input
.LastError())
608 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
609 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
610 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
611 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
612 default: textCtrl
.WriteText( "Huh?\n" ); break;
614 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
615 textCtrl
.WriteText( msg
);
616 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
617 textCtrl
.WriteText( msg
);
618 textCtrl
.WriteText( "\n\n" );
620 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
622 buf_input
.Read( buf
, 500 );
624 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
625 switch (buf_input
.LastError())
627 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
628 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
629 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
630 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
631 default: textCtrl
.WriteText( "Huh?\n" ); break;
633 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
634 textCtrl
.WriteText( msg
);
635 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
636 textCtrl
.WriteText( msg
);
637 textCtrl
.WriteText( "\n\n" );
641 void MyApp::DoUnicodeDemo(wxCommandEvent
& WXUNUSED(event
))
643 wxTextCtrl
& textCtrl
= * GetTextCtrl();
646 textCtrl
<< "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
649 str
= _T("Robert Röbling\n");
651 printf( "\n\nConversion with wxConvLocal:\n" );
652 wxConvCurrent
= &wxConvLocal
;
653 printf( (const char*) str
.mbc_str() );
655 printf( "\n\nConversion with wxConvGdk:\n" );
656 wxConvCurrent
= &wxConvGdk
;
657 printf( (const char*) str
.mbc_str() );
659 printf( "\n\nConversion with wxConvLibc:\n" );
660 wxConvCurrent
= &wxConvLibc
;
661 printf( (const char*) str
.mbc_str() );
666 void MyApp::DoMIMEDemo(wxCommandEvent
& WXUNUSED(event
))
668 static wxString s_defaultExt
= "xyz";
670 wxString ext
= wxGetTextFromUser("Enter a file extension: ",
671 "MIME database test",
677 // init MIME database if not done yet
678 if ( !m_mimeDatabase
)
680 m_mimeDatabase
= new wxMimeTypesManager
;
682 static const wxFileTypeInfo fallbacks
[] =
684 wxFileTypeInfo("application/xyz",
687 "The one and only XYZ format file",
689 wxFileTypeInfo("text/html",
691 "lynx -dump %s | lpr",
692 "HTML document (from fallback)",
693 "htm", "html", NULL
),
695 // must terminate the table with this!
699 m_mimeDatabase
->AddFallbacks(fallbacks
);
702 wxTextCtrl
& textCtrl
= * GetTextCtrl();
704 wxFileType
*filetype
= m_mimeDatabase
->GetFileTypeFromExtension(ext
);
707 textCtrl
<< "Unknown extension '" << ext
<< "'\n";
711 wxString type
, desc
, open
;
712 filetype
->GetMimeType(&type
);
713 filetype
->GetDescription(&desc
);
715 wxString filename
= "filename";
716 filename
<< "." << ext
;
717 wxFileType::MessageParameters
params(filename
, type
);
718 filetype
->GetOpenCommand(&open
, params
);
720 textCtrl
<< "MIME information about extension '" << ext
<< "'\n"
721 << "\tMIME type: " << ( !type
? "unknown"
722 : type
.c_str() ) << '\n'
723 << "\tDescription: " << ( !desc
? "" : desc
.c_str() )
725 << "\tCommand to open: " << ( !open
? "no" : open
.c_str() )
731 //else: cancelled by user
734 void MyApp::DoByteOrderDemo(wxCommandEvent
& WXUNUSED(event
))
736 wxTextCtrl
& textCtrl
= * GetTextCtrl();
739 textCtrl
<< "\nTest byte order macros:\n\n";
741 if (wxBYTE_ORDER
== wxLITTLE_ENDIAN
)
742 textCtrl
<< "This is a little endian system.\n\n";
744 textCtrl
<< "This is a big endian system.\n\n";
748 wxInt32 var
= 0xF1F2F3F4;
750 text
.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var
);
751 textCtrl
.WriteText( text
);
754 text
.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var
) );
755 textCtrl
.WriteText( text
);
758 text
.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var
) );
759 textCtrl
.WriteText( text
);
762 text
.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var
) );
763 textCtrl
.WriteText( text
);
766 void MyApp::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
768 wxTextCtrl
& textCtrl
= * GetTextCtrl();
771 textCtrl
<< "\nTest class wxTime:\n";
773 textCtrl
<< "It is now " << (wxString
) now
<< "\n";
776 void MyApp::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
778 wxTextCtrl
& textCtrl
= * GetTextCtrl();
781 textCtrl
<< "\nTest class wxDate" << "\n";
783 // Various versions of the constructors
784 // and various output
786 wxDate
x(10,20,1962);
788 textCtrl
<< x
.FormatDate(wxFULL
) << " (full)\n";
790 // constuctor with a string, just printing the day of the week
791 wxDate
y("8/8/1988");
793 textCtrl
<< y
.FormatDate(wxDAY
) << " (just day)\n";
795 // constructor with a julian
796 wxDate
z( 2450000L );
797 textCtrl
<< z
.FormatDate(wxFULL
) << " (full)\n";
799 // using date addition and subtraction
801 textCtrl
<< a
.FormatDate(wxFULL
) << " (full)\n";
803 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << " (European)\n";
805 // Using subtraction of two date objects
806 wxDate a1
= wxString("7/13/1991");
808 textCtrl
<< (a1
-a2
) << "\n";
809 textCtrl
<< (a2
+=10) << "\n";
812 textCtrl
<< "Tomorrow= " << a1
.FormatDate(wxFULL
) << "\n";
814 wxDate
tmpDate1("08/01/1991");
815 wxDate
tmpDate2("07/14/1991");
816 textCtrl
<< "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1
< tmpDate1
) ? "TRUE" : "FALSE") << "\n";
817 textCtrl
<< "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1
> tmpDate1
) ? "TRUE" : "FALSE") << "\n";
818 textCtrl
<< "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1
==tmpDate2
) ? "TRUE" : "FALSE") << "\n";
821 textCtrl
<< "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1
==a3
) ? "TRUE" : "FALSE") << "\n";
823 textCtrl
<< "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1
==++a4
) ? "TRUE" : "FALSE") << "\n";
825 wxDate a5
= wxString("today");
826 textCtrl
<< "Today is: " << a5
<< "\n";
828 textCtrl
<< "Today (a4) is: " << a4
<< "\n";
830 textCtrl
<< "Today + 4 is: " << (a4
+=4) << "\n";
832 textCtrl
<< "Today - 4 is: " << (a4
-=4) << "\n";
834 textCtrl
<< "=========== Leap Year Test ===========\n";
836 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
837 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
840 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
841 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
843 textCtrl
<< "================== string assignment test ====================\n";
844 wxString date_string
=a1
;
845 textCtrl
<< "a1 as a string (s/b 2/16/1993) ==> " << date_string
<< "\n";
847 textCtrl
<< "================== SetFormat test ============================\n";
848 a1
.SetFormat(wxFULL
);
849 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
850 a1
.SetFormat(wxEUROPEAN
);
851 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
853 textCtrl
<< "================== SetOption test ============================\n";
854 textCtrl
<< "Date abbreviation ON\n";
856 a1
.SetOption(wxDATE_ABBR
);
857 a1
.SetFormat(wxMONTH
);
858 textCtrl
<< "a1 (s/b MONTH format) ==> " << a1
<< "\n";
860 textCtrl
<< "a1 (s/b DAY format) ==> " << a1
<< "\n";
861 a1
.SetFormat(wxFULL
);
862 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
863 a1
.SetFormat(wxEUROPEAN
);
864 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
865 textCtrl
<< "Century suppression ON\n";
866 a1
.SetOption(wxNO_CENTURY
);
868 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
869 textCtrl
<< "Century suppression OFF\n";
870 a1
.SetOption(wxNO_CENTURY
,FALSE
);
871 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
872 textCtrl
<< "Century suppression ON\n";
873 a1
.SetOption(wxNO_CENTURY
);
874 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
875 a1
.SetFormat(wxFULL
);
876 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
878 textCtrl
<< "\n=============== Version 4.0 Enhancement Test =================\n";
880 wxDate
v4("11/26/1966");
881 textCtrl
<< "\n---------- Set Stuff -----------\n";
882 textCtrl
<< "First, 'Set' to today..." << "\n";
883 textCtrl
<< "Before 'Set' => " << v4
<< "\n";
884 textCtrl
<< "After 'Set' => " << v4
.Set() << "\n\n";
886 textCtrl
<< "Set to 11/26/66 => " << v4
.Set(11,26,1966) << "\n";
887 textCtrl
<< "Current Julian => " << v4
.GetJulianDate() << "\n";
888 textCtrl
<< "Set to Julian 2450000L => " << v4
.Set(2450000L) << "\n";
889 textCtrl
<< "See! => " << v4
.GetJulianDate() << "\n";
891 textCtrl
<< "---------- Add Stuff -----------\n";
892 textCtrl
<< "Start => " << v4
<< "\n";
893 textCtrl
<< "Add 4 Weeks => " << v4
.AddWeeks(4) << "\n";
894 textCtrl
<< "Sub 1 Month => " << v4
.AddMonths(-1) << "\n";
895 textCtrl
<< "Add 2 Years => " << v4
.AddYears(2) << "\n";
897 textCtrl
<< "---------- Misc Stuff -----------\n";
898 textCtrl
<< "The date aboves' day of the month is => " << v4
.GetDay() << "\n";
899 textCtrl
<< "There are " << v4
.GetDaysInMonth() << " days in this month.\n";
900 textCtrl
<< "The first day of this month lands on " << v4
.GetFirstDayOfMonth() << "\n";
901 textCtrl
<< "This day happens to be " << v4
.GetDayOfWeekName() << "\n";
902 textCtrl
<< "the " << v4
.GetDayOfWeek() << " day of the week," << "\n";
903 textCtrl
<< "on the " << v4
.GetWeekOfYear() << " week of the year," << "\n";
904 textCtrl
<< "on the " << v4
.GetWeekOfMonth() << " week of the month, " << "\n";
905 textCtrl
<< "(which is " << v4
.GetMonthName() << ")\n";
906 textCtrl
<< "the "<< v4
.GetMonth() << "th month in the year.\n";
907 textCtrl
<< "The year alone is " << v4
.GetYear() << "\n";
909 textCtrl
<< "---------- First and Last Stuff -----------\n";
911 textCtrl
<< "The first date of this month is " << v4
.GetMonthStart() << "\n";
912 textCtrl
<< "The last date of this month is " << v4
.GetMonthEnd() << "\n";
913 textCtrl
<< "The first date of this year is " << v4
.GetYearStart() << "\n";
914 textCtrl
<< "The last date of this year is " << v4
.GetYearEnd() << "\n";
917 void MyApp::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
919 wxTextCtrl
& textCtrl
= * GetTextCtrl();
921 wxVariant var1
= "String value";
922 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
925 wxString str
= var1
.MakeString();
928 textCtrl
<< "var1 = " << var1
.GetReal() << "\n";
930 // Implicit conversion
934 textCtrl
<< "var1 = " << var1
.GetLong() << "\n";
936 // Implicit conversion
939 // suppress compile warnings about unused variables
945 wxStringList stringList
;
946 stringList
.Add(_T("one")); stringList
.Add(_T("two")); stringList
.Add(_T("three"));
948 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
951 var1
.Append(wxVariant(1.2345));
952 var1
.Append(wxVariant("hello"));
953 var1
.Append(wxVariant(54321L));
955 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
957 size_t n
= var1
.GetCount();
959 for (i
= (size_t) 0; i
< n
; i
++)
961 textCtrl
<< "var1[" << (int) i
<< "] (type " << var1
[i
].GetType() << ") = " << var1
[i
].MakeString() << "\n";
965 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
966 EVT_MENU(TYPES_QUIT
, MyFrame::OnQuit
)
967 EVT_MENU(TYPES_ABOUT
, MyFrame::OnAbout
)
970 // My frame constructor
971 MyFrame::MyFrame(wxFrame
*parent
, const wxString
& title
,
972 const wxPoint
& pos
, const wxSize
& size
):
973 wxFrame(parent
, -1, title
, pos
, size
)
976 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
981 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
983 wxMessageDialog
dialog(this, "Tests various wxWindows types",
984 "About Types", wxYES_NO
|wxCANCEL
);