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