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