]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
search progress bar has smooth gauge under win95 now
[wxWidgets.git] / src / html / helpfrm.cpp
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 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h"
17
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 #ifndef WXPRECOMP
28 #include "wx/wx.h"
29 #endif
30
31 #include "wx/html/helpfrm.h"
32 #include "wx/notebook.h"
33 #include "wx/imaglist.h"
34 #include "wx/treectrl.h"
35 #include "wx/tokenzr.h"
36 #include "wx/wfstream.h"
37 #include "wx/html/htmlwin.h"
38 #include "wx/busyinfo.h"
39 #include "wx/progdlg.h"
40 #include "wx/toolbar.h"
41 #include "wx/fontenum.h"
42
43 // Bitmaps:
44
45 #ifndef __WXMSW__
46 #include "bitmaps/wpanel.xpm"
47 #include "bitmaps/wback.xpm"
48 #include "bitmaps/wforward.xpm"
49 #include "bitmaps/wbook.xpm"
50 #include "bitmaps/woptions.xpm"
51 #include "bitmaps/wfolder.xpm"
52 #include "bitmaps/wpage.xpm"
53 #include "bitmaps/whelp.xpm"
54 #include "bitmaps/whlproot.xpm"
55 #include "bitmaps/wbkadd.xpm"
56 #include "bitmaps/wbkdel.xpm"
57 #endif
58
59 #include "wx/stream.h"
60
61 // number of times that the contents/index creation progress dialog
62 // is updated.
63 #define PROGRESS_STEP 40
64
65 // what is considered "small index"?
66 #define INDEX_IS_SMALL 100
67
68
69 //--------------------------------------------------------------------------
70 // wxHtmlHelpTreeItemData (private)
71 //--------------------------------------------------------------------------
72
73 class wxHtmlHelpTreeItemData : public wxTreeItemData
74 {
75 private:
76 wxString m_Page;
77
78 public:
79 wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData()
80 {
81 m_Page = it -> m_Book -> GetBasePath() + it -> m_Page;
82 }
83 const wxString& GetPage() { return m_Page; }
84 };
85
86
87
88
89 //---------------------------------------------------------------------------
90 // wxHtmlHelpFrame
91 //---------------------------------------------------------------------------
92
93 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
94
95 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
96 int style, wxHtmlHelpData* data)
97 {
98 Init(data);
99 Create(parent, id, title, style);
100 }
101
102 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
103 {
104 if (data) {
105 m_Data = data;
106 m_DataCreated = FALSE;
107 } else {
108 m_Data = new wxHtmlHelpData();
109 m_DataCreated = TRUE;
110 }
111
112 m_ContentsImageList = new wxImageList(16, 16);
113 m_ContentsImageList -> Add(wxICON(wbook));
114 m_ContentsImageList -> Add(wxICON(wfolder));
115 m_ContentsImageList -> Add(wxICON(wpage));
116 m_ContentsImageList -> Add(wxICON(whlproot));
117
118 m_ContentsBox = NULL;
119 m_IndexList = NULL;
120 m_IndexButton = NULL;
121 m_IndexButtonAll = NULL;
122 m_IndexText = NULL;
123 m_SearchList = NULL;
124 m_SearchButton = NULL;
125 m_SearchText = NULL;
126 m_SearchChoice = NULL;
127 m_IndexCountInfo = NULL;
128 m_Splitter = NULL;
129 m_NavigPan = NULL;
130 m_HtmlWin = NULL;
131 m_Bookmarks = NULL;
132 m_SearchCaseSensitive = NULL;
133 m_SearchWholeWords = NULL;
134
135 m_Config = NULL;
136 m_ConfigRoot = wxEmptyString;
137
138 m_Cfg.x = m_Cfg.y = 0;
139 m_Cfg.w = 700;
140 m_Cfg.h = 480;
141 m_Cfg.sashpos = 240;
142 m_Cfg.navig_on = TRUE;
143
144 m_NormalFonts = m_FixedFonts = NULL;
145 m_FontSize = 1;
146 m_NormalFace = m_FixedFace = wxEmptyString;
147 }
148
149 // Create: builds the GUI components.
150 // with the style flag it's possible to toggle the toolbar, contents, index and search
151 // controls.
152 // m_HtmlWin will *always* be created, but it's important to realize that
153 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
154 // m_SearchButton may be NULL.
155 // moreover, if no contents, index or searchpage is needed, m_Splitter and
156 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
157
158 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title,
159 int style)
160 {
161 // Do the config in two steps. We read the HtmlWindow customization after we
162 // create the window.
163 if (m_Config)
164 ReadCustomization(m_Config, m_ConfigRoot);
165
166 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), wxDEFAULT_FRAME_STYLE, "wxHtmlHelp");
167
168 GetPosition(&m_Cfg.x, &m_Cfg.y);
169
170 SetIcon(wxICON(whelp));
171
172 int notebook_page = 0;
173
174 CreateStatusBar();
175
176 // toolbar?
177 if (style & wxHF_TOOLBAR) {
178 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE);
179 toolBar->SetMargins( 2, 2 );
180
181 toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap,
182 FALSE, -1, -1, (wxObject *) NULL,
183 _("Show/hide navigation panel"));
184 toolBar -> AddSeparator();
185 toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap,
186 FALSE, -1, -1, (wxObject *) NULL,
187 _("Go back to the previous HTML page"));
188 toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap,
189 FALSE, -1, -1, (wxObject *) NULL,
190 _("Go forward to the next HTML page"));
191 toolBar -> AddSeparator();
192
193 if (style & wxHF_BOOKMARKS) {
194 m_Bookmarks = new wxComboBox(toolBar, wxID_HTML_BOOKMARKSLIST, wxEmptyString,
195 wxDefaultPosition, wxSize(300,-1), 0, NULL, wxCB_READONLY | wxCB_SORT);
196 m_Bookmarks -> Append(_("<bookmarks>"));
197 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
198 m_Bookmarks -> Append(m_BookmarksNames[i]);
199 m_Bookmarks -> SetSelection(0);
200 toolBar -> AddControl(m_Bookmarks);
201 #ifdef __WXGTK__
202 toolBar -> AddSeparator();
203 #endif
204 toolBar -> AddTool(wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxNullBitmap,
205 FALSE, -1, -1, (wxObject *) NULL,
206 _("Add current page to bookmarks"));
207 toolBar -> AddTool(wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxNullBitmap,
208 FALSE, -1, -1, (wxObject *) NULL,
209 _("Remove current page from bookmarks"));
210 }
211
212 toolBar -> AddSeparator();
213 toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
214 FALSE, -1, -1, (wxObject *) NULL,
215 _("Display options dialog"));
216
217 toolBar -> Realize();
218 }
219
220 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) {
221 // traditional help controller; splitter window with html page on the
222 // right and a notebook containing various pages on the left
223 m_Splitter = new wxSplitterWindow(this);
224
225 m_HtmlWin = new wxHtmlWindow(m_Splitter);
226 m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK,
227 wxDefaultPosition, wxDefaultSize);
228 } else { // only html window, no notebook with index,contents etc
229 m_HtmlWin = new wxHtmlWindow(this);
230 }
231
232 m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat);
233 m_HtmlWin -> SetRelatedStatusBar(0);
234 if (m_Config)
235 m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
236
237 // contents tree panel?
238 if (style & wxHF_CONTENTS) {
239 m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL,
240 wxDefaultPosition, wxDefaultSize,
241 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
242 m_ContentsBox -> SetImageList(m_ContentsImageList);
243 m_NavigPan -> AddPage(m_ContentsBox, _("Contents"));
244 m_ContentsPage = notebook_page++;
245 }
246
247 // index listbox panel?
248 if (style & wxHF_INDEX) {
249 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
250
251 wxLayoutConstraints *b1 = new wxLayoutConstraints;
252 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
253 b1 -> top.SameAs (dummy, wxTop, 10);
254 b1 -> left.SameAs (dummy, wxLeft, 10);
255 b1 -> right.SameAs (dummy, wxRight, 10);
256 b1 -> height.AsIs();
257 m_IndexText -> SetConstraints(b1);
258
259 wxLayoutConstraints *b4 = new wxLayoutConstraints;
260 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, _("Show all"));
261
262 b4 -> top.Below (m_IndexText, 10);
263 b4 -> right.SameAs (dummy, wxRight, 10);
264 b4 -> width.AsIs();
265 b4 -> height.AsIs();
266 m_IndexButtonAll -> SetConstraints(b4);
267
268 wxLayoutConstraints *b2 = new wxLayoutConstraints;
269 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
270 b2 -> top.Below (m_IndexText, 10);
271 b2 -> right.LeftOf (m_IndexButtonAll, 10);
272 b2 -> width.AsIs();
273 b2 -> height.AsIs();
274 m_IndexButton -> SetConstraints(b2);
275
276 wxLayoutConstraints *b5 = new wxLayoutConstraints;
277 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
278
279 b5 -> top.Below (m_IndexButton, 5);
280 b5 -> right.SameAs (dummy, wxRight, 10);
281 b5 -> left.SameAs (dummy, wxLeft, 10);
282 b5 -> height.AsIs();
283 m_IndexCountInfo -> SetConstraints(b5);
284
285 wxLayoutConstraints *b3 = new wxLayoutConstraints;
286 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB);
287 b3 -> top.Below (m_IndexCountInfo, 5);
288 b3 -> left.SameAs (dummy, wxLeft, 0);
289 b3 -> right.SameAs (dummy, wxRight, 0);
290 b3 -> bottom.SameAs (dummy, wxBottom, 0);
291 m_IndexList -> SetConstraints(b3);
292
293 #if wxUSE_TOOLTIPS
294 m_IndexButtonAll -> SetToolTip(_("Show all items in index"));
295 m_IndexButton -> SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
296 #endif //wxUSE_TOOLTIPS
297
298 dummy -> SetAutoLayout(TRUE);
299 dummy -> Layout();
300
301 m_NavigPan -> AddPage(dummy, _("Index"));
302 m_IndexPage = notebook_page++;
303 }
304
305 // search list panel?
306 if (style & wxHF_SEARCH) {
307 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
308
309 wxLayoutConstraints *b1 = new wxLayoutConstraints;
310 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
311 b1 -> top.SameAs (dummy, wxTop, 10);
312 b1 -> left.SameAs (dummy, wxLeft, 10);
313 b1 -> right.SameAs (dummy, wxRight, 10);
314 b1 -> height.AsIs();
315 m_SearchText -> SetConstraints(b1);
316
317 wxLayoutConstraints *b2 = new wxLayoutConstraints;
318 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
319 #if wxUSE_TOOLTIPS
320 m_SearchButton -> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
321 #endif //wxUSE_TOOLTIPS
322 b2 -> top.Below (m_SearchText, 10);
323 b2 -> left.SameAs (dummy, wxLeft, 10);
324 b2 -> width.AsIs();
325 b2 -> height.AsIs();
326 m_SearchButton -> SetConstraints(b2);
327
328 wxLayoutConstraints *b4 = new wxLayoutConstraints;
329 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
330 wxDefaultSize);
331 b4 -> top.Below (m_SearchText, 10);
332 b4 -> left.SameAs (m_SearchButton, wxRight, 10);
333 b4 -> right.SameAs (dummy, wxRight, 10);
334 b4 -> height.AsIs();
335 m_SearchChoice -> SetConstraints(b4);
336
337 wxLayoutConstraints *b5 = new wxLayoutConstraints;
338 m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive"));
339 b5 -> top.Below (m_SearchButton, 10);
340 b5 -> left.SameAs (dummy, wxLeft, 10);
341 b5 -> right.SameAs (dummy, wxRight, 10);
342 b5 -> height.AsIs ();
343 m_SearchCaseSensitive -> SetConstraints(b5);
344
345 wxLayoutConstraints *b6 = new wxLayoutConstraints;
346 m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only"));
347 b6 -> top.Below (m_SearchCaseSensitive, 0);
348 b6 -> left.SameAs (dummy, wxLeft, 10);
349 b6 -> right.SameAs (dummy, wxRight, 10);
350 b6 -> height.AsIs ();
351 m_SearchWholeWords -> SetConstraints(b6);
352
353 wxLayoutConstraints *b3 = new wxLayoutConstraints;
354 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB);
355 b3 -> top.Below (m_SearchWholeWords, 10);
356 b3 -> left.SameAs (dummy, wxLeft, 0);
357 b3 -> right.SameAs (dummy, wxRight, 0);
358 b3 -> bottom.SameAs (dummy, wxBottom, 0);
359 m_SearchList -> SetConstraints(b3);
360
361 dummy -> SetAutoLayout(TRUE);
362 dummy -> Layout();
363 m_NavigPan -> AddPage(dummy, _("Search"));
364 m_SearchPage = notebook_page++;
365 }
366 m_HtmlWin -> Show(TRUE);
367
368 //RefreshLists();
369
370 // showtime
371 if (m_NavigPan && m_Splitter) {
372 m_Splitter -> SetMinimumPaneSize(20);
373 if (m_Cfg.navig_on)
374 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
375 else {
376 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
377 m_Splitter -> Unsplit();
378 }
379 if (m_Cfg.navig_on) {
380 m_NavigPan -> Show(TRUE);
381 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
382 }
383 else {
384 m_NavigPan -> Show(FALSE);
385 m_Splitter -> Initialize(m_HtmlWin);
386 }
387 }
388 return TRUE;
389 }
390
391 wxHtmlHelpFrame::~wxHtmlHelpFrame()
392 {
393 delete m_ContentsImageList;
394 if (m_DataCreated)
395 delete m_Data;
396 if (m_NormalFonts) delete m_NormalFonts;
397 if (m_FixedFonts) delete m_FixedFonts;
398 }
399
400 bool wxHtmlHelpFrame::Display(const wxString& x)
401 {
402 wxString url = m_Data->FindPageByName(x);
403 if (! url.IsEmpty()) {
404 m_HtmlWin->LoadPage(url);
405 return TRUE;
406 }
407 return FALSE;
408 }
409
410 bool wxHtmlHelpFrame::Display(const int id)
411 {
412 wxString url = m_Data->FindPageById(id);
413 if (! url.IsEmpty()) {
414 m_HtmlWin->LoadPage(url);
415 return TRUE;
416 }
417 return FALSE;
418 }
419
420
421
422 bool wxHtmlHelpFrame::DisplayContents()
423 {
424 if (! m_ContentsBox)
425 return FALSE;
426 if (!m_Splitter -> IsSplit()) {
427 m_NavigPan -> Show(TRUE);
428 m_HtmlWin -> Show(TRUE);
429 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
430 m_Cfg.navig_on = TRUE;
431 }
432 m_NavigPan -> SetSelection(0);
433 return TRUE;
434 }
435
436
437
438 bool wxHtmlHelpFrame::DisplayIndex()
439 {
440 if (! m_IndexList)
441 return FALSE;
442 if (!m_Splitter -> IsSplit()) {
443 m_NavigPan -> Show(TRUE);
444 m_HtmlWin -> Show(TRUE);
445 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
446 }
447 m_NavigPan -> SetSelection(1);
448 return TRUE;
449 }
450
451 bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
452 {
453 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
454 return FALSE;
455
456 int foundcnt = 0, curi;
457 wxString foundstr;
458 wxString book = wxEmptyString;
459
460 if (!m_Splitter -> IsSplit()) {
461 m_NavigPan -> Show(TRUE);
462 m_HtmlWin -> Show(TRUE);
463 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
464 }
465 m_NavigPan -> SetSelection(m_SearchPage);
466 m_SearchList -> Clear();
467 m_SearchText -> SetValue(keyword);
468 m_SearchButton -> Enable(FALSE);
469
470 if (m_SearchChoice->GetSelection() != 0)
471 book = m_SearchChoice->GetStringSelection();
472
473 wxHtmlSearchStatus status(m_Data, keyword,
474 m_SearchCaseSensitive -> GetValue(), m_SearchWholeWords -> GetValue(),
475 book);
476
477 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
478 status.GetMaxIndex(), this,
479 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE | wxGA_SMOOTH);
480
481 while (status.IsActive()) {
482 curi = status.GetCurIndex();
483 if (curi % 10 == 0 && progress.Update(curi) == FALSE)
484 break;
485 if (status.Search()) {
486 foundstr.Printf(_("Found %i matches"), ++foundcnt);
487 progress.Update(status.GetCurIndex(), foundstr);
488 m_SearchList -> Append(status.GetName(), status.GetContentsItem());
489 }
490 wxYield();
491 }
492
493 m_SearchButton -> Enable(TRUE);
494 m_SearchText -> SetSelection(0, keyword.Length());
495 m_SearchText -> SetFocus();
496 if (foundcnt) {
497 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0);
498 if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
499 }
500 return (foundcnt > 0);
501 }
502
503 #define MAX_ROOTS 64
504
505 void wxHtmlHelpFrame::CreateContents(bool show_progress)
506 {
507 if (! m_ContentsBox)
508 return ;
509
510 wxProgressDialog *progress = NULL;
511 wxString proginfo;
512
513 wxLogDebug("building context");
514 m_ContentsBox->Clear();
515
516 int cnt = m_Data->GetContentsCnt();
517 int div = (cnt / PROGRESS_STEP) + 1;
518 int i;
519
520 wxHtmlContentsItem *it;
521
522 if (show_progress)
523 progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString,
524 cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
525 wxPD_AUTO_HIDE);
526
527 wxTreeItemId roots[MAX_ROOTS];
528 bool imaged[MAX_ROOTS];
529
530 m_ContentsBox -> DeleteAllItems();
531 roots[0] = m_ContentsBox -> AddRoot(_("(Help)"));
532 m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder);
533 m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder);
534 imaged[0] = TRUE;
535
536 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
537 if (show_progress && ((i % div) == 0)) {
538 proginfo.Printf(_("Added %d/%d items"), i, cnt);
539 if (! progress->Update(i, proginfo))
540 break;
541 wxYield();
542 }
543 roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
544 roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
545 new wxHtmlHelpTreeItemData(it));
546
547 if (it -> m_Level == 0) {
548 m_ContentsBox -> SetItemBold(roots[1], TRUE);
549 m_ContentsBox -> SetItemImage(roots[1], IMG_Book);
550 m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book);
551 imaged[1] = TRUE;
552 } else imaged[it -> m_Level + 1] = FALSE;
553
554 if (!imaged[it -> m_Level]) {
555 m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder);
556 m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder);
557 imaged[it -> m_Level] = TRUE;
558 }
559 }
560 if (show_progress)
561 delete progress;
562 m_ContentsBox -> Expand(roots[0]);
563 wxLogDebug("...done");
564 }
565
566
567 void wxHtmlHelpFrame::CreateIndex(bool show_progress)
568 {
569 if (! m_IndexList)
570 return ;
571
572 wxProgressDialog *progress = NULL;
573 wxString proginfo;
574
575 m_IndexList->Clear();
576
577 int cnt = m_Data->GetIndexCnt();
578
579 wxString cnttext;
580 if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt);
581 else cnttext.Printf(_("%i of %i"), cnt, cnt);
582 m_IndexCountInfo -> SetLabel(cnttext);
583 if (cnt > INDEX_IS_SMALL) return;
584
585 int div = (cnt / PROGRESS_STEP) + 1;
586
587 wxHtmlContentsItem* index = m_Data->GetIndex();
588
589 if (show_progress)
590 progress = new wxProgressDialog(_("Building index list..."), wxEmptyString,
591 cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
592 wxPD_AUTO_HIDE);
593 for (int i = 0; i < cnt; i++) {
594 if (show_progress && ((i % div) == 0)) {
595 proginfo.Printf(_("Added %d/%d items"), i, cnt);
596 if (! progress->Update(i, proginfo))
597 break;
598 wxYield();
599 }
600 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
601 }
602
603 if (show_progress)
604 delete progress;
605 }
606
607 void wxHtmlHelpFrame::CreateSearch()
608 {
609 if (! (m_SearchList && m_SearchChoice))
610 return ;
611 m_SearchList -> Clear();
612 m_SearchChoice -> Clear();
613 m_SearchChoice -> Append(_("all books"));
614 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
615 int i, cnt = bookrec.GetCount();
616 for (i = 0; i < cnt; i++)
617 m_SearchChoice->Append(bookrec[i].GetTitle());
618 m_SearchChoice->SetSelection(0);
619 }
620
621
622 void wxHtmlHelpFrame::RefreshLists(bool show_progress)
623 {
624 CreateContents(show_progress);
625 CreateIndex(show_progress);
626 CreateSearch();
627 }
628
629 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
630 {
631 wxString oldpath;
632 wxString tmp;
633
634 if (path != wxEmptyString) {
635 oldpath = cfg -> GetPath();
636 cfg -> SetPath(path);
637 }
638
639 m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0;
640 m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos);
641 m_Cfg.x = cfg -> Read("hcX", m_Cfg.x);
642 m_Cfg.y = cfg -> Read("hcY", m_Cfg.y);
643 m_Cfg.w = cfg -> Read("hcW", m_Cfg.w);
644 m_Cfg.h = cfg -> Read("hcH", m_Cfg.h);
645
646 m_FixedFace = cfg -> Read("hcFixedFace", m_FixedFace);
647 m_NormalFace = cfg -> Read("hcNormalFace", m_NormalFace);
648 m_FontSize = cfg -> Read("hcFontSize", m_FontSize);
649
650 {
651 int i;
652 int cnt;
653 wxString val, s;
654
655 cnt = cfg -> Read("hcBookmarksCnt", 0L);
656 if (cnt != 0) {
657 m_BookmarksNames.Clear();
658 m_BookmarksPages.Clear();
659 if (m_Bookmarks) {
660 m_Bookmarks -> Clear();
661 m_Bookmarks -> Append(_("<bookmarks>"));
662 }
663
664 for (i = 0; i < cnt; i++) {
665 val.Printf(wxT("hcBookmark_%i"), i);
666 s = cfg -> Read(val);
667 m_BookmarksNames.Add(s);
668 if (m_Bookmarks) m_Bookmarks -> Append(s);
669 val.Printf(wxT("hcBookmark_%i_url"), i);
670 s = cfg -> Read(val);
671 m_BookmarksPages.Add(s);
672 }
673 }
674 }
675
676 if (m_HtmlWin)
677 m_HtmlWin->ReadCustomization(cfg, path);
678
679 if (path != wxEmptyString)
680 cfg -> SetPath(oldpath);
681 }
682
683 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
684 {
685 wxString oldpath;
686 wxString tmp;
687
688 if (path != wxEmptyString) {
689 oldpath = cfg -> GetPath();
690 cfg -> SetPath(path);
691 }
692
693 cfg -> Write("hcNavigPanel", m_Cfg.navig_on);
694 cfg -> Write("hcSashPos", (long)m_Cfg.sashpos);
695 cfg -> Write("hcX", (long)m_Cfg.x);
696 cfg -> Write("hcY", (long)m_Cfg.y);
697 cfg -> Write("hcW", (long)m_Cfg.w);
698 cfg -> Write("hcH", (long)m_Cfg.h);
699 cfg -> Write("hcFixedFace", m_FixedFace);
700 cfg -> Write("hcNormalFace", m_NormalFace);
701 cfg -> Write("hcFontSize", (long)m_FontSize);
702
703 if (m_Bookmarks) {
704 int i;
705 int cnt = m_BookmarksNames.GetCount();
706 wxString val;
707
708 cfg -> Write("hcBookmarksCnt", (long)cnt);
709 for (i = 0; i < cnt; i++) {
710 val.Printf(wxT("hcBookmark_%i"), i);
711 cfg -> Write(val, m_BookmarksNames[i]);
712 val.Printf(wxT("hcBookmark_%i_url"), i);
713 cfg -> Write(val, m_BookmarksPages[i]);
714 }
715 }
716
717 if (m_HtmlWin)
718 m_HtmlWin->WriteCustomization(cfg, path);
719
720 if (path != wxEmptyString)
721 cfg -> SetPath(oldpath);
722 }
723
724
725
726
727
728 static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
729 {
730 static int f_sizes[3][7] =
731 {
732 { 8, 9, 12, 14, 16, 19, 22},
733 {10, 12, 14, 16, 19, 24, 32},
734 {14, 16, 18, 24, 32, 38, 45}
735 };
736
737 win -> SetFonts(scalf, fixf, f_sizes[size]);
738 }
739
740
741 class wxHtmlHelpFrameOptionsDialog : public wxDialog
742 {
743 public:
744 wxComboBox *NormalFont, *FixedFont;
745 wxRadioBox *RadioBox;
746 wxHtmlWindow *TestWin;
747
748 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
749 {
750 wxString choices[3] = {_("small"), _("medium"), _("large")};
751 wxBoxSizer *topsizer, *sizer, *sizer2;
752
753 topsizer = new wxBoxSizer(wxVERTICAL);
754
755 sizer = new wxBoxSizer(wxHORIZONTAL);
756
757 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL);
758 sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
759 wxSize(200, 200),
760 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
761 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
762
763 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
764
765 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL);
766 sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
767 wxSize(200, 200),
768 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
769 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
770
771 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
772
773 topsizer -> Add(sizer);
774
775 topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
776 wxDefaultPosition, wxDefaultSize, 3, choices, 3),
777 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
778
779 topsizer -> Add(new wxStaticText(this, -1, _("Preview:")),
780 0, wxLEFT | wxTOP, 10);
781 topsizer -> Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)),
782 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
783
784 sizer = new wxBoxSizer(wxHORIZONTAL);
785 sizer -> Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10);
786 sizer -> Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10);
787 topsizer -> Add(sizer, 0, wxALIGN_RIGHT);
788
789 SetAutoLayout(TRUE);
790 SetSizer(topsizer);
791 topsizer -> Fit(this);
792 Centre(wxBOTH);
793 }
794
795
796 void UpdateTestWin()
797 {
798 wxBusyCursor bcur;
799 SetFontsToHtmlWin(TestWin,
800 NormalFont -> GetStringSelection(),
801 FixedFont -> GetStringSelection(),
802 RadioBox -> GetSelection());
803 TestWin -> SetPage(_("<html><body>"
804 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
805 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
806 "<font size=-2>font size -2</font><br>"
807 "<font size=-1>font size -1</font><br>"
808 "<font size=+0>font size +0</font><br>"
809 "<font size=+1>font size +1</font><br>"
810 "<font size=+2>font size +2</font><br>"
811 "<font size=+3>font size +3</font><br>"
812 "<font size=+4>font size +4</font><br>"
813
814 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
815 "<b><i>bold italic <u>underlined</u></i></b><br>"
816 "<font size=-2>font size -2</font><br>"
817 "<font size=-1>font size -1</font><br>"
818 "<font size=+0>font size +0</font><br>"
819 "<font size=+1>font size +1</font><br>"
820 "<font size=+2>font size +2</font><br>"
821 "<font size=+3>font size +3</font><br>"
822 "<font size=+4>font size +4</font></tt>"
823 "</body></html>"));
824 }
825
826 void OnUpdate(wxCloseEvent& event)
827 {
828 UpdateTestWin();
829 }
830
831 DECLARE_EVENT_TABLE()
832 };
833
834 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
835 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
836 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
837 END_EVENT_TABLE()
838
839
840 void wxHtmlHelpFrame::OptionsDialog()
841 {
842 wxHtmlHelpFrameOptionsDialog dlg(this);
843 unsigned i;
844
845 if (m_NormalFonts == NULL) {
846 wxFontEnumerator enu;
847 enu.EnumerateFacenames();
848 m_NormalFonts = new wxArrayString;
849 *m_NormalFonts = *enu.GetFacenames();
850 m_NormalFonts -> Sort();
851 }
852 if (m_FixedFonts == NULL) {
853 wxFontEnumerator enu;
854 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);
855 m_FixedFonts = new wxArrayString;
856 *m_FixedFonts = *enu.GetFacenames();
857 m_FixedFonts -> Sort();
858 }
859
860 for (i = 0; i < m_NormalFonts -> GetCount(); i++)
861 dlg.NormalFont -> Append((*m_NormalFonts)[i]);
862 for (i = 0; i < m_FixedFonts -> GetCount(); i++)
863 dlg.FixedFont -> Append((*m_FixedFonts)[i]);
864 if (!m_NormalFace.IsEmpty()) dlg.NormalFont -> SetStringSelection(m_NormalFace);
865 else dlg.NormalFont -> SetSelection(0);
866 if (!m_FixedFace.IsEmpty()) dlg.FixedFont -> SetStringSelection(m_FixedFace);
867 else dlg.FixedFont -> SetSelection(0);
868 dlg.RadioBox -> SetSelection(m_FontSize);
869 dlg.UpdateTestWin();
870
871 if (dlg.ShowModal() == wxID_OK) {
872 m_NormalFace = dlg.NormalFont -> GetStringSelection();
873 m_FixedFace = dlg.FixedFont -> GetStringSelection();
874 m_FontSize = dlg.RadioBox -> GetSelection();
875 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
876 }
877 }
878
879
880
881
882
883 /*
884 EVENT HANDLING :
885 */
886
887
888 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
889 {
890 switch (event.GetId()) {
891
892 case wxID_HTML_BACK :
893 m_HtmlWin -> HistoryBack();
894 break;
895
896 case wxID_HTML_FORWARD :
897 m_HtmlWin -> HistoryForward();
898 break;
899
900 case wxID_HTML_PANEL :
901 if (! (m_Splitter && m_NavigPan))
902 return ;
903 if (m_Splitter -> IsSplit()) {
904 m_Cfg.sashpos = m_Splitter -> GetSashPosition();
905 m_Splitter -> Unsplit(m_NavigPan);
906 m_Cfg.navig_on = FALSE;
907 } else {
908 m_NavigPan -> Show(TRUE);
909 m_HtmlWin -> Show(TRUE);
910 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
911 m_Cfg.navig_on = TRUE;
912 }
913 break;
914
915 case wxID_HTML_OPTIONS :
916 OptionsDialog();
917 break;
918
919 case wxID_HTML_BOOKMARKSADD :
920 {
921 wxString item;
922 wxString url;
923
924 item = m_HtmlWin -> GetOpenedPageTitle();
925 url = m_HtmlWin -> GetOpenedPage();
926 if (item == wxEmptyString) item = url.AfterLast(wxT('/'));
927 if (m_BookmarksPages.Index(url) == wxNOT_FOUND) {
928 m_Bookmarks -> Append(item);
929 m_BookmarksNames.Add(item);
930 m_BookmarksPages.Add(url);
931 }
932 }
933 break;
934
935 case wxID_HTML_BOOKMARKSREMOVE :
936 {
937 wxString item;
938 int pos;
939
940 item = m_Bookmarks -> GetStringSelection();
941 pos = m_BookmarksNames.Index(item);
942 if (pos != wxNOT_FOUND) {
943 m_BookmarksNames.Remove(pos);
944 m_BookmarksPages.Remove(pos);
945 m_Bookmarks -> Delete(m_Bookmarks -> GetSelection());
946 }
947 }
948 break;
949 }
950 }
951
952
953
954 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
955 {
956 wxHtmlHelpTreeItemData *pg;
957
958 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
959 if (pg) m_HtmlWin -> LoadPage(pg -> GetPage());
960 }
961
962
963
964 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
965 {
966 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList -> GetClientData(m_IndexList -> GetSelection());
967 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
968 }
969
970
971 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
972 {
973 wxString sr = m_IndexText -> GetLineText(0);
974 sr.MakeLower();
975 if (sr == wxEmptyString)
976 OnIndexAll(event);
977
978 else {
979 wxBusyCursor bcur;
980 const wxChar *cstr = sr.c_str();
981 wxChar mybuff[512], *ptr;
982 bool first = TRUE;
983
984 m_IndexList->Clear();
985 int cnt = m_Data->GetIndexCnt();
986 wxHtmlContentsItem* index = m_Data->GetIndex();
987
988 int displ = 0;
989 for (int i = 0; i < cnt; i++)
990 {
991 wxStrncpy(mybuff, index[i].m_Name, 512);
992 mybuff[511] = 0;
993 for (ptr = mybuff; *ptr != 0; ptr++)
994 if (*ptr >= 'A' && *ptr <= 'Z') *ptr -= 'A' - 'a';
995 if (wxStrstr(mybuff, cstr) != NULL) {
996 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
997 displ++;
998 if (first) {
999 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
1000 first = FALSE;
1001 }
1002 }
1003 }
1004
1005 wxString cnttext;
1006 cnttext.Printf(_("%i of %i"), displ, cnt);
1007 m_IndexCountInfo -> SetLabel(cnttext);
1008
1009 m_IndexText -> SetSelection(0, sr.Length());
1010 m_IndexText -> SetFocus();
1011 }
1012 }
1013
1014 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1015 {
1016 wxBusyCursor bcur;
1017
1018 m_IndexList->Clear();
1019 int cnt = m_Data->GetIndexCnt();
1020 bool first = TRUE;
1021 wxHtmlContentsItem* index = m_Data->GetIndex();
1022
1023 for (int i = 0; i < cnt; i++) {
1024 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
1025 if (first) {
1026 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
1027 first = FALSE;
1028 }
1029 }
1030
1031 wxString cnttext;
1032 cnttext.Printf(_("%i of %i"), cnt, cnt);
1033 m_IndexCountInfo -> SetLabel(cnttext);
1034 }
1035
1036
1037 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
1038 {
1039 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
1040 if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1041 }
1042
1043 void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
1044 {
1045 wxString sr = m_SearchText -> GetLineText(0);
1046
1047 if (sr != wxEmptyString) KeywordSearch(sr);
1048 }
1049
1050 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1051 {
1052 wxString sr = m_Bookmarks -> GetStringSelection();
1053
1054 if (sr != wxEmptyString && sr != _("<bookmarks>"))
1055 m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
1056 }
1057
1058 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1059 {
1060 GetSize(&m_Cfg.w, &m_Cfg.h);
1061 GetPosition(&m_Cfg.x, &m_Cfg.y);
1062
1063 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1064
1065 if (m_Config)
1066 WriteCustomization(m_Config, m_ConfigRoot);
1067
1068 evt.Skip();
1069 }
1070
1071 BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
1072 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1073 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1074 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1075 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1076 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1077 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
1078 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1079 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1080 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
1081 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
1082 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
1083 END_EVENT_TABLE()
1084
1085 #endif