]> git.saurik.com Git - wxWidgets.git/blame - samples/typetest/typetest.cpp
Small changed to wxExtDialog
[wxWidgets.git] / samples / typetest / typetest.cpp
CommitLineData
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"
53daeada 46#include "wx/datstrm.h"
38830220
RR
47
48
cfb88c55
JS
49// Create a new application object
50IMPLEMENT_APP (MyApp)
51
52IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp)
53
54BEGIN_EVENT_TABLE(MyApp, wxApp)
dcf924a3
RR
55 EVT_MENU(TYPES_DATE, MyApp::DoDateDemo)
56 EVT_MENU(TYPES_TIME, MyApp::DoTimeDemo)
57 EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo)
7e2c43b8 58 EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo)
dcf924a3
RR
59#if wxUSE_UNICODE
60 EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo)
61#endif
38830220 62 EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo)
cfb88c55
JS
63END_EVENT_TABLE()
64
65bool MyApp::OnInit(void)
66{
67 // Create the main frame window
68 MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxWindows Types Demo",
69 wxPoint(50, 50), wxSize(450, 340));
70
71 // Give it an icon
72 frame->SetIcon(wxICON(mondrian));
73
74 // Make a menubar
75 wxMenu *file_menu = new wxMenu;
76
77 file_menu->Append(TYPES_ABOUT, "&About");
78 file_menu->AppendSeparator();
79 file_menu->Append(TYPES_DATE, "&Date test");
80 file_menu->Append(TYPES_TIME, "&Time test");
81 file_menu->Append(TYPES_VARIANT, "&Variant test");
7e2c43b8 82 file_menu->Append(TYPES_BYTEORDER, "&Byteorder test");
dcf924a3
RR
83#if wxUSE_UNICODE
84 file_menu->Append(TYPES_UNICODE, "&Unicode test");
85#endif
38830220 86 file_menu->Append(TYPES_STREAM, "&Stream test");
cfb88c55
JS
87 file_menu->AppendSeparator();
88 file_menu->Append(TYPES_QUIT, "E&xit");
89 wxMenuBar *menu_bar = new wxMenuBar;
90 menu_bar->Append(file_menu, "&File");
91 frame->SetMenuBar(menu_bar);
92
93 m_textCtrl = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE);
94
95 // Show the frame
96 frame->Show(TRUE);
97
98 SetTopWindow(frame);
99
100 return TRUE;
101}
102
38830220
RR
103void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
104{
105 wxTextCtrl& textCtrl = * GetTextCtrl();
106
107 textCtrl.Clear();
108 textCtrl << "\nTest fstream vs. wxFileStream:\n\n";
109
e57e26dd
RR
110 textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
111
38830220
RR
112 ofstream std_file_output( "test_std.dat" );
113 wxFileOutputStream file_output( "test_wx.dat" );
114
38830220
RR
115 wxString tmp;
116 signed int si = 0xFFFFFFFF;
117 tmp.Printf( "Signed int: %d\n", si );
118 textCtrl.WriteText( tmp );
119 file_output << si << "\n";
120 std_file_output << si << "\n";
121
122 unsigned int ui = 0xFFFFFFFF;
123 tmp.Printf( "Unsigned int: %u\n", ui );
124 textCtrl.WriteText( tmp );
125 file_output << ui << "\n";
126 std_file_output << ui << "\n";
127
128 double d = 2.01234567890123456789;
129 tmp.Printf( "Double: %f\n", d );
130 textCtrl.WriteText( tmp );
131 file_output << d << "\n";
132 std_file_output << d << "\n";
133
e57e26dd
RR
134 float f = 0.00001;
135 tmp.Printf( "Float: %f\n", f );
136 textCtrl.WriteText( tmp );
137 file_output << f << "\n";
138 std_file_output << f << "\n";
139
38830220
RR
140 wxString str( "Hello!" );
141 tmp.Printf( "String: %s\n", str.c_str() );
142 textCtrl.WriteText( tmp );
143 file_output << str << "\n";
144 std_file_output << str.c_str() << "\n";
145
e57e26dd
RR
146 textCtrl.WriteText( "\nReading from ifstream:\n" );
147
148 ifstream std_file_input( "test_std.dat" );
149
150 std_file_input >> si;
151 tmp.Printf( "Signed int: %d\n", si );
152 textCtrl.WriteText( tmp );
153
154 std_file_input >> ui;
155 tmp.Printf( "Unsigned int: %u\n", ui );
156 textCtrl.WriteText( tmp );
157
158 std_file_input >> d;
159 tmp.Printf( "Double: %f\n", d );
160 textCtrl.WriteText( tmp );
161
162 std_file_input >> f;
163 tmp.Printf( "Float: %f\n", f );
164 textCtrl.WriteText( tmp );
165
166 std_file_input >> str;
167 tmp.Printf( "String: %s\n", str.c_str() );
168 textCtrl.WriteText( tmp );
169
170 textCtrl.WriteText( "\nReading from wxFileInputStream:\n" );
b6bff301
GL
171
172 file_output.OutputStreamBuffer()->FlushBuffer();
e57e26dd
RR
173
174 wxFileInputStream file_input( "test_wx.dat" );
175
176 file_input >> si;
177 tmp.Printf( "Signed int: %d\n", si );
178 textCtrl.WriteText( tmp );
179
180 file_input >> ui;
181 tmp.Printf( "Unsigned int: %u\n", ui );
182 textCtrl.WriteText( tmp );
183
184 file_input >> d;
185 tmp.Printf( "Double: %f\n", d );
186 textCtrl.WriteText( tmp );
187
188 file_input >> f;
189 tmp.Printf( "Float: %f\n", f );
190 textCtrl.WriteText( tmp );
191
192 file_input >> str;
193 tmp.Printf( "String: %s\n", str.c_str() );
194 textCtrl.WriteText( tmp );
53daeada
RR
195
196
197 textCtrl << "\nTest for wxDataStream:\n\n";
198
199 textCtrl.WriteText( "Writing to wxDataOutputStream:\n" );
200
201 file_output.SeekO( 0 );
202 wxDataOutputStream data_output( file_output );
203
329e86bf
RR
204 wxInt16 i16 = 0xFFFF;
205 tmp.Printf( "Signed int16: %d\n", (int)i16 );
53daeada 206 textCtrl.WriteText( tmp );
329e86bf 207 data_output.Write16( i16 );
53daeada 208
329e86bf
RR
209 wxUint16 ui16 = 0xFFFF;
210 tmp.Printf( "Unsigned int16: %u\n", (unsigned int) ui16 );
53daeada 211 textCtrl.WriteText( tmp );
329e86bf 212 data_output.Write16( ui16 );
53daeada
RR
213
214 d = 2.01234567890123456789;
215 tmp.Printf( "Double: %f\n", d );
216 textCtrl.WriteText( tmp );
217 data_output.WriteDouble( d );
218
219 str = "Hello!";
220 tmp.Printf( "String: %s\n", str.c_str() );
221 textCtrl.WriteText( tmp );
222 data_output.WriteString( str );
223
224 file_output.OutputStreamBuffer()->FlushBuffer();
225
226 textCtrl.WriteText( "\nReading from wxDataInputStream:\n" );
227
228 file_input.SeekI( 0 );
229 wxDataInputStream data_input( file_input );
230
329e86bf
RR
231 i16 = data_input.Read16();
232 tmp.Printf( "Signed int16: %d\n", (int)i16 );
53daeada
RR
233 textCtrl.WriteText( tmp );
234
329e86bf
RR
235 ui16 = data_input.Read16();
236 tmp.Printf( "Unsigned int16: %u\n", (unsigned int) ui16 );
53daeada
RR
237 textCtrl.WriteText( tmp );
238
239 d = data_input.ReadDouble();
240 tmp.Printf( "Double: %f\n", d );
241 textCtrl.WriteText( tmp );
242
243 str = data_input.ReadString();
244 tmp.Printf( "String: %s\n", str.c_str() );
245 textCtrl.WriteText( tmp );
38830220
RR
246}
247
dcf924a3
RR
248#if wxUSE_UNICODE
249void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event))
250{
251 wxTextCtrl& textCtrl = * GetTextCtrl();
252
253 textCtrl.Clear();
254 textCtrl << "\nTest wchar_t to char (Unicode to ANSI/Multibyte) converions:";
255
256 wxString str;
257