]> git.saurik.com Git - wxWidgets.git/blob - samples/html/help/help.cpp
Remove GtkPrintOperation preview signal handler.
[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 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
21 #ifndef WX_PRECOMP
22 #include "wx/wx.h"
23 #endif
24
25 #include "wx/image.h"
26 #include "wx/html/helpfrm.h"
27 #include "wx/html/helpctrl.h"
28 #include "wx/filesys.h"
29 #include "wx/fs_zip.h"
30
31 #ifndef __WXMSW__
32 #include "../../sample.xpm"
33 #endif
34
35
36 // ----------------------------------------------------------------------------
37 // private classes
38 // ----------------------------------------------------------------------------
39
40
41 // Define a new application type, each program should derive a class from wxApp
42 class MyApp : public wxApp
43 {
44 public:
45 // override base class virtuals
46 // ----------------------------
47
48 // this one is called on application startup and is a good place for the app
49 // initialization (doing it here and not in the ctor allows to have an error
50 // return: if OnInit() returns false, the application terminates)
51 virtual bool OnInit();
52 };
53
54
55
56 // Define a new frame type: this is going to be our main frame
57 class MyFrame : public wxFrame
58 {
59 public:
60 // ctor(s)
61 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
62
63 // event handlers (these functions should _not_ be virtual)
64 void OnQuit(wxCommandEvent& event);
65 void OnHelp(wxCommandEvent& event);
66 void OnClose(wxCloseEvent& event);
67 private:
68 wxHtmlHelpController help;
69
70 // any class wishing to process wxWidgets events must use this macro
71 DECLARE_EVENT_TABLE()
72 };
73
74 // ----------------------------------------------------------------------------
75 // constants
76 // ----------------------------------------------------------------------------
77
78 // IDs for the controls and the menu commands
79 enum
80 {
81 // menu items
82 Minimal_Quit = 1,
83 Minimal_Help
84 };
85
86 // ----------------------------------------------------------------------------
87 // event tables and other macros for wxWidgets
88 // ----------------------------------------------------------------------------
89
90 // the event tables connect the wxWidgets events with the functions (event
91 // handlers) which process them. It can be also done at run-time, but for the
92 // simple menu events like this the static method is much simpler.
93 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
94 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
95 EVT_MENU(Minimal_Help, MyFrame::OnHelp)
96 EVT_CLOSE(MyFrame::OnClose)
97 END_EVENT_TABLE()
98
99 // Create a new application object: this macro will allow wxWidgets to create
100 // the application object during program execution (it's better than using a
101 // static object for many reasons) and also declares the accessor function
102 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
103 // not wxApp)
104 IMPLEMENT_APP(MyApp)
105
106 // ============================================================================
107 // implementation
108 // ============================================================================
109
110 // ----------------------------------------------------------------------------
111 // the application class
112 // ----------------------------------------------------------------------------
113 // `Main program' equivalent: the program execution "starts" here
114 bool MyApp::OnInit()
115 {
116 if ( !wxApp::OnInit() )
117 return false;
118
119 wxInitAllImageHandlers();
120 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
121 wxFileSystem::AddHandler(new wxZipFSHandler);
122 #endif
123 SetVendorName(wxT("wxWidgets"));
124 SetAppName(wxT("wxHTMLHelp"));
125
126 // Create the main application window
127 MyFrame *frame = new MyFrame(_("HTML Help Sample"),
128 wxDefaultPosition, wxDefaultSize);
129
130 // Show it and tell the application that it's our main window
131 // @@@ what does it do exactly, in fact? is it necessary here?
132 frame->Show(true);
133 SetTopWindow(frame);
134
135
136 // success: wxApp::OnRun() will be called which will enter the main message
137 // loop and the application will run. If we returned false here, the
138 // application would exit immediately.
139 return true;
140 }
141
142 // ----------------------------------------------------------------------------
143 // main frame
144 // ----------------------------------------------------------------------------
145
146
147 // frame constructor
148 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
149 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size),
150 help(wxHF_DEFAULT_STYLE | wxHF_OPEN_FILES)
151 {
152 SetIcon(wxICON(sample));
153
154 // create a menu bar
155 wxMenu *menuFile = new wxMenu;
156
157 menuFile->Append(Minimal_Help, _("&Help"));
158 menuFile->Append(Minimal_Quit, _("E&xit"));
159
160 // now append the freshly created menu to the menu bar...
161 wxMenuBar *menuBar = new wxMenuBar;
162 menuBar->Append(menuFile, _("&File"));
163
164 // ... and attach this menu bar to the frame
165 SetMenuBar(menuBar);
166
167 help.UseConfig(wxConfig::Get());
168 bool ret;
169 help.SetTempDir(wxT("."));
170 ret = help.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX));
171 if (! ret)
172 wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
173 ret = help.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX));
174 if (! ret)
175 wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
176 }
177
178
179 // event handlers
180
181 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
182 {
183 // true is to force the frame to close
184 Close(true);
185 }
186
187 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
188 {
189 help.Display(wxT("Test HELPFILE"));
190 }
191
192 void MyFrame::OnClose(wxCloseEvent& event)
193 {
194 // Close the help frame; this will cause the config data to
195 // get written.
196 if ( help.GetFrame() ) // returns NULL if no help frame active
197 help.GetFrame()->Close(true);
198 // now we can safely delete the config pointer
199 event.Skip();
200 delete wxConfig::Set(NULL);
201 }
202
203
204