1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample: help test
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 // for all others, include the necessary headers (this file is usually all you
19 // need because it includes almost all "standard" wxWidgets headers
25 #include "wx/html/helpfrm.h"
26 #include "wx/html/helpctrl.h"
27 #include "wx/filesys.h"
28 #include "wx/fs_zip.h"
30 #ifndef wxHAS_IMAGES_IN_RESOURCES
31 #include "../../sample.xpm"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
40 // Define a new application type, each program should derive a class from wxApp
41 class MyApp
: public wxApp
44 // override base class virtuals
45 // ----------------------------
47 // this one is called on application startup and is a good place for the app
48 // initialization (doing it here and not in the ctor allows to have an error
49 // return: if OnInit() returns false, the application terminates)
50 virtual bool OnInit();
55 // Define a new frame type: this is going to be our main frame
56 class MyFrame
: public wxFrame
60 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
62 // event handlers (these functions should _not_ be virtual)
63 void OnQuit(wxCommandEvent
& event
);
64 void OnHelp(wxCommandEvent
& event
);
65 void OnClose(wxCloseEvent
& event
);
67 wxHtmlHelpController help
;
69 // any class wishing to process wxWidgets events must use this macro
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 // IDs for the controls and the menu commands
85 // ----------------------------------------------------------------------------
86 // event tables and other macros for wxWidgets
87 // ----------------------------------------------------------------------------
89 // the event tables connect the wxWidgets events with the functions (event
90 // handlers) which process them. It can be also done at run-time, but for the
91 // simple menu events like this the static method is much simpler.
92 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
93 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
94 EVT_MENU(Minimal_Help
, MyFrame::OnHelp
)
95 EVT_CLOSE(MyFrame::OnClose
)
98 // Create a new application object: this macro will allow wxWidgets to create
99 // the application object during program execution (it's better than using a
100 // static object for many reasons) and also declares the accessor function
101 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
105 // ============================================================================
107 // ============================================================================
109 // ----------------------------------------------------------------------------
110 // the application class
111 // ----------------------------------------------------------------------------
112 // `Main program' equivalent: the program execution "starts" here
115 if ( !wxApp::OnInit() )
118 wxInitAllImageHandlers();
119 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
120 wxFileSystem::AddHandler(new wxZipFSHandler
);
122 SetVendorName(wxT("wxWidgets"));
123 SetAppName(wxT("wxHTMLHelp"));
125 // Create the main application window
126 MyFrame
*frame
= new MyFrame(_("HTML Help Sample"),
127 wxDefaultPosition
, wxDefaultSize
);
132 // success: wxApp::OnRun() will be called which will enter the main message
133 // loop and the application will run. If we returned false here, the
134 // application would exit immediately.
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
144 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
145 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
),
146 help(wxHF_DEFAULT_STYLE
| wxHF_OPEN_FILES
)
148 SetIcon(wxICON(sample
));
151 wxMenu
*menuFile
= new wxMenu
;
153 menuFile
->Append(Minimal_Help
, _("&Help"));
154 menuFile
->Append(Minimal_Quit
, _("E&xit"));
156 // now append the freshly created menu to the menu bar...
157 wxMenuBar
*menuBar
= new wxMenuBar
;
158 menuBar
->Append(menuFile
, _("&File"));
160 // ... and attach this menu bar to the frame
163 help
.UseConfig(wxConfig::Get());
165 help
.SetTempDir(wxT("."));
166 ret
= help
.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX
));
168 wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
169 ret
= help
.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX
));
171 wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
177 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
179 // true is to force the frame to close
183 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
185 help
.Display(wxT("Test HELPFILE"));
188 void MyFrame::OnClose(wxCloseEvent
& event
)
190 // Close the help frame; this will cause the config data to
192 if ( help
.GetFrame() ) // returns NULL if no help frame active
193 help
.GetFrame()->Close(true);
194 // now we can safely delete the config pointer
196 delete wxConfig::Set(NULL
);