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