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