]>
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"
31 #include "wx/dynlib.h"
37 // This is found in the HTML Help Workshop installation,
38 // along with htmlhelp.lib.
44 #include "wx/msw/private.h"
49 // utility functions to manage the loading/unloading
52 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
53 #define HTMLHELP_NAME "HtmlHelpA"
55 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
56 #define HTMLHELP_NAME "HtmlHelpW"
58 // dll handle/reference count
59 static HTMLHELP gs_htmlHelp
= 0;
60 static wxDllType gs_dllHandle
= 0;
61 static int gs_dllCount
= 0;
63 static bool LoadHtmlHelpLibrary()
67 gs_dllHandle
= wxDllLoader::LoadLibrary( "hhctrl.ocx" );
70 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
76 gs_htmlHelp
= (HTMLHELP
)wxDllLoader::GetSymbol( gs_dllHandle
, HTMLHELP_NAME
);
80 wxLogError(_("Failed to initialize MS HTML Help."));
82 wxDllLoader::UnloadLibrary(gs_dllHandle
);
98 static void UnloadHtmlHelpLibrary()
100 if( gs_dllCount
!= 0 && !--gs_dllCount
)
102 wxDllLoader::UnloadLibrary( gs_dllHandle
);
108 static HWND
GetSuitableHWND()
110 if (wxTheApp
->GetTopWindow())
111 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
113 return GetDesktopWindow();
116 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
118 bool wxCHMHelpController::Initialize(const wxString
& filename
)
121 if( !LoadHtmlHelpLibrary() )
124 m_helpFile
= filename
;
128 bool wxCHMHelpController::LoadFile(const wxString
& file
)
135 bool wxCHMHelpController::DisplayContents()
137 if (m_helpFile
.IsEmpty()) return FALSE
;
139 wxString str
= GetValidFilename(m_helpFile
);
141 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_FINDER
, 0L);
145 // Use topic or HTML filename
146 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
148 if (m_helpFile
.IsEmpty()) return FALSE
;
150 wxString str
= GetValidFilename(m_helpFile
);
152 // Is this an HTML file or a keyword?
153 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
156 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
158 KeywordSearch(section
);
162 // Use context number
163 bool wxCHMHelpController::DisplaySection(int section
)
165 if (m_helpFile
.IsEmpty()) return FALSE
;
167 wxString str
= GetValidFilename(m_helpFile
);
169 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
173 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
175 if (m_helpFile
.IsEmpty()) return FALSE
;
177 wxString str
= GetValidFilename(m_helpFile
);
179 // We also have to specify the popups file (default is cshelp.txt).
180 // str += wxT("::/cshelp.txt");
183 popup
.cbStruct
= sizeof(popup
);
184 popup
.hinst
= (HINSTANCE
) wxGetInstance();
185 popup
.idString
= contextId
;
187 GetCursorPos(& popup
.pt
);
188 popup
.clrForeground
= (COLORREF
)-1;
189 popup
.clrBackground
= (COLORREF
)-1;
190 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
191 popup
.pszFont
= NULL
;
192 popup
.pszText
= NULL
;
194 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
198 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
201 popup
.cbStruct
= sizeof(popup
);
202 popup
.hinst
= (HINSTANCE
) wxGetInstance();
204 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
205 popup
.clrForeground
= (COLORREF
)-1;
206 popup
.clrBackground
= (COLORREF
)-1;
207 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
208 popup
.pszFont
= NULL
;
209 popup
.pszText
= (const wxChar
*) text
;
211 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
215 bool wxCHMHelpController::DisplayBlock(long block
)
217 return DisplaySection(block
);
220 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
222 if (m_helpFile
.IsEmpty()) return FALSE
;
224 wxString str
= GetValidFilename(m_helpFile
);
227 link
.cbStruct
= sizeof(HH_AKLINK
) ;
228 link
.fReserved
= FALSE
;
229 link
.pszKeywords
= k
.c_str() ;
231 link
.pszMsgText
= NULL
;
232 link
.pszMsgTitle
= NULL
;
233 link
.pszWindow
= NULL
;
234 link
.fIndexOnFail
= TRUE
;
236 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
240 bool wxCHMHelpController::Quit()
242 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
243 UnloadHtmlHelpLibrary();
248 // Append extension if necessary.
249 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
251 wxString path
, name
, ext
;
252 wxSplitPath(file
, & path
, & name
, & ext
);
256 fullName
= name
+ wxT(".chm");
257 else if (path
.Last() == wxT('\\'))
258 fullName
= path
+ name
+ wxT(".chm");
260 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");