]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpbest.cpp
Make mouse capture checking asserts stronger and more detailed.
[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 // Copyright: (c) Mattia Barbon
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/log.h"
20 #endif
21
22 #include "wx/filename.h"
23
24 #if wxUSE_HELP && wxUSE_MS_HTML_HELP \
25 && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
26
27 #include "wx/msw/helpchm.h"
28 #include "wx/html/helpctrl.h"
29 #include "wx/msw/helpbest.h"
30
31 IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase )
32
33 bool wxBestHelpController::Initialize( const wxString& filename )
34 {
35 // try wxCHMHelpController
36 wxCHMHelpController* chm = new wxCHMHelpController(m_parentWindow);
37
38 m_helpControllerType = wxUseChmHelp;
39 // do not warn upon failure
40 wxLogNull dontWarnOnFailure;
41
42 if( chm->Initialize( GetValidFilename( filename ) ) )
43 {
44 m_helpController = chm;
45 m_parentWindow = NULL;
46 return true;
47 }
48
49 // failed
50 delete chm;
51
52 // try wxHtmlHelpController
53 wxHtmlHelpController *
54 html = new wxHtmlHelpController(m_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 wxFileName fn(filename);
73
74 switch( m_helpControllerType )
75 {
76 case wxUseChmHelp:
77 fn.SetExt("chm");
78 if( fn.FileExists() )
79 return fn.GetFullPath();
80
81 return filename;
82
83 case wxUseHtmlHelp:
84 fn.SetExt("htb");
85 if( fn.FileExists() )
86 return fn.GetFullPath();
87
88 fn.SetExt("zip");
89 if( fn.FileExists() )
90 return fn.GetFullPath();
91
92 fn.SetExt("hhp");
93 if( fn.FileExists() )
94 return fn.GetFullPath();
95
96 return filename;
97
98 default:
99 // we CAN'T get here
100 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
101 }
102
103 return wxEmptyString;
104 }
105
106 #endif
107 // wxUSE_HELP && wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP