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