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