2 /////////////////////////////////////////////////////////////////////////////
4 // Purpose: wxHtml testing example
5 /////////////////////////////////////////////////////////////////////////////
8 #pragma implementation "help.cpp"
9 #pragma interface "help.cpp"
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include <wx/wxprec.h>
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWindows headers
26 #include <wx/wxhtml.h>
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
33 // Define a new application type, each program should derive a class from wxApp
34 class MyApp
: public wxApp
37 // override base class virtuals
38 // ----------------------------
40 // this one is called on application startup and is a good place for the app
41 // initialization (doing it here and not in the ctor allows to have an error
42 // return: if OnInit() returns false, the application terminates)
43 virtual bool OnInit();
48 // Define a new frame type: this is going to be our main frame
49 class MyFrame
: public wxFrame
53 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
55 // event handlers (these functions should _not_ be virtual)
56 void OnQuit(wxCommandEvent
& event
);
57 void OnHelp(wxCommandEvent
& event
);
58 void OnClose(wxCloseEvent
& event
);
60 wxHtmlHelpController help
;
63 // any class wishing to process wxWindows events must use this macro
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // IDs for the controls and the menu commands
79 // ----------------------------------------------------------------------------
80 // event tables and other macros for wxWindows
81 // ----------------------------------------------------------------------------
83 // the event tables connect the wxWindows events with the functions (event
84 // handlers) which process them. It can be also done at run-time, but for the
85 // simple menu events like this the static method is much simpler.
86 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
87 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
88 EVT_MENU(Minimal_Help
, MyFrame::OnHelp
)
89 EVT_CLOSE(MyFrame::OnClose
)
92 // Create a new application object: this macro will allow wxWindows to create
93 // the application object during program execution (it's better than using a
94 // static object for many reasons) and also declares the accessor function
95 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
99 // ============================================================================
101 // ============================================================================
103 // ----------------------------------------------------------------------------
104 // the application class
105 // ----------------------------------------------------------------------------
106 // `Main program' equivalent: the program execution "starts" here
110 wxImage::AddHandler(new wxPNGHandler
);
113 wxImage::AddHandler(new wxJPEGHandler
);
116 // Create the main application window
117 MyFrame
*frame
= new MyFrame("HTML Help Sample",
118 wxPoint(50, 50), wxSize(150, 50));
120 // Show it and tell the application that it's our main window
121 // @@@ what does it do exactly, in fact? is it necessary here?
126 // success: wxApp::OnRun() will be called which will enter the main message
127 // loop and the application will run. If we returned FALSE here, the
128 // application would exit immediately.
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
138 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
139 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
), help()
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 config
= new wxConfig("wxHTMLhelp");
156 help
.UseConfig(config
);
158 ret
= help
.AddBook("helpfiles/testing.hhp");
160 wxMessageBox("Failed adding book helpfiles/testing.hhp");
161 ret
= help
.AddBook("helpfiles/another.hhp");
163 wxMessageBox("Failed adding book helpfiles/another.hhp");
169 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
171 // TRUE is to force the frame to close
175 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
177 help
.Display("Main page");
180 void MyFrame::OnClose(wxCloseEvent
& event
)
182 // Close the help frame; this will cause the config data to
184 if ( help
.GetFrame() ) // returns NULL if no help frame active
185 help
.GetFrame()->Close(TRUE
);
186 // now we can safely delete the config pointer