]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
7ad636774742bba39206a70e10912ec4e8d11584
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help system: MS HTML Help implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "helpchm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
25 #include "wx/filefn.h"
26 #include "wx/msw/helpchm.h"
28 #include "wx/dynload.h"
35 #include "wx/msw/private.h"
36 #include "wx/msw/missing.h"
38 // ----------------------------------------------------------------------------
39 // utility functions to manage the loading/unloading
41 // ----------------------------------------------------------------------------
44 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCSTR
, UINT
, DWORD
);
45 #define HTMLHELP_NAME wxT("HtmlHelpA")
47 typedef HWND ( WINAPI
* HTMLHELP
)( HWND
, LPCWSTR
, UINT
, DWORD
);
48 #define HTMLHELP_NAME wxT("HtmlHelpW")
52 static HTMLHELP gs_htmlHelp
= 0;
54 static bool LoadHtmlHelpLibrary()
56 wxPluginLibrary
*lib
= wxPluginManager::LoadLibrary( _T("HHCTRL.OCX"), wxDL_DEFAULT
| wxDL_VERBATIM
);
60 wxLogError(_("MS HTML Help functions are unavailable because the MS HTML Help library is not installed on this machine. Please install it."));
65 gs_htmlHelp
= (HTMLHELP
)lib
->GetSymbol( HTMLHELP_NAME
);
69 wxLogError(_("Failed to initialize MS HTML Help."));
79 static void UnloadHtmlHelpLibrary()
83 if (wxPluginManager::UnloadLibrary( _T("HHCTRL.OCX") ))
88 static HWND
GetSuitableHWND()
90 if (wxTheApp
->GetTopWindow())
91 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
93 return GetDesktopWindow();
96 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
98 bool wxCHMHelpController::Initialize(const wxString
& filename
)
101 if( !LoadHtmlHelpLibrary() )
104 m_helpFile
= filename
;
108 bool wxCHMHelpController::LoadFile(const wxString
& file
)
115 bool wxCHMHelpController::DisplayContents()
117 if (m_helpFile
.IsEmpty()) return FALSE
;
119 wxString str
= GetValidFilename(m_helpFile
);
121 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, 0L);
125 // Use topic or HTML filename
126 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
128 if (m_helpFile
.IsEmpty()) return FALSE
;
130 wxString str
= GetValidFilename(m_helpFile
);
132 // Is this an HTML file or a keyword?
133 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
136 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
138 KeywordSearch(section
);
142 // Use context number
143 bool wxCHMHelpController::DisplaySection(int section
)
145 if (m_helpFile
.IsEmpty()) return FALSE
;
147 wxString str
= GetValidFilename(m_helpFile
);
149 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
153 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
155 if (m_helpFile
.IsEmpty()) return FALSE
;
157 wxString str
= GetValidFilename(m_helpFile
);
159 // We also have to specify the popups file (default is cshelp.txt).
160 // str += wxT("::/cshelp.txt");
163 popup
.cbStruct
= sizeof(popup
);
164 popup
.hinst
= (HINSTANCE
) wxGetInstance();
165 popup
.idString
= contextId
;
167 GetCursorPos(& popup
.pt
);
168 popup
.clrForeground
= (COLORREF
)-1;
169 popup
.clrBackground
= (COLORREF
)-1;
170 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
171 popup
.pszFont
= NULL
;
172 popup
.pszText
= NULL
;
174 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
178 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
181 popup
.cbStruct
= sizeof(popup
);
182 popup
.hinst
= (HINSTANCE
) wxGetInstance();
184 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
185 popup
.clrForeground
= (COLORREF
)-1;
186 popup
.clrBackground
= (COLORREF
)-1;
187 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
188 popup
.pszFont
= NULL
;
189 popup
.pszText
= (const wxChar
*) text
;
191 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
195 bool wxCHMHelpController::DisplayBlock(long block
)
197 return DisplaySection(block
);
200 bool wxCHMHelpController::KeywordSearch(const wxString
& k
,
201 wxHelpSearchMode
WXUNUSED(mode
))
203 if (m_helpFile
.IsEmpty()) return FALSE
;
205 wxString str
= GetValidFilename(m_helpFile
);
208 link
.cbStruct
= sizeof(HH_AKLINK
) ;
209 link
.fReserved
= FALSE
;
210 link
.pszKeywords
= k
.c_str() ;
212 link
.pszMsgText
= NULL
;
213 link
.pszMsgTitle
= NULL
;
214 link
.pszWindow
= NULL
;
215 link
.fIndexOnFail
= TRUE
;
217 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
221 bool wxCHMHelpController::Quit()
223 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
228 // Append extension if necessary.
229 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
231 wxString path
, name
, ext
;
232 wxSplitPath(file
, & path
, & name
, & ext
);
236 fullName
= name
+ wxT(".chm");
237 else if (path
.Last() == wxT('\\'))
238 fullName
= path
+ name
+ wxT(".chm");
240 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");
244 wxCHMHelpController::~wxCHMHelpController()
246 UnloadHtmlHelpLibrary();