]> git.saurik.com Git - wxWidgets.git/blame - src/msw/helpchm.cpp
Remove some out of date comments.
[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
0016bb3b 5// Modified by: Vadim Zeitlin at 2008-03-01: refactoring, simplification
f6bcfd97
BP
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 20
730078f8 21#include "wx/filename.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
392c5133 47HTMLHELP GetHtmlHelpFunction()
638a0b2c 48{
392c5133 49 static HTMLHELP s_htmlHelp = NULL;
638a0b2c 50
392c5133 51 if ( !s_htmlHelp )
638a0b2c 52 {
9a83f860 53 static wxDynamicLibrary s_dllHtmlHelp(wxT("HHCTRL.OCX"), wxDL_VERBATIM);
4f89dbc4 54
392c5133 55 if ( !s_dllHtmlHelp.IsLoaded() )
4f89dbc4 56 {
392c5133
VZ
57 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
58 }
59 else
60 {
61 s_htmlHelp = (HTMLHELP)s_dllHtmlHelp.GetSymbol(HTMLHELP_NAME);
62 if ( !s_htmlHelp )
63 {
64 wxLogError(_("Failed to initialize MS HTML Help."));
65 }
4f89dbc4 66 }
638a0b2c
VS
67 }
68
392c5133 69 return s_htmlHelp;
638a0b2c
VS
70}
71
392c5133
VZ
72// find the window to use in HtmlHelp() call: use the given one by default but
73// fall back to the top level app window and then the desktop if it's NULL
74static HWND GetSuitableHWND(wxWindow *win)
638a0b2c 75{
392c5133
VZ
76 if ( !win && wxTheApp )
77 win = wxTheApp->GetTopWindow();
78
79 return win ? GetHwndOf(win) : ::GetDesktopWindow();
638a0b2c
VS
80}
81
f6bcfd97
BP
82
83IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController, wxHelpControllerBase)
84
85bool wxCHMHelpController::Initialize(const wxString& filename)
86{
392c5133 87 if ( !GetHtmlHelpFunction() )
59af881e 88 return false;
638a0b2c 89
f6bcfd97 90 m_helpFile = filename;
59af881e 91 return true;
f6bcfd97
BP
92}
93
94bool wxCHMHelpController::LoadFile(const wxString& file)
95{
96 if (!file.IsEmpty())
97 m_helpFile = file;
59af881e 98 return true;
f6bcfd97
BP
99}
100
0016bb3b
VZ
101/* static */ bool
102wxCHMHelpController::CallHtmlHelp(wxWindow *win,
103 const wxChar *str,
104 unsigned cmd,
105 WXWPARAM param)
106{
107 HTMLHELP htmlHelp = GetHtmlHelpFunction();
108
109 return htmlHelp && htmlHelp(GetSuitableHWND(win), str, cmd, param);
110}
111
f6bcfd97
BP
112bool wxCHMHelpController::DisplayContents()
113{
392c5133
VZ
114 if (m_helpFile.IsEmpty())
115 return false;
f6bcfd97 116
0016bb3b 117 return CallHtmlHelp(HH_DISPLAY_TOPIC);
f6bcfd97
BP
118}
119
120// Use topic or HTML filename
121bool wxCHMHelpController::DisplaySection(const wxString& section)
122{
392c5133
VZ
123 if (m_helpFile.IsEmpty())
124 return false;
f6bcfd97 125
f6bcfd97 126 // Is this an HTML file or a keyword?
392c5133
VZ
127 if ( section.Find(wxT(".htm")) != wxNOT_FOUND )
128 {
129 // interpret as a file name
0016bb3b 130 return CallHtmlHelp(HH_DISPLAY_TOPIC, section.wx_str());
392c5133 131 }
f6bcfd97 132
392c5133 133 return KeywordSearch(section);
f6bcfd97
BP
134}
135
136// Use context number
137bool wxCHMHelpController::DisplaySection(int section)
138{
392c5133
VZ
139 if (m_helpFile.IsEmpty())
140 return false;
f6bcfd97 141
0016bb3b 142 return CallHtmlHelp(HH_HELP_CONTEXT, section);
f6bcfd97
BP
143}
144
0016bb3b
VZ
145/* static */
146bool
147wxCHMHelpController::DoDisplayTextPopup(const wxChar *text,
148 const wxPoint& pos,
149 int contextId,
150 wxWindow *window)
5100cabf 151{
5100cabf
JS
152 HH_POPUP popup;
153 popup.cbStruct = sizeof(popup);
154 popup.hinst = (HINSTANCE) wxGetInstance();
0016bb3b
VZ
155 popup.idString = contextId;
156 popup.pszText = text;
157 popup.pt.x = pos.x;
158 popup.pt.y = pos.y;
09e02fc7
JS
159 popup.clrForeground = ::GetSysColor(COLOR_INFOTEXT);
160 popup.clrBackground = ::GetSysColor(COLOR_INFOBK);
0016bb3b
VZ
161 popup.rcMargins.top =
162 popup.rcMargins.left =
163 popup.rcMargins.right =
164 popup.rcMargins.bottom = -1;
5100cabf 165 popup.pszFont = NULL;
5100cabf 166
0016bb3b
VZ
167 return CallHtmlHelp(window, NULL, HH_DISPLAY_TEXT_POPUP, &popup);
168}
169
170bool wxCHMHelpController::DisplayContextPopup(int contextId)
171{
172 return DoDisplayTextPopup(NULL, wxGetMousePosition(), contextId,
173 GetParentWindow());
392c5133
VZ
174}
175
176bool
177wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint& pos)
178{
179 return ShowContextHelpPopup(text, pos, GetParentWindow());
5100cabf
JS
180}
181
392c5133
VZ
182/* static */
183bool wxCHMHelpController::ShowContextHelpPopup(const wxString& text,
184 const wxPoint& pos,
185 wxWindow *window)
5100cabf 186{
0016bb3b 187 return DoDisplayTextPopup(text.wx_str(), pos, 0, window);
5100cabf
JS
188}
189
f6bcfd97
BP
190bool wxCHMHelpController::DisplayBlock(long block)
191{
192 return DisplaySection(block);
193}
194
69b5cec2
VS
195bool wxCHMHelpController::KeywordSearch(const wxString& k,
196 wxHelpSearchMode WXUNUSED(mode))
f6bcfd97 197{
392c5133
VZ
198 if (m_helpFile.IsEmpty())
199 return false;
f6bcfd97 200
f6bcfd97 201 HH_AKLINK link;
0016bb3b
VZ
202 link.cbStruct = sizeof(HH_AKLINK);
203 link.fReserved = FALSE;
204 link.pszKeywords = k.wx_str();
205 link.pszUrl = NULL;
206 link.pszMsgText = NULL;
207 link.pszMsgTitle = NULL;
208 link.pszWindow = NULL;
209 link.fIndexOnFail = TRUE;
210
211 return CallHtmlHelp(HH_KEYWORD_LOOKUP, &link);
f6bcfd97
BP
212}
213
214bool wxCHMHelpController::Quit()
215{
40ec64ae 216 return CallHtmlHelp(NULL, NULL, HH_CLOSE_ALL);
f6bcfd97
BP
217}
218
0016bb3b 219wxString wxCHMHelpController::GetValidFilename() const
f6bcfd97
BP
220{
221 wxString path, name, ext;
bd365871 222 wxFileName::SplitPath(m_helpFile, &path, &name, &ext);
f6bcfd97
BP
223
224 wxString fullName;
225 if (path.IsEmpty())
226 fullName = name + wxT(".chm");
227 else if (path.Last() == wxT('\\'))
228 fullName = path + name + wxT(".chm");
229 else
230 fullName = path + wxT("\\") + name + wxT(".chm");
231 return fullName;
232}
233
234#endif // wxUSE_HELP