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