]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | // Name: htmlhelp.cpp |
2 | // Purpose: Help controller | |
3 | // Author: Vaclav Slavik | |
4 | // Copyright: (c) 1999 Vaclav Slavik | |
5 | // Licence: wxWindows Licence | |
6 | ///////////////////////////////////////////////////////////////////////////// | |
7 | ||
8 | ||
9 | #ifdef __GNUG__ | |
10 | #pragma implementation | |
11 | #endif | |
12 | ||
13 | #include <wx/wxprec.h> | |
14 | ||
15 | #include "wx/defs.h" | |
16 | #if wxUSE_HTML | |
17 | ||
18 | #ifdef __BORDLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #ifndef WXPRECOMP | |
23 | #include <wx/wx.h> | |
24 | #endif | |
25 | ||
26 | ||
27 | #include <wx/notebook.h> | |
28 | #include <wx/imaglist.h> | |
29 | #include <wx/treectrl.h> | |
30 | #include <wx/tokenzr.h> | |
31 | #include <wx/wfstream.h> | |
32 | #include <wx/html/htmlwin.h> | |
33 | #include <wx/html/htmlhelp.h> | |
34 | #include <wx/busyinfo.h> | |
35 | ||
36 | #if !((wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))) | |
37 | #include <wx/progdlg.h> | |
38 | #endif | |
39 | ||
40 | ||
41 | // Bitmaps: | |
42 | ||
43 | #ifndef __WXMSW__ | |
44 | #include "bitmaps/panel.xpm" | |
45 | #include "bitmaps/back.xpm" | |
46 | #include "bitmaps/forward.xpm" | |
47 | #include "bitmaps/book.xpm" | |
48 | #include "bitmaps/folder.xpm" | |
49 | #include "bitmaps/page.xpm" | |
50 | #endif | |
51 | ||
52 | #include "search.h" | |
53 | ||
54 | ||
55 | ||
56 | //----------------------------------------------------------------------------- | |
57 | // Helper constants | |
58 | //----------------------------------------------------------------------------- | |
59 | ||
60 | ||
61 | // Command IDs : | |
62 | ||
63 | enum { | |
64 | wxID_HTML_PANEL = wxID_HIGHEST + 1, | |
65 | wxID_HTML_BACK, | |
66 | wxID_HTML_FORWARD, | |
67 | wxID_HTML_TREECTRL, | |
68 | wxID_HTML_INDEXPAGE, | |
69 | wxID_HTML_INDEXLIST, | |
70 | wxID_HTML_NOTEBOOK, | |
71 | wxID_HTML_SEARCHPAGE, | |
72 | wxID_HTML_SEARCHTEXT, | |
73 | wxID_HTML_SEARCHLIST, | |
74 | wxID_HTML_SEARCHBUTTON | |
75 | }; | |
76 | ||
77 | ||
78 | // Images: | |
79 | ||
80 | enum { | |
81 | IMG_Book = 0, | |
82 | IMG_Folder, | |
83 | IMG_Page | |
84 | }; | |
85 | ||
86 | ||
87 | ||
88 | ||
89 | ||
90 | ||
91 | class HtmlHelpTreeItemData : public wxTreeItemData | |
92 | { | |
93 | private: | |
94 | wxString m_Page; | |
95 | ||
96 | public: | |
97 | HtmlHelpTreeItemData(HtmlContentsItem *it) : wxTreeItemData() {m_Page = it -> m_Book -> GetBasePath() + it -> m_Page;} | |
98 | const wxString& GetPage() {return m_Page;} | |
99 | }; | |
100 | ||
101 | ||
102 | ||
103 | ||
104 | ||
105 | #include <wx/arrimpl.cpp> | |
106 | WX_DEFINE_OBJARRAY(HtmlBookRecArray) | |
107 | ||
108 | ||
109 | ||
110 | ||
111 | ||
112 | ||
113 | ||
114 | ||
115 | ||
116 | //----------------------------------------------------------------------------- | |
117 | // wxHtmlHelpController | |
118 | //----------------------------------------------------------------------------- | |
119 | ||
120 | ||
121 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxEvtHandler) | |
122 | ||
123 | ||
124 | wxHtmlHelpController::wxHtmlHelpController() : wxEvtHandler() | |
125 | { | |
126 | m_Frame = NULL; | |
127 | m_Config = NULL; | |
128 | m_ConfigRoot = wxEmptyString; | |
129 | m_TitleFormat = _("Help : %s"); | |
130 | m_TempPath = wxEmptyString; | |
131 | ||
132 | m_Cfg.x = m_Cfg.y = 0; | |
133 | m_Cfg.w = 700; m_Cfg.h = 480; | |
134 | m_Cfg.sashpos = 240; | |
135 | m_Cfg.navig_on = TRUE; | |
136 | ||
137 | m_ContentsImageList = new wxImageList(12, 12); | |
138 | m_ContentsImageList -> Add(wxICON(book)); | |
139 | m_ContentsImageList -> Add(wxICON(folder)); | |
140 | m_ContentsImageList -> Add(wxICON(page)); | |
141 | ||
142 | m_Contents = NULL; | |
143 | m_ContentsCnt = 0; | |
144 | m_Index = NULL; | |
145 | m_IndexCnt = 0; | |
146 | } | |
147 | ||
148 | ||
149 | ||
150 | wxHtmlHelpController::~wxHtmlHelpController() | |
151 | { | |
152 | int i; | |
153 | ||
154 | m_BookRecords.Empty(); | |
155 | delete m_ContentsImageList; | |
156 | if (m_Contents) { | |
157 | for (i = 0; i < m_ContentsCnt; i++) { | |
158 | free(m_Contents[i].m_Page); | |
159 | free(m_Contents[i].m_Name); | |
160 | } | |
161 | free(m_Contents); | |
162 | } | |
163 | if (m_Index) { | |
164 | for (i = 0; i < m_IndexCnt; i++) { | |
165 | free(m_Index[i].m_Page); | |
166 | free(m_Index[i].m_Name); | |
167 | } | |
168 | free(m_Index); | |
169 | } | |
170 | } | |
171 | ||
172 | ||
173 | ||
174 | void wxHtmlHelpController::SetTempDir(const wxString& path) | |
175 | { | |
176 | if (path == wxEmptyString) m_TempPath = path; | |
177 | else { | |
178 | if (wxIsAbsolutePath(path)) m_TempPath = path; | |
179 | else m_TempPath = wxGetCwd() + "/" + path; | |
180 | ||
181 | if (m_TempPath[m_TempPath.Length() - 1] != '/') | |
182 | m_TempPath << "/"; | |
183 | } | |
184 | } | |
185 | ||
186 | ||
187 | ||
188 | ||
189 | // Reads one line, stores it into buf and returns pointer to new line or NULL. | |
190 | static char* ReadLine(char *line, char *buf) | |
191 | { | |
192 | char *writeptr = buf, *readptr = line; | |
193 | ||
194 | while (*readptr != 0 && *readptr != '\r' && *readptr != '\n') *(writeptr++) = *(readptr++); | |
195 | *writeptr = 0; | |
196 | while (*readptr == '\r' || *readptr == '\n') readptr++; | |
197 | if (*readptr == 0) return NULL; | |
198 | else return readptr; | |
199 | } | |
200 | ||
201 | ||
202 | static wxString SafeFileName(const wxString& s) | |
203 | { | |
204 | wxString res = s; | |
205 | res.Replace(":", "_", TRUE); | |
206 | res.Replace(" ", "_", TRUE); | |
207 | res.Replace("/", "_", TRUE); | |
208 | res.Replace("\\", "_", TRUE); | |
209 | res.Replace("#", "_", TRUE); | |
210 | res.Replace(".", "_", TRUE); | |
211 | return res; | |
212 | } | |
213 | ||
214 | ||
215 | static int IndexCompareFunc(const void *a, const void *b) | |
216 | { | |
217 | return strcmp(((HtmlContentsItem*)a) -> m_Name, ((HtmlContentsItem*)b) -> m_Name); | |
218 | } | |
219 | ||
220 | ||
221 | ||
222 | bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FALSE) | |
223 | { | |
224 | wxFSFile *fi; | |
225 | wxFileSystem fsys; | |
226 | wxInputStream *s; | |
227 | HtmlBookRecord *bookr; | |
228 | wxString bookFull; | |
229 | ||
230 | int sz; | |
231 | char *buff, *lineptr; | |
232 | char linebuf[300]; | |
233 | ||
234 | wxString title = _("noname"), | |
235 | safetitle, | |
236 | start = wxEmptyString, | |
237 | contents = wxEmptyString, index = wxEmptyString; | |
238 | ||
239 | if (wxIsAbsolutePath(book)) bookFull = book; | |
240 | else bookFull = wxGetCwd() + "/" + book; | |
241 | ||
242 | fi = fsys.OpenFile(bookFull); | |
243 | if (fi == NULL) return FALSE; | |
244 | fsys.ChangePathTo(bookFull); | |
245 | s = fi -> GetStream(); | |
246 | sz = s -> StreamSize(); | |
247 | buff = (char*) malloc(sz+1); | |
248 | buff[sz] = 0; | |
249 | s -> Read(buff, sz); | |
250 | lineptr = buff; | |
251 | delete fi; | |
252 | ||
253 | while ((lineptr = ReadLine(lineptr, linebuf)) != NULL) { | |
254 | if (strstr(linebuf, "Title=") == linebuf) | |
255 | title = linebuf + strlen("Title="); | |
256 | if (strstr(linebuf, "Default topic=") == linebuf) | |
257 | start = linebuf + strlen("Default topic="); | |
258 | if (strstr(linebuf, "Index file=") == linebuf) | |
259 | index = linebuf + strlen("Index file="); | |
260 | if (strstr(linebuf, "Contents file=") == linebuf) | |
261 | contents = linebuf + strlen("Contents file="); | |
262 | } | |
263 | free(buff); | |
264 | ||
265 | bookr = new HtmlBookRecord(fsys.GetPath(), title, start); | |
266 | ||
267 | if (m_ContentsCnt % HTML_REALLOC_STEP == 0) | |
268 | m_Contents = (HtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + HTML_REALLOC_STEP) * sizeof(HtmlContentsItem)); | |
269 | m_Contents[m_ContentsCnt].m_Level = 0; | |
270 | m_Contents[m_ContentsCnt].m_ID = 0; | |
271 | m_Contents[m_ContentsCnt].m_Page = (char*) malloc(start.Length() + 1); | |
272 | strcpy(m_Contents[m_ContentsCnt].m_Page, start.c_str()); | |
273 | m_Contents[m_ContentsCnt].m_Name = (char*) malloc(title.Length() + 1); | |
274 | strcpy(m_Contents[m_ContentsCnt].m_Name, title.c_str()); | |
275 | m_Contents[m_ContentsCnt].m_Book = bookr; | |
276 | m_ContentsCnt++; | |
277 | ||
278 | // Try to find cached binary versions: | |
279 | safetitle = SafeFileName(title); | |
280 | fi = fsys.OpenFile(safetitle + ".cached"); | |
281 | if (fi == NULL) fi = fsys.OpenFile(m_TempPath + safetitle + ".cached"); | |
282 | if ((fi == NULL) || (m_TempPath == wxEmptyString)) { | |
283 | LoadMSProject(bookr, fsys, index, contents, show_wait_msg); | |
284 | if (m_TempPath != wxEmptyString) { | |
285 | wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + safetitle + ".cached"); | |
286 | SaveCachedBook(bookr, outs); | |
287 | delete outs; | |
288 | } | |
289 | } | |
290 | else { | |
291 | LoadCachedBook(bookr, fi -> GetStream()); | |
292 | delete fi; | |
293 | } | |
294 | ||
295 | m_BookRecords.Add(bookr); | |
296 | if (m_IndexCnt > 0) | |
297 | qsort(m_Index, m_IndexCnt, sizeof(HtmlContentsItem), IndexCompareFunc); | |
298 | ||
299 | return TRUE; | |
300 | } | |
301 | ||
302 | ||
303 | ||
304 | ||
305 | void wxHtmlHelpController::Display(const wxString& x) | |
306 | { | |
307 | int cnt; | |
308 | int i; | |
309 | wxFileSystem fsys; | |
310 | wxFSFile *f; | |
311 | ||
312 | CreateHelpWindow(); | |
313 | ||
314 | /* 1. try to open given file: */ | |
315 | ||
316 | cnt = m_BookRecords.GetCount(); | |
317 | for (i = 0; i < cnt; i++) { | |
318 | f = fsys.OpenFile(m_BookRecords[i].GetBasePath() + x); | |
319 | if (f) { | |
320 | m_HtmlWin -> LoadPage(m_BookRecords[i].GetBasePath() + x); | |
321 | delete f; | |
322 | return; | |
323 | } | |
324 | } | |
325 | ||
326 | ||
327 | /* 2. try to find a book: */ | |
328 | ||
329 | for (i = 0; i < cnt; i++) { | |
330 | if (m_BookRecords[i].GetTitle() == x) { | |
331 | m_HtmlWin -> LoadPage(m_BookRecords[i].GetBasePath() + m_BookRecords[i].GetStart()); | |
332 | return; | |
333 | } | |
334 | } | |
335 | ||
336 | /* 3. try to find in contents: */ | |
337 | ||
338 | cnt = m_ContentsCnt; | |
339 | for (i = 0; i < cnt; i++) { | |
340 | if (strcmp(m_Contents[i].m_Name, x) == 0) { | |
341 | m_HtmlWin -> LoadPage(m_Contents[i].m_Book -> GetBasePath() + m_Contents[i].m_Page); | |
342 | return; | |
343 | } | |
344 | } | |
345 | ||
346 | ||
347 | /* 4. try to find in index: */ | |
348 | ||
349 | cnt = m_IndexCnt; | |
350 | for (i = 0; i < cnt; i++) { | |
351 | if (strcmp(m_Index[i].m_Name, x) == 0) { | |
352 | m_HtmlWin -> LoadPage(m_Index[i].m_Book -> GetBasePath() + m_Index[i].m_Page); | |
353 | return; | |
354 | } | |
355 | } | |
356 | ||
357 | ||
358 | /* 5. if everything failed, search the documents: */ | |
359 | ||
360 | KeywordSearch(x); | |
361 | } | |
362 | ||
363 | ||
364 | ||
365 | void wxHtmlHelpController::Display(const int id) | |
366 | { | |
367 | CreateHelpWindow(); | |
368 | ||
369 | for (int i = 0; i < m_ContentsCnt; i++) { | |
370 | if (m_Contents[i].m_ID == id) { | |
371 | m_HtmlWin -> LoadPage(m_Contents[i].m_Book -> GetBasePath() + m_Contents[i].m_Page); | |
372 | return; | |
373 | } | |
374 | } | |
375 | } | |
376 | ||
377 | ||
378 | ||
379 | void wxHtmlHelpController::DisplayContents() | |
380 | { | |
381 | CreateHelpWindow(); | |
382 | m_Frame -> Raise(); | |
383 | if (!m_Splitter -> IsSplit()) { | |
384 | m_NavigPan -> Show(TRUE); | |
385 | m_HtmlWin -> Show(TRUE); | |
386 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
387 | } | |
388 | m_NavigPan -> SetSelection(0); | |
389 | } | |
390 | ||
391 | ||
392 | ||
393 | void wxHtmlHelpController::DisplayIndex() | |
394 | { | |
395 | CreateHelpWindow(); | |
396 | m_Frame -> Raise(); | |
397 | if (!m_Splitter -> IsSplit()) { | |
398 | m_NavigPan -> Show(TRUE); | |
399 | m_HtmlWin -> Show(TRUE); | |
400 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
401 | } | |
402 | m_NavigPan -> SetSelection(1); | |
403 | } | |
404 | ||
405 | ||
406 | ||
407 | ||
408 | #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)) | |
409 | ||
410 | class MyProgressDlg : public wxDialog | |
411 | { | |
412 | public: | |
413 | bool m_Canceled; | |
414 | ||
415 | MyProgressDlg(wxWindow *parent) : wxDialog(parent, -1, | |
416 | _("Searching..."), | |
417 | wxPoint(0, 0), | |
418 | #ifdef __WXGTK__ | |
419 | wxSize(300, 110)) | |
420 | #else | |
421 | wxSize(300, 130)) | |
422 | #endif | |
423 | {m_Canceled = FALSE;} | |
424 | void OnCancel(wxCommandEvent& event) {m_Canceled = TRUE;} | |
425 | DECLARE_EVENT_TABLE() | |
426 | }; | |
427 | BEGIN_EVENT_TABLE(MyProgressDlg, wxDialog) | |
428 | EVT_BUTTON(wxID_CANCEL, MyProgressDlg::OnCancel) | |
429 | END_EVENT_TABLE() | |
430 | ||
431 | #endif | |
432 | ||
433 | ||
434 | bool wxHtmlHelpController::KeywordSearch(const wxString& keyword) | |
435 | { | |
436 | int foundcnt = 0; | |
437 | ||
438 | CreateHelpWindow(); | |
439 | m_Frame -> Raise(); | |
440 | if (!m_Splitter -> IsSplit()) { | |
441 | m_NavigPan -> Show(TRUE); | |
442 | m_HtmlWin -> Show(TRUE); | |
443 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
444 | } | |
445 | m_NavigPan -> SetSelection(2); | |
446 | m_SearchList -> Clear(); | |
447 | m_SearchText -> SetValue(keyword); | |
448 | m_SearchButton -> Enable(FALSE); | |
449 | ||
450 | { | |
451 | int cnt = m_ContentsCnt; | |
452 | wxSearchEngine engine; | |
453 | wxFileSystem fsys; | |
454 | wxFSFile *file; | |
455 | wxString lastpage = wxEmptyString; | |
456 | wxString foundstr; | |
457 | ||
458 | #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)) | |
459 | MyProgressDlg progress(m_Frame); | |
460 | ||
461 | wxStaticText *prompt = new wxStaticText(&progress, -1, "", wxPoint(20, 50), wxSize(260, 25), wxALIGN_CENTER); | |
462 | wxGauge *gauge = new wxGauge(&progress, -1, cnt, wxPoint(20, 20), wxSize(260, 25)); | |
463 | wxButton *btn = new wxButton(&progress, wxID_CANCEL, _("Cancel"), wxPoint(110, 70), wxSize(80, 25)); | |
464 | btn = btn; /* fool compiler :-) */ | |
465 | prompt -> SetLabel(_("No matching page found yet")); | |
466 | ||
467 | progress.Centre(wxBOTH); | |
468 | progress.Show(TRUE); | |
469 | #else | |
470 | wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), cnt, m_Frame, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); | |
471 | #endif | |
472 | ||
473 | engine.LookFor(keyword); | |
474 | ||
475 | for (int i = 0; i < cnt; i++) { | |
476 | #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)) | |
477 | gauge -> SetValue(i); | |
478 | if (progress.m_Canceled) break; | |
479 | #else | |
480 | if (progress.Update(i) == FALSE) break; | |
481 | #endif | |
482 | wxYield(); | |
483 | ||
484 | file = fsys.OpenFile(m_Contents[i].m_Book -> GetBasePath() + m_Contents[i].m_Page); | |
485 | if (file) { | |
486 | if (lastpage != file -> GetLocation()) { | |
487 | lastpage = file -> GetLocation(); | |
488 | if (engine.Scan(file -> GetStream())) { | |
489 | foundstr.Printf(_("Found %i matches"), ++foundcnt); | |
490 | #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)) | |
491 | prompt -> SetLabel(foundstr); | |
492 | #else | |
493 | progress.Update(i, foundstr); | |
494 | #endif | |
495 | wxYield(); | |
496 | m_SearchList -> Append(m_Contents[i].m_Name, (char*)(m_Contents + i)); | |
497 | } | |
498 | } | |
499 | delete file; | |
500 | } | |
501 | } | |
502 | ||
503 | #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)) | |
504 | progress.Close(TRUE); | |
505 | #endif | |
506 | } | |
507 | ||
508 | m_SearchButton -> Enable(TRUE); | |
509 | m_SearchText -> SetSelection(0, keyword.Length()); | |
510 | m_SearchText -> SetFocus(); | |
511 | if (foundcnt) { | |
512 | HtmlContentsItem *it = (HtmlContentsItem*) m_SearchList -> GetClientData(0); | |
513 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
514 | } | |
515 | return (foundcnt > 0); | |
516 | } | |
517 | ||
518 | ||
519 | ||
520 | ||
521 | ||
522 | ||
523 | void wxHtmlHelpController::CreateHelpWindow() | |
524 | { | |
525 | wxBusyCursor cur; | |
526 | wxString oldpath; | |
527 | wxStatusBar *sbar; | |
528 | ||
529 | if (m_Frame) { | |
530 | m_Frame -> Raise(); | |
531 | m_Frame -> Show(TRUE); | |
532 | return; | |
533 | } | |
534 | ||
535 | wxBusyInfo busyinfo(_("Preparing help window...")); | |
536 | ||
537 | if (m_Config) ReadCustomization(m_Config, m_ConfigRoot); | |
538 | ||
539 | m_Frame = new wxFrame(NULL, -1, "", wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h)); | |
540 | m_Frame -> PushEventHandler(this); | |
541 | sbar = m_Frame -> CreateStatusBar(); | |
542 | ||
543 | { | |
544 | wxToolBar *toolBar; | |
545 | toolBar = m_Frame -> CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE); | |
546 | toolBar -> SetMargins(2, 2); | |
547 | wxBitmap* toolBarBitmaps[3]; | |
548 | ||
549 | #ifdef __WXMSW__ | |
550 | toolBarBitmaps[0] = new wxBitmap("panel"); | |
551 | toolBarBitmaps[1] = new wxBitmap("back"); | |
552 | toolBarBitmaps[2] = new wxBitmap("forward"); | |
553 | int width = 24; | |
554 | #else | |
555 | toolBarBitmaps[0] = new wxBitmap(panel_xpm); | |
556 | toolBarBitmaps[1] = new wxBitmap(back_xpm); | |
557 | toolBarBitmaps[2] = new wxBitmap(forward_xpm); | |
558 | int width = 16; | |
559 | #endif | |
560 | ||
561 | int currentX = 5; | |
562 | ||
563 | toolBar -> AddTool(wxID_HTML_PANEL, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, _("Show/hide navigation panel")); | |
564 | currentX += width + 5; | |
565 | toolBar -> AddSeparator(); | |
566 | toolBar -> AddTool(wxID_HTML_BACK, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, _("Go back to the previous HTML page")); | |
567 | currentX += width + 5; | |
568 | toolBar -> AddTool(wxID_HTML_FORWARD, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, _("Go forward to the next HTML page")); | |
569 | currentX += width + 5; | |
570 | ||
571 | toolBar -> Realize(); | |
572 | ||
573 | // Can delete the bitmaps since they're reference counted | |
574 | for (int i = 0; i < 3; i++) delete toolBarBitmaps[i]; | |
575 | } | |
576 | ||
577 | ||
578 | { | |
579 | m_Splitter = new wxSplitterWindow(m_Frame); | |
580 | ||
581 | m_HtmlWin = new wxHtmlWindow(m_Splitter); | |
582 | m_HtmlWin -> SetRelatedFrame(m_Frame, m_TitleFormat); | |
583 | m_HtmlWin -> SetRelatedStatusBar(0); | |
584 | if (m_Config) m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot); | |
585 | ||
586 | m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK, wxDefaultPosition, wxDefaultSize); | |
587 | { | |
588 | m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); | |
589 | m_ContentsBox -> SetImageList(m_ContentsImageList); | |
590 | m_NavigPan -> AddPage(m_ContentsBox, _("Contents")); | |
591 | } | |
592 | ||
593 | { | |
594 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE); | |
595 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
596 | b1 -> top.SameAs (dummy, wxTop, 0); | |
597 | b1 -> left.SameAs (dummy, wxLeft, 0); | |
598 | b1 -> width.PercentOf (dummy, wxWidth, 100); | |
599 | b1 -> bottom.SameAs (dummy, wxBottom, 0); | |
600 | m_IndexBox = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0); | |
601 | m_IndexBox -> SetConstraints(b1); | |
602 | dummy -> SetAutoLayout(TRUE); | |
603 | m_NavigPan -> AddPage(dummy, _("Index")); | |
604 | } | |
605 | ||
606 | { | |
607 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE); | |
608 | ||
609 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
610 | m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT); | |
611 | b1 -> top.SameAs (dummy, wxTop, 0); | |
612 | b1 -> left.SameAs (dummy, wxLeft, 0); | |
613 | b1 -> right.SameAs (dummy, wxRight, 0); | |
614 | b1 -> height.AsIs(); | |
615 | m_SearchText -> SetConstraints(b1); | |
616 | ||
617 | wxLayoutConstraints *b2 = new wxLayoutConstraints; | |
618 | m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search!")); | |
619 | b2 -> top.Below (m_SearchText, 10); | |
620 | b2 -> right.SameAs (dummy, wxRight, 10); | |
621 | b2 -> width.AsIs(); | |
622 | b2 -> height.AsIs(); | |
623 | m_SearchButton -> SetConstraints(b2); | |
624 | ||
625 | wxLayoutConstraints *b3 = new wxLayoutConstraints; | |
626 | m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0); | |
627 | b3 -> top.Below (m_SearchButton, 10); | |
628 | b3 -> left.SameAs (dummy, wxLeft, 0); | |
629 | b3 -> right.SameAs (dummy, wxRight, 0); | |
630 | b3 -> bottom.SameAs (dummy, wxBottom, 0); | |
631 | m_SearchList -> SetConstraints(b3); | |
632 | ||
633 | dummy -> SetAutoLayout(TRUE); | |
634 | dummy -> Layout(); | |
635 | m_NavigPan -> AddPage(dummy, _("Search")); | |
636 | } | |
637 | ||
638 | RefreshLists(); | |
639 | m_NavigPan -> Show(TRUE); | |
640 | m_HtmlWin -> Show(TRUE); | |
641 | m_Splitter -> SetMinimumPaneSize(20); | |
642 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
643 | if (!m_Cfg.navig_on) m_Splitter -> Unsplit(m_NavigPan); | |
644 | wxYield(); | |
645 | } | |
646 | ||
647 | m_Frame -> Show(TRUE); | |
648 | wxYield(); | |
649 | } | |
650 | ||
651 | ||
652 | ||
653 | #define MAX_ROOTS 64 | |
654 | ||
655 | void wxHtmlHelpController::CreateContents() | |
656 | { | |
657 | HtmlContentsItem *it; | |
658 | wxTreeItemId roots[MAX_ROOTS]; | |
659 | bool imaged[MAX_ROOTS]; | |
660 | int count = m_ContentsCnt; | |
661 | ||
662 | m_ContentsBox -> DeleteAllItems(); | |
663 | roots[0] = m_ContentsBox -> AddRoot(_("(Help)")); | |
664 | imaged[0] = TRUE; | |
665 | ||
666 | for (int i = 0; i < count; i++) { | |
667 | it = m_Contents + i; | |
668 | roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(roots[it -> m_Level], it -> m_Name, IMG_Page, -1, new HtmlHelpTreeItemData(it)); | |
669 | if (it -> m_Level == 0) { | |
670 | m_ContentsBox -> SetItemBold(roots[1], TRUE); | |
671 | m_ContentsBox -> SetItemImage(roots[1], IMG_Book); | |
672 | m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book); | |
673 | imaged[1] = TRUE; | |
674 | } | |
675 | else imaged[it -> m_Level + 1] = FALSE; | |
676 | ||
677 | if (!imaged[it -> m_Level]) { | |
678 | m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder); | |
679 | m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder); | |
680 | imaged[it -> m_Level] = TRUE; | |
681 | } | |
682 | } | |
683 | ||
684 | m_ContentsBox -> Expand(roots[0]); | |
685 | } | |
686 | ||
687 | ||
688 | ||
689 | ||
690 | void wxHtmlHelpController::CreateIndex() | |
691 | { | |
692 | m_IndexBox -> Clear(); | |
693 | ||
694 | for (int i = 0; i < m_IndexCnt; i++) | |
695 | m_IndexBox -> Append(m_Index[i].m_Name, (char*)(m_Index + i)); | |
696 | } | |
697 | ||
698 | ||
699 | ||
700 | void wxHtmlHelpController::RefreshLists() | |
701 | { | |
702 | if (m_Frame) { | |
703 | CreateContents(); | |
704 | CreateIndex(); | |
705 | m_SearchList -> Clear(); | |
706 | } | |
707 | } | |
708 | ||
709 | ||
710 | ||
711 | ||
712 | ||
713 | ||
714 | ||
715 | void wxHtmlHelpController::ReadCustomization(wxConfigBase *cfg, wxString path) | |
716 | { | |
717 | wxString oldpath; | |
718 | wxString tmp; | |
719 | ||
720 | if (path != wxEmptyString) { | |
721 | oldpath = cfg -> GetPath(); | |
722 | cfg -> SetPath(path); | |
723 | } | |
724 | ||
725 | m_Cfg.navig_on = (bool) cfg -> Read("hcNavigPanel", m_Cfg.navig_on); | |
726 | m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos); | |
727 | m_Cfg.x = cfg -> Read("hcX", m_Cfg.x); | |
728 | m_Cfg.y = cfg -> Read("hcY", m_Cfg.y); | |
729 | m_Cfg.w = cfg -> Read("hcW", m_Cfg.w); | |
730 | m_Cfg.h = cfg -> Read("hcH", m_Cfg.h); | |
731 | ||
732 | if (path != wxEmptyString) | |
733 | cfg -> SetPath(oldpath); | |
734 | } | |
735 | ||
736 | ||
737 | ||
738 | void wxHtmlHelpController::WriteCustomization(wxConfigBase *cfg, wxString path) | |
739 | { | |
740 | wxString oldpath; | |
741 | wxString tmp; | |
742 | ||
743 | if (path != wxEmptyString) { | |
744 | oldpath = cfg -> GetPath(); | |
745 | cfg -> SetPath(path); | |
746 | } | |
747 | ||
748 | cfg -> Write("hcNavigPanel", m_Cfg.navig_on); | |
749 | cfg -> Write("hcSashPos", (long)m_Cfg.sashpos); | |
750 | cfg -> Write("hcX", (long)m_Cfg.x); | |
751 | cfg -> Write("hcY", (long)m_Cfg.y); | |
752 | cfg -> Write("hcW", (long)m_Cfg.w); | |
753 | cfg -> Write("hcH", (long)m_Cfg.h); | |
754 | ||
755 | if (path != wxEmptyString) | |
756 | cfg -> SetPath(oldpath); | |
757 | } | |
758 | ||
759 | ||
760 | ||
761 | ||
762 | ||
763 | /* | |
764 | EVENT HANDLING : | |
765 | */ | |
766 | ||
767 | ||
768 | void wxHtmlHelpController::OnToolbar(wxCommandEvent& event) | |
769 | { | |
770 | switch (event.GetId()) { | |
771 | case wxID_HTML_BACK : | |
772 | m_HtmlWin -> HistoryBack(); | |
773 | break; | |
774 | case wxID_HTML_FORWARD : | |
775 | m_HtmlWin -> HistoryForward(); | |
776 | break; | |
777 | case wxID_HTML_PANEL : | |
778 | if (m_Splitter -> IsSplit()) { | |
779 | m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
780 | m_Splitter -> Unsplit(m_NavigPan); | |
781 | } | |
782 | else { | |
783 | m_NavigPan -> Show(TRUE); | |
784 | m_HtmlWin -> Show(TRUE); | |
785 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
786 | } | |
787 | break; | |
788 | } | |
789 | } | |
790 | ||
791 | ||
792 | ||
793 | void wxHtmlHelpController::OnContentsSel(wxTreeEvent& event) | |
794 | { | |
795 | HtmlHelpTreeItemData *pg; | |
796 | ||
797 | pg = (HtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); | |
798 | if (pg) m_HtmlWin -> LoadPage(pg -> GetPage()); | |
799 | } | |
800 | ||
801 | ||
802 | ||
803 | void wxHtmlHelpController::OnIndexSel(wxCommandEvent& event) | |
804 | { | |
805 | HtmlContentsItem *it = (HtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection()); | |
806 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
807 | } | |
808 | ||
809 | ||
810 | ||
811 | void wxHtmlHelpController::OnSearchSel(wxCommandEvent& event) | |
812 | { | |
813 | HtmlContentsItem *it = (HtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection()); | |
814 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
815 | } | |
816 | ||
817 | ||
818 | ||
819 | void wxHtmlHelpController::OnCloseWindow(wxCloseEvent& event) | |
820 | { | |
821 | int a, b; | |
822 | ||
823 | m_Cfg.navig_on = m_Splitter -> IsSplit(); | |
824 | if (m_Cfg.navig_on) | |
825 | m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
826 | m_Frame -> GetPosition(&a, &b); | |
827 | m_Cfg.x = a, m_Cfg.y = b; | |
828 | m_Frame -> GetSize(&a, &b); | |
829 | m_Cfg.w = a, m_Cfg.h = b; | |
830 | ||
831 | if (m_Config) { | |
832 | WriteCustomization(m_Config, m_ConfigRoot); | |
833 | m_HtmlWin -> WriteCustomization(m_Config, m_ConfigRoot); | |
834 | } | |
835 | m_Frame = NULL; | |
836 | ||
837 | event.Skip(); | |
838 | } | |
839 | ||
840 | ||
841 | ||
842 | void wxHtmlHelpController::OnSearch(wxCommandEvent& event) | |
843 | { | |
844 | wxString sr = m_SearchText -> GetLineText(0); | |
845 | ||
846 | if (sr != wxEmptyString) KeywordSearch(sr); | |
847 | } | |
848 | ||
849 | ||
850 | ||
851 | BEGIN_EVENT_TABLE(wxHtmlHelpController, wxEvtHandler) | |
852 | EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_FORWARD, wxHtmlHelpController::OnToolbar) | |
853 | EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpController::OnContentsSel) | |
854 | EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpController::OnIndexSel) | |
855 | EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpController::OnSearchSel) | |
856 | EVT_CLOSE(wxHtmlHelpController::OnCloseWindow) | |
857 | EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpController::OnSearch) | |
858 | EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpController::OnSearch) | |
859 | END_EVENT_TABLE() | |
860 | ||
861 | ||
862 | ||
863 | #endif | |
864 |