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