wxHtmlHelpController made compatible with other controllers
[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/html/helpctrl.h"
33 #include "wx/notebook.h"
34 #include "wx/imaglist.h"
35 #include "wx/treectrl.h"
36 #include "wx/tokenzr.h"
37 #include "wx/wfstream.h"
38 #include "wx/html/htmlwin.h"
39 #include "wx/busyinfo.h"
40 #include "wx/progdlg.h"
41 #include "wx/toolbar.h"
42 #include "wx/fontenum.h"
43 #include "wx/stream.h"
44 #include "wx/filedlg.h"
45
46 // Bitmaps:
47
48 #ifndef __WXMSW__
49 #include "bitmaps/wpanel.xpm"
50 #include "bitmaps/wback.xpm"
51 #include "bitmaps/wforward.xpm"
52 #include "bitmaps/wbook.xpm"
53 #include "bitmaps/woptions.xpm"
54 #include "bitmaps/wfolder.xpm"
55 #include "bitmaps/wpage.xpm"
56 #include "bitmaps/whelp.xpm"
57 #include "bitmaps/whlproot.xpm"
58 #include "bitmaps/wbkadd.xpm"
59 #include "bitmaps/wbkdel.xpm"
60 #include "bitmaps/wup.xpm"
61 #include "bitmaps/wupnode.xpm"
62 #include "bitmaps/wdown.xpm"
63 #include "bitmaps/wopen.xpm"
64 #include "bitmaps/wprint.xpm"
65 #endif
66
67
68 // what is considered "small index"?
69 #define INDEX_IS_SMALL 100
70
71
72 //--------------------------------------------------------------------------
73 // wxHtmlHelpTreeItemData (private)
74 //--------------------------------------------------------------------------
75
76 class wxHtmlHelpTreeItemData : public wxTreeItemData
77 {
78 public:
79 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
80 { m_Id = id;}
81
82 int m_Id;
83 };
84
85
86 //--------------------------------------------------------------------------
87 // wxHtmlHelpHashData (private)
88 //--------------------------------------------------------------------------
89
90 class wxHtmlHelpHashData : public wxObject
91 {
92 public:
93 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
94 { m_Index = index; m_Id = id;}
95
96 int m_Index;
97 wxTreeItemId m_Id;
98 };
99
100
101 //--------------------------------------------------------------------------
102 // wxHtmlHelpHtmlWindow (private)
103 //--------------------------------------------------------------------------
104
105 class wxHtmlHelpHtmlWindow : public wxHtmlWindow
106 {
107 public:
108 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent) : wxHtmlWindow(parent), m_Frame(fr) {}
109
110 virtual void OnLinkClicked(const wxHtmlLinkInfo& link)
111 {
112 wxHtmlWindow::OnLinkClicked(link);
113 m_Frame -> NotifyPageChanged();
114 }
115
116 private:
117 wxHtmlHelpFrame *m_Frame;
118 };
119
120
121
122 //---------------------------------------------------------------------------
123 // wxHtmlHelpFrame
124 //---------------------------------------------------------------------------
125
126 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
127
128 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
129 int style, wxHtmlHelpData* data)
130 {
131 Init(data);
132 Create(parent, id, title, style);
133 }
134
135 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
136 {
137 if (data) {
138 m_Data = data;
139 m_DataCreated = FALSE;
140 } else {
141 m_Data = new wxHtmlHelpData();
142 m_DataCreated = TRUE;
143 }
144
145 m_ContentsImageList = new wxImageList(16, 16);
146 m_ContentsImageList -> Add(wxICON(wbook));
147 m_ContentsImageList -> Add(wxICON(wfolder));
148 m_ContentsImageList -> Add(wxICON(wpage));
149 m_ContentsImageList -> Add(wxICON(whlproot));
150
151 m_ContentsBox = NULL;
152 m_IndexList = NULL;
153 m_IndexButton = NULL;
154 m_IndexButtonAll = NULL;
155 m_IndexText = NULL;
156 m_SearchList = NULL;
157 m_SearchButton = NULL;
158 m_SearchText = NULL;
159 m_SearchChoice = NULL;
160 m_IndexCountInfo = NULL;
161 m_Splitter = NULL;
162 m_NavigPan = NULL;
163 m_HtmlWin = NULL;
164 m_Bookmarks = NULL;
165 m_SearchCaseSensitive = NULL;
166 m_SearchWholeWords = NULL;
167
168 m_Config = NULL;
169 m_ConfigRoot = wxEmptyString;
170
171 m_Cfg.x = m_Cfg.y = 0;
172 m_Cfg.w = 700;
173 m_Cfg.h = 480;
174 m_Cfg.sashpos = 240;
175 m_Cfg.navig_on = TRUE;
176
177 m_NormalFonts = m_FixedFonts = NULL;
178 m_NormalFace = m_FixedFace = wxEmptyString;
179 m_FontSize = 1;
180
181 #if wxUSE_PRINTING_ARCHITECTURE
182 m_Printer = NULL;
183 #endif
184
185 m_PagesHash = NULL;
186 m_UpdateContents = TRUE;
187 m_helpController = (wxHelpControllerBase*) NULL;
188 }
189
190 // Create: builds the GUI components.
191 // with the style flag it's possible to toggle the toolbar, contents, index and search
192 // controls.
193 // m_HtmlWin will *always* be created, but it's important to realize that
194 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
195 // m_SearchButton may be NULL.
196 // moreover, if no contents, index or searchpage is needed, m_Splitter and
197 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
198
199 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title,
200 int style)
201 {
202 // Do the config in two steps. We read the HtmlWindow customization after we
203 // create the window.
204 if (m_Config)
205 ReadCustomization(m_Config, m_ConfigRoot);
206
207 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), wxDEFAULT_FRAME_STYLE, "wxHtmlHelp");
208
209 GetPosition(&m_Cfg.x, &m_Cfg.y);
210
211 SetIcon(wxICON(whelp));
212
213 int notebook_page = 0;
214
215 CreateStatusBar();
216
217 // toolbar?
218 if (style & wxHF_TOOLBAR) {
219 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE);
220 toolBar->SetMargins( 2, 2 );
221 AddToolbarButtons(toolBar, style);
222 toolBar -> Realize();
223 }
224
225 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) {
226 // traditional help controller; splitter window with html page on the
227 // right and a notebook containing various pages on the left
228 m_Splitter = new wxSplitterWindow(this);
229
230 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
231 m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK,
232 wxDefaultPosition, wxDefaultSize);
233 } else { // only html window, no notebook with index,contents etc
234 m_HtmlWin = new wxHtmlWindow(this);
235 }
236
237 m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat);
238 m_HtmlWin -> SetRelatedStatusBar(0);
239 if (m_Config)
240 m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
241
242 // contents tree panel?
243 if (style & wxHF_CONTENTS) {
244 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
245
246 if (style & wxHF_BOOKMARKS) {
247 wxLayoutConstraints *b1 = new wxLayoutConstraints;
248 wxBitmapButton *bmpbt = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxDefaultPosition, wxSize(20,20));
249
250 b1 -> top.SameAs (dummy, wxTop, 10);
251 b1 -> right.SameAs (dummy, wxRight, 10);
252 b1 -> height.AsIs();
253 b1 -> width.AsIs();
254 bmpbt -> SetConstraints(b1);
255
256 wxLayoutConstraints *b2 = new wxLayoutConstraints;
257 wxBitmapButton *bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxDefaultPosition, wxSize(20,20));
258
259 b2 -> top.SameAs (dummy, wxTop, 10);
260 b2 -> right.LeftOf (bmpbt, 2);
261 b2 -> height.AsIs();
262 b2 -> width.AsIs();
263 bmpbt2 -> SetConstraints(b2);
264
265 #if wxUSE_TOOLTIPS
266 bmpbt -> SetToolTip(_("Remove current page from bookmarks"));
267 bmpbt2 -> SetToolTip(_("Add current page to bookmarks"));
268 #endif //wxUSE_TOOLTIPS
269
270 wxLayoutConstraints *b3 = new wxLayoutConstraints;
271 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, wxEmptyString,
272 wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT);
273 m_Bookmarks -> Append(_("(bookmarks)"));
274 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
275 m_Bookmarks -> Append(m_BookmarksNames[i]);
276 m_Bookmarks -> SetSelection(0);
277
278 b3 -> centreY.SameAs (bmpbt2, wxCentreY);
279 b3 -> left.SameAs (dummy, wxLeft, 10);
280 b3 -> right.LeftOf (bmpbt2, 5);
281 b3 -> height.AsIs();
282 m_Bookmarks -> SetConstraints(b3);
283
284
285 wxLayoutConstraints *b4 = new wxLayoutConstraints;
286 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
287 wxDefaultPosition, wxDefaultSize,
288 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
289 m_ContentsBox -> SetImageList(m_ContentsImageList);
290
291 b4 -> top.Below (m_Bookmarks, 10);
292 b4 -> left.SameAs (dummy, wxLeft, 0);
293 b4 -> right.SameAs (dummy, wxRight, 0);
294 b4 -> bottom.SameAs (dummy, wxBottom, 0);
295 m_ContentsBox -> SetConstraints(b4);
296
297 dummy -> SetAutoLayout(TRUE);
298 dummy -> Layout();
299
300 m_NavigPan -> AddPage(dummy, _("Contents"));
301 }
302
303 else
304 {
305 m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL,
306 wxDefaultPosition, wxDefaultSize,
307 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
308 m_ContentsBox -> SetImageList(m_ContentsImageList);
309 m_NavigPan -> AddPage(m_ContentsBox, _("Contents"));
310 }
311
312 m_ContentsPage = notebook_page++;
313 }
314
315 // index listbox panel?
316 if (style & wxHF_INDEX) {
317 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
318
319 wxLayoutConstraints *b1 = new wxLayoutConstraints;
320 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
321 b1 -> top.SameAs (dummy, wxTop, 10);
322 b1 -> left.SameAs (dummy, wxLeft, 10);
323 b1 -> right.SameAs (dummy, wxRight, 10);
324 b1 -> height.AsIs();
325 m_IndexText -> SetConstraints(b1);
326
327 wxLayoutConstraints *b4 = new wxLayoutConstraints;
328 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, _("Show all"));
329
330 b4 -> top.Below (m_IndexText, 10);
331 b4 -> right.SameAs (dummy, wxRight, 10);
332 b4 -> width.AsIs();
333 b4 -> height.AsIs();
334 m_IndexButtonAll -> SetConstraints(b4);
335
336 wxLayoutConstraints *b2 = new wxLayoutConstraints;
337 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
338 b2 -> top.Below (m_IndexText, 10);
339 b2 -> right.LeftOf (m_IndexButtonAll, 10);
340 b2 -> width.AsIs();
341 b2 -> height.AsIs();
342 m_IndexButton -> SetConstraints(b2);
343
344 wxLayoutConstraints *b5 = new wxLayoutConstraints;
345 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
346
347 b5 -> top.Below (m_IndexButton, 5);
348 b5 -> right.SameAs (dummy, wxRight, 10);
349 b5 -> left.SameAs (dummy, wxLeft, 10);
350 b5 -> height.AsIs();
351 m_IndexCountInfo -> SetConstraints(b5);
352
353 wxLayoutConstraints *b3 = new wxLayoutConstraints;
354 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
355 b3 -> top.Below (m_IndexCountInfo, 5);
356 b3 -> left.SameAs (dummy, wxLeft, 0);
357 b3 -> right.SameAs (dummy, wxRight, 0);
358 b3 -> bottom.SameAs (dummy, wxBottom, 0);
359 m_IndexList -> SetConstraints(b3);
360
361 #if wxUSE_TOOLTIPS
362 m_IndexButtonAll -> SetToolTip(_("Show all items in index"));
363 m_IndexButton -> SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
364 #endif //wxUSE_TOOLTIPS
365
366 dummy -> SetAutoLayout(TRUE);
367 dummy -> Layout();
368
369 m_NavigPan -> AddPage(dummy, _("Index"));
370 m_IndexPage = notebook_page++;
371 }
372
373 // search list panel?
374 if (style & wxHF_SEARCH) {
375 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
376
377 wxLayoutConstraints *b1 = new wxLayoutConstraints;
378 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
379 b1 -> top.SameAs (dummy, wxTop, 10);
380 b1 -> left.SameAs (dummy, wxLeft, 10);
381 b1 -> right.SameAs (dummy, wxRight, 10);
382 b1 -> height.AsIs();
383 m_SearchText -> SetConstraints(b1);
384
385 wxLayoutConstraints *b4 = new wxLayoutConstraints;
386 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
387 wxDefaultSize);
388 b4 -> top.Below (m_SearchText, 10);
389 b4 -> left.SameAs (dummy, wxLeft, 10);
390 b4 -> right.SameAs (dummy, wxRight, 10);
391 b4 -> height.AsIs();
392 m_SearchChoice -> SetConstraints(b4);
393
394 wxLayoutConstraints *b5 = new wxLayoutConstraints;
395 m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive"));
396 b5 -> top.Below (m_SearchChoice, 10);
397 b5 -> left.SameAs (dummy, wxLeft, 10);
398 b5 -> width.AsIs();
399 b5 -> height.AsIs ();
400 m_SearchCaseSensitive -> SetConstraints(b5);
401
402 wxLayoutConstraints *b6 = new wxLayoutConstraints;
403 m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only"));
404 b6 -> top.Below (m_SearchCaseSensitive, 0);
405 b6 -> left.SameAs (dummy, wxLeft, 10);
406 b6 -> width.AsIs();
407 b6 -> height.AsIs ();
408 m_SearchWholeWords -> SetConstraints(b6);
409
410 wxLayoutConstraints *b2 = new wxLayoutConstraints;
411 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
412 #if wxUSE_TOOLTIPS
413 m_SearchButton -> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
414 #endif //wxUSE_TOOLTIPS
415 b2 -> top.Below (m_SearchWholeWords, 0);
416 b2 -> right.SameAs (dummy, wxRight, 10);
417 b2 -> width.AsIs();
418 b2 -> height.AsIs();
419 m_SearchButton -> SetConstraints(b2);
420
421 wxLayoutConstraints *b3 = new wxLayoutConstraints;
422 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
423 b3 -> top.Below (m_SearchButton, 10);
424 b3 -> left.SameAs (dummy, wxLeft, 0);
425 b3 -> right.SameAs (dummy, wxRight, 0);
426 b3 -> bottom.SameAs (dummy, wxBottom, 0);
427 m_SearchList -> SetConstraints(b3);
428
429 dummy -> SetAutoLayout(TRUE);
430 dummy -> Layout();
431 m_NavigPan -> AddPage(dummy, _("Search"));
432 m_SearchPage = notebook_page++;
433 }
434 m_HtmlWin -> Show(TRUE);
435
436 RefreshLists();
437
438 // showtime
439 if (m_NavigPan && m_Splitter) {
440 m_Splitter -> SetMinimumPaneSize(20);
441 if (m_Cfg.navig_on)
442 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
443 else {
444 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
445 m_Splitter -> Unsplit();
446 }
447 if (m_Cfg.navig_on) {
448 m_NavigPan -> Show(TRUE);
449 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
450 }
451 else {
452 m_NavigPan -> Show(FALSE);
453 m_Splitter -> Initialize(m_HtmlWin);
454 }
455 }
456 return TRUE;
457 }
458
459 wxHtmlHelpFrame::~wxHtmlHelpFrame()
460 {
461 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
462 delete m_ContentsImageList;
463 if (m_DataCreated)
464 delete m_Data;
465 if (m_NormalFonts) delete m_NormalFonts;
466 if (m_FixedFonts) delete m_FixedFonts;
467 if (m_PagesHash) delete m_PagesHash;
468 }
469
470
471 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style)
472 {
473 toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap,
474 FALSE, -1, -1, (wxObject *) NULL,
475 _("Show/hide navigation panel"));
476
477 toolBar -> AddSeparator();
478 toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap,
479 FALSE, -1, -1, (wxObject *) NULL,
480 _("Go back"));
481 toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap,
482 FALSE, -1, -1, (wxObject *) NULL,
483 _("Go forward"));
484 toolBar -> AddSeparator();
485
486 toolBar -> AddTool(wxID_HTML_UPNODE, wxBITMAP(wupnode), wxNullBitmap,
487 FALSE, -1, -1, (wxObject *) NULL,
488 _("Go one level up in document hierarchy"));
489 toolBar -> AddTool(wxID_HTML_UP, wxBITMAP(wup), wxNullBitmap,
490 FALSE, -1, -1, (wxObject *) NULL,
491 _("Previous page"));
492 toolBar -> AddTool(wxID_HTML_DOWN, wxBITMAP(wdown), wxNullBitmap,
493 FALSE, -1, -1, (wxObject *) NULL,
494 _("Next page"));
495
496 if ((style & wxHF_PRINT) || (style & wxHF_OPENFILES))
497 toolBar -> AddSeparator();
498
499 if (style & wxHF_OPENFILES)
500 toolBar -> AddTool(wxID_HTML_OPENFILE, wxBITMAP(wopen), wxNullBitmap,
501 FALSE, -1, -1, (wxObject *) NULL,
502 _("Open HTML document"));
503
504 #if wxUSE_PRINTING_ARCHITECTURE
505 if (style & wxHF_PRINT)
506 toolBar -> AddTool(wxID_HTML_PRINT, wxBITMAP(wprint), wxNullBitmap,
507 FALSE, -1, -1, (wxObject *) NULL,
508 _("Print this page"));
509 #endif
510
511 toolBar -> AddSeparator();
512 toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
513 FALSE, -1, -1, (wxObject *) NULL,
514 _("Display options dialog"));
515 }
516
517
518 void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
519 {
520 if (m_HtmlWin)
521 m_HtmlWin->SetRelatedFrame(this, format);
522 m_TitleFormat = format;
523 }
524
525
526 bool wxHtmlHelpFrame::Display(const wxString& x)
527 {
528 wxString url = m_Data->FindPageByName(x);
529 if (! url.IsEmpty()) {
530 m_HtmlWin->LoadPage(url);
531 NotifyPageChanged();
532 return TRUE;
533 }
534 return FALSE;
535 }
536
537 bool wxHtmlHelpFrame::Display(const int id)
538 {
539 wxString url = m_Data->FindPageById(id);
540 if (! url.IsEmpty()) {
541 m_HtmlWin->LoadPage(url);
542 NotifyPageChanged();
543 return TRUE;
544 }
545 return FALSE;
546 }
547
548
549
550 bool wxHtmlHelpFrame::DisplayContents()
551 {
552 if (! m_ContentsBox)
553 return FALSE;
554 if (!m_Splitter -> IsSplit()) {
555 m_NavigPan -> Show(TRUE);
556 m_HtmlWin -> Show(TRUE);
557 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
558 m_Cfg.navig_on = TRUE;
559 }
560 m_NavigPan -> SetSelection(0);
561 return TRUE;
562 }
563
564
565
566 bool wxHtmlHelpFrame::DisplayIndex()
567 {
568 if (! m_IndexList)
569 return FALSE;
570 if (!m_Splitter -> IsSplit()) {
571 m_NavigPan -> Show(TRUE);
572 m_HtmlWin -> Show(TRUE);
573 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
574 }
575 m_NavigPan -> SetSelection(1);
576 return TRUE;
577 }
578
579
580
581 bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
582 {
583 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
584 return FALSE;
585
586 int foundcnt = 0, curi;
587 wxString foundstr;
588 wxString book = wxEmptyString;
589
590 if (!m_Splitter -> IsSplit()) {
591 m_NavigPan -> Show(TRUE);
592 m_HtmlWin -> Show(TRUE);
593 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
594 }
595 m_NavigPan -> SetSelection(m_SearchPage);
596 m_SearchList -> Clear();
597 m_SearchText -> SetValue(keyword);
598 m_SearchButton -> Enable(FALSE);
599
600 if (m_SearchChoice->GetSelection() != 0)
601 book = m_SearchChoice->GetStringSelection();
602
603 wxHtmlSearchStatus status(m_Data, keyword,
604 m_SearchCaseSensitive -> GetValue(), m_SearchWholeWords -> GetValue(),
605 book);
606
607 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
608 status.GetMaxIndex(), this,
609 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
610
611 while (status.IsActive()) {
612 curi = status.GetCurIndex();
613 if (curi % 32 == 0 && progress.Update(curi) == FALSE)
614 break;
615 if (status.Search()) {
616 foundstr.Printf(_("Found %i matches"), ++foundcnt);
617 progress.Update(status.GetCurIndex(), foundstr);
618 m_SearchList -> Append(status.GetName(), status.GetContentsItem());
619 }
620 }
621
622 m_SearchButton -> Enable(TRUE);
623 m_SearchText -> SetSelection(0, keyword.Length());
624 m_SearchText -> SetFocus();
625 if (foundcnt) {
626 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0);
627 if (it)
628 {
629 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
630 NotifyPageChanged();
631 }
632 }
633 return (foundcnt > 0);
634 }
635
636 #define MAX_ROOTS 64
637
638 void wxHtmlHelpFrame::CreateContents()
639 {
640 if (! m_ContentsBox)
641 return ;
642
643 m_ContentsBox->Clear();
644
645 if (m_PagesHash) delete m_PagesHash;
646 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data -> GetContentsCnt());
647 m_PagesHash -> DeleteContents(TRUE);
648
649 int cnt = m_Data->GetContentsCnt();
650 int i;
651
652 wxHtmlContentsItem *it;
653
654 wxTreeItemId roots[MAX_ROOTS];
655 bool imaged[MAX_ROOTS];
656
657 m_ContentsBox -> DeleteAllItems();
658 roots[0] = m_ContentsBox -> AddRoot(_("(Help)"));
659 m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder);
660 m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder);
661 imaged[0] = TRUE;
662
663 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
664 roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
665 roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
666 new wxHtmlHelpTreeItemData(i));
667 m_PagesHash -> Put(it -> m_Book -> GetBasePath() + it -> m_Page,
668 new wxHtmlHelpHashData(i, roots[it -> m_Level + 1]));
669
670 if (it -> m_Level == 0) {
671 m_ContentsBox -> SetItemBold(roots[1], TRUE);
672 m_ContentsBox -> SetItemImage(roots[1], IMG_Book);
673 m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book);
674 imaged[1] = TRUE;
675 } else imaged[it -> m_Level + 1] = FALSE;
676
677 if (!imaged[it -> m_Level]) {
678 m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder);
679 m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder);
680 imaged[it -> m_Level] = TRUE;
681 }
682 }
683 m_ContentsBox -> Expand(roots[0]);
684 }
685
686
687 void wxHtmlHelpFrame::CreateIndex()
688 {
689 if (! m_IndexList)
690 return ;
691
692 m_IndexList->Clear();
693
694 int cnt = m_Data->GetIndexCnt();
695
696 wxString cnttext;
697 if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt);
698 else cnttext.Printf(_("%i of %i"), cnt, cnt);
699 m_IndexCountInfo -> SetLabel(cnttext);
700 if (cnt > INDEX_IS_SMALL) return;
701
702 wxHtmlContentsItem* index = m_Data->GetIndex();
703
704 for (int i = 0; i < cnt; i++)
705 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
706 }
707
708 void wxHtmlHelpFrame::CreateSearch()
709 {
710 if (! (m_SearchList && m_SearchChoice))
711 return ;
712 m_SearchList -> Clear();
713 m_SearchChoice -> Clear();
714 m_SearchChoice -> Append(_("Search in all books"));
715 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
716 int i, cnt = bookrec.GetCount();
717 for (i = 0; i < cnt; i++)
718 m_SearchChoice->Append(bookrec[i].GetTitle());
719 m_SearchChoice->SetSelection(0);
720 }
721
722
723 void wxHtmlHelpFrame::RefreshLists()
724 {
725 CreateContents();
726 CreateIndex();
727 CreateSearch();
728 }
729
730 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
731 {
732 wxString oldpath;
733 wxString tmp;
734
735 if (path != wxEmptyString) {
736 oldpath = cfg -> GetPath();
737 cfg -> SetPath(_T("/") + path);
738 }
739
740 m_Cfg.navig_on = cfg -> Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
741 m_Cfg.sashpos = cfg -> Read(wxT("hcSashPos"), m_Cfg.sashpos);
742 m_Cfg.x = cfg -> Read(wxT("hcX"), m_Cfg.x);
743 m_Cfg.y = cfg -> Read(wxT("hcY"), m_Cfg.y);
744 m_Cfg.w = cfg -> Read(wxT("hcW"), m_Cfg.w);
745 m_Cfg.h = cfg -> Read(wxT("hcH"), m_Cfg.h);
746
747 m_FixedFace = cfg -> Read(wxT("hcFixedFace"), m_FixedFace);
748 m_NormalFace = cfg -> Read(wxT("hcNormalFace"), m_NormalFace);
749 m_FontSize = cfg -> Read(wxT("hcFontSize"), m_FontSize);
750
751 {
752 int i;
753 int cnt;
754 wxString val, s;
755
756 cnt = cfg -> Read(wxT("hcBookmarksCnt"), 0L);
757 if (cnt != 0) {
758 m_BookmarksNames.Clear();
759 m_BookmarksPages.Clear();
760 if (m_Bookmarks) {
761 m_Bookmarks -> Clear();
762 m_Bookmarks -> Append(_("(bookmarks)"));
763 }
764
765 for (i = 0; i < cnt; i++) {
766 val.Printf(wxT("hcBookmark_%i"), i);
767 s = cfg -> Read(val);
768 m_BookmarksNames.Add(s);
769 if (m_Bookmarks) m_Bookmarks -> Append(s);
770 val.Printf(wxT("hcBookmark_%i_url"), i);
771 s = cfg -> Read(val);
772 m_BookmarksPages.Add(s);
773 }
774 }
775 }
776
777 if (m_HtmlWin)
778 m_HtmlWin->ReadCustomization(cfg);
779
780 if (path != wxEmptyString)
781 cfg -> SetPath(oldpath);
782 }
783
784 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
785 {
786 wxString oldpath;
787 wxString tmp;
788
789 if (path != wxEmptyString) {
790 oldpath = cfg -> GetPath();
791 cfg -> SetPath(_T("/") + path);
792 }
793
794 cfg -> Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
795 cfg -> Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
796 cfg -> Write(wxT("hcX"), (long)m_Cfg.x);
797 cfg -> Write(wxT("hcY"), (long)m_Cfg.y);
798 cfg -> Write(wxT("hcW"), (long)m_Cfg.w);
799 cfg -> Write(wxT("hcH"), (long)m_Cfg.h);
800 cfg -> Write(wxT("hcFixedFace"), m_FixedFace);
801 cfg -> Write(wxT("hcNormalFace"), m_NormalFace);
802 cfg -> Write(wxT("hcFontSize"), (long)m_FontSize);
803
804 if (m_Bookmarks) {
805 int i;
806 int cnt = m_BookmarksNames.GetCount();
807 wxString val;
808
809 cfg -> Write(wxT("hcBookmarksCnt"), (long)cnt);
810 for (i = 0; i < cnt; i++) {
811 val.Printf(wxT("hcBookmark_%i"), i);
812 cfg -> Write(val, m_BookmarksNames[i]);
813 val.Printf(wxT("hcBookmark_%i_url"), i);
814 cfg -> Write(val, m_BookmarksPages[i]);
815 }
816 }
817
818 if (m_HtmlWin)
819 m_HtmlWin->WriteCustomization(cfg);
820
821 if (path != wxEmptyString)
822 cfg -> SetPath(oldpath);
823 }
824
825
826
827
828
829 static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
830 {
831 static int f_sizes[5][7] =
832 {
833 { 6, 7, 9, 12, 14, 16, 19},
834 { 8, 9, 12, 14, 16, 19, 22},
835 {10, 12, 14, 16, 19, 24, 32},
836 {14, 16, 18, 24, 32, 38, 45},
837 {16, 20, 24, 32, 38, 45, 50}
838 };
839
840 win -> SetFonts(scalf, fixf, f_sizes[size]);
841 }
842
843
844 class wxHtmlHelpFrameOptionsDialog : public wxDialog
845 {
846 public:
847 wxComboBox *NormalFont, *FixedFont;
848 wxRadioBox *RadioBox;
849 wxHtmlWindow *TestWin;
850
851 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
852 {
853 wxString choices[5] = {_("very small"), _("small"), _("medium"), _("large"), _("very large")};
854 wxBoxSizer *topsizer, *sizer, *sizer2;
855
856 topsizer = new wxBoxSizer(wxVERTICAL);
857
858 sizer = new wxBoxSizer(wxHORIZONTAL);
859
860 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL);
861 sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
862 wxSize(200, 200),
863 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
864 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
865
866 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
867
868 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL);
869 sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
870 wxSize(200, 200),
871 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
872 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
873
874 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
875
876 topsizer -> Add(sizer);
877
878 topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
879 wxDefaultPosition, wxDefaultSize, 5, choices, 5),
880 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
881
882 topsizer -> Add(new wxStaticText(this, -1, _("Preview:")),
883 0, wxLEFT | wxTOP, 10);
884 topsizer -> Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)),
885 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
886
887 sizer = new wxBoxSizer(wxHORIZONTAL);
888 sizer -> Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10);
889 sizer -> Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10);
890 topsizer -> Add(sizer, 0, wxALIGN_RIGHT);
891
892 SetAutoLayout(TRUE);
893 SetSizer(topsizer);
894 topsizer -> Fit(this);
895 Centre(wxBOTH);
896 }
897
898
899 void UpdateTestWin()
900 {
901 wxBusyCursor bcur;
902 SetFontsToHtmlWin(TestWin,
903 NormalFont -> GetStringSelection(),
904 FixedFont -> GetStringSelection(),
905 RadioBox -> GetSelection());
906 TestWin -> SetPage(_("<html><body>"
907 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
908 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
909 "<font size=-2>font size -2</font><br>"
910 "<font size=-1>font size -1</font><br>"
911 "<font size=+0>font size +0</font><br>"
912 "<font size=+1>font size +1</font><br>"
913 "<font size=+2>font size +2</font><br>"
914 "<font size=+3>font size +3</font><br>"
915 "<font size=+4>font size +4</font><br>"
916
917 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
918 "<b><i>bold italic <u>underlined</u></i></b><br>"
919 "<font size=-2>font size -2</font><br>"
920 "<font size=-1>font size -1</font><br>"
921 "<font size=+0>font size +0</font><br>"
922 "<font size=+1>font size +1</font><br>"
923 "<font size=+2>font size +2</font><br>"
924 "<font size=+3>font size +3</font><br>"
925 "<font size=+4>font size +4</font></tt>"
926 "</body></html>"));
927 }
928
929 void OnUpdate(wxCommandEvent& event)
930 {
931 UpdateTestWin();
932 }
933
934 DECLARE_EVENT_TABLE()
935 };
936
937 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
938 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
939 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
940 END_EVENT_TABLE()
941
942
943 void wxHtmlHelpFrame::OptionsDialog()
944 {
945 wxHtmlHelpFrameOptionsDialog dlg(this);
946 unsigned i;
947
948 if (m_NormalFonts == NULL) {
949 wxFontEnumerator enu;
950 enu.EnumerateFacenames();
951 m_NormalFonts = new wxArrayString;
952 *m_NormalFonts = *enu.GetFacenames();
953 m_NormalFonts -> Sort();
954 }
955 if (m_FixedFonts == NULL) {
956 wxFontEnumerator enu;
957 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);
958 m_FixedFonts = new wxArrayString;
959 *m_FixedFonts = *enu.GetFacenames();
960 m_FixedFonts -> Sort();
961 }
962
963 for (i = 0; i < m_NormalFonts -> GetCount(); i++)
964 dlg.NormalFont -> Append((*m_NormalFonts)[i]);
965 for (i = 0; i < m_FixedFonts -> GetCount(); i++)
966 dlg.FixedFont -> Append((*m_FixedFonts)[i]);
967 if (!m_NormalFace.IsEmpty()) dlg.NormalFont -> SetStringSelection(m_NormalFace);
968 else dlg.NormalFont -> SetSelection(0);
969 if (!m_FixedFace.IsEmpty()) dlg.FixedFont -> SetStringSelection(m_FixedFace);
970 else dlg.FixedFont -> SetSelection(0);
971 dlg.RadioBox -> SetSelection(m_FontSize);
972 dlg.UpdateTestWin();
973
974 if (dlg.ShowModal() == wxID_OK) {
975 m_NormalFace = dlg.NormalFont -> GetStringSelection();
976 m_FixedFace = dlg.FixedFont -> GetStringSelection();
977 m_FontSize = dlg.RadioBox -> GetSelection();
978 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
979 }
980 }
981
982
983
984 void wxHtmlHelpFrame::NotifyPageChanged()
985 {
986 if (m_UpdateContents && m_PagesHash)
987 {
988 wxString an = m_HtmlWin -> GetOpenedAnchor();
989 wxHtmlHelpHashData *ha;
990 if (an.IsEmpty())
991 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
992 else
993 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
994 if (ha)
995 {
996 bool olduc = m_UpdateContents;
997 m_UpdateContents = FALSE;
998 m_ContentsBox -> SelectItem(ha -> m_Id);
999 m_ContentsBox -> EnsureVisible(ha -> m_Id);
1000 m_UpdateContents = olduc;
1001 }
1002 }
1003 }
1004
1005
1006
1007 /*
1008 EVENT HANDLING :
1009 */
1010
1011
1012 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
1013 {
1014 switch (event.GetId()) {
1015
1016 case wxID_HTML_BACK :
1017 m_HtmlWin -> HistoryBack();
1018 NotifyPageChanged();
1019 break;
1020
1021 case wxID_HTML_FORWARD :
1022 m_HtmlWin -> HistoryForward();
1023 NotifyPageChanged();
1024 break;
1025
1026 case wxID_HTML_UP :
1027 if (m_PagesHash)
1028 {
1029 wxString an = m_HtmlWin -> GetOpenedAnchor();
1030 wxHtmlHelpHashData *ha;
1031 if (an.IsEmpty())
1032 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
1033 else
1034 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
1035 if (ha && ha -> m_Index > 0)
1036 {
1037 wxHtmlContentsItem *it = m_Data -> GetContents() + (ha -> m_Index - 1);
1038 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1039 NotifyPageChanged();
1040 }
1041 }
1042 break;
1043
1044 case wxID_HTML_UPNODE :
1045 if (m_PagesHash)
1046 {
1047 wxString an = m_HtmlWin -> GetOpenedAnchor();
1048 wxHtmlHelpHashData *ha;
1049 if (an.IsEmpty())
1050 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
1051 else
1052 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
1053 if (ha && ha -> m_Index > 0)
1054 {
1055 int level = m_Data -> GetContents()[ha -> m_Index].m_Level - 1;
1056 wxHtmlContentsItem *it;
1057 int ind = ha -> m_Index - 1;
1058
1059 it = m_Data -> GetContents() + ind;
1060 while (ind >= 0 && it -> m_Level != level) ind--, it--;
1061 if (ind >= 0)
1062 {
1063 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1064 NotifyPageChanged();
1065 }
1066 }
1067 }
1068 break;
1069
1070 case wxID_HTML_DOWN :
1071 if (m_PagesHash)
1072 {
1073 wxString an = m_HtmlWin -> GetOpenedAnchor();
1074 wxString adr;
1075 wxHtmlHelpHashData *ha;
1076
1077 if (an.IsEmpty()) adr = m_HtmlWin -> GetOpenedPage();
1078 else adr = m_HtmlWin -> GetOpenedPage() + wxT("#") + an;
1079
1080 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(adr);
1081
1082 if (ha && ha -> m_Index < m_Data -> GetContentsCnt() - 1)
1083 {
1084 wxHtmlContentsItem *it = m_Data -> GetContents() + (ha -> m_Index + 1);
1085
1086 while (it -> m_Book -> GetBasePath() + it -> m_Page == adr) it++;
1087 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1088 NotifyPageChanged();
1089 }
1090 }
1091 break;
1092
1093 case wxID_HTML_PANEL :
1094 {
1095 if (! (m_Splitter && m_NavigPan))
1096 return ;
1097 if (m_Splitter -> IsSplit()) {
1098 m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1099 m_Splitter -> Unsplit(m_NavigPan);
1100 m_Cfg.navig_on = FALSE;
1101 } else {
1102 m_NavigPan -> Show(TRUE);
1103 m_HtmlWin -> Show(TRUE);
1104 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
1105 m_Cfg.navig_on = TRUE;
1106 }
1107 }
1108 break;
1109
1110 case wxID_HTML_OPTIONS :
1111 OptionsDialog();
1112 break;
1113
1114 case wxID_HTML_BOOKMARKSADD :
1115 {
1116 wxString item;
1117 wxString url;
1118
1119 item = m_HtmlWin -> GetOpenedPageTitle();
1120 url = m_HtmlWin -> GetOpenedPage();
1121 if (item == wxEmptyString) item = url.AfterLast(wxT('/'));
1122 if (m_BookmarksPages.Index(url) == wxNOT_FOUND) {
1123 m_Bookmarks -> Append(item);
1124 m_BookmarksNames.Add(item);
1125 m_BookmarksPages.Add(url);
1126 }
1127 }
1128 break;
1129
1130 case wxID_HTML_BOOKMARKSREMOVE :
1131 {
1132 wxString item;
1133 int pos;
1134
1135 item = m_Bookmarks -> GetStringSelection();
1136 pos = m_BookmarksNames.Index(item);
1137 if (pos != wxNOT_FOUND) {
1138 m_BookmarksNames.Remove(pos);
1139 m_BookmarksPages.Remove(pos);
1140 m_Bookmarks -> Delete(m_Bookmarks -> GetSelection());
1141 }
1142 }
1143 break;
1144
1145 #if wxUSE_PRINTING_ARCHITECTURE
1146 case wxID_HTML_PRINT :
1147 {
1148 if (m_Printer == NULL)
1149 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
1150 m_Printer -> PrintFile(m_HtmlWin -> GetOpenedPage());
1151 }
1152 break;
1153 #endif
1154
1155 case wxID_HTML_OPENFILE :
1156 {
1157 wxString s = wxFileSelector(_("Open HTML document"), wxEmptyString, wxEmptyString, wxEmptyString,
1158 wxT("HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|"
1159 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|"
1160 "HTML Help Project (*.hhp)|*.hhp|"
1161 "All files (*.*)|*"),
1162 wxOPEN | wxFILE_MUST_EXIST, this);
1163 if (!s.IsEmpty())
1164 {
1165 wxString ext = s.Right(4).Lower();
1166 if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp"))
1167 {
1168 wxBusyCursor bcur;
1169 m_Data -> AddBook(s);
1170 RefreshLists();
1171 }
1172 else
1173 m_HtmlWin -> LoadPage(s);
1174 }
1175 }
1176 break;
1177 }
1178 }
1179
1180
1181
1182 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
1183 {
1184 wxHtmlHelpTreeItemData *pg;
1185 wxHtmlContentsItem *it;
1186
1187 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
1188
1189 if (pg && m_UpdateContents)
1190 {
1191 it = m_Data -> GetContents() + (pg -> m_Id);
1192 m_UpdateContents = FALSE;
1193 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1194 m_UpdateContents = TRUE;
1195 }
1196 }
1197
1198
1199
1200 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
1201 {
1202 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList -> GetClientData(m_IndexList -> GetSelection());
1203 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1204 NotifyPageChanged();
1205 }
1206
1207
1208 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
1209 {
1210 wxString sr = m_IndexText -> GetLineText(0);
1211 sr.MakeLower();
1212 if (sr == wxEmptyString)
1213 OnIndexAll(event);
1214
1215 else {
1216 wxBusyCursor bcur;
1217 const wxChar *cstr = sr.c_str();
1218 wxChar mybuff[512], *ptr;
1219 bool first = TRUE;
1220
1221 m_IndexList->Clear();
1222 int cnt = m_Data->GetIndexCnt();
1223 wxHtmlContentsItem* index = m_Data->GetIndex();
1224
1225 int displ = 0;
1226 for (int i = 0; i < cnt; i++)
1227 {
1228 wxStrncpy(mybuff, index[i].m_Name, 512);
1229 mybuff[511] = 0;
1230 for (ptr = mybuff; *ptr != 0; ptr++)
1231 if (*ptr >= 'A' && *ptr <= 'Z') *ptr -= 'A' - 'a';
1232 if (wxStrstr(mybuff, cstr) != NULL) {
1233 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
1234 displ++;
1235 if (first) {
1236 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
1237 NotifyPageChanged();
1238 first = FALSE;
1239 }
1240 }
1241 }
1242
1243 wxString cnttext;
1244 cnttext.Printf(_("%i of %i"), displ, cnt);
1245 m_IndexCountInfo -> SetLabel(cnttext);
1246
1247 m_IndexText -> SetSelection(0, sr.Length());
1248 m_IndexText -> SetFocus();
1249 }
1250 }
1251
1252 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1253 {
1254 wxBusyCursor bcur;
1255
1256 m_IndexList->Clear();
1257 int cnt = m_Data->GetIndexCnt();
1258 bool first = TRUE;
1259 wxHtmlContentsItem* index = m_Data->GetIndex();
1260
1261 for (int i = 0; i < cnt; i++) {
1262 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
1263 if (first) {
1264 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
1265 NotifyPageChanged();
1266 first = FALSE;
1267 }
1268 }
1269
1270 wxString cnttext;
1271 cnttext.Printf(_("%i of %i"), cnt, cnt);
1272 m_IndexCountInfo -> SetLabel(cnttext);
1273 }
1274
1275
1276 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
1277 {
1278 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
1279 if (it)
1280 {
1281 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1282 NotifyPageChanged();
1283 }
1284 }
1285
1286 void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
1287 {
1288 wxString sr = m_SearchText -> GetLineText(0);
1289
1290 if (sr != wxEmptyString) KeywordSearch(sr);
1291 }
1292
1293 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1294 {
1295 wxString sr = m_Bookmarks -> GetStringSelection();
1296
1297 if (sr != wxEmptyString && sr != _("(bookmarks)"))
1298 {
1299 m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
1300 NotifyPageChanged();
1301 }
1302 }
1303
1304 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1305 {
1306 GetSize(&m_Cfg.w, &m_Cfg.h);
1307 GetPosition(&m_Cfg.x, &m_Cfg.y);
1308
1309 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1310
1311 if (m_Config)
1312 WriteCustomization(m_Config, m_ConfigRoot);
1313
1314 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
1315 {
1316 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
1317 }
1318
1319 evt.Skip();
1320 }
1321
1322 BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
1323 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar)
1324 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1325 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar)
1326 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1327 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1328 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1329 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1330 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
1331 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1332 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1333 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
1334 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
1335 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
1336 END_EVENT_TABLE()
1337
1338 #endif