]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
4f26427f28915dfabb734df23a02774cf18b8b1d
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help system: MS HTML Help implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "helpchm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
25 #include "wx/filefn.h"
26 #include "wx/msw/helpchm.h"
28 #include "wx/dynlib.h"
30 #include "wx/msw/private.h"
32 // instead of including htmlhelp.h, duplicate the things from it we need here
50 HH_DISPLAY_TEXT_POPUP
,
52 HH_TP_HELP_CONTEXTMENU
,
60 HH_SET_INCLUSIVE_FILTER
,
61 HH_SET_EXCLUSIVE_FILTER
71 COLORREF clrForeground
;
72 COLORREF clrBackground
;
89 // ----------------------------------------------------------------------------
90 // utility functions to manage the loading/unloading
92 // ----------------------------------------------------------------------------
95 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
96 #define HTMLHELP_NAME "HtmlHelpA"
98 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
99 #define HTMLHELP_NAME "HtmlHelpW"
103 static HTMLHELP gs_htmlHelp
= 0;
105 static bool LoadHtmlHelpLibrary()
107 wxPluginLibrary
*lib
= wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT
| wxDL_VERBATIM
);
111 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
116 gs_htmlHelp
= (HTMLHELP
)lib
->GetSymbol( HTMLHELP_NAME
);
120 wxLogError(_("Failed to initialize MS HTML Help."));
130 static void UnloadHtmlHelpLibrary()
134 wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") );
140 static HWND
GetSuitableHWND()
142 if (wxTheApp
->GetTopWindow())
143 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
145 return GetDesktopWindow();
148 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
150 bool wxCHMHelpController::Initialize(const wxString
& filename
)
153 if( !LoadHtmlHelpLibrary() )
156 m_helpFile
= filename
;
160 bool wxCHMHelpController::LoadFile(const wxString
& file
)
167 bool wxCHMHelpController::DisplayContents()
169 if (m_helpFile
.IsEmpty()) return FALSE
;
171 wxString str
= GetValidFilename(m_helpFile
);
173 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, 0L);
177 // Use topic or HTML filename
178 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
180 if (m_helpFile
.IsEmpty()) return FALSE
;
182 wxString str
= GetValidFilename(m_helpFile
);
184 // Is this an HTML file or a keyword?
185 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
188 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
190 KeywordSearch(section
);
194 // Use context number
195 bool wxCHMHelpController::DisplaySection(int section
)
197 if (m_helpFile
.IsEmpty()) return FALSE
;
199 wxString str
= GetValidFilename(m_helpFile
);
201 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
205 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
207 if (m_helpFile
.IsEmpty()) return FALSE
;
209 wxString str
= GetValidFilename(m_helpFile
);
211 // We also have to specify the popups file (default is cshelp.txt).
212 // str += wxT("::/cshelp.txt");
215 popup
.cbStruct
= sizeof(popup
);
216 popup
.hinst
= (HINSTANCE
) wxGetInstance();
217 popup
.idString
= contextId
;
219 GetCursorPos(& popup
.pt
);
220 popup
.clrForeground
= (COLORREF
)-1;
221 popup
.clrBackground
= (COLORREF
)-1;
222 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
223 popup
.pszFont
= NULL
;
224 popup
.pszText
= NULL
;
226 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
230 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
233 popup
.cbStruct
= sizeof(popup
);
234 popup
.hinst
= (HINSTANCE
) wxGetInstance();
236 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
237 popup
.clrForeground
= (COLORREF
)-1;
238 popup
.clrBackground
= (COLORREF
)-1;
239 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
240 popup
.pszFont
= NULL
;
241 popup
.pszText
= (const wxChar
*) text
;
243 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
247 bool wxCHMHelpController::DisplayBlock(long block
)
249 return DisplaySection(block
);
252 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
254 if (m_helpFile
.IsEmpty()) return FALSE
;
256 wxString str
= GetValidFilename(m_helpFile
);
259 link
.cbStruct
= sizeof(HH_AKLINK
) ;
260 link
.fReserved
= FALSE
;
261 link
.pszKeywords
= k
.c_str() ;
263 link
.pszMsgText
= NULL
;
264 link
.pszMsgTitle
= NULL
;
265 link
.pszWindow
= NULL
;
266 link
.fIndexOnFail
= TRUE
;
268 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
272 bool wxCHMHelpController::Quit()
274 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
279 // Append extension if necessary.
280 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
282 wxString path
, name
, ext
;
283 wxSplitPath(file
, & path
, & name
, & ext
);
287 fullName
= name
+ wxT(".chm");
288 else if (path
.Last() == wxT('\\'))
289 fullName
= path
+ name
+ wxT(".chm");
291 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");
295 wxCHMHelpController::~wxCHMHelpController()
297 UnloadHtmlHelpLibrary();