A couple of fixes to Brazilian Portuguese translations from Felipe.
[wxWidgets.git] / samples / artprov / arttest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: arttest.cpp
3 // Purpose: wxArtProvider sample
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 2002/03/25
7 // Copyright: (c) Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #ifndef wxHAS_IMAGES_IN_RESOURCES
23 #include "../sample.xpm"
24 #endif
25
26 #include "wx/artprov.h"
27 #include "artbrows.h"
28
29 // ----------------------------------------------------------------------------
30 // private classes
31 // ----------------------------------------------------------------------------
32
33 class MyApp : public wxApp
34 {
35 public:
36 virtual bool OnInit();
37 };
38
39 class MyFrame : public wxFrame
40 {
41 public:
42 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
43 long style = wxDEFAULT_FRAME_STYLE);
44
45 private:
46 // event handlers (these functions should _not_ be virtual)
47 void OnQuit(wxCommandEvent& event);
48 void OnAbout(wxCommandEvent& event);
49 #if wxUSE_LOG
50 void OnLogs(wxCommandEvent& event);
51 #endif // wxUSE_LOG
52 void OnBrowser(wxCommandEvent& event);
53 void OnPlugProvider(wxCommandEvent& event);
54
55 DECLARE_EVENT_TABLE()
56 };
57
58 // ----------------------------------------------------------------------------
59 // constants
60 // ----------------------------------------------------------------------------
61
62 // IDs for the controls and the menu commands
63 enum
64 {
65 ID_Quit = wxID_EXIT,
66 ID_Logs = wxID_HIGHEST+1,
67 ID_Browser,
68 ID_PlugProvider
69 };
70
71 // ----------------------------------------------------------------------------
72 // event tables and other macros for wxWidgets
73 // ----------------------------------------------------------------------------
74
75 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
76 EVT_MENU(ID_Quit, MyFrame::OnQuit)
77 #if wxUSE_LOG
78 EVT_MENU(ID_Logs, MyFrame::OnLogs)
79 #endif // wxUSE_LOG
80 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
81 EVT_MENU(ID_Browser, MyFrame::OnBrowser)
82 EVT_MENU(ID_PlugProvider, MyFrame::OnPlugProvider)
83 END_EVENT_TABLE()
84
85 IMPLEMENT_APP(MyApp)
86
87 // ============================================================================
88 // implementation
89 // ============================================================================
90
91 // ----------------------------------------------------------------------------
92 // the application class
93 // ----------------------------------------------------------------------------
94
95 // 'Main program' equivalent: the program execution "starts" here
96 bool MyApp::OnInit()
97 {
98 if ( !wxApp::OnInit() )
99 return false;
100
101 // create the main application window
102 MyFrame *frame = new MyFrame(wxT("wxArtProvider sample"),
103 wxPoint(50, 50), wxSize(450, 340));
104 frame->Show(true);
105 return true;
106 }
107
108 // ----------------------------------------------------------------------------
109 // custom art provider
110 // ----------------------------------------------------------------------------
111
112 class MyArtProvider : public wxArtProvider
113 {
114 protected:
115 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
116 const wxSize& size);
117 };
118
119 #include "info.xpm"
120 #include "error.xpm"
121 #include "warning.xpm"
122 #include "question.xpm"
123
124 wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,
125 const wxArtClient& client,
126 const wxSize& WXUNUSED(size))
127 {
128 if ( client == wxART_MESSAGE_BOX )
129 {
130 if ( id == wxART_INFORMATION )
131 return wxBitmap(info_xpm);
132 if ( id == wxART_ERROR )
133 return wxBitmap(error_xpm);
134 if ( id == wxART_WARNING )
135 return wxBitmap(warning_xpm);
136 if ( id == wxART_QUESTION )
137 return wxBitmap(question_xpm);
138 }
139 return wxNullBitmap;
140 }
141
142
143
144 // ----------------------------------------------------------------------------
145 // main frame
146 // ----------------------------------------------------------------------------
147
148 // frame constructor
149 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
150 : wxFrame(NULL, wxID_ANY, title, pos, size, style)
151 {
152 SetIcon(wxICON(sample));
153
154 // create a menu bar
155 wxMenu *menuFile = new wxMenu;
156
157 // the "About" item should be in the help menu
158 wxMenu *helpMenu = new wxMenu;
159 helpMenu->Append(wxID_ABOUT, wxT("&About\tF1"), wxT("Show about dialog"));
160
161 menuFile->AppendCheckItem(ID_PlugProvider, wxT("&Plug-in art provider"), wxT("Enable custom art provider"));
162 menuFile->AppendSeparator();
163
164 #if wxUSE_LOG
165 menuFile->Append(ID_Logs, wxT("&Logging test"), wxT("Show some logging output"));
166 #endif // wxUSE_LOG
167 menuFile->Append(ID_Browser, wxT("&Resources browser"), wxT("Browse all available icons"));
168 menuFile->AppendSeparator();
169
170 menuFile->Append(ID_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
171
172 // now append the freshly created menu to the menu bar...
173 wxMenuBar *menuBar = new wxMenuBar();
174 menuBar->Append(menuFile, wxT("&File"));
175 menuBar->Append(helpMenu, wxT("&Help"));
176
177 // ... and attach this menu bar to the frame
178 SetMenuBar(menuBar);
179 }
180
181
182 // event handlers
183
184 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
185 {
186 // true is to force the frame to close
187 Close(true);
188 }
189
190 #if wxUSE_LOG
191 void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
192 {
193 wxLogMessage(wxT("Some information."));
194 wxLogError(wxT("This is an error."));
195 wxLogWarning(wxT("A warning."));
196 wxLogError(wxT("Yet another error."));
197 wxLog::GetActiveTarget()->Flush();
198 wxLogMessage(wxT("Check/uncheck 'File/Plug-in art provider' and try again."));
199 }
200 #endif // wxUSE_LOG
201
202 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
203 {
204 wxString msg;
205 msg.Printf( wxT("This is the about dialog of wxArtProvider sample.\n")
206 wxT("Welcome to %s"), wxVERSION_STRING);
207
208 wxMessageBox(msg, wxT("About wxArtProvider sample"),
209 wxOK | wxICON_INFORMATION, this);
210 }
211
212 void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
213 {
214 wxArtBrowserDialog dlg(this);
215 dlg.ShowModal();
216 }
217
218 void MyFrame::OnPlugProvider(wxCommandEvent& event)
219 {
220 if ( event.IsChecked() )
221 wxArtProvider::Push(new MyArtProvider);
222 else
223 wxArtProvider::Pop();
224 }