]> git.saurik.com Git - wxWidgets.git/blame - samples/internat/internat.cpp
applied patch 430835 (missing wxSTD breaking compilation for VC++ 5)
[wxWidgets.git] / samples / internat / internat.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: internat.cpp
c7f3b78b 3// Purpose: Demonstrates internationalisation (i18n) support
c801d85f
KB
4// Author: Vadim Zeitlin/Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c7f3b78b 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#pragma interface
15#endif
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
28#include "wx/intl.h"
c7f3b78b 29#include "wx/file.h"
c801d85f
KB
30#include "wx/log.h"
31
b412f9be 32#if defined(__WXGTK__) || defined(__WXMOTIF__)
47908e25
RR
33#include "mondrian.xpm"
34#endif
35
c801d85f
KB
36// Define a new application type
37class MyApp: public wxApp
38{
39public:
c7f3b78b
VZ
40 virtual bool OnInit();
41
c801d85f 42protected:
c7f3b78b 43 wxLocale m_locale; // locale we'll be using
c801d85f
KB
44};
45
46// Define a new frame type
47class MyFrame: public wxFrame
c7f3b78b
VZ
48{
49public:
d3f3e35f
VS
50 MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h,
51 wxLocale& m_locale);
c7f3b78b
VZ
52
53public:
54 void OnQuit(wxCommandEvent& event);
55 void OnAbout(wxCommandEvent& event);
56 void OnPlay(wxCommandEvent& event);
57 void OnOpen(wxCommandEvent& event);
e3065973 58
c7f3b78b 59 DECLARE_EVENT_TABLE()
d3f3e35f
VS
60
61 wxLocale& m_locale;
c801d85f
KB
62};
63
64// ID for the menu commands
c7f3b78b
VZ
65enum
66{
6a2a235b 67 MINIMAL_QUIT = 1,
c7f3b78b
VZ
68 MINIMAL_TEXT,
69 MINIMAL_ABOUT,
70 MINIMAL_TEST,
71 MINIMAL_OPEN
72};
c801d85f
KB
73
74BEGIN_EVENT_TABLE(MyFrame, wxFrame)
c7f3b78b
VZ
75 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
76 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
77 EVT_MENU(MINIMAL_TEST, MyFrame::OnPlay)
78 EVT_MENU(MINIMAL_OPEN, MyFrame::OnOpen)
c801d85f
KB
79END_EVENT_TABLE()
80
81IMPLEMENT_APP(MyApp)
82
83
071cc2be 84// `Main program' equivalent, creating windows and returning main app frame
fd323a5e 85bool MyApp::OnInit()
c801d85f 86{
4a377e13
VS
87 wxString langs[] = {_T("(System default)"),
88 _T("French"),
89 _T("German"),
90 _T("English"),
91 _T("English (U.S.)")};
1af9f469 92 SetExitOnFrameDelete(FALSE);
4a377e13
VS
93 int lng = wxGetSingleChoiceIndex(_T("Please choose language:"), _T("Language"),
94 5, langs);
1af9f469
VS
95 SetExitOnFrameDelete(TRUE);
96
97 switch (lng)
98 {
99 case 0 : m_locale.Init(wxLANGUAGE_DEFAULT); break;
100 case 1 : m_locale.Init(wxLANGUAGE_FRENCH); break;
101 case 2 : m_locale.Init(wxLANGUAGE_GERMAN); break;
4a377e13
VS
102 case 3 : m_locale.Init(wxLANGUAGE_ENGLISH); break;
103 case 4 : m_locale.Init(wxLANGUAGE_ENGLISH_US); break;
1af9f469
VS
104 default:
105 return FALSE;
106 }
d3f3e35f 107
071cc2be 108
fd323a5e 109 // Initialize the catalogs we'll be using
c801d85f
KB
110 /* not needed any more, done in wxLocale ctor
111 m_locale.AddCatalog("wxstd"); // 1) for library messages
112 */
113 m_locale.AddCatalog("internat"); // 2) our private one
c7f3b78b 114 /* this catalog is installed in standard location on Linux systems,
c801d85f
KB
115 it might not be installed on yours - just ignore the errrors
116 or comment out this line then */
8e97b17b 117#ifdef __LINUX__
d3f3e35f 118 //m_locale.AddCatalog("fileutils"); // 3) and another just for testing
8e97b17b 119#endif
c801d85f 120
c801d85f 121 // Create the main frame window
fd323a5e 122 MyFrame *frame = new MyFrame((wxFrame *) NULL, _("International wxWindows App"),
d3f3e35f 123 50, 50, 350, 60, m_locale);
c801d85f
KB
124
125 // Give it an icon
b412f9be 126 frame->SetIcon(wxICON(mondrian));
c801d85f
KB
127
128 // Make a menubar
129 wxMenu *file_menu = new wxMenu;
fd323a5e 130 file_menu->Append(MINIMAL_ABOUT, _("&About..."));
c7f3b78b
VZ
131 file_menu->AppendSeparator();
132 file_menu->Append(MINIMAL_QUIT, _("E&xit"));
133
134 wxMenu *test_menu = new wxMenu;
135 test_menu->Append(MINIMAL_OPEN, _("&Open bogus file"));
136 test_menu->Append(MINIMAL_TEST, _("&Play a game"));
c801d85f 137
c801d85f 138 wxMenuBar *menu_bar = new wxMenuBar;
c7f3b78b
VZ
139 menu_bar->Append(file_menu, _("&File"));
140 menu_bar->Append(test_menu, _("&Test"));
c801d85f
KB
141 frame->SetMenuBar(menu_bar);
142
c801d85f
KB
143 // Show the frame
144 frame->Show(TRUE);
c801d85f
KB
145 SetTopWindow(frame);
146
147 return TRUE;
148}
149
150// My frame constructor
d3f3e35f
VS
151MyFrame::MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h,
152 wxLocale& l)
153 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)),
154 m_locale(l)
c7f3b78b
VZ
155{
156}
c801d85f 157
bd7d06f2 158void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
159{
160 Close(TRUE);
161}
162
bd7d06f2 163void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
c801d85f 164{
d3f3e35f
VS
165 wxString localeInfo;
166 localeInfo.Printf(_("Language: %s\n"
167 "System locale name: %s\n"
168 "Canonical locale name: %s\n"),
169 m_locale.GetLocale(),
170 m_locale.GetSysName().c_str(),
171 m_locale.GetCanonicalName().c_str());
172
173 wxMessageDialog(this, wxString(_("I18n sample\n"
174 "(c) 1998, 1999 Vadim Zeitlin and Julian Smart"))
175 + wxT("\n\n") + localeInfo,
c7f3b78b 176 _("About Internat"), wxOK | wxICON_INFORMATION).ShowModal();
c801d85f
KB
177}
178
bd7d06f2 179void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
c7f3b78b
VZ
180{
181 wxString str = wxGetTextFromUser(_("Enter your number:"),
182 _("Try to guess my number!"),
183 "", this);
fd323a5e
VZ
184 if ( str.IsEmpty() )
185 return;
186
c7f3b78b
VZ
187 int num;
188 sscanf(str, "%d", &num);
189 if ( num == 0 )
fd323a5e 190 str = _("You've probably entered an invalid number.");
c7f3b78b 191 else if ( num == 9 ) // this message is not translated (not in catalog)
fd323a5e 192 str = "You've found a bug in this program!";
c7f3b78b 193 else if ( num != 17 ) // a more implicit way to write _()
fd323a5e 194 str = wxGetTranslation("Bad luck! try again...");
c7f3b78b
VZ
195 else {
196 str.Empty();
197 // string must be split in two -- otherwise the translation won't be found
fd323a5e 198 str << _("Congratulations! you've won. Here is the magic phrase:")
c7f3b78b
VZ
199 << _("cannot create fifo `%s'");
200 }
c801d85f 201
c7f3b78b
VZ
202 wxMessageBox(str, _("Result"), wxOK | wxICON_INFORMATION);
203}
204
205void MyFrame::OnOpen(wxCommandEvent&)
206{
207 // open a bogus file -- the error message should be also translated if you've
208 // got wxstd.mo somewhere in the search path
209 wxFile file("NOTEXIST.ING");
071cc2be 210}