]>
Commit | Line | Data |
---|---|---|
cfb88c55 JS |
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 | ||
31 | #include "typetest.h" | |
32 | ||
b412f9be | 33 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
cfb88c55 JS |
34 | #include "mondrian.xpm" |
35 | #endif | |
36 | ||
38830220 RR |
37 | #include "wx/ioswrap.h" |
38 | ||
39 | #if wxUSE_IOSTREAMH | |
40 | #include <fstream.h> | |
41 | #else | |
42 | #include <fstream> | |
43 | #endif | |
44 | ||
45 | #include "wx/wfstream.h" | |
46 | ||
47 | ||
cfb88c55 JS |
48 | // Create a new application object |
49 | IMPLEMENT_APP (MyApp) | |
50 | ||
51 | IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp) | |
52 | ||
53 | BEGIN_EVENT_TABLE(MyApp, wxApp) | |
dcf924a3 RR |
54 | EVT_MENU(TYPES_DATE, MyApp::DoDateDemo) |
55 | EVT_MENU(TYPES_TIME, MyApp::DoTimeDemo) | |
56 | EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo) | |
7e2c43b8 | 57 | EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo) |
dcf924a3 RR |
58 | #if wxUSE_UNICODE |
59 | EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo) | |
60 | #endif | |
38830220 | 61 | EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo) |
cfb88c55 JS |
62 | END_EVENT_TABLE() |
63 | ||
64 | bool MyApp::OnInit(void) | |
65 | { | |
66 | // Create the main frame window | |
67 | MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxWindows Types Demo", | |
68 | wxPoint(50, 50), wxSize(450, 340)); | |
69 | ||
70 | // Give it an icon | |
71 | frame->SetIcon(wxICON(mondrian)); | |
72 | ||
73 | // Make a menubar | |
74 | wxMenu *file_menu = new wxMenu; | |
75 | ||
76 | file_menu->Append(TYPES_ABOUT, "&About"); | |
77 | file_menu->AppendSeparator(); | |
78 | file_menu->Append(TYPES_DATE, "&Date test"); | |
79 | file_menu->Append(TYPES_TIME, "&Time test"); | |
80 | file_menu->Append(TYPES_VARIANT, "&Variant test"); | |
7e2c43b8 | 81 | file_menu->Append(TYPES_BYTEORDER, "&Byteorder test"); |
dcf924a3 RR |
82 | #if wxUSE_UNICODE |
83 | file_menu->Append(TYPES_UNICODE, "&Unicode test"); | |
84 | #endif | |
38830220 | 85 | file_menu->Append(TYPES_STREAM, "&Stream test"); |
cfb88c55 JS |
86 | file_menu->AppendSeparator(); |
87 | file_menu->Append(TYPES_QUIT, "E&xit"); | |
88 | wxMenuBar *menu_bar = new wxMenuBar; | |
89 | menu_bar->Append(file_menu, "&File"); | |
90 | frame->SetMenuBar(menu_bar); | |
91 | ||
92 | m_textCtrl = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE); | |
93 | ||
94 | // Show the frame | |
95 | frame->Show(TRUE); | |
96 | ||
97 | SetTopWindow(frame); | |
98 | ||
99 | return TRUE; | |
100 | } | |
101 | ||
38830220 RR |
102 | void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) |
103 | { | |
104 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
105 | ||
106 | textCtrl.Clear(); | |
107 | textCtrl << "\nTest fstream vs. wxFileStream:\n\n"; | |
108 | ||
109 | ofstream std_file_output( "test_std.dat" ); | |
110 | wxFileOutputStream file_output( "test_wx.dat" ); | |
111 | ||
112 | textCtrl.WriteText( "Writig to fstream:\n" ); | |
113 | ||
114 | wxString tmp; | |
115 | signed int si = 0xFFFFFFFF; | |
116 | tmp.Printf( "Signed int: %d\n", si ); | |
117 | textCtrl.WriteText( tmp ); | |
118 | file_output << si << "\n"; | |
119 | std_file_output << si << "\n"; | |
120 | ||
121 | unsigned int ui = 0xFFFFFFFF; | |
122 | tmp.Printf( "Unsigned int: %u\n", ui ); | |
123 | textCtrl.WriteText( tmp ); | |
124 | file_output << ui << "\n"; | |
125 | std_file_output << ui << "\n"; | |
126 | ||
127 | double d = 2.01234567890123456789; | |
128 | tmp.Printf( "Double: %f\n", d ); | |
129 | textCtrl.WriteText( tmp ); | |
130 | file_output << d << "\n"; | |
131 | std_file_output << d << "\n"; | |
132 | ||
133 | wxString str( "Hello!" ); | |
134 | tmp.Printf( "String: %s\n", str.c_str() ); | |
135 | textCtrl.WriteText( tmp ); | |
136 | file_output << str << "\n"; | |
137 | std_file_output << str.c_str() << "\n"; | |
138 | ||
139 | } | |
140 | ||
dcf924a3 RR |
141 | #if wxUSE_UNICODE |
142 | void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event)) | |
143 | { | |
144 | wxTextCtrl& textCtrl = * GetTextCtrl(); | |
145 | ||
146 | textCtrl.Clear(); | |
147 | textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:"; | |
148 | ||
149 | wxString str; | |
150 |