]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpbest.cpp
final sweep over docs - replace & with \&
[wxWidgets.git] / src / msw / helpbest.cpp
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
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
28 #include "wx/log.h"
29
30 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) \
31 && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
32
33 #include "wx/msw/helpchm.h"
34 #include "wx/html/helpctrl.h"
35 #include "wx/msw/helpbest.h"
36
37 IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase )
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 {
80 case wxUseChmHelp:
81 if( ::wxFileExists( tmp + wxT(".chm") ) )
82 return tmp + wxT(".chm");
83
84 return filename;
85
86 case wxUseHtmlHelp:
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");
93
94 return filename;
95
96 default:
97 // we CAN'T get here
98 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
99 }
100
101 return wxEmptyString;
102 }
103
104 #endif
105 // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP