Added tests for buffered streams.
[wxWidgets.git] / samples / typetest / typetest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: typetest.cpp
3 // Purpose: Types wxWindows sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "typetest.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/time.h"
28 #include "wx/date.h"
29 #include "wx/variant.h"
30 #include "wx/mimetype.h"
31
32 #include "typetest.h"
33
34 #if defined(__WXGTK__) || defined(__WXMOTIF__)
35 #include "mondrian.xpm"
36 #endif
37
38 #include "wx/ioswrap.h"
39
40 #if wxUSE_IOSTREAMH
41 #include <fstream.h>
42 #else
43 #include <fstream>
44 #endif
45
46 #include "wx/wfstream.h"
47 #include "wx/datstrm.h"
48 #include "wx/txtstrm.h"
49
50 // Create a new application object
51 IMPLEMENT_APP (MyApp)
52
53 IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp)
54
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)
60 #if wxUSE_UNICODE
61 EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo)
62 #endif
63 EVT_MENU(TYPES_STREAM2, MyApp::DoStreamDemo2)
64 EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo)
65 EVT_MENU(TYPES_MIME, MyApp::DoMIMEDemo)
66 END_EVENT_TABLE()
67
68 bool MyApp::OnInit()
69 {
70 // Create the main frame window
71 MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxWindows Types Demo",
72 wxPoint(50, 50), wxSize(450, 340));
73
74 // Give it an icon
75 frame->SetIcon(wxICON(mondrian));
76
77 // Make a menubar
78 wxMenu *file_menu = new wxMenu;
79
80 file_menu->Append(TYPES_ABOUT, "&About");
81 file_menu->AppendSeparator();
82 file_menu->Append(TYPES_QUIT, "E&xit\tAlt-X");
83
84 wxMenu *test_menu = new wxMenu;
85 test_menu->Append(TYPES_DATE, "&Date test");
86 test_menu->Append(TYPES_TIME, "&Time test");
87 test_menu->Append(TYPES_VARIANT, "&Variant test");
88 test_menu->Append(TYPES_BYTEORDER, "&Byteorder test");
89 #if wxUSE_UNICODE
90 test_menu->Append(TYPES_UNICODE, "&Unicode test");
91 #endif
92 test_menu->Append(TYPES_STREAM, "&Stream test");
93 test_menu->Append(TYPES_STREAM2, "&Stream seek test");
94 test_menu->AppendSeparator();
95 test_menu->Append(TYPES_MIME, "&MIME database test");
96
97 wxMenuBar *menu_bar = new wxMenuBar;
98 menu_bar->Append(file_menu, "&File");
99 menu_bar->Append(test_menu, "&Tests");
100 frame->SetMenuBar(menu_bar);
101
102 m_textCtrl = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE);
103
104 // Show the frame
105 frame->Show(TRUE);
106
107 SetTopWindow(frame);
108
109 return TRUE;
110 }
111
112 void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
113 {
114 wxTextCtrl& textCtrl = * GetTextCtrl();
115
116 textCtrl.Clear();
117 textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n");
118
119 textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
120
121 ofstream std_file_output( "test_std.dat" );
122 wxFileOutputStream file_output( "test_wx.dat" );
123 wxBufferedOutputStream buf_output( file_output );
124 wxTextOutputStream text_output( buf_output );
125
126 wxString tmp;
127 signed int si = 0xFFFFFFFF;
128 tmp.Printf( _T("Signed int: %d\n"), si );
129 textCtrl.WriteText( tmp );
130 text_output << si << "\n";
131 std_file_output << si << "\n";
132
133 unsigned int ui = 0xFFFFFFFF;
134 tmp.Printf( _T("Unsigned int: %u\n"), ui );
135 textCtrl.WriteText( tmp );
136 text_output << ui << "\n";
137 std_file_output << ui << "\n";
138
139 double d = 2.01234567890123456789;
140 tmp.Printf( _T("Double: %f\n"), d );
141 textCtrl.WriteText( tmp );
142 text_output << d << "\n";
143 std_file_output << d << "\n";
144
145 float f = (float)0.00001;
146 tmp.Printf( _T("Float: %f\n"), f );
147 textCtrl.WriteText( tmp );
148 text_output << f << "\n";
149 std_file_output << f << "\n";
150
151 wxString str( _T("Hello!") );
152 tmp.Printf( _T("String: %s\n"), str.c_str() );
153 textCtrl.WriteText( tmp );
154 text_output << str << "\n";
155 std_file_output << str.c_str() << "\n";
156
157 textCtrl.WriteText( "\nReading from ifstream:\n" );
158
159 ifstream std_file_input( "test_std.dat" );
160
161 std_file_input >> si;
162 tmp.Printf( _T("Signed int: %d\n"), si );
163 textCtrl.WriteText( tmp );
164
165 std_file_input >> ui;
166 tmp.Printf( _T("Unsigned int: %u\n"), ui );
167 textCtrl.WriteText( tmp );
168
169 std_file_input >> d;
170 tmp.Printf( _T("Double: %f\n"), d );
171 textCtrl.WriteText( tmp );
172
173 std_file_input >> f;
174 tmp.Printf( _T("Float: %f\n"), f );
175 textCtrl.WriteText( tmp );
176
177 std_file_input >> str;
178 tmp.Printf( _T("String: %s\n"), str.c_str() );
179 textCtrl.WriteText( tmp );
180
181 textCtrl.WriteText( "\nReading from wxFileInputStream:\n" );
182
183 buf_output.Sync();
184
185 wxFileInputStream file_input( "test_wx.dat" );
186 wxBufferedInputStream buf_input( file_input );
187 wxTextInputStream text_input( buf_input );
188
189 text_input >> si;
190 tmp.Printf( _T("Signed int: %d\n"), si );
191 textCtrl.WriteText( tmp );
192
193 text_input >> ui;
194 tmp.Printf( _T("Unsigned int: %u\n"), ui );
195 textCtrl.WriteText( tmp );
196
197 text_input >> d;
198 tmp.Printf( _T("Double: %f\n"), d );
199 textCtrl.WriteText( tmp );
200
201 text_input >> f;
202 tmp.Printf( _T("Float: %f\n"), f );
203 textCtrl.WriteText( tmp );
204
205 text_input >> str;
206 tmp.Printf( _T("String: %s\n"), str.c_str() );
207 textCtrl.WriteText( tmp );
208
209
210 textCtrl << "\nTest for wxDataStream:\n\n";
211
212 textCtrl.WriteText( "Writing to wxDataOutputStream:\n" );
213
214 file_output.SeekO( 0 );
215 wxDataOutputStream data_output( buf_output );
216
217 wxInt16 i16 = (short)0xFFFF;
218 tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
219 textCtrl.WriteText( tmp );
220 data_output.Write16( i16 );
221
222 wxUint16 ui16 = 0xFFFF;
223 tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
224 textCtrl.WriteText( tmp );
225 data_output.Write16( ui16 );
226
227 d = 2.01234567890123456789;
228 tmp.Printf( _T("Double: %f\n"), d );
229 textCtrl.WriteText( tmp );
230 data_output.WriteDouble( d );
231
232 str = "Hello!";
233 tmp.Printf( _T("String: %s\n"), str.c_str() );
234 textCtrl.WriteText( tmp );
235 data_output.WriteString( str );
236
237 buf_output.Sync();
238
239 textCtrl.WriteText( "\nReading from wxDataInputStream:\n" );
240
241 file_input.SeekI( 0 );
242 wxDataInputStream data_input( buf_input );
243
244 i16 = data_input.Read16();
245 tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
246 textCtrl.WriteText( tmp );
247
248 ui16 = data_input.Read16();
249 tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
250 textCtrl.WriteText( tmp );
251
252 d = data_input.ReadDouble();
253 tmp.Printf( _T("Double: %f\n"), d );
254 textCtrl.WriteText( tmp );
255
256 str = data_input.ReadString();
257 tmp.Printf( _T("String: %s\n"), str.c_str() );
258 textCtrl.WriteText( tmp );
259 }
260
261 void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event))
262 {
263 wxTextCtrl& textCtrl = * GetTextCtrl();
264
265 textCtrl.Clear();
266 textCtrl << _T("\nTest wxBufferedStream:\n\n");
267
268 char ch,ch2;
269
270 textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
271
272 wxFileOutputStream file_output( "test_wx.dat" );
273 wxBufferedOutputStream buf_output( file_output );
274 for (ch = 0; ch < 10; ch++)
275 buf_output.Write( &ch, 1 );
276 buf_output.Sync();
277
278 wxFileInputStream file_input( "test_wx.dat" );
279 for (ch2 = 0; ch2 < 10; ch2++)
280 {
281 file_input.Read( &ch, 1 );
282 textCtrl.WriteText( (char)(ch + '0') );
283 }
284 textCtrl.WriteText( "\n\n\n" );
285
286 textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
287 textCtrl.WriteText( "seeking back to #3 and writing 3:\n\n" );
288
289 wxFileOutputStream file_output2( "test_wx2.dat" );
290 wxBufferedOutputStream buf_output2( file_output2 );
291 for (ch = 0; ch < 10; ch++)
292 buf_output2.Write( &ch, 1 );
293 buf_output2.SeekO( 3 );
294 ch = 3;
295 buf_output2.Write( &ch, 1 );
296 buf_output2.Sync();
297
298 wxFileInputStream file_input2( "test_wx2.dat" );
299 for (ch2 = 0; ch2 < 10; ch2++)
300 {
301 file_input2.Read( &ch, 1 );
302 textCtrl.WriteText( (char)(ch + '0') );
303 }
304 textCtrl.WriteText( "\n\n\n" );
305
306 // now append 2000 bytes to file (bigger than buffer)
307 buf_output2.SeekO( 0, wxFromEnd );
308 ch = 1;
309 for (int i = 0; i < 2000; i++)
310 buf_output2.Write( &ch, 1 );
311 buf_output2.Sync();
312
313 textCtrl.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
314 textCtrl.WriteText( "seeking back to #3 and reading 3:\n\n" );
315
316 wxFileInputStream file_input3( "test_wx2.dat" );
317 wxBufferedInputStream buf_input3( file_input3 );
318 for (ch2 = 0; ch2 < 10; ch2++)
319 {
320 buf_input3.Read( &ch, 1 );
321 textCtrl.WriteText( (char)(ch + '0') );
322 }
323 for (int j = 0; j < 2000; j++)
324 buf_input3.Read( &ch, 1 );
325 textCtrl.WriteText( "\n" );
326 buf_input3.SeekI( 3 );
327 buf_input3.Read( &ch, 1 );
328 textCtrl.WriteText( (char)(ch + '0') );
329 textCtrl.WriteText( "\n\n\n" );
330
331 }
332
333 #if wxUSE_UNICODE
334 void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event))
335 {
336 wxTextCtrl& textCtrl = * GetTextCtrl();
337
338 textCtrl.Clear();
339 textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
340
341 wxString str;
342 str = _T("Robert Röbling\n");
343
344 printf( "\n\nConversion with wxConvLocal:\n" );
345 wxConvCurrent = &wxConvLocal;
346 printf( (const char*) str.mbc_str() );
347
348 printf( "\n\nConversion with wxConvGdk:\n" );
349 wxConvCurrent = &wxConvGdk;
350 printf( (const char*) str.mbc_str() );
351
352 printf( "\n\nConversion with wxConvLibc:\n" );
353 wxConvCurrent = &wxConvLibc;
354 printf( (const char*) str.mbc_str() );
355
356 }
357 #endif
358
359 void MyApp::DoMIMEDemo(wxCommandEvent& WXUNUSED(event))
360 {
361 static wxString s_defaultExt = "xyz";
362
363 wxString ext = wxGetTextFromUser("Enter a file extension: ",
364 "MIME database test",
365 s_defaultExt);
366 if ( !!ext )
367 {
368 s_defaultExt = ext;
369
370 // init MIME database if not done yet
371 if ( !m_mimeDatabase )
372 {
373 m_mimeDatabase = new wxMimeTypesManager;
374
375 static const wxFileTypeInfo fallbacks[] =
376 {
377 wxFileTypeInfo("application/xyz",
378 "XyZ %s",
379 "XyZ -p %s",
380 "The one and only XYZ format file",
381 "xyz", "123", NULL),
382 wxFileTypeInfo("text/html",
383 "lynx %s",
384 "lynx -dump %s | lpr",
385 "HTML document (from fallback)",
386 "htm", "html", NULL),
387
388 // must terminate the table with this!
389 wxFileTypeInfo()
390 };
391
392 m_mimeDatabase->AddFallbacks(fallbacks);
393 }
394
395 wxTextCtrl& textCtrl = * GetTextCtrl();
396
397 wxFileType *filetype = m_mimeDatabase->GetFileTypeFromExtension(ext);
398 if ( !filetype )
399 {
400 textCtrl << "Unknown extension '" << ext << "'\n";
401 }
402 else
403 {
404 wxString type, desc, open;
405 filetype->GetMimeType(&type);
406 filetype->GetDescription(&desc);
407
408 wxString filename = "filename";
409 filename << "." << ext;
410 wxFileType::MessageParameters params(filename, type);
411 filetype->GetOpenCommand(&open, params);
412
413 textCtrl << "MIME information about extension '" << ext << "'\n"
414 << "\tMIME type: " << ( !type ? "unknown"
415 : type.c_str() ) << '\n'
416 << "\tDescription: " << ( !desc ? "" : desc.c_str() )
417 << '\n'
418 << "\tCommand to open: " << ( !open ? "no" : open.c_str() )
419 << '\n';
420
421 delete filetype;
422 }
423 }
424 //else: cancelled by user
425 }
426
427 void MyApp::DoByteOrderDemo(wxCommandEvent& WXUNUSED(event))
428 {
429 wxTextCtrl& textCtrl = * GetTextCtrl();
430
431 textCtrl.Clear();
432 textCtrl << "\nTest byte order macros:\n\n";
433
434 if (wxBYTE_ORDER == wxLITTLE_ENDIAN)
435 textCtrl << "This is a little endian system.\n\n";
436 else
437 textCtrl << "This is a big endian system.\n\n";
438
439 wxString text;
440
441 wxInt32 var = 0xF1F2F3F4;
442 text = "";
443 text.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var );
444 textCtrl.WriteText( text );
445
446 text = "";
447 text.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var ) );
448 textCtrl.WriteText( text );
449
450 text = "";
451 text.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var ) );
452 textCtrl.WriteText( text );
453
454 text = "";
455 text.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var ) );
456 textCtrl.WriteText( text );
457 }
458
459 void MyApp::DoTimeDemo(wxCommandEvent& WXUNUSED(event))
460 {
461 wxTextCtrl& textCtrl = * GetTextCtrl();
462
463 textCtrl.Clear();
464 textCtrl << "\nTest class wxTime:\n";
465 wxTime now;
466 textCtrl << "It is now " << (wxString) now << "\n";
467 }
468
469 void MyApp::DoDateDemo(wxCommandEvent& WXUNUSED(event))
470 {
471 wxTextCtrl& textCtrl = * GetTextCtrl();
472
473 textCtrl.Clear();
474 textCtrl << "\nTest class wxDate" << "\n";
475
476 // Various versions of the constructors
477 // and various output
478
479 wxDate x(10,20,1962);
480
481 textCtrl << x.FormatDate(wxFULL) << " (full)\n";
482
483 // constuctor with a string, just printing the day of the week
484 wxDate y("8/8/1988");
485
486 textCtrl << y.FormatDate(wxDAY) << " (just day)\n";
487
488 // constructor with a julian
489 wxDate z( 2450000L );
490 textCtrl << z.FormatDate(wxFULL) << " (full)\n";
491
492 // using date addition and subtraction
493 wxDate a = x + 10;
494 textCtrl << a.FormatDate(wxFULL) << " (full)\n";
495 a = a - 25;
496 textCtrl << a.FormatDate(wxEUROPEAN) << " (European)\n";
497
498 // Using subtraction of two date objects
499 wxDate a1 = wxString("7/13/1991");
500 wxDate a2 = a1 + 14;
501 textCtrl << (a1-a2) << "\n";
502 textCtrl << (a2+=10) << "\n";
503
504 a1++;
505 textCtrl << "Tomorrow= " << a1.FormatDate(wxFULL) << "\n";
506
507 wxDate tmpDate1("08/01/1991");
508 wxDate tmpDate2("07/14/1991");
509 textCtrl << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < tmpDate1) ? "TRUE" : "FALSE") << "\n";
510 textCtrl << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > tmpDate1) ? "TRUE" : "FALSE") << "\n";
511 textCtrl << "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1==tmpDate2) ? "TRUE" : "FALSE") << "\n";
512
513 wxDate a3 = a1;
514 textCtrl << "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << "\n";
515 wxDate a4 = a1;
516 textCtrl << "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1==++a4) ? "TRUE" : "FALSE") << "\n";
517
518 wxDate a5 = wxString("today");
519 textCtrl << "Today is: " << a5 << "\n";
520 a4 = "TODAY";
521 textCtrl << "Today (a4) is: " << a4 << "\n";
522
523 textCtrl << "Today + 4 is: " << (a4+=4) << "\n";
524 a4 = "TODAY";
525 textCtrl << "Today - 4 is: " << (a4-=4) << "\n";
526
527 textCtrl << "=========== Leap Year Test ===========\n";
528 a1 = "1/15/1992";
529 textCtrl << a1.FormatDate(wxFULL) << " " << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
530 textCtrl << " " << "day of year: " << a1.GetDayOfYear() << "\n";
531
532 a1 = "2/16/1993";
533 textCtrl << a1.FormatDate(wxFULL) << " " << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
534 textCtrl << " " << "day of year: " << a1.GetDayOfYear() << "\n";
535
536 textCtrl << "================== string assignment test ====================\n";
537 wxString date_string=a1;
538 textCtrl << "a1 as a string (s/b 2/16/1993) ==> " << date_string << "\n";
539
540 textCtrl << "================== SetFormat test ============================\n";
541 a1.SetFormat(wxFULL);
542 textCtrl << "a1 (s/b FULL format) ==> " << a1 << "\n";
543 a1.SetFormat(wxEUROPEAN);
544 textCtrl << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
545
546 textCtrl << "================== SetOption test ============================\n";
547 textCtrl << "Date abbreviation ON\n";
548
549 a1.SetOption(wxDATE_ABBR);
550 a1.SetFormat(wxMONTH);
551 textCtrl << "a1 (s/b MONTH format) ==> " << a1 << "\n";
552 a1.SetFormat(wxDAY);
553 textCtrl << "a1 (s/b DAY format) ==> " << a1 << "\n";
554 a1.SetFormat(wxFULL);
555 textCtrl << "a1 (s/b FULL format) ==> " << a1 << "\n";
556 a1.SetFormat(wxEUROPEAN);
557 textCtrl << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
558 textCtrl << "Century suppression ON\n";
559 a1.SetOption(wxNO_CENTURY);
560 a1.SetFormat(wxMDY);
561 textCtrl << "a1 (s/b MDY format) ==> " << a1 << "\n";
562 textCtrl << "Century suppression OFF\n";
563 a1.SetOption(wxNO_CENTURY,FALSE);
564 textCtrl << "a1 (s/b MDY format) ==> " << a1 << "\n";
565 textCtrl << "Century suppression ON\n";
566 a1.SetOption(wxNO_CENTURY);
567 textCtrl << "a1 (s/b MDY format) ==> " << a1 << "\n";
568 a1.SetFormat(wxFULL);
569 textCtrl << "a1 (s/b FULL format) ==> " << a1 << "\n";
570
571 textCtrl << "\n=============== Version 4.0 Enhancement Test =================\n";
572
573 wxDate v4("11/26/1966");
574 textCtrl << "\n---------- Set Stuff -----------\n";
575 textCtrl << "First, 'Set' to today..." << "\n";
576 textCtrl << "Before 'Set' => " << v4 << "\n";
577 textCtrl << "After 'Set' => " << v4.Set() << "\n\n";
578
579 textCtrl << "Set to 11/26/66 => " << v4.Set(11,26,1966) << "\n";
580 textCtrl << "Current Julian => " << v4.GetJulianDate() << "\n";
581 textCtrl << "Set to Julian 2450000L => " << v4.Set(2450000L) << "\n";
582 textCtrl << "See! => " << v4.GetJulianDate() << "\n";
583
584 textCtrl << "---------- Add Stuff -----------\n";
585 textCtrl << "Start => " << v4 << "\n";
586 textCtrl << "Add 4 Weeks => " << v4.AddWeeks(4) << "\n";
587 textCtrl << "Sub 1 Month => " << v4.AddMonths(-1) << "\n";
588 textCtrl << "Add 2 Years => " << v4.AddYears(2) << "\n";
589
590 textCtrl << "---------- Misc Stuff -----------\n";
591 textCtrl << "The date aboves' day of the month is => " << v4.GetDay() << "\n";
592 textCtrl << "There are " << v4.GetDaysInMonth() << " days in this month.\n";
593 textCtrl << "The first day of this month lands on " << v4.GetFirstDayOfMonth() << "\n";
594 textCtrl << "This day happens to be " << v4.GetDayOfWeekName() << "\n";
595 textCtrl << "the " << v4.GetDayOfWeek() << " day of the week," << "\n";
596 textCtrl << "on the " << v4.GetWeekOfYear() << " week of the year," << "\n";
597 textCtrl << "on the " << v4.GetWeekOfMonth() << " week of the month, " << "\n";
598 textCtrl << "(which is " << v4.GetMonthName() << ")\n";
599 textCtrl << "the "<< v4.GetMonth() << "th month in the year.\n";
600 textCtrl << "The year alone is " << v4.GetYear() << "\n";
601
602 textCtrl << "---------- First and Last Stuff -----------\n";
603 v4.Set();
604 textCtrl << "The first date of this month is " << v4.GetMonthStart() << "\n";
605 textCtrl << "The last date of this month is " << v4.GetMonthEnd() << "\n";
606 textCtrl << "The first date of this year is " << v4.GetYearStart() << "\n";
607 textCtrl << "The last date of this year is " << v4.GetYearEnd() << "\n";
608 }
609
610 void MyApp::DoVariantDemo(wxCommandEvent& WXUNUSED(event) )
611 {
612 wxTextCtrl& textCtrl = * GetTextCtrl();
613
614 wxVariant var1 = "String value";
615 textCtrl << "var1 = " << var1.MakeString() << "\n";
616
617 // Conversion
618 wxString str = var1.MakeString();
619
620 var1 = 123.456;
621 textCtrl << "var1 = " << var1.GetReal() << "\n";
622
623 // Implicit conversion
624 double v = var1;
625
626 var1 = 9876L;
627 textCtrl << "var1 = " << var1.GetLong() << "\n";
628
629 // Implicit conversion
630 long l = var1;
631
632 // suppress compile warnings about unused variables
633 if ( l < v )
634 {
635 ;
636 }
637
638 wxStringList stringList;
639 stringList.Add(_T("one")); stringList.Add(_T("two")); stringList.Add(_T("three"));
640 var1 = stringList;
641 textCtrl << "var1 = " << var1.MakeString() << "\n";
642
643 var1.ClearList();
644 var1.Append(wxVariant(1.2345));
645 var1.Append(wxVariant("hello"));
646 var1.Append(wxVariant(54321L));
647
648 textCtrl << "var1 = " << var1.MakeString() << "\n";
649
650 size_t n = var1.GetCount();
651 size_t i;
652 for (i = (size_t) 0; i < n; i++)
653 {
654 textCtrl << "var1[" << (int) i << "] (type " << var1[i].GetType() << ") = " << var1[i].MakeString() << "\n";
655 }
656 }
657
658 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
659 EVT_MENU(TYPES_QUIT, MyFrame::OnQuit)
660 EVT_MENU(TYPES_ABOUT, MyFrame::OnAbout)
661 END_EVENT_TABLE()
662
663 // My frame constructor
664 MyFrame::MyFrame(wxFrame *parent, const wxString& title,
665 const wxPoint& pos, const wxSize& size):
666 wxFrame(parent, -1, title, pos, size)
667 {}
668
669 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
670 {
671 Close(TRUE);
672 }
673
674 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
675 {
676 wxMessageDialog dialog(this, "Tests various wxWindows types",
677 "About Types", wxYES_NO|wxCANCEL);
678
679 dialog.ShowModal();
680 }
681
682