]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
merged 2.2 branch
[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 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
32
33 wxHtmlHelpController::wxHtmlHelpController(int style)
34 {
35 m_helpFrame = NULL;
36 m_Config = NULL;
37 m_ConfigRoot = wxEmptyString;
38 m_titleFormat = _("Help: %s");
39 m_FrameStyle = style;
40 }
41
42 wxHtmlHelpController::~wxHtmlHelpController()
43 {
44 if (m_Config)
45 WriteCustomization(m_Config, m_ConfigRoot);
46 if (m_helpFrame)
47 DestroyHelpWindow();
48 }
49
50
51 void wxHtmlHelpController::DestroyHelpWindow()
52 {
53 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
54 if (m_helpFrame)
55 m_helpFrame->Destroy();
56 }
57
58 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
59 {
60 evt.Skip();
61
62 OnQuit();
63
64 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
65 m_helpFrame = NULL;
66 }
67
68 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
69 {
70 m_titleFormat = title;
71 if (m_helpFrame)
72 m_helpFrame->SetTitleFormat(title);
73 }
74
75
76 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
77 {
78 wxBusyCursor cur;
79 #if wxUSE_BUSYINFO
80 wxBusyInfo* busy = NULL;
81 wxString info;
82 if (show_wait_msg) {
83 info.Printf(_("Adding book %s"), book.c_str());
84 busy = new wxBusyInfo(info);
85 }
86 #endif
87 bool retval = m_helpData.AddBook(book);
88 #if wxUSE_BUSYINFO
89 if (show_wait_msg)
90 delete busy;
91 #endif
92 return retval;
93 }
94
95
96
97 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
98 {
99 return new wxHtmlHelpFrame(data);
100 }
101
102
103 void wxHtmlHelpController::CreateHelpWindow()
104 {
105 if (m_helpFrame) {
106 m_helpFrame->Raise();
107 return ;
108 }
109
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
117 m_helpFrame = CreateHelpFrame(&m_helpData);
118 m_helpFrame->SetController(this);
119
120 if (m_Config)
121 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
122
123 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
124 m_helpFrame->SetTitleFormat(m_titleFormat);
125 m_helpFrame->Show(TRUE);
126 }
127
128 void 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 */
132 if (m_helpFrame && cfg)
133 m_helpFrame->ReadCustomization(cfg, path);
134 }
135
136 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
137 {
138 /* typically called by the controllers OnCloseFrame handler */
139 if (m_helpFrame && cfg)
140 m_helpFrame->WriteCustomization(cfg, path);
141 }
142
143 void 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
151 //// Backward compatibility with wxHelpController API
152
153 bool wxHtmlHelpController::Initialize(const wxString& file)
154 {
155 wxString dir, filename, ext;
156 wxSplitPath(file, & dir, & filename, & ext);
157
158 if (!dir.IsEmpty())
159 dir = dir + wxString(wxT("/"));
160
161 // Try to find a suitable file
162 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
163 if (!wxFileExists(actualFilename))
164 {
165 actualFilename = dir + filename + wxString(wxT(".htb"));
166 if (!wxFileExists(actualFilename))
167 {
168 actualFilename = dir + filename + wxString(wxT(".hhp"));
169 if (!wxFileExists(actualFilename))
170 return FALSE;
171 }
172 }
173
174 return AddBook(actualFilename);
175 }
176
177 bool 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
183 bool wxHtmlHelpController::DisplaySection(int sectionNo)
184 {
185 return Display(sectionNo);
186 }
187
188 void 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
200 wxFrame* 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
213 bool wxHtmlHelpController::Quit()
214 {
215 DestroyHelpWindow();
216 return TRUE;
217 }
218
219
220 #endif