]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: internat.cpp | |
3 | // Purpose: Demonstrates internationalisation 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/log.h" | |
30 | ||
31 | // Define a new application type | |
32 | class MyApp: public wxApp | |
33 | { | |
34 | public: | |
35 | MyApp(); | |
36 | bool OnInit(void); | |
37 | protected: | |
38 | wxLocale m_locale; // locale we'll be using | |
39 | }; | |
40 | ||
41 | // Define a new frame type | |
42 | class MyFrame: public wxFrame | |
43 | { public: | |
44 | MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); | |
45 | ||
46 | public: | |
47 | void OnQuit(wxCommandEvent& event); | |
48 | void OnAbout(wxCommandEvent& event); | |
49 | bool OnClose(void) { return TRUE; } | |
50 | ||
51 | DECLARE_EVENT_TABLE() | |
52 | ||
53 | }; | |
54 | ||
55 | // ID for the menu commands | |
56 | #define MINIMAL_QUIT 1 | |
57 | #define MINIMAL_TEXT 101 | |
58 | #define MINIMAL_ABOUT 102 | |
59 | ||
60 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
61 | EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit) | |
62 | EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout) | |
63 | END_EVENT_TABLE() | |
64 | ||
65 | IMPLEMENT_APP(MyApp) | |
66 | ||
67 | ||
68 | MyApp::MyApp(): | |
69 | m_locale("french", "fr", "C") | |
70 | { | |
71 | // catalogs we'll be using: | |
72 | /* not needed any more, done in wxLocale ctor | |
73 | m_locale.AddCatalog("wxstd"); // 1) for library messages | |
74 | */ | |
75 | m_locale.AddCatalog("internat"); // 2) our private one | |
76 | /* this catalog is installed in standard location on Liux systems, | |
77 | it might not be installed on yours - just ignore the errrors | |
78 | or comment out this line then */ | |
79 | m_locale.AddCatalog("fileutils"); // 3) and another just for testing | |
80 | ||
81 | } | |
82 | ||
83 | // `Main program' equivalent, creating windows and returning main app frame | |
84 | bool MyApp::OnInit(void) | |
85 | { | |
86 | // Create the main frame window | |
87 | MyFrame *frame = new MyFrame(NULL, "Minimal wxWindows App", 50, 50, 450, 340); | |
88 | ||
89 | // Give it an icon | |
2049ba38 | 90 | #ifdef __WXMSW__ |
c801d85f KB |
91 | frame->SetIcon(wxIcon("mondrian")); |
92 | #endif | |
93 | #ifdef __X__ | |
94 | frame->SetIcon(wxIcon("aiai.xbm")); | |
95 | #endif | |
96 | ||
97 | // Make a menubar | |
98 | wxMenu *file_menu = new wxMenu; | |
99 | ||
100 | file_menu->Append(MINIMAL_ABOUT, "&About"); | |
101 | file_menu->Append(MINIMAL_QUIT, "E&xit"); | |
102 | wxMenuBar *menu_bar = new wxMenuBar; | |
103 | menu_bar->Append(file_menu, "&File"); | |
104 | frame->SetMenuBar(menu_bar); | |
105 | ||
106 | // Make a panel with a message | |
107 | wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL); | |
108 | ||
109 | wxString msgString; | |
110 | int num = 2; | |
111 | if ( num == 0 ) | |
112 | msgString = wxTString("you've probably entered an invalid number."); | |
113 | else if ( num == 9 ) // this message is not translated | |
114 | msgString = wxTString("You've found a bug in this program!"); | |
115 | else if ( num != 17 ) | |
116 | msgString = wxTString("bad luck! try again..."); | |
117 | else { | |
118 | msgString = wxTString("congratulations! you've won. Here is the magic phrase:"); | |
119 | } | |
120 | ||
121 | wxStaticText *msg = new wxStaticText(panel, 311, msgString, wxPoint(10, 10), wxSize(-1, -1), | |
122 | 0); | |
123 | ||
124 | // Show the frame | |
125 | frame->Show(TRUE); | |
126 | ||
127 | ||
128 | SetTopWindow(frame); | |
129 | ||
130 | return TRUE; | |
131 | } | |
132 | ||
133 | // My frame constructor | |
134 | MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): | |
135 | wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
136 | {} | |
137 | ||
138 | void MyFrame::OnQuit(wxCommandEvent& event) | |
139 | { | |
140 | Close(TRUE); | |
141 | } | |
142 | ||
143 | void MyFrame::OnAbout(wxCommandEvent& event) | |
144 | { | |
145 | wxMessageDialog dialog(this, "This is a minimal sample\nA second line in the message box", | |
146 | "About Minimal", wxYES_NO|wxCANCEL); | |
147 | ||
148 | dialog.ShowModal(); | |
149 | } | |
150 | ||
151 |