]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpbest.cpp
Updated to new PyCrust
[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 #ifdef __GNUG__
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
29 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP
30 #include "wx/msw/helpchm.h"
31 #include "wx/html/helpctrl.h"
32 #include "wx/msw/helpbest.h"
33
34 IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase );
35
36 bool wxBestHelpController::Initialize( const wxString& filename )
37 {
38 // try wxCHMHelpController
39 wxCHMHelpController* chm = new wxCHMHelpController;
40
41 m_helpControllerType = wxUseChmHelp;
42 // do not warn upon failure
43 wxLogNull dontWarnOnFailure;
44
45 if( chm->Initialize( GetValidFilename( filename ) ) )
46 {
47 m_helpController = chm;
48 return TRUE;
49 }
50
51 // failed
52 delete chm;
53
54 // try wxHtmlHelpController
55 wxHtmlHelpController* html = new wxHtmlHelpController;
56
57 m_helpControllerType = wxUseHtmlHelp;
58 if( html->Initialize( GetValidFilename( filename ) ) )
59 {
60 m_helpController = html;
61 return TRUE;
62 }
63
64 // failed
65 delete html;
66
67 return FALSE;
68 }
69
70 wxString wxBestHelpController::GetValidFilename( const wxString& filename ) const
71 {
72 wxString tmp = filename;
73 ::wxStripExtension( tmp );
74
75 switch( m_helpControllerType )
76 {
77 case wxUseChmHelp:
78 if( ::wxFileExists( tmp + ".chm" ) )
79 return tmp + ".chm";
80
81 return filename;
82 break;
83 case wxUseHtmlHelp:
84 if( ::wxFileExists( tmp + ".htb" ) )
85 return tmp + ".htb";
86 if( ::wxFileExists( tmp + ".zip" ) )
87 return tmp + ".zip";
88 if( ::wxFileExists( tmp + ".hhp" ) )
89 return tmp + ".hhp";
90
91 return filename;
92 break;
93 default:
94 // we CAN'T get here
95 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
96 return wxEmptyString;
97 break;
98 }
99 }
100
101 #endif
102 // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP