]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
fix from Robert for extra refreshes
[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::DisplayContextPopup(int contextId)
106 {
107 if (m_helpFile.IsEmpty()) return FALSE;
108
109 wxString str = GetValidFilename(m_helpFile);
110
111 // We also have to specify the popups file (default is cshelp.txt).
112 // str += wxT("::/cshelp.txt");
113
114 HH_POPUP popup;
115 popup.cbStruct = sizeof(popup);
116 popup.hinst = (HINSTANCE) wxGetInstance();
117 popup.idString = contextId ;
118
119 GetCursorPos(& popup.pt);
120 popup.clrForeground = -1;
121 popup.clrBackground = -1;
122 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
123 popup.pszFont = NULL;
124 popup.pszText = NULL;
125
126 HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
127 return TRUE;
128 }
129
130 bool wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint& pos)
131 {
132 HH_POPUP popup;
133 popup.cbStruct = sizeof(popup);
134 popup.hinst = (HINSTANCE) wxGetInstance();
135 popup.idString = 0 ;
136 popup.pt.x = pos.x; popup.pt.y = pos.y;
137 popup.clrForeground = -1;
138 popup.clrBackground = -1;
139 popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1;
140 popup.pszFont = NULL;
141 popup.pszText = (const wxChar*) text;
142
143 HtmlHelp(GetSuitableHWND(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
144 return TRUE;
145 }
146
147 bool wxCHMHelpController::DisplayBlock(long block)
148 {
149 return DisplaySection(block);
150 }
151
152 bool wxCHMHelpController::KeywordSearch(const wxString& k)
153 {
154 if (m_helpFile.IsEmpty()) return FALSE;
155
156 wxString str = GetValidFilename(m_helpFile);
157
158 HH_AKLINK link;
159 link.cbStruct = sizeof(HH_AKLINK) ;
160 link.fReserved = FALSE ;
161 link.pszKeywords = k.c_str() ;
162 link.pszUrl = NULL ;
163 link.pszMsgText = NULL ;
164 link.pszMsgTitle = NULL ;
165 link.pszWindow = NULL ;
166 link.fIndexOnFail = TRUE ;
167
168 HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
169 return TRUE;
170 }
171
172 bool wxCHMHelpController::Quit()
173 {
174 HtmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL, 0L);
175 return TRUE;
176 }
177
178 // Append extension if necessary.
179 wxString wxCHMHelpController::GetValidFilename(const wxString& file) const
180 {
181 wxString path, name, ext;
182 wxSplitPath(file, & path, & name, & ext);
183
184 wxString fullName;
185 if (path.IsEmpty())
186 fullName = name + wxT(".chm");
187 else if (path.Last() == wxT('\\'))
188 fullName = path + name + wxT(".chm");
189 else
190 fullName = path + wxT("\\") + name + wxT(".chm");
191 return fullName;
192 }
193
194 #endif // wxUSE_HELP