]>
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(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
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
)
62 EVT_MENU(TYPES_DATE
, MyApp::DoDateDemo
)
63 EVT_MENU(TYPES_TIME
, MyApp::DoTimeDemo
)
64 #endif // wxUSE_TIMEDATE
65 EVT_MENU(TYPES_VARIANT
, MyApp::DoVariantDemo
)
66 EVT_MENU(TYPES_BYTEORDER
, MyApp::DoByteOrderDemo
)
68 EVT_MENU(TYPES_UNICODE
, MyApp::DoUnicodeDemo
)
69 #endif // wxUSE_UNICODE
70 EVT_MENU(TYPES_STREAM
, MyApp::DoStreamDemo
)
71 EVT_MENU(TYPES_STREAM2
, MyApp::DoStreamDemo2
)
72 EVT_MENU(TYPES_STREAM3
, MyApp::DoStreamDemo3
)
73 EVT_MENU(TYPES_STREAM4
, MyApp::DoStreamDemo4
)
74 EVT_MENU(TYPES_STREAM5
, MyApp::DoStreamDemo5
)
75 EVT_MENU(TYPES_STREAM6
, MyApp::DoStreamDemo6
)
76 EVT_MENU(TYPES_STREAM7
, MyApp::DoStreamDemo7
)
77 EVT_MENU(TYPES_MIME
, MyApp::DoMIMEDemo
)
82 // Create the main frame window
83 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWindows Types Demo"),
84 wxPoint(50, 50), wxSize(450, 340));
87 frame
->SetIcon(wxICON(mondrian
));
90 wxMenu
*file_menu
= new wxMenu
;
92 file_menu
->Append(TYPES_ABOUT
, _T("&About"));
93 file_menu
->AppendSeparator();
94 file_menu
->Append(TYPES_QUIT
, _T("E&xit\tAlt-X"));
96 wxMenu
*test_menu
= new wxMenu
;
98 test_menu
->Append(TYPES_DATE
, _T("&Date test"));
99 test_menu
->Append(TYPES_TIME
, _T("&Time test"));
100 #endif // wxUSE_TIMEDATE
101 test_menu
->Append(TYPES_VARIANT
, _T("&Variant test"));
102 test_menu
->Append(TYPES_BYTEORDER
, _T("&Byteorder test"));
104 test_menu
->Append(TYPES_UNICODE
, _T("&Unicode test"));
105 #endif // wxUSE_UNICODE
106 test_menu
->Append(TYPES_STREAM
, _T("&Stream test"));
107 test_menu
->Append(TYPES_STREAM2
, _T("&Stream seek test"));
108 test_menu
->Append(TYPES_STREAM3
, _T("&Stream error test"));
109 test_menu
->Append(TYPES_STREAM4
, _T("&Stream buffer test"));
110 test_menu
->Append(TYPES_STREAM5
, _T("&Stream peek test"));
111 test_menu
->Append(TYPES_STREAM6
, _T("&Stream ungetch test"));
112 test_menu
->Append(TYPES_STREAM7
, _T("&Stream ungetch test for a buffered stream"));
113 test_menu
->AppendSeparator();
114 test_menu
->Append(TYPES_MIME
, _T("&MIME database test"));
116 wxMenuBar
*menu_bar
= new wxMenuBar
;
117 menu_bar
->Append(file_menu
, _T("&File"));
118 menu_bar
->Append(test_menu
, _T("&Tests"));
119 frame
->SetMenuBar(menu_bar
);
121 m_textCtrl
= new wxTextCtrl(frame
, -1, _T(""), wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
131 void MyApp::DoStreamDemo(wxCommandEvent
& WXUNUSED(event
))
133 wxTextCtrl
& textCtrl
= * GetTextCtrl();
136 textCtrl
<< _T("\nTest fstream vs. wxFileStream:\n\n");
138 textCtrl
.WriteText( _T("Writing to ofstream and wxFileOutputStream:\n") );
140 wxSTD ofstream
std_file_output( "test_std.dat" );
141 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
142 wxBufferedOutputStream
buf_output( file_output
);
143 wxTextOutputStream
text_output( buf_output
);
146 signed int si
= 0xFFFFFFFF;
147 tmp
.Printf( _T("Signed int: %d\n"), si
);
148 textCtrl
.WriteText( tmp
);
149 text_output
<< si
<< _T("\n");
150 std_file_output
<< si
<< _T("\n");
152 unsigned int ui
= 0xFFFFFFFF;
153 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
154 textCtrl
.WriteText( tmp
);
155 text_output
<< ui
<< _T("\n");
156 std_file_output
<< ui
<< _T("\n");
158 double d
= 2.01234567890123456789;
159 tmp
.Printf( _T("Double: %f\n"), d
);
160 textCtrl
.WriteText( tmp
);
161 text_output
<< d
<< _T("\n");
162 std_file_output
<< d
<< _T("\n");
164 float f
= (float)0.00001;
165 tmp
.Printf( _T("Float: %f\n"), f
);
166 textCtrl
.WriteText( tmp
);
167 text_output
<< f
<< _T("\n");
168 std_file_output
<< f
<< _T("\n");
170 wxString
str( _T("Hello!") );
171 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
172 textCtrl
.WriteText( tmp
);
173 text_output
<< str
<< _T("\n");
174 std_file_output
<< str
.c_str() << _T("\n");
176 textCtrl
.WriteText( _T("\nReading from ifstream:\n") );
178 wxSTD ifstream
std_file_input( "test_std.dat" );
180 std_file_input
>> si
;
181 tmp
.Printf( _T("Signed int: %d\n"), si
);
182 textCtrl
.WriteText( tmp
);
184 std_file_input
>> ui
;
185 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
186 textCtrl
.WriteText( tmp
);
189 tmp
.Printf( _T("Double: %f\n"), d
);
190 textCtrl
.WriteText( tmp
);
193 tmp
.Printf( _T("Float: %f\n"), f
);
194 textCtrl
.WriteText( tmp
);
196 // Why doesn't this work?
199 std_file_input
>> std_buf
;
200 tmp
.Printf( _T("String: %s\n"), std_buf
);
201 textCtrl
.WriteText( tmp
);
204 textCtrl
.WriteText( _T("\nReading from wxFileInputStream:\n") );
208 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
209 wxBufferedInputStream
buf_input( file_input
);
210 wxTextInputStream
text_input( file_input
);
213 tmp
.Printf( _T("Signed int: %d\n"), si
);
214 textCtrl
.WriteText( tmp
);
217 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
218 textCtrl
.WriteText( tmp
);
221 tmp
.Printf( _T("Double: %f\n"), d
);
222 textCtrl
.WriteText( tmp
);
225 tmp
.Printf( _T("Float: %f\n"), f
);
226 textCtrl
.WriteText( tmp
);
229 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
230 textCtrl
.WriteText( tmp
);
234 textCtrl
<< _T("\nTest for wxDataStream:\n\n");
236 textCtrl
.WriteText( _T("Writing to wxDataOutputStream:\n") );
238 file_output
.SeekO( 0 );
239 wxDataOutputStream
data_output( buf_output
);
241 wxInt16 i16
= (unsigned short)0xFFFF;
242 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
243 textCtrl
.WriteText( tmp
);
244 data_output
.Write16( i16
);
246 wxUint16 ui16
= 0xFFFF;
247 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
248 textCtrl
.WriteText( tmp
);
249 data_output
.Write16( ui16
);
251 d
= 2.01234567890123456789;
252 tmp
.Printf( _T("Double: %f\n"), d
);
253 textCtrl
.WriteText( tmp
);
254 data_output
.WriteDouble( d
);
257 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
258 textCtrl
.WriteText( tmp
);
259 data_output
.WriteString( str
);
263 textCtrl
.WriteText( _T("\nReading from wxDataInputStream:\n") );
265 file_input
.SeekI( 0 );
266 wxDataInputStream
data_input( buf_input
);
268 i16
= data_input
.Read16();
269 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
270 textCtrl
.WriteText( tmp
);
272 ui16
= data_input
.Read16();
273 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
274 textCtrl
.WriteText( tmp
);
276 d
= data_input
.ReadDouble();
277 tmp
.Printf( _T("Double: %f\n"), d
);
278 textCtrl
.WriteText( tmp
);
280 str
= data_input
.ReadString();
281 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
282 textCtrl
.WriteText( tmp
);
285 void MyApp::DoStreamDemo2(wxCommandEvent
& WXUNUSED(event
))
287 wxTextCtrl
& textCtrl
= * GetTextCtrl();
290 textCtrl
<< _T("\nTesting wxBufferedStream:\n\n");
294 textCtrl
.WriteText( _T("Writing number 0 to 9 to buffered wxFileOutputStream:\n\n") );
296 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
297 wxBufferedOutputStream
buf_output( file_output
);
298 for (ch
= 0; ch
< 10; ch
++)
299 buf_output
.Write( &ch
, 1 );
302 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
303 for (ch2
= 0; ch2
< 10; ch2
++)
305 file_input
.Read( &ch
, 1 );
306 textCtrl
.WriteText( (wxChar
)(ch
+ _T('0')) );
308 textCtrl
.WriteText( _T("\n\n\n") );
310 textCtrl
.WriteText( _T("Writing number 0 to 9 to buffered wxFileOutputStream, then\n") );
311 textCtrl
.WriteText( _T("seeking back to #3 and writing 0:\n\n") );
313 wxFileOutputStream
file_output2( wxString(_T("test_wx2.dat")) );
314 wxBufferedOutputStream
buf_output2( file_output2
);
315 for (ch
= 0; ch
< 10; ch
++)
316 buf_output2
.Write( &ch
, 1 );
317 buf_output2
.SeekO( 3 );
319 buf_output2
.Write( &ch
, 1 );
322 wxFileInputStream
file_input2( wxString(_T("test_wx2.dat")) );
323 for (ch2
= 0; ch2
< 10; ch2
++)
325 file_input2
.Read( &ch
, 1 );
326 textCtrl
.WriteText( (wxChar
)(ch
+ _T('0')) );
328 textCtrl
.WriteText( _T("\n\n\n") );
330 // now append 2000 bytes to file (bigger than buffer)
331 buf_output2
.SeekO( 0, wxFromEnd
);
333 for (int i
= 0; i
< 2000; i
++)
334 buf_output2
.Write( &ch
, 1 );
337 textCtrl
.WriteText( _T("Reading number 0 to 9 from buffered wxFileInputStream, then\n") );
338 textCtrl
.WriteText( _T("seeking back to #3 and reading the 0:\n\n") );
340 wxFileInputStream
file_input3( wxString(_T("test_wx2.dat")) );
341 wxBufferedInputStream
buf_input3( file_input3
);
342 for (ch2
= 0; ch2
< 10; ch2
++)
344 buf_input3
.Read( &ch
, 1 );
345 textCtrl
.WriteText( (wxChar
)(ch
+ _T('0')) );
347 for (int j
= 0; j
< 2000; j
++)
348 buf_input3
.Read( &ch
, 1 );
349 textCtrl
.WriteText( _T("\n") );
350 buf_input3
.SeekI( 3 );
351 buf_input3
.Read( &ch
, 1 );
352 textCtrl
.WriteText( (wxChar
)(ch
+ _T('0')) );
353 textCtrl
.WriteText( _T("\n\n\n") );
357 void MyApp::DoStreamDemo3(wxCommandEvent
& WXUNUSED(event
))
359 wxTextCtrl
& textCtrl
= * GetTextCtrl();
362 textCtrl
<< _T("\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n");
366 textCtrl
.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream:\n\n") );
368 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
369 for (ch
= 0; ch
< 10; ch
++)
370 file_output
.Write( &ch
, 1 );
372 // Testing wxFileInputStream
374 textCtrl
.WriteText( _T("Reading 0 to 10 to wxFileInputStream:\n\n") );
376 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
377 for (ch2
= 0; ch2
< 11; ch2
++)
379 file_input
.Read( &ch
, 1 );
380 textCtrl
.WriteText( _T("Value read: ") );
381 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
382 textCtrl
.WriteText( _T("; stream.GetLastError() returns: ") );
383 switch (file_input
.GetLastError())
385 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
386 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
387 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
388 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
389 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
392 textCtrl
.WriteText( _T("\n") );
394 textCtrl
.WriteText( _T("Seeking to 0; stream.GetLastError() returns: ") );
395 file_input
.SeekI( 0 );
396 switch (file_input
.GetLastError())
398 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
399 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
400 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
401 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
402 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
404 textCtrl
.WriteText( _T("\n") );
406 file_input
.Read( &ch
, 1 );
407 textCtrl
.WriteText( _T("Value read: ") );
408 textCtrl
.WriteText( (wxChar
)(ch
+ _T('0')) );
409 textCtrl
.WriteText( _T("; stream.GetLastError() returns: ") );
410 switch (file_input
.GetLastError())
412 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
413 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
414 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
415 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
416 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
418 textCtrl
.WriteText( _T("\n\n") );
421 // Testing wxFFileInputStream
423 textCtrl
.WriteText( _T("Reading 0 to 10 to wxFFileInputStream:\n\n") );
425 wxFFileInputStream
ffile_input( wxString(_T("test_wx.dat")) );
426 for (ch2
= 0; ch2
< 11; ch2
++)
428 ffile_input
.Read( &ch
, 1 );
429 textCtrl
.WriteText( _T("Value read: ") );
430 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
431 textCtrl
.WriteText( _T("; stream.GetLastError() returns: ") );
432 switch (ffile_input
.GetLastError())
434 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
435 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
436 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
437 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
438 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
441 textCtrl
.WriteText( _T("\n") );
443 textCtrl
.WriteText( _T("Seeking to 0; stream.GetLastError() returns: ") );
444 ffile_input
.SeekI( 0 );
445 switch (ffile_input
.GetLastError())
447 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
448 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
449 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
450 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
451 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
453 textCtrl
.WriteText( _T("\n") );
455 ffile_input
.Read( &ch
, 1 );
456 textCtrl
.WriteText( _T("Value read: ") );
457 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
458 textCtrl
.WriteText( _T("; stream.GetLastError() returns: ") );
459 switch (ffile_input
.GetLastError())
461 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
462 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
463 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
464 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
465 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
467 textCtrl
.WriteText( _T("\n\n") );
469 // Testing wxFFileInputStream
471 textCtrl
.WriteText( _T("Reading 0 to 10 to buffered wxFFileInputStream:\n\n") );
473 wxFFileInputStream
ffile_input2( wxString(_T("test_wx.dat")) );
474 wxBufferedInputStream
buf_input( ffile_input2
);
475 for (ch2
= 0; ch2
< 11; ch2
++)
477 buf_input
.Read( &ch
, 1 );
478 textCtrl
.WriteText( _T("Value read: ") );
479 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
480 textCtrl
.WriteText( _T("; stream.GetLastError() returns: ") );
481 switch (buf_input
.GetLastError())
483 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
484 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
485 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
486 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
487 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
490 textCtrl
.WriteText( _T("\n") );
492 textCtrl
.WriteText( _T("Seeking to 0; stream.GetLastError() returns: ") );
493 buf_input
.SeekI( 0 );
494 switch (buf_input
.GetLastError())
496 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
497 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
498 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
499 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
500 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
502 textCtrl
.WriteText( _T("\n") );
504 buf_input
.Read( &ch
, 1 );
505 textCtrl
.WriteText( _T("Value read: ") );
506 textCtrl
.WriteText( (wxChar
)(ch
+ '0') );
507 textCtrl
.WriteText( _T("; stream.GetLastError() returns: ") );
508 switch (buf_input
.GetLastError())
510 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
511 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
512 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
513 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
514 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
518 void MyApp::DoStreamDemo4(wxCommandEvent
& WXUNUSED(event
))
520 wxTextCtrl
& textCtrl
= * GetTextCtrl();
525 textCtrl
<< _T("\nTesting wxStreamBuffer:\n\n");
527 // bigger than buffer
528 textCtrl
.WriteText( _T("Writing 2000x 1 to wxFileOutputStream.\n\n") );
530 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
531 for (int i
= 0; i
< 2000; i
++)
534 file_output
.Write( &ch
, 1 );
537 textCtrl
.WriteText( _T("Opening with a buffered wxFileInputStream:\n\n") );
539 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
540 wxBufferedInputStream
buf_input( file_input
);
542 textCtrl
.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") );
543 switch (buf_input
.GetLastError())
545 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
546 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
547 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
548 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
549 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
551 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
552 textCtrl
.WriteText( msg
);
553 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
554 textCtrl
.WriteText( msg
);
555 textCtrl
.WriteText( _T("\n\n") );
558 textCtrl
.WriteText( _T("Seeking to position 300:\n\n") );
560 buf_input
.SeekI( 300 );
562 textCtrl
.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") );
563 switch (buf_input
.GetLastError())
565 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
566 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
567 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
568 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
569 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
571 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
572 textCtrl
.WriteText( msg
);
573 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
574 textCtrl
.WriteText( msg
);
575 textCtrl
.WriteText( _T("\n\n") );
580 textCtrl
.WriteText( _T("Reading 500 bytes:\n\n") );
582 buf_input
.Read( buf
, 500 );
584 textCtrl
.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") );
585 switch (buf_input
.GetLastError())
587 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
588 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
589 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
590 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
591 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
593 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
594 textCtrl
.WriteText( msg
);
595 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
596 textCtrl
.WriteText( msg
);
597 textCtrl
.WriteText( _T("\n\n") );
599 textCtrl
.WriteText( _T("Reading another 500 bytes:\n\n") );
601 buf_input
.Read( buf
, 500 );
603 textCtrl
.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") );
604 switch (buf_input
.GetLastError())
606 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
607 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
608 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
609 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
610 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
612 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
613 textCtrl
.WriteText( msg
);
614 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
615 textCtrl
.WriteText( msg
);
616 textCtrl
.WriteText( _T("\n\n") );
618 textCtrl
.WriteText( _T("Reading another 500 bytes:\n\n") );
620 buf_input
.Read( buf
, 500 );
622 textCtrl
.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") );
623 switch (buf_input
.GetLastError())
625 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
626 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
627 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
628 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
629 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
631 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
632 textCtrl
.WriteText( msg
);
633 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
634 textCtrl
.WriteText( msg
);
635 textCtrl
.WriteText( _T("\n\n") );
637 textCtrl
.WriteText( _T("Reading another 500 bytes:\n\n") );
639 buf_input
.Read( buf
, 500 );
641 textCtrl
.WriteText( _T("wxBufferedInputStream.GetLastError() returns: ") );
642 switch (buf_input
.GetLastError())
644 case wxSTREAM_NO_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_NO_ERROR\n") ); break;
645 case wxSTREAM_EOF
: textCtrl
.WriteText( _T("wxSTREAM_EOF\n") ); break;
646 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_READ_ERROR\n") ); break;
647 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( _T("wxSTREAM_WRITE_ERROR\n") ); break;
648 default: textCtrl
.WriteText( _T("Huh?\n") ); break;
650 msg
.Printf( wxT("wxBufferedInputStream.LastRead() returns: %d\n"), (int)buf_input
.LastRead() );
651 textCtrl
.WriteText( msg
);
652 msg
.Printf( wxT("wxBufferedInputStream.TellI() returns: %d\n"), (int)buf_input
.TellI() );
653 textCtrl
.WriteText( msg
);
654 textCtrl
.WriteText( _T("\n\n") );
657 void MyApp::DoStreamDemo5(wxCommandEvent
& WXUNUSED(event
))
659 wxTextCtrl
& textCtrl
= * GetTextCtrl();
662 textCtrl
<< _T("\nTesting wxFileInputStream's Peek():\n\n");
667 textCtrl
.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream:\n\n") );
669 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
670 for (ch
= 0; ch
< 10; ch
++)
671 file_output
.Write( &ch
, 1 );
675 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
677 ch
= file_input
.Peek();
678 str
.Printf( wxT("First char peeked: %d\n"), (int) ch
);
679 textCtrl
.WriteText( str
);
681 ch
= file_input
.GetC();
682 str
.Printf( wxT("First char read: %d\n"), (int) ch
);
683 textCtrl
.WriteText( str
);
685 ch
= file_input
.Peek();
686 str
.Printf( wxT("Second char peeked: %d\n"), (int) ch
);
687 textCtrl
.WriteText( str
);
689 ch
= file_input
.GetC();
690 str
.Printf( wxT("Second char read: %d\n"), (int) ch
);
691 textCtrl
.WriteText( str
);
693 ch
= file_input
.Peek();
694 str
.Printf( wxT("Third char peeked: %d\n"), (int) ch
);
695 textCtrl
.WriteText( str
);
697 ch
= file_input
.GetC();
698 str
.Printf( wxT("Third char read: %d\n"), (int) ch
);
699 textCtrl
.WriteText( str
);
702 textCtrl
<< _T("\n\n\nTesting wxMemoryInputStream's Peek():\n\n");
704 char buf
[] = { 0,1,2,3,4,5,6,7,8,9,10 };
705 wxMemoryInputStream
input( buf
, 10 );
708 str
.Printf( wxT("First char peeked: %d\n"), (int) ch
);
709 textCtrl
.WriteText( str
);
712 str
.Printf( wxT("First char read: %d\n"), (int) ch
);
713 textCtrl
.WriteText( str
);
716 str
.Printf( wxT("Second char peeked: %d\n"), (int) ch
);
717 textCtrl
.WriteText( str
);
720 str
.Printf( wxT("Second char read: %d\n"), (int) ch
);
721 textCtrl
.WriteText( str
);
724 str
.Printf( wxT("Third char peeked: %d\n"), (int) ch
);
725 textCtrl
.WriteText( str
);
728 str
.Printf( wxT("Third char read: %d\n"), (int) ch
);
729 textCtrl
.WriteText( str
);
732 void MyApp::DoStreamDemo6(wxCommandEvent
& WXUNUSED(event
))
734 wxTextCtrl
& textCtrl
= * GetTextCtrl();
737 textCtrl
.WriteText( _T("\nTesting Ungetch():\n\n") );
743 textCtrl
.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream...\n\n") );
745 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
746 for (ch
= 0; ch
< 10; ch
++)
747 file_output
.Write( &ch
, 1 );
751 textCtrl
.WriteText( _T("Reading char from wxFileInputStream:\n\n") );
753 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
755 ch
= file_input
.GetC();
756 pos
= file_input
.TellI();
757 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
758 textCtrl
.WriteText( str
);
760 textCtrl
.WriteText( _T("Reading another char from wxFileInputStream:\n\n") );
762 ch
= file_input
.GetC();
763 pos
= file_input
.TellI();
764 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
765 textCtrl
.WriteText( str
);
767 textCtrl
.WriteText( _T("Reading yet another char from wxFileInputStream:\n\n") );
769 ch
= file_input
.GetC();
770 pos
= file_input
.TellI();
771 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
772 textCtrl
.WriteText( str
);
774 textCtrl
.WriteText( _T("Now calling Ungetch( 5 ) from wxFileInputStream...\n\n") );
776 file_input
.Ungetch( 5 );
777 pos
= file_input
.TellI();
778 str
.Printf( wxT("Now at position %d\n\n"), (int) pos
);
779 textCtrl
.WriteText( str
);
781 textCtrl
.WriteText( _T("Reading char from wxFileInputStream:\n\n") );
783 ch
= file_input
.GetC();
784 pos
= file_input
.TellI();
785 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
786 textCtrl
.WriteText( str
);
788 textCtrl
.WriteText( _T("Reading another char from wxFileInputStream:\n\n") );
790 ch
= file_input
.GetC();
791 pos
= file_input
.TellI();
792 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
793 textCtrl
.WriteText( str
);
795 textCtrl
.WriteText( _T("Now calling Ungetch( 5 ) from wxFileInputStream again...\n\n") );
797 file_input
.Ungetch( 5 );
798 pos
= file_input
.TellI();
799 str
.Printf( wxT("Now at position %d\n\n"), (int) pos
);
800 textCtrl
.WriteText( str
);
802 textCtrl
.WriteText( _T("Seeking to pos 3 in wxFileInputStream. This invalidates the writeback buffer.\n\n") );
804 file_input
.SeekI( 3 );
806 ch
= file_input
.GetC();
807 pos
= file_input
.TellI();
808 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
809 textCtrl
.WriteText( str
);
812 void MyApp::DoStreamDemo7(wxCommandEvent
& WXUNUSED(event
))
814 wxTextCtrl
& textCtrl
= * GetTextCtrl();
817 textCtrl
.WriteText( _T("\nTesting Ungetch() in buffered input stream:\n\n") );
823 textCtrl
.WriteText( _T("Writing number 0 to 9 to wxFileOutputStream...\n\n") );
825 wxFileOutputStream
file_output( wxString(_T("test_wx.dat")) );
826 for (ch
= 0; ch
< 10; ch
++)
827 file_output
.Write( &ch
, 1 );
831 textCtrl
.WriteText( _T("Reading char from wxBufferedInputStream via wxFileInputStream:\n\n") );
833 wxFileInputStream
file_input( wxString(_T("test_wx.dat")) );
834 wxBufferedInputStream
buf_input( file_input
);
836 ch
= buf_input
.GetC();
837 pos
= buf_input
.TellI();
838 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
839 textCtrl
.WriteText( str
);
841 textCtrl
.WriteText( _T("Reading another char from wxBufferedInputStream:\n\n") );
843 ch
= buf_input
.GetC();
844 pos
= buf_input
.TellI();
845 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
846 textCtrl
.WriteText( str
);
848 textCtrl
.WriteText( _T("Reading yet another char from wxBufferedInputStream:\n\n") );
850 ch
= buf_input
.GetC();
851 pos
= buf_input
.TellI();
852 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
853 textCtrl
.WriteText( str
);
855 textCtrl
.WriteText( _T("Now calling Ungetch( 5 ) from wxBufferedInputStream...\n\n") );
857 buf_input
.Ungetch( 5 );
858 pos
= buf_input
.TellI();
859 str
.Printf( wxT("Now at position %d\n\n"), (int) pos
);
860 textCtrl
.WriteText( str
);
862 textCtrl
.WriteText( _T("Reading char from wxBufferedInputStream:\n\n") );
864 ch
= buf_input
.GetC();
865 pos
= buf_input
.TellI();
866 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
867 textCtrl
.WriteText( str
);
869 textCtrl
.WriteText( _T("Reading another char from wxBufferedInputStream:\n\n") );
871 ch
= buf_input
.GetC();
872 pos
= buf_input
.TellI();
873 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
874 textCtrl
.WriteText( str
);
876 textCtrl
.WriteText( _T("Now calling Ungetch( 5 ) from wxBufferedInputStream again...\n\n") );
878 buf_input
.Ungetch( 5 );
879 pos
= buf_input
.TellI();
880 str
.Printf( wxT("Now at position %d\n\n"), (int) pos
);
881 textCtrl
.WriteText( str
);
883 textCtrl
.WriteText( _T("Seeking to pos 3 in wxBufferedInputStream. This invalidates the writeback buffer.\n\n") );
885 buf_input
.SeekI( 3 );
887 ch
= buf_input
.GetC();
888 pos
= buf_input
.TellI();
889 str
.Printf( wxT("Read char: %d. Now at position %d\n\n"), (int) ch
, (int) pos
);
890 textCtrl
.WriteText( str
);
894 void MyApp::DoUnicodeDemo(wxCommandEvent
& WXUNUSED(event
))
896 wxTextCtrl
& textCtrl
= * GetTextCtrl();
899 textCtrl
<< _T("\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:");
902 str
= _T("Robert Röbling\n");
904 printf( "\n\nConversion with wxConvLocal:\n" );
905 wxConvCurrent
= &wxConvLocal
;
906 printf( (const char*) str
.mbc_str() );
907 #if defined(__WXGTK__)
908 printf( "\n\nConversion with wxConvGdk:\n" );
909 wxConvCurrent
= &wxConvGdk
;
910 printf( (const char*) str
.mbc_str() );
912 printf( "\n\nConversion with wxConvLibc:\n" );
913 wxConvCurrent
= &wxConvLibc
;
914 printf( (const char*) str
.mbc_str() );
919 void MyApp::DoMIMEDemo(wxCommandEvent
& WXUNUSED(event
))
921 static wxString s_defaultExt
= _T("xyz");
923 wxString ext
= wxGetTextFromUser(_T("Enter a file extension: "),
924 _T("MIME database test"),
930 // init MIME database if not done yet
931 if ( !m_mimeDatabase
)
933 m_mimeDatabase
= new wxMimeTypesManager
;
935 static const wxFileTypeInfo fallbacks
[] =
937 wxFileTypeInfo(_T("application/xyz"),
940 _T("The one and only XYZ format file"),
941 _T("xyz"), _T("123"), NULL
),
942 wxFileTypeInfo(_T("text/html"),
944 _T("lynx -dump %s | lpr"),
945 _T("HTML document (from fallback)"),
946 _T("htm"), _T("html"), NULL
),
948 // must terminate the table with this!
952 m_mimeDatabase
->AddFallbacks(fallbacks
);
955 wxTextCtrl
& textCtrl
= * GetTextCtrl();
957 wxFileType
*filetype
= m_mimeDatabase
->GetFileTypeFromExtension(ext
);
960 textCtrl
<< _T("Unknown extension '") << ext
<< _T("'\n");
964 wxString type
, desc
, open
;
965 filetype
->GetMimeType(&type
);
966 filetype
->GetDescription(&desc
);
968 wxString filename
= _T("filename");
969 filename
<< _T(".") << ext
;
970 wxFileType::MessageParameters
params(filename
, type
);
971 filetype
->GetOpenCommand(&open
, params
);
973 textCtrl
<< _T("MIME information about extension '") << ext
<< _T("'\n")
974 << _T("\tMIME type: ") << ( !type
? wxT("unknown")
975 : type
.c_str() ) << '\n'
976 << _T("\tDescription: ") << ( !desc
? wxT("") : desc
.c_str() )
978 << _T("\tCommand to open: ") << ( !open
? wxT("no") : open
.c_str() )
984 //else: cancelled by user
987 void MyApp::DoByteOrderDemo(wxCommandEvent
& WXUNUSED(event
))
989 wxTextCtrl
& textCtrl
= * GetTextCtrl();
992 textCtrl
<< _T("\nTest byte order macros:\n\n");
994 if (wxBYTE_ORDER
== wxLITTLE_ENDIAN
)
995 textCtrl
<< _T("This is a little endian system.\n\n");
997 textCtrl
<< _T("This is a big endian system.\n\n");
1001 wxInt32 var
= 0xF1F2F3F4;
1003 text
.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var
);
1004 textCtrl
.WriteText( text
);
1007 text
.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var
) );
1008 textCtrl
.WriteText( text
);
1011 text
.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var
) );
1012 textCtrl
.WriteText( text
);
1015 text
.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var
) );
1016 textCtrl
.WriteText( text
);
1021 void MyApp::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
1023 wxTextCtrl
& textCtrl
= * GetTextCtrl();
1026 textCtrl
<< _T("\nTest class wxTime:\n");
1028 textCtrl
<< _T("It is now ") << (wxString
) now
<< _T("\n");
1031 void MyApp::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
1033 wxTextCtrl
& textCtrl
= * GetTextCtrl();
1036 textCtrl
<< _T("\nTest class wxDate") << _T("\n");
1038 // Various versions of the constructors
1039 // and various output
1041 wxDate
x(10,20,1962);
1043 textCtrl
<< x
.FormatDate(wxFULL
) << _T(" (full)\n");
1045 // constuctor with a string, just printing the day of the week
1046 wxDate
y(_T("8/8/1988"));
1048 textCtrl
<< y
.FormatDate(wxDAY
) << _T(" (just day)\n");
1050 // constructor with a julian
1051 wxDate
z( 2450000L );
1052 textCtrl
<< z
.FormatDate(wxFULL
) << _T(" (full)\n");
1054 // using date addition and subtraction
1056 textCtrl
<< a
.FormatDate(wxFULL
) << _T(" (full)\n");
1058 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << _T(" (European)\n");
1060 // Using subtraction of two date objects
1061 wxDate a1
= wxString(_T("7/13/1991"));
1062 wxDate a2
= a1
+ 14;
1063 textCtrl
<< (a1
-a2
) << _T("\n");
1064 textCtrl
<< (a2
+=10) << _T("\n");
1067 textCtrl
<< _T("Tomorrow= ") << a1
.FormatDate(wxFULL
) << _T("\n");
1069 wxDate
tmpDate1(_T("08/01/1991"));
1070 wxDate
tmpDate2(_T("07/14/1991"));
1071 textCtrl
<< _T("a1 (7-14-91) < 8-01-91 ? ==> ") << ((a1
< tmpDate1
) ? _T("TRUE") : _T("FALSE")) << _T("\n");
1072 textCtrl
<< _T("a1 (7-14-91) > 8-01-91 ? ==> ") << ((a1
> tmpDate1
) ? _T("TRUE") : _T("FALSE")) << _T("\n");
1073 textCtrl
<< _T("a1 (7-14-91)== 7-14-91 ? ==> ") << ((a1
==tmpDate2
) ? _T("TRUE") : _T("FALSE")) << _T("\n");
1076 textCtrl
<< _T("a1 (7-14-91)== a3 (7-14-91) ? ==> ") << ((a1
==a3
) ? _T("TRUE") : _T("FALSE")) << _T("\n");
1078 textCtrl
<< _T("a1 (7-14-91)== a4 (7-15-91) ? ==> ") << ((a1
==++a4
) ? _T("TRUE") : _T("FALSE")) << _T("\n");
1080 wxDate a5
= wxString(_T("today"));
1081 textCtrl
<< _T("Today is: ") << a5
<< _T("\n");
1083 textCtrl
<< _T("Today (a4) is: ") << a4
<< _T("\n");
1085 textCtrl
<< _T("Today + 4 is: ") << (a4
+=4) << _T("\n");
1087 textCtrl
<< _T("Today - 4 is: ") << (a4
-=4) << _T("\n");
1089 textCtrl
<< _T("=========== Leap Year Test ===========\n");
1090 a1
= _T("1/15/1992");
1091 textCtrl
<< a1
.FormatDate(wxFULL
) << _T(" ") << ((a1
.IsLeapYear()) ? _T("Leap") : _T("non-Leap"));
1092 textCtrl
<< _T(" ") << _T("day of year: ") << a1
.GetDayOfYear() << _T("\n");
1094 a1
= _T("2/16/1993");
1095 textCtrl
<< a1
.FormatDate(wxFULL
) << _T(" ") << ((a1
.IsLeapYear()) ? _T("Leap") : _T("non-Leap"));
1096 textCtrl
<< _T(" ") << _T("day of year: ") << a1
.GetDayOfYear() << _T("\n");
1098 textCtrl
<< _T("================== string assignment test ====================\n");
1099 wxString date_string
=a1
;
1100 textCtrl
<< _T("a1 as a string (s/b 2/16/1993) ==> ") << date_string
<< _T("\n");
1102 textCtrl
<< _T("================== SetFormat test ============================\n");
1103 a1
.SetFormat(wxFULL
);
1104 textCtrl
<< _T("a1 (s/b FULL format) ==> ") << a1
<< _T("\n");
1105 a1
.SetFormat(wxEUROPEAN
);
1106 textCtrl
<< _T("a1 (s/b EUROPEAN format) ==> ") << a1
<< _T("\n");
1108 textCtrl
<< _T("================== SetOption test ============================\n");
1109 textCtrl
<< _T("Date abbreviation ON\n");
1111 a1
.SetOption(wxDATE_ABBR
);
1112 a1
.SetFormat(wxMONTH
);
1113 textCtrl
<< _T("a1 (s/b MONTH format) ==> ") << a1
<< _T("\n");
1114 a1
.SetFormat(wxDAY
);
1115 textCtrl
<< _T("a1 (s/b DAY format) ==> ") << a1
<< _T("\n");
1116 a1
.SetFormat(wxFULL
);
1117 textCtrl
<< _T("a1 (s/b FULL format) ==> ") << a1
<< _T("\n");
1118 a1
.SetFormat(wxEUROPEAN
);
1119 textCtrl
<< _T("a1 (s/b EUROPEAN format) ==> ") << a1
<< _T("\n");
1120 textCtrl
<< _T("Century suppression ON\n");
1121 a1
.SetOption(wxNO_CENTURY
);
1122 a1
.SetFormat(wxMDY
);
1123 textCtrl
<< _T("a1 (s/b MDY format) ==> ") << a1
<< _T("\n");
1124 textCtrl
<< _T("Century suppression OFF\n");
1125 a1
.SetOption(wxNO_CENTURY
,FALSE
);
1126 textCtrl
<< _T("a1 (s/b MDY format) ==> ") << a1
<< _T("\n");
1127 textCtrl
<< _T("Century suppression ON\n");
1128 a1
.SetOption(wxNO_CENTURY
);
1129 textCtrl
<< _T("a1 (s/b MDY format) ==> ") << a1
<< _T("\n");
1130 a1
.SetFormat(wxFULL
);
1131 textCtrl
<< _T("a1 (s/b FULL format) ==> ") << a1
<< _T("\n");
1133 textCtrl
<< _T("\n=============== Version 4.0 Enhancement Test =================\n");
1135 wxDate
v4(_T("11/26/1966"));
1136 textCtrl
<< _T("\n---------- Set Stuff -----------\n");
1137 textCtrl
<< _T("First, 'Set' to today...") << _T("\n");
1138 textCtrl
<< _T("Before 'Set' => ") << v4
<< _T("\n");
1139 textCtrl
<< _T("After 'Set' => ") << v4
.Set() << _T("\n\n");
1141 textCtrl
<< _T("Set to 11/26/66 => ") << v4
.Set(11,26,1966) << _T("\n");
1142 textCtrl
<< _T("Current Julian => ") << v4
.GetJulianDate() << _T("\n");
1143 textCtrl
<< _T("Set to Julian 2450000L => ") << v4
.Set(2450000L) << _T("\n");
1144 textCtrl
<< _T("See! => ") << v4
.GetJulianDate() << _T("\n");
1146 textCtrl
<< _T("---------- Add Stuff -----------\n");
1147 textCtrl
<< _T("Start => ") << v4
<< _T("\n");
1148 textCtrl
<< _T("Add 4 Weeks => ") << v4
.AddWeeks(4) << _T("\n");
1149 textCtrl
<< _T("Sub 1 Month => ") << v4
.AddMonths(-1) << _T("\n");
1150 textCtrl
<< _T("Add 2 Years => ") << v4
.AddYears(2) << _T("\n");
1152 textCtrl
<< _T("---------- Misc Stuff -----------\n");
1153 textCtrl
<< _T("The date aboves' day of the month is => ") << v4
.GetDay() << _T("\n");
1154 textCtrl
<< _T("There are ") << v4
.GetDaysInMonth() << _T(" days in this month.\n");
1155 textCtrl
<< _T("The first day of this month lands on ") << v4
.GetFirstDayOfMonth() << _T("\n");
1156 textCtrl
<< _T("This day happens to be ") << v4
.GetDayOfWeekName() << _T("\n");
1157 textCtrl
<< _T("the ") << v4
.GetDayOfWeek() << _T(" day of the week,") << _T("\n");
1158 textCtrl
<< _T("on the ") << v4
.GetWeekOfYear() << _T(" week of the year,") << _T("\n");
1159 textCtrl
<< _T("on the ") << v4
.GetWeekOfMonth() << _T(" week of the month, ") << _T("\n");
1160 textCtrl
<< _T("(which is ") << v4
.GetMonthName() << _T(")\n");
1161 textCtrl
<< _T("the ")<< v4
.GetMonth() << _T("th month in the year.\n");
1162 textCtrl
<< _T("The year alone is ") << v4
.GetYear() << _T("\n");
1164 textCtrl
<< _T("---------- First and Last Stuff -----------\n");
1166 textCtrl
<< _T("The first date of this month is ") << v4
.GetMonthStart() << _T("\n");
1167 textCtrl
<< _T("The last date of this month is ") << v4
.GetMonthEnd() << _T("\n");
1168 textCtrl
<< _T("The first date of this year is ") << v4
.GetYearStart() << _T("\n");
1169 textCtrl
<< _T("The last date of this year is ") << v4
.GetYearEnd() << _T("\n");
1172 #endif // wxUSE_TIMEDATE
1174 void MyApp::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
1176 wxTextCtrl
& textCtrl
= * GetTextCtrl();
1178 wxVariant var1
= _T("String value");
1179 textCtrl
<< _T("var1 = ") << var1
.MakeString() << _T("\n");
1182 wxString str
= var1
.MakeString();
1185 textCtrl
<< _T("var1 = ") << var1
.GetReal() << _T("\n");
1187 // Implicit conversion
1191 textCtrl
<< _T("var1 = ") << var1
.GetLong() << _T("\n");
1193 // Implicit conversion
1196 // suppress compile warnings about unused variables
1202 wxStringList stringList
;
1203 stringList
.Add(_T("one")); stringList
.Add(_T("two")); stringList
.Add(_T("three"));
1205 textCtrl
<< _T("var1 = ") << var1
.MakeString() << _T("\n");
1208 var1
.Append(wxVariant(1.2345));
1209 var1
.Append(wxVariant(_T("hello")));
1210 var1
.Append(wxVariant(54321L));
1212 textCtrl
<< _T("var1 = ") << var1
.MakeString() << _T("\n");
1214 size_t n
= var1
.GetCount();
1216 for (i
= (size_t) 0; i
< n
; i
++)
1218 textCtrl
<< _T("var1[") << (int) i
<< _T("] (type ") << var1
[i
].GetType() << _T(") = ") << var1
[i
].MakeString() << _T("\n");
1222 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1223 EVT_MENU(TYPES_QUIT
, MyFrame::OnQuit
)
1224 EVT_MENU(TYPES_ABOUT
, MyFrame::OnAbout
)
1227 // My frame constructor
1228 MyFrame::MyFrame(wxFrame
*parent
, const wxString
& title
,
1229 const wxPoint
& pos
, const wxSize
& size
):
1230 wxFrame(parent
, -1, title
, pos
, size
)
1233 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
1238 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
1240 wxMessageDialog
dialog(this, _T("Tests various wxWindows types"),
1241 _T("About Types"), wxYES_NO
|wxCANCEL
);