]> git.saurik.com Git - wxWidgets.git/blame - samples/artprov/arttest.cpp
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / samples / artprov / arttest.cpp
CommitLineData
12fd305b
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: arttest.cpp
3// Purpose: wxArtProvider sample
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2002/03/25
12fd305b 7// Copyright: (c) Vaclav Slavik
526954c5 8// Licence: wxWindows licence
12fd305b
VS
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
e7092398 22#ifndef wxHAS_IMAGES_IN_RESOURCES
3cb332c1 23 #include "../sample.xpm"
12fd305b
VS
24#endif
25
26#include "wx/artprov.h"
ccb42cc5 27#include "artbrows.h"
12fd305b
VS
28
29// ----------------------------------------------------------------------------
30// private classes
31// ----------------------------------------------------------------------------
32
33class MyApp : public wxApp
34{
35public:
36 virtual bool OnInit();
37};
38
39class MyFrame : public wxFrame
40{
41public:
42 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
43 long style = wxDEFAULT_FRAME_STYLE);
44
45private:
46 // event handlers (these functions should _not_ be virtual)
47 void OnQuit(wxCommandEvent& event);
48 void OnAbout(wxCommandEvent& event);
f07941fc 49#if wxUSE_LOG
12fd305b 50 void OnLogs(wxCommandEvent& event);
f07941fc 51#endif // wxUSE_LOG
ccb42cc5
VS
52 void OnBrowser(wxCommandEvent& event);
53 void OnPlugProvider(wxCommandEvent& event);
5f4d35b8 54
12fd305b
VS
55 DECLARE_EVENT_TABLE()
56};
57
58// ----------------------------------------------------------------------------
59// constants
60// ----------------------------------------------------------------------------
61
62// IDs for the controls and the menu commands
63enum
64{
6e22db9e
SC
65 ID_Quit = wxID_EXIT,
66 ID_Logs = wxID_HIGHEST+1,
ccb42cc5
VS
67 ID_Browser,
68 ID_PlugProvider
12fd305b
VS
69};
70
71// ----------------------------------------------------------------------------
be5a51fb 72// event tables and other macros for wxWidgets
12fd305b
VS
73// ----------------------------------------------------------------------------
74
75BEGIN_EVENT_TABLE(MyFrame, wxFrame)
ccb42cc5 76 EVT_MENU(ID_Quit, MyFrame::OnQuit)
f07941fc 77#if wxUSE_LOG
ccb42cc5 78 EVT_MENU(ID_Logs, MyFrame::OnLogs)
f07941fc 79#endif // wxUSE_LOG
ccb42cc5
VS
80 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
81 EVT_MENU(ID_Browser, MyFrame::OnBrowser)
82 EVT_MENU(ID_PlugProvider, MyFrame::OnPlugProvider)
12fd305b
VS
83END_EVENT_TABLE()
84
85IMPLEMENT_APP(MyApp)
86
87// ============================================================================
88// implementation
89// ============================================================================
90
91// ----------------------------------------------------------------------------
92// the application class
93// ----------------------------------------------------------------------------
94
95// 'Main program' equivalent: the program execution "starts" here
96bool MyApp::OnInit()
97{
45e6e6f8
VZ
98 if ( !wxApp::OnInit() )
99 return false;
100
12fd305b 101 // create the main application window
9a83f860 102 MyFrame *frame = new MyFrame(wxT("wxArtProvider sample"),
12fd305b 103 wxPoint(50, 50), wxSize(450, 340));
5014bb3a
WS
104 frame->Show(true);
105 return true;
12fd305b
VS
106}
107
ccb42cc5
VS
108// ----------------------------------------------------------------------------
109// custom art provider
110// ----------------------------------------------------------------------------
111
112class MyArtProvider : public wxArtProvider
113{
114protected:
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
124wxBitmap 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
12fd305b
VS
144// ----------------------------------------------------------------------------
145// main frame
146// ----------------------------------------------------------------------------
147
148// frame constructor
149MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
5014bb3a 150 : wxFrame(NULL, wxID_ANY, title, pos, size, style)
12fd305b 151{
3cb332c1 152 SetIcon(wxICON(sample));
12fd305b
VS
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;
2d143b66 159 helpMenu->Append(wxID_ABOUT, wxT("&About\tF1"), wxT("Show about dialog"));
12fd305b 160
9a83f860 161 menuFile->AppendCheckItem(ID_PlugProvider, wxT("&Plug-in art provider"), wxT("Enable custom art provider"));
ccb42cc5
VS
162 menuFile->AppendSeparator();
163
f07941fc 164#if wxUSE_LOG
9a83f860 165 menuFile->Append(ID_Logs, wxT("&Logging test"), wxT("Show some logging output"));
f07941fc 166#endif // wxUSE_LOG
9a83f860 167 menuFile->Append(ID_Browser, wxT("&Resources browser"), wxT("Browse all available icons"));
12fd305b 168 menuFile->AppendSeparator();
ccb42cc5 169
9a83f860 170 menuFile->Append(ID_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
12fd305b
VS
171
172 // now append the freshly created menu to the menu bar...
173 wxMenuBar *menuBar = new wxMenuBar();
9a83f860
VZ
174 menuBar->Append(menuFile, wxT("&File"));
175 menuBar->Append(helpMenu, wxT("&Help"));
12fd305b
VS
176
177 // ... and attach this menu bar to the frame
178 SetMenuBar(menuBar);
179}
180
181
182// event handlers
183
184void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
185{
5014bb3a
WS
186 // true is to force the frame to close
187 Close(true);
12fd305b
VS
188}
189
f07941fc 190#if wxUSE_LOG
12fd305b
VS
191void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
192{
9a83f860
VZ
193 wxLogMessage(wxT("Some information."));
194 wxLogError(wxT("This is an error."));
195 wxLogWarning(wxT("A warning."));
196 wxLogError(wxT("Yet another error."));
12fd305b 197 wxLog::GetActiveTarget()->Flush();
9a83f860 198 wxLogMessage(wxT("Check/uncheck 'File/Plug-in art provider' and try again."));
12fd305b 199}
f07941fc 200#endif // wxUSE_LOG
12fd305b
VS
201
202void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
203{
204 wxString msg;
9a83f860
VZ
205 msg.Printf( wxT("This is the about dialog of wxArtProvider sample.\n")
206 wxT("Welcome to %s"), wxVERSION_STRING);
12fd305b 207
9a83f860 208 wxMessageBox(msg, wxT("About wxArtProvider sample"),
aec18ff7 209 wxOK | wxICON_INFORMATION, this);
12fd305b 210}
ccb42cc5
VS
211
212void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
213{
214 wxArtBrowserDialog dlg(this);
215 dlg.ShowModal();
216}
217
218void MyFrame::OnPlugProvider(wxCommandEvent& event)
219{
220 if ( event.IsChecked() )
571d2e0f 221 wxArtProvider::Push(new MyArtProvider);
ccb42cc5 222 else
571d2e0f 223 wxArtProvider::Pop();
ccb42cc5 224}