]>
Commit | Line | Data |
---|---|---|
8ec2b484 HH |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpfrm.cpp | |
3 | // Purpose: wxHtmlHelpFrame | |
d5bb85a0 | 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 | ||
c32bfc10 VS |
16 | // For compilers that support precompilation, includes "wx.h" |
17 | ||
8ec2b484 HH |
18 | #include "wx/wxprec.h" |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #include "wx/defs.h" | |
25 | ||
26 | #if wxUSE_HTML | |
8ec2b484 | 27 | #ifndef WXPRECOMP |
3096bd2f | 28 | #include "wx/wx.h" |
8ec2b484 HH |
29 | #endif |
30 | ||
31 | #include "wx/html/helpfrm.h" | |
32 | #include "wx/notebook.h" | |
33 | #include "wx/imaglist.h" | |
34 | #include "wx/treectrl.h" | |
35 | #include "wx/tokenzr.h" | |
36 | #include "wx/wfstream.h" | |
37 | #include "wx/html/htmlwin.h" | |
38 | #include "wx/busyinfo.h" | |
39 | #include "wx/progdlg.h" | |
2bd5bbc9 | 40 | #include "wx/toolbar.h" |
8ec2b484 HH |
41 | |
42 | // Bitmaps: | |
43 | ||
44 | #ifndef __WXMSW__ | |
45 | #include "bitmaps/panel.xpm" | |
46 | #include "bitmaps/back.xpm" | |
47 | #include "bitmaps/forward.xpm" | |
48 | #include "bitmaps/book.xpm" | |
49 | #include "bitmaps/folder.xpm" | |
50 | #include "bitmaps/page.xpm" | |
c32bfc10 | 51 | #include "bitmaps/help.xpm" |
5c172c17 | 52 | #include "bitmaps/helproot.xpm" |
8ec2b484 HH |
53 | #endif |
54 | ||
55 | #include "wx/stream.h" | |
56 | ||
57 | // number of times that the contents/index creation progress dialog | |
58 | // is updated. | |
d5bb85a0 | 59 | #define PROGRESS_STEP 40 |
8ec2b484 HH |
60 | |
61 | //-------------------------------------------------------------------------- | |
62 | // wxHtmlHelpTreeItemData | |
63 | //-------------------------------------------------------------------------- | |
64 | ||
65 | class wxHtmlHelpTreeItemData : public wxTreeItemData | |
66 | { | |
67 | private: | |
68 | wxString m_Page; | |
69 | ||
70 | public: | |
d5bb85a0 VS |
71 | wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData() |
72 | { | |
73 | m_Page = it -> m_Book -> GetBasePath() + it -> m_Page; | |
74 | } | |
75 | const wxString& GetPage() { return m_Page; } | |
8ec2b484 HH |
76 | }; |
77 | ||
78 | //--------------------------------------------------------------------------- | |
79 | // wxHtmlHelpFrame | |
80 | //--------------------------------------------------------------------------- | |
81 | ||
82 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame) | |
83 | ||
84 | wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title, | |
d5bb85a0 | 85 | int style, wxHtmlHelpData* data) |
8ec2b484 HH |
86 | { |
87 | Init(data); | |
88 | Create(parent, id, title, style); | |
89 | } | |
d5bb85a0 | 90 | |
8ec2b484 HH |
91 | void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) |
92 | { | |
93 | if (data) { | |
d5bb85a0 VS |
94 | m_Data = data; |
95 | m_DataCreated = FALSE; | |
96 | } else { | |
97 | m_Data = new wxHtmlHelpData(); | |
98 | m_DataCreated = TRUE; | |
8ec2b484 HH |
99 | } |
100 | ||
68364659 | 101 | m_ContentsImageList = new wxImageList(16, 16); |
8ec2b484 HH |
102 | m_ContentsImageList -> Add(wxICON(book)); |
103 | m_ContentsImageList -> Add(wxICON(folder)); | |
104 | m_ContentsImageList -> Add(wxICON(page)); | |
5c172c17 | 105 | m_ContentsImageList -> Add(wxICON(helproot)); |
8ec2b484 HH |
106 | |
107 | m_ContentsBox = NULL; | |
108 | m_IndexBox = NULL; | |
109 | m_SearchList = NULL; | |
110 | m_SearchButton = NULL; | |
111 | m_SearchText = NULL; | |
112 | m_SearchChoice = NULL; | |
113 | m_Splitter = NULL; | |
114 | m_NavigPan = NULL; | |
115 | m_HtmlWin = NULL; | |
116 | m_Config = NULL; | |
117 | m_ConfigRoot = wxEmptyString; | |
118 | ||
119 | m_Cfg.x = m_Cfg.y = 0; | |
d5bb85a0 VS |
120 | m_Cfg.w = 700; |
121 | m_Cfg.h = 480; | |
8ec2b484 HH |
122 | m_Cfg.sashpos = 240; |
123 | m_Cfg.navig_on = TRUE; | |
8ec2b484 HH |
124 | } |
125 | ||
d5bb85a0 VS |
126 | // Create: builds the GUI components. |
127 | // with the style flag it's possible to toggle the toolbar, contents, index and search | |
128 | // controls. | |
129 | // m_HtmlWin will *always* be created, but it's important to realize that | |
130 | // m_ContentsBox, m_IndexBox, m_SearchList, m_SearchButton, m_SearchText and | |
131 | // m_SearchButton may be NULL. | |
132 | // moreover, if no contents, index or searchpage is needed, m_Splitter and | |
133 | // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame) | |
134 | ||
8ec2b484 | 135 | bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title, |
d5bb85a0 | 136 | int style) |
8ec2b484 HH |
137 | { |
138 | // Do the config in two steps. We read the HtmlWindow customization after we | |
139 | // create the window. | |
d5bb85a0 VS |
140 | if (m_Config) |
141 | ReadCustomization(m_Config, m_ConfigRoot); | |
8ec2b484 | 142 | |
68364659 | 143 | wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h)); |
8ec2b484 | 144 | |
5d4b632b DW |
145 | #if defined(__WXMSW__) || (__WXPM__) |
146 | wxIcon frameIcon("wxhelp", wxBITMAP_TYPE_ICO_RESOURCE, 32, 32); | |
147 | #else | |
148 | wxIcon frameIcon(help_xpm); | |
149 | #endif | |
150 | if (frameIcon.Ok()) | |
151 | SetIcon(frameIcon); | |
152 | ||
5c172c17 VS |
153 | GetPosition(&m_Cfg.x, &m_Cfg.y); |
154 | ||
155 | SetIcon(wxICON(help)); | |
9ffdee80 | 156 | |
8ec2b484 HH |
157 | int notebook_page = 0; |
158 | ||
159 | CreateStatusBar(); | |
160 | ||
161 | // toolbar? | |
162 | if (style & wxHF_TOOLBAR) { | |
d5bb85a0 VS |
163 | wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | /*wxTB_FLAT | */ |
164 | wxTB_DOCKABLE); | |
165 | toolBar -> SetMargins(2, 2); | |
166 | wxBitmap* toolBarBitmaps[3]; | |
8ec2b484 | 167 | |
5d4b632b | 168 | #if defined(__WXMSW__) || (__WXPM__) |
d5bb85a0 VS |
169 | toolBarBitmaps[0] = new wxBitmap("panel"); |
170 | toolBarBitmaps[1] = new wxBitmap("back"); | |
171 | toolBarBitmaps[2] = new wxBitmap("forward"); | |
172 | int width = 24; | |
8ec2b484 | 173 | #else |
68364659 | 174 | toolBarBitmaps[0] = new wxBitmap(panel_xpm); |
d5bb85a0 VS |
175 | toolBarBitmaps[1] = new wxBitmap(back_xpm); |
176 | toolBarBitmaps[2] = new wxBitmap(forward_xpm); | |
177 | int width = 16; | |
8ec2b484 HH |
178 | #endif |
179 | ||
d5bb85a0 VS |
180 | int currentX = 5; |
181 | ||
182 | toolBar -> AddTool(wxID_HTML_PANEL, *(toolBarBitmaps[0]), wxNullBitmap, | |
183 | FALSE, currentX, -1, (wxObject *) NULL, | |
184 | _("Show/hide navigation panel")); | |
185 | currentX += width + 5; | |
186 | toolBar -> AddSeparator(); | |
187 | toolBar -> AddTool(wxID_HTML_BACK, *(toolBarBitmaps[1]), wxNullBitmap, | |
188 | FALSE, currentX, -1, (wxObject *) NULL, | |
189 | _("Go back to the previous HTML page")); | |
190 | currentX += width + 5; | |
191 | toolBar -> AddTool(wxID_HTML_FORWARD, *(toolBarBitmaps[2]), wxNullBitmap, | |
192 | FALSE, currentX, -1, (wxObject *) NULL, | |
193 | _("Go forward to the next HTML page")); | |
194 | currentX += width + 5; | |
195 | ||
196 | toolBar -> Realize(); | |
197 | ||
198 | // Can delete the bitmaps since they're reference counted | |
199 | for (int i = 0; i < 3; i++) | |
200 | delete toolBarBitmaps[i]; | |
8ec2b484 | 201 | } |
d5bb85a0 | 202 | |
8ec2b484 | 203 | if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) { |
d5bb85a0 VS |
204 | // traditional help controller; splitter window with html page on the |
205 | // right and a notebook containing various pages on the left | |
206 | m_Splitter = new wxSplitterWindow(this); | |
207 | ||
208 | m_HtmlWin = new wxHtmlWindow(m_Splitter); | |
209 | m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK, | |
210 | wxDefaultPosition, wxDefaultSize); | |
211 | } else { // only html window, no notebook with index,contents etc | |
212 | m_HtmlWin = new wxHtmlWindow(this); | |
8ec2b484 HH |
213 | } |
214 | ||
215 | m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat); | |
216 | m_HtmlWin -> SetRelatedStatusBar(0); | |
d5bb85a0 VS |
217 | if (m_Config) |
218 | m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot); | |
8ec2b484 HH |
219 | |
220 | // contents tree panel? | |
221 | if (style & wxHF_CONTENTS) { | |
d5bb85a0 VS |
222 | m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL, |
223 | wxDefaultPosition, wxDefaultSize, | |
224 | wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); | |
225 | m_ContentsBox -> SetImageList(m_ContentsImageList); | |
226 | m_NavigPan -> AddPage(m_ContentsBox, _("Contents")); | |
227 | m_ContentsPage = notebook_page++; | |
8ec2b484 HH |
228 | } |
229 | ||
230 | // index listbox panel? | |
231 | if (style & wxHF_INDEX) { | |
d5bb85a0 VS |
232 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE); |
233 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
234 | b1 -> top.SameAs (dummy, wxTop, 0); | |
235 | b1 -> left.SameAs (dummy, wxLeft, 0); | |
236 | b1 -> width.PercentOf (dummy, wxWidth, 100); | |
237 | b1 -> bottom.SameAs (dummy, wxBottom, 0); | |
238 | m_IndexBox = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, | |
239 | wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB); | |
240 | m_IndexBox -> SetConstraints(b1); | |
241 | dummy -> SetAutoLayout(TRUE); | |
242 | m_NavigPan -> AddPage(dummy, _("Index")); | |
243 | m_IndexPage = notebook_page++; | |
8ec2b484 HH |
244 | } |
245 | ||
246 | // search list panel? | |
247 | if (style & wxHF_SEARCH) { | |
d5bb85a0 VS |
248 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE); |
249 | ||
250 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
251 | m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT); | |
252 | b1 -> top.SameAs (dummy, wxTop, 10); | |
253 | b1 -> left.SameAs (dummy, wxLeft, 10); | |
254 | b1 -> right.SameAs (dummy, wxRight, 10); | |
255 | b1 -> height.AsIs(); | |
256 | m_SearchText -> SetConstraints(b1); | |
257 | ||
258 | wxLayoutConstraints *b2 = new wxLayoutConstraints; | |
259 | m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search")); | |
260 | b2 -> top.Below (m_SearchText, 10); | |
261 | b2 -> left.SameAs (dummy, wxLeft, 10); | |
262 | b2 -> width.AsIs(); | |
263 | b2 -> height.AsIs(); | |
264 | m_SearchButton -> SetConstraints(b2); | |
265 | ||
d5bb85a0 VS |
266 | wxLayoutConstraints *b4 = new wxLayoutConstraints; |
267 | m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition, | |
268 | wxDefaultSize); | |
269 | b4 -> top.Below (m_SearchText, 10); | |
270 | b4 -> left.SameAs (m_SearchButton, wxRight, 10); | |
271 | b4 -> right.SameAs (dummy, wxRight, 10); | |
272 | b4 -> height.AsIs(); | |
273 | m_SearchChoice -> SetConstraints(b4); | |
274 | ||
954269e6 VS |
275 | wxLayoutConstraints *b3 = new wxLayoutConstraints; |
276 | m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0); | |
277 | b3 -> top.Below (m_SearchButton, 10); | |
278 | b3 -> left.SameAs (dummy, wxLeft, 0); | |
279 | b3 -> right.SameAs (dummy, wxRight, 0); | |
280 | b3 -> bottom.SameAs (dummy, wxBottom, 0); | |
281 | m_SearchList -> SetConstraints(b3); | |
282 | ||
d5bb85a0 VS |
283 | dummy -> SetAutoLayout(TRUE); |
284 | dummy -> Layout(); | |
285 | m_NavigPan -> AddPage(dummy, _("Search")); | |
286 | m_SearchPage = notebook_page++; | |
8ec2b484 | 287 | } |
c32bfc10 | 288 | m_HtmlWin -> Show(TRUE); |
8ec2b484 HH |
289 | |
290 | //RefreshLists(); | |
291 | ||
292 | // showtime | |
293 | if (m_NavigPan && m_Splitter) { | |
d5bb85a0 | 294 | m_Splitter -> SetMinimumPaneSize(20); |
f38374d0 DW |
295 | if (m_Cfg.navig_on) |
296 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
297 | else { | |
298 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
299 | m_Splitter -> Unsplit(); | |
300 | } | |
c32bfc10 VS |
301 | if (m_Cfg.navig_on) { |
302 | m_NavigPan -> Show(TRUE); | |
d5bb85a0 | 303 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
c32bfc10 | 304 | } |
68364659 | 305 | else { |
c32bfc10 VS |
306 | m_NavigPan -> Show(FALSE); |
307 | m_Splitter -> Initialize(m_HtmlWin); | |
68364659 | 308 | } |
8ec2b484 | 309 | } |
8ec2b484 HH |
310 | return TRUE; |
311 | } | |
312 | ||
313 | wxHtmlHelpFrame::~wxHtmlHelpFrame() | |
314 | { | |
315 | delete m_ContentsImageList; | |
316 | if (m_DataCreated) | |
d5bb85a0 | 317 | delete m_Data; |
8ec2b484 HH |
318 | } |
319 | ||
320 | bool wxHtmlHelpFrame::Display(const wxString& x) | |
321 | { | |
322 | wxString url = m_Data->FindPageByName(x); | |
323 | if (! url.IsEmpty()) { | |
d5bb85a0 VS |
324 | m_HtmlWin->LoadPage(url); |
325 | return TRUE; | |
8ec2b484 HH |
326 | } |
327 | return FALSE; | |
328 | } | |
329 | ||
330 | bool wxHtmlHelpFrame::Display(const int id) | |
331 | { | |
332 | wxString url = m_Data->FindPageById(id); | |
333 | if (! url.IsEmpty()) { | |
d5bb85a0 VS |
334 | m_HtmlWin->LoadPage(url); |
335 | return TRUE; | |
8ec2b484 HH |
336 | } |
337 | return FALSE; | |
338 | } | |
339 | ||
340 | ||
341 | ||
342 | bool wxHtmlHelpFrame::DisplayContents() | |
343 | { | |
344 | if (! m_ContentsBox) | |
d5bb85a0 | 345 | return FALSE; |
8ec2b484 | 346 | if (!m_Splitter -> IsSplit()) { |
d5bb85a0 VS |
347 | m_NavigPan -> Show(TRUE); |
348 | m_HtmlWin -> Show(TRUE); | |
349 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
c32bfc10 | 350 | m_Cfg.navig_on = TRUE; |
8ec2b484 HH |
351 | } |
352 | m_NavigPan -> SetSelection(0); | |
353 | return TRUE; | |
354 | } | |
355 | ||
356 | ||
357 | ||
358 | bool wxHtmlHelpFrame::DisplayIndex() | |
359 | { | |
360 | if (! m_IndexBox) | |
d5bb85a0 | 361 | return FALSE; |
8ec2b484 | 362 | if (!m_Splitter -> IsSplit()) { |
d5bb85a0 VS |
363 | m_NavigPan -> Show(TRUE); |
364 | m_HtmlWin -> Show(TRUE); | |
365 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
8ec2b484 HH |
366 | } |
367 | m_NavigPan -> SetSelection(1); | |
368 | return TRUE; | |
369 | } | |
370 | ||
371 | bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) | |
372 | { | |
373 | if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice)) | |
d5bb85a0 | 374 | return FALSE; |
8ec2b484 HH |
375 | |
376 | int foundcnt = 0; | |
377 | wxString foundstr; | |
378 | wxString book = wxEmptyString; | |
379 | ||
380 | if (!m_Splitter -> IsSplit()) { | |
d5bb85a0 VS |
381 | m_NavigPan -> Show(TRUE); |
382 | m_HtmlWin -> Show(TRUE); | |
383 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
8ec2b484 HH |
384 | } |
385 | m_NavigPan -> SetSelection(m_SearchPage); | |
386 | m_SearchList -> Clear(); | |
387 | m_SearchText -> SetValue(keyword); | |
388 | m_SearchButton -> Enable(FALSE); | |
389 | ||
390 | if (m_SearchChoice->GetSelection() != 0) | |
d5bb85a0 | 391 | book = m_SearchChoice->GetStringSelection(); |
8ec2b484 HH |
392 | |
393 | wxHtmlSearchStatus status(m_Data, keyword, book); | |
394 | ||
d5bb85a0 VS |
395 | wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), |
396 | status.GetMaxIndex(), this, | |
397 | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); | |
8ec2b484 HH |
398 | |
399 | while (status.IsActive()) { | |
d5bb85a0 VS |
400 | if (progress.Update(status.GetCurIndex()) == FALSE) |
401 | break; | |
402 | if (status.Search()) { | |
403 | foundstr.Printf(_("Found %i matches"), ++foundcnt); | |
404 | progress.Update(status.GetCurIndex(), foundstr); | |
405 | m_SearchList -> Append(status.GetName(), status.GetContentsItem()); | |
406 | } | |
407 | wxYield(); | |
8ec2b484 HH |
408 | } |
409 | ||
410 | m_SearchButton -> Enable(TRUE); | |
411 | m_SearchText -> SetSelection(0, keyword.Length()); | |
412 | m_SearchText -> SetFocus(); | |
413 | if (foundcnt) { | |
414 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0); | |
415 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
416 | } | |
417 | return (foundcnt > 0); | |
418 | } | |
419 | ||
420 | #define MAX_ROOTS 64 | |
421 | ||
422 | void wxHtmlHelpFrame::CreateContents(bool show_progress) | |
423 | { | |
424 | if (! m_ContentsBox) | |
d5bb85a0 | 425 | return ; |
8ec2b484 HH |
426 | |
427 | wxProgressDialog *progress; | |
428 | wxString proginfo; | |
429 | ||
430 | m_ContentsBox->Clear(); | |
431 | ||
432 | int cnt = m_Data->GetContentsCnt(); | |
433 | int div = (cnt / PROGRESS_STEP) + 1; | |
434 | int i; | |
435 | ||
436 | wxHtmlContentsItem *it = m_Data->GetContents(); | |
d5bb85a0 VS |
437 | |
438 | if (show_progress) | |
439 | progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString, | |
440 | cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | | |
441 | wxPD_AUTO_HIDE); | |
442 | ||
8ec2b484 HH |
443 | wxTreeItemId roots[MAX_ROOTS]; |
444 | bool imaged[MAX_ROOTS]; | |
445 | ||
446 | m_ContentsBox -> DeleteAllItems(); | |
447 | roots[0] = m_ContentsBox -> AddRoot(_("(Help)")); | |
5c172c17 VS |
448 | m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder); |
449 | m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder); | |
8ec2b484 HH |
450 | imaged[0] = TRUE; |
451 | ||
452 | for (i = 0; i < cnt; i++, it++) { | |
d5bb85a0 VS |
453 | if (show_progress && ((i % div) == 0)) { |
454 | proginfo.Printf(_("Added %d/%d items"), i, cnt); | |
455 | if (! progress->Update(i, proginfo)) | |
456 | break; | |
457 | wxYield(); | |
458 | } | |
8ec2b484 | 459 | roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( |
d5bb85a0 VS |
460 | roots[it -> m_Level], it -> m_Name, IMG_Page, -1, |
461 | new wxHtmlHelpTreeItemData(it)); | |
8ec2b484 HH |
462 | |
463 | if (it -> m_Level == 0) { | |
464 | m_ContentsBox -> SetItemBold(roots[1], TRUE); | |
465 | m_ContentsBox -> SetItemImage(roots[1], IMG_Book); | |
466 | m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book); | |
467 | imaged[1] = TRUE; | |
d5bb85a0 | 468 | } else imaged[it -> m_Level + 1] = FALSE; |
8ec2b484 HH |
469 | |
470 | if (!imaged[it -> m_Level]) { | |
471 | m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder); | |
472 | m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder); | |
473 | imaged[it -> m_Level] = TRUE; | |
474 | } | |
475 | } | |
476 | if (show_progress) | |
d5bb85a0 | 477 | delete progress; |
8ec2b484 HH |
478 | m_ContentsBox -> Expand(roots[0]); |
479 | } | |
480 | ||
481 | ||
482 | void wxHtmlHelpFrame::CreateIndex(bool show_progress) | |
483 | { | |
484 | if (! m_IndexBox) | |
d5bb85a0 | 485 | return ; |
8ec2b484 HH |
486 | |
487 | wxProgressDialog *progress; | |
488 | wxString proginfo; | |
489 | ||
490 | m_IndexBox->Clear(); | |
491 | ||
492 | int cnt = m_Data->GetIndexCnt(); | |
493 | int div = (cnt / PROGRESS_STEP) + 1; | |
494 | ||
495 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
496 | ||
d5bb85a0 VS |
497 | if (show_progress) |
498 | progress = new wxProgressDialog(_("Building index list..."), wxEmptyString, | |
499 | cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | | |
500 | wxPD_AUTO_HIDE); | |
8ec2b484 | 501 | for (int i = 0; i < cnt; i++) { |
d5bb85a0 VS |
502 | if (show_progress && ((i % div) == 0)) { |
503 | proginfo.Printf(_("Added %d/%d items"), i, cnt); | |
504 | if (! progress->Update(i, proginfo)) | |
505 | break; | |
506 | wxYield(); | |
507 | } | |
8ec2b484 HH |
508 | m_IndexBox -> Append(index[i].m_Name, (char*)(index + i)); |
509 | } | |
510 | ||
511 | if (show_progress) | |
d5bb85a0 | 512 | delete progress; |
8ec2b484 HH |
513 | } |
514 | ||
515 | void wxHtmlHelpFrame::CreateSearch() | |
516 | { | |
517 | if (! (m_SearchList && m_SearchChoice)) | |
d5bb85a0 | 518 | return ; |
8ec2b484 HH |
519 | m_SearchList -> Clear(); |
520 | m_SearchChoice -> Clear(); | |
521 | m_SearchChoice -> Append(_("all books")); | |
522 | const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); | |
523 | int i, cnt = bookrec.GetCount(); | |
d5bb85a0 VS |
524 | for (i = 0; i < cnt; i++) |
525 | m_SearchChoice->Append(bookrec[i].GetTitle()); | |
8ec2b484 HH |
526 | m_SearchChoice->SetSelection(0); |
527 | } | |
528 | ||
529 | ||
530 | void wxHtmlHelpFrame::RefreshLists(bool show_progress) | |
531 | { | |
532 | CreateContents(show_progress); | |
533 | CreateIndex(show_progress); | |
534 | CreateSearch(); | |
535 | } | |
536 | ||
537 | void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) | |
538 | { | |
539 | wxString oldpath; | |
540 | wxString tmp; | |
541 | ||
542 | if (path != wxEmptyString) { | |
543 | oldpath = cfg -> GetPath(); | |
544 | cfg -> SetPath(path); | |
545 | } | |
546 | ||
547 | m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0; | |
548 | m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos); | |
549 | m_Cfg.x = cfg -> Read("hcX", m_Cfg.x); | |
550 | m_Cfg.y = cfg -> Read("hcY", m_Cfg.y); | |
551 | m_Cfg.w = cfg -> Read("hcW", m_Cfg.w); | |
552 | m_Cfg.h = cfg -> Read("hcH", m_Cfg.h); | |
8ec2b484 HH |
553 | |
554 | if (m_HtmlWin) | |
d5bb85a0 | 555 | m_HtmlWin->ReadCustomization(cfg, path); |
8ec2b484 HH |
556 | |
557 | if (path != wxEmptyString) | |
558 | cfg -> SetPath(oldpath); | |
559 | } | |
560 | ||
561 | void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path) | |
562 | { | |
563 | wxString oldpath; | |
564 | wxString tmp; | |
8ec2b484 HH |
565 | |
566 | if (path != wxEmptyString) { | |
567 | oldpath = cfg -> GetPath(); | |
568 | cfg -> SetPath(path); | |
569 | } | |
570 | ||
571 | cfg -> Write("hcNavigPanel", m_Cfg.navig_on); | |
572 | cfg -> Write("hcSashPos", (long)m_Cfg.sashpos); | |
573 | cfg -> Write("hcX", (long)m_Cfg.x); | |
574 | cfg -> Write("hcY", (long)m_Cfg.y); | |
575 | cfg -> Write("hcW", (long)m_Cfg.w); | |
576 | cfg -> Write("hcH", (long)m_Cfg.h); | |
8ec2b484 HH |
577 | |
578 | if (m_HtmlWin) | |
d5bb85a0 | 579 | m_HtmlWin->WriteCustomization(cfg, path); |
8ec2b484 HH |
580 | |
581 | if (path != wxEmptyString) | |
582 | cfg -> SetPath(oldpath); | |
583 | } | |
584 | ||
585 | ||
586 | /* | |
587 | EVENT HANDLING : | |
588 | */ | |
589 | ||
590 | ||
591 | void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) | |
592 | { | |
593 | switch (event.GetId()) { | |
594 | case wxID_HTML_BACK : | |
595 | m_HtmlWin -> HistoryBack(); | |
596 | break; | |
597 | case wxID_HTML_FORWARD : | |
598 | m_HtmlWin -> HistoryForward(); | |
599 | break; | |
600 | case wxID_HTML_PANEL : | |
d5bb85a0 VS |
601 | if (! (m_Splitter && m_NavigPan)) |
602 | return ; | |
8ec2b484 HH |
603 | if (m_Splitter -> IsSplit()) { |
604 | m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
605 | m_Splitter -> Unsplit(m_NavigPan); | |
68364659 | 606 | m_Cfg.navig_on = FALSE; |
d5bb85a0 | 607 | } else { |
8ec2b484 HH |
608 | m_NavigPan -> Show(TRUE); |
609 | m_HtmlWin -> Show(TRUE); | |
610 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
68364659 | 611 | m_Cfg.navig_on = TRUE; |
8ec2b484 HH |
612 | } |
613 | break; | |
614 | } | |
615 | } | |
616 | ||
617 | ||
618 | ||
619 | void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event) | |
620 | { | |
621 | wxHtmlHelpTreeItemData *pg; | |
622 | ||
623 | pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); | |
624 | if (pg) m_HtmlWin -> LoadPage(pg -> GetPage()); | |
625 | } | |
626 | ||
627 | ||
628 | ||
a4c97004 | 629 | void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 | 630 | { |
5d4b632b | 631 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection()); |
c32bfc10 | 632 | m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); |
8ec2b484 HH |
633 | } |
634 | ||
635 | ||
636 | ||
a4c97004 | 637 | void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
638 | { |
639 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection()); | |
640 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
641 | } | |
642 | ||
a4c97004 | 643 | void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
644 | { |
645 | wxString sr = m_SearchText -> GetLineText(0); | |
646 | ||
647 | if (sr != wxEmptyString) KeywordSearch(sr); | |
648 | } | |
649 | ||
650 | void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) | |
651 | { | |
68364659 VS |
652 | GetSize(&m_Cfg.w, &m_Cfg.h); |
653 | GetPosition(&m_Cfg.x, &m_Cfg.y); | |
5c172c17 | 654 | |
68364659 VS |
655 | if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition(); |
656 | ||
d5bb85a0 VS |
657 | if (m_Config) |
658 | WriteCustomization(m_Config, m_ConfigRoot); | |
68364659 | 659 | |
8ec2b484 HH |
660 | evt.Skip(); |
661 | } | |
662 | ||
663 | BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) | |
664 | EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_FORWARD, wxHtmlHelpFrame::OnToolbar) | |
665 | EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) | |
666 | EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) | |
667 | EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) | |
668 | EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) | |
669 | EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) | |
670 | EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) | |
671 | END_EVENT_TABLE() | |
672 | ||
673 | #endif |