]>
Commit | Line | Data |
---|---|---|
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 |
37 | class MyApp: public wxApp | |
38 | { | |
39 | public: | |
c7f3b78b VZ |
40 | virtual bool OnInit(); |
41 | ||
c801d85f | 42 | protected: |
c7f3b78b | 43 | wxLocale m_locale; // locale we'll be using |
c801d85f KB |
44 | }; |
45 | ||
46 | // Define a new frame type | |
47 | class MyFrame: public wxFrame | |
c7f3b78b VZ |
48 | { |
49 | public: | |
50 | MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h); | |
51 | ||
52 | public: | |
53 | void OnQuit(wxCommandEvent& event); | |
54 | void OnAbout(wxCommandEvent& event); | |
55 | void OnPlay(wxCommandEvent& event); | |
56 | void OnOpen(wxCommandEvent& event); | |
e3065973 | 57 | |
c7f3b78b | 58 | DECLARE_EVENT_TABLE() |
c801d85f KB |
59 | }; |
60 | ||
61 | // ID for the menu commands | |
c7f3b78b VZ |
62 | enum |
63 | { | |
6a2a235b | 64 | MINIMAL_QUIT = 1, |
c7f3b78b VZ |
65 | MINIMAL_TEXT, |
66 | MINIMAL_ABOUT, | |
67 | MINIMAL_TEST, | |
68 | MINIMAL_OPEN | |
69 | }; | |
c801d85f KB |
70 | |
71 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
c7f3b78b VZ |
72 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) |
73 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
74 | EVT_MENU(MINIMAL_TEST, MyFrame::OnPlay) | |
75 | EVT_MENU(MINIMAL_OPEN, MyFrame::OnOpen) | |
c801d85f KB |
76 | END_EVENT_TABLE() |
77 | ||
78 | IMPLEMENT_APP(MyApp) | |
79 | ||
80 | ||
071cc2be | 81 | // `Main program' equivalent, creating windows and returning main app frame |
fd323a5e | 82 | bool MyApp::OnInit() |
c801d85f | 83 | { |
fd323a5e VZ |
84 | // set the language to use |
85 | const char *language = NULL; | |
86 | const char *langid = NULL; | |
87 | switch ( argc ) | |
88 | { | |
89 | default: | |
90 | // ignore the other args, fall through | |
91 | ||
92 | case 3: | |
93 | language = argv[1]; | |
94 | langid = argv[2]; | |
95 | break; | |
96 | ||
97 | case 2: | |
98 | language = argv[1]; | |
99 | break; | |
100 | ||
101 | case 1: | |
102 | language = "french"; | |
103 | langid = "fr"; | |
104 | }; | |
105 | ||
106 | // there are very few systems right now which support locales other than "C" | |
107 | m_locale.Init(language, langid, "C"); | |
f6bcfd97 BP |
108 | // note that under GTK starting from version 1.2.8 if |
109 | // you set locale to "C" and then use ASCII characters above | |
110 | // #128 in GUI elements, they will be truncated (it seems GTK | |
111 | // replaces them by \0). You should use either "" (checks | |
112 | // the value of LC_ALL etc. environment variables) or the form | |
113 | // accepted by glibc, e.g cs_CZ. | |
071cc2be | 114 | |
fd323a5e | 115 | // Initialize the catalogs we'll be using |
c801d85f KB |
116 | /* not needed any more, done in wxLocale ctor |
117 | m_locale.AddCatalog("wxstd"); // 1) for library messages | |
118 | */ | |
119 | m_locale.AddCatalog("internat"); // 2) our private one | |
c7f3b78b | 120 | /* this catalog is installed in standard location on Linux systems, |
c801d85f KB |
121 | it might not be installed on yours - just ignore the errrors |
122 | or comment out this line then */ | |
8e97b17b VZ |
123 | #ifdef __LINUX__ |
124 | m_locale.AddCatalog("fileutils"); // 3) and another just for testing | |
125 | #endif | |
c801d85f | 126 | |
c801d85f | 127 | // Create the main frame window |
fd323a5e | 128 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _("International wxWindows App"), |
6a2a235b | 129 | 50, 50, 350, 60); |
c801d85f KB |
130 | |
131 | // Give it an icon | |
b412f9be | 132 | frame->SetIcon(wxICON(mondrian)); |
c801d85f KB |
133 | |
134 | // Make a menubar | |
135 | wxMenu *file_menu = new wxMenu; | |
fd323a5e | 136 | file_menu->Append(MINIMAL_ABOUT, _("&About...")); |
c7f3b78b VZ |
137 | file_menu->AppendSeparator(); |
138 | file_menu->Append(MINIMAL_QUIT, _("E&xit")); | |
139 | ||
140 | wxMenu *test_menu = new wxMenu; | |
141 | test_menu->Append(MINIMAL_OPEN, _("&Open bogus file")); | |
142 | test_menu->Append(MINIMAL_TEST, _("&Play a game")); | |
c801d85f | 143 | |
c801d85f | 144 | wxMenuBar *menu_bar = new wxMenuBar; |
c7f3b78b VZ |
145 | menu_bar->Append(file_menu, _("&File")); |
146 | menu_bar->Append(test_menu, _("&Test")); | |
c801d85f KB |
147 | frame->SetMenuBar(menu_bar); |
148 | ||
c801d85f KB |
149 | // Show the frame |
150 | frame->Show(TRUE); | |
c801d85f KB |
151 | SetTopWindow(frame); |
152 | ||
153 | return TRUE; | |
154 | } | |
155 | ||
156 | // My frame constructor | |
c7f3b78b VZ |
157 | MyFrame::MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h) |
158 | : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
159 | { | |
160 | } | |
c801d85f | 161 | |
bd7d06f2 | 162 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) |
c801d85f KB |
163 | { |
164 | Close(TRUE); | |
165 | } | |
166 | ||
bd7d06f2 | 167 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
c801d85f | 168 | { |
fd323a5e VZ |
169 | wxMessageDialog(this, _("I18n sample\n" |
170 |