]>
git.saurik.com Git - wxWidgets.git/blob - samples/typetest/typetest.cpp
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"
33 #if defined(__WXGTK__) || defined(__WXMOTIF__)
34 #include "mondrian.xpm"
37 // Create a new application object
40 IMPLEMENT_DYNAMIC_CLASS (MyApp
, wxApp
)
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
)
48 bool MyApp::OnInit(void)
50 // Create the main frame window
51 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "wxWindows Types Demo",
52 wxPoint(50, 50), wxSize(450, 340));
55 frame
->SetIcon(wxICON(mondrian
));
58 wxMenu
*file_menu
= new wxMenu
;
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
);
71 m_textCtrl
= new wxTextCtrl(frame
, -1, "", wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
81 void MyApp::DoTimeDemo(wxCommandEvent
& WXUNUSED(event
))
83 wxTextCtrl
& textCtrl
= * GetTextCtrl();
86 cout
<< "\nTest class wxTime" << endl
;
88 textCtrl
<< "It is now " << (wxString
) now
<< "\n";
91 void MyApp::DoDateDemo(wxCommandEvent
& WXUNUSED(event
))
93 wxTextCtrl
& textCtrl
= * GetTextCtrl();
96 textCtrl
<< "\nTest class wxDate" << "\n";
98 // Various versions of the constructors
101 wxDate
x(10,20,1962);
103 textCtrl
<< x
.FormatDate(wxFULL
) << " (full)\n";
105 // constuctor with a string, just printing the day of the week
106 wxDate
y("8/8/1988");
108 textCtrl
<< y
.FormatDate(wxDAY
) << " (just day)\n";
110 // constructor with a julian
111 wxDate
z( 2450000L );
112 textCtrl
<< z
.FormatDate(wxFULL
) << " (full)\n";
114 // using date addition and subtraction
116 textCtrl
<< a
.FormatDate(wxFULL
) << " (full)\n";
118 textCtrl
<< a
.FormatDate(wxEUROPEAN
) << " (European)\n";
121 // Using subtraction of two date objects
122 wxDate a1
= wxString("7/13/1991");
124 textCtrl
<< (a1
-a2
) << "\n";
125 textCtrl
<< (a2
+=10) << "\n";
128 textCtrl
<< "Tomorrow= " << a1
.FormatDate(wxFULL
) << "\n";
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";
137 textCtrl
<< "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1
==a3
) ? "TRUE" : "FALSE") << "\n";
139 textCtrl
<< "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1
==++a4
) ? "TRUE" : "FALSE") << "\n";
141 wxDate a5
= wxString("today");
142 textCtrl
<< "Today is: " << a5
<< "\n";
144 textCtrl
<< "Today (a4) is: " << a4
<< "\n";
146 textCtrl
<< "Today + 4 is: " << (a4
+=4) << "\n";
148 textCtrl
<< "Today - 4 is: " << (a4
-=4) << "\n";
150 textCtrl
<< "=========== Leap Year Test ===========\n";
152 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
153 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
156 textCtrl
<< a1
.FormatDate(wxFULL
) << " " << ((a1
.IsLeapYear()) ? "Leap" : "non-Leap");
157 textCtrl
<< " " << "day of year: " << a1
.GetDayOfYear() << "\n";
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";
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";
169 textCtrl
<< "================== SetOption test ============================\n";
170 textCtrl
<< "Date abbreviation ON\n";
172 a1
.SetOption(wxDATE_ABBR
);
173 a1
.SetFormat(wxMONTH
);
174 textCtrl
<< "a1 (s/b MONTH format) ==> " << a1
<< "\n";
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
);
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";
194 textCtrl
<< "\n=============== Version 4.0 Enhancement Test =================\n";
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";
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";
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";
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";
225 textCtrl
<< "---------- First and Last Stuff -----------\n";
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";
233 void MyApp::DoVariantDemo(wxCommandEvent
& WXUNUSED(event
) )
235 wxTextCtrl
& textCtrl
= * GetTextCtrl();
237 wxVariant var1
= "String value";
238 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
241 wxString str
= var1
.MakeString();
244 textCtrl
<< "var1 = " << var1
.GetReal() << "\n";
246 // Implicit conversion
250 textCtrl
<< "var1 = " << var1
.GetLong() << "\n";
252 // Implicit conversion
255 wxStringList stringList
;
256 stringList
.Add("one"); stringList
.Add("two"); stringList
.Add("three");
258 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
261 var1
.Append(wxVariant(1.2345));
262 var1
.Append(wxVariant("hello"));
263 var1
.Append(wxVariant(54321L));
265 textCtrl
<< "var1 = " << var1
.MakeString() << "\n";
267 size_t n
= var1
.GetCount();
269 for (i
= (size_t) 0; i
< n
; i
++)
271 textCtrl
<< "var1[" << (int) i
<< "] (type " << var1
[i
].GetType() << ") = " << var1
[i
].MakeString() << "\n";
275 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
276 EVT_MENU(TYPES_QUIT
, MyFrame::OnQuit
)
277 EVT_MENU(TYPES_ABOUT
, MyFrame::OnAbout
)
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
)
286 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
291 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
293 wxMessageDialog
dialog(this, "Tests various wxWindows types",
294 "About Types", wxYES_NO
|wxCANCEL
);