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