]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
Applied patch for Forty, print patch and wxHTML book patch
[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 if (m_helpFrame)
100 m_helpFrame->RefreshLists() ;
101 return retval;
102 }
103
104
105
106 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
107 {
108 return new wxHtmlHelpFrame(data);
109 }
110
111
112 void wxHtmlHelpController::CreateHelpWindow()
113 {
114 if (m_helpFrame)
115 {
116 m_helpFrame->Raise();
117 return ;
118 }
119
120 if (m_Config == NULL)
121 {
122 m_Config = wxConfigBase::Get(FALSE);
123 if (m_Config != NULL)
124 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
125 }
126
127 m_helpFrame = CreateHelpFrame(&m_helpData);
128 m_helpFrame->SetController(this);
129
130 if (m_Config)
131 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
132
133 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
134 m_helpFrame->SetTitleFormat(m_titleFormat);
135 m_helpFrame->Show(TRUE);
136 }
137
138 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
139 {
140 /* should not be called by the user; call UseConfig, and the controller
141 * will do the rest */
142 if (m_helpFrame && cfg)
143 m_helpFrame->ReadCustomization(cfg, path);
144 }
145
146 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
147 {
148 /* typically called by the controllers OnCloseFrame handler */
149 if (m_helpFrame && cfg)
150 m_helpFrame->WriteCustomization(cfg, path);
151 }
152
153 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
154 {
155 m_Config = config;
156 m_ConfigRoot = rootpath;
157 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
158 ReadCustomization(config, rootpath);
159 }
160
161 //// Backward compatibility with wxHelpController API
162
163 bool wxHtmlHelpController::Initialize(const wxString& file)
164 {
165 wxString dir, filename, ext;
166 wxSplitPath(file, & dir, & filename, & ext);
167
168 if (!dir.IsEmpty())
169 dir = dir + wxString(wxT("/"));
170
171 // Try to find a suitable file
172 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
173 if (!wxFileExists(actualFilename))
174 {
175 actualFilename = dir + filename + wxString(wxT(".htb"));
176 if (!wxFileExists(actualFilename))
177 {
178 actualFilename = dir + filename + wxString(wxT(".hhp"));
179 if (!wxFileExists(actualFilename))
180 return FALSE;
181 }
182 }
183
184 return AddBook(actualFilename);
185 }
186
187 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
188 {
189 // Don't reload the file or we'll have it appear again, presumably.
190 return TRUE;
191 }
192
193 bool wxHtmlHelpController::DisplaySection(int sectionNo)
194 {
195 return Display(sectionNo);
196 }
197
198 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
199 {
200 #if wxUSE_TIPWINDOW
201 static wxTipWindow* s_tipWindow = NULL;
202
203 if (s_tipWindow)
204 {
205 // Prevent s_tipWindow being nulled in OnIdle,
206 // thereby removing the chance for the window to be closed by ShowHelp
207 s_tipWindow->SetTipWindowPtr(NULL);
208 s_tipWindow->Close();
209 }
210 s_tipWindow = NULL;
211
212 if ( !text.empty() )
213 {
214 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
215
216 return TRUE;
217 }
218 #endif // wxUSE_TIPWINDOW
219
220 return FALSE;
221 }
222
223 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
224 const wxSize& size,
225 const wxPoint& pos,
226 bool WXUNUSED(newFrameEachTime))
227 {
228 SetTitleFormat(title);
229 if (m_helpFrame)
230 {
231 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
232 }
233 }
234
235 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
236 wxPoint *pos,
237 bool *newFrameEachTime)
238 {
239 if (newFrameEachTime)
240 (* newFrameEachTime) = FALSE;
241 if (size && m_helpFrame)
242 (* size) = m_helpFrame->GetSize();
243 if (pos && m_helpFrame)
244 (* pos) = m_helpFrame->GetPosition();
245 return m_helpFrame;
246 }
247
248 bool wxHtmlHelpController::Quit()
249 {
250 DestroyHelpWindow();
251 return TRUE;
252 }
253
254 #endif // wxUSE_WXHTML_HELP
255