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