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