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