]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: helpfrm.cpp | |
3 | // Purpose: wxHtmlHelpFrame | |
4 | // Notes: Based on htmlhelp.cpp, implementing a monolithic | |
5 | // HTML Help controller class, by Vaclav Slavik | |
6 | // Author: Harm van der Heijden and Vaclav Slavik | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h" | |
17 | ||
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #include "wx/defs.h" | |
25 | ||
26 | #if wxUSE_HTML | |
27 | #ifndef WXPRECOMP | |
28 | #include "wx/wx.h" | |
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" | |
40 | #include "wx/toolbar.h" | |
41 | #include "wx/fontenum.h" | |
42 | ||
43 | // Bitmaps: | |
44 | ||
45 | #ifndef __WXMSW__ | |
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" | |
55 | #include "bitmaps/wbkadd.xpm" | |
56 | #include "bitmaps/wbkdel.xpm" | |
57 | #endif | |
58 | ||
59 | #include "wx/stream.h" | |
60 | ||
61 | // number of times that the contents/index creation progress dialog | |
62 | // is updated. | |
63 | #define PROGRESS_STEP 40 | |
64 | ||
65 | // what is considered "small index"? | |
66 | #define INDEX_IS_SMALL 100 | |
67 | ||
68 | ||
69 | //-------------------------------------------------------------------------- | |
70 | // wxHtmlHelpTreeItemData (private) | |
71 | //-------------------------------------------------------------------------- | |
72 | ||
73 | class wxHtmlHelpTreeItemData : public wxTreeItemData | |
74 | { | |
75 | private: | |
76 | wxString m_Page; | |
77 | ||
78 | public: | |
79 | wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData() | |
80 | { | |
81 | m_Page = it -> m_Book -> GetBasePath() + it -> m_Page; | |
82 | } | |
83 | const wxString& GetPage() { return m_Page; } | |
84 | }; | |
85 | ||
86 | ||
87 | ||
88 | ||
89 | //--------------------------------------------------------------------------- | |
90 | // wxHtmlHelpFrame | |
91 | //--------------------------------------------------------------------------- | |
92 | ||
93 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame) | |
94 | ||
95 | wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title, | |
96 | int style, wxHtmlHelpData* data) | |
97 | { | |
98 | Init(data); | |
99 | Create(parent, id, title, style); | |
100 | } | |
101 | ||
102 | void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) | |
103 | { | |
104 | if (data) { | |
105 | m_Data = data; | |
106 | m_DataCreated = FALSE; | |
107 | } else { | |
108 | m_Data = new wxHtmlHelpData(); | |
109 | m_DataCreated = TRUE; | |
110 | } | |
111 | ||
112 | m_ContentsImageList = new wxImageList(16, 16); | |
113 | m_ContentsImageList -> Add(wxICON(wbook)); | |
114 | m_ContentsImageList -> Add(wxICON(wfolder)); | |
115 | m_ContentsImageList -> Add(wxICON(wpage)); | |
116 | m_ContentsImageList -> Add(wxICON(whlproot)); | |
117 | ||
118 | m_ContentsBox = NULL; | |
119 | m_IndexList = NULL; | |
120 | m_IndexButton = NULL; | |
121 | m_IndexButtonAll = NULL; | |
122 | m_IndexText = NULL; | |
123 | m_SearchList = NULL; | |
124 | m_SearchButton = NULL; | |
125 | m_SearchText = NULL; | |
126 | m_SearchChoice = NULL; | |
127 | m_IndexCountInfo = NULL; | |
128 | m_Splitter = NULL; | |
129 | m_NavigPan = NULL; | |
130 | m_HtmlWin = NULL; | |
131 | m_Bookmarks = NULL; | |
132 | m_SearchCaseSensitive = NULL; | |
133 | m_SearchWholeWords = NULL; | |
134 | ||
135 | m_Config = NULL; | |
136 | m_ConfigRoot = wxEmptyString; | |
137 | ||
138 | m_Cfg.x = m_Cfg.y = 0; | |
139 | m_Cfg.w = 700; | |
140 | m_Cfg.h = 480; | |
141 | m_Cfg.sashpos = 240; | |
142 | m_Cfg.navig_on = TRUE; | |
143 | ||
144 | m_NormalFonts = m_FixedFonts = NULL; | |
145 | m_FontSize = 1; | |
146 | m_NormalFace = m_FixedFace = wxEmptyString; | |
147 | } | |
148 | ||
149 | // Create: builds the GUI components. | |
150 | // with the style flag it's possible to toggle the toolbar, contents, index and search | |
151 | // controls. | |
152 | // m_HtmlWin will *always* be created, but it's important to realize that | |
153 | // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and | |
154 | // m_SearchButton may be NULL. | |
155 | // moreover, if no contents, index or searchpage is needed, m_Splitter and | |
156 | // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame) | |
157 | ||
158 | bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title, | |
159 | int style) | |
160 | { | |
161 | // Do the config in two steps. We read the HtmlWindow customization after we | |
162 | // create the window. | |
163 | if (m_Config) | |
164 | ReadCustomization(m_Config, m_ConfigRoot); | |
165 | ||
166 | wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), wxDEFAULT_FRAME_STYLE, "wxHtmlHelp"); | |
167 | ||
168 | GetPosition(&m_Cfg.x, &m_Cfg.y); | |
169 | ||
170 | SetIcon(wxICON(whelp)); | |
171 | ||
172 | int notebook_page = 0; | |
173 | ||
174 | CreateStatusBar(); | |
175 | ||
176 | // toolbar? | |
177 | if (style & wxHF_TOOLBAR) { | |
178 | wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE); | |
179 | toolBar->SetMargins( 2, 2 ); | |
180 | AddToolbarButtons(toolBar, style); | |
181 | toolBar -> Realize(); | |
182 | } | |
183 | ||
184 | if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) { | |
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); | |
194 | } | |
195 | ||
196 | m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat); | |
197 | m_HtmlWin -> SetRelatedStatusBar(0); | |
198 | if (m_Config) | |
199 | m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot); | |
200 | ||
201 | // contents tree panel? | |
202 | if (style & wxHF_CONTENTS) { | |
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++; | |
209 | } | |
210 | ||
211 | // index listbox panel? | |
212 | if (style & wxHF_INDEX) { | |
213 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE); | |
214 | ||
215 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
216 | m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); | |
217 | b1 -> top.SameAs (dummy, wxTop, 10); | |
218 | b1 -> left.SameAs (dummy, wxLeft, 10); | |
219 | b1 -> right.SameAs (dummy, wxRight, 10); | |
220 | b1 -> height.AsIs(); | |
221 | m_IndexText -> SetConstraints(b1); | |
222 | ||
223 | wxLayoutConstraints *b4 = new wxLayoutConstraints; | |
224 | m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, _("Show all")); | |
225 | ||
226 | b4 -> top.Below (m_IndexText, 10); | |
227 | b4 -> right.SameAs (dummy, wxRight, 10); | |
228 | b4 -> width.AsIs(); | |
229 | b4 -> height.AsIs(); | |
230 | m_IndexButtonAll -> SetConstraints(b4); | |
231 | ||
232 | wxLayoutConstraints *b2 = new wxLayoutConstraints; | |
233 | m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find")); | |
234 | b2 -> top.Below (m_IndexText, 10); | |
235 | b2 -> right.LeftOf (m_IndexButtonAll, 10); | |
236 | b2 -> width.AsIs(); | |
237 | b2 -> height.AsIs(); | |
238 | m_IndexButton -> SetConstraints(b2); | |
239 | ||
240 | wxLayoutConstraints *b5 = new wxLayoutConstraints; | |
241 | m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE); | |
242 | ||
243 | b5 -> top.Below (m_IndexButton, 5); | |
244 | b5 -> right.SameAs (dummy, wxRight, 10); | |
245 | b5 -> left.SameAs (dummy, wxLeft, 10); | |
246 | b5 -> height.AsIs(); | |
247 | m_IndexCountInfo -> SetConstraints(b5); | |
248 | ||
249 | wxLayoutConstraints *b3 = new wxLayoutConstraints; | |
250 | m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB); | |
251 | b3 -> top.Below (m_IndexCountInfo, 5); | |
252 | b3 -> left.SameAs (dummy, wxLeft, 0); | |
253 | b3 -> right.SameAs (dummy, wxRight, 0); | |
254 | b3 -> bottom.SameAs (dummy, wxBottom, 0); | |
255 | m_IndexList -> SetConstraints(b3); | |
256 | ||
257 | #if wxUSE_TOOLTIPS | |
258 | m_IndexButtonAll -> SetToolTip(_("Show all items in index")); | |
259 | m_IndexButton -> SetToolTip(_("Display all index items that contain given substring. Search is case insensitive.")); | |
260 | #endif //wxUSE_TOOLTIPS | |
261 | ||
262 | dummy -> SetAutoLayout(TRUE); | |
263 | dummy -> Layout(); | |
264 | ||
265 | m_NavigPan -> AddPage(dummy, _("Index")); | |
266 | m_IndexPage = notebook_page++; | |
267 | } | |
268 | ||
269 | // search list panel? | |
270 | if (style & wxHF_SEARCH) { | |
271 | wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE); | |
272 | ||
273 | wxLayoutConstraints *b1 = new wxLayoutConstraints; | |
274 | m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); | |
275 | b1 -> top.SameAs (dummy, wxTop, 10); | |
276 | b1 -> left.SameAs (dummy, wxLeft, 10); | |
277 | b1 -> right.SameAs (dummy, wxRight, 10); | |
278 | b1 -> height.AsIs(); | |
279 | m_SearchText -> SetConstraints(b1); | |
280 | ||
281 | wxLayoutConstraints *b2 = new wxLayoutConstraints; | |
282 | m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search")); | |
283 | #if wxUSE_TOOLTIPS | |
284 | m_SearchButton -> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above")); | |
285 | #endif //wxUSE_TOOLTIPS | |
286 | b2 -> top.Below (m_SearchText, 10); | |
287 | b2 -> left.SameAs (dummy, wxLeft, 10); | |
288 | b2 -> width.AsIs(); | |
289 | b2 -> height.AsIs(); | |
290 | m_SearchButton -> SetConstraints(b2); | |
291 | ||
292 | wxLayoutConstraints *b4 = new wxLayoutConstraints; | |
293 | m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition, | |
294 | wxDefaultSize); | |
295 | b4 -> top.Below (m_SearchText, 10); | |
296 | b4 -> left.SameAs (m_SearchButton, wxRight, 10); | |
297 | b4 -> right.SameAs (dummy, wxRight, 10); | |
298 | b4 -> height.AsIs(); | |
299 | m_SearchChoice -> SetConstraints(b4); | |
300 | ||
301 | wxLayoutConstraints *b5 = new wxLayoutConstraints; | |
302 | m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive")); | |
303 | b5 -> top.Below (m_SearchButton, 10); | |
304 | b5 -> left.SameAs (dummy, wxLeft, 10); | |
305 | b5 -> right.SameAs (dummy, wxRight, 10); | |
306 | b5 -> height.AsIs (); | |
307 | m_SearchCaseSensitive -> SetConstraints(b5); | |
308 | ||
309 | wxLayoutConstraints *b6 = new wxLayoutConstraints; | |
310 | m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only")); | |
311 | b6 -> top.Below (m_SearchCaseSensitive, 0); | |
312 | b6 -> left.SameAs (dummy, wxLeft, 10); | |
313 | b6 -> right.SameAs (dummy, wxRight, 10); | |
314 | b6 -> height.AsIs (); | |
315 | m_SearchWholeWords -> SetConstraints(b6); | |
316 | ||
317 | wxLayoutConstraints *b3 = new wxLayoutConstraints; | |
318 | m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB); | |
319 | b3 -> top.Below (m_SearchWholeWords, 10); | |
320 | b3 -> left.SameAs (dummy, wxLeft, 0); | |
321 | b3 -> right.SameAs (dummy, wxRight, 0); | |
322 | b3 -> bottom.SameAs (dummy, wxBottom, 0); | |
323 | m_SearchList -> SetConstraints(b3); | |
324 | ||
325 | dummy -> SetAutoLayout(TRUE); | |
326 | dummy -> Layout(); | |
327 | m_NavigPan -> AddPage(dummy, _("Search")); | |
328 | m_SearchPage = notebook_page++; | |
329 | } | |
330 | m_HtmlWin -> Show(TRUE); | |
331 | ||
332 | RefreshLists(); | |
333 | ||
334 | // showtime | |
335 | if (m_NavigPan && m_Splitter) { | |
336 | m_Splitter -> SetMinimumPaneSize(20); | |
337 | if (m_Cfg.navig_on) | |
338 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
339 | else { | |
340 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
341 | m_Splitter -> Unsplit(); | |
342 | } | |
343 | if (m_Cfg.navig_on) { | |
344 | m_NavigPan -> Show(TRUE); | |
345 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
346 | } | |
347 | else { | |
348 | m_NavigPan -> Show(FALSE); | |
349 | m_Splitter -> Initialize(m_HtmlWin); | |
350 | } | |
351 | } | |
352 | return TRUE; | |
353 | } | |
354 | ||
355 | wxHtmlHelpFrame::~wxHtmlHelpFrame() | |
356 | { | |
357 | PopEventHandler(); // wxhtmlhelpcontroller | |
358 | delete m_ContentsImageList; | |
359 | if (m_DataCreated) | |
360 | delete m_Data; | |
361 | if (m_NormalFonts) delete m_NormalFonts; | |
362 | if (m_FixedFonts) delete m_FixedFonts; | |
363 | } | |
364 | ||
365 | ||
366 | void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style) | |
367 | { | |
368 | toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap, | |
369 | FALSE, -1, -1, (wxObject *) NULL, | |
370 | _("Show/hide navigation panel")); | |
371 | toolBar -> AddSeparator(); | |
372 | toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap, | |
373 | FALSE, -1, -1, (wxObject *) NULL, | |
374 | _("Go back to the previous HTML page")); | |
375 | toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap, | |
376 | FALSE, -1, -1, (wxObject *) NULL, | |
377 | _("Go forward to the next HTML page")); | |
378 | toolBar -> AddSeparator(); | |
379 | ||
380 | if (style & wxHF_BOOKMARKS) { | |
381 | m_Bookmarks = new wxComboBox(toolBar, wxID_HTML_BOOKMARKSLIST, wxEmptyString, | |
382 | wxDefaultPosition, wxSize(300,-1), 0, NULL, wxCB_READONLY | wxCB_SORT); | |
383 | m_Bookmarks -> Append(_("<bookmarks>")); | |
384 | for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++) | |
385 | m_Bookmarks -> Append(m_BookmarksNames[i]); | |
386 | m_Bookmarks -> SetSelection(0); | |
387 | toolBar -> AddControl(m_Bookmarks); | |
388 | #ifdef __WXGTK__ | |
389 | toolBar -> AddSeparator(); | |
390 | #endif | |
391 | toolBar -> AddTool(wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxNullBitmap, | |
392 | FALSE, -1, -1, (wxObject *) NULL, | |
393 | _("Add current page to bookmarks")); | |
394 | toolBar -> AddTool(wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxNullBitmap, | |
395 | FALSE, -1, -1, (wxObject *) NULL, | |
396 | _("Remove current page from bookmarks")); | |
397 | } | |
398 | ||
399 | toolBar -> AddSeparator(); | |
400 | toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap, | |
401 | FALSE, -1, -1, (wxObject *) NULL, | |
402 | _("Display options dialog")); | |
403 | } | |
404 | ||
405 | ||
406 | ||
407 | bool wxHtmlHelpFrame::Display(const wxString& x) | |
408 | { | |
409 | wxString url = m_Data->FindPageByName(x); | |
410 | if (! url.IsEmpty()) { | |
411 | m_HtmlWin->LoadPage(url); | |
412 | return TRUE; | |
413 | } | |
414 | return FALSE; | |
415 | } | |
416 | ||
417 | bool wxHtmlHelpFrame::Display(const int id) | |
418 | { | |
419 | wxString url = m_Data->FindPageById(id); | |
420 | if (! url.IsEmpty()) { | |
421 | m_HtmlWin->LoadPage(url); | |
422 | return TRUE; | |
423 | } | |
424 | return FALSE; | |
425 | } | |
426 | ||
427 | ||
428 | ||
429 | bool wxHtmlHelpFrame::DisplayContents() | |
430 | { | |
431 | if (! m_ContentsBox) | |
432 | return FALSE; | |
433 | if (!m_Splitter -> IsSplit()) { | |
434 | m_NavigPan -> Show(TRUE); | |
435 | m_HtmlWin -> Show(TRUE); | |
436 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
437 | m_Cfg.navig_on = TRUE; | |
438 | } | |
439 | m_NavigPan -> SetSelection(0); | |
440 | return TRUE; | |
441 | } | |
442 | ||
443 | ||
444 | ||
445 | bool wxHtmlHelpFrame::DisplayIndex() | |
446 | { | |
447 | if (! m_IndexList) | |
448 | return FALSE; | |
449 | if (!m_Splitter -> IsSplit()) { | |
450 | m_NavigPan -> Show(TRUE); | |
451 | m_HtmlWin -> Show(TRUE); | |
452 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
453 | } | |
454 | m_NavigPan -> SetSelection(1); | |
455 | return TRUE; | |
456 | } | |
457 | ||
458 | ||
459 | ||
460 | bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) | |
461 | { | |
462 | if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice)) | |
463 | return FALSE; | |
464 | ||
465 | int foundcnt = 0, curi; | |
466 | wxString foundstr; | |
467 | wxString book = wxEmptyString; | |
468 | ||
469 | if (!m_Splitter -> IsSplit()) { | |
470 | m_NavigPan -> Show(TRUE); | |
471 | m_HtmlWin -> Show(TRUE); | |
472 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
473 | } | |
474 | m_NavigPan -> SetSelection(m_SearchPage); | |
475 | m_SearchList -> Clear(); | |
476 | m_SearchText -> SetValue(keyword); | |
477 | m_SearchButton -> Enable(FALSE); | |
478 | ||
479 | if (m_SearchChoice->GetSelection() != 0) | |
480 | book = m_SearchChoice->GetStringSelection(); | |
481 | ||
482 | wxHtmlSearchStatus status(m_Data, keyword, | |
483 | m_SearchCaseSensitive -> GetValue(), m_SearchWholeWords -> GetValue(), | |
484 | book); | |
485 | ||
486 | wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), | |
487 | status.GetMaxIndex(), this, | |
488 | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE | wxGA_SMOOTH); | |
489 | ||
490 | while (status.IsActive()) { | |
491 | curi = status.GetCurIndex(); | |
492 | if (curi % 32 == 0 && progress.Update(curi) == FALSE) | |
493 | break; | |
494 | if (status.Search()) { | |
495 | foundstr.Printf(_("Found %i matches"), ++foundcnt); | |
496 | progress.Update(status.GetCurIndex(), foundstr); | |
497 | m_SearchList -> Append(status.GetName(), status.GetContentsItem()); | |
498 | } | |
499 | } | |
500 | ||
501 | m_SearchButton -> Enable(TRUE); | |
502 | m_SearchText -> SetSelection(0, keyword.Length()); | |
503 | m_SearchText -> SetFocus(); | |
504 | if (foundcnt) { | |
505 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0); | |
506 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
507 | } | |
508 | return (foundcnt > 0); | |
509 | } | |
510 | ||
511 | #define MAX_ROOTS 64 | |
512 | ||
513 | void wxHtmlHelpFrame::CreateContents() | |
514 | { | |
515 | if (! m_ContentsBox) | |
516 | return ; | |
517 | ||
518 | m_ContentsBox->Clear(); | |
519 | ||
520 | int cnt = m_Data->GetContentsCnt(); | |
521 | int i; | |
522 | ||
523 | wxHtmlContentsItem *it; | |
524 | ||
525 | wxTreeItemId roots[MAX_ROOTS]; | |
526 | bool imaged[MAX_ROOTS]; | |
527 | ||
528 | m_ContentsBox -> DeleteAllItems(); | |
529 | roots[0] = m_ContentsBox -> AddRoot(_("(Help)")); | |
530 | m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder); | |
531 | m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder); | |
532 | imaged[0] = TRUE; | |
533 | ||
534 | for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) { | |
535 | roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( | |
536 | roots[it -> m_Level], it -> m_Name, IMG_Page, -1, | |
537 | new wxHtmlHelpTreeItemData(it)); | |
538 | ||
539 | if (it -> m_Level == 0) { | |
540 | m_ContentsBox -> SetItemBold(roots[1], TRUE); | |
541 | m_ContentsBox -> SetItemImage(roots[1], IMG_Book); | |
542 | m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book); | |
543 | imaged[1] = TRUE; | |
544 | } else imaged[it -> m_Level + 1] = FALSE; | |
545 | ||
546 | if (!imaged[it -> m_Level]) { | |
547 | m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder); | |
548 | m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder); | |
549 | imaged[it -> m_Level] = TRUE; | |
550 | } | |
551 | } | |
552 | m_ContentsBox -> Expand(roots[0]); | |
553 | } | |
554 | ||
555 | ||
556 | void wxHtmlHelpFrame::CreateIndex() | |
557 | { | |
558 | if (! m_IndexList) | |
559 | return ; | |
560 | ||
561 | m_IndexList->Clear(); | |
562 | ||
563 | int cnt = m_Data->GetIndexCnt(); | |
564 | ||
565 | wxString cnttext; | |
566 | if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt); | |
567 | else cnttext.Printf(_("%i of %i"), cnt, cnt); | |
568 | m_IndexCountInfo -> SetLabel(cnttext); | |
569 | if (cnt > INDEX_IS_SMALL) return; | |
570 | ||
571 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
572 | ||
573 | for (int i = 0; i < cnt; i++) | |
574 | m_IndexList -> Append(index[i].m_Name, (char*)(index + i)); | |
575 | } | |
576 | ||
577 | void wxHtmlHelpFrame::CreateSearch() | |
578 | { | |
579 | if (! (m_SearchList && m_SearchChoice)) | |
580 | return ; | |
581 | m_SearchList -> Clear(); | |
582 | m_SearchChoice -> Clear(); | |
583 | m_SearchChoice -> Append(_("all books")); | |
584 | const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); | |
585 | int i, cnt = bookrec.GetCount(); | |
586 | for (i = 0; i < cnt; i++) | |
587 | m_SearchChoice->Append(bookrec[i].GetTitle()); | |
588 | m_SearchChoice->SetSelection(0); | |
589 | } | |
590 | ||
591 | ||
592 | void wxHtmlHelpFrame::RefreshLists() | |
593 | { | |
594 | CreateContents(); | |
595 | CreateIndex(); | |
596 | CreateSearch(); | |
597 | } | |
598 | ||
599 | void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) | |
600 | { | |
601 | wxString oldpath; | |
602 | wxString tmp; | |
603 | ||
604 | if (path != wxEmptyString) { | |
605 | oldpath = cfg -> GetPath(); | |
606 | cfg -> SetPath(_T("/") + path); | |
607 | } | |
608 | ||
609 | m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0; | |
610 | m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos); | |
611 | m_Cfg.x = cfg -> Read("hcX", m_Cfg.x); | |
612 | m_Cfg.y = cfg -> Read("hcY", m_Cfg.y); | |
613 | m_Cfg.w = cfg -> Read("hcW", m_Cfg.w); | |
614 | m_Cfg.h = cfg -> Read("hcH", m_Cfg.h); | |
615 | ||
616 | m_FixedFace = cfg -> Read("hcFixedFace", m_FixedFace); | |
617 | m_NormalFace = cfg -> Read("hcNormalFace", m_NormalFace); | |
618 | m_FontSize = cfg -> Read("hcFontSize", m_FontSize); | |
619 | ||
620 | { | |
621 | int i; | |
622 | int cnt; | |
623 | wxString val, s; | |
624 | ||
625 | cnt = cfg -> Read("hcBookmarksCnt", 0L); | |
626 | if (cnt != 0) { | |
627 | m_BookmarksNames.Clear(); | |
628 | m_BookmarksPages.Clear(); | |
629 | if (m_Bookmarks) { | |
630 | m_Bookmarks -> Clear(); | |
631 | m_Bookmarks -> Append(_("<bookmarks>")); | |
632 | } | |
633 | ||
634 | for (i = 0; i < cnt; i++) { | |
635 | val.Printf(wxT("hcBookmark_%i"), i); | |
636 | s = cfg -> Read(val); | |
637 | m_BookmarksNames.Add(s); | |
638 | if (m_Bookmarks) m_Bookmarks -> Append(s); | |
639 | val.Printf(wxT("hcBookmark_%i_url"), i); | |
640 | s = cfg -> Read(val); | |
641 | m_BookmarksPages.Add(s); | |
642 | } | |
643 | } | |
644 | } | |
645 | ||
646 | if (m_HtmlWin) | |
647 | m_HtmlWin->ReadCustomization(cfg); | |
648 | ||
649 | if (path != wxEmptyString) | |
650 | cfg -> SetPath(oldpath); | |
651 | } | |
652 | ||
653 | void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path) | |
654 | { | |
655 | wxString oldpath; | |
656 | wxString tmp; | |
657 | ||
658 | if (path != wxEmptyString) { | |
659 | oldpath = cfg -> GetPath(); | |
660 | cfg -> SetPath(_T("/") + path); | |
661 | } | |
662 | ||
663 | cfg -> Write("hcNavigPanel", m_Cfg.navig_on); | |
664 | cfg -> Write("hcSashPos", (long)m_Cfg.sashpos); | |
665 | cfg -> Write("hcX", (long)m_Cfg.x); | |
666 | cfg -> Write("hcY", (long)m_Cfg.y); | |
667 | cfg -> Write("hcW", (long)m_Cfg.w); | |
668 | cfg -> Write("hcH", (long)m_Cfg.h); | |
669 | cfg -> Write("hcFixedFace", m_FixedFace); | |
670 | cfg -> Write("hcNormalFace", m_NormalFace); | |
671 | cfg -> Write("hcFontSize", (long)m_FontSize); | |
672 | ||
673 | if (m_Bookmarks) { | |
674 | int i; | |
675 | int cnt = m_BookmarksNames.GetCount(); | |
676 | wxString val; | |
677 | ||
678 | cfg -> Write("hcBookmarksCnt", (long)cnt); | |
679 | for (i = 0; i < cnt; i++) { | |
680 | val.Printf(wxT("hcBookmark_%i"), i); | |
681 | cfg -> Write(val, m_BookmarksNames[i]); | |
682 | val.Printf(wxT("hcBookmark_%i_url"), i); | |
683 | cfg -> Write(val, m_BookmarksPages[i]); | |
684 | } | |
685 | } | |
686 | ||
687 | if (m_HtmlWin) | |
688 | m_HtmlWin->WriteCustomization(cfg); | |
689 | ||
690 | if (path != wxEmptyString) | |
691 | cfg -> SetPath(oldpath); | |
692 | } | |
693 | ||
694 | ||
695 | ||
696 | ||
697 | ||
698 | static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size) | |
699 | { | |
700 | static int f_sizes[3][7] = | |
701 | { | |
702 | { 8, 9, 12, 14, 16, 19, 22}, | |
703 | {10, 12, 14, 16, 19, 24, 32}, | |
704 | {14, 16, 18, 24, 32, 38, 45} | |
705 | }; | |
706 | ||
707 | win -> SetFonts(scalf, fixf, f_sizes[size]); | |
708 | } | |
709 | ||
710 | ||
711 | class wxHtmlHelpFrameOptionsDialog : public wxDialog | |
712 | { | |
713 | public: | |
714 | wxComboBox *NormalFont, *FixedFont; | |
715 | wxRadioBox *RadioBox; | |
716 | wxHtmlWindow *TestWin; | |
717 | ||
718 | wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options"))) | |
719 | { | |
720 | wxString choices[3] = {_("small"), _("medium"), _("large")}; | |
721 | wxBoxSizer *topsizer, *sizer, *sizer2; | |
722 | ||
723 | topsizer = new wxBoxSizer(wxVERTICAL); | |
724 | ||
725 | sizer = new wxBoxSizer(wxHORIZONTAL); | |
726 | ||
727 | sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL); | |
728 | sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, | |
729 | wxSize(200, 200), | |
730 | 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), | |
731 | 1, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
732 | ||
733 | sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10); | |
734 | ||
735 | sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL); | |
736 | sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, | |
737 | wxSize(200, 200), | |
738 | 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), | |
739 | 1, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
740 | ||
741 | sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10); | |
742 | ||
743 | topsizer -> Add(sizer); | |
744 | ||
745 | topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"), | |
746 | wxDefaultPosition, wxDefaultSize, 3, choices, 3), | |
747 | 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10); | |
748 | ||
749 | topsizer -> Add(new wxStaticText(this, -1, _("Preview:")), | |
750 | 0, wxLEFT | wxTOP, 10); | |
751 | topsizer -> Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)), | |
752 | 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10); | |
753 | ||
754 | sizer = new wxBoxSizer(wxHORIZONTAL); | |
755 | sizer -> Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10); | |
756 | sizer -> Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10); | |
757 | topsizer -> Add(sizer, 0, wxALIGN_RIGHT); | |
758 | ||
759 | SetAutoLayout(TRUE); | |
760 | SetSizer(topsizer); | |
761 | topsizer -> Fit(this); | |
762 | Centre(wxBOTH); | |
763 | } | |
764 | ||
765 | ||
766 | void UpdateTestWin() | |
767 | { | |
768 | wxBusyCursor bcur; | |
769 | SetFontsToHtmlWin(TestWin, | |
770 | NormalFont -> GetStringSelection(), | |
771 | FixedFont -> GetStringSelection(), | |
772 | RadioBox -> GetSelection()); | |
773 | TestWin -> SetPage(_("<html><body>" | |
774 | "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> " | |
775 | "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>" | |
776 | "<font size=-2>font size -2</font><br>" | |
777 | "<font size=-1>font size -1</font><br>" | |
778 | "<font size=+0>font size +0</font><br>" | |
779 | "<font size=+1>font size +1</font><br>" | |
780 | "<font size=+2>font size +2</font><br>" | |
781 | "<font size=+3>font size +3</font><br>" | |
782 | "<font size=+4>font size +4</font><br>" | |
783 | ||
784 | "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> " | |
785 | "<b><i>bold italic <u>underlined</u></i></b><br>" | |
786 | "<font size=-2>font size -2</font><br>" | |
787 | "<font size=-1>font size -1</font><br>" | |
788 | "<font size=+0>font size +0</font><br>" | |
789 | "<font size=+1>font size +1</font><br>" | |
790 | "<font size=+2>font size +2</font><br>" | |
791 | "<font size=+3>font size +3</font><br>" | |
792 | "<font size=+4>font size +4</font></tt>" | |
793 | "</body></html>")); | |
794 | } | |
795 | ||
796 | void OnUpdate(wxCloseEvent& event) | |
797 | { | |
798 | UpdateTestWin(); | |
799 | } | |
800 | ||
801 | DECLARE_EVENT_TABLE() | |
802 | }; | |
803 | ||
804 | BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog) | |
805 | EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) | |
806 | EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) | |
807 | END_EVENT_TABLE() | |
808 | ||
809 | ||
810 | void wxHtmlHelpFrame::OptionsDialog() | |
811 | { | |
812 | wxHtmlHelpFrameOptionsDialog dlg(this); | |
813 | unsigned i; | |
814 | ||
815 | if (m_NormalFonts == NULL) { | |
816 | wxFontEnumerator enu; | |
817 | enu.EnumerateFacenames(); | |
818 | m_NormalFonts = new wxArrayString; | |
819 | *m_NormalFonts = *enu.GetFacenames(); | |
820 | m_NormalFonts -> Sort(); | |
821 | } | |
822 | if (m_FixedFonts == NULL) { | |
823 | wxFontEnumerator enu; | |
824 | enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE); | |
825 | m_FixedFonts = new wxArrayString; | |
826 | *m_FixedFonts = *enu.GetFacenames(); | |
827 | m_FixedFonts -> Sort(); | |
828 | } | |
829 | ||
830 | for (i = 0; i < m_NormalFonts -> GetCount(); i++) | |
831 | dlg.NormalFont -> Append((*m_NormalFonts)[i]); | |
832 | for (i = 0; i < m_FixedFonts -> GetCount(); i++) | |
833 | dlg.FixedFont -> Append((*m_FixedFonts)[i]); | |
834 | if (!m_NormalFace.IsEmpty()) dlg.NormalFont -> SetStringSelection(m_NormalFace); | |
835 | else dlg.NormalFont -> SetSelection(0); | |
836 | if (!m_FixedFace.IsEmpty()) dlg.FixedFont -> SetStringSelection(m_FixedFace); | |
837 | else dlg.FixedFont -> SetSelection(0); | |
838 | dlg.RadioBox -> SetSelection(m_FontSize); | |
839 | dlg.UpdateTestWin(); | |
840 | ||
841 | if (dlg.ShowModal() == wxID_OK) { | |
842 | m_NormalFace = dlg.NormalFont -> GetStringSelection(); | |
843 | m_FixedFace = dlg.FixedFont -> GetStringSelection(); | |
844 | m_FontSize = dlg.RadioBox -> GetSelection(); | |
845 | SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize); | |
846 | } | |
847 | } | |
848 | ||
849 | ||
850 | ||
851 | ||
852 | ||
853 | /* | |
854 | EVENT HANDLING : | |
855 | */ | |
856 | ||
857 | ||
858 | void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) | |
859 | { | |
860 | switch (event.GetId()) { | |
861 | ||
862 | case wxID_HTML_BACK : | |
863 | m_HtmlWin -> HistoryBack(); | |
864 | break; | |
865 | ||
866 | case wxID_HTML_FORWARD : | |
867 | m_HtmlWin -> HistoryForward(); | |
868 | break; | |
869 | ||
870 | case wxID_HTML_PANEL : | |
871 | if (! (m_Splitter && m_NavigPan)) | |
872 | return ; | |
873 | if (m_Splitter -> IsSplit()) { | |
874 | m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
875 | m_Splitter -> Unsplit(m_NavigPan); | |
876 | m_Cfg.navig_on = FALSE; | |
877 | } else { | |
878 | m_NavigPan -> Show(TRUE); | |
879 | m_HtmlWin -> Show(TRUE); | |
880 | m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); | |
881 | m_Cfg.navig_on = TRUE; | |
882 | } | |
883 | break; | |
884 | ||
885 | case wxID_HTML_OPTIONS : | |
886 | OptionsDialog(); | |
887 | break; | |
888 | ||
889 | case wxID_HTML_BOOKMARKSADD : | |
890 | { | |
891 | wxString item; | |
892 | wxString url; | |
893 | ||
894 | item = m_HtmlWin -> GetOpenedPageTitle(); | |
895 | url = m_HtmlWin -> GetOpenedPage(); | |
896 | if (item == wxEmptyString) item = url.AfterLast(wxT('/')); | |
897 | if (m_BookmarksPages.Index(url) == wxNOT_FOUND) { | |
898 | m_Bookmarks -> Append(item); | |
899 | m_BookmarksNames.Add(item); | |
900 | m_BookmarksPages.Add(url); | |
901 | } | |
902 | } | |
903 | break; | |
904 | ||
905 | case wxID_HTML_BOOKMARKSREMOVE : | |
906 | { | |
907 | wxString item; | |
908 | int pos; | |
909 | ||
910 | item = m_Bookmarks -> GetStringSelection(); | |
911 | pos = m_BookmarksNames.Index(item); | |
912 | if (pos != wxNOT_FOUND) { | |
913 | m_BookmarksNames.Remove(pos); | |
914 | m_BookmarksPages.Remove(pos); | |
915 | m_Bookmarks -> Delete(m_Bookmarks -> GetSelection()); | |
916 | } | |
917 | } | |
918 | break; | |
919 | } | |
920 | } | |
921 | ||
922 | ||
923 | ||
924 | void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event) | |
925 | { | |
926 | wxHtmlHelpTreeItemData *pg; | |
927 | ||
928 | pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); | |
929 | if (pg) m_HtmlWin -> LoadPage(pg -> GetPage()); | |
930 | } | |
931 | ||
932 | ||
933 | ||
934 | void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event)) | |
935 | { | |
936 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList -> GetClientData(m_IndexList -> GetSelection()); | |
937 | m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
938 | } | |
939 | ||
940 | ||
941 | void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event) | |
942 | { | |
943 | wxString sr = m_IndexText -> GetLineText(0); | |
944 | sr.MakeLower(); | |
945 | if (sr == wxEmptyString) | |
946 | OnIndexAll(event); | |
947 | ||
948 | else { | |
949 | wxBusyCursor bcur; | |
950 | const wxChar *cstr = sr.c_str(); | |
951 | wxChar mybuff[512], *ptr; | |
952 | bool first = TRUE; | |
953 | ||
954 | m_IndexList->Clear(); | |
955 | int cnt = m_Data->GetIndexCnt(); | |
956 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
957 | ||
958 | int displ = 0; | |
959 | for (int i = 0; i < cnt; i++) | |
960 | { | |
961 | wxStrncpy(mybuff, index[i].m_Name, 512); | |
962 | mybuff[511] = 0; | |
963 | for (ptr = mybuff; *ptr != 0; ptr++) | |
964 | if (*ptr >= 'A' && *ptr <= 'Z') *ptr -= 'A' - 'a'; | |
965 | if (wxStrstr(mybuff, cstr) != NULL) { | |
966 | m_IndexList -> Append(index[i].m_Name, (char*)(index + i)); | |
967 | displ++; | |
968 | if (first) { | |
969 | m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page); | |
970 | first = FALSE; | |
971 | } | |
972 | } | |
973 | } | |
974 | ||
975 | wxString cnttext; | |
976 | cnttext.Printf(_("%i of %i"), displ, cnt); | |
977 | m_IndexCountInfo -> SetLabel(cnttext); | |
978 | ||
979 | m_IndexText -> SetSelection(0, sr.Length()); | |
980 | m_IndexText -> SetFocus(); | |
981 | } | |
982 | } | |
983 | ||
984 | void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event)) | |
985 | { | |
986 | wxBusyCursor bcur; | |
987 | ||
988 | m_IndexList->Clear(); | |
989 | int cnt = m_Data->GetIndexCnt(); | |
990 | bool first = TRUE; | |
991 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
992 | ||
993 | for (int i = 0; i < cnt; i++) { | |
994 | m_IndexList -> Append(index[i].m_Name, (char*)(index + i)); | |
995 | if (first) { | |
996 | m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page); | |
997 | first = FALSE; | |
998 | } | |
999 | } | |
1000 | ||
1001 | wxString cnttext; | |
1002 | cnttext.Printf(_("%i of %i"), cnt, cnt); | |
1003 | m_IndexCountInfo -> SetLabel(cnttext); | |
1004 | } | |
1005 | ||
1006 | ||
1007 | void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event)) | |
1008 | { | |
1009 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection()); | |
1010 | if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); | |
1011 | } | |
1012 | ||
1013 | void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) | |
1014 | { | |
1015 | wxString sr = m_SearchText -> GetLineText(0); | |
1016 | ||
1017 | if (sr != wxEmptyString) KeywordSearch(sr); | |
1018 | } | |
1019 | ||
1020 | void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event)) | |
1021 | { | |
1022 | wxString sr = m_Bookmarks -> GetStringSelection(); | |
1023 | ||
1024 | if (sr != wxEmptyString && sr != _("<bookmarks>")) | |
1025 | m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]); | |
1026 | } | |
1027 | ||
1028 | void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) | |
1029 | { | |
1030 | GetSize(&m_Cfg.w, &m_Cfg.h); | |
1031 | GetPosition(&m_Cfg.x, &m_Cfg.y); | |
1032 | ||
1033 | if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition(); | |
1034 | ||
1035 | if (m_Config) | |
1036 | WriteCustomization(m_Config, m_ConfigRoot); | |
1037 | ||
1038 | evt.Skip(); | |
1039 | } | |
1040 | ||
1041 | BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) | |
1042 | EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar) | |
1043 | EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) | |
1044 | EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) | |
1045 | EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) | |
1046 | EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) | |
1047 | EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) | |
1048 | EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind) | |
1049 | EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind) | |
1050 | EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll) | |
1051 | EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel) | |
1052 | EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) | |
1053 | END_EVENT_TABLE() | |
1054 | ||
1055 | #endif |