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