]>
Commit | Line | Data |
---|---|---|
8ec2b484 HH |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpfrm.cpp | |
3 | // Purpose: wxHtmlHelpFrame | |
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 | // Created: | |
8 | // RCS-ID: | |
9 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifdef __GNUG__ | |
14 | #pragma implementation "helpfrm.h" | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx.h". | |
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 | |
27 | ||
28 | #ifndef WXPRECOMP | |
29 | #include <wx/wx.h> | |
30 | #endif | |
31 | ||
32 | #include "wx/html/helpfrm.h" | |
33 | #include "wx/notebook.h" | |
34 | #include "wx/imaglist.h" | |
35 | #include "wx/treectrl.h" | |
36 | #include "wx/tokenzr.h" | |
37 | #include "wx/wfstream.h" | |
38 | #include "wx/html/htmlwin.h" | |
39 | #include "wx/busyinfo.h" | |
40 | #include "wx/progdlg.h" | |
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. | |
57 | static const int PROGRESS_STEP = 40; | |
58 | ||
59 | //-------------------------------------------------------------------------- | |
60 | // wxHtmlHelpTreeItemData | |
61 | //-------------------------------------------------------------------------- | |
62 | ||
63 | class wxHtmlHelpTreeItemData : public wxTreeItemData | |
64 | { | |
65 | private: | |
66 | wxString m_Page; | |
67 | ||
68 | public: | |
69 | wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData() | |
70 | { | |
71 | m_Page = it -> m_Book -> GetBasePath() + it -> m_Page; | |
72 | } | |
73 | const wxString& GetPage() {return m_Page;} | |
74 | }; | |
75 | ||
76 | //--------------------------------------------------------------------------- | |
77 | // wxHtmlHelpFrame | |
78 | //--------------------------------------------------------------------------- | |
79 | ||
80 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame) | |
81 | ||
82 | wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title, | |
83 | int style, wxHtmlHelpData* data) | |
84 | { | |
85 | Init(data); | |
86 | Create(parent, id, title, style); | |
87 | } | |
88 | ||
89 | void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) | |
90 | { | |
91 | if (data) { | |
92 | m_Data = data; | |
93 | m_DataCreated = FALSE; | |
94 | } | |
95 | else { | |
96 | m_Data = new wxHtmlHelpData(); | |
97 | m_DataCreated = TRUE; | |
98 | } | |
99 | ||
100 | m_ContentsImageList = new wxImageList(12, 12); | |
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; | |
118 | m_Cfg.w = 700; m_Cfg.h = 480; | |
119 | m_Cfg.sashpos = 240; | |
120 | m_Cfg.navig_on = TRUE; | |
121 | m_Cfg.titleformat = _("Help: %s"); | |
122 | m_Cfg.style = wxHF_TOOLBAR | wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH; | |
123 | } | |
124 | ||
125 | /* Create: builds the GUI components. | |
126 | * with the style flag it's possible to toggle the toolbar, contents, index and search | |
127 | * controls. | |
128 | * m_HtmlWin will *always* be created, but it's important to realize that | |
129 | * m_ContentsBox, m_IndexBox, m_SearchList, m_SearchButton, m_SearchText and | |
130 | * m_SearchButton may be NULL. | |
131 | * moreover, if no contents, index or searchpage is needed, m_Splitter and | |
132 | * m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame) | |
133 | */ | |
134 | bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title, | |
135 | int style) | |
136 | { | |
137 | // Do the config in two steps. We read the HtmlWindow customization after we | |
138 | // create the window. | |
139 | if (m_Config) | |
140 | ReadCustomization(m_Config, m_ConfigRoot); | |
141 | ||
142 | wxFrame::Create(parent, id, "", wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h)); | |
143 | ||
144 | if (style == wxHF_DEFAULTSTYLE) | |
145 | style = m_Cfg.style; | |
146 | ||
147 | if (! title.IsEmpty()) // overridden? | |
148 | m_Cfg.titleformat = title; | |
149 | ||
150 | int notebook_page = 0; | |
151 | ||
152 | CreateStatusBar(); | |
153 | ||
154 | // toolbar? | |
155 | if (style & wxHF_TOOLBAR) { | |
156 | wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | | |
157 | wxTB_DOCKABLE); | |
158 | toolBar -> SetMargins(2, 2); | |
159 | wxBitmap* toolBarBitmaps[3]; | |
160 | ||
161 | #ifdef __WXMSW__ | |
162 | toolBarBitmaps[0] = new wxBitmap("panel"); | |
163 | toolBarBitmaps[1] = new wxBitmap("back"); | |
164 | toolBarBitmaps[2] = new wxBitmap("forward"); | |
165 | int width = 24; | |
166 | #else | |
167 | toolBarBitmaps[0] = new wxBitmap(panel_xpm); | |
168 | toolBarBitmaps[1] = new wxBitmap(back_xpm); | |
169 | toolBarBitmaps[2] = new wxBitmap(forward_xpm); | |
170 | int width = 16; | |
171 | #endif | |
172 | ||
173 | int currentX = 5; | |
174 | ||
175 | toolBar -> AddTool(wxID_HTML_PANEL, *(toolBarBitmaps[0]), wxNullBitmap, | |
176 | FALSE, currentX, -1, (wxObject *) NULL, | |
177 | _("Show/hide navigation panel")); | |
178 | currentX += width + 5; | |
179 | toolBar -> AddSeparator(); | |
180 | toolBar -> AddTool(wxID_HTML_BACK, *(toolBarBitmaps[1]), wxNullBitmap, | |
181 | FALSE, currentX, -1, (wxObject *) NULL, | |
182 | _("Go back to the previous HTML page")); | |
183 | currentX += width + 5; | |
184 | toolBar -> AddTool(wxID_HTML_FORWARD, *(toolBarBitmaps[2]), wxNullBitmap, | |
185 | FALSE, currentX, -1, (wxObject *) NULL, | |
186 | _("Go forward to the next HTML page")); | |
187 | currentX += width + 5; | |
188 | ||
189 | toolBar -> Realize(); | |
190 | ||
191 | // Can delete the bitmaps since they're reference counted | |
192 | for (int i = 0; i < 3; i++) | |
193 | delete toolBarBitmaps[i]; | |
194 | } | |
195 | ||
196 | if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) { | |
197 | // traditional help controller; splitter window with html page on the | |
198 | // right and a notebook containing various pages on the left | |
199 | m_Splitter = new wxSplitterWindow(this); | |
200 | ||
201 | m_HtmlWin = new wxHtmlWindow(m_Splitter); | |
202 | m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK, | |
203 | wxDefaultPosition, wxDefaultSize); | |
204 | } | |
205 | else { // only html window, no notebook with index,contents etc | |
206 | m_HtmlWin = new wxHtmlWindow(this); | |
207 | } | |
208 | ||
209 | m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat); | |
210 | m_HtmlWin -> SetRelatedStatusBar(0); | |
211 | if (m_Config) | |
212 | m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot); | |
213 | ||
214 | // contents tree panel? | |
215 | if (style & wxHF_CONTENTS) { | |
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++; | |
222 | } | |
223 | ||
224 | // index listbox panel? | |
225 | if (style & wxHF_INDEX) { | |
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++; | |
238 | } | |
239 | ||
240 | // search list panel? | |
241 | if (style & wxHF_SEARCH) { | |
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++; | |
281 | } | |
282 | ||
283 | //RefreshLists(); | |
284 | ||
285 | // showtime | |
286 | if (m_NavigPan && m_Splitter) { | |
287 | m_NavigPan -> Show(TRUE); | |
288 | m_Splitter -> SetMinimumPaneSize(20); | |
289 | if (m_Cfg.navig_on) | |
290 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
291 | } | |
292 | m_HtmlWin -> Show(TRUE); | |
293 | return TRUE; | |
294 | } | |
295 | ||
296 | wxHtmlHelpFrame::~wxHtmlHelpFrame() | |
297 | { | |
298 | delete m_ContentsImageList; | |
299 | if (m_DataCreated) | |
300 | delete m_Data; | |
301 | } | |
302 | ||
303 | bool wxHtmlHelpFrame::Display(const wxString& x) | |
304 | { | |
305 | wxString url = m_Data->FindPageByName(x); | |
306 | if (! url.IsEmpty()) { | |
307 | m_HtmlWin->LoadPage(url); | |
308 | return TRUE; | |
309 | } | |
310 | return FALSE; | |
311 | } | |
312 | ||
313 | bool wxHtmlHelpFrame::Display(const int id) | |
314 | { | |
315 | wxString url = m_Data->FindPageById(id); | |
316 | if (! url.IsEmpty()) { | |
317 | m_HtmlWin->LoadPage(url); | |
318 | return TRUE; | |
319 | } | |
320 | return FALSE; | |
321 | } | |
322 | ||
323 | ||
324 | ||
325 | bool wxHtmlHelpFrame::DisplayContents() | |
326 | { | |
327 | if (! m_ContentsBox) | |
328 | return FALSE; | |
329 | if (!m_Splitter -> IsSplit()) { | |
330 | m_NavigPan -> Show(TRUE); | |
331 | m_HtmlWin -> Show(TRUE); | |
332 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
333 | } | |
334 | m_NavigPan -> SetSelection(0); | |
335 | return TRUE; | |
336 | } | |
337 | ||
338 | ||
339 | ||
340 | bool wxHtmlHelpFrame::DisplayIndex() | |
341 | { | |
342 | if (! m_IndexBox) | |
343 | return FALSE; | |
344 | if (!m_Splitter -> IsSplit()) { | |
345 | m_NavigPan -> Show(TRUE); | |
346 | m_HtmlWin -> Show(TRUE); | |
347 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
348 | } | |
349 | m_NavigPan -> SetSelection(1); | |
350 | return TRUE; | |
351 | } | |
352 | ||
353 | bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) | |
354 | { | |
355 | if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice)) | |
356 | return FALSE; | |
357 | ||
358 | int foundcnt = 0; | |
359 | wxString foundstr; | |
360 | wxString book = wxEmptyString; | |
361 | ||
362 | if (!m_Splitter -> IsSplit()) { | |
363 | m_NavigPan -> Show(TRUE); | |
364 | m_HtmlWin -> Show(TRUE); | |
365 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
366 | } | |
367 | m_NavigPan -> SetSelection(m_SearchPage); | |
368 | m_SearchList -> Clear(); | |
369 | m_SearchText -> SetValue(keyword); | |
370 | m_SearchButton -> Enable(FALSE); | |
371 | ||
372 | if (m_SearchChoice->GetSelection() != 0) | |
373 | book = m_SearchChoice->GetStringSelection(); | |
374 | ||
375 | wxHtmlSearchStatus status(m_Data, keyword, book); | |
376 | ||
377 | wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), | |
378 | status.GetMaxIndex(), this, | |
379 | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); | |
380 | ||
381 | while (status.IsActive()) { | |
382 | if (progress.Update(status.GetCurIndex()) == FALSE) | |
383 | break; | |
384 | if (status.Search()) { | |
385 | foundstr.Printf(_("Found %i matches"), ++foundcnt); | |
386 | progress.Update(status.GetCurIndex(), foundstr); | |
387 | m_SearchList -> Append(status.GetName(), status.GetContentsItem()); | |
388 | } | |
389 | wxYield(); | |
390 | } | |
391 | ||
392 | m_SearchButton -> Enable(TRUE); | |
393 | m_SearchText -> SetSelection(0, keyword.Length()); | |
394 | m_SearchText -> SetFocus(); | |
395 | if (foundcnt) { | |
396 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0); | |
397 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
398 | } | |
399 | return (foundcnt > 0); | |
400 | } | |
401 | ||
402 | #define MAX_ROOTS 64 | |
403 | ||
404 | void wxHtmlHelpFrame::CreateContents(bool show_progress) | |
405 | { | |
406 | if (! m_ContentsBox) | |
407 | return; | |
408 | ||
409 | wxProgressDialog *progress; | |
410 | wxString proginfo; | |
411 | ||
412 | m_ContentsBox->Clear(); | |
413 | ||
414 | int cnt = m_Data->GetContentsCnt(); | |
415 | int div = (cnt / PROGRESS_STEP) + 1; | |
416 | int i; | |
417 | ||
418 | wxHtmlContentsItem *it = m_Data->GetContents(); | |
419 | ||
420 | if (show_progress) | |
421 | progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString, | |
422 | cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | | |
423 | wxPD_AUTO_HIDE); | |
424 | ||
425 | wxTreeItemId roots[MAX_ROOTS]; | |
426 | bool imaged[MAX_ROOTS]; | |
427 | ||
428 | m_ContentsBox -> DeleteAllItems(); | |
429 | roots[0] = m_ContentsBox -> AddRoot(_("(Help)")); | |
430 | imaged[0] = TRUE; | |
431 | ||
432 | for (i = 0; i < cnt; i++, it++) { | |
433 | if (show_progress && ((i % div) == 0)) { | |
434 | proginfo.Printf("Added %d/%d items", i, cnt); | |
435 | if (! progress->Update(i, proginfo)) | |
436 | break; | |
437 | wxYield(); | |
438 | } | |
439 | roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( | |
440 | roots[it -> m_Level], it -> m_Name, IMG_Page, -1, | |
441 | new wxHtmlHelpTreeItemData(it)); | |
442 | ||
443 | if (it -> m_Level == 0) { | |
444 | m_ContentsBox -> SetItemBold(roots[1], TRUE); | |
445 | m_ContentsBox -> SetItemImage(roots[1], IMG_Book); | |
446 | m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book); | |
447 | imaged[1] = TRUE; | |
448 | } | |
449 | else imaged[it -> m_Level + 1] = FALSE; | |
450 | ||
451 | if (!imaged[it -> m_Level]) { | |
452 | m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder); | |
453 | m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder); | |
454 | imaged[it -> m_Level] = TRUE; | |
455 | } | |
456 | } | |
457 | if (show_progress) | |
458 | delete progress; | |
459 | m_ContentsBox -> Expand(roots[0]); | |
460 | } | |
461 | ||
462 | ||
463 | void wxHtmlHelpFrame::CreateIndex(bool show_progress) | |
464 | { | |
465 | if (! m_IndexBox) | |
466 | return; | |
467 | ||
468 | wxProgressDialog *progress; | |
469 | wxString proginfo; | |
470 | ||
471 | m_IndexBox->Clear(); | |
472 | ||
473 | int cnt = m_Data->GetIndexCnt(); | |
474 | int div = (cnt / PROGRESS_STEP) + 1; | |
475 | ||
476 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
477 | ||
478 | if (show_progress) | |
479 | progress = new wxProgressDialog(_("Building index list..."), wxEmptyString, | |
480 | cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | | |
481 | wxPD_AUTO_HIDE); | |
482 | for (int i = 0; i < cnt; i++) { | |
483 | if (show_progress && ((i % div) == 0)) { | |
484 | proginfo.Printf("Added %d/%d items", i, cnt); | |
485 | if (! progress->Update(i, proginfo)) | |
486 | break; | |
487 | wxYield(); | |
488 | } | |
489 | m_IndexBox -> Append(index[i].m_Name, (char*)(index + i)); | |
490 | } | |
491 | ||
492 | if (show_progress) | |
493 | delete progress; | |
494 | } | |
495 | ||
496 | void wxHtmlHelpFrame::CreateSearch() | |
497 | { | |
498 | if (! (m_SearchList && m_SearchChoice)) | |
499 | return; | |
500 | m_SearchList -> Clear(); | |
501 | m_SearchChoice -> Clear(); | |
502 | m_SearchChoice -> Append(_("all books")); | |
503 | const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); | |
504 | int i, cnt = bookrec.GetCount(); | |
505 | for (i=0; i<cnt; i++) | |
506 | m_SearchChoice->Append(bookrec[i].GetTitle()); | |
507 | m_SearchChoice->SetSelection(0); | |
508 | } | |
509 | ||
510 | ||
511 | void wxHtmlHelpFrame::RefreshLists(bool show_progress) | |
512 | { | |
513 | CreateContents(show_progress); | |
514 | CreateIndex(show_progress); | |
515 | CreateSearch(); | |
516 | } | |
517 | ||
518 | void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) | |
519 | { | |
520 | wxString oldpath; | |
521 | wxString tmp; | |
522 | ||
523 | if (path != wxEmptyString) { | |
524 | oldpath = cfg -> GetPath(); | |
525 | cfg -> SetPath(path); | |
526 | } | |
527 | ||
528 | m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0; | |
529 | m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos); | |
530 | m_Cfg.x = cfg -> Read("hcX", m_Cfg.x); | |
531 | m_Cfg.y = cfg -> Read("hcY", m_Cfg.y); | |
532 | m_Cfg.w = cfg -> Read("hcW", m_Cfg.w); | |
533 | m_Cfg.h = cfg -> Read("hcH", m_Cfg.h); | |
534 | m_Cfg.titleformat = cfg -> Read("hcTitleFormat", m_Cfg.titleformat); | |
535 | m_Cfg.style = (int)cfg -> Read("hcStyle", (long)m_Cfg.style); | |
536 | ||
537 | if (m_HtmlWin) | |
538 | m_HtmlWin->ReadCustomization(cfg, path); | |
539 | ||
540 | if (path != wxEmptyString) | |
541 | cfg -> SetPath(oldpath); | |
542 | } | |
543 | ||
544 | void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path) | |
545 | { | |
546 | wxString oldpath; | |
547 | wxString tmp; | |
548 | //printf("wxHtmlHelpFrame. Writing config to %s\n", (const char*)path); | |
549 | ||
550 | if (path != wxEmptyString) { | |
551 | oldpath = cfg -> GetPath(); | |
552 | cfg -> SetPath(path); | |
553 | } | |
554 | ||
555 | cfg -> Write("hcNavigPanel", m_Cfg.navig_on); | |
556 | cfg -> Write("hcSashPos", (long)m_Cfg.sashpos); | |
557 | cfg -> Write("hcX", (long)m_Cfg.x); | |
558 | cfg -> Write("hcY", (long)m_Cfg.y); | |
559 | cfg -> Write("hcW", (long)m_Cfg.w); | |
560 | cfg -> Write("hcH", (long)m_Cfg.h); | |
561 | cfg -> Write("hcTitleFormat", m_Cfg.titleformat); | |
562 | cfg -> Write("hcStyle", (long)m_Cfg.style); | |
563 | ||
564 | if (m_HtmlWin) | |
565 | m_HtmlWin->WriteCustomization(cfg, path); | |
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 : | |
587 | if (! (m_Splitter && m_NavigPan)) | |
588 | return; | |
589 | if (m_Splitter -> IsSplit()) { | |
590 | m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
591 | m_Splitter -> Unsplit(m_NavigPan); | |
592 | } | |
593 | else { | |
594 | m_NavigPan -> Show(TRUE); | |
595 | m_HtmlWin -> Show(TRUE); | |
596 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
597 | } | |
598 | break; | |
599 | } | |
600 | } | |
601 | ||
602 | ||
603 | ||
604 | void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event) | |
605 | { | |
606 | wxHtmlHelpTreeItemData *pg; | |
607 | ||
608 | pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); | |
609 | if (pg) m_HtmlWin -> LoadPage(pg -> GetPage()); | |
610 | } | |
611 | ||
612 | ||
613 | ||
a4c97004 | 614 | void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
615 | { |
616 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection()); | |
617 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
618 | } | |
619 | ||
620 | ||
621 | ||
a4c97004 | 622 | void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
623 | { |
624 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection()); | |
625 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
626 | } | |
627 | ||
a4c97004 | 628 | void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
629 | { |
630 | wxString sr = m_SearchText -> GetLineText(0); | |
631 | ||
632 | if (sr != wxEmptyString) KeywordSearch(sr); | |
633 | } | |
634 | ||
635 | void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) | |
636 | { | |
637 | if (m_Config) | |
638 | WriteCustomization(m_Config, m_ConfigRoot); | |
639 | evt.Skip(); | |
640 | } | |
641 | ||
642 | BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) | |
643 | EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_FORWARD, wxHtmlHelpFrame::OnToolbar) | |
644 | EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) | |
645 | EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) | |
646 | EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) | |
647 | EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) | |
648 | EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) | |
649 | EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) | |
650 | END_EVENT_TABLE() | |
651 | ||
652 | #endif |