]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpctrl.cpp
fixed MDI accel bug, more tests for it in the sample
[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
HH
81 wxString info;
82 if (show_wait_msg) {
d5bb85a0
VS
83 info.Printf(_("Adding book %s"), book.c_str());
84 busy = new wxBusyInfo(info);
8ec2b484
HH
85 }
86#endif
87 bool retval = m_helpData.AddBook(book);
88#if wxUSE_BUSYINFO
89 if (show_wait_msg)
d5bb85a0
VS
90 delete busy;
91#endif
8ec2b484
HH
92 return retval;
93}
94
b854b7b8
VS
95
96
97wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
98{
99 return new wxHtmlHelpFrame(data);
100}
101
102
052e12db 103void wxHtmlHelpController::CreateHelpWindow()
8ec2b484
HH
104{
105 if (m_helpFrame) {
d5bb85a0
VS
106 m_helpFrame->Raise();
107 return ;
8ec2b484 108 }
d5bb85a0 109
74accc50
VS
110 if (m_Config == NULL)
111 {
112 m_Config = wxConfigBase::Get(FALSE);
113 if (m_Config != NULL)
114 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
115 }
116
b854b7b8 117 m_helpFrame = CreateHelpFrame(&m_helpData);
b4414c1f 118 m_helpFrame->SetController(this);
74accc50 119
8ec2b484 120 if (m_Config)
d5bb85a0 121 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
74accc50 122
d5bb85a0 123 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
8ec2b484
HH
124 m_helpFrame->SetTitleFormat(m_titleFormat);
125 m_helpFrame->Show(TRUE);
126}
127
128void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
129{
130 /* should not be called by the user; call UseConfig, and the controller
131 * will do the rest */
f6bcfd97 132 if (m_helpFrame && cfg)
d5bb85a0 133 m_helpFrame->ReadCustomization(cfg, path);
8ec2b484
HH
134}
135
136void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
137{
138 /* typically called by the controllers OnCloseFrame handler */
f6bcfd97 139 if (m_helpFrame && cfg)
d5bb85a0 140 m_helpFrame->WriteCustomization(cfg, path);
8ec2b484
HH
141}
142
721ab905
VS
143void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
144{
145 m_Config = config;
146 m_ConfigRoot = rootpath;
147 if (m_helpFrame) m_helpFrame -> UseConfig(config, rootpath);
148 ReadCustomization(config, rootpath);
149}
150
b4414c1f
JS
151//// Backward compatibility with wxHelpController API
152
153bool wxHtmlHelpController::Initialize(const wxString& file)
154{
155 wxString dir, filename, ext;
156 wxSplitPath(file, & dir, & filename, & ext);
157
158 if (!dir.IsEmpty())
e81910e0 159 dir = dir + wxString(wxT("/"));
b4414c1f
JS
160
161 // Try to find a suitable file
e81910e0 162 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
b4414c1f
JS
163 if (!wxFileExists(actualFilename))
164 {
e81910e0 165 actualFilename = dir + filename + wxString(wxT(".htb"));
b4414c1f
JS
166 if (!wxFileExists(actualFilename))
167 {
e81910e0 168 actualFilename = dir + filename + wxString(wxT(".hhp"));
b4414c1f
JS
169 if (!wxFileExists(actualFilename))
170 return FALSE;
171 }
172 }
173
174 return AddBook(actualFilename);
175}
176
177bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
178{
179 // Don't reload the file or we'll have it appear again, presumably.
180 return TRUE;
181}
182
183bool wxHtmlHelpController::DisplaySection(int sectionNo)
184{
185 return Display(sectionNo);
186}
187
188void wxHtmlHelpController::SetFrameParameters(const wxString& title,
189 const wxSize& size,
190 const wxPoint& pos,
191 bool WXUNUSED(newFrameEachTime))
192{
193 SetTitleFormat(title);
194 if (m_helpFrame)
195 {
196 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
197 }
198}
199
200wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
201 wxPoint *pos,
202 bool *newFrameEachTime)
203{
204 if (newFrameEachTime)
205 (* newFrameEachTime) = FALSE;
206 if (size && m_helpFrame)
207 (* size) = m_helpFrame->GetSize();
208 if (pos && m_helpFrame)
209 (* pos) = m_helpFrame->GetPosition();
210 return m_helpFrame;
211}
212
213bool wxHtmlHelpController::Quit()
214{
215 DestroyHelpWindow();
216 return TRUE;
217}
218
721ab905 219
8ec2b484 220#endif