renamed OnLinkClicked() event handler to avoid hiding the virtual function with the...
[wxWidgets.git] / src / html / helpwnd.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/helpwnd.cpp
3 // Purpose: wxHtmlHelpWindow
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 // For compilers that support precompilation, includes "wx.h"
13
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #if wxUSE_WXHTML_HELP
21
22 #ifndef WXPRECOMP
23 #include "wx/object.h"
24 #include "wx/dynarray.h"
25 #include "wx/intl.h"
26 #include "wx/log.h"
27 #if wxUSE_STREAMS
28 #include "wx/stream.h"
29 #endif
30
31 #include "wx/sizer.h"
32
33 #include "wx/bmpbuttn.h"
34 #include "wx/statbox.h"
35 #include "wx/radiobox.h"
36 #include "wx/menu.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
41 #include "wx/choicdlg.h"
42 #include "wx/filedlg.h"
43 #endif // WXPRECOMP
44
45 #include "wx/html/helpfrm.h"
46 #include "wx/html/helpdlg.h"
47 #include "wx/html/helpctrl.h"
48 #include "wx/notebook.h"
49 #include "wx/imaglist.h"
50 #include "wx/treectrl.h"
51 #include "wx/tokenzr.h"
52 #include "wx/wfstream.h"
53 #include "wx/html/htmlwin.h"
54 #include "wx/busyinfo.h"
55 #include "wx/progdlg.h"
56 #include "wx/fontenum.h"
57 #include "wx/artprov.h"
58 #include "wx/spinctrl.h"
59
60 // what is considered "small index"?
61 #define INDEX_IS_SMALL 100
62
63 /* Motif defines this as a macro */
64 #ifdef Below
65 #undef Below
66 #endif
67
68 //--------------------------------------------------------------------------
69 // wxHtmlHelpTreeItemData (private)
70 //--------------------------------------------------------------------------
71
72 class wxHtmlHelpTreeItemData : public wxTreeItemData
73 {
74 public:
75 #if defined(__VISAGECPP__)
76 // VA needs a default ctor for some reason....
77 wxHtmlHelpTreeItemData() : wxTreeItemData()
78 { m_Id = 0; }
79 #endif
80 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
81 { m_Id = id;}
82
83 int m_Id;
84 };
85
86
87 //--------------------------------------------------------------------------
88 // wxHtmlHelpHashData (private)
89 //--------------------------------------------------------------------------
90
91 class wxHtmlHelpHashData : public wxObject
92 {
93 public:
94 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
95 { m_Index = index; m_Id = id;}
96 virtual ~wxHtmlHelpHashData() {}
97
98 int m_Index;
99 wxTreeItemId m_Id;
100 };
101
102
103 //--------------------------------------------------------------------------
104 // wxHtmlHelpHtmlWindow (private)
105 //--------------------------------------------------------------------------
106
107
108 class wxHtmlHelpHtmlWindow : public wxHtmlWindow
109 {
110 public:
111 wxHtmlHelpHtmlWindow(wxHtmlHelpWindow *win, wxWindow *parent)
112 : wxHtmlWindow(parent), m_Window(win)
113 {
114 SetStandardFonts();
115 }
116
117 void OnLink(wxHtmlLinkEvent& ev)
118 {
119 const wxMouseEvent *e = ev.GetLinkInfo().GetEvent();
120 if (e == NULL || e->LeftUp())
121 m_Window->NotifyPageChanged();
122 }
123
124 // Returns full location with anchor (helper)
125 static wxString GetOpenedPageWithAnchor(wxHtmlWindow *win)
126 {
127 if(!win)
128 return wxEmptyString;
129
130 wxString an = win->GetOpenedAnchor();
131 wxString pg = win->GetOpenedPage();
132 if(!an.empty())
133 {
134 pg << wxT("#") << an;
135 }
136 return pg;
137 }
138
139 private:
140 wxHtmlHelpWindow *m_Window;
141
142 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow)
143 DECLARE_EVENT_TABLE()
144 };
145
146 BEGIN_EVENT_TABLE(wxHtmlHelpHtmlWindow, wxHtmlWindow)
147 EVT_HTML_LINK_CLICKED(wxID_ANY, wxHtmlHelpHtmlWindow::OnLink)
148 END_EVENT_TABLE()
149
150
151 //---------------------------------------------------------------------------
152 // wxHtmlHelpWindow::m_mergedIndex
153 //---------------------------------------------------------------------------
154
155 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem*, wxHtmlHelpDataItemPtrArray);
156
157 struct wxHtmlHelpMergedIndexItem
158 {
159 wxHtmlHelpMergedIndexItem *parent;
160 wxString name;
161 wxHtmlHelpDataItemPtrArray items;
162 };
163
164 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem, wxHtmlHelpMergedIndex);
165 #include "wx/arrimpl.cpp"
166 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex)
167
168 void wxHtmlHelpWindow::UpdateMergedIndex()
169 {
170 delete m_mergedIndex;
171 m_mergedIndex = new wxHtmlHelpMergedIndex;
172 wxHtmlHelpMergedIndex& merged = *m_mergedIndex;
173
174 const wxHtmlHelpDataItems& items = m_Data->GetIndexArray();
175 size_t len = items.size();
176
177 wxHtmlHelpMergedIndexItem *history[128] = {NULL};
178
179 for (size_t i = 0; i < len; i++)
180 {
181 const wxHtmlHelpDataItem& item = items[i];
182 wxASSERT_MSG( item.level < 128, _T("nested index entries too deep") );
183
184 if (history[item.level] &&
185 history[item.level]->items[0]->name == item.name)
186 {
187 // same index entry as previous one, update list of items
188 history[item.level]->items.Add(&item);
189 }
190 else
191 {
192 // new index entry
193 wxHtmlHelpMergedIndexItem *mi = new wxHtmlHelpMergedIndexItem();
194 mi->name = item.GetIndentedName();
195 mi->items.Add(&item);
196 mi->parent = (item.level == 0) ? NULL : history[item.level - 1];
197 history[item.level] = mi;
198 merged.Add(mi);
199 }
200 }
201 }
202
203 //---------------------------------------------------------------------------
204 // wxHtmlHelpWindow
205 //---------------------------------------------------------------------------
206
207 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow, wxWindow)
208
209 BEGIN_EVENT_TABLE(wxHtmlHelpWindow, wxWindow)
210 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpWindow::OnToolbar)
211 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpWindow::OnToolbar)
212 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpWindow::OnToolbar)
213 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpWindow::OnContentsSel)
214 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpWindow::OnIndexSel)
215 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpWindow::OnSearchSel)
216 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpWindow::OnSearch)
217 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpWindow::OnSearch)
218 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpWindow::OnIndexFind)
219 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpWindow::OnIndexFind)
220 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpWindow::OnIndexAll)
221 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpWindow::OnBookmarksSel)
222 EVT_SIZE(wxHtmlHelpWindow::OnSize)
223 END_EVENT_TABLE()
224
225 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow* parent, wxWindowID id,
226 const wxPoint& pos,
227 const wxSize& size,
228 int style, int helpStyle, wxHtmlHelpData* data)
229 {
230 Init(data);
231 Create(parent, id, pos, size, style, helpStyle);
232 }
233
234 void wxHtmlHelpWindow::Init(wxHtmlHelpData* data)
235 {
236 if (data)
237 {
238 m_Data = data;
239 m_DataCreated = false;
240 }
241 else
242 {
243 m_Data = new wxHtmlHelpData();
244 m_DataCreated = true;
245 }
246
247 m_ContentsPage = 0;
248 m_IndexPage = 0;
249 m_SearchPage = 0;
250
251 m_ContentsBox = NULL;
252 m_IndexList = NULL;
253 m_IndexButton = NULL;
254 m_IndexButtonAll = NULL;
255 m_IndexText = NULL;
256 m_SearchList = NULL;
257 m_SearchButton = NULL;
258 m_SearchText = NULL;
259 m_SearchChoice = NULL;
260 m_IndexCountInfo = NULL;
261 m_Splitter = NULL;
262 m_NavigPan = NULL;
263 m_NavigNotebook = NULL;
264 m_HtmlWin = NULL;
265 m_Bookmarks = NULL;
266 m_SearchCaseSensitive = NULL;
267 m_SearchWholeWords = NULL;
268
269 m_mergedIndex = NULL;
270
271 m_Config = NULL;
272 m_ConfigRoot = wxEmptyString;
273
274 m_Cfg.x = m_Cfg.y = wxDefaultCoord;
275 m_Cfg.w = 700;
276 m_Cfg.h = 480;
277 m_Cfg.sashpos = 240;
278 m_Cfg.navig_on = true;
279
280 m_NormalFonts = m_FixedFonts = NULL;
281 m_NormalFace = m_FixedFace = wxEmptyString;
282 #ifdef __WXMSW__
283 m_FontSize = 10;
284 #else
285 m_FontSize = 14;
286 #endif
287
288 #if wxUSE_PRINTING_ARCHITECTURE
289 m_Printer = NULL;
290 #endif
291
292 m_PagesHash = NULL;
293 m_UpdateContents = true;
294 m_toolBar = NULL;
295 m_helpController = (wxHtmlHelpController*) NULL;
296 }
297
298 // Create: builds the GUI components.
299 // with the style flag it's possible to toggle the toolbar, contents, index and search
300 // controls.
301 // m_HtmlWin will *always* be created, but it's important to realize that
302 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
303 // m_SearchButton may be NULL.
304 // moreover, if no contents, index or searchpage is needed, m_Splitter and
305 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
306
307 bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
308 const wxPoint& pos, const wxSize& size,
309 int style, int helpStyle)
310 {
311 m_hfStyle = helpStyle;
312
313 wxImageList *ContentsImageList = new wxImageList(16, 16);
314 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK,
315 wxART_HELP_BROWSER,
316 wxSize(16, 16)));
317 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER,
318 wxART_HELP_BROWSER,
319 wxSize(16, 16)));
320 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE,
321 wxART_HELP_BROWSER,
322 wxSize(16, 16)));
323
324 // Do the config in two steps. We read the HtmlWindow customization after we
325 // create the window.
326 if (m_Config)
327 ReadCustomization(m_Config, m_ConfigRoot);
328
329 wxWindow::Create(parent, id, pos, size, style, wxT("wxHtmlHelp"));
330
331 SetHelpText(_("Displays help as you browse the books on the left."));
332
333 GetPosition(&m_Cfg.x, &m_Cfg.y);
334
335 int notebook_page = 0;
336
337 // The sizer for the whole top-level window.
338 wxSizer *topWindowSizer = new wxBoxSizer(wxVERTICAL);
339 SetSizer(topWindowSizer);
340 SetAutoLayout(true);
341
342 #if wxUSE_TOOLBAR
343 // toolbar?
344 if (helpStyle & (wxHF_TOOLBAR | wxHF_FLAT_TOOLBAR))
345 {
346 wxToolBar *toolBar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
347 wxNO_BORDER | wxTB_HORIZONTAL |
348 wxTB_DOCKABLE | wxTB_NODIVIDER |
349 (helpStyle & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0));
350 toolBar->SetMargins( 2, 2 );
351 AddToolbarButtons(toolBar, helpStyle);
352 toolBar->Realize();
353 topWindowSizer->Add(toolBar, 0, wxEXPAND);
354 m_toolBar = toolBar;
355 }
356 #endif //wxUSE_TOOLBAR
357
358 wxSizer *navigSizer = NULL;
359
360 if (helpStyle & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH))
361 {
362 // traditional help controller; splitter window with html page on the
363 // right and a notebook containing various pages on the left
364 m_Splitter = new wxSplitterWindow(this);
365
366 topWindowSizer->Add(m_Splitter, 1, wxEXPAND);
367
368 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
369 m_NavigPan = new wxPanel(m_Splitter, wxID_ANY);
370 m_NavigNotebook = new wxNotebook(m_NavigPan, wxID_HTML_NOTEBOOK,
371 wxDefaultPosition, wxDefaultSize);
372
373 navigSizer = new wxBoxSizer(wxVERTICAL);
374 navigSizer->Add(m_NavigNotebook, 1, wxEXPAND);
375
376 m_NavigPan->SetSizer(navigSizer);
377 }
378 else
379 {
380 // only html window, no notebook with index,contents etc
381 m_HtmlWin = new wxHtmlWindow(this);
382 topWindowSizer->Add(m_HtmlWin, 1, wxEXPAND);
383 }
384
385 if ( m_Config )
386 m_HtmlWin->ReadCustomization(m_Config, m_ConfigRoot);
387
388 // contents tree panel?
389 if ( helpStyle & wxHF_CONTENTS )
390 {
391 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
392 wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
393
394 topsizer->Add(0, 10);
395
396 dummy->SetSizer(topsizer);
397
398 if ( helpStyle & wxHF_BOOKMARKS )
399 {
400 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST,
401 wxEmptyString,
402 wxDefaultPosition, wxDefaultSize,
403 0, NULL, wxCB_READONLY | wxCB_SORT);
404 m_Bookmarks->Append(_("(bookmarks)"));
405 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
406 m_Bookmarks->Append(m_BookmarksNames[i]);
407 m_Bookmarks->SetSelection(0);
408
409 wxBitmapButton *bmpbt1, *bmpbt2;
410 bmpbt1 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD,
411 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK,
412 wxART_BUTTON));
413 bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE,
414 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK,
415 wxART_BUTTON));
416 #if wxUSE_TOOLTIPS
417 bmpbt1->SetToolTip(_("Add current page to bookmarks"));
418 bmpbt2->SetToolTip(_("Remove current page from bookmarks"));
419 #endif // wxUSE_TOOLTIPS
420
421 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
422
423 sizer->Add(m_Bookmarks, 1, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5);
424 sizer->Add(bmpbt1, 0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 2);
425 sizer->Add(bmpbt2, 0, wxALIGN_CENTRE_VERTICAL, 0);
426
427 topsizer->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 10);
428 }
429
430 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
431 wxDefaultPosition, wxDefaultSize,
432 #ifdef __WXGTK20__
433 wxSUNKEN_BORDER |
434 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT |
435 wxTR_NO_LINES
436 #else
437 wxSUNKEN_BORDER |
438 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT |
439 wxTR_LINES_AT_ROOT
440 #endif
441 );
442
443 m_ContentsBox->AssignImageList(ContentsImageList);
444
445 topsizer->Add(m_ContentsBox, 1,
446 wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT,
447 2);
448
449 m_NavigNotebook->AddPage(dummy, _("Contents"));
450 m_ContentsPage = notebook_page++;
451 }
452
453 // index listbox panel?
454 if ( helpStyle & wxHF_INDEX )
455 {
456 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
457 wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
458
459 dummy->SetSizer(topsizer);
460
461 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString,
462 wxDefaultPosition, wxDefaultSize,
463 wxTE_PROCESS_ENTER);
464 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
465 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL,
466 _("Show all"));
467 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO,
468 wxEmptyString, wxDefaultPosition,
469 wxDefaultSize,
470 wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
471 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST,
472 wxDefaultPosition, wxDefaultSize,
473 0, NULL, wxLB_SINGLE);
474
475 #if wxUSE_TOOLTIPS
476 m_IndexButton->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
477 m_IndexButtonAll->SetToolTip(_("Show all items in index"));
478 #endif //wxUSE_TOOLTIPS
479
480 topsizer->Add(m_IndexText, 0, wxEXPAND | wxALL, 10);
481 wxSizer *btsizer = new wxBoxSizer(wxHORIZONTAL);
482 btsizer->Add(m_IndexButton, 0, wxRIGHT, 2);
483 btsizer->Add(m_IndexButtonAll);
484 topsizer->Add(btsizer, 0,
485 wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 10);
486 topsizer->Add(m_IndexCountInfo, 0, wxEXPAND | wxLEFT | wxRIGHT, 2);
487 topsizer->Add(m_IndexList, 1, wxEXPAND | wxALL, 2);
488
489 m_NavigNotebook->AddPage(dummy, _("Index"));
490 m_IndexPage = notebook_page++;
491 }
492
493 // search list panel?
494 if ( helpStyle & wxHF_SEARCH )
495 {
496 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
497 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
498
499 dummy->SetSizer(sizer);
500
501 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT,
502 wxEmptyString,
503 wxDefaultPosition, wxDefaultSize,
504 wxTE_PROCESS_ENTER);
505 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE,
506 wxDefaultPosition, wxSize(125,wxDefaultCoord));
507 m_SearchCaseSensitive = new wxCheckBox(dummy, wxID_ANY, _("Case sensitive"));
508 m_SearchWholeWords = new wxCheckBox(dummy, wxID_ANY, _("Whole words only"));
509 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
510 #if wxUSE_TOOLTIPS
511 m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
512 #endif //wxUSE_TOOLTIPS
513 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST,
514 wxDefaultPosition, wxDefaultSize,
515 0, NULL, wxLB_SINGLE);
516
517 sizer->Add(m_SearchText, 0, wxEXPAND | wxALL, 10);
518 sizer->Add(m_SearchChoice, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
519 sizer->Add(m_SearchCaseSensitive, 0, wxLEFT | wxRIGHT, 10);
520 sizer->Add(m_SearchWholeWords, 0, wxLEFT | wxRIGHT, 10);
521 sizer->Add(m_SearchButton, 0, wxALL | wxALIGN_RIGHT, 8);
522 sizer->Add(m_SearchList, 1, wxALL | wxEXPAND, 2);
523
524 m_NavigNotebook->AddPage(dummy, _("Search"));
525 m_SearchPage = notebook_page;
526 }
527
528 m_HtmlWin->Show();
529
530 RefreshLists();
531
532 if ( navigSizer )
533 {
534 navigSizer->SetSizeHints(m_NavigPan);
535 m_NavigPan->Layout();
536 }
537
538 // showtime
539 if ( m_NavigPan && m_Splitter )
540 {
541 m_Splitter->SetMinimumPaneSize(20);
542 if ( m_Cfg.navig_on )
543 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
544
545 if ( m_Cfg.navig_on )
546 {
547 m_NavigPan->Show();
548 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
549 }
550 else
551 {
552 m_NavigPan->Show(false);
553 m_Splitter->Initialize(m_HtmlWin);
554 }
555 }
556
557 // Reduce flicker by updating the splitter pane sizes before the
558 // frame is shown
559 wxSizeEvent sizeEvent(GetSize(), GetId());
560 ProcessEvent(sizeEvent);
561
562 if (m_Splitter)
563 m_Splitter->UpdateSize();
564
565 return true;
566 }
567
568 wxHtmlHelpWindow::~wxHtmlHelpWindow()
569 {
570 delete m_mergedIndex;
571
572 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
573 if (m_DataCreated)
574 delete m_Data;
575 if (m_NormalFonts) delete m_NormalFonts;
576 if (m_FixedFonts) delete m_FixedFonts;
577 if (m_PagesHash)
578 {
579 WX_CLEAR_HASH_TABLE(*m_PagesHash);
580 delete m_PagesHash;
581 }
582 #if wxUSE_PRINTING_ARCHITECTURE
583 if (m_Printer) delete m_Printer;
584 #endif
585 }
586
587 void wxHtmlHelpWindow::SetController(wxHtmlHelpController* controller)
588 {
589 if (m_DataCreated)
590 delete m_Data;
591 m_helpController = controller;
592 m_Data = controller->GetHelpData();
593 m_DataCreated = false;
594 }
595
596 #if wxUSE_TOOLBAR
597 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar *toolBar, int style)
598 {
599 wxBitmap wpanelBitmap =
600 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL, wxART_TOOLBAR);
601 wxBitmap wbackBitmap =
602 wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_TOOLBAR);
603 wxBitmap wforwardBitmap =
604 wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_TOOLBAR);
605 wxBitmap wupnodeBitmap =
606 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_TOOLBAR);
607 wxBitmap wupBitmap =
608 wxArtProvider::GetBitmap(wxART_GO_UP, wxART_TOOLBAR);
609 wxBitmap wdownBitmap =
610 wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_TOOLBAR);
611 wxBitmap wopenBitmap =
612 wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_TOOLBAR);
613 wxBitmap wprintBitmap =
614 wxArtProvider::GetBitmap(wxART_PRINT, wxART_TOOLBAR);
615 wxBitmap woptionsBitmap =
616 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS, wxART_TOOLBAR);
617
618 wxASSERT_MSG( (wpanelBitmap.Ok() && wbackBitmap.Ok() &&
619 wforwardBitmap.Ok() && wupnodeBitmap.Ok() &&
620 wupBitmap.Ok() && wdownBitmap.Ok() &&
621 wopenBitmap.Ok() && wprintBitmap.Ok() &&
622 woptionsBitmap.Ok()),
623 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
624
625
626 toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap,
627 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
628 _("Show/hide navigation panel"));
629
630 toolBar->AddSeparator();
631 toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap,
632 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
633 _("Go back"));
634 toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap,
635 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
636 _("Go forward"));
637 toolBar->AddSeparator();
638
639 toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap,
640 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
641 _("Go one level up in document hierarchy"));
642 toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap,
643 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
644 _("Previous page"));
645 toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap,
646 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
647 _("Next page"));
648
649 if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES))
650 toolBar->AddSeparator();
651
652 if (style & wxHF_OPEN_FILES)
653 toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap,
654 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
655 _("Open HTML document"));
656
657 #if wxUSE_PRINTING_ARCHITECTURE
658 if (style & wxHF_PRINT)
659 toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap,
660 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
661 _("Print this page"));
662 #endif
663
664 toolBar->AddSeparator();
665 toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap,
666 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
667 _("Display options dialog"));
668
669 // Allow application to add custom buttons
670 wxHtmlHelpFrame* parentFrame = wxDynamicCast(GetParent(), wxHtmlHelpFrame);
671 wxHtmlHelpDialog* parentDialog = wxDynamicCast(GetParent(), wxHtmlHelpDialog);
672 if (parentFrame)
673 parentFrame->AddToolbarButtons(toolBar, style);
674 if (parentDialog)
675 parentDialog->AddToolbarButtons(toolBar, style);
676 }
677 #endif //wxUSE_TOOLBAR
678
679
680 bool wxHtmlHelpWindow::Display(const wxString& x)
681 {
682 wxString url = m_Data->FindPageByName(x);
683 if (!url.empty())
684 {
685 m_HtmlWin->LoadPage(url);
686 NotifyPageChanged();
687 return true;
688 }
689
690 return false;
691 }
692
693 bool wxHtmlHelpWindow::Display(const int id)
694 {
695 wxString url = m_Data->FindPageById(id);
696 if (!url.empty())
697 {
698 m_HtmlWin->LoadPage(url);
699 NotifyPageChanged();
700 return true;
701 }
702
703 return false;
704 }
705
706 bool wxHtmlHelpWindow::DisplayContents()
707 {
708 if (! m_ContentsBox)
709 return false;
710
711 if (!m_Splitter->IsSplit())
712 {
713 m_NavigPan->Show();
714 m_HtmlWin->Show();
715 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
716 m_Cfg.navig_on = true;
717 }
718
719 m_NavigNotebook->SetSelection(m_ContentsPage);
720
721 if (m_Data->GetBookRecArray().GetCount() > 0)
722 {
723 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
724 if (!book.GetStart().empty())
725 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
726 }
727
728 return true;
729 }
730
731 bool wxHtmlHelpWindow::DisplayIndex()
732 {
733 if (! m_IndexList)
734 return false;
735
736 if (!m_Splitter->IsSplit())
737 {
738 m_NavigPan->Show();
739 m_HtmlWin->Show();
740 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
741 }
742
743 m_NavigNotebook->SetSelection(m_IndexPage);
744
745 if (m_Data->GetBookRecArray().GetCount() > 0)
746 {
747 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
748 if (!book.GetStart().empty())
749 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
750 }
751
752 return true;
753 }
754
755 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it)
756 {
757 if (it->items.size() == 1)
758 {
759 if (!it->items[0]->page.empty())
760 {
761 m_HtmlWin->LoadPage(it->items[0]->GetFullPath());
762 NotifyPageChanged();
763 }
764 }
765 else
766 {
767 wxBusyCursor busy_cursor;
768
769 // more pages associated with this index item -- let the user choose
770 // which one she/he wants from a list:
771 wxArrayString arr;
772 size_t len = it->items.size();
773 for (size_t i = 0; i < len; i++)
774 {
775 wxString page = it->items[i]->page;
776 // try to find page's title in contents:
777 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
778 size_t clen = contents.size();
779 for (size_t j = 0; j < clen; j++)
780 {
781 if (contents[j].page == page)
782 {
783 page = contents[j].name;
784 break;
785 }
786 }
787 arr.push_back(page);
788 }
789
790 wxSingleChoiceDialog dlg(this,
791 _("Please choose the page to display:"),
792 _("Help Topics"),
793 arr, NULL, wxCHOICEDLG_STYLE & ~wxCENTRE);
794 if (dlg.ShowModal() == wxID_OK)
795 {
796 m_HtmlWin->LoadPage(it->items[dlg.GetSelection()]->GetFullPath());
797 NotifyPageChanged();
798 }
799 }
800 }
801
802 bool wxHtmlHelpWindow::KeywordSearch(const wxString& keyword,
803 wxHelpSearchMode mode)
804 {
805 if (mode == wxHELP_SEARCH_ALL)
806 {
807 if ( !(m_SearchList &&
808 m_SearchButton && m_SearchText && m_SearchChoice) )
809 return false;
810 }
811 else if (mode == wxHELP_SEARCH_INDEX)
812 {
813 if ( !(m_IndexList &&
814 m_IndexButton && m_IndexButtonAll && m_IndexText) )
815 return false;
816 }
817
818 int foundcnt = 0;
819 wxString foundstr;
820 wxString book = wxEmptyString;
821
822 if (!m_Splitter->IsSplit())
823 {
824 m_NavigPan->Show();
825 m_HtmlWin->Show();
826 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
827 }
828
829 if (mode == wxHELP_SEARCH_ALL)
830 {
831 m_NavigNotebook->SetSelection(m_SearchPage);
832 m_SearchList->Clear();
833 m_SearchText->SetValue(keyword);
834 m_SearchButton->Disable();
835
836 if (m_SearchChoice->GetSelection() != 0)
837 book = m_SearchChoice->GetStringSelection();
838
839 wxHtmlSearchStatus status(m_Data, keyword,
840 m_SearchCaseSensitive->GetValue(),
841 m_SearchWholeWords->GetValue(),
842 book);
843
844 #if wxUSE_PROGRESSDLG
845 wxProgressDialog progress(_("Searching..."),
846 _("No matching page found yet"),
847 status.GetMaxIndex(), this,
848 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
849 #endif
850
851 int curi;
852 while (status.IsActive())
853 {
854 curi = status.GetCurIndex();
855 if (curi % 32 == 0
856 #if wxUSE_PROGRESSDLG
857 && !progress.Update(curi)
858 #endif
859 )
860 break;
861 if (status.Search())
862 {
863 foundstr.Printf(_("Found %i matches"), ++foundcnt);
864 #if wxUSE_PROGRESSDLG
865 progress.Update(status.GetCurIndex(), foundstr);
866 #endif
867 m_SearchList->Append(status.GetName(), (void*)status.GetCurItem());
868 }
869 }
870
871 m_SearchButton->Enable();
872 m_SearchText->SetSelection(0, keyword.length());
873 m_SearchText->SetFocus();
874 }
875 else if (mode == wxHELP_SEARCH_INDEX)
876 {
877 m_NavigNotebook->SetSelection(m_IndexPage);
878 m_IndexList->Clear();
879 m_IndexButton->Disable();
880 m_IndexButtonAll->Disable();
881 m_IndexText->SetValue(keyword);
882
883 DoIndexFind();
884 m_IndexButton->Enable();
885 m_IndexButtonAll->Enable();
886 foundcnt = m_IndexList->GetCount();
887 }
888
889 if (foundcnt)
890 {
891 switch ( mode )
892 {
893 default:
894 wxFAIL_MSG( _T("unknown help search mode") );
895 // fall back
896
897 case wxHELP_SEARCH_ALL:
898 {
899 wxHtmlHelpDataItem *it =
900 (wxHtmlHelpDataItem*) m_SearchList->GetClientData(0);
901 if (it)
902 {
903 m_HtmlWin->LoadPage(it->GetFullPath());
904 NotifyPageChanged();
905 }
906 break;
907 }
908
909 case wxHELP_SEARCH_INDEX:
910 {
911 wxHtmlHelpMergedIndexItem* it =
912 (wxHtmlHelpMergedIndexItem*) m_IndexList->GetClientData(0);
913 if (it)
914 DisplayIndexItem(it);
915 break;
916 }
917 }
918
919 }
920
921 return foundcnt > 0;
922 }
923
924 void wxHtmlHelpWindow::CreateContents()
925 {
926 if (! m_ContentsBox)
927 return ;
928
929 if (m_PagesHash)
930 {
931 WX_CLEAR_HASH_TABLE(*m_PagesHash);
932 delete m_PagesHash;
933 }
934
935 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
936
937 size_t cnt = contents.size();
938
939 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * cnt);
940
941 const int MAX_ROOTS = 64;
942 wxTreeItemId roots[MAX_ROOTS];
943 // VS: this array holds information about whether we've set item icon at
944 // given level. This is necessary because m_Data has a flat structure
945 // and there's no way of recognizing if some item has subitems or not.
946 // We set the icon later: when we find an item with level=n, we know
947 // that the last item with level=n-1 was afolder with subitems, so we
948 // set its icon accordingly
949 bool imaged[MAX_ROOTS];
950 m_ContentsBox->DeleteAllItems();
951
952 roots[0] = m_ContentsBox->AddRoot(_("(Help)"));
953 imaged[0] = true;
954
955 for (size_t i = 0; i < cnt; i++)
956 {
957 wxHtmlHelpDataItem *it = &contents[i];
958 // Handle books:
959 if (it->level == 0)
960 {
961 if (m_hfStyle & wxHF_MERGE_BOOKS)
962 // VS: we don't want book nodes, books' content should
963 // appear under tree's root. This line will create a "fake"
964 // record about book node so that the rest of this look
965 // will believe there really _is_ a book node and will
966 // behave correctly.
967 roots[1] = roots[0];
968 else
969 {
970 roots[1] = m_ContentsBox->AppendItem(roots[0],
971 it->name, IMG_Book, -1,
972 new wxHtmlHelpTreeItemData(i));
973 m_ContentsBox->SetItemBold(roots[1], true);
974 }
975 imaged[1] = true;
976 }
977 // ...and their contents:
978 else
979 {
980 roots[it->level + 1] = m_ContentsBox->AppendItem(
981 roots[it->level], it->name, IMG_Page,
982 -1, new wxHtmlHelpTreeItemData(i));
983 imaged[it->level + 1] = false;
984 }
985
986 m_PagesHash->Put(it->GetFullPath(),
987 new wxHtmlHelpHashData(i, roots[it->level + 1]));
988
989 // Set the icon for the node one level up in the hierarchy,
990 // unless already done (see comment above imaged[] declaration)
991 if (!imaged[it->level])
992 {
993 int image = IMG_Folder;
994 if (m_hfStyle & wxHF_ICONS_BOOK)
995 image = IMG_Book;
996 else if (m_hfStyle & wxHF_ICONS_BOOK_CHAPTER)
997 image = (it->level == 1) ? IMG_Book : IMG_Folder;
998 m_ContentsBox->SetItemImage(roots[it->level], image);
999 m_ContentsBox->SetItemImage(roots[it->level], image,
1000 wxTreeItemIcon_Selected);
1001 imaged[it->level] = true;
1002 }
1003 }
1004 }
1005
1006 void wxHtmlHelpWindow::CreateIndex()
1007 {
1008 if (! m_IndexList)
1009 return ;
1010
1011 m_IndexList->Clear();
1012
1013 size_t cnt = m_mergedIndex->size();
1014
1015 wxString cnttext;
1016 if (cnt > INDEX_IS_SMALL)
1017 cnttext.Printf(_("%i of %i"), 0, cnt);
1018 else
1019 cnttext.Printf(_("%i of %i"), cnt, cnt);
1020 m_IndexCountInfo->SetLabel(cnttext);
1021 if (cnt > INDEX_IS_SMALL)
1022 return;
1023
1024 for (size_t i = 0; i < cnt; i++)
1025 m_IndexList->Append((*m_mergedIndex)[i].name,
1026 (char*)(&(*m_mergedIndex)[i]));
1027 }
1028
1029 void wxHtmlHelpWindow::CreateSearch()
1030 {
1031 if (! (m_SearchList && m_SearchChoice))
1032 return ;
1033 m_SearchList->Clear();
1034 m_SearchChoice->Clear();
1035 m_SearchChoice->Append(_("Search in all books"));
1036 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
1037 int i, cnt = bookrec.GetCount();
1038 for (i = 0; i < cnt; i++)
1039 m_SearchChoice->Append(bookrec[i].GetTitle());
1040 m_SearchChoice->SetSelection(0);
1041 }
1042
1043 void wxHtmlHelpWindow::RefreshLists()
1044 {
1045 // Update m_mergedIndex:
1046 UpdateMergedIndex();
1047 // Update the controls
1048 CreateContents();
1049 CreateIndex();
1050 CreateSearch();
1051 }
1052
1053 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase *cfg, const wxString& path)
1054 {
1055 wxString oldpath;
1056 wxString tmp;
1057
1058 if (path != wxEmptyString)
1059 {
1060 oldpath = cfg->GetPath();
1061 cfg->SetPath(_T("/") + path);
1062 }
1063
1064 m_Cfg.navig_on = cfg->Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
1065 m_Cfg.sashpos = cfg->Read(wxT("hcSashPos"), m_Cfg.sashpos);
1066 m_Cfg.x = cfg->Read(wxT("hcX"), m_Cfg.x);
1067 m_Cfg.y = cfg->Read(wxT("hcY"), m_Cfg.y);
1068 m_Cfg.w = cfg->Read(wxT("hcW"), m_Cfg.w);
1069 m_Cfg.h = cfg->Read(wxT("hcH"), m_Cfg.h);
1070
1071 m_FixedFace = cfg->Read(wxT("hcFixedFace"), m_FixedFace);
1072 m_NormalFace = cfg->Read(wxT("hcNormalFace"), m_NormalFace);
1073 m_FontSize = cfg->Read(wxT("hcBaseFontSize"), m_FontSize);
1074
1075 {
1076 int i;
1077 int cnt;
1078 wxString val, s;
1079
1080 cnt = cfg->Read(wxT("hcBookmarksCnt"), 0L);
1081 if (cnt != 0)
1082 {
1083 m_BookmarksNames.Clear();
1084 m_BookmarksPages.Clear();
1085 if (m_Bookmarks)
1086 {
1087 m_Bookmarks->Clear();
1088 m_Bookmarks->Append(_("(bookmarks)"));
1089 }
1090
1091 for (i = 0; i < cnt; i++)
1092 {
1093 val.Printf(wxT("hcBookmark_%i"), i);
1094 s = cfg->Read(val);
1095 m_BookmarksNames.Add(s);
1096 if (m_Bookmarks) m_Bookmarks->Append(s);
1097 val.Printf(wxT("hcBookmark_%i_url"), i);
1098 s = cfg->Read(val);
1099 m_BookmarksPages.Add(s);
1100 }
1101 }
1102 }
1103
1104 if (m_HtmlWin)
1105 m_HtmlWin->ReadCustomization(cfg);
1106
1107 if (path != wxEmptyString)
1108 cfg->SetPath(oldpath);
1109 }
1110
1111 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase *cfg, const wxString& path)
1112 {
1113 wxString oldpath;
1114 wxString tmp;
1115
1116 if (path != wxEmptyString)
1117 {
1118 oldpath = cfg->GetPath();
1119 cfg->SetPath(_T("/") + path);
1120 }
1121
1122 cfg->Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
1123 cfg->Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
1124
1125 // Don't write if iconized as this would make the window
1126 // disappear next time it is shown!
1127 cfg->Write(wxT("hcX"), (long)m_Cfg.x);
1128 cfg->Write(wxT("hcY"), (long)m_Cfg.y);
1129 cfg->Write(wxT("hcW"), (long)m_Cfg.w);
1130 cfg->Write(wxT("hcH"), (long)m_Cfg.h);
1131
1132 cfg->Write(wxT("hcFixedFace"), m_FixedFace);
1133 cfg->Write(wxT("hcNormalFace"), m_NormalFace);
1134 cfg->Write(wxT("hcBaseFontSize"), (long)m_FontSize);
1135
1136 if (m_Bookmarks)
1137 {
1138 int i;
1139 int cnt = m_BookmarksNames.GetCount();
1140 wxString val;
1141
1142 cfg->Write(wxT("hcBookmarksCnt"), (long)cnt);
1143 for (i = 0; i < cnt; i++)
1144 {
1145 val.Printf(wxT("hcBookmark_%i"), i);
1146 cfg->Write(val, m_BookmarksNames[i]);
1147 val.Printf(wxT("hcBookmark_%i_url"), i);
1148 cfg->Write(val, m_BookmarksPages[i]);
1149 }
1150 }
1151
1152 if (m_HtmlWin)
1153 m_HtmlWin->WriteCustomization(cfg);
1154
1155 if (path != wxEmptyString)
1156 cfg->SetPath(oldpath);
1157 }
1158
1159 static void SetFontsToHtmlWin(wxHtmlWindow *win, const wxString& scalf, const wxString& fixf, int size)
1160 {
1161 int f_sizes[7];
1162 f_sizes[0] = int(size * 0.6);
1163 f_sizes[1] = int(size * 0.8);
1164 f_sizes[2] = size;
1165 f_sizes[3] = int(size * 1.2);
1166 f_sizes[4] = int(size * 1.4);
1167 f_sizes[5] = int(size * 1.6);
1168 f_sizes[6] = int(size * 1.8);
1169
1170 win->SetFonts(scalf, fixf, f_sizes);
1171 }
1172
1173 class wxHtmlHelpWindowOptionsDialog : public wxDialog
1174 {
1175 public:
1176 wxComboBox *NormalFont, *FixedFont;
1177 wxSpinCtrl *FontSize;
1178 wxHtmlWindow *TestWin;
1179
1180 wxHtmlHelpWindowOptionsDialog(wxWindow *parent)
1181 : wxDialog(parent, wxID_ANY, wxString(_("Help Browser Options")))
1182 {
1183 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
1184 wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 3, 2, 5);
1185
1186 sizer->Add(new wxStaticText(this, wxID_ANY, _("Normal font:")));
1187 sizer->Add(new wxStaticText(this, wxID_ANY, _("Fixed font:")));
1188 sizer->Add(new wxStaticText(this, wxID_ANY, _("Font size:")));
1189
1190 sizer->Add(NormalFont = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
1191 wxSize(200, wxDefaultCoord),
1192 0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
1193
1194 sizer->Add(FixedFont = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
1195 wxSize(200, wxDefaultCoord),
1196 0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
1197
1198 sizer->Add(FontSize = new wxSpinCtrl(this, wxID_ANY));
1199 FontSize->SetRange(2, 100);
1200
1201 topsizer->Add(sizer, 0, wxLEFT|wxRIGHT|wxTOP, 10);
1202
1203 topsizer->Add(new wxStaticText(this, wxID_ANY, _("Preview:")),
1204 0, wxLEFT | wxTOP, 10);
1205 topsizer->Add(TestWin = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(20, 150),
1206 wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER),
1207 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
1208
1209 wxBoxSizer *sizer2 = new wxBoxSizer(wxHORIZONTAL);
1210 wxButton *ok;
1211 sizer2->Add(ok = new wxButton(this, wxID_OK), 0, wxALL, 10);
1212 ok->SetDefault();
1213 sizer2->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 10);
1214 topsizer->Add(sizer2, 0, wxALIGN_RIGHT);
1215
1216 SetSizer(topsizer);
1217 topsizer->Fit(this);
1218 Centre(wxBOTH);
1219 }
1220
1221
1222 void UpdateTestWin()
1223 {
1224 wxBusyCursor bcur;
1225 SetFontsToHtmlWin(TestWin,
1226 NormalFont->GetStringSelection(),
1227 FixedFont->GetStringSelection(),
1228 FontSize->GetValue());
1229
1230 wxString content(_("font size"));
1231
1232 content = _T("<font size=-2>") + content + _T(" -2</font><br>")
1233 _T("<font size=-1>") + content + _T(" -1</font><br>")
1234 _T("<font size=+0>") + content + _T(" +0</font><br>")
1235 _T("<font size=+1>") + content + _T(" +1</font><br>")
1236 _T("<font size=+2>") + content + _T(" +2</font><br>")
1237 _T("<font size=+3>") + content + _T(" +3</font><br>")
1238 _T("<font size=+4>") + content + _T(" +4</font><br>") ;
1239
1240 content = wxString( _T("<html><body><table><tr><td>") ) +
1241 _("Normal face<br>and <u>underlined</u>. ") +
1242 _("<i>Italic face.</i> ") +
1243 _("<b>Bold face.</b> ") +
1244 _("<b><i>Bold italic face.</i></b><br>") +
1245 content +
1246 wxString( _T("</td><td><tt>") ) +
1247 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1248 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1249 content +
1250 _T("</tt></td></tr></table></body></html>");
1251
1252 TestWin->SetPage( content );
1253 }
1254
1255 void OnUpdate(wxCommandEvent& WXUNUSED(event))
1256 {
1257 UpdateTestWin();
1258 }
1259 void OnUpdateSpin(wxSpinEvent& WXUNUSED(event))
1260 {
1261 UpdateTestWin();
1262 }
1263
1264 DECLARE_EVENT_TABLE()
1265 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog)
1266 };
1267
1268 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog, wxDialog)
1269 EVT_COMBOBOX(wxID_ANY, wxHtmlHelpWindowOptionsDialog::OnUpdate)
1270 EVT_SPINCTRL(wxID_ANY, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin)
1271 END_EVENT_TABLE()
1272
1273 void wxHtmlHelpWindow::OptionsDialog()
1274 {
1275 wxHtmlHelpWindowOptionsDialog dlg(this);
1276 unsigned i;
1277
1278 if (m_NormalFonts == NULL)
1279 {
1280 m_NormalFonts = new wxArrayString(wxFontEnumerator::GetFacenames());
1281 m_NormalFonts->Sort(); // ascending sort
1282 }
1283 if (m_FixedFonts == NULL)
1284 {
1285 m_FixedFonts = new wxArrayString(
1286 wxFontEnumerator::GetFacenames(wxFONTENCODING_SYSTEM,
1287 true /*enum fixed width only*/));
1288 m_FixedFonts->Sort(); // ascending sort
1289 }
1290
1291 // VS: We want to show the font that is actually used by wxHtmlWindow.
1292 // If customization dialog wasn't used yet, facenames are empty and
1293 // wxHtmlWindow uses default fonts -- let's find out what they
1294 // are so that we can pass them to the dialog:
1295 if (m_NormalFace.empty())
1296 {
1297 wxFont fnt(m_FontSize, wxSWISS, wxNORMAL, wxNORMAL, false);
1298 m_NormalFace = fnt.GetFaceName();
1299 }
1300 if (m_FixedFace.empty())
1301 {
1302 wxFont fnt(m_FontSize, wxMODERN, wxNORMAL, wxNORMAL, false);
1303 m_FixedFace = fnt.GetFaceName();
1304 }
1305
1306 for (i = 0; i < m_NormalFonts->GetCount(); i++)
1307 dlg.NormalFont->Append((*m_NormalFonts)[i]);
1308 for (i = 0; i < m_FixedFonts->GetCount(); i++)
1309 dlg.FixedFont->Append((*m_FixedFonts)[i]);
1310 if (!m_NormalFace.empty())
1311 dlg.NormalFont->SetStringSelection(m_NormalFace);
1312 else
1313 dlg.NormalFont->SetSelection(0);
1314 if (!m_FixedFace.empty())
1315 dlg.FixedFont->SetStringSelection(m_FixedFace);
1316 else
1317 dlg.FixedFont->SetSelection(0);
1318 dlg.FontSize->SetValue(m_FontSize);
1319 dlg.UpdateTestWin();
1320
1321 if (dlg.ShowModal() == wxID_OK)
1322 {
1323 m_NormalFace = dlg.NormalFont->GetStringSelection();
1324 m_FixedFace = dlg.FixedFont->GetStringSelection();
1325 m_FontSize = dlg.FontSize->GetValue();
1326 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
1327 }
1328 }
1329
1330 void wxHtmlHelpWindow::NotifyPageChanged()
1331 {
1332 if (m_UpdateContents && m_PagesHash)
1333 {
1334 wxString page = wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin);
1335 wxHtmlHelpHashData *ha = NULL;
1336 if (!page.empty())
1337 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(page);
1338
1339 if (ha)
1340 {
1341 bool olduc = m_UpdateContents;
1342 m_UpdateContents = false;
1343 m_ContentsBox->SelectItem(ha->m_Id);
1344 m_ContentsBox->EnsureVisible(ha->m_Id);
1345 m_UpdateContents = olduc;
1346 }
1347 }
1348 }
1349
1350 /*
1351 EVENT HANDLING :
1352 */
1353
1354
1355 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent& event)
1356 {
1357 switch (event.GetId())
1358 {
1359 case wxID_HTML_BACK :
1360 m_HtmlWin->HistoryBack();
1361 NotifyPageChanged();
1362 break;
1363
1364 case wxID_HTML_FORWARD :
1365 m_HtmlWin->HistoryForward();
1366 NotifyPageChanged();
1367 break;
1368
1369 case wxID_HTML_UP :
1370 if (m_PagesHash)
1371 {
1372 wxString page = wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin);
1373 wxHtmlHelpHashData *ha = NULL;
1374 if (!page.empty())
1375 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(page);
1376 if (ha && ha->m_Index > 0)
1377 {
1378 const wxHtmlHelpDataItem& it = m_Data->GetContentsArray()[ha->m_Index - 1];
1379 if (!it.page.empty())
1380 {
1381 m_HtmlWin->LoadPage(it.GetFullPath());
1382 NotifyPageChanged();
1383 }
1384 }
1385 }
1386 break;
1387
1388 case wxID_HTML_UPNODE :
1389 if (m_PagesHash)
1390 {
1391 wxString page = wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin);
1392 wxHtmlHelpHashData *ha = NULL;
1393 if (!page.empty())
1394 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(page);
1395 if (ha && ha->m_Index > 0)
1396 {
1397 int level =
1398 m_Data->GetContentsArray()[ha->m_Index].level - 1;
1399 int ind = ha->m_Index - 1;
1400
1401 const wxHtmlHelpDataItem *it =
1402 &m_Data->GetContentsArray()[ind];
1403 while (ind >= 0 && it->level != level)
1404 {
1405 ind--;
1406 it = &m_Data->GetContentsArray()[ind];
1407 }
1408 if (ind >= 0)
1409 {
1410 if (!it->page.empty())
1411 {
1412 m_HtmlWin->LoadPage(it->GetFullPath());
1413 NotifyPageChanged();
1414 }
1415 }
1416 }
1417 }
1418 break;
1419
1420 case wxID_HTML_DOWN :
1421 if (m_PagesHash)
1422 {
1423 wxString page = wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin);
1424 wxHtmlHelpHashData *ha = NULL;
1425 if (!page.empty())
1426 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(page);
1427
1428 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
1429 if (ha && ha->m_Index < (int)contents.size() - 1)
1430 {
1431 size_t idx = ha->m_Index + 1;
1432
1433 while (contents[idx].GetFullPath() == page) idx++;
1434
1435 if (!contents[idx].page.empty())
1436 {
1437 m_HtmlWin->LoadPage(contents[idx].GetFullPath());
1438 NotifyPageChanged();
1439 }
1440 }
1441 }
1442 break;
1443
1444 case wxID_HTML_PANEL :
1445 {
1446 if (! (m_Splitter && m_NavigPan))
1447 return ;
1448 if (m_Splitter->IsSplit())
1449 {
1450 m_Cfg.sashpos = m_Splitter->GetSashPosition();
1451 m_Splitter->Unsplit(m_NavigPan);
1452 m_Cfg.navig_on = false;
1453 }
1454 else
1455 {
1456 m_NavigPan->Show();
1457 m_HtmlWin->Show();
1458 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
1459 m_Cfg.navig_on = true;
1460 }
1461 }
1462 break;
1463
1464 case wxID_HTML_OPTIONS :
1465 OptionsDialog();
1466 break;
1467
1468 case wxID_HTML_BOOKMARKSADD :
1469 {
1470 wxString item;
1471 wxString url;
1472
1473 item = m_HtmlWin->GetOpenedPageTitle();
1474 url = m_HtmlWin->GetOpenedPage();
1475 if (item == wxEmptyString)
1476 item = url.AfterLast(wxT('/'));
1477 if (m_BookmarksPages.Index(url) == wxNOT_FOUND)
1478 {
1479 m_Bookmarks->Append(item);
1480 m_BookmarksNames.Add(item);
1481 m_BookmarksPages.Add(url);
1482 }
1483 }
1484 break;
1485
1486 case wxID_HTML_BOOKMARKSREMOVE :
1487 {
1488 wxString item;
1489 int pos;
1490
1491 item = m_Bookmarks->GetStringSelection();
1492 pos = m_BookmarksNames.Index(item);
1493 if (pos != wxNOT_FOUND)
1494 {
1495 m_BookmarksNames.RemoveAt(pos);
1496 m_BookmarksPages.RemoveAt(pos);
1497 pos = m_Bookmarks->GetSelection();
1498 wxASSERT_MSG( pos != wxNOT_FOUND , wxT("Unknown bookmark position") ) ;
1499 m_Bookmarks->Delete((unsigned int)pos);
1500 }
1501 }
1502 break;
1503
1504 #if wxUSE_PRINTING_ARCHITECTURE
1505 case wxID_HTML_PRINT :
1506 {
1507 if (m_Printer == NULL)
1508 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
1509 if (!m_HtmlWin->GetOpenedPage())
1510 wxLogWarning(_("Cannot print empty page."));
1511 else
1512 m_Printer->PrintFile(m_HtmlWin->GetOpenedPage());
1513 }
1514 break;
1515 #endif
1516
1517 case wxID_HTML_OPENFILE :
1518 {
1519 wxString filemask = wxString(
1520 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1521 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1522 _("HTML Help Project (*.hhp)|*.hhp|") +
1523 #if wxUSE_LIBMSPACK
1524 _("Compressed HTML Help file (*.chm)|*.chm|") +
1525 #endif
1526 _("All files (*.*)|*");
1527 wxString s = wxFileSelector(_("Open HTML document"),
1528 wxEmptyString,
1529 wxEmptyString,
1530 wxEmptyString,
1531 filemask,
1532 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1533 this);
1534 if (!s.empty())
1535 {
1536 wxString ext = s.Right(4).Lower();
1537 if (ext == _T(".zip") || ext == _T(".htb") ||
1538 #if wxUSE_LIBMSPACK
1539 ext == _T(".chm") ||
1540 #endif
1541 ext == _T(".hhp"))
1542 {
1543 wxBusyCursor bcur;
1544 m_Data->AddBook(s);
1545 RefreshLists();
1546 }
1547 else
1548 m_HtmlWin->LoadPage(s);
1549 }
1550 }
1551 break;
1552 }
1553 }
1554
1555 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent& event)
1556 {
1557 wxHtmlHelpTreeItemData *pg;
1558
1559 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox->GetItemData(event.GetItem());
1560
1561 if (pg && m_UpdateContents)
1562 {
1563 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
1564 m_UpdateContents = false;
1565 if (!contents[pg->m_Id].page.empty())
1566 m_HtmlWin->LoadPage(contents[pg->m_Id].GetFullPath());
1567 m_UpdateContents = true;
1568 }
1569 }
1570
1571 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent& WXUNUSED(event))
1572 {
1573 wxHtmlHelpMergedIndexItem *it = (wxHtmlHelpMergedIndexItem*)
1574 m_IndexList->GetClientData(m_IndexList->GetSelection());
1575 if (it)
1576 DisplayIndexItem(it);
1577 }
1578
1579 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent& WXUNUSED(event))
1580 {
1581 DoIndexFind();
1582 }
1583
1584 void wxHtmlHelpWindow::DoIndexFind()
1585 {
1586 wxString sr = m_IndexText->GetLineText(0);
1587 sr.MakeLower();
1588 if (sr == wxEmptyString)
1589 {
1590 DoIndexAll();
1591 }
1592 else
1593 {
1594 wxBusyCursor bcur;
1595
1596 m_IndexList->Clear();
1597 const wxHtmlHelpMergedIndex& index = *m_mergedIndex;
1598 size_t cnt = index.size();
1599
1600 int displ = 0;
1601 for (size_t i = 0; i < cnt; i++)
1602 {
1603 if (index[i].name.Lower().find(sr) != wxString::npos)
1604 {
1605 int pos = m_IndexList->Append(index[i].name,
1606 (char*)(&index[i]));
1607
1608 if (displ++ == 0)
1609 {
1610 // don't automatically show topic selector if this
1611 // item points to multiple pages:
1612 if (index[i].items.size() == 1)
1613 {
1614 m_IndexList->SetSelection(0);
1615 DisplayIndexItem(&index[i]);
1616 }
1617 }
1618
1619 // if this is nested item of the index, show its parent(s)
1620 // as well, otherwise it would not be clear what entry is
1621 // shown:
1622 wxHtmlHelpMergedIndexItem *parent = index[i].parent;
1623 while (parent)
1624 {
1625 if (pos == 0 ||
1626 (index.Index(*(wxHtmlHelpMergedIndexItem*)m_IndexList->GetClientData(pos-1))) < index.Index(*parent))
1627 {
1628 m_IndexList->Insert(parent->name,
1629 pos, (char*)parent);
1630 parent = parent->parent;
1631 }
1632 else break;
1633 }
1634
1635 // finally, it the item we just added is itself a parent for
1636 // other items, show them as well, because they are refinements
1637 // of the displayed index entry (i.e. it is implicitly contained
1638 // in them: "foo" with parent "bar" reads as "bar, foo"):
1639 int level = index[i].items[0]->level;
1640 i++;
1641 while (i < cnt && index[i].items[0]->level > level)
1642 {
1643 m_IndexList->Append(index[i].name, (char*)(&index[i]));
1644 i++;
1645 }
1646 i--;
1647 }
1648 }
1649
1650 wxString cnttext;
1651 cnttext.Printf(_("%i of %i"), displ, cnt);
1652 m_IndexCountInfo->SetLabel(cnttext);
1653
1654 m_IndexText->SetSelection(0, sr.length());
1655 m_IndexText->SetFocus();
1656 }
1657 }
1658
1659 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1660 {
1661 DoIndexAll();
1662 }
1663
1664 void wxHtmlHelpWindow::DoIndexAll()
1665 {
1666 wxBusyCursor bcur;
1667
1668 m_IndexList->Clear();
1669 const wxHtmlHelpMergedIndex& index = *m_mergedIndex;
1670 size_t cnt = index.size();
1671 bool first = true;
1672
1673 for (size_t i = 0; i < cnt; i++)
1674 {
1675 m_IndexList->Append(index[i].name, (char*)(&index[i]));
1676 if (first)
1677 {
1678 // don't automatically show topic selector if this
1679 // item points to multiple pages:
1680 if (index[i].items.size() == 1)
1681 {
1682 DisplayIndexItem(&index[i]);
1683 }
1684 first = false;
1685 }
1686 }
1687
1688 wxString cnttext;
1689 cnttext.Printf(_("%i of %i"), cnt, cnt);
1690 m_IndexCountInfo->SetLabel(cnttext);
1691 }
1692
1693 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent& WXUNUSED(event))
1694 {
1695 wxHtmlHelpDataItem *it = (wxHtmlHelpDataItem*) m_SearchList->GetClientData(m_SearchList->GetSelection());
1696 if (it)
1697 {
1698 if (!it->page.empty())
1699 m_HtmlWin->LoadPage(it->GetFullPath());
1700 NotifyPageChanged();
1701 }
1702 }
1703
1704 void wxHtmlHelpWindow::OnSearch(wxCommandEvent& WXUNUSED(event))
1705 {
1706 wxString sr = m_SearchText->GetLineText(0);
1707
1708 if (!sr.empty())
1709 KeywordSearch(sr, wxHELP_SEARCH_ALL);
1710 }
1711
1712 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1713 {
1714 wxString str = m_Bookmarks->GetStringSelection();
1715 int idx = m_BookmarksNames.Index(str);
1716 if (!str.empty() && str != _("(bookmarks)") && idx != wxNOT_FOUND)
1717 {
1718 m_HtmlWin->LoadPage(m_BookmarksPages[(size_t)idx]);
1719 NotifyPageChanged();
1720 }
1721 }
1722
1723 void wxHtmlHelpWindow::OnSize(wxSizeEvent& WXUNUSED(event))
1724 {
1725 Layout();
1726 }
1727
1728 #endif // wxUSE_WXHTML_HELP