]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
88dff23aab0bda1c4e7f2a596592199340925fce
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;
104 static wxPluginLibrary
*gs_libHtmlHelp
= NULL
;
106 static bool LoadHtmlHelpLibrary()
108 gs_libHtmlHelp
= wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT
| wxDL_VERBATIM
);
110 if( !gs_libHtmlHelp
)
112 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
117 gs_htmlHelp
= (HTMLHELP
)gs_libHtmlHelp
->GetSymbol( HTMLHELP_NAME
);
121 wxLogError(_("Failed to initialize MS HTML Help."));
123 gs_libHtmlHelp
->UnrefLib();
131 static void UnloadHtmlHelpLibrary()
135 wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") );
136 gs_libHtmlHelp
->UnrefLib();
142 static HWND
GetSuitableHWND()
144 if (wxTheApp
->GetTopWindow())
145 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
147 return GetDesktopWindow();
150 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
152 bool wxCHMHelpController::Initialize(const wxString
& filename
)
155 if( !LoadHtmlHelpLibrary() )
158 m_helpFile
= filename
;
162 bool wxCHMHelpController::LoadFile(const wxString
& file
)
169 bool wxCHMHelpController::DisplayContents()
171 if (m_helpFile
.IsEmpty()) return FALSE
;
173 wxString str
= GetValidFilename(m_helpFile
);
175 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, 0L);
179 // Use topic or HTML filename
180 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
182 if (m_helpFile
.IsEmpty()) return FALSE
;
184 wxString str
= GetValidFilename(m_helpFile
);
186 // Is this an HTML file or a keyword?
187 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
190 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
192 KeywordSearch(section
);
196 // Use context number
197 bool wxCHMHelpController::DisplaySection(int section
)
199 if (m_helpFile
.IsEmpty()) return FALSE
;
201 wxString str
= GetValidFilename(m_helpFile
);
203 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
207 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
209 if (m_helpFile
.IsEmpty()) return FALSE
;
211 wxString str
= GetValidFilename(m_helpFile
);
213 // We also have to specify the popups file (default is cshelp.txt).
214 // str += wxT("::/cshelp.txt");
217 popup
.cbStruct
= sizeof(popup
);
218 popup
.hinst
= (HINSTANCE
) wxGetInstance();
219 popup
.idString
= contextId
;
221 GetCursorPos(& popup
.pt
);
222 popup
.clrForeground
= (COLORREF
)-1;
223 popup
.clrBackground
= (COLORREF
)-1;
224 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
225 popup
.pszFont
= NULL
;
226 popup
.pszText
= NULL
;
228 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
232 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
235 popup
.cbStruct
= sizeof(popup
);
236 popup
.hinst
= (HINSTANCE
) wxGetInstance();
238 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
239 popup
.clrForeground
= (COLORREF
)-1;
240 popup
.clrBackground
= (COLORREF
)-1;
241 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
242 popup
.pszFont
= NULL
;
243 popup
.pszText
= (const wxChar
*) text
;
245 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
249 bool wxCHMHelpController::DisplayBlock(long block
)
251 return DisplaySection(block
);
254 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
256 if (m_helpFile
.IsEmpty()) return FALSE
;
258 wxString str
= GetValidFilename(m_helpFile
);
261 link
.cbStruct
= sizeof(HH_AKLINK
) ;
262 link
.fReserved
= FALSE
;
263 link
.pszKeywords
= k
.c_str() ;
265 link
.pszMsgText
= NULL
;
266 link
.pszMsgTitle
= NULL
;
267 link
.pszWindow
= NULL
;
268 link
.fIndexOnFail
= TRUE
;
270 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
274 bool wxCHMHelpController::Quit()
276 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
281 // Append extension if necessary.
282 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
284 wxString path
, name
, ext
;
285 wxSplitPath(file
, & path
, & name
, & ext
);
289 fullName
= name
+ wxT(".chm");
290 else if (path
.Last() == wxT('\\'))
291 fullName
= path
+ name
+ wxT(".chm");
293 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");
297 wxCHMHelpController::~wxCHMHelpController()
299 UnloadHtmlHelpLibrary();