]> git.saurik.com Git - wxWidgets.git/blame - src/msw/helpchm.cpp
treectrl -> treetest
[wxWidgets.git] / src / msw / helpchm.cpp
CommitLineData
f6bcfd97
BP
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpchm.cpp
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
4f89dbc4 9// Licence: wxWindows licence
f6bcfd97
BP
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
3295e238 13 #pragma implementation "helpchm.h"
f6bcfd97
BP
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
3295e238 20 #pragma hdrstop
f6bcfd97
BP
21#endif
22
3295e238 23#if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
f6bcfd97
BP
24
25#include "wx/filefn.h"
f6bcfd97 26#include "wx/msw/helpchm.h"
0b9ab0bd 27
638a0b2c 28#include "wx/dynlib.h"
0b9ab0bd 29
9fcaaedd
VS
30#ifndef WX_PRECOMP
31 #include "wx/intl.h"
32 #include "wx/app.h"
33#endif
34
f6bcfd97 35#include "wx/msw/private.h"
f6bcfd97 36
3295e238 37// instead of including htmlhelp.h, duplicate the things from it we need here
f6bcfd97 38
3295e238
VZ
39enum
40{
41 HH_DISPLAY_TOPIC,
42 HH_DISPLAY_TOC,
43 HH_DISPLAY_INDEX,
44 HH_DISPLAY_SEARCH,
45 HH_SET_WIN_TYPE,
46 HH_GET_WIN_TYPE,
47 HH_GET_WIN_HANDLE,
48 HH_ENUM_INFO_TYPE,
49 HH_SET_INFO_TYPE,
50 HH_SYNC,
51 HH_RESERVED1,
52 HH_RESERVED2,
53 HH_RESERVED3,
54 HH_KEYWORD_LOOKUP,
55 HH_DISPLAY_TEXT_POPUP,
56 HH_HELP_CONTEXT,
57 HH_TP_HELP_CONTEXTMENU,
58 HH_TP_HELP_WM_HELP,
59 HH_CLOSE_ALL,
60 HH_ALINK_LOOKUP,
61 HH_GET_LAST_ERROR,
62 HH_ENUM_CATEGORY,
63 HH_ENUM_CATEGORY_IT,
64 HH_RESET_IT_FILTER,
65 HH_SET_INCLUSIVE_FILTER,
66 HH_SET_EXCLUSIVE_FILTER
67};
68
69struct HH_POPUP
70{
71 int cbStruct;
72 HINSTANCE hinst;
73 UINT idString;
74 LPCTSTR pszText;
75 POINT pt;
76 COLORREF clrForeground;
77 COLORREF clrBackground;
78 RECT rcMargins;
79 LPCTSTR pszFont;
80};
81
82struct HH_AKLINK
83{
84 int cbStruct;
85 BOOL fReserved;
86 LPCTSTR pszKeywords;
87 LPCTSTR pszUrl;
88 LPCTSTR pszMsgText;
89 LPCTSTR pszMsgTitle;
90 LPCTSTR pszWindow;
91 BOOL fIndexOnFail;
92};
93
94// ----------------------------------------------------------------------------
638a0b2c
VS
95// utility functions to manage the loading/unloading
96// of hhctrl.ocx
3295e238
VZ
97// ----------------------------------------------------------------------------
98
638a0b2c 99#ifndef UNICODE
3295e238
VZ
100 typedef HWND ( WINAPI * HTMLHELP )( HWND, LPCSTR, UINT, DWORD );
101 #define HTMLHELP_NAME "HtmlHelpA"
102#else // ANSI
103 typedef HWND ( WINAPI * HTMLHELP )( HWND, LPCWSTR, UINT, DWORD );
104 #define HTMLHELP_NAME "HtmlHelpW"
638a0b2c 105#endif
3295e238 106
4f89dbc4 107// dll symbol handle
638a0b2c 108static HTMLHELP gs_htmlHelp = 0;
638a0b2c
VS
109
110static bool LoadHtmlHelpLibrary()
111{
cd560c96 112 wxPluginLibrary *lib = wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT | wxDL_VERBATIM );
638a0b2c 113
cd560c96 114 if( !lib )
4f89dbc4
RL
115 {
116 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
117 return FALSE;
638a0b2c
VS
118 }
119 else
120 {
cd560c96 121 gs_htmlHelp = (HTMLHELP)lib->GetSymbol( HTMLHELP_NAME );
4f89dbc4
RL
122
123 if( !gs_htmlHelp )
124 {
125 wxLogError(_("Failed to initialize MS HTML Help."));
126
cd560c96 127 lib->UnrefLib();
4f89dbc4
RL
128 return FALSE ;
129 }
638a0b2c
VS
130 }
131
132 return TRUE;
133}
134
135static void UnloadHtmlHelpLibrary()
136{
cd560c96 137 if ( gs_htmlHelp )
638a0b2c 138 {
4f89dbc4 139 wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") );
3295e238 140
638a0b2c
VS
141 gs_htmlHelp = 0;
142 }
143}
144
f6bcfd97
BP
145static HWND GetSuitableHWND()
146{
147 if (wxTheApp->GetTopWindow())
148 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
149 else
150 return GetDesktopWindow();
151}
152
153IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController, wxHelpControllerBase)
154
155bool wxCHMHelpController::Initialize(const wxString& filename)
156{
638a0b2c
VS
157 // warn on failure
158 if( !LoadHtmlHelpLibrary() )
159 return FALSE;
160
f6bcfd97
BP
161 m_helpFile = filename;
162 return TRUE;
163}
164
165bool wxCHMHelpController::LoadFile(const wxString& file)
166{
167 if (!file.IsEmpty())
168 m_helpFile = file;
169 return TRUE;
170}
171
172bool wxCHMHelpController::DisplayContents()
173{
174 if (m_helpFile.IsEmpty()) return FALSE;
175
176 wxString str = GetValidFilename(m_helpFile);
177
3295e238 178 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TOPIC, 0L);
f6bcfd97
BP
179 return TRUE;
180}
181
182// Use topic or HTML filename
183bool wxCHMHelpController::DisplaySection(const wxString& section)
184{
185 if (m_helpFile.IsEmpty()) return FALSE;
186
187 wxString str = GetValidFilename(m_helpFile);
188
189 // Is this an HTML file or a keyword?
190 bool isFilename = (section.Find(wxT(".htm")) != -1);
191
192 if (isFilename)
638a0b2c 193 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TOPIC, (DWORD) (const wxChar*) section);
f6bcfd97
BP
194 else
195 KeywordSearch(section);
196 return TRUE;
197}
198
199// Use context number
200bool wxCHMHelpController::DisplaySection(int section)
201{
202 if (m_helpFile.IsEmpty()) return FALSE;
203
204 wxString str = GetValidFilename(m_helpFile);
205
638a0b2c 206 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)section);
f6bcfd97
BP
207 return TRUE;
208}
209
5100cabf
JS
210bool wxCHMHelpController::DisplayContextPopup(int contextId)
211{
212 if (m_helpFile.IsEmpty()) return FALSE;
213
214 wxString str = GetValidFilename(m_helpFile);
215
a1b8f548
JS
216 // We also have to specify the popups file (default is cshelp.txt).
217 // str += wxT("::/cshelp.txt");
218
5100cabf
JS
219 HH_POPUP popup;
220 popup.cbStruct = sizeof(popup);
221 popup.hinst = (HINSTANCE) wxGetInstance();
222 popup.idString = contextId ;
223
224 GetCursorPos(& popup.pt);
5438a566
VZ
225 popup.clrForeground = (COLORREF)-1;
226 popup.clrBackground = (COLORREF)-1;
5100cabf
JS
227 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
228 popup.pszFont = NULL;
229 popup.pszText = NULL;
230
638a0b2c 231 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
5100cabf
JS
232 return TRUE;
233}
234
235bool wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint& pos)
236{
237 HH_POPUP popup;
238 popup.cbStruct = sizeof(popup);
239 popup.hinst = (HINSTANCE) wxGetInstance();
240 popup.idString = 0 ;
241 popup.pt.x = pos.x; popup.pt.y = pos.y;
5438a566
VZ
242 popup.clrForeground = (COLORREF)-1;
243 popup.clrBackground = (COLORREF)-1;
5100cabf
JS
244 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
245 popup.pszFont = NULL;
246 popup.pszText = (const wxChar*) text;
247
638a0b2c 248 gs_htmlHelp(GetSuitableHWND(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
5100cabf
JS
249 return TRUE;
250}
251
f6bcfd97
BP
252bool wxCHMHelpController::DisplayBlock(long block)
253{
254 return DisplaySection(block);
255}
256
257bool wxCHMHelpController::KeywordSearch(const wxString& k)
258{
259 if (m_helpFile.IsEmpty()) return FALSE;
260
261 wxString str = GetValidFilename(m_helpFile);
262
263 HH_AKLINK link;
264 link.cbStruct = sizeof(HH_AKLINK) ;
265 link.fReserved = FALSE ;
266 link.pszKeywords = k.c_str() ;
267 link.pszUrl = NULL ;
268 link.pszMsgText = NULL ;
269 link.pszMsgTitle = NULL ;
270 link.pszWindow = NULL ;
271 link.fIndexOnFail = TRUE ;
272
638a0b2c 273 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
f6bcfd97
BP
274 return TRUE;
275}
276
277bool wxCHMHelpController::Quit()
278{
638a0b2c 279 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL, 0L);
638a0b2c 280
f6bcfd97
BP
281 return TRUE;
282}
283
284// Append extension if necessary.
285wxString wxCHMHelpController::GetValidFilename(const wxString& file) const
286{
287 wxString path, name, ext;
288 wxSplitPath(file, & path, & name, & ext);
289
290 wxString fullName;
291 if (path.IsEmpty())
292 fullName = name + wxT(".chm");
293 else if (path.Last() == wxT('\\'))
294 fullName = path + name + wxT(".chm");
295 else
296 fullName = path + wxT("\\") + name + wxT(".chm");
297 return fullName;
298}
299
3295e238
VZ
300wxCHMHelpController::~wxCHMHelpController()
301{
302 UnloadHtmlHelpLibrary();
303}
304
f6bcfd97 305#endif // wxUSE_HELP
4f89dbc4 306