]>
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 | ||
24 | #include "wx/defs.h" | |
25 | ||
26 | #if wxUSE_HTML | |
8ec2b484 | 27 | #ifndef WXPRECOMP |
3096bd2f | 28 | #include "wx/wx.h" |
8ec2b484 HH |
29 | #endif |
30 | ||
31 | #include "wx/html/helpfrm.h" | |
32 | #include "wx/notebook.h" | |
33 | #include "wx/imaglist.h" | |
34 | #include "wx/treectrl.h" | |
35 | #include "wx/tokenzr.h" | |
36 | #include "wx/wfstream.h" | |
37 | #include "wx/html/htmlwin.h" | |
38 | #include "wx/busyinfo.h" | |
39 | #include "wx/progdlg.h" | |
2bd5bbc9 | 40 | #include "wx/toolbar.h" |
83efdf33 | 41 | #include "wx/fontenum.h" |
8ec2b484 HH |
42 | |
43 | // Bitmaps: | |
44 | ||
45 | #ifndef __WXMSW__ | |
83efdf33 VS |
46 | #include "bitmaps/wpanel.xpm" |
47 | #include "bitmaps/wback.xpm" | |
48 | #include "bitmaps/wforward.xpm" | |
49 | #include "bitmaps/wbook.xpm" | |
50 | #include "bitmaps/woptions.xpm" | |
51 | #include "bitmaps/wfolder.xpm" | |
52 | #include "bitmaps/wpage.xpm" | |
53 | #include "bitmaps/whelp.xpm" | |
54 | #include "bitmaps/whlproot.xpm" | |
8ec2b484 HH |
55 | #endif |
56 | ||
57 | #include "wx/stream.h" | |
58 | ||
59 | // number of times that the contents/index creation progress dialog | |
60 | // is updated. | |
d5bb85a0 | 61 | #define PROGRESS_STEP 40 |
8ec2b484 HH |
62 | |
63 | //-------------------------------------------------------------------------- | |
64 | // wxHtmlHelpTreeItemData | |
65 | //-------------------------------------------------------------------------- | |
66 | ||
67 | class wxHtmlHelpTreeItemData : public wxTreeItemData | |
68 | { | |
69 | private: | |
70 | wxString m_Page; | |
71 | ||
72 | public: | |
d5bb85a0 VS |
73 | wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData() |
74 | { | |
75 | m_Page = it -> m_Book -> GetBasePath() + it -> m_Page; | |
76 | } | |
77 | const wxString& GetPage() { return m_Page; } | |
8ec2b484 HH |
78 | }; |
79 | ||
80 | //--------------------------------------------------------------------------- | |
81 | // wxHtmlHelpFrame | |
82 | //--------------------------------------------------------------------------- | |
83 | ||
84 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame) | |
85 | ||
86 | wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title, | |
d5bb85a0 | 87 | int style, wxHtmlHelpData* data) |
8ec2b484 HH |
88 | { |
89 | Init(data); | |
90 | Create(parent, id, title, style); | |
91 | } | |
d5bb85a0 | 92 | |
8ec2b484 HH |
93 | void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) |
94 | { | |
95 | if (data) { | |
d5bb85a0 VS |
96 | m_Data = data; |
97 | m_DataCreated = FALSE; | |
98 | } else { | |
99 | m_Data = new wxHtmlHelpData(); | |
100 | m_DataCreated = TRUE; | |
8ec2b484 HH |
101 | } |
102 | ||
68364659 | 103 | m_ContentsImageList = new wxImageList(16, 16); |
83efdf33 VS |
104 | m_ContentsImageList -> Add(wxICON(wbook)); |
105 | m_ContentsImageList -> Add(wxICON(wfolder)); | |
106 | m_ContentsImageList -> Add(wxICON(wpage)); | |
107 | m_ContentsImageList -> Add(wxICON(whlproot)); | |
8ec2b484 HH |
108 | |
109 | m_ContentsBox = NULL; | |
110 | m_IndexBox = NULL; | |
111 | m_SearchList = NULL; | |
112 | m_SearchButton = NULL; | |
113 | m_SearchText = NULL; | |
114 | m_SearchChoice = NULL; | |
115 | m_Splitter = NULL; | |
116 | m_NavigPan = NULL; | |
117 | m_HtmlWin = NULL; | |
118 | m_Config = NULL; | |
119 | m_ConfigRoot = wxEmptyString; | |
120 | ||
121 | m_Cfg.x = m_Cfg.y = 0; | |
d5bb85a0 VS |
122 | m_Cfg.w = 700; |
123 | m_Cfg.h = 480; | |
8ec2b484 HH |
124 | m_Cfg.sashpos = 240; |
125 | m_Cfg.navig_on = TRUE; | |
83efdf33 VS |
126 | |
127 | m_NormalFonts = m_FixedFonts = NULL; | |
128 | m_FontSize = 1; | |
129 | m_NormalFace = m_FixedFace = wxEmptyString; | |
130 | m_NormalItalic = m_FixedItalic = wxSLANT; | |
8ec2b484 HH |
131 | } |
132 | ||
d5bb85a0 VS |
133 | // Create: builds the GUI components. |
134 | // with the style flag it's possible to toggle the toolbar, contents, index and search | |
135 | // controls. | |
136 | // m_HtmlWin will *always* be created, but it's important to realize that | |
137 | // m_ContentsBox, m_IndexBox, m_SearchList, m_SearchButton, m_SearchText and | |
138 | // m_SearchButton may be NULL. | |
139 | // moreover, if no contents, index or searchpage is needed, m_Splitter and | |
140 | // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame) | |
141 | ||
8ec2b484 | 142 | bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title, |
d5bb85a0 | 143 | int style) |
8ec2b484 HH |
144 | { |
145 | // Do the config in two steps. We read the HtmlWindow customization after we | |
146 | // create the window. | |
d5bb85a0 VS |
147 | if (m_Config) |
148 | ReadCustomization(m_Config, m_ConfigRoot); | |
8ec2b484 | 149 | |
68364659 | 150 | wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h)); |
8ec2b484 | 151 | |
5c172c17 VS |
152 | GetPosition(&m_Cfg.x, &m_Cfg.y); |
153 | ||
83efdf33 | 154 | SetIcon(wxICON(whelp)); |
9ffdee80 | 155 | |
8ec2b484 HH |
156 | int notebook_page = 0; |
157 | ||
158 | CreateStatusBar(); | |
159 | ||
160 | // toolbar? | |
161 | if (style & wxHF_TOOLBAR) { | |
83efdf33 | 162 | wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE); |
d5bb85a0 | 163 | toolBar -> SetMargins(2, 2); |
d5bb85a0 | 164 | |
83efdf33 VS |
165 | toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap, |
166 | FALSE, -1, -1, (wxObject *) NULL, | |
d5bb85a0 | 167 | _("Show/hide navigation panel")); |
d5bb85a0 | 168 | toolBar -> AddSeparator(); |
83efdf33 VS |
169 | toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap, |
170 | FALSE, -1, -1, (wxObject *) NULL, | |
d5bb85a0 | 171 | _("Go back to the previous HTML page")); |
83efdf33 VS |
172 | toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap, |
173 | FALSE, -1, -1, (wxObject *) NULL, | |
d5bb85a0 | 174 | _("Go forward to the next HTML page")); |
d5bb85a0 | 175 | |
83efdf33 VS |
176 | toolBar -> AddSeparator(); |
177 | toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap, | |
178 | FALSE, -1, -1, (wxObject *) NULL, | |
179 | _("Display options dialog")); | |
d5bb85a0 | 180 | |
83efdf33 | 181 | toolBar -> Realize(); |
8ec2b484 | 182 | } |
d5bb85a0 | 183 | |
8ec2b484 | 184 | if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) { |
d5bb85a0 VS |
185 | // traditional help controller; splitter window with html page on the |
186 | // right and a notebook containing various pages on the left | |
187 | m_Splitter = new wxSplitterWindow(this); | |
188 | ||
189 | m_HtmlWin = new wxHtmlWindow(m_Splitter); | |
190 | m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK, | |
191 | wxDefaultPosition, wxDefaultSize); | |
192 | } else { // only html window, no notebook with index,contents etc | |
193 | m_HtmlWin = new wxHtmlWindow(this); | |
8ec2b484 HH |
194 | } |
195 | ||
196 | m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat); | |
197 | m_HtmlWin -> SetRelatedStatusBar(0); | |
d5bb85a0 VS |
198 | if (m_Config) |
199 | m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot); | |
8ec2b484 HH |
200 | |
201 | // contents tree panel? | |
202 | if (style & wxHF_CONTENTS) { | |
d5bb85a0 VS |
203 | m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL, |
204 | wxDefaultPosition, wxDefaultSize, | |
205 | wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); | |
206 | m_ContentsBox -> SetImageList(m_ContentsImageList); | |
207 | m_NavigPan -> AddPage(m_ContentsBox, _("Contents")); | |
208 | m_ContentsPage = notebook_page++; | |
8ec2b484 HH |
209 | } |
210 | ||
211 | // index listbox panel? | |
212 | if (style & wxHF_INDEX) { | |
d5bb85a0 VS |
213 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE); |
214 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
215 | b1 -> top.SameAs (dummy, wxTop, 0); | |
216 | b1 -> left.SameAs (dummy, wxLeft, 0); | |
217 | b1 -> width.PercentOf (dummy, wxWidth, 100); | |
218 | b1 -> bottom.SameAs (dummy, wxBottom, 0); | |
219 | m_IndexBox = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, | |
220 | wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB); | |
221 | m_IndexBox -> SetConstraints(b1); | |
222 | dummy -> SetAutoLayout(TRUE); | |
223 | m_NavigPan -> AddPage(dummy, _("Index")); | |
224 | m_IndexPage = notebook_page++; | |
8ec2b484 HH |
225 | } |
226 | ||
227 | // search list panel? | |
228 | if (style & wxHF_SEARCH) { | |
d5bb85a0 VS |
229 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE); |
230 | ||
231 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
232 | m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT); | |
233 | b1 -> top.SameAs (dummy, wxTop, 10); | |
234 | b1 -> left.SameAs (dummy, wxLeft, 10); | |
235 | b1 -> right.SameAs (dummy, wxRight, 10); | |
236 | b1 -> height.AsIs(); | |
237 | m_SearchText -> SetConstraints(b1); | |
238 | ||
239 | wxLayoutConstraints *b2 = new wxLayoutConstraints; | |
240 | m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search")); | |
241 | b2 -> top.Below (m_SearchText, 10); | |
242 | b2 -> left.SameAs (dummy, wxLeft, 10); | |
243 | b2 -> width.AsIs(); | |
244 | b2 -> height.AsIs(); | |
245 | m_SearchButton -> SetConstraints(b2); | |
246 | ||
d5bb85a0 VS |
247 | wxLayoutConstraints *b4 = new wxLayoutConstraints; |
248 | m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition, | |
249 | wxDefaultSize); | |
250 | b4 -> top.Below (m_SearchText, 10); | |
251 | b4 -> left.SameAs (m_SearchButton, wxRight, 10); | |
252 | b4 -> right.SameAs (dummy, wxRight, 10); | |
253 | b4 -> height.AsIs(); | |
254 | m_SearchChoice -> SetConstraints(b4); | |
255 | ||
954269e6 VS |
256 | wxLayoutConstraints *b3 = new wxLayoutConstraints; |
257 | m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0); | |
258 | b3 -> top.Below (m_SearchButton, 10); | |
259 | b3 -> left.SameAs (dummy, wxLeft, 0); | |
260 | b3 -> right.SameAs (dummy, wxRight, 0); | |
261 | b3 -> bottom.SameAs (dummy, wxBottom, 0); | |
262 | m_SearchList -> SetConstraints(b3); | |
263 | ||
d5bb85a0 VS |
264 | dummy -> SetAutoLayout(TRUE); |
265 | dummy -> Layout(); | |
266 | m_NavigPan -> AddPage(dummy, _("Search")); | |
267 | m_SearchPage = notebook_page++; | |
8ec2b484 | 268 | } |
c32bfc10 | 269 | m_HtmlWin -> Show(TRUE); |
8ec2b484 HH |
270 | |
271 | //RefreshLists(); | |
272 | ||
273 | // showtime | |
274 | if (m_NavigPan && m_Splitter) { | |
d5bb85a0 | 275 | m_Splitter -> SetMinimumPaneSize(20); |
f38374d0 DW |
276 | if (m_Cfg.navig_on) |
277 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
278 | else { | |
279 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
280 | m_Splitter -> Unsplit(); | |
281 | } | |
c32bfc10 VS |
282 | if (m_Cfg.navig_on) { |
283 | m_NavigPan -> Show(TRUE); | |
d5bb85a0 | 284 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
c32bfc10 | 285 | } |
68364659 | 286 | else { |
c32bfc10 VS |
287 | m_NavigPan -> Show(FALSE); |
288 | m_Splitter -> Initialize(m_HtmlWin); | |
68364659 | 289 | } |
8ec2b484 | 290 | } |
8ec2b484 HH |
291 | return TRUE; |
292 | } | |
293 | ||
294 | wxHtmlHelpFrame::~wxHtmlHelpFrame() | |
295 | { | |
296 | delete m_ContentsImageList; | |
297 | if (m_DataCreated) | |
d5bb85a0 | 298 | delete m_Data; |
83efdf33 VS |
299 | if (m_NormalFonts) delete m_NormalFonts; |
300 | if (m_FixedFonts) delete m_FixedFonts; | |
8ec2b484 HH |
301 | } |
302 | ||
303 | bool wxHtmlHelpFrame::Display(const wxString& x) | |
304 | { | |
305 | wxString url = m_Data->FindPageByName(x); | |
306 | if (! url.IsEmpty()) { | |
d5bb85a0 VS |
307 | m_HtmlWin->LoadPage(url); |
308 | return TRUE; | |
8ec2b484 HH |
309 | } |
310 | return FALSE; | |
311 | } | |
312 | ||
313 | bool wxHtmlHelpFrame::Display(const int id) | |
314 | { | |
315 | wxString url = m_Data->FindPageById(id); | |
316 | if (! url.IsEmpty()) { | |
d5bb85a0 VS |
317 | m_HtmlWin->LoadPage(url); |
318 | return TRUE; | |
8ec2b484 HH |
319 | } |
320 | return FALSE; | |
321 | } | |
322 | ||
323 | ||
324 | ||
325 | bool wxHtmlHelpFrame::DisplayContents() | |
326 | { | |
327 | if (! m_ContentsBox) | |
d5bb85a0 | 328 | return FALSE; |
8ec2b484 | 329 | if (!m_Splitter -> IsSplit()) { |
d5bb85a0 VS |
330 | m_NavigPan -> Show(TRUE); |
331 | m_HtmlWin -> Show(TRUE); | |
332 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
c32bfc10 | 333 | m_Cfg.navig_on = TRUE; |
8ec2b484 HH |
334 | } |
335 | m_NavigPan -> SetSelection(0); | |
336 | return TRUE; | |
337 | } | |
338 | ||
339 | ||
340 | ||
341 | bool wxHtmlHelpFrame::DisplayIndex() | |
342 | { | |
343 | if (! m_IndexBox) | |
d5bb85a0 | 344 | return FALSE; |
8ec2b484 | 345 | if (!m_Splitter -> IsSplit()) { |
d5bb85a0 VS |
346 | m_NavigPan -> Show(TRUE); |
347 | m_HtmlWin -> Show(TRUE); | |
348 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
8ec2b484 HH |
349 | } |
350 | m_NavigPan -> SetSelection(1); | |
351 | return TRUE; | |
352 | } | |
353 | ||
354 | bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) | |
355 | { | |
356 | if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice)) | |
d5bb85a0 | 357 | return FALSE; |
8ec2b484 HH |
358 | |
359 | int foundcnt = 0; | |
360 | wxString foundstr; | |
361 | wxString book = wxEmptyString; | |
362 | ||
363 | if (!m_Splitter -> IsSplit()) { | |
d5bb85a0 VS |
364 | m_NavigPan -> Show(TRUE); |
365 | m_HtmlWin -> Show(TRUE); | |
366 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
8ec2b484 HH |
367 | } |
368 | m_NavigPan -> SetSelection(m_SearchPage); | |
369 | m_SearchList -> Clear(); | |
370 | m_SearchText -> SetValue(keyword); | |
371 | m_SearchButton -> Enable(FALSE); | |
372 | ||
373 | if (m_SearchChoice->GetSelection() != 0) | |
d5bb85a0 | 374 | book = m_SearchChoice->GetStringSelection(); |
8ec2b484 HH |
375 | |
376 | wxHtmlSearchStatus status(m_Data, keyword, book); | |
377 | ||
d5bb85a0 VS |
378 | wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), |
379 | status.GetMaxIndex(), this, | |
380 | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); | |
8ec2b484 HH |
381 | |
382 | while (status.IsActive()) { | |
d5bb85a0 VS |
383 | if (progress.Update(status.GetCurIndex()) == FALSE) |
384 | break; | |
385 | if (status.Search()) { | |
386 | foundstr.Printf(_("Found %i matches"), ++foundcnt); | |
387 | progress.Update(status.GetCurIndex(), foundstr); | |
388 | m_SearchList -> Append(status.GetName(), status.GetContentsItem()); | |
389 | } | |
390 | wxYield(); | |
8ec2b484 HH |
391 | } |
392 | ||
393 | m_SearchButton -> Enable(TRUE); | |
394 | m_SearchText -> SetSelection(0, keyword.Length()); | |
395 | m_SearchText -> SetFocus(); | |
396 | if (foundcnt) { | |
397 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0); | |
398 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
399 | } | |
400 | return (foundcnt > 0); | |
401 | } | |
402 | ||
403 | #define MAX_ROOTS 64 | |
404 | ||
405 | void wxHtmlHelpFrame::CreateContents(bool show_progress) | |
406 | { | |
407 | if (! m_ContentsBox) | |
d5bb85a0 | 408 | return ; |
8ec2b484 | 409 | |
83efdf33 | 410 | wxProgressDialog *progress = NULL; |
8ec2b484 HH |
411 | wxString proginfo; |
412 | ||
413 | m_ContentsBox->Clear(); | |
414 | ||
415 | int cnt = m_Data->GetContentsCnt(); | |
416 | int div = (cnt / PROGRESS_STEP) + 1; | |
417 | int i; | |
418 | ||
83efdf33 | 419 | wxHtmlContentsItem *it; |
d5bb85a0 VS |
420 | |
421 | if (show_progress) | |
422 | progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString, | |
423 | cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | | |
424 | wxPD_AUTO_HIDE); | |
425 | ||
8ec2b484 HH |
426 | wxTreeItemId roots[MAX_ROOTS]; |
427 | bool imaged[MAX_ROOTS]; | |
428 | ||
429 | m_ContentsBox -> DeleteAllItems(); | |
430 | roots[0] = m_ContentsBox -> AddRoot(_("(Help)")); | |
5c172c17 VS |
431 | m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder); |
432 | m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder); | |
8ec2b484 HH |
433 | imaged[0] = TRUE; |
434 | ||
83efdf33 | 435 | for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) { |
d5bb85a0 VS |
436 | if (show_progress && ((i % div) == 0)) { |
437 | proginfo.Printf(_("Added %d/%d items"), i, cnt); | |
438 | if (! progress->Update(i, proginfo)) | |
439 | break; | |
440 | wxYield(); | |
441 | } | |
8ec2b484 | 442 | roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( |
d5bb85a0 VS |
443 | roots[it -> m_Level], it -> m_Name, IMG_Page, -1, |
444 | new wxHtmlHelpTreeItemData(it)); | |
8ec2b484 HH |
445 | |
446 | if (it -> m_Level == 0) { | |
447 | m_ContentsBox -> SetItemBold(roots[1], TRUE); | |
448 | m_ContentsBox -> SetItemImage(roots[1], IMG_Book); | |
449 | m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book); | |
450 | imaged[1] = TRUE; | |
d5bb85a0 | 451 | } else imaged[it -> m_Level + 1] = FALSE; |
8ec2b484 HH |
452 | |
453 | if (!imaged[it -> m_Level]) { | |
454 | m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder); | |
455 | m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder); | |
456 | imaged[it -> m_Level] = TRUE; | |
457 | } | |
458 | } | |
459 | if (show_progress) | |
d5bb85a0 | 460 | delete progress; |
8ec2b484 HH |
461 | m_ContentsBox -> Expand(roots[0]); |
462 | } | |
463 | ||
464 | ||
465 | void wxHtmlHelpFrame::CreateIndex(bool show_progress) | |
466 | { | |
467 | if (! m_IndexBox) | |
d5bb85a0 | 468 | return ; |
8ec2b484 | 469 | |
83efdf33 | 470 | wxProgressDialog *progress = NULL; |
8ec2b484 HH |
471 | wxString proginfo; |
472 | ||
473 | m_IndexBox->Clear(); | |
474 | ||
475 | int cnt = m_Data->GetIndexCnt(); | |
476 | int div = (cnt / PROGRESS_STEP) + 1; | |
477 | ||
478 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
479 | ||
d5bb85a0 VS |
480 | if (show_progress) |
481 | progress = new wxProgressDialog(_("Building index list..."), wxEmptyString, | |
482 | cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | | |
483 | wxPD_AUTO_HIDE); | |
8ec2b484 | 484 | for (int i = 0; i < cnt; i++) { |
d5bb85a0 VS |
485 | if (show_progress && ((i % div) == 0)) { |
486 | proginfo.Printf(_("Added %d/%d items"), i, cnt); | |
487 | if (! progress->Update(i, proginfo)) | |
488 | break; | |
489 | wxYield(); | |
490 | } | |
8ec2b484 HH |
491 | m_IndexBox -> Append(index[i].m_Name, (char*)(index + i)); |
492 | } | |
493 | ||
494 | if (show_progress) | |
d5bb85a0 | 495 | delete progress; |
8ec2b484 HH |
496 | } |
497 | ||
498 | void wxHtmlHelpFrame::CreateSearch() | |
499 | { | |
500 | if (! (m_SearchList && m_SearchChoice)) | |
d5bb85a0 | 501 | return ; |
8ec2b484 HH |
502 | m_SearchList -> Clear(); |
503 | m_SearchChoice -> Clear(); | |
504 | m_SearchChoice -> Append(_("all books")); | |
505 | const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); | |
506 | int i, cnt = bookrec.GetCount(); | |
d5bb85a0 VS |
507 | for (i = 0; i < cnt; i++) |
508 | m_SearchChoice->Append(bookrec[i].GetTitle()); | |
8ec2b484 HH |
509 | m_SearchChoice->SetSelection(0); |
510 | } | |
511 | ||
512 | ||
513 | void wxHtmlHelpFrame::RefreshLists(bool show_progress) | |
514 | { | |
515 | CreateContents(show_progress); | |
516 | CreateIndex(show_progress); | |
517 | CreateSearch(); | |
518 | } | |
519 | ||
520 | void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) | |
521 | { | |
522 | wxString oldpath; | |
523 | wxString tmp; | |
524 | ||
525 | if (path != wxEmptyString) { | |
526 | oldpath = cfg -> GetPath(); | |
527 | cfg -> SetPath(path); | |
528 | } | |
529 | ||
530 | m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0; | |
531 | m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos); | |
532 | m_Cfg.x = cfg -> Read("hcX", m_Cfg.x); | |
533 | m_Cfg.y = cfg -> Read("hcY", m_Cfg.y); | |
534 | m_Cfg.w = cfg -> Read("hcW", m_Cfg.w); | |
535 | m_Cfg.h = cfg -> Read("hcH", m_Cfg.h); | |
8ec2b484 | 536 | |
83efdf33 VS |
537 | m_FixedFace = cfg -> Read("hcFixedFace", m_FixedFace); |
538 | m_NormalFace = cfg -> Read("hcNormalFace", m_NormalFace); | |
539 | m_FontSize = cfg -> Read("hcFontSize", m_FontSize); | |
540 | m_NormalItalic = cfg -> Read("hcNormalItalic", m_NormalItalic); | |
541 | m_FixedItalic = cfg -> Read("hcFixedItalic", m_FixedItalic); | |
542 | ||
8ec2b484 | 543 | if (m_HtmlWin) |
d5bb85a0 | 544 | m_HtmlWin->ReadCustomization(cfg, path); |
8ec2b484 HH |
545 | |
546 | if (path != wxEmptyString) | |
547 | cfg -> SetPath(oldpath); | |
548 | } | |
549 | ||
550 | void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path) | |
551 | { | |
552 | wxString oldpath; | |
553 | wxString tmp; | |
8ec2b484 HH |
554 | |
555 | if (path != wxEmptyString) { | |
556 | oldpath = cfg -> GetPath(); | |
557 | cfg -> SetPath(path); | |
558 | } | |
559 | ||
560 | cfg -> Write("hcNavigPanel", m_Cfg.navig_on); | |
561 | cfg -> Write("hcSashPos", (long)m_Cfg.sashpos); | |
562 | cfg -> Write("hcX", (long)m_Cfg.x); | |
563 | cfg -> Write("hcY", (long)m_Cfg.y); | |
564 | cfg -> Write("hcW", (long)m_Cfg.w); | |
565 | cfg -> Write("hcH", (long)m_Cfg.h); | |
83efdf33 VS |
566 | cfg -> Write("hcFixedFace", m_FixedFace); |
567 | cfg -> Write("hcNormalFace", m_NormalFace); | |
568 | cfg -> Write("hcFontSize", (long)m_FontSize); | |
569 | cfg -> Write("hcNormalItalic", (long)m_NormalItalic); | |
570 | cfg -> Write("hcFixedItalic", (long)m_FixedItalic); | |
8ec2b484 HH |
571 | |
572 | if (m_HtmlWin) | |
d5bb85a0 | 573 | m_HtmlWin->WriteCustomization(cfg, path); |
8ec2b484 HH |
574 | |
575 | if (path != wxEmptyString) | |
576 | cfg -> SetPath(oldpath); | |
577 | } | |
578 | ||
579 | ||
83efdf33 VS |
580 | |
581 | ||
582 | ||
583 | static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, int scalit, wxString fixf, int fixit, int size) | |
584 | { | |
83efdf33 VS |
585 | static int f_sizes[3][7] = |
586 | { | |
f151e8b5 | 587 | { 8, 9, 12, 14, 16, 19, 22}, |
83efdf33 | 588 | {10, 12, 14, 16, 19, 24, 32}, |
83efdf33 VS |
589 | {14, 16, 18, 24, 32, 38, 45} |
590 | }; | |
f151e8b5 | 591 | |
83efdf33 VS |
592 | win -> SetFonts(scalf, scalit, fixf, fixit, f_sizes[size]); |
593 | } | |
594 | ||
595 | ||
596 | class wxHtmlHelpFrameOptionsDialog : public wxDialog | |
597 | { | |
598 | public: | |
f151e8b5 | 599 | wxComboBox *NormalFont, *FixedFont; |
83efdf33 VS |
600 | wxRadioButton *SFI_i, *SFI_s, *FFI_i, *FFI_s; |
601 | wxRadioBox *RadioBox; | |
602 | wxHtmlWindow *TestWin; | |
603 | ||
604 | wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options"))) | |
605 | { | |
f151e8b5 VS |
606 | wxString choices[3] = {_("small"), _("medium"), _("large")}; |
607 | wxString choices2[2] = {_("italic"), _("slant")}; | |
83efdf33 VS |
608 | wxBoxSizer *topsizer, *sizer, *sizer2, *sizer3; |
609 | ||
610 | topsizer = new wxBoxSizer(wxVERTICAL); | |
611 | ||
612 | sizer = new wxBoxSizer(wxHORIZONTAL); | |
613 | ||
614 | sizer2 = new wxBoxSizer(wxVERTICAL); | |
615 | sizer2 -> Add(new wxStaticText(this, -1, _("Normal font:")), | |
616 | 0, wxLEFT | wxTOP, 10); | |
f151e8b5 | 617 | sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), |
83efdf33 VS |
618 | 1, wxEXPAND | wxLEFT | wxRIGHT, 10); |
619 | ||
620 | sizer3 = new wxBoxSizer(wxHORIZONTAL); | |
621 | sizer3 -> Add(SFI_i = new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP), | |
622 | 1, wxEXPAND, 0); | |
623 | sizer3 -> Add(SFI_s = new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition, wxDefaultSize, 0), | |
624 | 1, wxEXPAND, 0); | |
625 | sizer2 -> Add(sizer3, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
626 | ||
627 | sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
628 | ||
629 | sizer2 = new wxBoxSizer(wxVERTICAL); | |
630 | sizer2 -> Add(new wxStaticText(this, -1, _("Fixed font:")), | |
631 | 0, wxLEFT | wxTOP, 10); | |
f151e8b5 | 632 | sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), |
83efdf33 VS |
633 | 1, wxEXPAND | wxLEFT | wxRIGHT, 10); |
634 | ||
635 | sizer3 = new wxBoxSizer(wxHORIZONTAL); | |
636 | sizer3 -> Add(FFI_i = new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP), | |
637 | 1, wxEXPAND, 0); | |
638 | sizer3 -> Add(FFI_s = new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition, wxDefaultSize, 0), | |
639 | 1, wxEXPAND, 0); | |
640 | sizer2 -> Add(sizer3, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
641 | ||
642 | sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
643 | ||
644 | topsizer -> Add(sizer); | |
645 | ||
646 | topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"), | |
647 | wxDefaultPosition, wxDefaultSize, 3, choices, 3), | |
648 | 0, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
649 | ||
650 | topsizer -> Add(new wxStaticText(this, -1, _("Preview:")), | |
651 | 0, wxLEFT | wxTOP, 10); | |
652 | topsizer -> Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)), | |
653 | 1, wxEXPAND | wxLEFT | wxTOP, 10); | |
654 | ||
655 | sizer = new wxBoxSizer(wxHORIZONTAL); | |
656 | sizer -> Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10); | |
657 | sizer -> Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10); | |
658 | topsizer -> Add(sizer, 0, wxALIGN_RIGHT); | |
659 | ||
660 | SetAutoLayout(TRUE); | |
661 | SetSizer(topsizer); | |
662 | topsizer -> Fit(this); | |
663 | Centre(wxBOTH); | |
664 | } | |
665 | ||
666 | ||
667 | void UpdateTestWin() | |
668 | { | |
669 | wxBusyCursor bcur; | |
670 | SetFontsToHtmlWin(TestWin, | |
671 | NormalFont -> GetStringSelection(), SFI_i -> GetValue() ? wxITALIC : wxSLANT, | |
672 | FixedFont -> GetStringSelection(), FFI_i -> GetValue() ? wxITALIC : wxSLANT, | |
673 | RadioBox -> GetSelection()); | |
674 | TestWin -> SetPage(_("<html><body>" | |
675 | "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> " | |
676 | "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>" | |
677 | "<font size=-2>font size -2</font><br>" | |
678 | "<font size=-1>font size -1</font><br>" | |
679 | "<font size=+0>font size +0</font><br>" | |
680 | "<font size=+1>font size +1</font><br>" | |
681 | "<font size=+2>font size +2</font><br>" | |
682 | "<font size=+3>font size +3</font><br>" | |
683 | "<font size=+4>font size +4</font><br>" | |
684 | ||
685 | "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> " | |
686 | "<b><i>bold italic <u>underlined</u></i></b></tt><br>" | |
687 | "<font size=-2>font size -2</font><br>" | |
688 | "<font size=-1>font size -1</font><br>" | |
689 | "<font size=+0>font size +0</font><br>" | |
690 | "<font size=+1>font size +1</font><br>" | |
691 | "<font size=+2>font size +2</font><br>" | |
692 | "<font size=+3>font size +3</font><br>" | |
693 | "<font size=+4>font size +4</font>" | |
694 | "</body></html>")); | |
695 | } | |
696 | ||
697 | void OnUpdate(wxCloseEvent& event) | |
698 | { | |
699 | UpdateTestWin(); | |
700 | } | |
701 | ||
702 | DECLARE_EVENT_TABLE() | |
703 | }; | |
704 | ||
705 | BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog) | |
f151e8b5 | 706 | EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) |
83efdf33 VS |
707 | EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) |
708 | EVT_RADIOBUTTON(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) | |
709 | END_EVENT_TABLE() | |
710 | ||
711 | ||
712 | void wxHtmlHelpFrame::OptionsDialog() | |
713 | { | |
714 | wxHtmlHelpFrameOptionsDialog dlg(this); | |
715 | unsigned i; | |
716 | ||
717 | if (m_NormalFonts == NULL) { | |
718 | wxFontEnumerator enu; | |
719 | enu.EnumerateFacenames(); | |
720 | m_NormalFonts = new wxArrayString; | |
721 | *m_NormalFonts = *enu.GetFacenames(); | |
722 | m_NormalFonts -> Sort(); | |
723 | } | |
724 | if (m_FixedFonts == NULL) { | |
725 | wxFontEnumerator enu; | |
726 | enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE); | |
727 | m_FixedFonts = new wxArrayString; | |
728 | *m_FixedFonts = *enu.GetFacenames(); | |
729 | m_FixedFonts -> Sort(); | |
730 | } | |
731 | ||
732 | for (i = 0; i < m_NormalFonts -> GetCount(); i++) | |
733 | dlg.NormalFont -> Append((*m_NormalFonts)[i]); | |
734 | for (i = 0; i < m_FixedFonts -> GetCount(); i++) | |
735 | dlg.FixedFont -> Append((*m_FixedFonts)[i]); | |
736 | if (!m_NormalFace.IsEmpty()) dlg.NormalFont -> SetStringSelection(m_NormalFace); | |
737 | else dlg.NormalFont -> SetSelection(0); | |
738 | if (!m_FixedFace.IsEmpty()) dlg.FixedFont -> SetStringSelection(m_FixedFace); | |
739 | else dlg.FixedFont -> SetSelection(0); | |
740 | dlg.RadioBox -> SetSelection(m_FontSize); | |
741 | dlg.SFI_i -> SetValue(m_NormalItalic == wxITALIC); | |
742 | dlg.SFI_s -> SetValue(m_NormalItalic == wxSLANT); | |
743 | dlg.FFI_i -> SetValue(m_FixedItalic == wxITALIC); | |
744 | dlg.FFI_s -> SetValue(m_FixedItalic == wxSLANT); | |
745 | dlg.UpdateTestWin(); | |
746 | ||
747 | if (dlg.ShowModal() == wxID_OK) { | |
748 | m_NormalFace = dlg.NormalFont -> GetStringSelection(); | |
749 | m_FixedFace = dlg.FixedFont -> GetStringSelection(); | |
750 | m_FontSize = dlg.RadioBox -> GetSelection(); | |
751 | m_NormalItalic = dlg.SFI_i -> GetValue() ? wxITALIC : wxSLANT; | |
752 | m_FixedItalic = dlg.FFI_i -> GetValue() ? wxITALIC : wxSLANT; | |
753 | SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_NormalItalic, m_FixedFace, m_FixedItalic, m_FontSize); | |
754 | } | |
755 | } | |
756 | ||
757 | ||
758 | ||
759 | ||
760 | ||
8ec2b484 HH |
761 | /* |
762 | EVENT HANDLING : | |
763 | */ | |
764 | ||
765 | ||
766 | void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) | |
767 | { | |
768 | switch (event.GetId()) { | |
769 | case wxID_HTML_BACK : | |
770 | m_HtmlWin -> HistoryBack(); | |
771 | break; | |
772 | case wxID_HTML_FORWARD : | |
773 | m_HtmlWin -> HistoryForward(); | |
774 | break; | |
775 | case wxID_HTML_PANEL : | |
d5bb85a0 VS |
776 | if (! (m_Splitter && m_NavigPan)) |
777 | return ; | |
8ec2b484 HH |
778 | if (m_Splitter -> IsSplit()) { |
779 | m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
780 | m_Splitter -> Unsplit(m_NavigPan); | |
68364659 | 781 | m_Cfg.navig_on = FALSE; |
d5bb85a0 | 782 | } else { |
8ec2b484 HH |
783 | m_NavigPan -> Show(TRUE); |
784 | m_HtmlWin -> Show(TRUE); | |
785 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
68364659 | 786 | m_Cfg.navig_on = TRUE; |
8ec2b484 HH |
787 | } |
788 | break; | |
83efdf33 VS |
789 | case wxID_HTML_OPTIONS : |
790 | OptionsDialog(); | |
791 | break; | |
8ec2b484 HH |
792 | } |
793 | } | |
794 | ||
795 | ||
796 | ||
797 | void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event) | |
798 | { | |
799 | wxHtmlHelpTreeItemData *pg; | |
800 | ||
801 | pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); | |
802 | if (pg) m_HtmlWin -> LoadPage(pg -> GetPage()); | |
803 | } | |
804 | ||
805 | ||
806 | ||
a4c97004 | 807 | void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 | 808 | { |
5d4b632b | 809 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection()); |
c32bfc10 | 810 | m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); |
8ec2b484 HH |
811 | } |
812 | ||
813 | ||
814 | ||
a4c97004 | 815 | void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
816 | { |
817 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection()); | |
818 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
819 | } | |
820 | ||
a4c97004 | 821 | void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 HH |
822 | { |
823 | wxString sr = m_SearchText -> GetLineText(0); | |
824 | ||
825 | if (sr != wxEmptyString) KeywordSearch(sr); | |
826 | } | |
827 | ||
828 | void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) | |
829 | { | |
68364659 VS |
830 | GetSize(&m_Cfg.w, &m_Cfg.h); |
831 | GetPosition(&m_Cfg.x, &m_Cfg.y); | |
5c172c17 | 832 | |
68364659 VS |
833 | if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition(); |
834 | ||
d5bb85a0 VS |
835 | if (m_Config) |
836 | WriteCustomization(m_Config, m_ConfigRoot); | |
68364659 | 837 | |
8ec2b484 HH |
838 | evt.Skip(); |
839 | } | |
840 | ||
841 | BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) | |
83efdf33 | 842 | EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar) |
8ec2b484 HH |
843 | EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) |
844 | EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) | |
845 | EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) | |
846 | EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) | |
847 | EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) | |
848 | EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) | |
849 | END_EVENT_TABLE() | |
850 | ||
851 | #endif |