]>
Commit | Line | Data |
---|---|---|
3d285623 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpbest.cpp | |
3 | // Purpose: Tries to load MS HTML Help, falls back to wxHTML upon failure | |
4 | // Author: Mattia Barbon | |
5 | // Modified by: | |
6 | // Created: 02/04/2001 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Mattia Barbon | |
59af881e | 9 | // Licence: wxWindows licence |
3d285623 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d285623 VS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/defs.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/filefn.h" | |
9fcaaedd | 24 | #include "wx/log.h" |
3d285623 | 25 | |
62cdd7d3 MB |
26 | #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) \ |
27 | && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__) | |
28 | ||
3d285623 VS |
29 | #include "wx/msw/helpchm.h" |
30 | #include "wx/html/helpctrl.h" | |
31 | #include "wx/msw/helpbest.h" | |
32 | ||
4e352a3f | 33 | IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase ) |
3d285623 VS |
34 | |
35 | bool wxBestHelpController::Initialize( const wxString& filename ) | |
36 | { | |
37 | // try wxCHMHelpController | |
38 | wxCHMHelpController* chm = new wxCHMHelpController; | |
39 | ||
40 | m_helpControllerType = wxUseChmHelp; | |
41 | // do not warn upon failure | |
42 | wxLogNull dontWarnOnFailure; | |
43 | ||
44 | if( chm->Initialize( GetValidFilename( filename ) ) ) | |
45 | { | |
46 | m_helpController = chm; | |
59af881e | 47 | return true; |
3d285623 VS |
48 | } |
49 | ||
50 | // failed | |
51 | delete chm; | |
52 | ||
53 | // try wxHtmlHelpController | |
54 | wxHtmlHelpController* html = new wxHtmlHelpController; | |
55 | ||
56 | m_helpControllerType = wxUseHtmlHelp; | |
57 | if( html->Initialize( GetValidFilename( filename ) ) ) | |
58 | { | |
59 | m_helpController = html; | |
59af881e | 60 | return true; |
3d285623 VS |
61 | } |
62 | ||
63 | // failed | |
64 | delete html; | |
65 | ||
59af881e | 66 | return false; |
3d285623 VS |
67 | } |
68 | ||
69 | wxString wxBestHelpController::GetValidFilename( const wxString& filename ) const | |
70 | { | |
71 | wxString tmp = filename; | |
72 | ::wxStripExtension( tmp ); | |
73 | ||
74 | switch( m_helpControllerType ) | |
75 | { | |
c34bed14 | 76 | case wxUseChmHelp: |
2b5f62a0 VZ |
77 | if( ::wxFileExists( tmp + wxT(".chm") ) ) |
78 | return tmp + wxT(".chm"); | |
c34bed14 VZ |
79 | |
80 | return filename; | |
81 | ||
82 | case wxUseHtmlHelp: | |
2b5f62a0 VZ |
83 | if( ::wxFileExists( tmp + wxT(".htb") ) ) |
84 | return tmp + wxT(".htb"); | |
85 | if( ::wxFileExists( tmp + wxT(".zip") ) ) | |
86 | return tmp + wxT(".zip"); | |
87 | if( ::wxFileExists( tmp + wxT(".hhp") ) ) | |
88 | return tmp + wxT(".hhp"); | |
c34bed14 VZ |
89 | |
90 | return filename; | |
91 | ||
92 | default: | |
93 | // we CAN'T get here | |
94 | wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") ); | |
3d285623 | 95 | } |
ac92c7e9 VZ |
96 | |
97 | return wxEmptyString; | |
3d285623 VS |
98 | } |
99 | ||
100 | #endif | |
101 | // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP |