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