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