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