]>
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__) || defined(__WXMAC__)
35 #include "mondrian.xpm"
42 #include "wx/ioswrap.h"
50 #include "wx/wfstream.h"
51 #include "wx/datstrm.h"
52 #include "wx/txtstrm.h"
53 #include "wx/mstream.h"
55 // Create a new application object
58 IMPLEMENT_DYNAMIC_CLASS (MyApp
, wxApp
)
60 BEGIN_EVENT_TABLE(MyApp
, wxApp
)
61 EVT_MENU(TYPES_DATE
, MyApp::DoDateDemo
)
62 EVT_MENU(TYPES_TIME
, MyApp::DoTimeDemo
)
63 EVT_MENU(TYPES_VARIANT
, MyApp::DoVariantDemo
)
64 EVT_MENU(TYPES_BYTEORDER
, MyApp::DoByteOrderDemo
)
66 EVT_MENU(TYPES_UNICODE
, MyApp::DoUnicodeDemo
)
68 EVT_MENU(TYPES_STREAM
, MyApp::DoStreamDemo
)
69 EVT_MENU(TYPES_STREAM2
, MyApp::DoStreamDemo2
)
70 EVT_MENU(TYPES_STREAM3
, MyApp::DoStreamDemo3
)
71 EVT_MENU(TYPES_STREAM4
, MyApp::DoStreamDemo4
)
72 EVT_MENU(TYPES_STREAM5
, MyApp::DoStreamDemo5
)
73 EVT_MENU(TYPES_MIME
, MyApp::DoMIMEDemo
)
78 // Create the main frame window
79 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "wxWindows Types Demo",
80 wxPoint(50, 50), wxSize(450, 340));
83 frame
->SetIcon(wxICON(mondrian
));
86 wxMenu
*file_menu
= new wxMenu
;
88 file_menu
->Append(TYPES_ABOUT
, "&About");
89 file_menu
->AppendSeparator();
90 file_menu
->Append(TYPES_QUIT
, "E&xit\tAlt-X");
92 wxMenu
*test_menu
= new wxMenu
;
93 test_menu
->Append(TYPES_DATE
, "&Date test");
94 test_menu
->Append(TYPES_TIME
, "&Time test");
95 test_menu
->Append(TYPES_VARIANT
, "&Variant test");
96 test_menu
->Append(TYPES_BYTEORDER
, "&Byteorder test");
98 test_menu
->Append(TYPES_UNICODE
, "&Unicode test");
100 test_menu
->Append(TYPES_STREAM
, "&Stream test");
101 test_menu
->Append(TYPES_STREAM2
, "&Stream seek test");
102 test_menu
->Append(TYPES_STREAM3
, "&Stream error test");
103 test_menu
->Append(TYPES_STREAM4
, "&Stream buffer test");
104 test_menu
->Append(TYPES_STREAM5
, "&Stream peek test");
105 test_menu
->AppendSeparator();
106 test_menu
->Append(TYPES_MIME
, "&MIME database test");
108 wxMenuBar
*menu_bar
= new wxMenuBar
;
109 menu_bar
->Append(file_menu
, "&File");
110 menu_bar
->Append(test_menu
, "&Tests");
111 frame
->SetMenuBar(menu_bar
);
113 m_textCtrl
= new wxTextCtrl(frame
, -1, "", wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
123 void MyApp::DoStreamDemo(wxCommandEvent
& WXUNUSED(event
))
125 wxTextCtrl
& textCtrl
= * GetTextCtrl();
128 textCtrl
<< _T("\nTest fstream vs. wxFileStream:\n\n");
130 textCtrl
.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
132 wxSTD ofstream
std_file_output( "test_std.dat" );
133 wxFileOutputStream
file_output( wxString("test_wx.dat") );
134 wxBufferedOutputStream
buf_output( file_output
);
135 wxTextOutputStream
text_output( buf_output
);
138 signed int si
= 0xFFFFFFFF;
139 tmp
.Printf( _T("Signed int: %d\n"), si
);
140 textCtrl
.WriteText( tmp
);
141 text_output
<< si
<< "\n";
142 std_file_output
<< si
<< "\n";
144 unsigned int ui
= 0xFFFFFFFF;
145 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
146 textCtrl
.WriteText( tmp
);
147 text_output
<< ui
<< "\n";
148 std_file_output
<< ui
<< "\n";
150 double d
= 2.01234567890123456789;
151 tmp
.Printf( _T("Double: %f\n"), d
);
152 textCtrl
.WriteText( tmp
);
153 text_output
<< d
<< "\n";
154 std_file_output
<< d
<< "\n";
156 float f
= (float)0.00001;
157 tmp
.Printf( _T("Float: %f\n"), f
);
158 textCtrl
.WriteText( tmp
);
159 text_output
<< f
<< "\n";
160 std_file_output
<< f
<< "\n";
162 wxString
str( _T("Hello!") );
163 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
164 textCtrl
.WriteText( tmp
);
165 text_output
<< str
<< "\n";
166 std_file_output
<< str
.c_str() << "\n";
168 textCtrl
.WriteText( "\nReading from ifstream:\n" );
170 wxSTD ifstream
std_file_input( "test_std.dat" );
172 std_file_input
>> si
;
173 tmp
.Printf( _T("Signed int: %d\n"), si
);
174 textCtrl
.WriteText( tmp
);
176 std_file_input
>> ui
;
177 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
178 textCtrl
.WriteText( tmp
);
181 tmp
.Printf( _T("Double: %f\n"), d
);
182 textCtrl
.WriteText( tmp
);
185 tmp
.Printf( _T("Float: %f\n"), f
);
186 textCtrl
.WriteText( tmp
);
188 // Why doesn't this work?
191 std_file_input
>> std_buf
;
192 tmp
.Printf( _T("String: %s\n"), std_buf
);
193 textCtrl
.WriteText( tmp
);
196 textCtrl
.WriteText( "\nReading from wxFileInputStream:\n" );
200 wxFileInputStream
file_input( wxString("test_wx.dat") );
201 wxBufferedInputStream
buf_input( file_input
);
202 wxTextInputStream
text_input( file_input
);
205 tmp
.Printf( _T("Signed int: %d\n"), si
);
206 textCtrl
.WriteText( tmp
);
209 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
210 textCtrl
.WriteText( tmp
);
213 tmp
.Printf( _T("Double: %f\n"), d
);
214 textCtrl
.WriteText( tmp
);
217 tmp
.Printf( _T("Float: %f\n"), f
);
218 textCtrl
.WriteText( tmp
);
221 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
222 textCtrl
.WriteText( tmp
);
226 textCtrl
<< "\nTest for wxDataStream:\n\n";
228 textCtrl
.WriteText( "Writing to wxDataOutputStream:\n" );
230 file_output
.SeekO( 0 );
231 wxDataOutputStream
data_output( buf_output
);
233 wxInt16 i16
= (short)0xFFFF;
234 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
235 textCtrl
.WriteText( tmp
);
236 data_output
.Write16( i16
);
238 wxUint16 ui16
= 0xFFFF;
239 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
240 textCtrl
.WriteText( tmp
);
241 data_output
.Write16( ui16
);
243 d
= 2.01234567890123456789;
244 tmp
.Printf( _T("Double: %f\n"), d
);
245 textCtrl
.WriteText( tmp
);
246 data_output
.WriteDouble( d
);
249 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
250 textCtrl
.WriteText( tmp
);
251 data_output
.WriteString( str
);
255 textCtrl
.WriteText( "\nReading from wxDataInputStream:\n" );
257 file_input
.SeekI( 0 );
258 wxDataInputStream
data_input( buf_input
);
260 i16
= data_input
.Read16();
261 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
262 textCtrl
.WriteText( tmp
);
264 ui16
= data_input
.Read16();
265 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
266 textCtrl
.WriteText( tmp
);
268 d
= data_input
.ReadDouble();
269 tmp
.Printf( _T("Double: %f\n"), d
);
270 textCtrl
.WriteText( tmp
);
272 str
= data_input
.ReadString();
273 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
274 textCtrl
.WriteText( tmp
);
277 void MyApp::DoStreamDemo2(wxCommandEvent
& WXUNUSED(event
))
279 wxTextCtrl
& textCtrl
= * GetTextCtrl();
282 textCtrl
<< _T("\nTesting wxBufferedStream:\n\n");
286 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
288 wxFileOutputStream
file_output( wxString("test_wx.dat") );
289 wxBufferedOutputStream
buf_output( file_output
);
290 for (ch
= 0; ch
< 10; ch
++)
291 buf_output
.Write( &ch
, 1 );
294 wxFileInputStream
file_input( wxString("test_wx.dat") );
295 for (ch2
= 0; ch2
< 10; ch2
++)
297 file_input
.Read( &ch
, 1 );
298 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
300 textCtrl
.WriteText( "\n\n\n" );
302 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
303 textCtrl
.WriteText( "seeking back to #3 and writing 3:\n\n" );
305 wxFileOutputStream
file_output2( wxString("test_wx2.dat") );
306 wxBufferedOutputStream
buf_output2( file_output2
);
307 for (ch
= 0; ch
< 10; ch
++)
308 buf_output2
.Write( &ch
, 1 );
309 buf_output2
.SeekO( 3 );
311 buf_output2
.Write( &ch
, 1 );
314 wxFileInputStream
file_input2( wxString("test_wx2.dat") );
315 for (ch2
= 0; ch2
< 10; ch2
++)
317 file_input2
.Read( &ch
, 1 );
318 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
320 textCtrl
.WriteText( "\n\n\n" );
322 // now append 2000 bytes to file (bigger than buffer)
323 buf_output2
.SeekO( 0, wxFromEnd
);
325 for (int i
= 0; i
< 2000; i
++)
326 buf_output2
.Write( &ch
, 1 );
329 textCtrl
.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
330 textCtrl
.WriteText( "seeking back to #3 and reading 3:\n\n" );
332 wxFileInputStream
file_input3( wxString("test_wx2.dat") );
333 wxBufferedInputStream
buf_input3( file_input3
);
334 for (ch2
= 0; ch2
< 10; ch2
++)
336 buf_input3
.Read( &ch
, 1 );
337 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
339 for (int j
= 0; j
< 2000; j
++)
340 buf_input3
.Read( &ch
, 1 );
341 textCtrl
.WriteText( "\n" );
342 buf_input3
.SeekI( 3 );
343 buf_input3
.Read( &ch
, 1 );
344 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
345 textCtrl
.WriteText( "\n\n\n" );
349 void MyApp::DoStreamDemo3(wxCommandEvent
& WXUNUSED(event
))
351 wxTextCtrl
& textCtrl
= * GetTextCtrl();
354 textCtrl
<< "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
358 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
360 wxFileOutputStream
file_output( wxString("test_wx.dat") );
361 for (ch
= 0; ch
< 10; ch
++)
362 file_output
.Write( &ch
, 1 );
364 // Testing wxFileInputStream
366 textCtrl
.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
368 wxFileInputStream
file_input( wxString("test_wx.dat") );
369 for (ch2
= 0; ch2
< 11; ch2
++)
371 file_input
.Read( &ch
, 1 );
372 textCtrl
.WriteText( "Value read: " );
373 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
374 textCtrl
.WriteText( "; stream.LastError() returns: " );
375 switch (file_input
.LastError())
377 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
378 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
379 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
380 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
381 default: textCtrl
.WriteText( "Huh?\n" ); break;
384 textCtrl
.WriteText( "\n" );
386 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
387 file_input
.SeekI( 0 );
388 switch (file_input
.LastError())
390 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
391 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
392 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
393 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
394 default: textCtrl
.WriteText( "Huh?\n" ); break;
396 textCtrl
.WriteText( "\n" );
398 file_input
.Read( &ch
, 1 );
399 textCtrl
.WriteText( "Value read: " );
400 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
401 textCtrl
.WriteText( "; stream.LastError() returns: " );
402 switch (file_input
.LastError())
404 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
405 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
406 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
407 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
408 default: textCtrl
.WriteText( "Huh?\n" ); break;
410 textCtrl
.WriteText( "\n\n" );
413 // Testing wxFFileInputStream
415 textCtrl
.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
417 wxFFileInputStream
ffile_input( wxString("test_wx.dat") );
418 for (ch2
= 0; ch2
< 11; ch2
++)
420 ffile_input
.Read( &ch
, 1 );
421 textCtrl
.WriteText( "Value read: " );
422 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
423 textCtrl
.WriteText( "; stream.LastError() returns: " );
424 switch (ffile_input
.LastError())
426 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
427 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
428 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
429 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
430 default: textCtrl
.WriteText( "Huh?\n" ); break;
433 textCtrl
.WriteText( "\n" );
435 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
436 ffile_input
.SeekI( 0 );
437 switch (ffile_input
.LastError())
439 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
440 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
441 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
442 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
443 default: textCtrl
.WriteText( "Huh?\n" ); break;
445 textCtrl
.WriteText( "\n" );
447 ffile_input
.Read( &ch
, 1 );
448 textCtrl
.WriteText( "Value read: " );
449 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
450 textCtrl
.WriteText( "; stream.LastError() returns: " );
451 switch (ffile_input
.LastError())
453 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
454 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
455 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
456 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
457 default: textCtrl
.WriteText( "Huh?\n" ); break;
459 textCtrl
.WriteText( "\n\n" );
461 // Testing wxFFileInputStream
463 textCtrl
.WriteText( "Reading 0 to 10 to buffered wxFFileInputStream:\n\n" );
465 wxFFileInputStream
ffile_input2( wxString("test_wx.dat") );
466 wxBufferedInputStream
buf_input( ffile_input2
);
467 for (ch2
= 0; ch2
< 11; ch2
++)
469 buf_input
.Read( &ch
, 1 );
470 textCtrl
.WriteText( "Value read: " );
471 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
472 textCtrl
.WriteText( "; stream.LastError() returns: " );
473 switch (buf_input
.LastError())
475 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
476 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
477 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
478 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
479 default: textCtrl
.WriteText( "Huh?\n" ); break;
482 textCtrl
.WriteText( "\n" );
484 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
485 buf_input
.SeekI( 0 );
486 switch (buf_input
.LastError())
488 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
489 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
490 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
491 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
492 default: textCtrl
.WriteText( "Huh?\n" ); break;
494 textCtrl
.WriteText( "\n" );
496 buf_input
.Read( &ch
, 1 );
497 textCtrl
.WriteText( "Value read: " );
498 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
499 textCtrl
.WriteText( "; stream.LastError() returns: " );
500 switch (buf_input
.LastError())
502 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
503 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
504 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
505 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
506 default: textCtrl
.WriteText( "Huh?\n" ); break;
510 void MyApp::DoStreamDemo4(wxCommandEvent
& WXUNUSED(event
))
512 wxTextCtrl
& textCtrl
= * GetTextCtrl();
517 textCtrl
<< "\nTesting wxStreamBuffer:\n\n";
519 // bigger than buffer
520 textCtrl
.WriteText( "Writing 2000x 1 to wxFileOutputStream.\n\n" );
522 wxFileOutputStream
file_output( wxString("test_wx.dat") );
523 for (int i
= 0; i
< 2000; i
++)
526 file_output
.Write( &ch
, 1 );
529 textCtrl
.WriteText( "Opening with a buffered wxFileInputStream:\n\n" );
531 wxFileInputStream
file_input( wxString("test_wx.dat") );
532 wxBufferedInputStream
buf_input( file_input
);
534 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
535 switch (buf_input
.LastError())
537 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
538 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
539 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
540 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
541 default: textCtrl
.WriteText( "Huh?\n" ); break;
543 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
544 textCtrl
.WriteText( msg
);
545 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
546 textCtrl
.WriteText( msg
);
547 textCtrl
.WriteText( "\n\n" );
550 textCtrl
.WriteText( "Seeking to position 300:\n\n" );
552 buf_input
.SeekI( 300 );
554 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
555 switch (buf_input
.LastError())
557 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
558 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
559 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
560 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
561 default: textCtrl
.WriteText( "Huh?\n" ); break;
563 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
564 textCtrl
.WriteText( msg
);
565 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
566 textCtrl
.WriteText( msg
);
567 textCtrl
.WriteText( "\n\n" );
572 textCtrl
.WriteText( "Reading 500 bytes:\n\n" );
574 buf_input
.Read( buf
, 500 );
576 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
577 switch (buf_input
.LastError())
579 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
580 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
581 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
582 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
583 default: textCtrl
.WriteText( "Huh?\n" ); break;
585 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
586 textCtrl
.WriteText( msg
);
587 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
588 textCtrl
.WriteText( msg
);
589 textCtrl
.WriteText( "\n\n" );
591 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
593 buf_input
.Read( buf
, 500 );
595 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
596 switch (buf_input
.LastError())
598 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
599 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
600 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
601 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
602 default: textCtrl
.WriteText( "Huh?\n" ); break;
604 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
605 textCtrl
.WriteText( msg
);
606 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
607 textCtrl
.WriteText( msg
);
608 textCtrl
.WriteText( "\n\n" );
610 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
612 buf_input
.Read( buf
, 500 );
614 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
615 switch (buf_input
.LastError())
617 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
618 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
619 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
620 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
621 default: textCtrl
.WriteText( "Huh?\n" ); break;
623 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
624 textCtrl
.WriteText( msg
);
625 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
626 textCtrl
.WriteText( msg
);
627 textCtrl
.WriteText( "\n\n" );
629 textCtrl
.WriteText( "Reading another 500 bytes:\n\n" );
631 buf_input
.Read( buf
, 500 );
633 textCtrl
.WriteText( "wxBufferedInputStream.LastError() returns: " );
634 switch (buf_input
.LastError())
636 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
637 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
638 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
639 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
640 default: textCtrl
.WriteText( "Huh?\n" ); break;
642 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
643 textCtrl
.WriteText( msg
);
644 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
645 textCtrl
.WriteText( msg
);
646 textCtrl
.WriteText( "\n\n" );
649 void MyApp::DoStreamDemo5(wxCommandEvent
& WXUNUSED(event
))
651 wxTextCtrl
& textCtrl
= * GetTextCtrl();
654 textCtrl
<< "\nTesting wxFileInputStream's Peek():\n\n";
659 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
661 wxFileOutputStream
file_output( wxString("test_wx.dat") );
662 for (ch
= 0; ch
< 10; ch
++)
663 file_output
.Write( &ch
, 1 );
667 wxFileInputStream
file_input( wxString("test_wx.dat") );
669 ch
= file_input
.Peek();
670 str
.Printf( wxT("First char peeked: %d\n"), (int) ch
);
671 textCtrl
.WriteText( str
);
673 ch
= file_input
.GetC();
674 str
.Printf( wxT("First char read: %d\n"), (int) ch
);
675 textCtrl
.WriteText( str
);
677 ch
= file_input
.Peek();
678 str
.Printf( wxT("Second char peeked: %d\n"), (int) ch
);
679 textCtrl
.WriteText( str
);
681 ch
= file_input
.GetC();
682 str
.Printf( wxT("Second char read: %d\n"), (int) ch
);
683 textCtrl
.WriteText( str
);
685 ch
= file_input
.Peek();
686 str
.Printf( wxT("Third char peeked: %d\n"), (int) ch
);
687 textCtrl
.WriteText( str
);
689 ch
= file_input
.GetC();
690 str
.Printf( wxT("Third char read: %d\n"), (int) ch
);
691 textCtrl
.WriteText( str
);
694 textCtrl
<< "\n\n\nTesting wxMemoryInputStream's Peek():\n\n";
696 char buf
[] = { 0,1,2,3,4,5,6,7,8,9,10 };
697 wxMemoryInputStream
input( buf
, 10 );
700 str
.Printf( wxT("First char peeked: %d\n"), (int) ch
);
701 textCtrl
.WriteText( str
);
704 str
.Printf( wxT("First char read: %d\n"), (int) ch
);
705 textCtrl
.WriteText( str
);
708 str
.Printf( wxT("Second char peeked: %d\n"), (int) ch
);
709 textCtrl
.WriteText( str
);
712 str
.Printf( wxT("Second char read: %d\n"), (int) ch
);
713 textCtrl
.WriteText( str
);
716 str
.Printf( wxT("Third char peeked: %d\n"), (int) ch
);
717 textCtrl
.WriteText( str
);
720 str
.Printf( wxT("Third char read: %d\n"), (int) ch
);
721 textCtrl
.WriteText( str
);
725 void MyApp::DoUnicodeDemo(wxCommandEvent
& WXUNUSED(event
))
727 wxTextCtrl
& textCtrl
= * GetTextCtrl();
730 textCtrl
<< "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
733 str
= _T("Robert Röbling\n");
735 printf( "\n\nConversion with wxConvLocal:\n" );
736 wxConvCurrent
= &wxConvLocal
;
737 printf( (const char*) str
.mbc_str() );
738 #if defined(__WXGTK__)
739 printf( "\n\nConversion with wxConvGdk:\n" );
740 wxConvCurrent
= &wxConvGdk
;
741 printf( (const char*) str
.mbc_str() );
743 printf( "\n\nConversion with wxConvLibc:\n" );
744 wxConvCurrent
= &wxConvLibc
;
745 printf( (const char*) str
.mbc_str() );
750 void MyApp::DoMIMEDemo(wxCommandEvent
& WXUNUSED(event
))
752 static wxString s_defaultExt
= "xyz";
754 wxString ext
= wxGetTextFromUser("Enter a file extension: ",
755 "MIME database test",
761 // init MIME database if not done yet
762 if ( !m_mimeDatabase
)
764 m_mimeDatabase
= new wxMimeTypesManager
;
766 static const wxFileTypeInfo fallbacks
[] =
768 wxFileTypeInfo("application/xyz",
771 "The one and only XYZ format file",
773 wxFileTypeInfo("text/html",
775 "lynx -dump %s | lpr",
776 "HTML document (from fallback)",
777 "htm", "html", NULL
),
779 // must terminate the table with this!
783 m_mimeDatabase
->AddFallbacks(fallbacks
);
786 wxTextCtrl
& textCtrl
= * GetTextCtrl();
788 wxFileType
*filetype
= m_mimeDatabase
->GetFileTypeFromExtension(ext
);
791 textCtrl
<< "Unknown extension '" << ext
<< "'\n";
795 wxString type
, desc
, open
;
796 filetype
->GetMimeType(&type
);
797 filetype
->GetDescription(&desc
);
799 wxString filename
= "filename";
800 filename
<< "." << ext
;
801 wxFileType::MessageParameters
params(filename
, type
);
802 filetype
->GetOpenCommand(&open
, params
);
804 textCtrl
<< "MIME information about extension '" << ext
<< "'\n"
805 << "\tMIME type: " << ( !type
? wxT("unknown")
806 : type
.c_str() ) << '\n'
807 << "\tDescription: " << ( !desc
? wxT("") : desc
.c_str() )
809 << "\tCommand to open: " << ( !open
? wxT("no") : open
.c_str() )
815 //else: cancelled by user
818 void MyApp::DoByteOrderDemo(wxCommandEvent
& WXUNUSED(event
))
820 wxTextCtrl
& textCtrl
= * GetTextCtrl();
823 textCtrl
<< "\nTest byte order macros:\n\n";
825 if (wxBYTE_ORDER
== wxLITTLE_ENDIAN
)
826 textCtrl
<< "This is a little endian system.\n\n";
828 textCtrl
<< "This is a big endian system.\n\n";
832 wxInt32 var
= 0xF1F2F3F4;
834 text
.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var
);
835 textCtrl
.WriteText( text
);
838 text
.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var
) );
839 textCtrl
.WriteText( text
);
842 text
.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var
) );
843 textCtrl
.WriteText( text
);
846 text
.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var
) );
847 textCtrl
.WriteText( text
);
850 void MyApp::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
852 wxTextCtrl
& textCtrl
= * GetTextCtrl();
855 textCtrl
<< "\nTest class wxTime:\n";
857 textCtrl
<< "It is now " << (wxString
) now
<< "\n";
860 void MyApp::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
862 wxTextCtrl
& textCtrl
= * GetTextCtrl();
865 textCtrl
<< "\nTest class wxDate" << "\n";
867 // Various versions of the constructors
868 // and various output
870 wxDate
x(10,20,1962);
872 textCtrl
<< x
.FormatDate(wxFULL
) << " (full)\n";
874 // constuctor with a string, just printing the day of the week
875 wxDate
y("8/8/1988");
877 textCtrl
<< y
.FormatDate(wxDAY
) << " (just day)\n";
879 // constructor with a julian
880 wxDate
z( 2450000L );
881 textCtrl
<< z
.FormatDate(wxFULL
) << " (full)\n";
883 // using date addition and subtraction
885 textCtrl
<< a
.FormatDate(wxFULL
) << " (full)\n";
887 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << " (European)\n";
889 // Using subtraction of two date objects
890 wxDate a1
= wxString("7/13/1991");
892 textCtrl
<< (a1
-a2
) << "\n";
893 textCtrl
<< (a2
+=10) << "\n";
896 textCtrl
<< "Tomorrow= " << a1
.FormatDate(wxFULL
) << "\n";
898 wxDate
tmpDate1("08/01/1991");
899 wxDate
tmpDate2("07/14/1991");
900 textCtrl
<< "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1
< tmpDate1
) ? "TRUE" : "FALSE") << "\n";
901 textCtrl
<< "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1
> tmpDate1
) ? "TRUE" : "FALSE") << "\n";
902 textCtrl
<< "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1
==tmpDate2
) ? "TRUE" : "FALSE") << "\n";
905 textCtrl
<< "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1
==a3
) ? "TRUE" : "FALSE") << "\n";
907 textCtrl
<< "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1
==++a4
) ? "TRUE" : "FALSE") << "\n";
909 wxDate a5
= wxString("today");
910 textCtrl
<< "Today is: " << a5
<< "\n";
912 textCtrl
<< "Today (a4) is: " << a4
<< "\n";
914 textCtrl
<< "Today + 4 is: " << (a4
+=4) << "\n";
916 textCtrl
<< "Today - 4 is: " << (a4
-=4) << "\n";
918 textCtrl
<< "=========== Leap Year Test ===========\n";
920 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
921 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
924 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
925 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
927 textCtrl
<< "================== string assignment test ====================\n";
928 wxString date_string
=a1
;
929 textCtrl
<< "a1 as a string (s/b 2/16/1993) ==> " << date_string
<< "\n";
931 textCtrl
<< "================== SetFormat test ============================\n";
932 a1
.SetFormat(wxFULL
);
933 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
934 a1
.SetFormat(wxEUROPEAN
);
935 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
937 textCtrl
<< "================== SetOption test ============================\n";
938 textCtrl
<< "Date abbreviation ON\n";
940 a1
.SetOption(wxDATE_ABBR
);
941 a1
.SetFormat(wxMONTH
);
942 textCtrl
<< "a1 (s/b MONTH format) ==> " << a1
<< "\n";
944 textCtrl
<< "a1 (s/b DAY format) ==> " << a1
<< "\n";
945 a1
.SetFormat(wxFULL
);
946 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
947 a1
.SetFormat(wxEUROPEAN
);
948 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
949 textCtrl
<< "Century suppression ON\n";
950 a1
.SetOption(wxNO_CENTURY
);
952 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
953 textCtrl
<< "Century suppression OFF\n";
954 a1
.SetOption(wxNO_CENTURY
,FALSE
);
955 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
956 textCtrl
<< "Century suppression ON\n";
957 a1
.SetOption(wxNO_CENTURY
);
958 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
959 a1
.SetFormat(wxFULL
);
960 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
962 textCtrl
<< "\n=============== Version 4.0 Enhancement Test =================\n";
964 wxDate
v4("11/26/1966");
965 textCtrl
<< "\n---------- Set Stuff -----------\n";
966 textCtrl
<< "First, 'Set' to today..." << "\n";
967 textCtrl
<< "Before 'Set' => " << v4
<< "\n";
968 textCtrl
<< "After 'Set' => " << v4
.Set() << "\n\n";
970 textCtrl
<< "Set to 11/26/66 => " << v4
.Set(11,26,1966) << "\n";
971 textCtrl
<< "Current Julian => " << v4
.GetJulianDate() << "\n";
972 textCtrl
<< "Set to Julian 2450000L => " << v4
.Set(2450000L) << "\n";
973 textCtrl
<< "See! => " << v4
.GetJulianDate() << "\n";
975 textCtrl
<< "---------- Add Stuff -----------\n";
976 textCtrl
<< "Start => " << v4
<< "\n";
977 textCtrl
<< "Add 4 Weeks => " << v4
.AddWeeks(4) << "\n";
978 textCtrl
<< "Sub 1 Month => " << v4
.AddMonths(-1) << "\n";
979 textCtrl
<< "Add 2 Years => " << v4
.AddYears(2) << "\n";
981 textCtrl
<< "---------- Misc Stuff -----------\n";
982 textCtrl
<< "The date aboves' day of the month is => " << v4
.GetDay() << "\n";
983 textCtrl
<< "There are " << v4
.GetDaysInMonth() << " days in this month.\n";
984 textCtrl
<< "The first day of this month lands on " << v4
.GetFirstDayOfMonth() << "\n";
985 textCtrl
<< "This day happens to be " << v4
.GetDayOfWeekName() << "\n";
986 textCtrl
<< "the " << v4
.GetDayOfWeek() << " day of the week," << "\n";
987 textCtrl
<< "on the " << v4
.GetWeekOfYear() << " week of the year," << "\n";
988 textCtrl
<< "on the " << v4
.GetWeekOfMonth() << " week of the month, " << "\n";
989 textCtrl
<< "(which is " << v4
.GetMonthName() << ")\n";
990 textCtrl
<< "the "<< v4
.GetMonth() << "th month in the year.\n";
991 textCtrl
<< "The year alone is " << v4
.GetYear() << "\n";
993 textCtrl
<< "---------- First and Last Stuff -----------\n";
995 textCtrl
<< "The first date of this month is " << v4
.GetMonthStart() << "\n";
996 textCtrl
<< "The last date of this month is " << v4
.GetMonthEnd() << "\n";
997 textCtrl
<< "The first date of this year is " << v4
.GetYearStart() << "\n";
998 textCtrl
<< "The last date of this year is " << v4
.GetYearEnd() << "\n";
1001 void MyApp::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
1003 wxTextCtrl
& textCtrl
= * GetTextCtrl();
1005 wxVariant var1
= "String value";
1006 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
1009 wxString str
= var1
.MakeString();
1012 textCtrl
<< "var1 = " << var1
.GetReal() << "\n";
1014 // Implicit conversion
1018 textCtrl
<< "var1 = " << var1
.GetLong() << "\n";
1020 // Implicit conversion
1023 // suppress compile warnings about unused variables
1029 wxStringList stringList
;
1030 stringList
.Add(_T("one")); stringList
.Add(_T("two")); stringList
.Add(_T("three"));
1032 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
1035 var1
.Append(wxVariant(1.2345));
1036 var1
.Append(wxVariant("hello"));
1037 var1
.Append(wxVariant(54321L));
1039 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
1041 size_t n
= var1
.GetCount();
1043 for (i
= (size_t) 0; i
< n
; i
++)
1045 textCtrl
<< "var1[" << (int) i
<< "] (type " << var1
[i
].GetType() << ") = " << var1
[i
].MakeString() << "\n";
1049 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1050 EVT_MENU(TYPES_QUIT
, MyFrame::OnQuit
)
1051 EVT_MENU(TYPES_ABOUT
, MyFrame::OnAbout
)
1054 // My frame constructor
1055 MyFrame::MyFrame(wxFrame
*parent
, const wxString
& title
,
1056 const wxPoint
& pos
, const wxSize
& size
):
1057 wxFrame(parent
, -1, title
, pos
, size
)
1060 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
1065 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
1067 wxMessageDialog
dialog(this, "Tests various wxWindows types",
1068 "About Types", wxYES_NO
|wxCANCEL
);