]> git.saurik.com Git - wxWidgets.git/blob - samples/html/help/help.cpp
Define __VISUALC__ for ICC under Windows again.
[wxWidgets.git] / samples / html / help / help.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: help.cpp
3 // Purpose: wxHtml sample: help test
4 // Author: ?
5 // Modified by:
6 // Created: ?
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 // for all others, include the necessary headers (this file is usually all you
19 // need because it includes almost all "standard" wxWidgets headers
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif
23
24 #include "wx/image.h"
25 #include "wx/html/helpfrm.h"
26 #include "wx/html/helpctrl.h"
27 #include "wx/filesys.h"
28 #include "wx/fs_zip.h"
29
30 #ifndef wxHAS_IMAGES_IN_RESOURCES
31 #include "../../sample.xpm"
32 #endif
33
34
35 // ----------------------------------------------------------------------------
36 // private classes
37 // ----------------------------------------------------------------------------
38
39
40 // Define a new application type, each program should derive a class from wxApp
41 class MyApp : public wxApp
42 {
43 public:
44 // override base class virtuals
45 // ----------------------------
46
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();
51 };
52
53
54
55 // Define a new frame type: this is going to be our main frame
56 class MyFrame : public wxFrame
57 {
58 public:
59 // ctor(s)
60 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
61
62 // event handlers (these functions should _not_ be virtual)
63 void OnQuit(wxCommandEvent& event);
64 void OnHelp(wxCommandEvent& event);
65 void OnClose(wxCloseEvent& event);
66 private:
67 wxHtmlHelpController help;
68
69 // any class wishing to process wxWidgets events must use this macro
70 DECLARE_EVENT_TABLE()
71 };
72
73 // ----------------------------------------------------------------------------
74 // constants
75 // ----------------------------------------------------------------------------
76
77 // IDs for the controls and the menu commands
78 enum
79 {
80 // menu items
81 Minimal_Quit = 1,
82 Minimal_Help
83 };
84
85 // ----------------------------------------------------------------------------
86 // event tables and other macros for wxWidgets
87 // ----------------------------------------------------------------------------
88
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)
96 END_EVENT_TABLE()
97
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
102 // not wxApp)
103 IMPLEMENT_APP(MyApp)
104
105 // ============================================================================
106 // implementation
107 // ============================================================================
108
109 // ----------------------------------------------------------------------------
110 // the application class
111 // ----------------------------------------------------------------------------
112 // `Main program' equivalent: the program execution "starts" here
113 bool MyApp::OnInit()
114 {
115 if ( !wxApp::OnInit() )
116 return false;
117
118 wxInitAllImageHandlers();
119 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
120 wxFileSystem::AddHandler(new wxZipFSHandler);
121 #endif
122 SetVendorName(wxT("wxWidgets"));
123 SetAppName(wxT("wxHTMLHelp"));
124
125 // Create the main application window
126 MyFrame *frame = new MyFrame(_("HTML Help Sample"),
127 wxDefaultPosition, wxDefaultSize);
128
129 // Show it
130 frame->Show(true);
131
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.
135 return true;
136 }
137
138 // ----------------------------------------------------------------------------
139 // main frame
140 // ----------------------------------------------------------------------------
141
142
143 // frame constructor
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)
147 {
148 SetIcon(wxICON(sample));
149
150 // create a menu bar
151 wxMenu *menuFile = new wxMenu;
152
153 menuFile->Append(Minimal_Help, _("&Help"));
154 menuFile->Append(Minimal_Quit, _("E&xit"));
155
156 // now append the freshly created menu to the menu bar...
157 wxMenuBar *menuBar = new wxMenuBar;
158 menuBar->Append(menuFile, _("&File"));
159
160 // ... and attach this menu bar to the frame
161 SetMenuBar(menuBar);
162
163 help.UseConfig(wxConfig::Get());
164 bool ret;
165 help.SetTempDir(wxT("."));
166 ret = help.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX));
167 if (! ret)
168 wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
169 ret = help.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX));
170 if (! ret)
171 wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
172 }
173
174
175 // event handlers
176
177 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
178 {
179 // true is to force the frame to close
180 Close(true);
181 }
182
183 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
184 {
185 help.Display(wxT("Test HELPFILE"));
186 }
187
188 void MyFrame::OnClose(wxCloseEvent& event)
189 {
190 // Close the help frame; this will cause the config data to
191 // get written.
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
195 event.Skip();
196 delete wxConfig::Set(NULL);
197 }
198
199
200