]>
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
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_HELP && wxUSE_MS_HTML_HELP
20 #include "wx/filename.h"
21 #include "wx/msw/helpchm.h"
23 #include "wx/dynload.h"
30 #include "wx/msw/private.h"
31 #include "wx/msw/htmlhelp.h"
33 // ----------------------------------------------------------------------------
34 // utility functions to manage the loading/unloading
36 // ----------------------------------------------------------------------------
39 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
40 #define HTMLHELP_NAME wxT("HtmlHelpA")
42 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
43 #define HTMLHELP_NAME wxT("HtmlHelpW")
46 HTMLHELP
GetHtmlHelpFunction()
48 static HTMLHELP s_htmlHelp
= NULL
;
52 static wxDynamicLibrary
s_dllHtmlHelp(wxT("HHCTRL.OCX"), wxDL_VERBATIM
);
54 if ( !s_dllHtmlHelp
.IsLoaded() )
56 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
60 s_htmlHelp
= (HTMLHELP
)s_dllHtmlHelp
.GetSymbol(HTMLHELP_NAME
);
63 wxLogError(_("Failed to initialize MS HTML Help."));
71 // find the window to use in HtmlHelp() call: use the given one by default but
72 // fall back to the top level app window and then the desktop if it's NULL
73 static HWND
GetSuitableHWND(wxWindow
*win
)
75 if ( !win
&& wxTheApp
)
76 win
= wxTheApp
->GetTopWindow();
78 return win
? GetHwndOf(win
) : ::GetDesktopWindow();
82 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
84 bool wxCHMHelpController::Initialize(const wxString
& filename
)
86 if ( !GetHtmlHelpFunction() )
89 m_helpFile
= filename
;
93 bool wxCHMHelpController::LoadFile(const wxString
& file
)
101 wxCHMHelpController::CallHtmlHelp(wxWindow
*win
,
106 HTMLHELP htmlHelp
= GetHtmlHelpFunction();
108 return htmlHelp
&& htmlHelp(GetSuitableHWND(win
), str
, cmd
, param
);
111 bool wxCHMHelpController::DisplayContents()
113 if (m_helpFile
.IsEmpty())
116 return CallHtmlHelp(HH_DISPLAY_TOPIC
);
119 // Use topic or HTML filename
120 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
122 if (m_helpFile
.IsEmpty())
125 // Is this an HTML file or a keyword?
126 if ( section
.Find(wxT(".htm")) != wxNOT_FOUND
)
128 // interpret as a file name
129 return CallHtmlHelp(HH_DISPLAY_TOPIC
, wxMSW_CONV_LPCTSTR(section
));
132 return KeywordSearch(section
);
135 // Use context number
136 bool wxCHMHelpController::DisplaySection(int section
)
138 if (m_helpFile
.IsEmpty())
141 return CallHtmlHelp(HH_HELP_CONTEXT
, section
);
146 wxCHMHelpController::DoDisplayTextPopup(const wxChar
*text
,
152 popup
.cbStruct
= sizeof(popup
);
153 popup
.hinst
= (HINSTANCE
) wxGetInstance();
154 popup
.idString
= contextId
;
155 popup
.pszText
= text
;
158 popup
.clrForeground
= ::GetSysColor(COLOR_INFOTEXT
);
159 popup
.clrBackground
= ::GetSysColor(COLOR_INFOBK
);
160 popup
.rcMargins
.top
=
161 popup
.rcMargins
.left
=
162 popup
.rcMargins
.right
=
163 popup
.rcMargins
.bottom
= -1;
164 popup
.pszFont
= NULL
;
166 return CallHtmlHelp(window
, NULL
, HH_DISPLAY_TEXT_POPUP
, &popup
);
169 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
171 return DoDisplayTextPopup(NULL
, wxGetMousePosition(), contextId
,
176 wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
178 return ShowContextHelpPopup(text
, pos
, GetParentWindow());
182 bool wxCHMHelpController::ShowContextHelpPopup(const wxString
& text
,
186 return DoDisplayTextPopup(text
.t_str(), pos
, 0, window
);
189 bool wxCHMHelpController::DisplayBlock(long block
)
191 return DisplaySection(block
);
194 bool wxCHMHelpController::KeywordSearch(const wxString
& k
,
195 wxHelpSearchMode
WXUNUSED(mode
))
197 if (m_helpFile
.IsEmpty())
201 link
.cbStruct
= sizeof(HH_AKLINK
);
202 link
.fReserved
= FALSE
;
203 link
.pszKeywords
= k
.t_str();
205 link
.pszMsgText
= NULL
;
206 link
.pszMsgTitle
= NULL
;
207 link
.pszWindow
= NULL
;
208 link
.fIndexOnFail
= TRUE
;
210 return CallHtmlHelp(HH_KEYWORD_LOOKUP
, &link
);
213 bool wxCHMHelpController::Quit()
215 return CallHtmlHelp(NULL
, NULL
, HH_CLOSE_ALL
);
218 wxString
wxCHMHelpController::GetValidFilename() const
220 wxString path
, name
, ext
;
221 wxFileName::SplitPath(m_helpFile
, &path
, &name
, &ext
);
225 fullName
= name
+ wxT(".chm");
226 else if (path
.Last() == wxT('\\'))
227 fullName
= path
+ name
+ wxT(".chm");
229 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");