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