]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpbest.cpp
document that the workaround used to make popup menus behave correctly is the one...
[wxWidgets.git] / src / msw / helpbest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/log.h"
21 #endif
22
23 #include "wx/filefn.h"
24
25 #if wxUSE_HELP && wxUSE_MS_HTML_HELP \
26 && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
27
28 #include "wx/msw/helpchm.h"
29 #include "wx/html/helpctrl.h"
30 #include "wx/msw/helpbest.h"
31
32 IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase )
33
34 bool wxBestHelpController::Initialize( const wxString& filename )
35 {
36 // try wxCHMHelpController
37 wxCHMHelpController* chm = new wxCHMHelpController(m_parentWindow);
38
39 m_helpControllerType = wxUseChmHelp;
40 // do not warn upon failure
41 wxLogNull dontWarnOnFailure;
42
43 if( chm->Initialize( GetValidFilename( filename ) ) )
44 {
45 m_helpController = chm;
46 m_parentWindow = NULL;
47 return true;
48 }
49
50 // failed
51 delete chm;
52
53 // try wxHtmlHelpController
54 wxHtmlHelpController* html = new wxHtmlHelpController(wxHF_DEFAULT_STYLE, m_parentWindow);
55
56 m_helpControllerType = wxUseHtmlHelp;
57 if( html->Initialize( GetValidFilename( filename ) ) )
58 {
59 m_helpController = html;
60 m_parentWindow = NULL;
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 + wxT(".chm") ) )
79 return tmp + wxT(".chm");
80
81 return filename;
82
83 case wxUseHtmlHelp:
84 if( ::wxFileExists( tmp + wxT(".htb") ) )
85 return tmp + wxT(".htb");
86 if( ::wxFileExists( tmp + wxT(".zip") ) )
87 return tmp + wxT(".zip");
88 if( ::wxFileExists( tmp + wxT(".hhp") ) )
89 return tmp + wxT(".hhp");
90
91 return filename;
92
93 default:
94 // we CAN'T get here
95 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
96 }
97
98 return wxEmptyString;
99 }
100
101 #endif
102 // wxUSE_HELP && wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP