]>
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"
60 static HTMLHELP gs_htmlHelp
= 0;
62 static bool LoadHtmlHelpLibrary()
64 wxPluginLibrary
*lib
= wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT
| wxDL_VERBATIM
);
66 if( !lib
->IsLoaded() )
68 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
73 gs_htmlHelp
= (HTMLHELP
)lib
->GetSymbol( HTMLHELP_NAME
);
77 wxLogError(_("Failed to initialize MS HTML Help."));
87 static void UnloadHtmlHelpLibrary()
91 wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") );
96 static HWND
GetSuitableHWND()
98 if (wxTheApp
->GetTopWindow())
99 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
101 return GetDesktopWindow();
104 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
106 bool wxCHMHelpController::Initialize(const wxString
& filename
)
109 if( !LoadHtmlHelpLibrary() )
112 m_helpFile
= filename
;
116 bool wxCHMHelpController::LoadFile(const wxString
& file
)
123 bool wxCHMHelpController::DisplayContents()
125 if (m_helpFile
.IsEmpty()) return FALSE
;
127 wxString str
= GetValidFilename(m_helpFile
);
129 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_FINDER
, 0L);
133 // Use topic or HTML filename
134 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
136 if (m_helpFile
.IsEmpty()) return FALSE
;
138 wxString str
= GetValidFilename(m_helpFile
);
140 // Is this an HTML file or a keyword?
141 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
144 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
146 KeywordSearch(section
);
150 // Use context number
151 bool wxCHMHelpController::DisplaySection(int section
)
153 if (m_helpFile
.IsEmpty()) return FALSE
;
155 wxString str
= GetValidFilename(m_helpFile
);
157 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
161 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
163 if (m_helpFile
.IsEmpty()) return FALSE
;
165 wxString str
= GetValidFilename(m_helpFile
);
167 // We also have to specify the popups file (default is cshelp.txt).
168 // str += wxT("::/cshelp.txt");
171 popup
.cbStruct
= sizeof(popup
);
172 popup
.hinst
= (HINSTANCE
) wxGetInstance();
173 popup
.idString
= contextId
;
175 GetCursorPos(& popup
.pt
);
176 popup
.clrForeground
= (COLORREF
)-1;
177 popup
.clrBackground
= (COLORREF
)-1;
178 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
179 popup
.pszFont
= NULL
;
180 popup
.pszText
= NULL
;
182 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
186 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
189 popup
.cbStruct
= sizeof(popup
);
190 popup
.hinst
= (HINSTANCE
) wxGetInstance();
192 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
193 popup
.clrForeground
= (COLORREF
)-1;
194 popup
.clrBackground
= (COLORREF
)-1;
195 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
196 popup
.pszFont
= NULL
;
197 popup
.pszText
= (const wxChar
*) text
;
199 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
203 bool wxCHMHelpController::DisplayBlock(long block
)
205 return DisplaySection(block
);
208 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
210 if (m_helpFile
.IsEmpty()) return FALSE
;
212 wxString str
= GetValidFilename(m_helpFile
);
215 link
.cbStruct
= sizeof(HH_AKLINK
) ;
216 link
.fReserved
= FALSE
;
217 link
.pszKeywords
= k
.c_str() ;
219 link
.pszMsgText
= NULL
;
220 link
.pszMsgTitle
= NULL
;
221 link
.pszWindow
= NULL
;
222 link
.fIndexOnFail
= TRUE
;
224 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
228 bool wxCHMHelpController::Quit()
230 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
231 UnloadHtmlHelpLibrary();
236 // Append extension if necessary.
237 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
239 wxString path
, name
, ext
;
240 wxSplitPath(file
, & path
, & name
, & ext
);
244 fullName
= name
+ wxT(".chm");
245 else if (path
.Last() == wxT('\\'))
246 fullName
= path
+ name
+ wxT(".chm");
248 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");