]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/helpbest.cpp
WinCE fixes (in case a WinCE-friendly backend gets written one day)
[wxWidgets.git] / src / msw / helpbest.cpp
... / ...
CommitLineData
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/defs.h"
21#endif
22
23#include "wx/filefn.h"
24#include "wx/log.h"
25
26#if wxUSE_HELP && wxUSE_MS_HTML_HELP \
27 && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
28
29#include "wx/msw/helpchm.h"
30#include "wx/html/helpctrl.h"
31#include "wx/msw/helpbest.h"
32
33IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase )
34
35bool wxBestHelpController::Initialize( const wxString& filename )
36{
37 // try wxCHMHelpController
38 wxCHMHelpController* chm = new wxCHMHelpController(m_parentWindow);
39
40 m_helpControllerType = wxUseChmHelp;
41 // do not warn upon failure
42 wxLogNull dontWarnOnFailure;
43
44 if( chm->Initialize( GetValidFilename( filename ) ) )
45 {
46 m_helpController = chm;
47 m_parentWindow = NULL;
48 return true;
49 }
50
51 // failed
52 delete chm;
53
54 // try wxHtmlHelpController
55 wxHtmlHelpController* html = new wxHtmlHelpController(wxHF_DEFAULT_STYLE, m_parentWindow);
56
57 m_helpControllerType = wxUseHtmlHelp;
58 if( html->Initialize( GetValidFilename( filename ) ) )
59 {
60 m_helpController = html;
61 m_parentWindow = NULL;
62 return true;
63 }
64
65 // failed
66 delete html;
67
68 return false;
69}
70
71wxString wxBestHelpController::GetValidFilename( const wxString& filename ) const
72{
73 wxString tmp = filename;
74 ::wxStripExtension( tmp );
75
76 switch( m_helpControllerType )
77 {
78 case wxUseChmHelp:
79 if( ::wxFileExists( tmp + wxT(".chm") ) )
80 return tmp + wxT(".chm");
81
82 return filename;
83
84 case wxUseHtmlHelp:
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");
91
92 return filename;
93
94 default:
95 // we CAN'T get here
96 wxFAIL_MSG( wxT("wxBestHelpController: Must call Initialize, first!") );
97 }
98
99 return wxEmptyString;
100}
101
102#endif
103 // wxUSE_HELP && wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP