Added bitmaps and icons to samples
[wxWidgets.git] / samples / internat / internat.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: internat.cpp
3 // Purpose: Demonstrates internationalisation (i18n) support
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
9 // Licence: wxWindows license
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"
29 #include "wx/file.h"
30 #include "wx/log.h"
31
32 #ifdef __WXGTK__
33 #include "mondrian.xpm"
34 #endif
35
36 // Define a new application type
37 class MyApp: public wxApp
38 {
39 public:
40 MyApp();
41
42 virtual bool OnInit();
43
44 protected:
45 wxLocale m_locale; // locale we'll be using
46 };
47
48 // Define a new frame type
49 class MyFrame: public wxFrame
50 {
51 public:
52 MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h);
53
54 public:
55 void OnQuit(wxCommandEvent& event);
56 void OnAbout(wxCommandEvent& event);
57 void OnPlay(wxCommandEvent& event);
58 void OnOpen(wxCommandEvent& event);
59 bool OnClose(void) { return TRUE; }
60
61 DECLARE_EVENT_TABLE()
62 };
63
64 // ID for the menu commands
65 enum
66 {
67 MINIMAL_QUIT,
68 MINIMAL_TEXT,
69 MINIMAL_ABOUT,
70 MINIMAL_TEST,
71 MINIMAL_OPEN
72 };
73
74 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
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)
79 END_EVENT_TABLE()
80
81 IMPLEMENT_APP(MyApp)
82
83
84 MyApp::MyApp() : m_locale("french", "fr", "C")
85 {
86 // catalogs we'll be using:
87 /* not needed any more, done in wxLocale ctor
88 m_locale.AddCatalog("wxstd"); // 1) for library messages
89 */
90 m_locale.AddCatalog("internat"); // 2) our private one
91 /* this catalog is installed in standard location on Linux systems,
92 it might not be installed on yours - just ignore the errrors
93 or comment out this line then */
94 m_locale.AddCatalog("fileutils"); // 3) and another just for testing
95
96 }
97
98 // `Main program' equivalent, creating windows and returning main app frame
99 bool MyApp::OnInit(void)
100 {
101 // Create the main frame window
102 MyFrame *frame = new MyFrame(NULL, _("Minimal wxWindows App"), 50, 50, 150, 40);
103
104 // Give it an icon
105 #ifdef __WXMSW__
106 frame->SetIcon(wxIcon("mondrian"));
107 #else
108 frame->SetIcon(wxIcon(mondrian_xpm));
109 #endif
110
111 // Make a menubar
112 wxMenu *file_menu = new wxMenu;
113 file_menu->Append(MINIMAL_ABOUT, _("&About"));
114 file_menu->AppendSeparator();
115 file_menu->Append(MINIMAL_QUIT, _("E&xit"));
116
117 wxMenu *test_menu = new wxMenu;
118 test_menu->Append(MINIMAL_OPEN, _("&Open bogus file"));
119 test_menu->Append(MINIMAL_TEST, _("&Play a game"));
120
121 wxMenuBar *menu_bar = new wxMenuBar;
122 menu_bar->Append(file_menu, _("&File"));
123 menu_bar->Append(test_menu, _("&Test"));
124 frame->SetMenuBar(menu_bar);
125
126 // Show the frame
127 frame->Show(TRUE);
128 SetTopWindow(frame);
129
130 return TRUE;
131 }
132
133 // My frame constructor
134 MyFrame::MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h)
135 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
136 {
137 }
138
139 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
140 {
141 Close(TRUE);
142 }
143
144 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
145 {
146 wxMessageDialog(this, _("I18n sample\n© Vadim Zeitlin & Julian Smart"),
147 _("About Internat"), wxOK | wxICON_INFORMATION).ShowModal();
148 }
149
150 void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
151 {
152 wxString str = wxGetTextFromUser(_("Enter your number:"),
153 _("Try to guess my number!"),
154 "", this);
155 int num;
156 sscanf(str, "%d", &num);
157 if ( num == 0 )
158 str = _("you've probably entered an invalid number.");
159 else if ( num == 9 ) // this message is not translated (not in catalog)
160 str = _("you've found a bug in this program!");
161 else if ( num != 17 ) // a more implicit way to write _()
162 str = wxGetTranslation("bad luck! try again...");
163 else {
164 str.Empty();
165 // string must be split in two -- otherwise the translation won't be found
166 str << _("congratulations! you've won. Here is the magic phrase:")
167 << _("cannot create fifo `%s'");
168 }
169
170 wxMessageBox(str, _("Result"), wxOK | wxICON_INFORMATION);
171 }
172
173 void MyFrame::OnOpen(wxCommandEvent&)
174 {
175 // open a bogus file -- the error message should be also translated if you've
176 // got wxstd.mo somewhere in the search path
177 wxFile file("NOTEXIST.ING");
178 }