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