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