]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
Added MSW toplevel.cpp and regenerated makefiles and such.
[wxWidgets.git] / src / html / helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpctrl.cpp
3 // Purpose: wxHtmlHelpController
4 // Notes: Based on htmlhelp.cpp, implementing a monolithic
5 // HTML Help controller class, by Vaclav Slavik
6 // Author: Harm van der Heijden and Vaclav Slavik
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
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 #if wxUSE_WXHTML_HELP
24
25 #ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/intl.h"
28 #endif // WX_PRECOMP
29
30 #include "wx/html/helpctrl.h"
31 #include "wx/busyinfo.h"
32
33 #if wxUSE_HELP
34 #include "wx/tipwin.h"
35 #endif
36
37 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
38
39 wxHtmlHelpController::wxHtmlHelpController(int style)
40 {
41 m_helpFrame = NULL;
42 m_Config = NULL;
43 m_ConfigRoot = wxEmptyString;
44 m_titleFormat = _("Help: %s");
45 m_FrameStyle = style;
46 }
47
48 wxHtmlHelpController::~wxHtmlHelpController()
49 {
50 if (m_Config)
51 WriteCustomization(m_Config, m_ConfigRoot);
52 if (m_helpFrame)
53 DestroyHelpWindow();
54 }
55
56
57 void wxHtmlHelpController::DestroyHelpWindow()
58 {
59 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
60 if (m_helpFrame)
61 m_helpFrame->Destroy();
62 }
63
64 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
65 {
66 evt.Skip();
67
68 OnQuit();
69
70 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
71 m_helpFrame = NULL;
72 }
73
74 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
75 {
76 m_titleFormat = title;
77 if (m_helpFrame)
78 m_helpFrame->SetTitleFormat(title);
79 }
80
81
82 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
83 {
84 wxBusyCursor cur;
85 #if wxUSE_BUSYINFO
86 wxBusyInfo* busy = NULL;
87 wxString info;
88 if (show_wait_msg)
89 {
90 info.Printf(_("Adding book %s"), book.c_str());
91 busy = new wxBusyInfo(info);
92 }
93 #endif
94 bool retval = m_helpData.AddBook(book);
95 #if wxUSE_BUSYINFO
96 if (show_wait_msg)
97 delete busy;
98 #endif
99 return retval;
100 }
101
102
103
104 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
105 {
106 return new wxHtmlHelpFrame(data);
107 }
108
109
110 void wxHtmlHelpController::CreateHelpWindow()
111 {
112 if (m_helpFrame)
113 {
114 m_helpFrame->Raise();
115 return ;
116 }
117
118 if (m_Config == NULL)
119 {
120 m_Config = wxConfigBase::Get(FALSE);
121 if (m_Config != NULL)
122 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
123 }
124
125 m_helpFrame = CreateHelpFrame(&m_helpData);
126 m_helpFrame->SetController(this);
127
128 if (m_Config)
129 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
130
131 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
132 m_helpFrame->SetTitleFormat(m_titleFormat);
133 m_helpFrame->Show(TRUE);
134 }
135
136 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
137 {
138 /* should not be called by the user; call UseConfig, and the controller
139 * will do the rest */
140 if (m_helpFrame && cfg)
141 m_helpFrame->ReadCustomization(cfg, path);
142 }
143
144 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
145 {
146 /* typically called by the controllers OnCloseFrame handler */
147 if (m_helpFrame && cfg)
148 m_helpFrame->WriteCustomization(cfg, path);
149 }
150
151 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
152 {
153 m_Config = config;
154 m_ConfigRoot = rootpath;
155 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
156 ReadCustomization(config, rootpath);
157 }
158
159 //// Backward compatibility with wxHelpController API
160
161 bool wxHtmlHelpController::Initialize(const wxString& file)
162 {
163 wxString dir, filename, ext;
164 wxSplitPath(file, & dir, & filename, & ext);
165
166 if (!dir.IsEmpty())
167 dir = dir + wxString(wxT("/"));
168
169 // Try to find a suitable file
170 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
171 if (!wxFileExists(actualFilename))
172 {
173 actualFilename = dir + filename + wxString(wxT(".htb"));
174 if (!wxFileExists(actualFilename))
175 {
176 actualFilename = dir + filename + wxString(wxT(".hhp"));
177 if (!wxFileExists(actualFilename))
178 return FALSE;
179 }
180 }
181
182 return AddBook(actualFilename);
183 }
184
185 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
186 {
187 // Don't reload the file or we'll have it appear again, presumably.
188 return TRUE;
189 }
190
191 bool wxHtmlHelpController::DisplaySection(int sectionNo)
192 {
193 return Display(sectionNo);
194 }
195
196 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
197 {
198 #if wxUSE_HELP
199 static wxTipWindow* s_tipWindow = NULL;
200
201 if (s_tipWindow)
202 {
203 // Prevent s_tipWindow being nulled in OnIdle,
204 // thereby removing the chance for the window to be closed by ShowHelp
205 s_tipWindow->SetTipWindowPtr(NULL);
206 s_tipWindow->Close();
207 }
208 s_tipWindow = NULL;
209
210 if ( !text.empty() )
211 {
212 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
213
214 return TRUE;
215 }
216 #endif
217 return FALSE;
218 }
219
220 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
221 const wxSize& size,
222 const wxPoint& pos,
223 bool WXUNUSED(newFrameEachTime))
224 {
225 SetTitleFormat(title);
226 if (m_helpFrame)
227 {
228 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
229 }
230 }
231
232 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
233 wxPoint *pos,
234 bool *newFrameEachTime)
235 {
236 if (newFrameEachTime)
237 (* newFrameEachTime) = FALSE;
238 if (size && m_helpFrame)
239 (* size) = m_helpFrame->GetSize();
240 if (pos && m_helpFrame)
241 (* pos) = m_helpFrame->GetPosition();
242 return m_helpFrame;
243 }
244
245 bool wxHtmlHelpController::Quit()
246 {
247 DestroyHelpWindow();
248 return TRUE;
249 }
250
251 #endif // wxUSE_WXHTML_HELP
252