1/////////////////////////////////////////////////////////////////////////////
2// Name:        helpview.cpp
3// Purpose:     wxHtml help browser
4// Please note: see utils/helpview for a more fully-featured
5// standalone help browser.
6/////////////////////////////////////////////////////////////////////////////
7
8// For compilers that support precompilation, includes "wx/wx.h".
9#include "wx/wxprec.h"
10
11#ifdef __BORLANDC__
12#pragma hdrstop
13#endif
14
15// for all others, include the necessary headers (this file is usually all you
16// need because it includes almost all "standard" wxWidgets headers
17#ifndef WX_PRECOMP
18#include "wx/wx.h"
19#endif
20
21#include "wx/image.h"
22#include "wx/wxhtml.h"
23#include "wx/fs_zip.h"
24#include "wx/log.h"
25#include "wx/filedlg.h"
26
27// ----------------------------------------------------------------------------
28// private classes
29// ----------------------------------------------------------------------------
30
31
32// Define a new application type, each program should derive a class from wxApp
33class MyApp : public wxApp
34{
35    public:
36        // override base class virtuals
37        // ----------------------------
38
39        // this one is called on application startup and is a good place for the app
40        // initialization (doing it here and not in the ctor allows to have an error
41        // return: if OnInit() returns false, the application terminates)
42
43        virtual bool OnInit();
44        virtual int OnExit();
45
46        /// Respond to idle event
47        void OnIdle(wxIdleEvent& event);
48
49private:
50        bool                    m_exitIfNoMainWindow;
51        wxHtmlHelpController *  help;
52DECLARE_EVENT_TABLE()
53};
54
55
56IMPLEMENT_APP(MyApp)
57
58BEGIN_EVENT_TABLE(MyApp, wxApp)
59    EVT_IDLE(MyApp::OnIdle)
60END_EVENT_TABLE()
61
62bool MyApp::OnInit()
63{
64    m_exitIfNoMainWindow = false;
65#ifdef __WXMOTIF__
66    delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
67#endif
68
69    // Don't exit on frame deletion, since the help window is programmed
70    // to cause the app to exit even if it is still open. We need to have the app
71    // close by other means.
72    SetExitOnFrameDelete(false);
73
74    wxInitAllImageHandlers();
75    wxFileSystem::AddHandler(new wxZipFSHandler);
76
77    SetVendorName(wxT("wxWidgets"));
78    SetAppName(wxT("wxHTMLHelp"));
79    wxConfig::Get(); // create an instance
80
81    help = new wxHtmlHelpController(wxHF_DEFAULT_STYLE|wxHF_OPEN_FILES);
82
83    if (argc < 2) {
84        wxLogError(wxT("Usage : helpview <helpfile> [<more helpfiles>]"));
85        wxLogError(wxT("  helpfile may be .hhp, .zip or .htb"));
86        return false;
87    }
88
89    for (int i = 1; i < argc; i++)
90        help->AddBook(wxFileName(argv[i]));
91
92#ifdef __WXMOTIF__
93    delete wxLog::SetActiveTarget(new wxLogGui);
94#endif
95
96    help -> DisplayContents();
97    SetTopWindow(help->GetFrame());
98    m_exitIfNoMainWindow = true;
99
100    return true;
101}
102
103void MyApp::OnIdle(wxIdleEvent& event)
104{
105    if (m_exitIfNoMainWindow && !GetTopWindow())
106        ExitMainLoop();
107
108    event.Skip();
109    event.RequestMore();
110}
111
112int MyApp::OnExit()
113{
114    delete help;
115    delete wxConfig::Set(NULL);
116
117    return 0;
118}
119
120