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