]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/helpchm.cpp
3 // Purpose: Help system: MS HTML Help implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_HELP && wxUSE_MS_HTML_HELP
21 #include "wx/filefn.h"
22 #include "wx/msw/helpchm.h"
24 #include "wx/dynload.h"
31 #include "wx/msw/private.h"
32 #include "wx/msw/htmlhelp.h"
34 // ----------------------------------------------------------------------------
35 // utility functions to manage the loading/unloading
37 // ----------------------------------------------------------------------------
40 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
41 #define HTMLHELP_NAME wxT("HtmlHelpA")
43 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
44 #define HTMLHELP_NAME wxT("HtmlHelpW")
48 static HTMLHELP gs_htmlHelp
= 0;
50 static bool LoadHtmlHelpLibrary()
52 wxPluginLibrary
*lib
= wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT
| wxDL_VERBATIM
);
56 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
61 gs_htmlHelp
= (HTMLHELP
)lib
->GetSymbol( HTMLHELP_NAME
);
65 wxLogError(_("Failed to initialize MS HTML Help."));
75 static void UnloadHtmlHelpLibrary()
79 if (wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") ))
84 static HWND
GetSuitableHWND(wxCHMHelpController
* controller
)
86 if (controller
->GetParentWindow())
87 return (HWND
) controller
->GetParentWindow()->GetHWND();
88 else if (wxTheApp
->GetTopWindow())
89 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
91 return GetDesktopWindow();
94 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
96 bool wxCHMHelpController::Initialize(const wxString
& filename
)
99 if( !LoadHtmlHelpLibrary() )
102 m_helpFile
= filename
;
106 bool wxCHMHelpController::LoadFile(const wxString
& file
)
113 bool wxCHMHelpController::DisplayContents()
115 if (m_helpFile
.IsEmpty()) return false;
117 wxString str
= GetValidFilename(m_helpFile
);
119 gs_htmlHelp(GetSuitableHWND(this), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, 0L);
123 // Use topic or HTML filename
124 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
126 if (m_helpFile
.IsEmpty()) return false;
128 wxString str
= GetValidFilename(m_helpFile
);
130 // Is this an HTML file or a keyword?
131 bool isFilename
= (section
.Find(wxT(".htm")) != wxNOT_FOUND
);
134 gs_htmlHelp(GetSuitableHWND(this), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
136 KeywordSearch(section
);
140 // Use context number
141 bool wxCHMHelpController::DisplaySection(int section
)
143 if (m_helpFile
.IsEmpty()) return false;
145 wxString str
= GetValidFilename(m_helpFile
);
147 gs_htmlHelp(GetSuitableHWND(this), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
151 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
153 if (m_helpFile
.IsEmpty()) return false;
155 wxString str
= GetValidFilename(m_helpFile
);
157 // We also have to specify the popups file (default is cshelp.txt).
158 // str += wxT("::/cshelp.txt");
161 popup
.cbStruct
= sizeof(popup
);
162 popup
.hinst
= (HINSTANCE
) wxGetInstance();
163 popup
.idString
= contextId
;
165 GetCursorPos(& popup
.pt
);
166 popup
.clrForeground
= (COLORREF
)-1;
167 popup
.clrBackground
= (COLORREF
)-1;
168 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
169 popup
.pszFont
= NULL
;
170 popup
.pszText
= NULL
;
172 gs_htmlHelp(GetSuitableHWND(this), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
176 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
179 popup
.cbStruct
= sizeof(popup
);
180 popup
.hinst
= (HINSTANCE
) wxGetInstance();
182 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
183 popup
.clrForeground
= (COLORREF
)-1;
184 popup
.clrBackground
= (COLORREF
)-1;
185 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
186 popup
.pszFont
= NULL
;
187 popup
.pszText
= (const wxChar
*) text
;
189 gs_htmlHelp(GetSuitableHWND(this), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
193 bool wxCHMHelpController::DisplayBlock(long block
)
195 return DisplaySection(block
);
198 bool wxCHMHelpController::KeywordSearch(const wxString
& k
,
199 wxHelpSearchMode
WXUNUSED(mode
))
201 if (m_helpFile
.IsEmpty()) return false;
203 wxString str
= GetValidFilename(m_helpFile
);
206 link
.cbStruct
= sizeof(HH_AKLINK
) ;
207 link
.fReserved
= FALSE
;
208 link
.pszKeywords
= k
.c_str() ;
210 link
.pszMsgText
= NULL
;
211 link
.pszMsgTitle
= NULL
;
212 link
.pszWindow
= NULL
;
213 link
.fIndexOnFail
= TRUE
;
215 gs_htmlHelp(GetSuitableHWND(this), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
219 bool wxCHMHelpController::Quit()
221 gs_htmlHelp(GetSuitableHWND(this), 0, HH_CLOSE_ALL
, 0L);
226 // Append extension if necessary.
227 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
229 wxString path
, name
, ext
;
230 wxSplitPath(file
, & path
, & name
, & ext
);
234 fullName
= name
+ wxT(".chm");
235 else if (path
.Last() == wxT('\\'))
236 fullName
= path
+ name
+ wxT(".chm");
238 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");
242 wxCHMHelpController::~wxCHMHelpController()
244 UnloadHtmlHelpLibrary();