]>
Commit | Line | Data |
---|---|---|
62877de0 VS |
1 | |
2 | ///////////////////////////////////////////////////////////////////////////// | |
3 | // Name: helpview.cpp | |
4 | // Purpose: wxHtml help browser | |
5 | ///////////////////////////////////////////////////////////////////////////// | |
6 | ||
7 | #ifdef __GNUG__ | |
8 | #pragma implementation "help.cpp" | |
9 | #pragma interface "help.cpp" | |
10 | #endif | |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
92a19c2e | 13 | #include "wx/wxprec.h" |
62877de0 VS |
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" wxWindows headers | |
21 | #ifndef WX_PRECOMP | |
67547666 | 22 | #include "wx/wx.h" |
62877de0 VS |
23 | #endif |
24 | ||
67547666 GD |
25 | #include "wx/image.h" |
26 | #include "wx/wxhtml.h" | |
27 | #include "wx/fs_zip.h" | |
28 | #include "wx/log.h" | |
7414c52c JS |
29 | #include "wx/artprov.h" |
30 | #include "wx/filedlg.h" | |
31 | ||
32 | // Set to 1 to: | |
33 | // | |
34 | // - provide different icons. | |
35 | // - add an open file icon for the toolbar. | |
36 | // - use a flat toolbar style. | |
37 | // - show a file selector if no file was given on the command line. | |
38 | // - remove 'Help:' from the title bar. | |
39 | // | |
40 | // Set to 0 to revert to previous behaviour. | |
41 | ||
42 | #define USE_ALTERNATE_UI 0 | |
43 | ||
44 | #if USE_ALTERNATE_UI | |
45 | class AlternateArtProvider : public wxArtProvider | |
46 | { | |
47 | protected: | |
48 | virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, | |
49 | const wxSize& size); | |
50 | }; | |
51 | #endif | |
62877de0 VS |
52 | |
53 | // ---------------------------------------------------------------------------- | |
54 | // private classes | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
57 | ||
58 | // Define a new application type, each program should derive a class from wxApp | |
59 | class MyApp : public wxApp | |
60 | { | |
61 | public: | |
62 | // override base class virtuals | |
63 | // ---------------------------- | |
64 | ||
65 | // this one is called on application startup and is a good place for the app | |
66 | // initialization (doing it here and not in the ctor allows to have an error | |
67 | // return: if OnInit() returns false, the application terminates) | |
68 | ||
69 | virtual bool OnInit(); | |
70 | virtual int OnExit(); | |
71 | ||
7414c52c JS |
72 | // Prompt the user for a book to open |
73 | bool OpenBook(wxHtmlHelpController* controller); | |
74 | ||
62877de0 VS |
75 | private: |
76 | wxHtmlHelpController *help; | |
62877de0 VS |
77 | }; |
78 | ||
79 | ||
80 | IMPLEMENT_APP(MyApp) | |
81 | ||
82 | ||
83 | bool MyApp::OnInit() | |
84 | { | |
6adaedf0 JS |
85 | #ifdef __WXMOTIF__ |
86 | delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used | |
87 | #endif | |
88 | ||
7414c52c JS |
89 | #if USE_ALTERNATE_UI |
90 | wxArtProvider::PushProvider(new AlternateArtProvider); | |
91 | #endif | |
92 | ||
62877de0 VS |
93 | wxInitAllImageHandlers(); |
94 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
95 | ||
5612e524 VS |
96 | SetVendorName("wxWindows"); |
97 | SetAppName("wxHTMLHelp"); | |
98 | wxConfig::Get(); // create an instance | |
99 | ||
7414c52c JS |
100 | help = new wxHtmlHelpController( |
101 | #if USE_ALTERNATE_UI | |
102 | wxHF_DEFAULT_STYLE|wxHF_FLAT_TOOLBAR|wxHF_OPEN_FILES | |
103 | #endif | |
104 | ); | |
62877de0 | 105 | |
7414c52c JS |
106 | #if USE_ALTERNATE_UI |
107 | help->SetTitleFormat(wxT("%s")); | |
108 | if (argc < 2) { | |
109 | if (!OpenBook(help)) | |
110 | return FALSE; | |
111 | } | |
112 | #else | |
62877de0 | 113 | if (argc < 2) { |
4693b20c MB |
114 | wxLogError(wxT("Usage : helpview <helpfile> [<more helpfiles>]")); |
115 | wxLogError(wxT(" helpfile may be .hhp, .zip or .htb")); | |
62877de0 VS |
116 | return FALSE; |
117 | } | |
7414c52c | 118 | #endif |
62877de0 VS |
119 | |
120 | for (int i = 1; i < argc; i++) | |
121 | help -> AddBook(argv[i]); | |
122 | ||
6adaedf0 JS |
123 | #ifdef __WXMOTIF__ |
124 | delete wxLog::SetActiveTarget(new wxLogGui); | |
125 | #endif | |
126 | ||
62877de0 VS |
127 | help -> DisplayContents(); |
128 | ||
129 | return TRUE; | |
130 | } | |
131 | ||
132 | ||
133 | int MyApp::OnExit() | |
134 | { | |
135 | delete help; | |
5612e524 | 136 | delete wxConfig::Set(NULL); |
62877de0 VS |
137 | |
138 | return 0; | |
139 | } | |
140 | ||
7414c52c JS |
141 | bool MyApp::OpenBook(wxHtmlHelpController* controller) |
142 | { | |
143 | wxString s = wxFileSelector(_("Open help file"), | |
144 | wxGetCwd(), | |
145 | wxEmptyString, | |
146 | wxEmptyString, | |
147 | _( | |
148 | "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\ | |
149 | HTML Help Project (*.hhp)|*.hhp"), | |
150 | wxOPEN | wxFILE_MUST_EXIST, | |
151 | NULL); | |
152 | ||
153 | if (!s.IsEmpty()) | |
154 | { | |
155 | wxString ext = s.Right(4).Lower(); | |
156 | if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp")) | |
157 | { | |
158 | wxBusyCursor bcur; | |
159 | controller->AddBook(s); | |
160 | return TRUE; | |
161 | } | |
162 | } | |
163 | return FALSE; | |
164 | } | |
165 | ||
166 | #if USE_ALTERNATE_UI | |
167 | ||
168 | /* | |
169 | * Art provider class | |
170 | */ | |
171 | ||
172 | // --------------------------------------------------------------------- | |
173 | // helper macros | |
174 | // --------------------------------------------------------------------- | |
175 | ||
176 | // Standard macro for getting a resource from XPM file: | |
177 | #define ART(artId, xpmRc) \ | |
178 | if ( id == artId ) return wxBitmap(xpmRc##_xpm); | |
179 | ||
180 | // Compatibility hack to use wxApp::GetStdIcon of overriden by the user | |
181 | #if WXWIN_COMPATIBILITY_2_2 | |
182 | #define GET_STD_ICON_FROM_APP(iconId) \ | |
183 | if ( client == wxART_MESSAGE_BOX ) \ | |
184 | { \ | |
185 | wxIcon icon = wxTheApp->GetStdIcon(iconId); \ | |
186 | if ( icon.Ok() ) \ | |
187 | { \ | |
188 | wxBitmap bmp; \ | |
189 | bmp.CopyFromIcon(icon); \ | |
190 | return bmp; \ | |
191 | } \ | |
192 | } | |
193 | #else | |
194 | #define GET_STD_ICON_FROM_APP(iconId) | |
195 | #endif | |
196 | ||
197 | // There are two ways of getting the standard icon: either via XPMs or via | |
198 | // wxIcon ctor. This depends on the platform: | |
199 | #if defined(__WXUNIVERSAL__) | |
200 | #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap; | |
201 | #elif defined(__WXGTK__) || defined(__WXMOTIF__) | |
202 | #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm); | |
203 | #else | |
204 | #define CREATE_STD_ICON(iconId, xpmRc) \ | |
205 | { \ | |
206 | wxIcon icon(_T(iconId)); \ | |
207 | wxBitmap bmp; \ | |
208 | bmp.CopyFromIcon(icon); \ | |
209 | return bmp; \ | |
210 | } | |
211 | #endif | |
212 | ||
213 | // Macro used in CreateBitmap to get wxICON_FOO icons: | |
214 | #define ART_MSGBOX(artId, iconId, xpmRc) \ | |
215 | if ( id == artId ) \ | |
216 | { \ | |
217 | GET_STD_ICON_FROM_APP(iconId) \ | |
218 | CREATE_STD_ICON(#iconId, xpmRc) \ | |
219 | } | |
220 | ||
221 | // --------------------------------------------------------------------- | |
222 | // XPMs with the art | |
223 | // --------------------------------------------------------------------- | |
224 | ||
225 | // XPM hack: make the arrays const | |
226 | //#define static static const | |
227 | ||
228 | #include "bitmaps/helpback.xpm" | |
229 | #include "bitmaps/helpbook.xpm" | |
230 | #include "bitmaps/helpdown.xpm" | |
231 | #include "bitmaps/helpforward.xpm" | |
232 | #include "bitmaps/helpoptions.xpm" | |
233 | #include "bitmaps/helppage.xpm" | |
234 | #include "bitmaps/helpsidepanel.xpm" | |
235 | #include "bitmaps/helpup.xpm" | |
236 | #include "bitmaps/helpuplevel.xpm" | |
237 | #include "bitmaps/helpicon.xpm" | |
238 | #include "bitmaps/helpopen.xpm" | |
239 | ||
240 | //#undef static | |
241 | ||
242 | // --------------------------------------------------------------------- | |
243 | // CreateBitmap routine | |
244 | // --------------------------------------------------------------------- | |
245 | ||
246 | wxBitmap AlternateArtProvider::CreateBitmap(const wxArtID& id, | |
247 | const wxArtClient& client, | |
248 | const wxSize& WXUNUSED(size)) | |
249 | { | |
250 | ART(wxART_HELP_SIDE_PANEL, helpsidepanel) | |
251 | ART(wxART_HELP_SETTINGS, helpoptions) | |
252 | ART(wxART_HELP_BOOK, helpbook) | |
253 | ART(wxART_HELP_FOLDER, helpbook) | |
254 | ART(wxART_HELP_PAGE, helppage) | |
255 | //ART(wxART_ADD_BOOKMARK, addbookm) | |
256 | //ART(wxART_DEL_BOOKMARK, delbookm) | |
257 | ART(wxART_GO_BACK, helpback) | |
258 | ART(wxART_GO_FORWARD, helpforward) | |
259 | ART(wxART_GO_UP, helpup) | |
260 | ART(wxART_GO_DOWN, helpdown) | |
261 | ART(wxART_GO_TO_PARENT, helpuplevel) | |
262 | ART(wxART_FILE_OPEN, helpopen) | |
263 | if (client == wxART_HELP_BROWSER) | |
264 | { | |
265 | ART(wxART_FRAME_ICON, helpicon) | |
266 | } | |
267 | ||
268 | //ART(wxART_GO_HOME, home) | |
269 | ||
270 | // Any wxWindows icons not implemented here | |
271 | // will be provided by the default art provider. | |
272 | return wxNullBitmap; | |
273 | } | |
274 | ||
275 | #endif |