]> git.saurik.com Git - wxWidgets.git/blame - src/msw/helpchm.cpp
determine the slider event type more precisely (i.e. generate LINE/PAGE UP/DOWN and...
[wxWidgets.git] / src / msw / helpchm.cpp
CommitLineData
f6bcfd97 1/////////////////////////////////////////////////////////////////////////////
a71d815b 2// Name: src/msw/helpchm.cpp
f6bcfd97
BP
3// Purpose: Help system: MS HTML Help implementation
4// Author: Julian Smart
5// Modified by:
6// Created: 16/04/2000
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
f6bcfd97
BP
10/////////////////////////////////////////////////////////////////////////////
11
f6bcfd97
BP
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
3295e238 16 #pragma hdrstop
f6bcfd97
BP
17#endif
18
a71d815b 19#if wxUSE_HELP && wxUSE_MS_HTML_HELP
f6bcfd97
BP
20
21#include "wx/filefn.h"
f6bcfd97 22#include "wx/msw/helpchm.h"
0b9ab0bd 23
397cfa3a 24#include "wx/dynload.h"
0b9ab0bd 25
9fcaaedd
VS
26#ifndef WX_PRECOMP
27 #include "wx/intl.h"
28 #include "wx/app.h"
29#endif
30
f6bcfd97 31#include "wx/msw/private.h"
92199f4c 32#include "wx/msw/htmlhelp.h"
3295e238
VZ
33
34// ----------------------------------------------------------------------------
638a0b2c
VS
35// utility functions to manage the loading/unloading
36// of hhctrl.ocx
3295e238
VZ
37// ----------------------------------------------------------------------------
38
638a0b2c 39#ifndef UNICODE
3295e238 40 typedef HWND ( WINAPI * HTMLHELP )( HWND, LPCSTR, UINT, DWORD );
2b5f62a0 41 #define HTMLHELP_NAME wxT("HtmlHelpA")
3295e238
VZ
42#else // ANSI
43 typedef HWND ( WINAPI * HTMLHELP )( HWND, LPCWSTR, UINT, DWORD );
2b5f62a0 44 #define HTMLHELP_NAME wxT("HtmlHelpW")
638a0b2c 45#endif
3295e238 46
4f89dbc4 47// dll symbol handle
638a0b2c 48static HTMLHELP gs_htmlHelp = 0;
638a0b2c
VS
49
50static bool LoadHtmlHelpLibrary()
51{
cd560c96 52 wxPluginLibrary *lib = wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT | wxDL_VERBATIM );
638a0b2c 53
cd560c96 54 if( !lib )
4f89dbc4
RL
55 {
56 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
59af881e 57 return false;
638a0b2c
VS
58 }
59 else
60 {
cd560c96 61 gs_htmlHelp = (HTMLHELP)lib->GetSymbol( HTMLHELP_NAME );
4f89dbc4
RL
62
63 if( !gs_htmlHelp )
64 {
65 wxLogError(_("Failed to initialize MS HTML Help."));
66
cd560c96 67 lib->UnrefLib();
59af881e 68 return false ;
4f89dbc4 69 }
638a0b2c
VS
70 }
71
59af881e 72 return true;
638a0b2c
VS
73}
74
75static void UnloadHtmlHelpLibrary()
76{
cd560c96 77 if ( gs_htmlHelp )
a71d815b 78 {
1be9536a
JS
79 if (wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") ))
80 gs_htmlHelp = 0;
638a0b2c
VS
81 }
82}
83
3db52265 84static HWND GetSuitableHWND(wxCHMHelpController* controller)
f6bcfd97 85{
3db52265
JS
86 if (controller->GetParentWindow())
87 return (HWND) controller->GetParentWindow()->GetHWND();
88 else if (wxTheApp->GetTopWindow())
f6bcfd97
BP
89 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
90 else
91 return GetDesktopWindow();
92}
93
94IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController, wxHelpControllerBase)
95
96bool wxCHMHelpController::Initialize(const wxString& filename)
97{
638a0b2c
VS
98 // warn on failure
99 if( !LoadHtmlHelpLibrary() )
59af881e 100 return false;
638a0b2c 101
f6bcfd97 102 m_helpFile = filename;
59af881e 103 return true;
f6bcfd97
BP
104}
105
106bool wxCHMHelpController::LoadFile(const wxString& file)
107{
108 if (!file.IsEmpty())
109 m_helpFile = file;
59af881e 110 return true;
f6bcfd97
BP
111}
112
113bool wxCHMHelpController::DisplayContents()
114{
59af881e 115 if (m_helpFile.IsEmpty()) return false;
f6bcfd97
BP
116
117 wxString str = GetValidFilename(m_helpFile);
118
3db52265 119 gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_DISPLAY_TOPIC, 0L);
59af881e 120 return true;
f6bcfd97
BP
121}
122
123// Use topic or HTML filename
124bool wxCHMHelpController::DisplaySection(const wxString& section)
125{
59af881e 126 if (m_helpFile.IsEmpty()) return false;
f6bcfd97
BP
127
128 wxString str = GetValidFilename(m_helpFile);
129
130 // Is this an HTML file or a keyword?
59af881e 131 bool isFilename = (section.Find(wxT(".htm")) != wxNOT_FOUND);
f6bcfd97
BP
132
133 if (isFilename)
3db52265 134 gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_DISPLAY_TOPIC, (DWORD) (const wxChar*) section);
f6bcfd97
BP
135 else
136 KeywordSearch(section);
59af881e 137 return true;
f6bcfd97
BP
138}
139
140// Use context number
141bool wxCHMHelpController::DisplaySection(int section)
142{
59af881e 143 if (m_helpFile.IsEmpty()) return false;
f6bcfd97
BP
144
145 wxString str = GetValidFilename(m_helpFile);
146
3db52265 147 gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)section);
59af881e 148 return true;
f6bcfd97
BP
149}
150
5100cabf
JS
151bool wxCHMHelpController::DisplayContextPopup(int contextId)
152{
59af881e 153 if (m_helpFile.IsEmpty()) return false;
5100cabf
JS
154
155 wxString str = GetValidFilename(m_helpFile);
156
a1b8f548
JS
157 // We also have to specify the popups file (default is cshelp.txt).
158 // str += wxT("::/cshelp.txt");
159
5100cabf
JS
160 HH_POPUP popup;
161 popup.cbStruct = sizeof(popup);
162 popup.hinst = (HINSTANCE) wxGetInstance();
163 popup.idString = contextId ;
164
165 GetCursorPos(& popup.pt);
5438a566
VZ
166 popup.clrForeground = (COLORREF)-1;
167 popup.clrBackground = (COLORREF)-1;
5100cabf
JS
168 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
169 popup.pszFont = NULL;
170 popup.pszText = NULL;
171
3db52265 172 gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
59af881e 173 return true;
5100cabf
JS
174}
175
176bool wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint& pos)
177{
178 HH_POPUP popup;
179 popup.cbStruct = sizeof(popup);
180 popup.hinst = (HINSTANCE) wxGetInstance();
181 popup.idString = 0 ;
182 popup.pt.x = pos.x; popup.pt.y = pos.y;
5438a566
VZ
183 popup.clrForeground = (COLORREF)-1;
184 popup.clrBackground = (COLORREF)-1;
5100cabf
JS
185 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
186 popup.pszFont = NULL;
187 popup.pszText = (const wxChar*) text;
188
3db52265 189 gs_htmlHelp(GetSuitableHWND(this), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
59af881e 190 return true;
5100cabf
JS
191}
192
f6bcfd97
BP
193bool wxCHMHelpController::DisplayBlock(long block)
194{
195 return DisplaySection(block);
196}
197
69b5cec2
VS
198bool wxCHMHelpController::KeywordSearch(const wxString& k,
199 wxHelpSearchMode WXUNUSED(mode))
f6bcfd97 200{
59af881e 201 if (m_helpFile.IsEmpty()) return false;
f6bcfd97
BP
202
203 wxString str = GetValidFilename(m_helpFile);
204
205 HH_AKLINK link;
206 link.cbStruct = sizeof(HH_AKLINK) ;
207 link.fReserved = FALSE ;
208 link.pszKeywords = k.c_str() ;
209 link.pszUrl = NULL ;
210 link.pszMsgText = NULL ;
211 link.pszMsgTitle = NULL ;
212 link.pszWindow = NULL ;
213 link.fIndexOnFail = TRUE ;
214
3db52265 215 gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
59af881e 216 return true;
f6bcfd97
BP
217}
218
219bool wxCHMHelpController::Quit()
220{
3db52265 221 gs_htmlHelp(GetSuitableHWND(this), 0, HH_CLOSE_ALL, 0L);
638a0b2c 222
59af881e 223 return true;
f6bcfd97
BP
224}
225
226// Append extension if necessary.
227wxString wxCHMHelpController::GetValidFilename(const wxString& file) const
228{
229 wxString path, name, ext;
230 wxSplitPath(file, & path, & name, & ext);
231
232 wxString fullName;
233 if (path.IsEmpty())
234 fullName = name + wxT(".chm");
235 else if (path.Last() == wxT('\\'))
236 fullName = path + name + wxT(".chm");
237 else
238 fullName = path + wxT("\\") + name + wxT(".chm");
239 return fullName;
240}
241
3295e238
VZ
242wxCHMHelpController::~wxCHMHelpController()
243{
244 UnloadHtmlHelpLibrary();
245}
246
f6bcfd97 247#endif // wxUSE_HELP