]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "helpchm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/filefn.h"
29 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
30 #include "wx/msw/helpchm.h"
32 // This is found in the HTML Help Workshop installation,
33 // along with htmlhelp.lib.
39 #include "wx/msw/private.h"
44 static HWND
GetSuitableHWND()
46 if (wxTheApp
->GetTopWindow())
47 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
49 return GetDesktopWindow();
52 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
54 bool wxCHMHelpController::Initialize(const wxString
& filename
)
56 m_helpFile
= filename
;
60 bool wxCHMHelpController::LoadFile(const wxString
& file
)
67 bool wxCHMHelpController::DisplayContents()
69 if (m_helpFile
.IsEmpty()) return FALSE
;
71 wxString str
= GetValidFilename(m_helpFile
);
73 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_FINDER
, 0L);
77 // Use topic or HTML filename
78 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
80 if (m_helpFile
.IsEmpty()) return FALSE
;
82 wxString str
= GetValidFilename(m_helpFile
);
84 // Is this an HTML file or a keyword?
85 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
88 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
90 KeywordSearch(section
);
95 bool wxCHMHelpController::DisplaySection(int section
)
97 if (m_helpFile
.IsEmpty()) return FALSE
;
99 wxString str
= GetValidFilename(m_helpFile
);
101 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
105 bool wxCHMHelpController::DisplayBlock(long block
)
107 return DisplaySection(block
);
110 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
112 if (m_helpFile
.IsEmpty()) return FALSE
;
114 wxString str
= GetValidFilename(m_helpFile
);
117 link
.cbStruct
= sizeof(HH_AKLINK
) ;
118 link
.fReserved
= FALSE
;
119 link
.pszKeywords
= k
.c_str() ;
121 link
.pszMsgText
= NULL
;
122 link
.pszMsgTitle
= NULL
;
123 link
.pszWindow
= NULL
;
124 link
.fIndexOnFail
= TRUE
;
126 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
130 bool wxCHMHelpController::Quit()
132 HtmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
136 // Append extension if necessary.
137 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
139 wxString path
, name
, ext
;
140 wxSplitPath(file
, & path
, & name
, & ext
);
144 fullName
= name
+ wxT(".chm");
145 else if (path
.Last() == wxT('\\'))
146 fullName
= path
+ name
+ wxT(".chm");
148 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");