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