]>
Commit | Line | Data |
---|---|---|
4e4152e4 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpview.h | |
3 | // Purpose: HelpView application | |
4 | // A standalone viewer for wxHTML Help (.htb) files | |
5 | // Author: Vaclav Slavik, Julian Smart | |
6 | // Modified by: | |
7 | // Created: 2002-07-09 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2002 Vaclav Slavik, Julian Smart and others | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
4e4152e4 JS |
13 | // For compilers that support precompilation, includes "wx/wx.h". |
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | // for all others, include the necessary headers (this file is usually all you | |
be5a51fb | 21 | // need because it includes almost all "standard" wxWidgets headers |
4e4152e4 JS |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/wx.h" | |
24 | #endif | |
25 | ||
d9b21c9f | 26 | #include "wx/filename.h" |
4e4152e4 JS |
27 | #include "wx/image.h" |
28 | #include "wx/wxhtml.h" | |
29 | #include "wx/fs_zip.h" | |
30 | #include "wx/log.h" | |
31 | #include "wx/artprov.h" | |
32 | #include "wx/filedlg.h" | |
33 | ||
877c86a2 JS |
34 | #include "helpview.h" |
35 | ||
4e4152e4 JS |
36 | class AlternateArtProvider : public wxArtProvider |
37 | { | |
38 | protected: | |
39 | virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, | |
40 | const wxSize& size); | |
41 | }; | |
42 | ||
4e4152e4 JS |
43 | IMPLEMENT_APP(hvApp) |
44 | ||
2b5f62a0 VZ |
45 | hvApp::hvApp() |
46 | { | |
62d1f48b | 47 | #if wxUSE_IPC |
2b5f62a0 VZ |
48 | m_server = NULL; |
49 | #endif | |
50 | } | |
4e4152e4 JS |
51 | |
52 | bool hvApp::OnInit() | |
53 | { | |
54 | #ifdef __WXMOTIF__ | |
55 | delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used | |
56 | #endif | |
03a90749 | 57 | |
3fafce67 | 58 | wxArtProvider::Push(new AlternateArtProvider); |
03a90749 | 59 | |
97c0c88b | 60 | #if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON |
476d3114 | 61 | wxApp::s_macAboutMenuItemId = wxID_ABOUT; |
63fa3f89 | 62 | wxFileName::MacRegisterDefaultTypeAndCreator( wxT("htb") , 'HTBD' , 'HTBA' ) ; |
d9b21c9f JS |
63 | #endif |
64 | ||
9d683b44 | 65 | int istyle = wxHF_DEFAULT_STYLE; |
03a90749 | 66 | |
254a2129 WS |
67 | wxString service, windowName, titleFormat, argStr; |
68 | wxString book[10]; | |
2b5f62a0 VZ |
69 | int bookCount = 0; |
70 | int i; | |
03a90749 DS |
71 | bool hasService = false; |
72 | bool hasWindowName = false; | |
73 | bool createServer = false; | |
74 | ||
62d1f48b | 75 | #if wxUSE_IPC |
2b5f62a0 | 76 | m_server = NULL; |
43b8a532 | 77 | #endif |
03a90749 | 78 | |
2b5f62a0 VZ |
79 | // Help books are recognized by extension ".hhp" ".htb" or ".zip". |
80 | // Service and window_name can occur anywhere in arguments, | |
81 | // but service must be first | |
82 | // Other arguments (topic?) could be added | |
03a90749 | 83 | |
2b5f62a0 VZ |
84 | // modes of operation: |
85 | // 1) no arguments - stand alone, prompt user for book | |
86 | // 2) books only - stand alone, open books | |
87 | // 3) "--server" as (any) arg - start connection with default service; | |
88 | // also open any books passed as other arguments | |
89 | // 4) at least one argument which is not book, and not "--server" - take first | |
90 | // such argument as service, second (if present) as window name, | |
91 | // start service, open any books | |
03a90749 DS |
92 | |
93 | for( i=1; i<argc; i++ ) | |
2b5f62a0 | 94 | { |
03a90749 DS |
95 | argStr = argv[i]; |
96 | ||
97 | if ( argStr.Find( wxT(".hhp") ) >= 0 | |
98 | || argStr.Find( wxT(".htb") ) >= 0 | |
99 | || argStr.Find( wxT(".zip") ) >= 0 ) | |
100 | { | |
101 | book[bookCount] = argStr; | |
102 | bookCount++; | |
103 | } | |
104 | else if ( argStr == wxT("--server") ) | |
105 | { | |
106 | createServer = true; | |
2b5f62a0 | 107 | #if defined(__WXMSW__) |
03a90749 | 108 | service = wxT("generic_helpservice"); |
2b5f62a0 | 109 | #elif defined(__UNIX__) |
03a90749 | 110 | service = wxT("/tmp/") + wxString(wxT("generic_helpservice")); |
2b5f62a0 | 111 | #else |
03a90749 | 112 | service = wxT("4242"); |
2b5f62a0 | 113 | #endif |
03a90749 DS |
114 | } |
115 | else if ( !hasService ) | |
116 | { | |
117 | service = argStr; | |
118 | hasService = true; | |
119 | createServer = true; | |
120 | } | |
121 | else if ( !hasWindowName ) | |
122 | { | |
123 | windowName = argStr; | |
124 | hasWindowName = true; | |
125 | } | |
126 | else if ( argStr.Find( wxT("--Style") ) >= 0 ) | |
127 | { | |
128 | long i; | |
129 | wxString numb = argStr.AfterLast(wxT('e')); | |
130 | if ( !(numb.ToLong(&i) ) ) | |
131 | { | |
132 | wxLogError( wxT("Integer conversion failed for --Style") ); | |
133 | } | |
134 | else | |
135 | { | |
136 | istyle = i; | |
137 | } | |
138 | } | |
139 | else | |
140 | { | |
141 | //unknown - could be topic? | |
142 | } | |
2b5f62a0 | 143 | } |
03a90749 | 144 | |
d9b21c9f JS |
145 | // No book - query user; but not on Mac, since there |
146 | // may be an AppleEvent to open a document on the way | |
147 | #ifndef __WXMAC__ | |
2b5f62a0 VZ |
148 | if ( bookCount < 1 ) |
149 | { | |
03a90749 DS |
150 | wxString s = wxFileSelector( wxT("Open help file"), |
151 | wxGetCwd(), | |
152 | wxEmptyString, | |
153 | wxEmptyString, | |
154 | wxT("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|HTML Help Project (*.hhp)|*.hhp"), | |
55325d01 | 155 | wxFD_OPEN | wxFD_FILE_MUST_EXIST, |
03a90749 DS |
156 | NULL); |
157 | ||
62d1f48b | 158 | if (!s.empty()) |
03a90749 DS |
159 | { |
160 | book[0] = s; | |
161 | bookCount = 1; | |
162 | } | |
163 | } | |
d9b21c9f | 164 | #endif |
03a90749 | 165 | |
62d1f48b | 166 | #if wxUSE_IPC |
03a90749 DS |
167 | |
168 | if ( createServer ) | |
169 | { | |
170 | // Create a new server | |
171 | m_server = new hvServer; | |
172 | ||
173 | if ( !m_server->Create(service) ) | |
174 | { | |
175 | wxString wxm = wxT("Server Create failed - service: "); | |
176 | wxString xxm = wxm << service; | |
177 | wxLogError( xxm ); | |
178 | //if MSW quits here, probably another copy already exists | |
179 | return false; | |
180 | } | |
181 | createServer = false; | |
182 | wxUnusedVar(createServer); | |
2b5f62a0 | 183 | } |
03a90749 | 184 | |
62d1f48b | 185 | #endif // wxUSE_IPC |
03a90749 | 186 | |
2b5f62a0 | 187 | //now add help |
4e4152e4 | 188 | wxInitAllImageHandlers(); |
03a90749 DS |
189 | wxFileSystem::AddHandler(new wxZipFSHandler); |
190 | ||
be5a51fb | 191 | SetVendorName(wxT("wxWidgets") ); |
03a90749 | 192 | SetAppName(wxT("wxHTMLHelpServer") ); |
4e4152e4 | 193 | wxConfig::Get(); // create an instance |
03a90749 | 194 | |
2b5f62a0 | 195 | m_helpController = new wxHtmlHelpController( istyle ); |
03a90749 | 196 | |
2b5f62a0 | 197 | if ( !hasWindowName ) |
03a90749 | 198 | { |
2b5f62a0 | 199 | titleFormat = wxT("Help: %s") ; |
03a90749 | 200 | } |
2b5f62a0 VZ |
201 | else |
202 | { | |
03a90749 DS |
203 | //remove underscores |
204 | windowName.Replace( wxT("_"), wxT(" ") ); | |
205 | titleFormat = windowName; | |
4e4152e4 | 206 | } |
03a90749 | 207 | |
2b5f62a0 | 208 | m_helpController->SetTitleFormat( titleFormat ); |
03a90749 DS |
209 | |
210 | for( i=0; i<bookCount; i++ ) | |
2b5f62a0 | 211 | { |
dba06cd0 | 212 | wxFileName fileName(book[i]); |
03a90749 | 213 | m_helpController->AddBook(fileName); |
2b5f62a0 | 214 | } |
03a90749 | 215 | |
4e4152e4 JS |
216 | #ifdef __WXMOTIF__ |
217 | delete wxLog::SetActiveTarget(new wxLogGui); | |
218 | #endif | |
03a90749 DS |
219 | |
220 | m_helpController->DisplayContents(); | |
221 | ||
222 | return true; | |
4e4152e4 JS |
223 | } |
224 | ||
225 | ||
226 | int hvApp::OnExit() | |
227 | { | |
62d1f48b | 228 | #if wxUSE_IPC |
8d0f1c1c | 229 | wxObjectList::compatibility_iterator node = m_connections.GetFirst(); |
2b5f62a0 VZ |
230 | while (node) |
231 | { | |
8d0f1c1c | 232 | wxObjectList::compatibility_iterator next = node->GetNext(); |
ddc4f3b5 | 233 | hvConnection* connection = (hvConnection*) node->GetData(); |
2b5f62a0 VZ |
234 | connection->Disconnect(); |
235 | delete connection; | |
236 | node = next; | |
237 | } | |
238 | m_connections.Clear(); | |
03a90749 | 239 | |
2b5f62a0 VZ |
240 | if (m_server) |
241 | { | |
242 | delete m_server; | |
243 | m_server = NULL; | |
244 | } | |
245 | #endif | |
03a90749 | 246 | |
2b5f62a0 | 247 | delete m_helpController; |
4e4152e4 | 248 | delete wxConfig::Set(NULL); |
03a90749 | 249 | |
4e4152e4 JS |
250 | return 0; |
251 | } | |
252 | ||
253 | bool hvApp::OpenBook(wxHtmlHelpController* controller) | |
254 | { | |
255 | wxString s = wxFileSelector(_("Open help file"), | |
256 | wxGetCwd(), | |
257 | wxEmptyString, | |
258 | wxEmptyString, | |
259 | _( | |
03a90749 DS |
260 | "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\ |
261 | HTML Help Project (*.hhp)|*.hhp"), | |
3fafce67 | 262 | wxFD_OPEN | wxFD_FILE_MUST_EXIST, |
03a90749 DS |
263 | NULL); |
264 | ||
265 | if ( !s.empty() ) | |
4e4152e4 JS |
266 | { |
267 | wxString ext = s.Right(4).Lower(); | |
9a83f860 | 268 | if (ext == wxT(".zip") || ext == wxT(".htb") || ext == wxT(".hhp")) |
4e4152e4 JS |
269 | { |
270 | wxBusyCursor bcur; | |
dba06cd0 JS |
271 | wxFileName fileName(s); |
272 | controller->AddBook(fileName); | |
03a90749 | 273 | return true; |
4e4152e4 JS |
274 | } |
275 | } | |
03a90749 DS |
276 | |
277 | return false; | |
4e4152e4 JS |
278 | } |
279 | ||
d9b21c9f JS |
280 | #ifdef __WXMAC__ |
281 | /// Respond to Apple Event for opening a document | |
282 | void hvApp::MacOpenFile(const wxString& filename) | |
283 | { | |
284 | wxBusyCursor bcur; | |
285 | wxFileName fileName(filename); | |
286 | m_helpController->AddBook(fileName); | |
287 | m_helpController->DisplayContents(); | |
288 | } | |
289 | #endif | |
290 | ||
291 | ||
4e4152e4 | 292 | /* |
2b5f62a0 VZ |
293 | * Art provider class |
294 | */ | |
4e4152e4 JS |
295 | |
296 | // --------------------------------------------------------------------- | |
297 | // helper macros | |
298 | // --------------------------------------------------------------------- | |
299 | ||
300 | // Standard macro for getting a resource from XPM file: | |
301 | #define ART(artId, xpmRc) \ | |
2b5f62a0 | 302 | if ( id == artId ) return wxBitmap(xpmRc##_xpm); |
4e4152e4 | 303 | |
2b5f62a0 | 304 | #define GET_STD_ICON_FROM_APP(iconId) |
4e4152e4 JS |
305 | |
306 | // There are two ways of getting the standard icon: either via XPMs or via | |
307 | // wxIcon ctor. This depends on the platform: | |
308 | #if defined(__WXUNIVERSAL__) | |
2b5f62a0 | 309 | #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap; |
4e4152e4 | 310 | #elif defined(__WXGTK__) || defined(__WXMOTIF__) |
2b5f62a0 | 311 | #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm); |
4e4152e4 | 312 | #else |
2b5f62a0 VZ |
313 | #define CREATE_STD_ICON(iconId, xpmRc) \ |
314 | { \ | |
9a83f860 | 315 | wxIcon icon(wxT(iconId)); \ |
03a90749 DS |
316 | wxBitmap bmp; \ |
317 | bmp.CopyFromIcon(icon); \ | |
318 | return bmp; \ | |
2b5f62a0 | 319 | } |
4e4152e4 JS |
320 | #endif |
321 | ||
322 | // Macro used in CreateBitmap to get wxICON_FOO icons: | |
323 | #define ART_MSGBOX(artId, iconId, xpmRc) \ | |
324 | if ( id == artId ) \ | |
2b5f62a0 | 325 | { \ |
03a90749 DS |
326 | GET_STD_ICON_FROM_APP(iconId) \ |
327 | CREATE_STD_ICON(#iconId, xpmRc) \ | |
2b5f62a0 | 328 | } |
4e4152e4 JS |
329 | |
330 | // --------------------------------------------------------------------- | |
331 | // XPMs with the art | |
332 | // --------------------------------------------------------------------- | |
333 | ||
334 | // XPM hack: make the arrays const | |
335 | //#define static static const | |
336 | ||
337 | #include "bitmaps/helpback.xpm" | |
338 | #include "bitmaps/helpbook.xpm" | |
339 | #include "bitmaps/helpdown.xpm" | |
340 | #include "bitmaps/helpforward.xpm" | |
341 | #include "bitmaps/helpoptions.xpm" | |
342 | #include "bitmaps/helppage.xpm" | |
343 | #include "bitmaps/helpsidepanel.xpm" | |
344 | #include "bitmaps/helpup.xpm" | |
345 | #include "bitmaps/helpuplevel.xpm" | |
346 | #include "bitmaps/helpicon.xpm" | |
347 | #include "bitmaps/helpopen.xpm" | |
348 | ||
349 | //#undef static | |
350 | ||
351 | // --------------------------------------------------------------------- | |
352 | // CreateBitmap routine | |
353 | // --------------------------------------------------------------------- | |
354 | ||
355 | wxBitmap AlternateArtProvider::CreateBitmap(const wxArtID& id, | |
356 | const wxArtClient& client, | |
357 | const wxSize& WXUNUSED(size)) | |
358 | { | |
359 | ART(wxART_HELP_SIDE_PANEL, helpsidepanel) | |
03a90749 DS |
360 | ART(wxART_HELP_SETTINGS, helpoptions) |
361 | ART(wxART_HELP_BOOK, helpbook) | |
362 | ART(wxART_HELP_FOLDER, helpbook) | |
363 | ART(wxART_HELP_PAGE, helppage) | |
364 | //ART(wxART_ADD_BOOKMARK, addbookm) | |
365 | //ART(wxART_DEL_BOOKMARK, delbookm) | |
366 | ART(wxART_GO_BACK, helpback) | |
367 | ART(wxART_GO_FORWARD, helpforward) | |
368 | ART(wxART_GO_UP, helpup) | |
369 | ART(wxART_GO_DOWN, helpdown) | |
370 | ART(wxART_GO_TO_PARENT, helpuplevel) | |
371 | ART(wxART_FILE_OPEN, helpopen) | |
372 | if (client == wxART_HELP_BROWSER) | |
373 | { | |
374 | //ART(wxART_FRAME_ICON, helpicon) | |
375 | ART(wxART_HELP, helpicon) | |
376 | } | |
377 | ||
378 | //ART(wxART_GO_HOME, home) | |
379 | ||
be5a51fb | 380 | // Any wxWidgets icons not implemented here |
03a90749 DS |
381 | // will be provided by the default art provider. |
382 | return wxNullBitmap; | |
2b5f62a0 VZ |
383 | } |
384 | ||
62d1f48b | 385 | #if wxUSE_IPC |
2b5f62a0 VZ |
386 | |
387 | wxConnectionBase *hvServer::OnAcceptConnection(const wxString& topic) | |
388 | { | |
389 | if (topic == wxT("HELP")) | |
390 | return new hvConnection(); | |
391 | else | |
392 | return NULL; | |
393 | } | |
394 | ||
395 | // ---------------------------------------------------------------------------- | |
396 | // hvConnection | |
397 | // ---------------------------------------------------------------------------- | |
398 | ||
399 | hvConnection::hvConnection() | |
400 | : wxConnection() | |
401 | { | |
402 | wxGetApp().GetConnections().Append(this); | |
403 | } | |
404 | ||
405 | hvConnection::~hvConnection() | |
406 | { | |
407 | wxGetApp().GetConnections().DeleteObject(this); | |
408 | } | |
4e4152e4 | 409 | |
587b4c84 VZ |
410 | bool hvConnection::OnExec(const wxString& WXUNUSED(topic), |
411 | const wxString& data) | |
2b5f62a0 | 412 | { |
03a90749 DS |
413 | // wxLogStatus("Execute command: %s", data); |
414 | ||
587b4c84 | 415 | if ( data == "--intstring" ) |
03a90749 | 416 | { |
2b5f62a0 | 417 | long i; |
03a90749 DS |
418 | wxString argStr = data; |
419 | wxString numb = argStr.AfterLast(wxT('g')); | |
420 | if ( !(numb.ToLong(&i) ) ) | |
421 | { | |
422 | wxLogError( wxT("Integer conversion failed for --intstring") ); | |
423 | } | |
424 | else | |
425 | { | |
426 | wxGetApp().GetHelpController()->Display(int(i)); | |
427 | } | |
428 | } | |
429 | else | |
430 | { | |
431 | wxGetApp().GetHelpController()->Display(data); | |
432 | } | |
433 | ||
434 | return true; | |
2b5f62a0 | 435 | } |
4e4152e4 | 436 | |
2b5f62a0 VZ |
437 | bool hvConnection::OnPoke(const wxString& WXUNUSED(topic), |
438 | const wxString& item, | |
bcb6619f VZ |
439 | const void *buf, |
440 | size_t size, | |
441 | wxIPCFormat format) | |
2b5f62a0 | 442 | { |
bcb6619f VZ |
443 | const wxString data = GetTextFromData(buf, size, format); |
444 | ||
03a90749 DS |
445 | // wxLogStatus("Poke command: %s = %s", item.c_str(), data); |
446 | //topic is not tested | |
447 | ||
448 | if ( wxGetApp().GetHelpController() ) | |
449 | { | |
450 | if ( item == wxT("--AddBook") ) | |
451 | { | |
452 | wxGetApp().GetHelpController()->AddBook(data); | |
453 | } | |
454 | else if ( item == wxT("--DisplayContents") ) | |
455 | { | |
456 | wxGetApp().GetHelpController()->DisplayContents(); | |
457 | } | |
458 | else if ( item == wxT("--DisplayIndex") ) | |
459 | { | |
460 | wxGetApp().GetHelpController()->DisplayIndex(); | |
461 | } | |
462 | else if ( item == wxT("--KeywordSearch") ) | |
463 | { | |
464 | wxGetApp().GetHelpController()->KeywordSearch(data); | |
465 | } | |
466 | else if ( item == wxT("--SetTitleFormat") ) | |
467 | { | |
468 | wxString newname = data; | |
469 | newname.Replace( wxT("_"), wxT(" ") ); | |
470 | wxGetApp().GetHelpController()->SetTitleFormat(newname); | |
471 | //does not redraw title bar? | |
472 | //wxGetApp().GetHelpController()->ReFresh(); - or something | |
473 | } | |
474 | else if ( item == wxT("--SetTempDir") ) | |
475 | { | |
476 | wxGetApp().GetHelpController()->SetTempDir(data); | |
477 | } | |
478 | else if ( item == wxT("--YouAreDead") ) | |
479 | { | |
480 | // don't really know how to kill app from down here... | |
481 | // use wxKill from client instead | |
482 | //wxWindow *win = wxTheApp->GetTopWindow(); | |
483 | //if ( win ) | |
484 | // win->Destroy(); | |
485 | } | |
486 | } | |
487 | ||
488 | return true; | |
4e4152e4 | 489 | } |
2b5f62a0 | 490 | |
62d1f48b | 491 | #endif // #if wxUSE_IPC |