]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/helpchm.cpp
some really ancient tips updated, mention make problems and flex version minimal...
[wxWidgets.git] / src / msw / helpchm.cpp
... / ...
CommitLineData
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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "helpchm.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/defs.h"
25#endif
26
27#include "wx/filefn.h"
28
29#if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
30#include "wx/msw/helpchm.h"
31
32#include "wx/dynlib.h"
33
34#ifndef WX_PRECOMP
35#include <windows.h>
36#endif
37
38// This is found in the HTML Help Workshop installation,
39// along with htmlhelp.lib.
40#include <htmlhelp.h>
41
42#include <time.h>
43
44#ifdef __WXMSW__
45#include "wx/msw/private.h"
46#endif
47
48#include <string.h>
49
50// utility functions to manage the loading/unloading
51// of hhctrl.ocx
52#ifndef UNICODE
53typedef HWND ( WINAPI * HTMLHELP )( HWND, LPCSTR, UINT, DWORD );
54#define HTMLHELP_NAME "HtmlHelpA"
55#else
56typedef HWND ( WINAPI * HTMLHELP )( HWND, LPCWSTR, UINT, DWORD );
57#define HTMLHELP_NAME "HtmlHelpW"
58#endif
59// dll symbol handle
60static HTMLHELP gs_htmlHelp = 0;
61
62static bool LoadHtmlHelpLibrary()
63{
64 wxPluginLibrary *lib = wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT | wxDL_VERBATIM );
65
66 if( !lib->IsLoaded() )
67 {
68 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
69 return FALSE;
70 }
71 else
72 {
73 gs_htmlHelp = (HTMLHELP)lib->GetSymbol( HTMLHELP_NAME );
74
75 if( !gs_htmlHelp )
76 {
77 wxLogError(_("Failed to initialize MS HTML Help."));
78
79 lib->UnrefLib();
80 return FALSE ;
81 }
82 }
83
84 return TRUE;
85}
86
87static void UnloadHtmlHelpLibrary()
88{
89 if( gs_htmlHelp )
90 {
91 wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") );
92 gs_htmlHelp = 0;
93 }
94}
95
96static HWND GetSuitableHWND()
97{
98 if (wxTheApp->GetTopWindow())
99 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
100 else
101 return GetDesktopWindow();
102}
103
104IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController, wxHelpControllerBase)
105
106bool wxCHMHelpController::Initialize(const wxString& filename)
107{
108 // warn on failure
109 if( !LoadHtmlHelpLibrary() )
110 return FALSE;
111
112 m_helpFile = filename;
113 return TRUE;
114}
115
116bool wxCHMHelpController::LoadFile(const wxString& file)
117{
118 if (!file.IsEmpty())
119 m_helpFile = file;
120 return TRUE;
121}
122
123bool wxCHMHelpController::DisplayContents()
124{
125 if (m_helpFile.IsEmpty()) return FALSE;
126
127 wxString str = GetValidFilename(m_helpFile);
128
129 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_FINDER, 0L);
130 return TRUE;
131}
132
133// Use topic or HTML filename
134bool wxCHMHelpController::DisplaySection(const wxString& section)
135{
136 if (m_helpFile.IsEmpty()) return FALSE;
137
138 wxString str = GetValidFilename(m_helpFile);
139
140 // Is this an HTML file or a keyword?
141 bool isFilename = (section.Find(wxT(".htm")) != -1);
142
143 if (isFilename)
144 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TOPIC, (DWORD) (const wxChar*) section);
145 else
146 KeywordSearch(section);
147 return TRUE;
148}
149
150// Use context number
151bool wxCHMHelpController::DisplaySection(int section)
152{
153 if (m_helpFile.IsEmpty()) return FALSE;
154
155 wxString str = GetValidFilename(m_helpFile);
156
157 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)section);
158 return TRUE;
159}
160
161bool wxCHMHelpController::DisplayContextPopup(int contextId)
162{
163 if (m_helpFile.IsEmpty()) return FALSE;
164
165 wxString str = GetValidFilename(m_helpFile);
166
167 // We also have to specify the popups file (default is cshelp.txt).
168 // str += wxT("::/cshelp.txt");
169
170 HH_POPUP popup;
171 popup.cbStruct = sizeof(popup);
172 popup.hinst = (HINSTANCE) wxGetInstance();
173 popup.idString = contextId ;
174
175 GetCursorPos(& popup.pt);
176 popup.clrForeground = (COLORREF)-1;
177 popup.clrBackground = (COLORREF)-1;
178 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
179 popup.pszFont = NULL;
180 popup.pszText = NULL;
181
182 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
183 return TRUE;
184}
185
186bool wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint& pos)
187{
188 HH_POPUP popup;
189 popup.cbStruct = sizeof(popup);
190 popup.hinst = (HINSTANCE) wxGetInstance();
191 popup.idString = 0 ;
192 popup.pt.x = pos.x; popup.pt.y = pos.y;
193 popup.clrForeground = (COLORREF)-1;
194 popup.clrBackground = (COLORREF)-1;
195 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
196 popup.pszFont = NULL;
197 popup.pszText = (const wxChar*) text;
198
199 gs_htmlHelp(GetSuitableHWND(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
200 return TRUE;
201}
202
203bool wxCHMHelpController::DisplayBlock(long block)
204{
205 return DisplaySection(block);
206}
207
208bool wxCHMHelpController::KeywordSearch(const wxString& k)
209{
210 if (m_helpFile.IsEmpty()) return FALSE;
211
212 wxString str = GetValidFilename(m_helpFile);
213
214 HH_AKLINK link;
215 link.cbStruct = sizeof(HH_AKLINK) ;
216 link.fReserved = FALSE ;
217 link.pszKeywords = k.c_str() ;
218 link.pszUrl = NULL ;
219 link.pszMsgText = NULL ;
220 link.pszMsgTitle = NULL ;
221 link.pszWindow = NULL ;
222 link.fIndexOnFail = TRUE ;
223
224 gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
225 return TRUE;
226}
227
228bool wxCHMHelpController::Quit()
229{
230 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL, 0L);
231 UnloadHtmlHelpLibrary();
232
233 return TRUE;
234}
235
236// Append extension if necessary.
237wxString wxCHMHelpController::GetValidFilename(const wxString& file) const
238{
239 wxString path, name, ext;
240 wxSplitPath(file, & path, & name, & ext);
241
242 wxString fullName;
243 if (path.IsEmpty())
244 fullName = name + wxT(".chm");
245 else if (path.Last() == wxT('\\'))
246 fullName = path + name + wxT(".chm");
247 else
248 fullName = path + wxT("\\") + name + wxT(".chm");
249 return fullName;
250}
251
252#endif // wxUSE_HELP
253
254// vi:sts=4:sw=4:et