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