]> git.saurik.com Git - wxWidgets.git/blob - samples/typetest/typetest.cpp
Fixed bug in dc::blit()
[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
31 #include "typetest.h"
32
33 #ifdef __WXGTK__
34 #include "mondrian.xpm"
35 #endif
36
37 // Create a new application object
38 IMPLEMENT_APP (MyApp)
39
40 IMPLEMENT_DYNAMIC_CLASS (MyApp, wxApp)
41
42 BEGIN_EVENT_TABLE(MyApp, wxApp)
43 EVT_MENU(TYPES_DATE, MyApp::DoDateDemo)
44 EVT_MENU(TYPES_TIME, MyApp::DoTimeDemo)
45 EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo)
46 END_EVENT_TABLE()
47
48 bool MyApp::OnInit(void)
49 {
50 // Create the main frame window
51 MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxWindows Types Demo",
52 wxPoint(50, 50), wxSize(450, 340));
53
54 // Give it an icon
55 frame->SetIcon(wxICON(mondrian));
56
57 // Make a menubar
58 wxMenu *file_menu = new wxMenu;
59
60 file_menu->Append(TYPES_ABOUT, "&About");
61 file_menu->AppendSeparator();
62 file_menu->Append(TYPES_DATE, "&Date test");
63 file_menu->Append(TYPES_TIME, "&Time test");
64 file_menu->Append(TYPES_VARIANT, "&Variant test");
65 file_menu->AppendSeparator();
66 file_menu->Append(TYPES_QUIT, "E&xit");
67 wxMenuBar *menu_bar = new wxMenuBar;
68 menu_bar->Append(file_menu, "&File");
69 frame->SetMenuBar(menu_bar);
70
71 m_textCtrl = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE);
72
73 // Show the frame
74 frame->Show(TRUE);
75
76 SetTopWindow(frame);
77
78 return TRUE;
79 }
80
81 void MyApp::DoTimeDemo(wxCommandEvent& event)
82 {
83 wxTextCtrl& textCtrl = * GetTextCtrl();
84
85 textCtrl.Clear();
86 cout << "\nTest class wxTime" << endl;
87 wxTime now;
88 textCtrl << "It is now " << (wxString) now << "\n";
89 }
90
91 void MyApp::DoDateDemo(wxCommandEvent& event)
92 {
93 wxTextCtrl& textCtrl = * GetTextCtrl();
94
95 textCtrl.Clear();
96 textCtrl << "\nTest class wxDate" << "\n";
97
98 // Various versions of the constructors
99 // and various output
100
101 wxDate x(10,20,1962);
102
103 textCtrl << x.FormatDate(wxFULL) << " (full)\n";
104
105 // constuctor with a string, just printing the day of the week
106 wxDate y("8/8/1988");
107
108 textCtrl << y.FormatDate(wxDAY) << " (just day)\n";
109
110 // constructor with a julian
111 wxDate z( 2450000L );
112 textCtrl << z.FormatDate(wxFULL) << " (full)\n";
113
114 // using date addition and subtraction
115 wxDate a = x + 10;
116 textCtrl << a.FormatDate(wxFULL) << " (full)\n";
117 a = a - 25;
118 textCtrl << a.FormatDate(wxEUROPEAN) << " (European)\n";
119
120
121 // Using subtraction of two date objects
122 wxDate a1 = wxString("7/13/1991");
123 wxDate a2 = a1 + 14;
124 textCtrl << (a1-a2) << "\n";
125 textCtrl << (a2+=10) << "\n";
126
127 a1++;
128 textCtrl << "Tomorrow= " << a1.FormatDate(wxFULL) << "\n";
129
130 wxDate tmpDate1("08/01/1991");
131 wxDate tmpDate2("07/14/1991");
132 textCtrl << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < tmpDate1) ? "TRUE" : "FALSE") << "\n";
133 textCtrl << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > tmpDate1) ? "TRUE" : "FALSE") << "\n";
134 textCtrl << "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1==tmpDate2) ? "TRUE" : "FALSE") << "\n";
135
136 wxDate a3 = a1;
137 textCtrl << "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << "\n";
138 wxDate a4 = a1;
139 textCtrl << "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1==++a4) ? "TRUE" : "FALSE") << "\n";
140
141 wxDate a5 = wxString("today");
142 textCtrl << "Today is: " << a5 << "\n";
143 a4 = "TODAY";
144 textCtrl << "Today (a4) is: " << a4 << "\n";
145
146 textCtrl << "Today + 4 is: " << (a4+=4) << "\n";
147 a4 = "TODAY";
148 textCtrl << "Today - 4 is: " << (a4-=4) << "\n";
149
150 textCtrl << "=========== Leap Year Test ===========\n";
151 a1 = "1/15/1992";
152 textCtrl << a1.FormatDate(wxFULL) << " " << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
153 textCtrl << " " << "day of year: " << a1.GetDayOfYear() << "\n";
154
155 a1 = "2/16/1993";
156 textCtrl << a1.FormatDate(wxFULL) << " " << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
157 textCtrl << " " << "day of year: " << a1.GetDayOfYear() << "\n";
158
159 textCtrl << "================== string assignment test ====================\n";
160 wxString date_string=a1;
161 textCtrl << "a1 as a string (s/b 2/16/1993) ==> " << date_string << "\n";
162
163 textCtrl << "================== SetFormat test ============================\n";
164 a1.SetFormat(wxFULL);
165 textCtrl << "a1 (s/b FULL format) ==> " << a1 << "\n";
166 a1.SetFormat(wxEUROPEAN);
167 textCtrl << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
168
169 textCtrl << "================== SetOption test ============================\n";
170 textCtrl << "Date abbreviation ON\n";
171
172 a1.SetOption(wxDATE_ABBR);
173 a1.SetFormat(wxMONTH);
174 textCtrl << "a1 (s/b MONTH format) ==> " << a1 << "\n";
175 a1.SetFormat(wxDAY);
176 textCtrl << "a1 (s/b DAY format) ==> " << a1 << "\n";
177 a1.SetFormat(wxFULL);
178 textCtrl << "a1 (s/b FULL format) ==> " << a1 << "\n";
179 a1.SetFormat(wxEUROPEAN);
180 textCtrl << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
181 textCtrl << "Century suppression ON\n";
182 a1.SetOption(wxNO_CENTURY);
183 a1.SetFormat(wxMDY);
184 textCtrl << "a1 (s/b MDY format) ==> " << a1 << "\n";
185 textCtrl << "Century suppression OFF\n";
186 a1.SetOption(wxNO_CENTURY,FALSE);
187 textCtrl << "a1 (s/b MDY format) ==> " << a1 << "\n";
188 textCtrl << "Century suppression ON\n";
189 a1.SetOption(wxNO_CENTURY);
190 textCtrl << "a1 (s/b MDY format) ==> " << a1 << "\n";
191 a1.SetFormat(wxFULL);
192 textCtrl << "a1 (s/b FULL format) ==> " << a1 << "\n";
193
194 textCtrl << "\n=============== Version 4.0 Enhancement Test =================\n";
195
196 wxDate v4("11/26/1966");
197 textCtrl << "\n---------- Set Stuff -----------\n";
198 textCtrl << "First, 'Set' to today..." << "\n";
199 textCtrl << "Before 'Set' => " << v4 << "\n";
200 textCtrl << "After 'Set' => " << v4.Set() << "\n\n";
201
202 textCtrl << "Set to 11/26/66 => " << v4.Set(11,26,1966) << "\n";
203 textCtrl << "Current Julian => " << v4.GetJulianDate() << "\n";
204 textCtrl << "Set to Julian 2450000L => " << v4.Set(2450000L) << "\n";
205 textCtrl << "See! => " << v4.GetJulianDate() << "\n";
206
207 textCtrl << "---------- Add Stuff -----------\n";
208 textCtrl << "Start => " << v4 << "\n";
209 textCtrl << "Add 4 Weeks => " << v4.AddWeeks(4) << "\n";
210 textCtrl << "Sub 1 Month => " << v4.AddMonths(-1) << "\n";
211 textCtrl << "Add 2 Years => " << v4.AddYears(2) << "\n";
212
213 textCtrl << "---------- Misc Stuff -----------\n";
214 textCtrl << "The date aboves' day of the month is => " << v4.GetDay() << "\n";
215 textCtrl << "There are " << v4.GetDaysInMonth() << " days in this month.\n";
216 textCtrl << "The first day of this month lands on " << v4.GetFirstDayOfMonth() << "\n";
217 textCtrl << "This day happens to be " << v4.GetDayOfWeekName() << "\n";
218 textCtrl << "the " << v4.GetDayOfWeek() << " day of the week," << "\n";
219 textCtrl << "on the " << v4.GetWeekOfYear() << " week of the year," << "\n";
220 textCtrl << "on the " << v4.GetWeekOfMonth() << " week of the month, " << "\n";
221 textCtrl << "(which is " << v4.GetMonthName() << ")\n";
222 textCtrl << "the "<< v4.GetMonth() << "th month in the year.\n";
223 textCtrl << "The year alone is " << v4.GetYear() << "\n";
224
225 textCtrl << "---------- First and Last Stuff -----------\n";
226 v4.Set();
227 textCtrl << "The first date of this month is " << v4.GetMonthStart() << "\n";
228 textCtrl << "The last date of this month is " << v4.GetMonthEnd() << "\n";
229 textCtrl << "The first date of this year is " << v4.GetYearStart() << "\n";
230 textCtrl << "The last date of this year is " << v4.GetYearEnd() << "\n";
231 }
232
233 void MyApp::DoVariantDemo(wxCommandEvent& event)
234 {
235 wxTextCtrl& textCtrl = * GetTextCtrl();
236
237 wxVariant var1 = "String value";
238 textCtrl << "var1 = " << (wxString) var1 << "\n";
239
240 // Implicit conversion
241 wxString str = var1;
242
243 var1 = 123.456;
244 textCtrl << "var1 = " << var1.GetReal() << "\n";
245
246 // Implicit conversion
247 double v = var1;
248
249 var1 = 9876L;
250 textCtrl << "var1 = " << var1.GetLong() << "\n";
251
252 // Implicit conversion
253 long l = var1;
254
255 wxStringList stringList;
256 stringList.Add("one"); stringList.Add("two"); stringList.Add("three");
257 var1 = stringList;
258 textCtrl << "var1 = " << (wxString) var1 << "\n";
259
260 var1.ClearList();
261 var1.Append(wxVariant(1.2345));
262 var1.Append(wxVariant("hello"));
263 var1.Append(wxVariant(54321L));
264
265 textCtrl << "var1 = " << (wxString) var1 << "\n";
266
267 size_t n = var1.GetCount();
268 size_t i;
269 for (i = (size_t) 0; i < n; i++)
270 {
271 textCtrl << "var1[" << (int) i << "] (type " << var1[i].GetType() << ") = " << (wxString) var1[i] << "\n";
272 }
273 }
274
275 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
276 EVT_MENU(TYPES_QUIT, MyFrame::OnQuit)
277 EVT_MENU(TYPES_ABOUT, MyFrame::OnAbout)
278 END_EVENT_TABLE()
279
280 // My frame constructor
281 MyFrame::MyFrame(wxFrame *parent, const wxString& title,
282 const wxPoint& pos, const wxSize& size):
283 wxFrame(parent, -1, title, pos, size)
284 {}
285
286 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
287 {
288 Close(TRUE);
289 }
290
291 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
292 {
293 wxMessageDialog dialog(this, "Tests various wxWindows types",
294 "About Types", wxYES_NO|wxCANCEL);
295
296 dialog.ShowModal();
297 }
298
299