]>
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
5 // Modified by: Vadim Zeitlin at 2008-03-01: refactoring, simplification
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/filename.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")
47 HTMLHELP
GetHtmlHelpFunction()
49 static HTMLHELP s_htmlHelp
= NULL
;
53 static wxDynamicLibrary
s_dllHtmlHelp(_T("HHCTRL.OCX"), wxDL_VERBATIM
);
55 if ( !s_dllHtmlHelp
.IsLoaded() )
57 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
61 s_htmlHelp
= (HTMLHELP
)s_dllHtmlHelp
.GetSymbol(HTMLHELP_NAME
);
64 wxLogError(_("Failed to initialize MS HTML Help."));
72 // find the window to use in HtmlHelp() call: use the given one by default but
73 // fall back to the top level app window and then the desktop if it's NULL
74 static HWND
GetSuitableHWND(wxWindow
*win
)
76 if ( !win
&& wxTheApp
)
77 win
= wxTheApp
->GetTopWindow();
79 return win
? GetHwndOf(win
) : ::GetDesktopWindow();
83 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
85 bool wxCHMHelpController::Initialize(const wxString
& filename
)
87 if ( !GetHtmlHelpFunction() )
90 m_helpFile
= filename
;
94 bool wxCHMHelpController::LoadFile(const wxString
& file
)
102 wxCHMHelpController::CallHtmlHelp(wxWindow
*win
,
107 HTMLHELP htmlHelp
= GetHtmlHelpFunction();
109 return htmlHelp
&& htmlHelp(GetSuitableHWND(win
), str
, cmd
, param
);
112 bool wxCHMHelpController::DisplayContents()
114 if (m_helpFile
.IsEmpty())
117 return CallHtmlHelp(HH_DISPLAY_TOPIC
);
120 // Use topic or HTML filename
121 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
123 if (m_helpFile
.IsEmpty())
126 // Is this an HTML file or a keyword?
127 if ( section
.Find(wxT(".htm")) != wxNOT_FOUND
)
129 // interpret as a file name
130 return CallHtmlHelp(HH_DISPLAY_TOPIC
, section
.wx_str());
133 return KeywordSearch(section
);
136 // Use context number
137 bool wxCHMHelpController::DisplaySection(int section
)
139 if (m_helpFile
.IsEmpty())
142 return CallHtmlHelp(HH_HELP_CONTEXT
, section
);
147 wxCHMHelpController::DoDisplayTextPopup(const wxChar
*text
,
153 popup
.cbStruct
= sizeof(popup
);
154 popup
.hinst
= (HINSTANCE
) wxGetInstance();
155 popup
.idString
= contextId
;
156 popup
.pszText
= text
;
159 popup
.clrForeground
= ::GetSysColor(COLOR_INFOTEXT
);
160 popup
.clrBackground
= ::GetSysColor(COLOR_INFOBK
);
161 popup
.rcMargins
.top
=
162 popup
.rcMargins
.left
=
163 popup
.rcMargins
.right
=
164 popup
.rcMargins
.bottom
= -1;
165 popup
.pszFont
= NULL
;
167 return CallHtmlHelp(window
, NULL
, HH_DISPLAY_TEXT_POPUP
, &popup
);
170 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
172 return DoDisplayTextPopup(NULL
, wxGetMousePosition(), contextId
,
177 wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
179 return ShowContextHelpPopup(text
, pos
, GetParentWindow());
183 bool wxCHMHelpController::ShowContextHelpPopup(const wxString
& text
,
187 return DoDisplayTextPopup(text
.wx_str(), pos
, 0, window
);
190 bool wxCHMHelpController::DisplayBlock(long block
)
192 return DisplaySection(block
);
195 bool wxCHMHelpController::KeywordSearch(const wxString
& k
,
196 wxHelpSearchMode
WXUNUSED(mode
))
198 if (m_helpFile
.IsEmpty())
202 link
.cbStruct
= sizeof(HH_AKLINK
);
203 link
.fReserved
= FALSE
;
204 link
.pszKeywords
= k
.wx_str();
206 link
.pszMsgText
= NULL
;
207 link
.pszMsgTitle
= NULL
;
208 link
.pszWindow
= NULL
;
209 link
.fIndexOnFail
= TRUE
;
211 return CallHtmlHelp(HH_KEYWORD_LOOKUP
, &link
);
214 bool wxCHMHelpController::Quit()
216 return CallHtmlHelp(NULL
, NULL
, HH_CLOSE_ALL
);
219 wxString
wxCHMHelpController::GetValidFilename() const
221 wxString path
, name
, ext
;
222 wxFileName::SplitPath(m_helpFile
, &path
, &name
, &ext
);
226 fullName
= name
+ wxT(".chm");
227 else if (path
.Last() == wxT('\\'))
228 fullName
= path
+ name
+ wxT(".chm");
230 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");