]> git.saurik.com Git - wxWidgets.git/blame - samples/artprov/arttest.cpp
make wxArtProvider pure virtual (I was not so on
[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
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
23#ifndef __WXMSW__
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
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);
50 void OnLogs(wxCommandEvent& event);
ccb42cc5
VS
51 void OnBrowser(wxCommandEvent& event);
52 void OnPlugProvider(wxCommandEvent& event);
53
12fd305b
VS
54 DECLARE_EVENT_TABLE()
55};
56
57// ----------------------------------------------------------------------------
58// constants
59// ----------------------------------------------------------------------------
60
61// IDs for the controls and the menu commands
62enum
63{
64 ID_Quit = wxID_HIGHEST,
ccb42cc5
VS
65 ID_Logs,
66 ID_Browser,
67 ID_PlugProvider
12fd305b
VS
68};
69
70// ----------------------------------------------------------------------------
71// event tables and other macros for wxWindows
72// ----------------------------------------------------------------------------
73
74BEGIN_EVENT_TABLE(MyFrame, wxFrame)
ccb42cc5
VS
75 EVT_MENU(ID_Quit, MyFrame::OnQuit)
76 EVT_MENU(ID_Logs, MyFrame::OnLogs)
77 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
78 EVT_MENU(ID_Browser, MyFrame::OnBrowser)
79 EVT_MENU(ID_PlugProvider, MyFrame::OnPlugProvider)
12fd305b
VS
80END_EVENT_TABLE()
81
82IMPLEMENT_APP(MyApp)
83
84// ============================================================================
85// implementation
86// ============================================================================
87
88// ----------------------------------------------------------------------------
89// the application class
90// ----------------------------------------------------------------------------
91
92// 'Main program' equivalent: the program execution "starts" here
93bool MyApp::OnInit()
94{
95 // create the main application window
96 MyFrame *frame = new MyFrame(_T("wxArtProvider sample"),
97 wxPoint(50, 50), wxSize(450, 340));
98 frame->Show(TRUE);
99 return TRUE;
100}
101
ccb42cc5
VS
102// ----------------------------------------------------------------------------
103// custom art provider
104// ----------------------------------------------------------------------------
105
106class MyArtProvider : public wxArtProvider
107{
108protected:
109 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
110 const wxSize& size);
111};
112
113#include "info.xpm"
114#include "error.xpm"
115#include "warning.xpm"
116#include "question.xpm"
117
118wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,
119 const wxArtClient& client,
120 const wxSize& WXUNUSED(size))
121{
122 if ( client == wxART_MESSAGE_BOX )
123 {
124 if ( id == wxART_INFORMATION )
125 return wxBitmap(info_xpm);
126 if ( id == wxART_ERROR )
127 return wxBitmap(error_xpm);
128 if ( id == wxART_WARNING )
129 return wxBitmap(warning_xpm);
130 if ( id == wxART_QUESTION )
131 return wxBitmap(question_xpm);
132 }
133 return wxNullBitmap;
134}
135
136
137
12fd305b
VS
138// ----------------------------------------------------------------------------
139// main frame
140// ----------------------------------------------------------------------------
141
142// frame constructor
143MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
144 : wxFrame(NULL, -1, title, pos, size, style)
145{
146 SetIcon(wxICON(mondrian));
147
148 // create a menu bar
149 wxMenu *menuFile = new wxMenu;
150
151 // the "About" item should be in the help menu
152 wxMenu *helpMenu = new wxMenu;
153 helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show about dialog"));
154
ccb42cc5
VS
155 menuFile->AppendCheckItem(ID_PlugProvider, _T("&Plug-in art provider"), _T("Enable custom art provider"));
156 menuFile->AppendSeparator();
157
12fd305b 158 menuFile->Append(ID_Logs, _T("&Logging test"), _T("Show some logging output"));
ccb42cc5 159 menuFile->Append(ID_Browser, _T("&Resources browser"), _T("Browse all available icons"));
12fd305b 160 menuFile->AppendSeparator();
ccb42cc5 161
12fd305b
VS
162 menuFile->Append(ID_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
163
164 // now append the freshly created menu to the menu bar...
165 wxMenuBar *menuBar = new wxMenuBar();
166 menuBar->Append(menuFile, _T("&File"));
167 menuBar->Append(helpMenu, _T("&Help"));
168
169 // ... and attach this menu bar to the frame
170 SetMenuBar(menuBar);
171}
172
173
174// event handlers
175
176void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
177{
178 // TRUE is to force the frame to close
179 Close(TRUE);
180}
181
182void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
183{
184 wxLogMessage(_T("Some information."));
185 wxLogError(_T("This is an error."));
186 wxLogWarning(_T("A warning."));
187 wxLogError(_T("Yet another error."));
188 wxLog::GetActiveTarget()->Flush();
ccb42cc5 189 wxLogMessage(_T("Check/uncheck 'File/Plug-in art provider' and try again."));
12fd305b
VS
190}
191
192void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
193{
194 wxString msg;
195 msg.Printf( _T("This is the about dialog of wxArtProvider sample.\n")
196 _T("Welcome to %s"), wxVERSION_STRING);
197
198 wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
199}
ccb42cc5
VS
200
201void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
202{
203 wxArtBrowserDialog dlg(this);
204 dlg.ShowModal();
205}
206
207void MyFrame::OnPlugProvider(wxCommandEvent& event)
208{
209 if ( event.IsChecked() )
210 wxArtProvider::PushProvider(new MyArtProvider);
211 else
212 wxArtProvider::PopProvider();
213}