]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
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"
35 #include "wx/msw/private.h"
37 // instead of including htmlhelp.h, duplicate the things from it we need here
55 HH_DISPLAY_TEXT_POPUP
,
57 HH_TP_HELP_CONTEXTMENU
,
65 HH_SET_INCLUSIVE_FILTER
,
66 HH_SET_EXCLUSIVE_FILTER
76 COLORREF clrForeground
;
77 COLORREF clrBackground
;
94 // ----------------------------------------------------------------------------
95 // utility functions to manage the loading/unloading
97 // ----------------------------------------------------------------------------
100 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
101 #define HTMLHELP_NAME "HtmlHelpA"
103 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
104 #define HTMLHELP_NAME "HtmlHelpW"
108 static HTMLHELP gs_htmlHelp
= 0;
110 static bool LoadHtmlHelpLibrary()
112 wxPluginLibrary
*lib
= wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT
| wxDL_VERBATIM
);
116 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
121 gs_htmlHelp
= (HTMLHELP
)lib
->GetSymbol( HTMLHELP_NAME
);
125 wxLogError(_("Failed to initialize MS HTML Help."));
135 static void UnloadHtmlHelpLibrary()
139 wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") );
145 static HWND
GetSuitableHWND()
147 if (wxTheApp
->GetTopWindow())
148 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
150 return GetDesktopWindow();
153 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
155 bool wxCHMHelpController::Initialize(const wxString
& filename
)
158 if( !LoadHtmlHelpLibrary() )
161 m_helpFile
= filename
;
165 bool wxCHMHelpController::LoadFile(const wxString
& file
)
172 bool wxCHMHelpController::DisplayContents()
174 if (m_helpFile
.IsEmpty()) return FALSE
;
176 wxString str
= GetValidFilename(m_helpFile
);
178 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, 0L);
182 // Use topic or HTML filename
183 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
185 if (m_helpFile
.IsEmpty()) return FALSE
;
187 wxString str
= GetValidFilename(m_helpFile
);
189 // Is this an HTML file or a keyword?
190 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
193 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
195 KeywordSearch(section
);
199 // Use context number
200 bool wxCHMHelpController::DisplaySection(int section
)
202 if (m_helpFile
.IsEmpty()) return FALSE
;
204 wxString str
= GetValidFilename(m_helpFile
);
206 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
210 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
212 if (m_helpFile
.IsEmpty()) return FALSE
;
214 wxString str
= GetValidFilename(m_helpFile
);
216 // We also have to specify the popups file (default is cshelp.txt).
217 // str += wxT("::/cshelp.txt");
220 popup
.cbStruct
= sizeof(popup
);
221 popup
.hinst
= (HINSTANCE
) wxGetInstance();
222 popup
.idString
= contextId
;
224 GetCursorPos(& popup
.pt
);
225 popup
.clrForeground
= (COLORREF
)-1;
226 popup
.clrBackground
= (COLORREF
)-1;
227 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
228 popup
.pszFont
= NULL
;
229 popup
.pszText
= NULL
;
231 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
235 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
238 popup
.cbStruct
= sizeof(popup
);
239 popup
.hinst
= (HINSTANCE
) wxGetInstance();
241 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
242 popup
.clrForeground
= (COLORREF
)-1;
243 popup
.clrBackground
= (COLORREF
)-1;
244 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
245 popup
.pszFont
= NULL
;
246 popup
.pszText
= (const wxChar
*) text
;
248 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
252 bool wxCHMHelpController::DisplayBlock(long block
)
254 return DisplaySection(block
);
257 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
259 if (m_helpFile
.IsEmpty()) return FALSE
;
261 wxString str
= GetValidFilename(m_helpFile
);
264 link
.cbStruct
= sizeof(HH_AKLINK
) ;
265 link
.fReserved
= FALSE
;
266 link
.pszKeywords
= k
.c_str() ;
268 link
.pszMsgText
= NULL
;
269 link
.pszMsgTitle
= NULL
;
270 link
.pszWindow
= NULL
;
271 link
.fIndexOnFail
= TRUE
;
273 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
277 bool wxCHMHelpController::Quit()
279 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
284 // Append extension if necessary.
285 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
287 wxString path
, name
, ext
;
288 wxSplitPath(file
, & path
, & name
, & ext
);
292 fullName
= name
+ wxT(".chm");
293 else if (path
.Last() == wxT('\\'))
294 fullName
= path
+ name
+ wxT(".chm");
296 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");
300 wxCHMHelpController::~wxCHMHelpController()
302 UnloadHtmlHelpLibrary();