]> git.saurik.com Git - wxWidgets.git/blame - samples/artprov/arttest.cpp
Update wxHtmlWindow documentation to refer to wxWebView.
[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
7// RCS-ID: $Id$
8// Copyright: (c) Vaclav Slavik
526954c5 9// Licence: wxWindows licence
12fd305b
VS
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__)
3cb332c1 24 #include "../sample.xpm"
12fd305b
VS
25#endif
26
27#include "wx/artprov.h"
ccb42cc5 28#include "artbrows.h"
12fd305b
VS
29
30// ----------------------------------------------------------------------------
31// private classes
32// ----------------------------------------------------------------------------
33
34class MyApp : public wxApp
35{
36public:
37 virtual bool OnInit();
38};
39
40class MyFrame : public wxFrame
41{
42public:
43 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
44 long style = wxDEFAULT_FRAME_STYLE);
45
46private:
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
64enum
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
76BEGIN_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
84END_EVENT_TABLE()
85
86IMPLEMENT_APP(MyApp)
87
88// ============================================================================
89// implementation
90// ============================================================================
91
92// ----------------------------------------------------------------------------
93// the application class
94// ----------------------------------------------------------------------------
95
96// 'Main program' equivalent: the program execution "starts" here
97bool MyApp::OnInit()
98{
45e6e6f8
VZ
99 if ( !wxApp::OnInit() )
100 return false;
101
12fd305b 102 // create the main application window
9a83f860 103 MyFrame *frame = new MyFrame(wxT("wxArtProvider sample"),
12fd305b 104 wxPoint(50, 50), wxSize(450, 340));
5014bb3a
WS
105 frame->Show(true);
106 return true;
12fd305b
VS
107}
108
ccb42cc5
VS
109// ----------------------------------------------------------------------------
110// custom art provider
111// ----------------------------------------------------------------------------
112
113class MyArtProvider : public wxArtProvider
114{
115protected:
116 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
117 const wxSize& size);
118};
119
120#include "info.xpm"
121#include "error.xpm"
122#include "warning.xpm"
123#include "question.xpm"
124
125wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,
126 const wxArtClient& client,
127 const wxSize& WXUNUSED(size))
128{
129 if ( client == wxART_MESSAGE_BOX )
130 {
131 if ( id == wxART_INFORMATION )
132 return wxBitmap(info_xpm);
133 if ( id == wxART_ERROR )
134 return wxBitmap(error_xpm);
135 if ( id == wxART_WARNING )
136 return wxBitmap(warning_xpm);
137 if ( id == wxART_QUESTION )
138 return wxBitmap(question_xpm);
139 }
140 return wxNullBitmap;
141}
142
143
144
12fd305b
VS
145// ----------------------------------------------------------------------------
146// main frame
147// ----------------------------------------------------------------------------
148
149// frame constructor
150MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
5014bb3a 151 : wxFrame(NULL, wxID_ANY, title, pos, size, style)
12fd305b 152{
3cb332c1 153 SetIcon(wxICON(sample));
12fd305b
VS
154
155 // create a menu bar
156 wxMenu *menuFile = new wxMenu;
157
158 // the "About" item should be in the help menu
159 wxMenu *helpMenu = new wxMenu;
9a83f860 160 helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog"));
12fd305b 161
9a83f860 162 menuFile->AppendCheckItem(ID_PlugProvider, wxT("&Plug-in art provider"), wxT("Enable custom art provider"));
ccb42cc5
VS
163 menuFile->AppendSeparator();
164
f07941fc 165#if wxUSE_LOG
9a83f860 166 menuFile->Append(ID_Logs, wxT("&Logging test"), wxT("Show some logging output"));
f07941fc 167#endif // wxUSE_LOG
9a83f860 168 menuFile->Append(ID_Browser, wxT("&Resources browser"), wxT("Browse all available icons"));
12fd305b 169 menuFile->AppendSeparator();
ccb42cc5 170
9a83f860 171 menuFile->Append(ID_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
12fd305b
VS
172
173 // now append the freshly created menu to the menu bar...
174 wxMenuBar *menuBar = new wxMenuBar();
9a83f860
VZ
175 menuBar->Append(menuFile, wxT("&File"));
176 menuBar->Append(helpMenu, wxT("&Help"));
12fd305b
VS
177
178 // ... and attach this menu bar to the frame
179 SetMenuBar(menuBar);
180}
181
182
183// event handlers
184
185void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
186{
5014bb3a
WS
187 // true is to force the frame to close
188 Close(true);
12fd305b
VS
189}
190
f07941fc 191#if wxUSE_LOG
12fd305b
VS
192void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
193{
9a83f860
VZ
194 wxLogMessage(wxT("Some information."));
195 wxLogError(wxT("This is an error."));
196 wxLogWarning(wxT("A warning."));
197 wxLogError(wxT("Yet another error."));
12fd305b 198 wxLog::GetActiveTarget()->Flush();
9a83f860 199 wxLogMessage(wxT("Check/uncheck 'File/Plug-in art provider' and try again."));
12fd305b 200}
f07941fc 201#endif // wxUSE_LOG
12fd305b
VS
202
203void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
204{
205 wxString msg;
9a83f860
VZ
206 msg.Printf( wxT("This is the about dialog of wxArtProvider sample.\n")
207 wxT("Welcome to %s"), wxVERSION_STRING);
12fd305b 208
9a83f860 209 wxMessageBox(msg, wxT("About wxArtProvider sample"),
aec18ff7 210 wxOK | wxICON_INFORMATION, this);
12fd305b 211}
ccb42cc5
VS
212
213void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
214{
215 wxArtBrowserDialog dlg(this);
216 dlg.ShowModal();
217}
218
219void MyFrame::OnPlugProvider(wxCommandEvent& event)
220{
221 if ( event.IsChecked() )
571d2e0f 222 wxArtProvider::Push(new MyArtProvider);
ccb42cc5 223 else
571d2e0f 224 wxArtProvider::Pop();
ccb42cc5 225}