]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpfrm.cpp
Oops, compile errors...
[wxWidgets.git] / src / html / helpfrm.cpp
CommitLineData
8ec2b484
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpfrm.cpp
3// Purpose: wxHtmlHelpFrame
d5bb85a0 4// Notes: Based on htmlhelp.cpp, implementing a monolithic
8ec2b484
HH
5// HTML Help controller class, by Vaclav Slavik
6// Author: Harm van der Heijden and Vaclav Slavik
69941f05 7// RCS-ID: $Id$
8ec2b484
HH
8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
69941f05 13#pragma implementation
8ec2b484
HH
14#endif
15
c32bfc10
VS
16// For compilers that support precompilation, includes "wx.h"
17
8ec2b484
HH
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#include "wx/defs.h"
25
26#if wxUSE_HTML
8ec2b484 27#ifndef WXPRECOMP
3096bd2f 28#include "wx/wx.h"
8ec2b484
HH
29#endif
30
31#include "wx/html/helpfrm.h"
b4414c1f 32#include "wx/html/helpctrl.h"
8ec2b484
HH
33#include "wx/notebook.h"
34#include "wx/imaglist.h"
35#include "wx/treectrl.h"
36#include "wx/tokenzr.h"
37#include "wx/wfstream.h"
38#include "wx/html/htmlwin.h"
39#include "wx/busyinfo.h"
40#include "wx/progdlg.h"
2bd5bbc9 41#include "wx/toolbar.h"
83efdf33 42#include "wx/fontenum.h"
0646614d
VS
43#include "wx/stream.h"
44#include "wx/filedlg.h"
8ec2b484
HH
45
46// Bitmaps:
47
48#ifndef __WXMSW__
83efdf33
VS
49#include "bitmaps/wpanel.xpm"
50#include "bitmaps/wback.xpm"
51#include "bitmaps/wforward.xpm"
52#include "bitmaps/wbook.xpm"
53#include "bitmaps/woptions.xpm"
54#include "bitmaps/wfolder.xpm"
55#include "bitmaps/wpage.xpm"
56#include "bitmaps/whelp.xpm"
57#include "bitmaps/whlproot.xpm"
382e6efe
VS
58#include "bitmaps/wbkadd.xpm"
59#include "bitmaps/wbkdel.xpm"
0646614d
VS
60#include "bitmaps/wup.xpm"
61#include "bitmaps/wupnode.xpm"
62#include "bitmaps/wdown.xpm"
63#include "bitmaps/wopen.xpm"
64#include "bitmaps/wprint.xpm"
8ec2b484
HH
65#endif
66
8ec2b484 67
f0b6a33f
VS
68// what is considered "small index"?
69#define INDEX_IS_SMALL 100
70
71
8ec2b484 72//--------------------------------------------------------------------------
382e6efe 73// wxHtmlHelpTreeItemData (private)
8ec2b484
HH
74//--------------------------------------------------------------------------
75
76class wxHtmlHelpTreeItemData : public wxTreeItemData
77{
0646614d
VS
78 public:
79 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
80 { m_Id = id;}
81
82 int m_Id;
83};
8ec2b484 84
0646614d
VS
85
86//--------------------------------------------------------------------------
87// wxHtmlHelpHashData (private)
88//--------------------------------------------------------------------------
89
90class wxHtmlHelpHashData : public wxObject
91{
8ec2b484 92 public:
0646614d
VS
93 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
94 { m_Index = index; m_Id = id;}
95
96 int m_Index;
97 wxTreeItemId m_Id;
8ec2b484
HH
98};
99
382e6efe 100
0646614d
VS
101//--------------------------------------------------------------------------
102// wxHtmlHelpHtmlWindow (private)
103//--------------------------------------------------------------------------
104
105class wxHtmlHelpHtmlWindow : public wxHtmlWindow
106{
107 public:
108 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent) : wxHtmlWindow(parent), m_Frame(fr) {}
109
110 virtual void OnLinkClicked(const wxHtmlLinkInfo& link)
111 {
112 wxHtmlWindow::OnLinkClicked(link);
113 m_Frame -> NotifyPageChanged();
114 }
115
116 private:
117 wxHtmlHelpFrame *m_Frame;
118};
119
382e6efe
VS
120
121
8ec2b484
HH
122//---------------------------------------------------------------------------
123// wxHtmlHelpFrame
124//---------------------------------------------------------------------------
125
126IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
127
128wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
d5bb85a0 129 int style, wxHtmlHelpData* data)
8ec2b484
HH
130{
131 Init(data);
132 Create(parent, id, title, style);
133}
d5bb85a0 134
8ec2b484
HH
135void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
136{
137 if (data) {
d5bb85a0
VS
138 m_Data = data;
139 m_DataCreated = FALSE;
140 } else {
141 m_Data = new wxHtmlHelpData();
142 m_DataCreated = TRUE;
8ec2b484
HH
143 }
144
68364659 145 m_ContentsImageList = new wxImageList(16, 16);
83efdf33
VS
146 m_ContentsImageList -> Add(wxICON(wbook));
147 m_ContentsImageList -> Add(wxICON(wfolder));
148 m_ContentsImageList -> Add(wxICON(wpage));
149 m_ContentsImageList -> Add(wxICON(whlproot));
8ec2b484
HH
150
151 m_ContentsBox = NULL;
f0b6a33f
VS
152 m_IndexList = NULL;
153 m_IndexButton = NULL;
154 m_IndexButtonAll = NULL;
155 m_IndexText = NULL;
8ec2b484
HH
156 m_SearchList = NULL;
157 m_SearchButton = NULL;
158 m_SearchText = NULL;
159 m_SearchChoice = NULL;
240c2873 160 m_IndexCountInfo = NULL;
8ec2b484
HH
161 m_Splitter = NULL;
162 m_NavigPan = NULL;
163 m_HtmlWin = NULL;
382e6efe 164 m_Bookmarks = NULL;
c4971147
VS
165 m_SearchCaseSensitive = NULL;
166 m_SearchWholeWords = NULL;
167
8ec2b484
HH
168 m_Config = NULL;
169 m_ConfigRoot = wxEmptyString;
170
171 m_Cfg.x = m_Cfg.y = 0;
d5bb85a0
VS
172 m_Cfg.w = 700;
173 m_Cfg.h = 480;
8ec2b484
HH
174 m_Cfg.sashpos = 240;
175 m_Cfg.navig_on = TRUE;
83efdf33
VS
176
177 m_NormalFonts = m_FixedFonts = NULL;
83efdf33 178 m_NormalFace = m_FixedFace = wxEmptyString;
0646614d
VS
179 m_FontSize = 1;
180
181#if wxUSE_PRINTING_ARCHITECTURE
182 m_Printer = NULL;
183#endif
184
185 m_PagesHash = NULL;
186 m_UpdateContents = TRUE;
b4414c1f 187 m_helpController = (wxHelpControllerBase*) NULL;
8ec2b484
HH
188}
189
d5bb85a0
VS
190// Create: builds the GUI components.
191// with the style flag it's possible to toggle the toolbar, contents, index and search
192// controls.
193// m_HtmlWin will *always* be created, but it's important to realize that
f0b6a33f 194// m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
d5bb85a0
VS
195// m_SearchButton may be NULL.
196// moreover, if no contents, index or searchpage is needed, m_Splitter and
197// m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
198
8ec2b484 199bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title,
d5bb85a0 200 int style)
8ec2b484
HH
201{
202 // Do the config in two steps. We read the HtmlWindow customization after we
203 // create the window.
d5bb85a0
VS
204 if (m_Config)
205 ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484 206
8eb2940f 207 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), wxDEFAULT_FRAME_STYLE, "wxHtmlHelp");
8ec2b484 208
5c172c17
VS
209 GetPosition(&m_Cfg.x, &m_Cfg.y);
210
83efdf33 211 SetIcon(wxICON(whelp));
9ffdee80 212
8ec2b484
HH
213 int notebook_page = 0;
214
215 CreateStatusBar();
216
217 // toolbar?
218 if (style & wxHF_TOOLBAR) {
83efdf33 219 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE);
00655497 220 toolBar->SetMargins( 2, 2 );
b854b7b8 221 AddToolbarButtons(toolBar, style);
83efdf33 222 toolBar -> Realize();
8ec2b484 223 }
d5bb85a0 224
8ec2b484 225 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) {
d5bb85a0
VS
226 // traditional help controller; splitter window with html page on the
227 // right and a notebook containing various pages on the left
228 m_Splitter = new wxSplitterWindow(this);
229
0646614d 230 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
d5bb85a0
VS
231 m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK,
232 wxDefaultPosition, wxDefaultSize);
233 } else { // only html window, no notebook with index,contents etc
234 m_HtmlWin = new wxHtmlWindow(this);
8ec2b484
HH
235 }
236
237 m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat);
238 m_HtmlWin -> SetRelatedStatusBar(0);
d5bb85a0
VS
239 if (m_Config)
240 m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484
HH
241
242 // contents tree panel?
243 if (style & wxHF_CONTENTS) {
ae80f837
VS
244 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
245
246 if (style & wxHF_BOOKMARKS) {
247 wxLayoutConstraints *b1 = new wxLayoutConstraints;
248 wxBitmapButton *bmpbt = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxDefaultPosition, wxSize(20,20));
249
250 b1 -> top.SameAs (dummy, wxTop, 10);
251 b1 -> right.SameAs (dummy, wxRight, 10);
252 b1 -> height.AsIs();
253 b1 -> width.AsIs();
254 bmpbt -> SetConstraints(b1);
255
256 wxLayoutConstraints *b2 = new wxLayoutConstraints;
257 wxBitmapButton *bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxDefaultPosition, wxSize(20,20));
258
259 b2 -> top.SameAs (dummy, wxTop, 10);
260 b2 -> right.LeftOf (bmpbt, 2);
261 b2 -> height.AsIs();
262 b2 -> width.AsIs();
263 bmpbt2 -> SetConstraints(b2);
264
265#if wxUSE_TOOLTIPS
266 bmpbt -> SetToolTip(_("Remove current page from bookmarks"));
267 bmpbt2 -> SetToolTip(_("Add current page to bookmarks"));
268#endif //wxUSE_TOOLTIPS
269
270 wxLayoutConstraints *b3 = new wxLayoutConstraints;
271 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, wxEmptyString,
272 wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT);
273 m_Bookmarks -> Append(_("(bookmarks)"));
274 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
275 m_Bookmarks -> Append(m_BookmarksNames[i]);
276 m_Bookmarks -> SetSelection(0);
277
278 b3 -> centreY.SameAs (bmpbt2, wxCentreY);
279 b3 -> left.SameAs (dummy, wxLeft, 10);
280 b3 -> right.LeftOf (bmpbt2, 5);
281 b3 -> height.AsIs();
282 m_Bookmarks -> SetConstraints(b3);
283
284
285 wxLayoutConstraints *b4 = new wxLayoutConstraints;
286 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
287 wxDefaultPosition, wxDefaultSize,
288 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
289 m_ContentsBox -> SetImageList(m_ContentsImageList);
290
291 b4 -> top.Below (m_Bookmarks, 10);
292 b4 -> left.SameAs (dummy, wxLeft, 0);
293 b4 -> right.SameAs (dummy, wxRight, 0);
294 b4 -> bottom.SameAs (dummy, wxBottom, 0);
295 m_ContentsBox -> SetConstraints(b4);
296
297 dummy -> SetAutoLayout(TRUE);
298 dummy -> Layout();
299
300 m_NavigPan -> AddPage(dummy, _("Contents"));
301 }
302
303 else
304 {
305 m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL,
306 wxDefaultPosition, wxDefaultSize,
307 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
308 m_ContentsBox -> SetImageList(m_ContentsImageList);
309 m_NavigPan -> AddPage(m_ContentsBox, _("Contents"));
310 }
311
d5bb85a0 312 m_ContentsPage = notebook_page++;
8ec2b484
HH
313 }
314
315 // index listbox panel?
316 if (style & wxHF_INDEX) {
d5bb85a0 317 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
f0b6a33f 318
d5bb85a0 319 wxLayoutConstraints *b1 = new wxLayoutConstraints;
f0b6a33f
VS
320 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
321 b1 -> top.SameAs (dummy, wxTop, 10);
322 b1 -> left.SameAs (dummy, wxLeft, 10);
323 b1 -> right.SameAs (dummy, wxRight, 10);
324 b1 -> height.AsIs();
325 m_IndexText -> SetConstraints(b1);
326
327 wxLayoutConstraints *b4 = new wxLayoutConstraints;
328 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, _("Show all"));
7618e374 329
f0b6a33f
VS
330 b4 -> top.Below (m_IndexText, 10);
331 b4 -> right.SameAs (dummy, wxRight, 10);
332 b4 -> width.AsIs();
333 b4 -> height.AsIs();
334 m_IndexButtonAll -> SetConstraints(b4);
335
336 wxLayoutConstraints *b2 = new wxLayoutConstraints;
337 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
f0b6a33f
VS
338 b2 -> top.Below (m_IndexText, 10);
339 b2 -> right.LeftOf (m_IndexButtonAll, 10);
340 b2 -> width.AsIs();
341 b2 -> height.AsIs();
342 m_IndexButton -> SetConstraints(b2);
343
240c2873
VS
344 wxLayoutConstraints *b5 = new wxLayoutConstraints;
345 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
346
347 b5 -> top.Below (m_IndexButton, 5);
348 b5 -> right.SameAs (dummy, wxRight, 10);
349 b5 -> left.SameAs (dummy, wxLeft, 10);
350 b5 -> height.AsIs();
351 m_IndexCountInfo -> SetConstraints(b5);
352
f0b6a33f 353 wxLayoutConstraints *b3 = new wxLayoutConstraints;
721ab905 354 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
240c2873 355 b3 -> top.Below (m_IndexCountInfo, 5);
f0b6a33f
VS
356 b3 -> left.SameAs (dummy, wxLeft, 0);
357 b3 -> right.SameAs (dummy, wxRight, 0);
358 b3 -> bottom.SameAs (dummy, wxBottom, 0);
359 m_IndexList -> SetConstraints(b3);
360
7618e374
VS
361#if wxUSE_TOOLTIPS
362 m_IndexButtonAll -> SetToolTip(_("Show all items in index"));
240c2873 363 m_IndexButton -> SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
7618e374
VS
364#endif //wxUSE_TOOLTIPS
365
d5bb85a0 366 dummy -> SetAutoLayout(TRUE);
f0b6a33f
VS
367 dummy -> Layout();
368
d5bb85a0
VS
369 m_NavigPan -> AddPage(dummy, _("Index"));
370 m_IndexPage = notebook_page++;
8ec2b484
HH
371 }
372
373 // search list panel?
374 if (style & wxHF_SEARCH) {
d5bb85a0
VS
375 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
376
377 wxLayoutConstraints *b1 = new wxLayoutConstraints;
f0b6a33f 378 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
d5bb85a0
VS
379 b1 -> top.SameAs (dummy, wxTop, 10);
380 b1 -> left.SameAs (dummy, wxLeft, 10);
381 b1 -> right.SameAs (dummy, wxRight, 10);
382 b1 -> height.AsIs();
383 m_SearchText -> SetConstraints(b1);
384
d5bb85a0
VS
385 wxLayoutConstraints *b4 = new wxLayoutConstraints;
386 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
387 wxDefaultSize);
388 b4 -> top.Below (m_SearchText, 10);
ae80f837 389 b4 -> left.SameAs (dummy, wxLeft, 10);
d5bb85a0
VS
390 b4 -> right.SameAs (dummy, wxRight, 10);
391 b4 -> height.AsIs();
392 m_SearchChoice -> SetConstraints(b4);
393
c4971147
VS
394 wxLayoutConstraints *b5 = new wxLayoutConstraints;
395 m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive"));
ae80f837 396 b5 -> top.Below (m_SearchChoice, 10);
c4971147 397 b5 -> left.SameAs (dummy, wxLeft, 10);
ae80f837 398 b5 -> width.AsIs();
c4971147
VS
399 b5 -> height.AsIs ();
400 m_SearchCaseSensitive -> SetConstraints(b5);
401
402 wxLayoutConstraints *b6 = new wxLayoutConstraints;
403 m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only"));
404 b6 -> top.Below (m_SearchCaseSensitive, 0);
405 b6 -> left.SameAs (dummy, wxLeft, 10);
ae80f837 406 b6 -> width.AsIs();
c4971147
VS
407 b6 -> height.AsIs ();
408 m_SearchWholeWords -> SetConstraints(b6);
409
ae80f837
VS
410 wxLayoutConstraints *b2 = new wxLayoutConstraints;
411 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
412#if wxUSE_TOOLTIPS
413 m_SearchButton -> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
414#endif //wxUSE_TOOLTIPS
415 b2 -> top.Below (m_SearchWholeWords, 0);
416 b2 -> right.SameAs (dummy, wxRight, 10);
417 b2 -> width.AsIs();
418 b2 -> height.AsIs();
419 m_SearchButton -> SetConstraints(b2);
420
954269e6 421 wxLayoutConstraints *b3 = new wxLayoutConstraints;
721ab905 422 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
ae80f837 423 b3 -> top.Below (m_SearchButton, 10);
954269e6
VS
424 b3 -> left.SameAs (dummy, wxLeft, 0);
425 b3 -> right.SameAs (dummy, wxRight, 0);
426 b3 -> bottom.SameAs (dummy, wxBottom, 0);
427 m_SearchList -> SetConstraints(b3);
428
d5bb85a0
VS
429 dummy -> SetAutoLayout(TRUE);
430 dummy -> Layout();
431 m_NavigPan -> AddPage(dummy, _("Search"));
432 m_SearchPage = notebook_page++;
8ec2b484 433 }
c32bfc10 434 m_HtmlWin -> Show(TRUE);
0646614d 435
b5a7b000 436 RefreshLists();
8ec2b484
HH
437
438 // showtime
439 if (m_NavigPan && m_Splitter) {
d5bb85a0 440 m_Splitter -> SetMinimumPaneSize(20);
f38374d0
DW
441 if (m_Cfg.navig_on)
442 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
443 else {
444 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
445 m_Splitter -> Unsplit();
446 }
c32bfc10
VS
447 if (m_Cfg.navig_on) {
448 m_NavigPan -> Show(TRUE);
d5bb85a0 449 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 450 }
68364659 451 else {
c32bfc10
VS
452 m_NavigPan -> Show(FALSE);
453 m_Splitter -> Initialize(m_HtmlWin);
68364659 454 }
8ec2b484 455 }
8ec2b484
HH
456 return TRUE;
457}
458
459wxHtmlHelpFrame::~wxHtmlHelpFrame()
460{
b4414c1f 461 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
8ec2b484
HH
462 delete m_ContentsImageList;
463 if (m_DataCreated)
d5bb85a0 464 delete m_Data;
83efdf33
VS
465 if (m_NormalFonts) delete m_NormalFonts;
466 if (m_FixedFonts) delete m_FixedFonts;
70aedad6 467 if (m_PagesHash) delete m_PagesHash;
8ec2b484
HH
468}
469
b854b7b8
VS
470
471void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style)
472{
473 toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap,
474 FALSE, -1, -1, (wxObject *) NULL,
475 _("Show/hide navigation panel"));
0646614d 476
b854b7b8
VS
477 toolBar -> AddSeparator();
478 toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap,
479 FALSE, -1, -1, (wxObject *) NULL,
0646614d 480 _("Go back"));
b854b7b8
VS
481 toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap,
482 FALSE, -1, -1, (wxObject *) NULL,
0646614d 483 _("Go forward"));
b854b7b8
VS
484 toolBar -> AddSeparator();
485
0646614d
VS
486 toolBar -> AddTool(wxID_HTML_UPNODE, wxBITMAP(wupnode), wxNullBitmap,
487 FALSE, -1, -1, (wxObject *) NULL,
488 _("Go one level up in document hierarchy"));
489 toolBar -> AddTool(wxID_HTML_UP, wxBITMAP(wup), wxNullBitmap,
490 FALSE, -1, -1, (wxObject *) NULL,
491 _("Previous page"));
492 toolBar -> AddTool(wxID_HTML_DOWN, wxBITMAP(wdown), wxNullBitmap,
493 FALSE, -1, -1, (wxObject *) NULL,
494 _("Next page"));
495
496 if ((style & wxHF_PRINT) || (style & wxHF_OPENFILES))
497 toolBar -> AddSeparator();
498
499 if (style & wxHF_OPENFILES)
500 toolBar -> AddTool(wxID_HTML_OPENFILE, wxBITMAP(wopen), wxNullBitmap,
501 FALSE, -1, -1, (wxObject *) NULL,
502 _("Open HTML document"));
503
504#if wxUSE_PRINTING_ARCHITECTURE
505 if (style & wxHF_PRINT)
506 toolBar -> AddTool(wxID_HTML_PRINT, wxBITMAP(wprint), wxNullBitmap,
507 FALSE, -1, -1, (wxObject *) NULL,
508 _("Print this page"));
509#endif
510
b854b7b8
VS
511 toolBar -> AddSeparator();
512 toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
513 FALSE, -1, -1, (wxObject *) NULL,
514 _("Display options dialog"));
515}
516
517
721ab905
VS
518void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
519{
520 if (m_HtmlWin)
521 m_HtmlWin->SetRelatedFrame(this, format);
522 m_TitleFormat = format;
523}
524
b854b7b8 525
8ec2b484
HH
526bool wxHtmlHelpFrame::Display(const wxString& x)
527{
528 wxString url = m_Data->FindPageByName(x);
529 if (! url.IsEmpty()) {
d5bb85a0 530 m_HtmlWin->LoadPage(url);
0646614d 531 NotifyPageChanged();
d5bb85a0 532 return TRUE;
8ec2b484
HH
533 }
534 return FALSE;
535}
536
537bool wxHtmlHelpFrame::Display(const int id)
538{
539 wxString url = m_Data->FindPageById(id);
540 if (! url.IsEmpty()) {
d5bb85a0 541 m_HtmlWin->LoadPage(url);
0646614d 542 NotifyPageChanged();
d5bb85a0 543 return TRUE;
8ec2b484
HH
544 }
545 return FALSE;
546}
547
548
549
550bool wxHtmlHelpFrame::DisplayContents()
551{
552 if (! m_ContentsBox)
d5bb85a0 553 return FALSE;
8ec2b484 554 if (!m_Splitter -> IsSplit()) {
d5bb85a0
VS
555 m_NavigPan -> Show(TRUE);
556 m_HtmlWin -> Show(TRUE);
557 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 558 m_Cfg.navig_on = TRUE;
8ec2b484
HH
559 }
560 m_NavigPan -> SetSelection(0);
561 return TRUE;
562}
563
564
565
566bool wxHtmlHelpFrame::DisplayIndex()
567{
f0b6a33f 568 if (! m_IndexList)
d5bb85a0 569 return FALSE;
8ec2b484 570 if (!m_Splitter -> IsSplit()) {
d5bb85a0
VS
571 m_NavigPan -> Show(TRUE);
572 m_HtmlWin -> Show(TRUE);
573 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484
HH
574 }
575 m_NavigPan -> SetSelection(1);
576 return TRUE;
577}
578
b854b7b8
VS
579
580
8ec2b484
HH
581bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
582{
583 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
d5bb85a0 584 return FALSE;
8ec2b484 585
c4971147 586 int foundcnt = 0, curi;
8ec2b484
HH
587 wxString foundstr;
588 wxString book = wxEmptyString;
589
590 if (!m_Splitter -> IsSplit()) {
d5bb85a0
VS
591 m_NavigPan -> Show(TRUE);
592 m_HtmlWin -> Show(TRUE);
593 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484
HH
594 }
595 m_NavigPan -> SetSelection(m_SearchPage);
596 m_SearchList -> Clear();
597 m_SearchText -> SetValue(keyword);
598 m_SearchButton -> Enable(FALSE);
599
600 if (m_SearchChoice->GetSelection() != 0)
d5bb85a0 601 book = m_SearchChoice->GetStringSelection();
8ec2b484 602
c4971147
VS
603 wxHtmlSearchStatus status(m_Data, keyword,
604 m_SearchCaseSensitive -> GetValue(), m_SearchWholeWords -> GetValue(),
605 book);
8ec2b484 606
d5bb85a0
VS
607 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
608 status.GetMaxIndex(), this,
b4414c1f 609 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
8ec2b484
HH
610
611 while (status.IsActive()) {
c4971147 612 curi = status.GetCurIndex();
b5a7b000 613 if (curi % 32 == 0 && progress.Update(curi) == FALSE)
d5bb85a0
VS
614 break;
615 if (status.Search()) {
616 foundstr.Printf(_("Found %i matches"), ++foundcnt);
617 progress.Update(status.GetCurIndex(), foundstr);
618 m_SearchList -> Append(status.GetName(), status.GetContentsItem());
619 }
8ec2b484
HH
620 }
621
622 m_SearchButton -> Enable(TRUE);
623 m_SearchText -> SetSelection(0, keyword.Length());
624 m_SearchText -> SetFocus();
625 if (foundcnt) {
626 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0);
0646614d
VS
627 if (it)
628 {
629 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
630 NotifyPageChanged();
631 }
8ec2b484
HH
632 }
633 return (foundcnt > 0);
634}
635
636#define MAX_ROOTS 64
637
b5a7b000 638void wxHtmlHelpFrame::CreateContents()
8ec2b484
HH
639{
640 if (! m_ContentsBox)
d5bb85a0 641 return ;
8ec2b484 642
8ec2b484 643 m_ContentsBox->Clear();
0646614d
VS
644
645 if (m_PagesHash) delete m_PagesHash;
646 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data -> GetContentsCnt());
647 m_PagesHash -> DeleteContents(TRUE);
8ec2b484
HH
648
649 int cnt = m_Data->GetContentsCnt();
8ec2b484
HH
650 int i;
651
83efdf33 652 wxHtmlContentsItem *it;
d5bb85a0 653
8ec2b484
HH
654 wxTreeItemId roots[MAX_ROOTS];
655 bool imaged[MAX_ROOTS];
656
657 m_ContentsBox -> DeleteAllItems();
658 roots[0] = m_ContentsBox -> AddRoot(_("(Help)"));
5c172c17
VS
659 m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder);
660 m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder);
8ec2b484
HH
661 imaged[0] = TRUE;
662
83efdf33 663 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
382e6efe 664 roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
d5bb85a0 665 roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
0646614d
VS
666 new wxHtmlHelpTreeItemData(i));
667 m_PagesHash -> Put(it -> m_Book -> GetBasePath() + it -> m_Page,
668 new wxHtmlHelpHashData(i, roots[it -> m_Level + 1]));
8ec2b484
HH
669
670 if (it -> m_Level == 0) {
671 m_ContentsBox -> SetItemBold(roots[1], TRUE);
672 m_ContentsBox -> SetItemImage(roots[1], IMG_Book);
673 m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book);
674 imaged[1] = TRUE;
d5bb85a0 675 } else imaged[it -> m_Level + 1] = FALSE;
8ec2b484
HH
676
677 if (!imaged[it -> m_Level]) {
678 m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder);
679 m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder);
680 imaged[it -> m_Level] = TRUE;
681 }
682 }
8ec2b484
HH
683 m_ContentsBox -> Expand(roots[0]);
684}
685
686
b5a7b000 687void wxHtmlHelpFrame::CreateIndex()
8ec2b484 688{
f0b6a33f 689 if (! m_IndexList)
d5bb85a0 690 return ;
8ec2b484 691
f0b6a33f 692 m_IndexList->Clear();
8ec2b484
HH
693
694 int cnt = m_Data->GetIndexCnt();
f0b6a33f 695
240c2873
VS
696 wxString cnttext;
697 if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt);
698 else cnttext.Printf(_("%i of %i"), cnt, cnt);
699 m_IndexCountInfo -> SetLabel(cnttext);
f0b6a33f
VS
700 if (cnt > INDEX_IS_SMALL) return;
701
8ec2b484
HH
702 wxHtmlContentsItem* index = m_Data->GetIndex();
703
b5a7b000 704 for (int i = 0; i < cnt; i++)
f0b6a33f 705 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
8ec2b484
HH
706}
707
708void wxHtmlHelpFrame::CreateSearch()
709{
710 if (! (m_SearchList && m_SearchChoice))
d5bb85a0 711 return ;
8ec2b484
HH
712 m_SearchList -> Clear();
713 m_SearchChoice -> Clear();
ae80f837 714 m_SearchChoice -> Append(_("Search in all books"));
8ec2b484
HH
715 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
716 int i, cnt = bookrec.GetCount();
d5bb85a0
VS
717 for (i = 0; i < cnt; i++)
718 m_SearchChoice->Append(bookrec[i].GetTitle());
8ec2b484
HH
719 m_SearchChoice->SetSelection(0);
720}
721
722
b5a7b000 723void wxHtmlHelpFrame::RefreshLists()
8ec2b484 724{
b5a7b000
VS
725 CreateContents();
726 CreateIndex();
8ec2b484
HH
727 CreateSearch();
728}
729
730void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
731{
732 wxString oldpath;
733 wxString tmp;
734
735 if (path != wxEmptyString) {
736 oldpath = cfg -> GetPath();
3e5296e7 737 cfg -> SetPath(_T("/") + path);
8ec2b484
HH
738 }
739
0646614d
VS
740 m_Cfg.navig_on = cfg -> Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
741 m_Cfg.sashpos = cfg -> Read(wxT("hcSashPos"), m_Cfg.sashpos);
742 m_Cfg.x = cfg -> Read(wxT("hcX"), m_Cfg.x);
743 m_Cfg.y = cfg -> Read(wxT("hcY"), m_Cfg.y);
744 m_Cfg.w = cfg -> Read(wxT("hcW"), m_Cfg.w);
745 m_Cfg.h = cfg -> Read(wxT("hcH"), m_Cfg.h);
8ec2b484 746
0646614d
VS
747 m_FixedFace = cfg -> Read(wxT("hcFixedFace"), m_FixedFace);
748 m_NormalFace = cfg -> Read(wxT("hcNormalFace"), m_NormalFace);
749 m_FontSize = cfg -> Read(wxT("hcFontSize"), m_FontSize);
83efdf33 750
382e6efe
VS
751 {
752 int i;
753 int cnt;
754 wxString val, s;
755
0646614d 756 cnt = cfg -> Read(wxT("hcBookmarksCnt"), 0L);
382e6efe
VS
757 if (cnt != 0) {
758 m_BookmarksNames.Clear();
759 m_BookmarksPages.Clear();
760 if (m_Bookmarks) {
761 m_Bookmarks -> Clear();
ae80f837 762 m_Bookmarks -> Append(_("(bookmarks)"));
382e6efe
VS
763 }
764
765 for (i = 0; i < cnt; i++) {
0413cec5 766 val.Printf(wxT("hcBookmark_%i"), i);
382e6efe
VS
767 s = cfg -> Read(val);
768 m_BookmarksNames.Add(s);
769 if (m_Bookmarks) m_Bookmarks -> Append(s);
0413cec5 770 val.Printf(wxT("hcBookmark_%i_url"), i);
382e6efe
VS
771 s = cfg -> Read(val);
772 m_BookmarksPages.Add(s);
773 }
774 }
775 }
776
8ec2b484 777 if (m_HtmlWin)
3e5296e7 778 m_HtmlWin->ReadCustomization(cfg);
8ec2b484
HH
779
780 if (path != wxEmptyString)
781 cfg -> SetPath(oldpath);
782}
783
784void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
785{
786 wxString oldpath;
787 wxString tmp;
8ec2b484
HH
788
789 if (path != wxEmptyString) {
790 oldpath = cfg -> GetPath();
3e5296e7 791 cfg -> SetPath(_T("/") + path);
8ec2b484
HH
792 }
793
0646614d
VS
794 cfg -> Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
795 cfg -> Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
796 cfg -> Write(wxT("hcX"), (long)m_Cfg.x);
797 cfg -> Write(wxT("hcY"), (long)m_Cfg.y);
798 cfg -> Write(wxT("hcW"), (long)m_Cfg.w);
799 cfg -> Write(wxT("hcH"), (long)m_Cfg.h);
800 cfg -> Write(wxT("hcFixedFace"), m_FixedFace);
801 cfg -> Write(wxT("hcNormalFace"), m_NormalFace);
802 cfg -> Write(wxT("hcFontSize"), (long)m_FontSize);
382e6efe
VS
803
804 if (m_Bookmarks) {
805 int i;
806 int cnt = m_BookmarksNames.GetCount();
807 wxString val;
808
0646614d 809 cfg -> Write(wxT("hcBookmarksCnt"), (long)cnt);
382e6efe 810 for (i = 0; i < cnt; i++) {
0413cec5 811 val.Printf(wxT("hcBookmark_%i"), i);
382e6efe 812 cfg -> Write(val, m_BookmarksNames[i]);
0413cec5 813 val.Printf(wxT("hcBookmark_%i_url"), i);
382e6efe
VS
814 cfg -> Write(val, m_BookmarksPages[i]);
815 }
816 }
8ec2b484
HH
817
818 if (m_HtmlWin)
3e5296e7 819 m_HtmlWin->WriteCustomization(cfg);
8ec2b484
HH
820
821 if (path != wxEmptyString)
822 cfg -> SetPath(oldpath);
823}
824
825
83efdf33
VS
826
827
828
8eb2940f 829static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
83efdf33 830{
0646614d 831 static int f_sizes[5][7] =
83efdf33 832 {
0646614d 833 { 6, 7, 9, 12, 14, 16, 19},
f151e8b5 834 { 8, 9, 12, 14, 16, 19, 22},
83efdf33 835 {10, 12, 14, 16, 19, 24, 32},
0646614d
VS
836 {14, 16, 18, 24, 32, 38, 45},
837 {16, 20, 24, 32, 38, 45, 50}
83efdf33 838 };
f151e8b5 839
8eb2940f 840 win -> SetFonts(scalf, fixf, f_sizes[size]);
83efdf33
VS
841}
842
843
844class wxHtmlHelpFrameOptionsDialog : public wxDialog
845{
846 public:
f151e8b5 847 wxComboBox *NormalFont, *FixedFont;
83efdf33
VS
848 wxRadioBox *RadioBox;
849 wxHtmlWindow *TestWin;
850
851 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
852 {
0646614d 853 wxString choices[5] = {_("very small"), _("small"), _("medium"), _("large"), _("very large")};
8eb2940f 854 wxBoxSizer *topsizer, *sizer, *sizer2;
83efdf33
VS
855
856 topsizer = new wxBoxSizer(wxVERTICAL);
857
858 sizer = new wxBoxSizer(wxHORIZONTAL);
859
6f67eafe 860 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL);
382e6efe 861 sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
382e6efe 862 wxSize(200, 200),
382e6efe 863 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
83efdf33
VS
864 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
865
6f67eafe 866 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
83efdf33 867
6f67eafe 868 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL);
382e6efe 869 sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
382e6efe 870 wxSize(200, 200),
382e6efe 871 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
83efdf33
VS
872 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
873
6f67eafe 874 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
83efdf33
VS
875
876 topsizer -> Add(sizer);
877
878 topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
0646614d 879 wxDefaultPosition, wxDefaultSize, 5, choices, 5),
6f67eafe 880 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
83efdf33
VS
881
882 topsizer -> Add(new wxStaticText(this, -1, _("Preview:")),
883 0, wxLEFT | wxTOP, 10);
884 topsizer -> Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)),
6f67eafe 885 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
83efdf33
VS
886
887 sizer = new wxBoxSizer(wxHORIZONTAL);
888 sizer -> Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10);
889 sizer -> Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10);
890 topsizer -> Add(sizer, 0, wxALIGN_RIGHT);
891
892 SetAutoLayout(TRUE);
893 SetSizer(topsizer);
894 topsizer -> Fit(this);
895 Centre(wxBOTH);
896 }
897
898
899 void UpdateTestWin()
900 {
901 wxBusyCursor bcur;
902 SetFontsToHtmlWin(TestWin,
8eb2940f
VS
903 NormalFont -> GetStringSelection(),
904 FixedFont -> GetStringSelection(),
83efdf33
VS
905 RadioBox -> GetSelection());
906 TestWin -> SetPage(_("<html><body>"
907 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
908 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
909 "<font size=-2>font size -2</font><br>"
910 "<font size=-1>font size -1</font><br>"
911 "<font size=+0>font size +0</font><br>"
912 "<font size=+1>font size +1</font><br>"
913 "<font size=+2>font size +2</font><br>"
914 "<font size=+3>font size +3</font><br>"
915 "<font size=+4>font size +4</font><br>"
916
917 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
74cfc369 918 "<b><i>bold italic <u>underlined</u></i></b><br>"
83efdf33
VS
919 "<font size=-2>font size -2</font><br>"
920 "<font size=-1>font size -1</font><br>"
921 "<font size=+0>font size +0</font><br>"
922 "<font size=+1>font size +1</font><br>"
923 "<font size=+2>font size +2</font><br>"
924 "<font size=+3>font size +3</font><br>"
74cfc369 925 "<font size=+4>font size +4</font></tt>"
83efdf33
VS
926 "</body></html>"));
927 }
928
658fb8e6 929 void OnUpdate(wxCommandEvent& event)
83efdf33
VS
930 {
931 UpdateTestWin();
932 }
933
934 DECLARE_EVENT_TABLE()
935};
936
937BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
f151e8b5 938 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
83efdf33 939 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
83efdf33
VS
940END_EVENT_TABLE()
941
942
943void wxHtmlHelpFrame::OptionsDialog()
944{
945 wxHtmlHelpFrameOptionsDialog dlg(this);
946 unsigned i;
947
948 if (m_NormalFonts == NULL) {
949 wxFontEnumerator enu;
950 enu.EnumerateFacenames();
951 m_NormalFonts = new wxArrayString;
952 *m_NormalFonts = *enu.GetFacenames();
953 m_NormalFonts -> Sort();
954 }
955 if (m_FixedFonts == NULL) {
956 wxFontEnumerator enu;
957 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);
958 m_FixedFonts = new wxArrayString;
959 *m_FixedFonts = *enu.GetFacenames();
960 m_FixedFonts -> Sort();
961 }
962
963 for (i = 0; i < m_NormalFonts -> GetCount(); i++)
964 dlg.NormalFont -> Append((*m_NormalFonts)[i]);
965 for (i = 0; i < m_FixedFonts -> GetCount(); i++)
966 dlg.FixedFont -> Append((*m_FixedFonts)[i]);
967 if (!m_NormalFace.IsEmpty()) dlg.NormalFont -> SetStringSelection(m_NormalFace);
968 else dlg.NormalFont -> SetSelection(0);
969 if (!m_FixedFace.IsEmpty()) dlg.FixedFont -> SetStringSelection(m_FixedFace);
970 else dlg.FixedFont -> SetSelection(0);
971 dlg.RadioBox -> SetSelection(m_FontSize);
83efdf33
VS
972 dlg.UpdateTestWin();
973
974 if (dlg.ShowModal() == wxID_OK) {
975 m_NormalFace = dlg.NormalFont -> GetStringSelection();
976 m_FixedFace = dlg.FixedFont -> GetStringSelection();
977 m_FontSize = dlg.RadioBox -> GetSelection();
8eb2940f 978 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
83efdf33
VS
979 }
980}
981
982
983
0646614d
VS
984void wxHtmlHelpFrame::NotifyPageChanged()
985{
986 if (m_UpdateContents && m_PagesHash)
987 {
988 wxString an = m_HtmlWin -> GetOpenedAnchor();
989 wxHtmlHelpHashData *ha;
990 if (an.IsEmpty())
991 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
992 else
993 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
994 if (ha)
995 {
996 bool olduc = m_UpdateContents;
997 m_UpdateContents = FALSE;
998 m_ContentsBox -> SelectItem(ha -> m_Id);
999 m_ContentsBox -> EnsureVisible(ha -> m_Id);
1000 m_UpdateContents = olduc;
1001 }
1002 }
1003}
1004
83efdf33
VS
1005
1006
8ec2b484
HH
1007/*
1008EVENT HANDLING :
1009*/
1010
1011
1012void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
1013{
1014 switch (event.GetId()) {
382e6efe 1015
8ec2b484
HH
1016 case wxID_HTML_BACK :
1017 m_HtmlWin -> HistoryBack();
0646614d 1018 NotifyPageChanged();
8ec2b484 1019 break;
382e6efe 1020
8ec2b484
HH
1021 case wxID_HTML_FORWARD :
1022 m_HtmlWin -> HistoryForward();
0646614d
VS
1023 NotifyPageChanged();
1024 break;
1025
1026 case wxID_HTML_UP :
1027 if (m_PagesHash)
1028 {
1029 wxString an = m_HtmlWin -> GetOpenedAnchor();
1030 wxHtmlHelpHashData *ha;
1031 if (an.IsEmpty())
1032 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
1033 else
1034 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
1035 if (ha && ha -> m_Index > 0)
1036 {
1037 wxHtmlContentsItem *it = m_Data -> GetContents() + (ha -> m_Index - 1);
1038 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1039 NotifyPageChanged();
1040 }
1041 }
1042 break;
1043
1044 case wxID_HTML_UPNODE :
1045 if (m_PagesHash)
1046 {
1047 wxString an = m_HtmlWin -> GetOpenedAnchor();
1048 wxHtmlHelpHashData *ha;
1049 if (an.IsEmpty())
1050 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
1051 else
1052 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
1053 if (ha && ha -> m_Index > 0)
1054 {
1055 int level = m_Data -> GetContents()[ha -> m_Index].m_Level - 1;
1056 wxHtmlContentsItem *it;
1057 int ind = ha -> m_Index - 1;
1058
1059 it = m_Data -> GetContents() + ind;
1060 while (ind >= 0 && it -> m_Level != level) ind--, it--;
1061 if (ind >= 0)
1062 {
1063 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1064 NotifyPageChanged();
1065 }
1066 }
1067 }
1068 break;
1069
1070 case wxID_HTML_DOWN :
1071 if (m_PagesHash)
1072 {
1073 wxString an = m_HtmlWin -> GetOpenedAnchor();
721ab905 1074 wxString adr;
0646614d 1075 wxHtmlHelpHashData *ha;
721ab905
VS
1076
1077 if (an.IsEmpty()) adr = m_HtmlWin -> GetOpenedPage();
1078 else adr = m_HtmlWin -> GetOpenedPage() + wxT("#") + an;
1079
1080 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(adr);
0646614d
VS
1081
1082 if (ha && ha -> m_Index < m_Data -> GetContentsCnt() - 1)
1083 {
1084 wxHtmlContentsItem *it = m_Data -> GetContents() + (ha -> m_Index + 1);
721ab905
VS
1085
1086 while (it -> m_Book -> GetBasePath() + it -> m_Page == adr) it++;
0646614d
VS
1087 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1088 NotifyPageChanged();
1089 }
1090 }
8ec2b484 1091 break;
382e6efe 1092
8ec2b484 1093 case wxID_HTML_PANEL :
0646614d
VS
1094 {
1095 if (! (m_Splitter && m_NavigPan))
1096 return ;
1097 if (m_Splitter -> IsSplit()) {
1098 m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1099 m_Splitter -> Unsplit(m_NavigPan);
1100 m_Cfg.navig_on = FALSE;
1101 } else {
1102 m_NavigPan -> Show(TRUE);
1103 m_HtmlWin -> Show(TRUE);
1104 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
1105 m_Cfg.navig_on = TRUE;
1106 }
8ec2b484
HH
1107 }
1108 break;
382e6efe 1109
83efdf33
VS
1110 case wxID_HTML_OPTIONS :
1111 OptionsDialog();
1112 break;
382e6efe
VS
1113
1114 case wxID_HTML_BOOKMARKSADD :
1115 {
1116 wxString item;
1117 wxString url;
1118
1119 item = m_HtmlWin -> GetOpenedPageTitle();
1120 url = m_HtmlWin -> GetOpenedPage();
1121 if (item == wxEmptyString) item = url.AfterLast(wxT('/'));
1122 if (m_BookmarksPages.Index(url) == wxNOT_FOUND) {
1123 m_Bookmarks -> Append(item);
1124 m_BookmarksNames.Add(item);
1125 m_BookmarksPages.Add(url);
1126 }
1127 }
1128 break;
1129
1130 case wxID_HTML_BOOKMARKSREMOVE :
1131 {
1132 wxString item;
1133 int pos;
1134
1135 item = m_Bookmarks -> GetStringSelection();
1136 pos = m_BookmarksNames.Index(item);
1137 if (pos != wxNOT_FOUND) {
1138 m_BookmarksNames.Remove(pos);
1139 m_BookmarksPages.Remove(pos);
1140 m_Bookmarks -> Delete(m_Bookmarks -> GetSelection());
1141 }
1142 }
1143 break;
0646614d
VS
1144
1145#if wxUSE_PRINTING_ARCHITECTURE
1146 case wxID_HTML_PRINT :
1147 {
1148 if (m_Printer == NULL)
1149 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
1150 m_Printer -> PrintFile(m_HtmlWin -> GetOpenedPage());
1151 }
1152 break;
1153#endif
1154
1155 case wxID_HTML_OPENFILE :
1156 {
1157 wxString s = wxFileSelector(_("Open HTML document"), wxEmptyString, wxEmptyString, wxEmptyString,
1158 wxT("HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|"
1159 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|"
1160 "HTML Help Project (*.hhp)|*.hhp|"
1161 "All files (*.*)|*"),
1162 wxOPEN | wxFILE_MUST_EXIST, this);
1163 if (!s.IsEmpty())
1164 {
1165 wxString ext = s.Right(4).Lower();
1166 if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp"))
1167 {
1168 wxBusyCursor bcur;
1169 m_Data -> AddBook(s);
1170 RefreshLists();
1171 }
1172 else
1173 m_HtmlWin -> LoadPage(s);
1174 }
1175 }
1176 break;
8ec2b484
HH
1177 }
1178}
1179
1180
1181
1182void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
1183{
1184 wxHtmlHelpTreeItemData *pg;
0646614d 1185 wxHtmlContentsItem *it;
8ec2b484
HH
1186
1187 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
0646614d
VS
1188
1189 if (pg && m_UpdateContents)
1190 {
1191 it = m_Data -> GetContents() + (pg -> m_Id);
1192 m_UpdateContents = FALSE;
1193 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1194 m_UpdateContents = TRUE;
1195 }
8ec2b484
HH
1196}
1197
1198
1199
a4c97004 1200void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
8ec2b484 1201{
f0b6a33f 1202 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList -> GetClientData(m_IndexList -> GetSelection());
c32bfc10 1203 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
0646614d 1204 NotifyPageChanged();
8ec2b484
HH
1205}
1206
1207
f0b6a33f
VS
1208void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
1209{
1210 wxString sr = m_IndexText -> GetLineText(0);
240c2873 1211 sr.MakeLower();
f0b6a33f
VS
1212 if (sr == wxEmptyString)
1213 OnIndexAll(event);
1214
1215 else {
1216 wxBusyCursor bcur;
1217 const wxChar *cstr = sr.c_str();
240c2873 1218 wxChar mybuff[512], *ptr;
f0b6a33f
VS
1219 bool first = TRUE;
1220
1221 m_IndexList->Clear();
1222 int cnt = m_Data->GetIndexCnt();
1223 wxHtmlContentsItem* index = m_Data->GetIndex();
1224
240c2873 1225 int displ = 0;
f0b6a33f 1226 for (int i = 0; i < cnt; i++)
240c2873
VS
1227 {
1228 wxStrncpy(mybuff, index[i].m_Name, 512);
1229 mybuff[511] = 0;
1230 for (ptr = mybuff; *ptr != 0; ptr++)
1231 if (*ptr >= 'A' && *ptr <= 'Z') *ptr -= 'A' - 'a';
1232 if (wxStrstr(mybuff, cstr) != NULL) {
f0b6a33f 1233 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
240c2873 1234 displ++;
f0b6a33f
VS
1235 if (first) {
1236 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
0646614d 1237 NotifyPageChanged();
f0b6a33f
VS
1238 first = FALSE;
1239 }
1240 }
240c2873
VS
1241 }
1242
1243 wxString cnttext;
1244 cnttext.Printf(_("%i of %i"), displ, cnt);
1245 m_IndexCountInfo -> SetLabel(cnttext);
f0b6a33f
VS
1246
1247 m_IndexText -> SetSelection(0, sr.Length());
1248 m_IndexText -> SetFocus();
1249 }
1250}
1251
1252void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1253{
1254 wxBusyCursor bcur;
1255
1256 m_IndexList->Clear();
1257 int cnt = m_Data->GetIndexCnt();
1258 bool first = TRUE;
1259 wxHtmlContentsItem* index = m_Data->GetIndex();
1260
1261 for (int i = 0; i < cnt; i++) {
1262 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
1263 if (first) {
1264 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
0646614d 1265 NotifyPageChanged();
f0b6a33f
VS
1266 first = FALSE;
1267 }
1268 }
240c2873
VS
1269
1270 wxString cnttext;
1271 cnttext.Printf(_("%i of %i"), cnt, cnt);
1272 m_IndexCountInfo -> SetLabel(cnttext);
f0b6a33f
VS
1273}
1274
8ec2b484 1275
a4c97004 1276void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
8ec2b484
HH
1277{
1278 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
0646614d
VS
1279 if (it)
1280 {
1281 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1282 NotifyPageChanged();
1283 }
8ec2b484
HH
1284}
1285
a4c97004 1286void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
8ec2b484
HH
1287{
1288 wxString sr = m_SearchText -> GetLineText(0);
1289
1290 if (sr != wxEmptyString) KeywordSearch(sr);
1291}
1292
382e6efe
VS
1293void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1294{
1295 wxString sr = m_Bookmarks -> GetStringSelection();
1296
ae80f837 1297 if (sr != wxEmptyString && sr != _("(bookmarks)"))
0646614d
VS
1298 {
1299 m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
1300 NotifyPageChanged();
1301 }
382e6efe
VS
1302}
1303
8ec2b484
HH
1304void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1305{
68364659
VS
1306 GetSize(&m_Cfg.w, &m_Cfg.h);
1307 GetPosition(&m_Cfg.x, &m_Cfg.y);
5c172c17 1308
68364659
VS
1309 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1310
d5bb85a0
VS
1311 if (m_Config)
1312 WriteCustomization(m_Config, m_ConfigRoot);
68364659 1313
b4414c1f
JS
1314 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
1315 {
1316 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
1317 }
1318
8ec2b484
HH
1319 evt.Skip();
1320}
1321
1322BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
ae80f837
VS
1323 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar)
1324 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1325 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar)
8ec2b484
HH
1326 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1327 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1328 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1329 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1330 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
f0b6a33f
VS
1331 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1332 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1333 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
382e6efe
VS
1334 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
1335 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
8ec2b484
HH
1336END_EVENT_TABLE()
1337
1338#endif