1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Tries to load MS HTML Help, falls back to wxHTML upon failure
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "helpbest.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/filefn.h"
30 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP
31 #include "wx/msw/helpchm.h"
32 #include "wx/html/helpctrl.h"
33 #include "wx/msw/helpbest.h"
35 IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController
, wxHelpControllerBase
)
37 bool wxBestHelpController::Initialize( const wxString
& filename
)
39 // try wxCHMHelpController
40 wxCHMHelpController
* chm
= new wxCHMHelpController
;
42 m_helpControllerType
= wxUseChmHelp
;
43 // do not warn upon failure
44 wxLogNull dontWarnOnFailure
;
46 if( chm
->Initialize( GetValidFilename( filename
) ) )
48 m_helpController
= chm
;
55 // try wxHtmlHelpController
56 wxHtmlHelpController
* html
= new wxHtmlHelpController
;
58 m_helpControllerType
= wxUseHtmlHelp
;
59 if( html
->Initialize( GetValidFilename( filename
) ) )
61 m_helpController
= html
;
71 wxString
wxBestHelpController::GetValidFilename( const wxString
& filename
) const
73 wxString tmp
= filename
;
74 ::wxStripExtension( tmp
);
76 switch( m_helpControllerType
)
79 if( ::wxFileExists( tmp
+ wxT(".chm") ) )
80 return tmp
+ wxT(".chm");
85 if( ::wxFileExists( tmp
+ wxT(".htb") ) )
86 return tmp
+ wxT(".htb");
87 if( ::wxFileExists( tmp
+ wxT(".zip") ) )
88 return tmp
+ wxT(".zip");
89 if( ::wxFileExists( tmp
+ wxT(".hhp") ) )
90 return tmp
+ wxT(".hhp");
96 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
103 // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP