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