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