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