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 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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__) \
31 && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
33 #include "wx/msw/helpchm.h"
34 #include "wx/html/helpctrl.h"
35 #include "wx/msw/helpbest.h"
37 IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController
, wxHelpControllerBase
)
39 bool wxBestHelpController::Initialize( const wxString
& filename
)
41 // try wxCHMHelpController
42 wxCHMHelpController
* chm
= new wxCHMHelpController
;
44 m_helpControllerType
= wxUseChmHelp
;
45 // do not warn upon failure
46 wxLogNull dontWarnOnFailure
;
48 if( chm
->Initialize( GetValidFilename( filename
) ) )
50 m_helpController
= chm
;
57 // try wxHtmlHelpController
58 wxHtmlHelpController
* html
= new wxHtmlHelpController
;
60 m_helpControllerType
= wxUseHtmlHelp
;
61 if( html
->Initialize( GetValidFilename( filename
) ) )
63 m_helpController
= html
;
73 wxString
wxBestHelpController::GetValidFilename( const wxString
& filename
) const
75 wxString tmp
= filename
;
76 ::wxStripExtension( tmp
);
78 switch( m_helpControllerType
)
81 if( ::wxFileExists( tmp
+ wxT(".chm") ) )
82 return tmp
+ wxT(".chm");
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");
98 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
101 return wxEmptyString
;
105 // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP