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