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