1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 /////////////////////////////////////////////////////////////////////////////
6 // For compilers that support precompilation, includes "wx/wx.h".
13 // for all others, include the necessary headers (this file is usually all you
14 // need because it includes almost all "standard" wxWidgets headers
20 #include "wx/html/helpfrm.h"
21 #include "wx/html/helpctrl.h"
22 #include "wx/filesys.h"
23 #include "wx/fs_zip.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
30 // Define a new application type, each program should derive a class from wxApp
31 class MyApp
: public wxApp
34 // override base class virtuals
35 // ----------------------------
37 // this one is called on application startup and is a good place for the app
38 // initialization (doing it here and not in the ctor allows to have an error
39 // return: if OnInit() returns false, the application terminates)
40 virtual bool OnInit();
45 // Define a new frame type: this is going to be our main frame
46 class MyFrame
: public wxFrame
50 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
52 // event handlers (these functions should _not_ be virtual)
53 void OnQuit(wxCommandEvent
& event
);
54 void OnHelp(wxCommandEvent
& event
);
55 void OnClose(wxCloseEvent
& event
);
57 wxHtmlHelpController help
;
59 // any class wishing to process wxWidgets events must use this macro
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // IDs for the controls and the menu commands
75 // ----------------------------------------------------------------------------
76 // event tables and other macros for wxWidgets
77 // ----------------------------------------------------------------------------
79 // the event tables connect the wxWidgets events with the functions (event
80 // handlers) which process them. It can be also done at run-time, but for the
81 // simple menu events like this the static method is much simpler.
82 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
83 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
84 EVT_MENU(Minimal_Help
, MyFrame::OnHelp
)
85 EVT_CLOSE(MyFrame::OnClose
)
88 // Create a new application object: this macro will allow wxWidgets to create
89 // the application object during program execution (it's better than using a
90 // static object for many reasons) and also declares the accessor function
91 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
95 // ============================================================================
97 // ============================================================================
99 // ----------------------------------------------------------------------------
100 // the application class
101 // ----------------------------------------------------------------------------
102 // `Main program' equivalent: the program execution "starts" here
105 if ( !wxApp::OnInit() )
108 wxInitAllImageHandlers();
109 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
110 wxFileSystem::AddHandler(new wxZipFSHandler
);
112 SetVendorName(wxT("wxWidgets"));
113 SetAppName(wxT("wxHTMLHelp"));
115 // Create the main application window
116 MyFrame
*frame
= new MyFrame(_("HTML Help Sample"),
117 wxDefaultPosition
, wxDefaultSize
);
119 // Show it and tell the application that it's our main window
120 // @@@ what does it do exactly, in fact? is it necessary here?
125 // success: wxApp::OnRun() will be called which will enter the main message
126 // loop and the application will run. If we returned false here, the
127 // application would exit immediately.
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
137 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
138 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
),
139 help(wxHF_DEFAULT_STYLE
| wxHF_OPEN_FILES
)
142 wxMenu
*menuFile
= new wxMenu
;
144 menuFile
->Append(Minimal_Help
, _("&Help"));
145 menuFile
->Append(Minimal_Quit
, _("E&xit"));
147 // now append the freshly created menu to the menu bar...
148 wxMenuBar
*menuBar
= new wxMenuBar
;
149 menuBar
->Append(menuFile
, _("&File"));
151 // ... and attach this menu bar to the frame
154 help
.UseConfig(wxConfig::Get());
156 help
.SetTempDir(wxT("."));
157 ret
= help
.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX
));
159 wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
160 ret
= help
.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX
));
162 wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
168 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
170 // true is to force the frame to close
174 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
176 help
.Display(wxT("Test HELPFILE"));
179 void MyFrame::OnClose(wxCloseEvent
& event
)
181 // Close the help frame; this will cause the config data to
183 if ( help
.GetFrame() ) // returns NULL if no help frame active
184 help
.GetFrame()->Close(true);
185 // now we can safely delete the config pointer
187 delete wxConfig::Set(NULL
);