2002-03-25 18:28:46 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: arttest.cpp
|
|
|
|
// Purpose: wxArtProvider sample
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2002/03/25
|
|
|
|
// Copyright: (c) Vaclav Slavik
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2002-03-25 18:28:46 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2010-06-20 13:42:33 -04:00
|
|
|
#include "../sample.xpm"
|
2002-03-25 18:28:46 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/artprov.h"
|
2002-04-06 09:55:16 -05:00
|
|
|
#include "artbrows.h"
|
2002-03-25 18:28:46 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2002-03-25 18:28:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2004-07-20 15:11:34 -04:00
|
|
|
#if wxUSE_LOG
|
2002-03-25 18:28:46 -05:00
|
|
|
void OnLogs(wxCommandEvent& event);
|
2004-07-20 15:11:34 -04:00
|
|
|
#endif // wxUSE_LOG
|
2002-04-06 09:55:16 -05:00
|
|
|
void OnBrowser(wxCommandEvent& event);
|
|
|
|
void OnPlugProvider(wxCommandEvent& event);
|
2005-08-23 11:54:39 -04:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2002-03-25 18:28:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
2012-05-02 14:44:23 -04:00
|
|
|
ID_Quit = wxID_EXIT,
|
|
|
|
ID_Logs = wxID_HIGHEST+1,
|
2002-04-06 09:55:16 -05:00
|
|
|
ID_Browser,
|
|
|
|
ID_PlugProvider
|
2002-03-25 18:28:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// event tables and other macros for wxWidgets
|
2002-03-25 18:28:46 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2002-04-06 09:55:16 -05:00
|
|
|
EVT_MENU(ID_Quit, MyFrame::OnQuit)
|
2004-07-20 15:11:34 -04:00
|
|
|
#if wxUSE_LOG
|
2002-04-06 09:55:16 -05:00
|
|
|
EVT_MENU(ID_Logs, MyFrame::OnLogs)
|
2004-07-20 15:11:34 -04:00
|
|
|
#endif // wxUSE_LOG
|
2002-04-06 09:55:16 -05:00
|
|
|
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(ID_Browser, MyFrame::OnBrowser)
|
|
|
|
EVT_MENU(ID_PlugProvider, MyFrame::OnPlugProvider)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2002-03-25 18:28:46 -05:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_APP(MyApp);
|
2002-03-25 18:28:46 -05:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2002-03-25 18:28:46 -05:00
|
|
|
// create the main application window
|
2018-09-22 19:15:08 -04:00
|
|
|
MyFrame *frame = new MyFrame("wxArtProvider sample",
|
2002-03-25 18:28:46 -05:00
|
|
|
wxPoint(50, 50), wxSize(450, 340));
|
2004-05-27 13:50:54 -04:00
|
|
|
frame->Show(true);
|
|
|
|
return true;
|
2002-03-25 18:28:46 -05:00
|
|
|
}
|
|
|
|
|
2002-04-06 09:55:16 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// custom art provider
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyArtProvider : public wxArtProvider
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
|
2014-03-29 20:02:23 -04:00
|
|
|
const wxSize& size) wxOVERRIDE;
|
2002-04-06 09:55:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-25 18:28:46 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// frame constructor
|
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
|
2004-05-27 13:50:54 -04:00
|
|
|
: wxFrame(NULL, wxID_ANY, title, pos, size, style)
|
2002-03-25 18:28:46 -05:00
|
|
|
{
|
2010-06-20 13:42:33 -04:00
|
|
|
SetIcon(wxICON(sample));
|
2002-03-25 18:28:46 -05:00
|
|
|
|
|
|
|
// create a menu bar
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
|
|
|
|
// the "About" item should be in the help menu
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
2018-09-22 19:15:08 -04:00
|
|
|
helpMenu->Append(wxID_ABOUT, "&About\tF1", "Show about dialog");
|
2002-03-25 18:28:46 -05:00
|
|
|
|
2018-09-22 19:15:08 -04:00
|
|
|
menuFile->AppendCheckItem(ID_PlugProvider, "&Plug-in art provider", "Enable custom art provider");
|
2002-04-06 09:55:16 -05:00
|
|
|
menuFile->AppendSeparator();
|
|
|
|
|
2004-07-20 15:11:34 -04:00
|
|
|
#if wxUSE_LOG
|
2018-09-22 19:15:08 -04:00
|
|
|
menuFile->Append(ID_Logs, "&Logging test", "Show some logging output");
|
2004-07-20 15:11:34 -04:00
|
|
|
#endif // wxUSE_LOG
|
2018-09-22 19:15:08 -04:00
|
|
|
menuFile->Append(ID_Browser, "&Resources browser", "Browse all available icons");
|
2002-03-25 18:28:46 -05:00
|
|
|
menuFile->AppendSeparator();
|
2002-04-06 09:55:16 -05:00
|
|
|
|
2018-09-22 19:15:08 -04:00
|
|
|
menuFile->Append(ID_Quit, "E&xit\tAlt-X", "Quit this program");
|
2002-03-25 18:28:46 -05:00
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
2018-09-22 19:15:08 -04:00
|
|
|
menuBar->Append(menuFile, "&File");
|
|
|
|
menuBar->Append(helpMenu, "&Help");
|
2002-03-25 18:28:46 -05:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-05-27 13:50:54 -04:00
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
2002-03-25 18:28:46 -05:00
|
|
|
}
|
|
|
|
|
2004-07-20 15:11:34 -04:00
|
|
|
#if wxUSE_LOG
|
2002-03-25 18:28:46 -05:00
|
|
|
void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2018-09-22 19:15:08 -04:00
|
|
|
wxLogMessage("Some information.");
|
|
|
|
wxLogError("This is an error.");
|
|
|
|
wxLogWarning("A warning.");
|
|
|
|
wxLogError("Yet another error.");
|
2002-03-25 18:28:46 -05:00
|
|
|
wxLog::GetActiveTarget()->Flush();
|
2018-09-22 19:15:08 -04:00
|
|
|
wxLogMessage("Check/uncheck 'File/Plug-in art provider' and try again.");
|
2002-03-25 18:28:46 -05:00
|
|
|
}
|
2004-07-20 15:11:34 -04:00
|
|
|
#endif // wxUSE_LOG
|
2002-03-25 18:28:46 -05:00
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString msg;
|
2018-09-22 19:15:08 -04:00
|
|
|
msg.Printf( "This is the about dialog of wxArtProvider sample.\n"
|
|
|
|
"Welcome to %s", wxVERSION_STRING);
|
2002-03-25 18:28:46 -05:00
|
|
|
|
2018-09-22 19:15:08 -04:00
|
|
|
wxMessageBox(msg, "About wxArtProvider sample",
|
2002-08-01 15:12:24 -04:00
|
|
|
wxOK | wxICON_INFORMATION, this);
|
2002-03-25 18:28:46 -05:00
|
|
|
}
|
2002-04-06 09:55:16 -05:00
|
|
|
|
|
|
|
void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxArtBrowserDialog dlg(this);
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnPlugProvider(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.IsChecked() )
|
2006-09-23 16:16:18 -04:00
|
|
|
wxArtProvider::Push(new MyArtProvider);
|
2002-04-06 09:55:16 -05:00
|
|
|
else
|
2006-09-23 16:16:18 -04:00
|
|
|
wxArtProvider::Pop();
|
2002-04-06 09:55:16 -05:00
|
|
|
}
|