]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/html/helpctrl.cpp
Improved selection mode handling in wxGrid::SelectBlock
[wxWidgets.git] / src / html / helpctrl.cpp
... / ...
CommitLineData
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
26
27#include "wx/html/helpctrl.h"
28#include "wx/wx.h"
29#include "wx/busyinfo.h"
30
31IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
32
33#if 0
34BEGIN_EVENT_TABLE(wxHtmlHelpController, wxEvtHandler)
35EVT_CLOSE(wxHtmlHelpController::OnCloseFrame)
36END_EVENT_TABLE()
37#endif
38
39wxHtmlHelpController::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
48wxHtmlHelpController::~wxHtmlHelpController()
49{
50 WriteCustomization(m_Config, m_ConfigRoot);
51 if (m_helpFrame)
52 DestroyHelpWindow();
53}
54
55
56void wxHtmlHelpController::DestroyHelpWindow()
57{
58 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
59 if (m_helpFrame)
60 m_helpFrame->Destroy();
61}
62
63void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
64{
65 evt.Skip();
66
67 OnQuit();
68
69 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
70 m_helpFrame = NULL;
71}
72
73void wxHtmlHelpController::SetTitleFormat(const wxString& title)
74{
75 m_titleFormat = title;
76 if (m_helpFrame)
77 m_helpFrame->SetTitleFormat(title);
78}
79
80
81bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
82{
83 wxBusyCursor cur;
84#if wxUSE_BUSYINFO
85 wxBusyInfo* busy = NULL;
86 wxString info;
87 if (show_wait_msg) {
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
102wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
103{
104 return new wxHtmlHelpFrame(data);
105}
106
107
108void wxHtmlHelpController::CreateHelpWindow()
109{
110 if (m_helpFrame) {
111 m_helpFrame->Raise();
112 return ;
113 }
114
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
122 m_helpFrame = CreateHelpFrame(&m_helpData);
123 m_helpFrame->SetController(this);
124// m_helpFrame->PushEventHandler(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
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)
139 m_helpFrame->ReadCustomization(cfg, path);
140}
141
142void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
143{
144 /* typically called by the controllers OnCloseFrame handler */
145 if (m_helpFrame)
146 m_helpFrame->WriteCustomization(cfg, path);
147}
148
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
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())
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
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
225
226#endif