]>
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 #include "wx/dynlib.h"
38 // This is found in the HTML Help Workshop installation,
39 // along with htmlhelp.lib.
45 #include "wx/msw/private.h"
50 // utility functions to manage the loading/unloading
53 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
54 #define HTMLHELP_NAME "HtmlHelpA"
56 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
57 #define HTMLHELP_NAME "HtmlHelpW"
59 // dll handle/reference count
60 static HTMLHELP gs_htmlHelp
= 0;
61 static wxDllType gs_dllHandle
= 0;
62 static int gs_dllCount
= 0;
64 static bool LoadHtmlHelpLibrary()
68 gs_dllHandle
= wxDllLoader::LoadLibrary( "hhctrl.ocx" );
71 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
77 gs_htmlHelp
= (HTMLHELP
)wxDllLoader::GetSymbol( gs_dllHandle
, HTMLHELP_NAME
);
81 wxLogError(_("Failed to initialize MS HTML Help."));
83 wxDllLoader::UnloadLibrary(gs_dllHandle
);
99 static void UnloadHtmlHelpLibrary()
101 if( gs_dllCount
!= 0 && !--gs_dllCount
)
103 wxDllLoader::UnloadLibrary( gs_dllHandle
);
109 static HWND
GetSuitableHWND()
111 if (wxTheApp
->GetTopWindow())
112 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
114 return GetDesktopWindow();
117 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
119 bool wxCHMHelpController::Initialize(const wxString
& filename
)
122 if( !LoadHtmlHelpLibrary() )
125 m_helpFile
= filename
;
129 bool wxCHMHelpController::LoadFile(const wxString
& file
)
136 bool wxCHMHelpController::DisplayContents()
138 if (m_helpFile
.IsEmpty()) return FALSE
;
140 wxString str
= GetValidFilename(m_helpFile
);
142 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_FINDER
, 0L);
146 // Use topic or HTML filename
147 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
149 if (m_helpFile
.IsEmpty()) return FALSE
;
151 wxString str
= GetValidFilename(m_helpFile
);
153 // Is this an HTML file or a keyword?
154 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
157 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
159 KeywordSearch(section
);
163 // Use context number
164 bool wxCHMHelpController::DisplaySection(int section
)
166 if (m_helpFile
.IsEmpty()) return FALSE
;
168 wxString str
= GetValidFilename(m_helpFile
);
170 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
174 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
176 if (m_helpFile
.IsEmpty()) return FALSE
;
178 wxString str
= GetValidFilename(m_helpFile
);
180 // We also have to specify the popups file (default is cshelp.txt).
181 // str += wxT("::/cshelp.txt");
184 popup
.cbStruct
= sizeof(popup
);
185 popup
.hinst
= (HINSTANCE
) wxGetInstance();
186 popup
.idString
= contextId
;
188 GetCursorPos(& popup
.pt
);
189 popup
.clrForeground
= (COLORREF
)-1;
190 popup
.clrBackground
= (COLORREF
)-1;
191 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
192 popup
.pszFont
= NULL
;
193 popup
.pszText
= NULL
;
195 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
199 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
202 popup
.cbStruct
= sizeof(popup
);
203 popup
.hinst
= (HINSTANCE
) wxGetInstance();
205 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
206 popup
.clrForeground
= (COLORREF
)-1;
207 popup
.clrBackground
= (COLORREF
)-1;
208 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
209 popup
.pszFont
= NULL
;
210 popup
.pszText
= (const wxChar
*) text
;
212 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
216 bool wxCHMHelpController::DisplayBlock(long block
)
218 return DisplaySection(block
);
221 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
223 if (m_helpFile
.IsEmpty()) return FALSE
;
225 wxString str
= GetValidFilename(m_helpFile
);
228 link
.cbStruct
= sizeof(HH_AKLINK
) ;
229 link
.fReserved
= FALSE
;
230 link
.pszKeywords
= k
.c_str() ;
232 link
.pszMsgText
= NULL
;
233 link
.pszMsgTitle
= NULL
;
234 link
.pszWindow
= NULL
;
235 link
.fIndexOnFail
= TRUE
;
237 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
241 bool wxCHMHelpController::Quit()
243 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
244 UnloadHtmlHelpLibrary();
249 // Append extension if necessary.
250 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
252 wxString path
, name
, ext
;
253 wxSplitPath(file
, & path
, & name
, & ext
);
257 fullName
= name
+ wxT(".chm");
258 else if (path
.Last() == wxT('\\'))
259 fullName
= path
+ name
+ wxT(".chm");
261 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");