]>
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( "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 std_file_input
>> str
;
182 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
183 textCtrl
.WriteText( tmp
);
185 textCtrl
.WriteText( "\nReading from wxFileInputStream:\n" );
189 wxFileInputStream
file_input( "test_wx.dat" );
190 wxBufferedInputStream
buf_input( file_input
);
191 wxTextInputStream
text_input( file_input
);
194 tmp
.Printf( _T("Signed int: %d\n"), si
);
195 textCtrl
.WriteText( tmp
);
198 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
199 textCtrl
.WriteText( tmp
);
202 tmp
.Printf( _T("Double: %f\n"), d
);
203 textCtrl
.WriteText( tmp
);
206 tmp
.Printf( _T("Float: %f\n"), f
);
207 textCtrl
.WriteText( tmp
);
210 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
211 textCtrl
.WriteText( tmp
);
214 textCtrl
<< "\nTest for wxDataStream:\n\n";
216 textCtrl
.WriteText( "Writing to wxDataOutputStream:\n" );
218 file_output
.SeekO( 0 );
219 wxDataOutputStream
data_output( buf_output
);
221 wxInt16 i16
= (short)0xFFFF;
222 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
223 textCtrl
.WriteText( tmp
);
224 data_output
.Write16( i16
);
226 wxUint16 ui16
= 0xFFFF;
227 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
228 textCtrl
.WriteText( tmp
);
229 data_output
.Write16( ui16
);
231 d
= 2.01234567890123456789;
232 tmp
.Printf( _T("Double: %f\n"), d
);
233 textCtrl
.WriteText( tmp
);
234 data_output
.WriteDouble( d
);
237 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
238 textCtrl
.WriteText( tmp
);
239 data_output
.WriteString( str
);
243 textCtrl
.WriteText( "\nReading from wxDataInputStream:\n" );
245 file_input
.SeekI( 0 );
246 wxDataInputStream
data_input( buf_input
);
248 i16
= data_input
.Read16();
249 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
250 textCtrl
.WriteText( tmp
);
252 ui16
= data_input
.Read16();
253 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
254 textCtrl
.WriteText( tmp
);
256 d
= data_input
.ReadDouble();
257 tmp
.Printf( _T("Double: %f\n"), d
);
258 textCtrl
.WriteText( tmp
);
260 str
= data_input
.ReadString();
261 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
262 textCtrl
.WriteText( tmp
);
265 void MyApp::DoStreamDemo2(wxCommandEvent
& WXUNUSED(event
))
267 wxTextCtrl
& textCtrl
= * GetTextCtrl();
270 textCtrl
<< _T("\nTesting wxBufferedStream:\n\n");
274 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
276 wxFileOutputStream
file_output( "test_wx.dat" );
277 wxBufferedOutputStream
buf_output( file_output
);
278 for (ch
= 0; ch
< 10; ch
++)
279 buf_output
.Write( &ch
, 1 );
282 wxFileInputStream
file_input( "test_wx.dat" );
283 for (ch2
= 0; ch2
< 10; ch2
++)
285 file_input
.Read( &ch
, 1 );
286 textCtrl
.WriteText( (char)(ch
+ '0') );
288 textCtrl
.WriteText( "\n\n\n" );
290 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
291 textCtrl
.WriteText( "seeking back to #3 and writing 3:\n\n" );
293 wxFileOutputStream
file_output2( "test_wx2.dat" );
294 wxBufferedOutputStream
buf_output2( file_output2
);
295 for (ch
= 0; ch
< 10; ch
++)
296 buf_output2
.Write( &ch
, 1 );
297 buf_output2
.SeekO( 3 );
299 buf_output2
.Write( &ch
, 1 );
302 wxFileInputStream
file_input2( "test_wx2.dat" );
303 for (ch2
= 0; ch2
< 10; ch2
++)
305 file_input2
.Read( &ch
, 1 );
306 textCtrl
.WriteText( (char)(ch
+ '0') );
308 textCtrl
.WriteText( "\n\n\n" );
310 // now append 2000 bytes to file (bigger than buffer)
311 buf_output2
.SeekO( 0, wxFromEnd
);
313 for (int i
= 0; i
< 2000; i
++)
314 buf_output2
.Write( &ch
, 1 );
317 textCtrl
.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
318 textCtrl
.WriteText( "seeking back to #3 and reading 3:\n\n" );
320 wxFileInputStream
file_input3( "test_wx2.dat" );
321 wxBufferedInputStream
buf_input3( file_input3
);
322 for (ch2
= 0; ch2
< 10; ch2
++)
324 buf_input3
.Read( &ch
, 1 );
325 textCtrl
.WriteText( (char)(ch
+ '0') );
327 for (int j
= 0; j
< 2000; j
++)
328 buf_input3
.Read( &ch
, 1 );
329 textCtrl
.WriteText( "\n" );
330 buf_input3
.SeekI( 3 );
331 buf_input3
.Read( &ch
, 1 );
332 textCtrl
.WriteText( (char)(ch
+ '0') );
333 textCtrl
.WriteText( "\n\n\n" );
337 void MyApp::DoStreamDemo3(wxCommandEvent
& WXUNUSED(event
))
339 wxTextCtrl
& textCtrl
= * GetTextCtrl();
342 textCtrl
<< "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
346 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
348 wxFileOutputStream
file_output( "test_wx.dat" );
349 for (ch
= 0; ch
< 10; ch
++)
350 file_output
.Write( &ch
, 1 );
352 // Testing wxFileInputStream
354 textCtrl
.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
356 wxFileInputStream
file_input( "test_wx.dat" );
357 for (ch2
= 0; ch2
< 11; ch2
++)
359 file_input
.Read( &ch
, 1 );
360 textCtrl
.WriteText( "Value read: " );
361 textCtrl
.WriteText( (char)(ch
+ '0') );
362 textCtrl
.WriteText( "; stream.LastError() returns: " );
363 switch (file_input
.LastError())
365 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
366 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
367 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
368 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
369 default: textCtrl
.WriteText( "Huh?\n" ); break;
372 textCtrl
.WriteText( "\n" );
374 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
375 file_input
.SeekI( 0 );
376 switch (file_input
.LastError())
378 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
379 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
380 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
381 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
382 default: textCtrl
.WriteText( "Huh?\n" ); break;
384 textCtrl
.WriteText( "\n" );
386 file_input
.Read( &ch
, 1 );
387 textCtrl
.WriteText( "Value read: " );
388 textCtrl
.WriteText( (char)(ch
+ '0') );
389 textCtrl
.WriteText( "; stream.LastError() returns: " );
390 switch (file_input
.LastError())
392 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
393 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
394 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
395 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
396 default: textCtrl
.WriteText( "Huh?\n" ); break;
398 textCtrl
.WriteText( "\n\n" );
401 // Testing wxFFileInputStream
403 textCtrl
.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
405 wxFFileInputStream
ffile_input( "test_wx.dat" );
406 for (ch2
= 0; ch2
< 11; ch2
++)
408 ffile_input
.Read( &ch
, 1 );
409 textCtrl
.WriteText( "Value read: " );
410 textCtrl
.WriteText( (char)(ch
+ '0') );
411 textCtrl
.WriteText( "; stream.LastError() returns: " );
412 switch (ffile_input
.LastError())
414 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
415 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
416 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
417 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
418 default: textCtrl
.WriteText( "Huh?\n" ); break;
421 textCtrl
.WriteText( "\n" );
423 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
424 ffile_input
.SeekI( 0 );
425 switch (ffile_input
.LastError())
427 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
428 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
429 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
430 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
431 default: textCtrl
.WriteText( "Huh?\n" ); break;
433 textCtrl
.WriteText( "\n" );
435 ffile_input
.Read( &ch
, 1 );
436 textCtrl
.WriteText( "Value read: " );
437 textCtrl
.WriteText( (char)(ch
+ '0') );
438 textCtrl
.WriteText( "; stream.LastError() returns: " );
439 switch (ffile_input
.LastError())
441 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
442 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
443 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
444 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
445 default: textCtrl
.WriteText( "Huh?\n" ); break;
447 textCtrl
.WriteText( "\n\n" );
449 // Testing wxFFileInputStream
451 textCtrl
.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" );
453 wxFFileInputStream
ffile_input2( "test_wx.dat" );
454 wxBufferedInputStream
buf_input( ffile_input2
);
455 for (ch2
= 0; ch2
< 11; ch2
++)
457 buf_input
.Read( &ch
, 1 );
458 textCtrl
.WriteText( "Value read: " );
459 textCtrl
.WriteText( (char)(ch
+ '0') );
460 textCtrl
.WriteText( "; stream.LastError() returns: " );
461 switch (buf_input
.LastError())
463 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
464 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
465 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
466 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
467 default: textCtrl
.WriteText( "Huh?\n" ); break;
470 textCtrl
.WriteText( "\n" );
472 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
473 buf_input
.SeekI( 0 );
474 switch (buf_input
.LastError())
476 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
477 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
478 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
479 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
480 default: textCtrl
.WriteText( "Huh?\n" ); break;
482 textCtrl
.WriteText( "\n" );
484 buf_input
.Read( &ch
, 1 );
485 textCtrl
.WriteText( "Value read: " );
486 textCtrl
.WriteText( (char)(ch
+ '0') );
487 textCtrl
.WriteText( "; stream.LastError() returns: " );
488 switch (buf_input
.LastError())
490 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
491 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
492 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
493 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
494 default: textCtrl
.WriteText( "Huh?\n" ); break;
498 void MyApp::DoStreamDemo4(wxCommandEvent
& WXUNUSED(event
))
500 wxTextCtrl
& textCtrl
= * GetTextCtrl();
505 textCtrl
<< "\nTesting wxStreamBuffer:\n\n";
507 // bigger than buffer
508 textCtrl
.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" );
510 wxFileOutputStream
file_output( "test_wx.dat" );
511 for (int i
= 0; i
< 2000; i
++)
514 file_output
.Write( &ch
, 1 );
517 textCtrl
.WriteText( "Opening with a buffered wxFileInputStream:\n\n" );
519 wxFileInputStream
file_input( "test_wx.dat" );
520 wxBufferedInputStream
buf_input( file_input
);
522 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
523 switch (buf_input
.LastError())
525 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
526 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
527 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
528 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
529 default: textCtrl
.WriteText( "Huh?\n" ); break;
531 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
532 textCtrl
.WriteText( msg
);
533 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
534 textCtrl
.WriteText( msg
);
535 textCtrl
.WriteText( "\n\n" );
538 textCtrl
.WriteText( "Seeking to position 300:\n\n" );
540 buf_input
.SeekI( 300 );
542 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
543 switch (buf_input
.LastError())
545 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
546 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
547 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
548 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
549 default: textCtrl
.WriteText( "Huh?\n" ); break;
551 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
552 textCtrl
.WriteText( msg
);
553 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
554 textCtrl
.WriteText( msg
);
555 textCtrl
.WriteText( "\n\n" );
560 textCtrl
.WriteText( "Reading 500 bytes:\n\n" );
562 buf_input
.Read( buf
, 500 );
564 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
565 switch (buf_input
.LastError())
567 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
568 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
569 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
570 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
571 default: textCtrl
.WriteText( "Huh?\n" ); break;
573 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
574 textCtrl
.WriteText( msg
);
575 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
576 textCtrl
.WriteText( msg
);
577 textCtrl
.WriteText( "\n\n" );
579 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
581 buf_input
.Read( buf
, 500 );
583 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
584 switch (buf_input
.LastError())
586 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
587 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
588 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
589 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
590 default: textCtrl
.WriteText( "Huh?\n" ); break;
592 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
593 textCtrl
.WriteText( msg
);
594 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
595 textCtrl
.WriteText( msg
);
596 textCtrl
.WriteText( "\n\n" );
598 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
600 buf_input
.Read( buf
, 500 );
602 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
603 switch (buf_input
.LastError())
605 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
606 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
607 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
608 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
609 default: textCtrl
.WriteText( "Huh?\n" ); break;
611 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
612 textCtrl
.WriteText( msg
);
613 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
614 textCtrl
.WriteText( msg
);
615 textCtrl
.WriteText( "\n\n" );
617 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
619 buf_input
.Read( buf
, 500 );
621 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
622 switch (buf_input
.LastError())
624 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
625 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
626 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
627 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
628 default: textCtrl
.WriteText( "Huh?\n" ); break;
630 msg
.Printf( "wxBufferedInputStream.LastRead() returns: %d\n", (int)buf_input
.LastRead() );
631 textCtrl
.WriteText( msg
);
632 msg
.Printf( "wxBufferedInputStream.TellI() returns: %d\n", (int)buf_input
.TellI() );
633 textCtrl
.WriteText( msg
);
634 textCtrl
.WriteText( "\n\n" );
638 void MyApp::DoUnicodeDemo(wxCommandEvent
& WXUNUSED(event
))
640 wxTextCtrl
& textCtrl
= * GetTextCtrl();
643 textCtrl
<< "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
646 str
= _T("Robert Röbling\n");
648 printf( "\n\nConversion with wxConvLocal:\n" );
649 wxConvCurrent
= &wxConvLocal
;
650 printf( (const char*) str
.mbc_str() );
652 printf( "\n\nConversion with wxConvGdk:\n" );
653 wxConvCurrent
= &wxConvGdk
;
654 printf( (const char*) str
.mbc_str() );
656 printf( "\n\nConversion with wxConvLibc:\n" );
657 wxConvCurrent
= &wxConvLibc
;
658 printf( (const char*) str
.mbc_str() );
663 void MyApp::DoMIMEDemo(wxCommandEvent
& WXUNUSED(event
))
665 static wxString s_defaultExt
= "xyz";
667 wxString ext
= wxGetTextFromUser("Enter a file extension: ",
668 "MIME database test",
674 // init MIME database if not done yet
675 if ( !m_mimeDatabase
)
677 m_mimeDatabase
= new wxMimeTypesManager
;
679 static const wxFileTypeInfo fallbacks
[] =
681 wxFileTypeInfo("application/xyz",
684 "The one and only XYZ format file",
686 wxFileTypeInfo("text/html",
688 "lynx -dump %s | lpr",
689 "HTML document (from fallback)",
690 "htm", "html", NULL
),
692 // must terminate the table with this!
696 m_mimeDatabase
->AddFallbacks(fallbacks
);
699 wxTextCtrl
& textCtrl
= * GetTextCtrl();
701 wxFileType
*filetype
= m_mimeDatabase
->GetFileTypeFromExtension(ext
);
704 textCtrl
<< "Unknown extension '" << ext
<< "'\n";
708 wxString type
, desc
, open
;
709 filetype
->GetMimeType(&type
);
710 filetype
->GetDescription(&desc
);
712 wxString filename
= "filename";
713 filename
<< "." << ext
;
714 wxFileType::MessageParameters
params(filename
, type
);
715 filetype
->GetOpenCommand(&open
, params
);
717 textCtrl
<< "MIME information about extension '" << ext
<< "'\n"
718 << "\tMIME type: " << ( !type
? "unknown"
719 : type
.c_str() ) << '\n'
720 << "\tDescription: " << ( !desc
? "" : desc
.c_str() )
722 << "\tCommand to open: " << ( !open
? "no" : open
.c_str() )
728 //else: cancelled by user
731 void MyApp::DoByteOrderDemo(wxCommandEvent
& WXUNUSED(event
))
733 wxTextCtrl
& textCtrl
= * GetTextCtrl();
736 textCtrl
<< "\nTest byte order macros:\n\n";
738 if (wxBYTE_ORDER
== wxLITTLE_ENDIAN
)
739 textCtrl
<< "This is a little endian system.\n\n";
741 textCtrl
<< "This is a big endian system.\n\n";
745 wxInt32 var
= 0xF1F2F3F4;
747 text
.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var
);
748 textCtrl
.WriteText( text
);
751 text
.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var
) );
752 textCtrl
.WriteText( text
);
755 text
.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var
) );
756 textCtrl
.WriteText( text
);
759 text
.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var
) );
760 textCtrl
.WriteText( text
);
763 void MyApp::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
765 wxTextCtrl
& textCtrl
= * GetTextCtrl();
768 textCtrl
<< "\nTest class wxTime:\n";
770 textCtrl
<< "It is now " << (wxString
) now
<< "\n";
773 void MyApp::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
775 wxTextCtrl
& textCtrl
= * GetTextCtrl();
778 textCtrl
<< "\nTest class wxDate" << "\n";
780 // Various versions of the constructors
781 // and various output
783 wxDate
x(10,20,1962);
785 textCtrl
<< x
.FormatDate(wxFULL
) << " (full)\n";
787 // constuctor with a string, just printing the day of the week
788 wxDate
y("8/8/1988");
790 textCtrl
<< y
.FormatDate(wxDAY
) << " (just day)\n";
792 // constructor with a julian
793 wxDate
z( 2450000L );
794 textCtrl
<< z
.FormatDate(wxFULL
) << " (full)\n";
796 // using date addition and subtraction
798 textCtrl
<< a
.FormatDate(wxFULL
) << " (full)\n";
800 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << " (European)\n";
802 // Using subtraction of two date objects
803 wxDate a1
= wxString("7/13/1991");
805 textCtrl
<< (a1
-a2
) << "\n";
806 textCtrl
<< (a2
+=10) << "\n";
809 textCtrl
<< "Tomorrow= " << a1
.FormatDate(wxFULL
) << "\n";
811 wxDate
tmpDate1("08/01/1991");
812 wxDate
tmpDate2("07/14/1991");
813 textCtrl
<< "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1
< tmpDate1
) ? "TRUE" : "FALSE") << "\n";
814 textCtrl
<< "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1
> tmpDate1
) ? "TRUE" : "FALSE") << "\n";
815 textCtrl
<< "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1
==tmpDate2
) ? "TRUE" : "FALSE") << "\n";
818 textCtrl
<< "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1
==a3
) ? "TRUE" : "FALSE") << "\n";
820 textCtrl
<< "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1
==++a4
) ? "TRUE" : "FALSE") << "\n";
822 wxDate a5
= wxString("today");
823 textCtrl
<< "Today is: " << a5
<< "\n";
825 textCtrl
<< "Today (a4) is: " << a4
<< "\n";
827 textCtrl
<< "Today + 4 is: " << (a4
+=4) << "\n";
829 textCtrl
<< "Today - 4 is: " << (a4
-=4) << "\n";
831 textCtrl
<< "=========== Leap Year Test ===========\n";
833 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
834 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
837 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
838 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
840 textCtrl
<< "================== string assignment test ====================\n";
841 wxString date_string
=a1
;
842 textCtrl
<< "a1 as a string (s/b 2/16/1993) ==> " << date_string
<< "\n";
844 textCtrl
<< "================== SetFormat test ============================\n";
845 a1
.SetFormat(wxFULL
);
846 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
847 a1
.SetFormat(wxEUROPEAN
);
848 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
850 textCtrl
<< "================== SetOption test ============================\n";
851 textCtrl
<< "Date abbreviation ON\n";
853 a1
.SetOption(wxDATE_ABBR
);
854 a1
.SetFormat(wxMONTH
);
855 textCtrl
<< "a1 (s/b MONTH format) ==> " << a1
<< "\n";
857 textCtrl
<< "a1 (s/b DAY format) ==> " << a1
<< "\n";
858 a1
.SetFormat(wxFULL
);
859 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
860 a1
.SetFormat(wxEUROPEAN
);
861 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
862 textCtrl
<< "Century suppression ON\n";
863 a1
.SetOption(wxNO_CENTURY
);
865 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
866 textCtrl
<< "Century suppression OFF\n";
867 a1
.SetOption(wxNO_CENTURY
,FALSE
);
868 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
869 textCtrl
<< "Century suppression ON\n";
870 a1
.SetOption(wxNO_CENTURY
);
871 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
872 a1
.SetFormat(wxFULL
);
873 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
875 textCtrl
<< "\n=============== Version 4.0 Enhancement Test =================\n";
877 wxDate
v4("11/26/1966");
878 textCtrl
<< "\n---------- Set Stuff -----------\n";
879 textCtrl
<< "First, 'Set' to today..." << "\n";
880 textCtrl
<< "Before 'Set' => " << v4
<< "\n";
881 textCtrl
<< "After 'Set' => " << v4
.Set() << "\n\n";
883 textCtrl
<< "Set to 11/26/66 => " << v4
.Set(11,26,1966) << "\n";
884 textCtrl
<< "Current Julian => " << v4
.GetJulianDate() << "\n";
885 textCtrl
<< "Set to Julian 2450000L => " << v4
.Set(2450000L) << "\n";
886 textCtrl
<< "See! => " << v4
.GetJulianDate() << "\n";
888 textCtrl
<< "---------- Add Stuff -----------\n";
889 textCtrl
<< "Start => " << v4
<< "\n";
890 textCtrl
<< "Add 4 Weeks => " << v4
.AddWeeks(4) << "\n";
891 textCtrl
<< "Sub 1 Month => " << v4
.AddMonths(-1) << "\n";
892 textCtrl
<< "Add 2 Years => " << v4
.AddYears(2) << "\n";
894 textCtrl
<< "---------- Misc Stuff -----------\n";
895 textCtrl
<< "The date aboves' day of the month is => " << v4
.GetDay() << "\n";
896 textCtrl
<< "There are " << v4
.GetDaysInMonth() << " days in this month.\n";
897 textCtrl
<< "The first day of this month lands on " << v4
.GetFirstDayOfMonth() << "\n";
898 textCtrl
<< "This day happens to be " << v4
.GetDayOfWeekName() << "\n";
899 textCtrl
<< "the " << v4
.GetDayOfWeek() << " day of the week," << "\n";
900 textCtrl
<< "on the " << v4
.GetWeekOfYear() << " week of the year," << "\n";
901 textCtrl
<< "on the " << v4
.GetWeekOfMonth() << " week of the month, " << "\n";
902 textCtrl
<< "(which is " << v4
.GetMonthName() << ")\n";
903 textCtrl
<< "the "<< v4
.GetMonth() << "th month in the year.\n";
904 textCtrl
<< "The year alone is " << v4
.GetYear() << "\n";
906 textCtrl
<< "---------- First and Last Stuff -----------\n";
908 textCtrl
<< "The first date of this month is " << v4
.GetMonthStart() << "\n";
909 textCtrl
<< "The last date of this month is " << v4
.GetMonthEnd() << "\n";
910 textCtrl
<< "The first date of this year is " << v4
.GetYearStart() << "\n";
911 textCtrl
<< "The last date of this year is " << v4
.GetYearEnd() << "\n";
914 void MyApp::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
916 wxTextCtrl
& textCtrl
= * GetTextCtrl();
918 wxVariant var1
= "String value";
919 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
922 wxString str
= var1
.MakeString();
925 textCtrl
<< "var1 = " << var1
.GetReal() << "\n";
927 // Implicit conversion
931 textCtrl
<< "var1 = " << var1
.GetLong() << "\n";
933 // Implicit conversion
936 // suppress compile warnings about unused variables
942 wxStringList stringList
;
943 stringList
.Add(_T("one")); stringList
.Add(_T("two")); stringList
.Add(_T("three"));
945 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
948 var1
.Append(wxVariant(1.2345));
949 var1
.Append(wxVariant("hello"));
950 var1
.Append(wxVariant(54321L));
952 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
954 size_t n
= var1
.GetCount();
956 for (i
= (size_t) 0; i
< n
; i
++)
958 textCtrl
<< "var1[" << (int) i
<< "] (type " << var1
[i
].GetType() << ") = " << var1
[i
].MakeString() << "\n";
962 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
963 EVT_MENU(TYPES_QUIT
, MyFrame::OnQuit
)
964 EVT_MENU(TYPES_ABOUT
, MyFrame::OnAbout
)
967 // My frame constructor
968 MyFrame::MyFrame(wxFrame
*parent
, const wxString
& title
,
969 const wxPoint
& pos
, const wxSize
& size
):
970 wxFrame(parent
, -1, title
, pos
, size
)
973 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
978 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
980 wxMessageDialog
dialog(this, "Tests various wxWindows types",
981 "About Types", wxYES_NO
|wxCANCEL
);