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