]>
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 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
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()
86 if (wxTheApp
->GetTopWindow())
87 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
89 return GetDesktopWindow();
92 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
94 bool wxCHMHelpController::Initialize(const wxString
& filename
)
97 if( !LoadHtmlHelpLibrary() )
100 m_helpFile
= filename
;
104 bool wxCHMHelpController::LoadFile(const wxString
& file
)
111 bool wxCHMHelpController::DisplayContents()
113 if (m_helpFile
.IsEmpty()) return false;
115 wxString str
= GetValidFilename(m_helpFile
);
117 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, 0L);
121 // Use topic or HTML filename
122 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
124 if (m_helpFile
.IsEmpty()) return false;
126 wxString str
= GetValidFilename(m_helpFile
);
128 // Is this an HTML file or a keyword?
129 bool isFilename
= (section
.Find(wxT(".htm")) != wxNOT_FOUND
);
132 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
134 KeywordSearch(section
);
138 // Use context number
139 bool wxCHMHelpController::DisplaySection(int section
)
141 if (m_helpFile
.IsEmpty()) return false;
143 wxString str
= GetValidFilename(m_helpFile
);
145 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
149 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
151 if (m_helpFile
.IsEmpty()) return false;
153 wxString str
= GetValidFilename(m_helpFile
);
155 // We also have to specify the popups file (default is cshelp.txt).
156 // str += wxT("::/cshelp.txt");
159 popup
.cbStruct
= sizeof(popup
);
160 popup
.hinst
= (HINSTANCE
) wxGetInstance();
161 popup
.idString
= contextId
;
163 GetCursorPos(& popup
.pt
);
164 popup
.clrForeground
= (COLORREF
)-1;
165 popup
.clrBackground
= (COLORREF
)-1;
166 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
167 popup
.pszFont
= NULL
;
168 popup
.pszText
= NULL
;
170 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
174 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
177 popup
.cbStruct
= sizeof(popup
);
178 popup
.hinst
= (HINSTANCE
) wxGetInstance();
180 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
181 popup
.clrForeground
= (COLORREF
)-1;
182 popup
.clrBackground
= (COLORREF
)-1;
183 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
184 popup
.pszFont
= NULL
;
185 popup
.pszText
= (const wxChar
*) text
;
187 gs_htmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
191 bool wxCHMHelpController::DisplayBlock(long block
)
193 return DisplaySection(block
);
196 bool wxCHMHelpController::KeywordSearch(const wxString
& k
,
197 wxHelpSearchMode
WXUNUSED(mode
))
199 if (m_helpFile
.IsEmpty()) return false;
201 wxString str
= GetValidFilename(m_helpFile
);
204 link
.cbStruct
= sizeof(HH_AKLINK
) ;
205 link
.fReserved
= FALSE
;
206 link
.pszKeywords
= k
.c_str() ;
208 link
.pszMsgText
= NULL
;
209 link
.pszMsgTitle
= NULL
;
210 link
.pszWindow
= NULL
;
211 link
.fIndexOnFail
= TRUE
;
213 gs_htmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
217 bool wxCHMHelpController::Quit()
219 gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
224 // Append extension if necessary.
225 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
227 wxString path
, name
, ext
;
228 wxSplitPath(file
, & path
, & name
, & ext
);
232 fullName
= name
+ wxT(".chm");
233 else if (path
.Last() == wxT('\\'))
234 fullName
= path
+ name
+ wxT(".chm");
236 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");
240 wxCHMHelpController::~wxCHMHelpController()
242 UnloadHtmlHelpLibrary();