]>
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"
27 #include "wx/filefn.h"
29 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
30 #include "wx/msw/helpchm.h"
32 #if wxUSE_DYNAMIC_LOADER || wxUSE_DYNLIB_CLASS
33 #include "wx/dynlib.h"
40 // This is found in the HTML Help Workshop installation,
41 // along with htmlhelp.lib.
47 #include "wx/msw/private.h"
52 // utility functions to manage the loading/unloading
55 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
56 #define HTMLHELP_NAME "HtmlHelpA"
58 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
59 #define HTMLHELP_NAME "HtmlHelpW"
61 // dll handle/reference count
62 static HTMLHELP gs_htmlHelp
= 0;
63 static wxDllType gs_dllHandle
= 0;
64 static int gs_dllCount
= 0;
66 static bool LoadHtmlHelpLibrary()
70 gs_dllHandle
= wxDllLoader::LoadLibrary( "hhctrl.ocx" );
73 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
79 gs_htmlHelp
= (HTMLHELP
)wxDllLoader::GetSymbol( gs_dllHandle
, HTMLHELP_NAME
);
83 wxLogError(_("Failed to initialize MS HTML Help."));
85 wxDllLoader::UnloadLibrary(gs_dllHandle
);
101 static void UnloadHtmlHelpLibrary()
103 if( gs_dllCount
!= 0 && !--gs_dllCount
)
105 wxDllLoader::UnloadLibrary( gs_dllHandle
);
111 static HWND
GetSuitableHWND()
113 if (wxTheApp
->GetTopWindow())
114 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
116 return GetDesktopWindow();
119 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
121 bool wxCHMHelpController::Initialize(const wxString
& filename
)
124 if( !LoadHtmlHelpLibrary() )
127 m_helpFile
= filename
;
131 bool wxCHMHelpController::LoadFile(const wxString
& file
)
138 bool wxCHMHelpController::DisplayContents()
140 if (m_helpFile
.IsEmpty()) return FALSE
;
142 wxString str
= GetValidFilename(m_helpFile
);
144 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_FINDER
, 0L);
148 // Use topic or HTML filename
149 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
151 if (m_helpFile
.IsEmpty()) return FALSE
;
153 wxString str
= GetValidFilename(m_helpFile
);
155 // Is this an HTML file or a keyword?
156 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
159 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
161 KeywordSearch(section
);
165 // Use context number
166 bool wxCHMHelpController::DisplaySection(int section
)
168 if (m_helpFile
.IsEmpty()) return FALSE
;
170 wxString str
= GetValidFilename(m_helpFile
);
172 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
176 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
178 if (m_helpFile
.IsEmpty()) return FALSE
;
180 wxString str
= GetValidFilename(m_helpFile
);
182 // We also have to specify the popups file (default is cshelp.txt).
183 // str += wxT("::/cshelp.txt");
186 popup
.cbStruct
= sizeof(popup
);
187 popup
.hinst
= (HINSTANCE
) wxGetInstance();
188 popup
.idString
= contextId
;
190 GetCursorPos(& popup
.pt
);
191 popup
.clrForeground
= (COLORREF
)-1;
192 popup
.clrBackground
= (COLORREF
)-1;
193 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
194 popup
.pszFont
= NULL
;
195 popup
.pszText
= NULL
;
197 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
201 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
204 popup
.cbStruct
= sizeof(popup
);
205 popup
.hinst
= (HINSTANCE
) wxGetInstance();
207 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
208 popup
.clrForeground
= (COLORREF
)-1;
209 popup
.clrBackground
= (COLORREF
)-1;
210 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
211 popup
.pszFont
= NULL
;
212 popup
.pszText
= (const wxChar
*) text
;
214 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
218 bool wxCHMHelpController::DisplayBlock(long block
)
220 return DisplaySection(block
);
223 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
225 if (m_helpFile
.IsEmpty()) return FALSE
;
227 wxString str
= GetValidFilename(m_helpFile
);
230 link
.cbStruct
= sizeof(HH_AKLINK
) ;
231 link
.fReserved
= FALSE
;
232 link
.pszKeywords
= k
.c_str() ;
234 link
.pszMsgText
= NULL
;
235 link
.pszMsgTitle
= NULL
;
236 link
.pszWindow
= NULL
;
237 link
.fIndexOnFail
= TRUE
;
239 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
243 bool wxCHMHelpController::Quit()
245 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
246 UnloadHtmlHelpLibrary();
251 // Append extension if necessary.
252 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
254 wxString path
, name
, ext
;
255 wxSplitPath(file
, & path
, & name
, & ext
);
259 fullName
= name
+ wxT(".chm");
260 else if (path
.Last() == wxT('\\'))
261 fullName
= path
+ name
+ wxT(".chm");
263 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");