]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
Added chapter on collection and container classes to contents
[wxWidgets.git] / src / msw / helpchm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpchm.cpp
3 // Purpose: Help system: MS HTML Help implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 16/04/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "helpchm.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/defs.h"
25 #endif
26
27 #include "wx/filefn.h"
28
29 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
30 #include "wx/msw/helpchm.h"
31
32 // This is found in the HTML Help Workshop installation,
33 // along with htmlhelp.lib.
34 #include <htmlhelp.h>
35
36 #include <time.h>
37
38 #ifdef __WXMSW__
39 #include "wx/msw/private.h"
40 #endif
41
42 #include <string.h>
43
44 static HWND GetSuitableHWND()
45 {
46 if (wxTheApp->GetTopWindow())
47 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
48 else
49 return GetDesktopWindow();
50 }
51
52 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController, wxHelpControllerBase)
53
54 bool wxCHMHelpController::Initialize(const wxString& filename)
55 {
56 m_helpFile = filename;
57 return TRUE;
58 }
59
60 bool wxCHMHelpController::LoadFile(const wxString& file)
61 {
62 if (!file.IsEmpty())
63 m_helpFile = file;
64 return TRUE;
65 }
66
67 bool wxCHMHelpController::DisplayContents()
68 {
69 if (m_helpFile.IsEmpty()) return FALSE;
70
71 wxString str = GetValidFilename(m_helpFile);
72
73 HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_FINDER, 0L);
74 return TRUE;
75 }
76
77 // Use topic or HTML filename
78 bool wxCHMHelpController::DisplaySection(const wxString& section)
79 {
80 if (m_helpFile.IsEmpty()) return FALSE;
81
82 wxString str = GetValidFilename(m_helpFile);
83
84 // Is this an HTML file or a keyword?
85 bool isFilename = (section.Find(wxT(".htm")) != -1);
86
87 if (isFilename)
88 HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TOPIC, (DWORD) (const wxChar*) section);
89 else
90 KeywordSearch(section);
91 return TRUE;
92 }
93
94 // Use context number
95 bool wxCHMHelpController::DisplaySection(int section)
96 {
97 if (m_helpFile.IsEmpty()) return FALSE;
98
99 wxString str = GetValidFilename(m_helpFile);
100
101 HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)section);
102 return TRUE;
103 }
104
105 bool wxCHMHelpController::DisplayBlock(long block)
106 {
107 return DisplaySection(block);
108 }
109
110 bool wxCHMHelpController::KeywordSearch(const wxString& k)
111 {
112 if (m_helpFile.IsEmpty()) return FALSE;
113
114 wxString str = GetValidFilename(m_helpFile);
115
116 HH_AKLINK link;
117 link.cbStruct = sizeof(HH_AKLINK) ;
118 link.fReserved = FALSE ;
119 link.pszKeywords = k.c_str() ;
120 link.pszUrl = NULL ;
121 link.pszMsgText = NULL ;
122 link.pszMsgTitle = NULL ;
123 link.pszWindow = NULL ;
124 link.fIndexOnFail = TRUE ;
125
126 HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
127 return TRUE;
128 }
129
130 bool wxCHMHelpController::Quit()
131 {
132 HtmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL, 0L);
133 return TRUE;
134 }
135
136 // Append extension if necessary.
137 wxString wxCHMHelpController::GetValidFilename(const wxString& file) const
138 {
139 wxString path, name, ext;
140 wxSplitPath(file, & path, & name, & ext);
141
142 wxString fullName;
143 if (path.IsEmpty())
144 fullName = name + wxT(".chm");
145 else if (path.Last() == wxT('\\'))
146 fullName = path + name + wxT(".chm");
147 else
148 fullName = path + wxT("\\") + name + wxT(".chm");
149 return fullName;
150 }
151
152 #endif // wxUSE_HELP