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