]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpctrl.cpp
moved wxDash typedef to gdicmn.h
[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
25#if wxUSE_HTML
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
b4414c1f 33#if 0
8ec2b484 34BEGIN_EVENT_TABLE(wxHtmlHelpController, wxEvtHandler)
d5bb85a0 35EVT_CLOSE(wxHtmlHelpController::OnCloseFrame)
8ec2b484 36END_EVENT_TABLE()
b4414c1f 37#endif
8ec2b484 38
d5bb85a0 39wxHtmlHelpController::wxHtmlHelpController(int style)
8ec2b484
HH
40{
41 m_helpFrame = NULL;
42 m_Config = NULL;
43 m_ConfigRoot = wxEmptyString;
44 m_titleFormat = _("Help: %s");
d5bb85a0 45 m_FrameStyle = style;
8ec2b484
HH
46}
47
48wxHtmlHelpController::~wxHtmlHelpController()
49{
50 WriteCustomization(m_Config, m_ConfigRoot);
51 if (m_helpFrame)
b854b7b8 52 DestroyHelpWindow();
8ec2b484
HH
53}
54
b854b7b8
VS
55
56void wxHtmlHelpController::DestroyHelpWindow()
57{
58 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
59 if (m_helpFrame)
60 m_helpFrame->Destroy();
61}
62
b4414c1f 63void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
b854b7b8 64{
b4414c1f 65 evt.Skip();
b854b7b8 66
b4414c1f 67 OnQuit();
b854b7b8 68
b4414c1f
JS
69 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
70 m_helpFrame = NULL;
71}
b854b7b8 72
8ec2b484
HH
73void wxHtmlHelpController::SetTitleFormat(const wxString& title)
74{
75 m_titleFormat = title;
76 if (m_helpFrame)
d5bb85a0 77 m_helpFrame->SetTitleFormat(title);
8ec2b484
HH
78}
79
d5bb85a0 80
8ec2b484
HH
81bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
82{
83 wxBusyCursor cur;
84#if wxUSE_BUSYINFO
69941f05 85 wxBusyInfo* busy = NULL;
8ec2b484
HH
86 wxString info;
87 if (show_wait_msg) {
d5bb85a0
VS
88 info.Printf(_("Adding book %s"), book.c_str());
89 busy = new wxBusyInfo(info);
8ec2b484
HH
90 }
91#endif
92 bool retval = m_helpData.AddBook(book);
93#if wxUSE_BUSYINFO
94 if (show_wait_msg)
d5bb85a0
VS
95 delete busy;
96#endif
8ec2b484
HH
97 return retval;
98}
99
b854b7b8
VS
100
101
102wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
103{
104 return new wxHtmlHelpFrame(data);
105}
106
107
052e12db 108void wxHtmlHelpController::CreateHelpWindow()
8ec2b484
HH
109{
110 if (m_helpFrame) {
d5bb85a0
VS
111 m_helpFrame->Raise();
112 return ;
8ec2b484 113 }
d5bb85a0 114
74accc50
VS
115 if (m_Config == NULL)
116 {
117 m_Config = wxConfigBase::Get(FALSE);
118 if (m_Config != NULL)
119 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
120 }
121
b854b7b8 122 m_helpFrame = CreateHelpFrame(&m_helpData);
b4414c1f
JS
123 m_helpFrame->SetController(this);
124// m_helpFrame->PushEventHandler(this);
74accc50 125
8ec2b484 126 if (m_Config)
d5bb85a0 127 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
74accc50 128
d5bb85a0 129 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
8ec2b484
HH
130 m_helpFrame->SetTitleFormat(m_titleFormat);
131 m_helpFrame->Show(TRUE);
132}
133
134void 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)
d5bb85a0 139 m_helpFrame->ReadCustomization(cfg, path);
8ec2b484
HH
140}
141
142void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
143{
144 /* typically called by the controllers OnCloseFrame handler */
145 if (m_helpFrame)
d5bb85a0 146 m_helpFrame->WriteCustomization(cfg, path);
8ec2b484
HH
147}
148
721ab905
VS
149void 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
b4414c1f
JS
157//// Backward compatibility with wxHelpController API
158
159bool wxHtmlHelpController::Initialize(const wxString& file)
160{
161 wxString dir, filename, ext;
162 wxSplitPath(file, & dir, & filename, & ext);
163
164 if (!dir.IsEmpty())
e81910e0 165 dir = dir + wxString(wxT("/"));
b4414c1f
JS
166
167 // Try to find a suitable file
e81910e0 168 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
b4414c1f
JS
169 if (!wxFileExists(actualFilename))
170 {
e81910e0 171 actualFilename = dir + filename + wxString(wxT(".htb"));
b4414c1f
JS
172 if (!wxFileExists(actualFilename))
173 {
e81910e0 174 actualFilename = dir + filename + wxString(wxT(".hhp"));
b4414c1f
JS
175 if (!wxFileExists(actualFilename))
176 return FALSE;
177 }
178 }
179
180 return AddBook(actualFilename);
181}
182
183bool 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
189bool wxHtmlHelpController::DisplaySection(int sectionNo)
190{
191 return Display(sectionNo);
192}
193
194void wxHtmlHelpController::SetFrameParameters(const wxString& title,
195 const wxSize& size,
196 const wxPoint& pos,
197 bool WXUNUSED(newFrameEachTime))
198{
199 SetTitleFormat(title);
200 if (m_helpFrame)
201 {
202 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
203 }
204}
205
206wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
207 wxPoint *pos,
208 bool *newFrameEachTime)
209{
210 if (newFrameEachTime)
211 (* newFrameEachTime) = FALSE;
212 if (size && m_helpFrame)
213 (* size) = m_helpFrame->GetSize();
214 if (pos && m_helpFrame)
215 (* pos) = m_helpFrame->GetPosition();
216 return m_helpFrame;
217}
218
219bool wxHtmlHelpController::Quit()
220{
221 DestroyHelpWindow();
222 return TRUE;
223}
224
721ab905 225
8ec2b484 226#endif