1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Types wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "typetest.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/variant.h"
30 #include "wx/mimetype.h"
34 #if defined(__WXGTK__) || defined(__WXMOTIF__)
35 #include "mondrian.xpm"
38 #include "wx/ioswrap.h"
46 #include "wx/wfstream.h"
47 #include "wx/datstrm.h"
48 #include "wx/txtstrm.h"
50 // Create a new application object
53 IMPLEMENT_DYNAMIC_CLASS (MyApp
, wxApp
)
55 BEGIN_EVENT_TABLE(MyApp
, wxApp
)
56 EVT_MENU(TYPES_DATE
, MyApp
::DoDateDemo
)
57 EVT_MENU(TYPES_TIME
, MyApp
::DoTimeDemo
)
58 EVT_MENU(TYPES_VARIANT
, MyApp
::DoVariantDemo
)
59 EVT_MENU(TYPES_BYTEORDER
, MyApp
::DoByteOrderDemo
)
61 EVT_MENU(TYPES_UNICODE
, MyApp
::DoUnicodeDemo
)
63 EVT_MENU(TYPES_STREAM
, MyApp
::DoStreamDemo
)
64 EVT_MENU(TYPES_STREAM2
, MyApp
::DoStreamDemo2
)
65 EVT_MENU(TYPES_STREAM3
, MyApp
::DoStreamDemo3
)
66 EVT_MENU(TYPES_MIME
, MyApp
::DoMIMEDemo
)
71 // Create the main frame window
72 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "wxWindows Types Demo",
73 wxPoint(50, 50), wxSize(450, 340));
76 frame
->SetIcon(wxICON(mondrian
));
79 wxMenu
*file_menu
= new wxMenu
;
81 file_menu
->Append(TYPES_ABOUT
, "&About");
82 file_menu
->AppendSeparator();
83 file_menu
->Append(TYPES_QUIT
, "E&xit\tAlt-X");
85 wxMenu
*test_menu
= new wxMenu
;
86 test_menu
->Append(TYPES_DATE
, "&Date test");
87 test_menu
->Append(TYPES_TIME
, "&Time test");
88 test_menu
->Append(TYPES_VARIANT
, "&Variant test");
89 test_menu
->Append(TYPES_BYTEORDER
, "&Byteorder test");
91 test_menu
->Append(TYPES_UNICODE
, "&Unicode test");
93 test_menu
->Append(TYPES_STREAM
, "&Stream test");
94 test_menu
->Append(TYPES_STREAM2
, "&Stream seek test");
95 test_menu
->Append(TYPES_STREAM3
, "&Stream error test");
96 test_menu
->AppendSeparator();
97 test_menu
->Append(TYPES_MIME
, "&MIME database test");
99 wxMenuBar
*menu_bar
= new wxMenuBar
;
100 menu_bar
->Append(file_menu
, "&File");
101 menu_bar
->Append(test_menu
, "&Tests");
102 frame
->SetMenuBar(menu_bar
);
104 m_textCtrl
= new wxTextCtrl(frame
, -1, "", wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
114 void MyApp
::DoStreamDemo(wxCommandEvent
& WXUNUSED(event
))
116 wxTextCtrl
& textCtrl
= * GetTextCtrl();
119 textCtrl
<< _T("\nTest fstream vs. wxFileStream:\n\n");
121 textCtrl
.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
123 ofstream
std_file_output( "test_std.dat" );
124 wxFileOutputStream
file_output( "test_wx.dat" );
125 wxBufferedOutputStream
buf_output( file_output
);
126 wxTextOutputStream
text_output( buf_output
);
129 signed int si
= 0xFFFFFFFF;
130 tmp
.Printf( _T("Signed int: %d\n"), si
);
131 textCtrl
.WriteText( tmp
);
132 text_output
<< si
<< "\n";
133 std_file_output
<< si
<< "\n";
135 unsigned int ui
= 0xFFFFFFFF;
136 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
137 textCtrl
.WriteText( tmp
);
138 text_output
<< ui
<< "\n";
139 std_file_output
<< ui
<< "\n";
141 double d
= 2.01234567890123456789;
142 tmp
.Printf( _T("Double: %f\n"), d
);
143 textCtrl
.WriteText( tmp
);
144 text_output
<< d
<< "\n";
145 std_file_output
<< d
<< "\n";
147 float f
= (float)0.00001;
148 tmp
.Printf( _T("Float: %f\n"), f
);
149 textCtrl
.WriteText( tmp
);
150 text_output
<< f
<< "\n";
151 std_file_output
<< f
<< "\n";
153 wxString
str( _T("Hello!") );
154 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
155 textCtrl
.WriteText( tmp
);
156 text_output
<< str
<< "\n";
157 std_file_output
<< str
.c_str() << "\n";
159 textCtrl
.WriteText( "\nReading from ifstream:\n" );
161 ifstream
std_file_input( "test_std.dat" );
163 std_file_input
>> si
;
164 tmp
.Printf( _T("Signed int: %d\n"), si
);
165 textCtrl
.WriteText( tmp
);
167 std_file_input
>> ui
;
168 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
169 textCtrl
.WriteText( tmp
);
172 tmp
.Printf( _T("Double: %f\n"), d
);
173 textCtrl
.WriteText( tmp
);
176 tmp
.Printf( _T("Float: %f\n"), f
);
177 textCtrl
.WriteText( tmp
);
179 std_file_input
>> str
;
180 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
181 textCtrl
.WriteText( tmp
);
183 textCtrl
.WriteText( "\nReading from wxFileInputStream:\n" );
187 wxFileInputStream
file_input( "test_wx.dat" );
188 wxBufferedInputStream
buf_input( file_input
);
189 wxTextInputStream
text_input( buf_input
);
192 tmp
.Printf( _T("Signed int: %d\n"), si
);
193 textCtrl
.WriteText( tmp
);
196 tmp
.Printf( _T("Unsigned int: %u\n"), ui
);
197 textCtrl
.WriteText( tmp
);
200 tmp
.Printf( _T("Double: %f\n"), d
);
201 textCtrl
.WriteText( tmp
);
204 tmp
.Printf( _T("Float: %f\n"), f
);
205 textCtrl
.WriteText( tmp
);
208 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
209 textCtrl
.WriteText( tmp
);
212 textCtrl
<< "\nTest for wxDataStream:\n\n";
214 textCtrl
.WriteText( "Writing to wxDataOutputStream:\n" );
216 file_output
.SeekO( 0 );
217 wxDataOutputStream
data_output( buf_output
);
219 wxInt16 i16
= (short)0xFFFF;
220 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
221 textCtrl
.WriteText( tmp
);
222 data_output
.Write16( i16
);
224 wxUint16 ui16
= 0xFFFF;
225 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
226 textCtrl
.WriteText( tmp
);
227 data_output
.Write16( ui16
);
229 d
= 2.01234567890123456789;
230 tmp
.Printf( _T("Double: %f\n"), d
);
231 textCtrl
.WriteText( tmp
);
232 data_output
.WriteDouble( d
);
235 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
236 textCtrl
.WriteText( tmp
);
237 data_output
.WriteString( str
);
241 textCtrl
.WriteText( "\nReading from wxDataInputStream:\n" );
243 file_input
.SeekI( 0 );
244 wxDataInputStream
data_input( buf_input
);
246 i16
= data_input
.Read16();
247 tmp
.Printf( _T("Signed int16: %d\n"), (int)i16
);
248 textCtrl
.WriteText( tmp
);
250 ui16
= data_input
.Read16();
251 tmp
.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16
);
252 textCtrl
.WriteText( tmp
);
254 d
= data_input
.ReadDouble();
255 tmp
.Printf( _T("Double: %f\n"), d
);
256 textCtrl
.WriteText( tmp
);
258 str
= data_input
.ReadString();
259 tmp
.Printf( _T("String: %s\n"), str
.c_str() );
260 textCtrl
.WriteText( tmp
);
263 void MyApp
::DoStreamDemo2(wxCommandEvent
& WXUNUSED(event
))
265 wxTextCtrl
& textCtrl
= * GetTextCtrl();
268 textCtrl
<< _T("\nTesting wxBufferedStream:\n\n");
272 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
274 wxFileOutputStream
file_output( "test_wx.dat" );
275 wxBufferedOutputStream
buf_output( file_output
);
276 for (ch
= 0; ch
< 10; ch
++)
277 buf_output
.Write( &ch
, 1 );
280 wxFileInputStream
file_input( "test_wx.dat" );
281 for (ch2
= 0; ch2
< 10; ch2
++)
283 file_input
.Read( &ch
, 1 );
284 textCtrl
.WriteText( (char)(ch
+ '0') );
286 textCtrl
.WriteText( "\n\n\n" );
288 textCtrl
.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
289 textCtrl
.WriteText( "seeking back to #3 and writing 3:\n\n" );
291 wxFileOutputStream
file_output2( "test_wx2.dat" );
292 wxBufferedOutputStream
buf_output2( file_output2
);
293 for (ch
= 0; ch
< 10; ch
++)
294 buf_output2
.Write( &ch
, 1 );
295 buf_output2
.SeekO( 3 );
297 buf_output2
.Write( &ch
, 1 );
300 wxFileInputStream
file_input2( "test_wx2.dat" );
301 for (ch2
= 0; ch2
< 10; ch2
++)
303 file_input2
.Read( &ch
, 1 );
304 textCtrl
.WriteText( (char)(ch
+ '0') );
306 textCtrl
.WriteText( "\n\n\n" );
308 // now append 2000 bytes to file (bigger than buffer)
309 buf_output2
.SeekO( 0, wxFromEnd
);
311 for (int i
= 0; i
< 2000; i
++)
312 buf_output2
.Write( &ch
, 1 );
315 textCtrl
.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
316 textCtrl
.WriteText( "seeking back to #3 and reading 3:\n\n" );
318 wxFileInputStream
file_input3( "test_wx2.dat" );
319 wxBufferedInputStream
buf_input3( file_input3
);
320 for (ch2
= 0; ch2
< 10; ch2
++)
322 buf_input3
.Read( &ch
, 1 );
323 textCtrl
.WriteText( (char)(ch
+ '0') );
325 for (int j
= 0; j
< 2000; j
++)
326 buf_input3
.Read( &ch
, 1 );
327 textCtrl
.WriteText( "\n" );
328 buf_input3
.SeekI( 3 );
329 buf_input3
.Read( &ch
, 1 );
330 textCtrl
.WriteText( (char)(ch
+ '0') );
331 textCtrl
.WriteText( "\n\n\n" );
335 void MyApp
::DoStreamDemo3(wxCommandEvent
& WXUNUSED(event
))
337 wxTextCtrl
& textCtrl
= * GetTextCtrl();
340 textCtrl
<< "\nTesting wxFileInputStream's and wxFFileInputStream's error handling:\n\n";
344 textCtrl
.WriteText( "Writing number 0 to 9 to wxFileOutputStream:\n\n" );
346 wxFileOutputStream
file_output( "test_wx.dat" );
347 for (ch
= 0; ch
< 10; ch
++)
348 file_output
.Write( &ch
, 1 );
350 // Testing wxFileInoutStream
352 textCtrl
.WriteText( "Reading 0 to 10 to wxFileInputStream:\n\n" );
354 wxFileInputStream
file_input( "test_wx.dat" );
355 for (ch2
= 0; ch2
< 11; ch2
++)
357 file_input
.Read( &ch
, 1 );
358 textCtrl
.WriteText( "Value read: " );
359 textCtrl
.WriteText( (char)(ch
+ '0') );
360 textCtrl
.WriteText( "; stream.LastError() returns: " );
361 switch (file_input
.LastError())
363 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
364 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
365 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
366 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
367 default: textCtrl
.WriteText( "Huh?\n" ); break;
370 textCtrl
.WriteText( "\n" );
372 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
373 file_input
.SeekI( 0 );
374 switch (file_input
.LastError())
376 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
377 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
378 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
379 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
380 default: textCtrl
.WriteText( "Huh?\n" ); break;
382 textCtrl
.WriteText( "\n" );
384 file_input
.Read( &ch
, 1 );
385 textCtrl
.WriteText( "Value read: " );
386 textCtrl
.WriteText( (char)(ch
+ '0') );
387 textCtrl
.WriteText( "; stream.LastError() returns: " );
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\n" );
399 // Testing wxFFileInoutStream
401 textCtrl
.WriteText( "Reading 0 to 10 to wxFFileInputStream:\n\n" );
403 wxFFileInputStream
ffile_input( "test_wx.dat" );
404 for (ch2
= 0; ch2
< 11; ch2
++)
406 ffile_input
.Read( &ch
, 1 );
407 textCtrl
.WriteText( "Value read: " );
408 textCtrl
.WriteText( (char)(ch
+ '0') );
409 textCtrl
.WriteText( "; stream.LastError() returns: " );
410 switch (ffile_input
.LastError())
412 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
413 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
414 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
415 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
416 default: textCtrl
.WriteText( "Huh?\n" ); break;
419 textCtrl
.WriteText( "\n" );
421 textCtrl
.WriteText( "Seeking to 0; stream.LastError() returns: " );
422 ffile_input
.SeekI( 0 );
423 switch (ffile_input
.LastError())
425 case wxSTREAM_NOERROR
: textCtrl
.WriteText( "wxSTREAM_NOERROR\n" ); break;
426 case wxSTREAM_EOF
: textCtrl
.WriteText( "wxSTREAM_EOF\n" ); break;
427 case wxSTREAM_READ_ERROR
: textCtrl
.WriteText( "wxSTREAM_READ_ERROR\n" ); break;
428 case wxSTREAM_WRITE_ERROR
: textCtrl
.WriteText( "wxSTREAM_WRITE_ERROR\n" ); break;
429 default: textCtrl
.WriteText( "Huh?\n" ); break;
431 textCtrl
.WriteText( "\n" );
433 ffile_input
.Read( &ch
, 1 );
434 textCtrl
.WriteText( "Value read: " );
435 textCtrl
.WriteText( (char)(ch
+ '0') );
436 textCtrl
.WriteText( "; stream.LastError() returns: " );
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;
449 void MyApp
::DoUnicodeDemo(wxCommandEvent
& WXUNUSED(event
))
451 wxTextCtrl
& textCtrl
= * GetTextCtrl();
454 textCtrl
<< "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
457 str
= _T("Robert Röbling\n");
459 printf( "\n\nConversion with wxConvLocal:\n" );
460 wxConvCurrent
= &wxConvLocal
;
461 printf( (const char*) str
.mbc_str() );
463 printf( "\n\nConversion with wxConvGdk:\n" );
464 wxConvCurrent
= &wxConvGdk
;
465 printf( (const char*) str
.mbc_str() );
467 printf( "\n\nConversion with wxConvLibc:\n" );
468 wxConvCurrent
= &wxConvLibc
;
469 printf( (const char*) str
.mbc_str() );
474 void MyApp
::DoMIMEDemo(wxCommandEvent
& WXUNUSED(event
))
476 static wxString s_defaultExt
= "xyz";
478 wxString ext
= wxGetTextFromUser("Enter a file extension: ",
479 "MIME database test",
485 // init MIME database if not done yet
486 if ( !m_mimeDatabase
)
488 m_mimeDatabase
= new wxMimeTypesManager
;
490 static const wxFileTypeInfo fallbacks
[] =
492 wxFileTypeInfo("application/xyz",
495 "The one and only XYZ format file",
497 wxFileTypeInfo("text/html",
499 "lynx -dump %s | lpr",
500 "HTML document (from fallback)",
501 "htm", "html", NULL
),
503 // must terminate the table with this!
507 m_mimeDatabase
->AddFallbacks(fallbacks
);
510 wxTextCtrl
& textCtrl
= * GetTextCtrl();
512 wxFileType
*filetype
= m_mimeDatabase
->GetFileTypeFromExtension(ext
);
515 textCtrl
<< "Unknown extension '" << ext
<< "'\n";
519 wxString type
, desc
, open
;
520 filetype
->GetMimeType(&type
);
521 filetype
->GetDescription(&desc
);
523 wxString filename
= "filename";
524 filename
<< "." << ext
;
525 wxFileType
::MessageParameters
params(filename
, type
);
526 filetype
->GetOpenCommand(&open
, params
);
528 textCtrl
<< "MIME information about extension '" << ext
<< "'\n"
529 << "\tMIME type: " << ( !type ?
"unknown"
530 : type
.c_str() ) << '\n'
531 << "\tDescription: " << ( !desc ?
"" : desc
.c_str() )
533 << "\tCommand to open: " << ( !open ?
"no" : open
.c_str() )
539 //else: cancelled by user
542 void MyApp
::DoByteOrderDemo(wxCommandEvent
& WXUNUSED(event
))
544 wxTextCtrl
& textCtrl
= * GetTextCtrl();
547 textCtrl
<< "\nTest byte order macros:\n\n";
549 if (wxBYTE_ORDER
== wxLITTLE_ENDIAN
)
550 textCtrl
<< "This is a little endian system.\n\n";
552 textCtrl
<< "This is a big endian system.\n\n";
556 wxInt32 var
= 0xF1F2F3F4;
558 text
.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var
);
559 textCtrl
.WriteText( text
);
562 text
.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var
) );
563 textCtrl
.WriteText( text
);
566 text
.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var
) );
567 textCtrl
.WriteText( text
);
570 text
.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var
) );
571 textCtrl
.WriteText( text
);
574 void MyApp
::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
576 wxTextCtrl
& textCtrl
= * GetTextCtrl();
579 textCtrl
<< "\nTest class wxTime:\n";
581 textCtrl
<< "It is now " << (wxString
) now
<< "\n";
584 void MyApp
::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
586 wxTextCtrl
& textCtrl
= * GetTextCtrl();
589 textCtrl
<< "\nTest class wxDate" << "\n";
591 // Various versions of the constructors
592 // and various output
594 wxDate
x(10,20,1962);
596 textCtrl
<< x
.FormatDate(wxFULL
) << " (full)\n";
598 // constuctor with a string, just printing the day of the week
599 wxDate
y("8/8/1988");
601 textCtrl
<< y
.FormatDate(wxDAY
) << " (just day)\n";
603 // constructor with a julian
604 wxDate
z( 2450000L );
605 textCtrl
<< z
.FormatDate(wxFULL
) << " (full)\n";
607 // using date addition and subtraction
609 textCtrl
<< a
.FormatDate(wxFULL
) << " (full)\n";
611 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << " (European)\n";
613 // Using subtraction of two date objects
614 wxDate a1
= wxString("7/13/1991");
616 textCtrl
<< (a1
-a2
) << "\n";
617 textCtrl
<< (a2
+=10) << "\n";
620 textCtrl
<< "Tomorrow= " << a1
.FormatDate(wxFULL
) << "\n";
622 wxDate
tmpDate1("08/01/1991");
623 wxDate
tmpDate2("07/14/1991");
624 textCtrl
<< "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1
< tmpDate1
) ?
"TRUE" : "FALSE") << "\n";
625 textCtrl
<< "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1
> tmpDate1
) ?
"TRUE" : "FALSE") << "\n";
626 textCtrl
<< "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1
==tmpDate2
) ?
"TRUE" : "FALSE") << "\n";
629 textCtrl
<< "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1
==a3
) ?
"TRUE" : "FALSE") << "\n";
631 textCtrl
<< "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1
==++a4
) ?
"TRUE" : "FALSE") << "\n";
633 wxDate a5
= wxString("today");
634 textCtrl
<< "Today is: " << a5
<< "\n";
636 textCtrl
<< "Today (a4) is: " << a4
<< "\n";
638 textCtrl
<< "Today + 4 is: " << (a4
+=4) << "\n";
640 textCtrl
<< "Today - 4 is: " << (a4
-=4) << "\n";
642 textCtrl
<< "=========== Leap Year Test ===========\n";
644 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ?
"Leap" : "non-Leap");
645 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
648 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ?
"Leap" : "non-Leap");
649 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
651 textCtrl
<< "================== string assignment test ====================\n";
652 wxString date_string
=a1
;
653 textCtrl
<< "a1 as a string (s/b 2/16/1993) ==> " << date_string
<< "\n";
655 textCtrl
<< "================== SetFormat test ============================\n";
656 a1
.SetFormat(wxFULL
);
657 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
658 a1
.SetFormat(wxEUROPEAN
);
659 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
661 textCtrl
<< "================== SetOption test ============================\n";
662 textCtrl
<< "Date abbreviation ON\n";
664 a1
.SetOption(wxDATE_ABBR
);
665 a1
.SetFormat(wxMONTH
);
666 textCtrl
<< "a1 (s/b MONTH format) ==> " << a1
<< "\n";
668 textCtrl
<< "a1 (s/b DAY format) ==> " << a1
<< "\n";
669 a1
.SetFormat(wxFULL
);
670 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
671 a1
.SetFormat(wxEUROPEAN
);
672 textCtrl
<< "a1 (s/b EUROPEAN format) ==> " << a1
<< "\n";
673 textCtrl
<< "Century suppression ON\n";
674 a1
.SetOption(wxNO_CENTURY
);
676 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
677 textCtrl
<< "Century suppression OFF\n";
678 a1
.SetOption(wxNO_CENTURY
,FALSE
);
679 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
680 textCtrl
<< "Century suppression ON\n";
681 a1
.SetOption(wxNO_CENTURY
);
682 textCtrl
<< "a1 (s/b MDY format) ==> " << a1
<< "\n";
683 a1
.SetFormat(wxFULL
);
684 textCtrl
<< "a1 (s/b FULL format) ==> " << a1
<< "\n";
686 textCtrl
<< "\n=============== Version 4.0 Enhancement Test =================\n";
688 wxDate
v4("11/26/1966");
689 textCtrl
<< "\n---------- Set Stuff -----------\n";
690 textCtrl
<< "First, 'Set' to today..." << "\n";
691 textCtrl
<< "Before 'Set' => " << v4
<< "\n";
692 textCtrl
<< "After 'Set' => " << v4
.Set() << "\n\n";
694 textCtrl
<< "Set to 11/26/66 => " << v4
.Set(11,26,1966) << "\n";
695 textCtrl
<< "Current Julian => " << v4
.GetJulianDate() << "\n";
696 textCtrl
<< "Set to Julian 2450000L => " << v4
.Set(2450000L) << "\n";
697 textCtrl
<< "See! => " << v4
.GetJulianDate() << "\n";
699 textCtrl
<< "---------- Add Stuff -----------\n";
700 textCtrl
<< "Start => " << v4
<< "\n";
701 textCtrl
<< "Add 4 Weeks => " << v4
.AddWeeks(4) << "\n";
702 textCtrl
<< "Sub 1 Month => " << v4
.AddMonths(-1) << "\n";
703 textCtrl
<< "Add 2 Years => " << v4
.AddYears(2) << "\n";
705 textCtrl
<< "---------- Misc Stuff -----------\n";
706 textCtrl
<< "The date aboves' day of the month is => " << v4
.GetDay() << "\n";
707 textCtrl
<< "There are " << v4
.GetDaysInMonth() << " days in this month.\n";
708 textCtrl
<< "The first day of this month lands on " << v4
.GetFirstDayOfMonth() << "\n";
709 textCtrl
<< "This day happens to be " << v4
.GetDayOfWeekName() << "\n";
710 textCtrl
<< "the " << v4
.GetDayOfWeek() << " day of the week," << "\n";
711 textCtrl
<< "on the " << v4
.GetWeekOfYear() << " week of the year," << "\n";
712 textCtrl
<< "on the " << v4
.GetWeekOfMonth() << " week of the month, " << "\n";
713 textCtrl
<< "(which is " << v4
.GetMonthName() << ")\n";
714 textCtrl
<< "the "<< v4
.GetMonth() << "th month in the year.\n";
715 textCtrl
<< "The year alone is " << v4
.GetYear() << "\n";
717 textCtrl
<< "---------- First and Last Stuff -----------\n";
719 textCtrl
<< "The first date of this month is " << v4
.GetMonthStart() << "\n";
720 textCtrl
<< "The last date of this month is " << v4
.GetMonthEnd() << "\n";
721 textCtrl
<< "The first date of this year is " << v4
.GetYearStart() << "\n";
722 textCtrl
<< "The last date of this year is " << v4
.GetYearEnd() << "\n";
725 void MyApp
::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
727 wxTextCtrl
& textCtrl
= * GetTextCtrl();
729 wxVariant var1
= "String value";
730 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
733 wxString str
= var1
.MakeString();
736 textCtrl
<< "var1 = " << var1
.GetReal() << "\n";
738 // Implicit conversion
742 textCtrl
<< "var1 = " << var1
.GetLong() << "\n";
744 // Implicit conversion
747 // suppress compile warnings about unused variables
753 wxStringList stringList
;
754 stringList
.Add(_T("one")); stringList
.Add(_T("two")); stringList
.Add(_T("three"));
756 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
759 var1
.Append(wxVariant(1.2345));
760 var1
.Append(wxVariant("hello"));
761 var1
.Append(wxVariant(54321L));
763 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
765 size_t n
= var1
.GetCount();
767 for (i
= (size_t) 0; i
< n
; i
++)
769 textCtrl
<< "var1[" << (int) i
<< "] (type " << var1
[i
].GetType() << ") = " << var1
[i
].MakeString() << "\n";
773 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
774 EVT_MENU(TYPES_QUIT
, MyFrame
::OnQuit
)
775 EVT_MENU(TYPES_ABOUT
, MyFrame
::OnAbout
)
778 // My frame constructor
779 MyFrame
::MyFrame(wxFrame
*parent
, const wxString
& title
,
780 const wxPoint
& pos
, const wxSize
& size
):
781 wxFrame(parent
, -1, title
, pos
, size
)
784 void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
789 void MyFrame
::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
791 wxMessageDialog
dialog(this, "Tests various wxWindows types",
792 "About Types", wxYES_NO
|wxCANCEL
);