1999-07-07 22:04:58 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2009-02-08 01:20:35 +00:00
|
|
|
// Name: about.cpp
|
|
|
|
// Purpose: wxHtml sample: about dialog test
|
|
|
|
// Author: ?
|
|
|
|
// Modified by:
|
|
|
|
// Created: ?
|
|
|
|
// Copyright: (c) wxWidgets team
|
|
|
|
// Licence: wxWindows licence
|
1999-07-07 22:04:58 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
2001-10-30 13:33:34 +00:00
|
|
|
#include "wx/wxprec.h"
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
2004-05-25 11:20:37 +00:00
|
|
|
// need because it includes almost all "standard" wxWidgets headers
|
1999-07-07 22:04:58 +00:00
|
|
|
#ifndef WX_PRECOMP
|
2002-01-13 17:41:56 +00:00
|
|
|
#include "wx/wx.h"
|
1999-07-07 22:04:58 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-13 17:41:56 +00:00
|
|
|
#include "wx/image.h"
|
|
|
|
#include "wx/imagpng.h"
|
|
|
|
#include "wx/wxhtml.h"
|
|
|
|
#include "wx/statline.h"
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2012-03-04 00:28:58 +00:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-08 01:20:35 +00:00
|
|
|
#include "../../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-07-07 22:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
2006-09-10 17:07:10 +00:00
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
1999-07-07 22:04:58 +00:00
|
|
|
// override base class virtuals
|
|
|
|
// ----------------------------
|
1999-08-05 19:31:15 +00:00
|
|
|
|
1999-07-07 22:04:58 +00:00
|
|
|
// this one is called on application startup and is a good place for the app
|
|
|
|
// initialization (doing it here and not in the ctor allows to have an error
|
|
|
|
// return: if OnInit() returns false, the application terminates)
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2006-09-10 17:07:10 +00:00
|
|
|
};
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
// Define a new frame type: this is going to be our main frame
|
2006-09-10 17:07:10 +00:00
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
1999-07-07 22:04:58 +00:00
|
|
|
// ctor(s)
|
2006-09-10 17:07:10 +00:00
|
|
|
MyFrame(const wxString& title);
|
1999-08-05 19:31:15 +00:00
|
|
|
|
1999-07-07 22:04:58 +00:00
|
|
|
// event handlers (these functions should _not_ be virtual)
|
2006-09-10 17:07:10 +00:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
private:
|
2004-05-25 11:20:37 +00:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2006-09-10 17:07:10 +00:00
|
|
|
};
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-05-25 11:20:37 +00:00
|
|
|
// event tables and other macros for wxWidgets
|
1999-07-07 22:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-05-25 11:20:37 +00:00
|
|
|
// the event tables connect the wxWidgets events with the functions (event
|
1999-07-07 22:04:58 +00:00
|
|
|
// handlers) which process them. It can be also done at run-time, but for the
|
|
|
|
// simple menu events like this the static method is much simpler.
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2006-09-10 17:07:10 +00:00
|
|
|
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-09-10 17:07:10 +00:00
|
|
|
|
|
|
|
// Create a new application object: this macro will allow wxWidgets to create
|
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also declares the accessor function
|
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
|
|
|
// not wxApp)
|
2015-04-23 11:49:01 +00:00
|
|
|
wxIMPLEMENT_APP(MyApp);
|
2006-09-10 17:07:10 +00:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
1999-08-05 19:31:15 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
// `Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-04 00:34:18 +00:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
// we use a PNG image in our HTML page
|
|
|
|
wxImage::AddHandler(new wxPNGHandler);
|
|
|
|
|
|
|
|
// create and show the main application window
|
|
|
|
MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"));
|
|
|
|
frame->Show();
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
// success: wxApp::OnRun() will be called which will enter the main message
|
2004-05-21 11:29:38 +00:00
|
|
|
// loop and the application will run. If we returned false here, the
|
1999-07-07 22:04:58 +00:00
|
|
|
// application would exit immediately.
|
2006-09-10 17:07:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// frame constructor
|
2006-09-10 17:07:10 +00:00
|
|
|
MyFrame::MyFrame(const wxString& title)
|
|
|
|
: wxFrame((wxFrame *)NULL, wxID_ANY, title)
|
|
|
|
{
|
2009-02-08 01:20:35 +00:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
1999-07-07 22:04:58 +00:00
|
|
|
// create a menu bar
|
2006-09-10 17:07:10 +00:00
|
|
|
wxMenu *menuFile = new wxMenu;
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
menuFile->Append(wxID_ABOUT);
|
|
|
|
menuFile->Append(wxID_EXIT);
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
2006-09-10 17:07:10 +00:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append(menuFile, _("&File"));
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
2006-09-10 17:07:10 +00:00
|
|
|
SetMenuBar(menuBar);
|
|
|
|
}
|
1999-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-05-21 11:29:38 +00:00
|
|
|
// true is to force the frame to close
|
2006-09-10 17:07:10 +00:00
|
|
|
Close(true);
|
|
|
|
}
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBoxSizer *topsizer;
|
|
|
|
wxHtmlWindow *html;
|
|
|
|
wxDialog dlg(this, wxID_ANY, wxString(_("About")));
|
2000-01-16 00:31:59 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
topsizer = new wxBoxSizer(wxVERTICAL);
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
|
|
|
|
html -> SetBorders(0);
|
|
|
|
html -> LoadPage(wxT("data/about.htm"));
|
2014-04-29 20:35:40 +00:00
|
|
|
html -> SetInitialSize(wxSize(html -> GetInternalRepresentation() -> GetWidth(),
|
|
|
|
html -> GetInternalRepresentation() -> GetHeight()));
|
2000-01-16 00:31:59 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
topsizer -> Add(html, 1, wxALL, 10);
|
2000-01-16 00:31:59 +00:00
|
|
|
|
2004-07-22 19:14:29 +00:00
|
|
|
#if wxUSE_STATLINE
|
2006-09-10 17:07:10 +00:00
|
|
|
topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
|
2004-07-22 19:14:29 +00:00
|
|
|
#endif // wxUSE_STATLINE
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
|
|
|
|
bu1 -> SetDefault();
|
2000-01-16 00:31:59 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
|
2000-01-16 00:31:59 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
dlg.SetSizer(topsizer);
|
|
|
|
topsizer -> Fit(&dlg);
|
2000-01-16 00:31:59 +00:00
|
|
|
|
2006-09-10 17:07:10 +00:00
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
1999-07-07 22:04:58 +00:00
|
|
|
|