X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/240c2873da05a48b57a861ffd795626edf20e7fb..8ad6ad991c39081d513f7d277bd3509fbbaa42fc:/src/html/helpfrm.cpp diff --git a/src/html/helpfrm.cpp b/src/html/helpfrm.cpp index 09655e5d8a..75684f5355 100644 --- a/src/html/helpfrm.cpp +++ b/src/html/helpfrm.cpp @@ -129,6 +129,9 @@ void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) m_NavigPan = NULL; m_HtmlWin = NULL; m_Bookmarks = NULL; + m_SearchCaseSensitive = NULL; + m_SearchWholeWords = NULL; + m_Config = NULL; m_ConfigRoot = wxEmptyString; @@ -174,43 +177,7 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti if (style & wxHF_TOOLBAR) { wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE); toolBar->SetMargins( 2, 2 ); - - toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Show/hide navigation panel")); - toolBar -> AddSeparator(); - toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Go back to the previous HTML page")); - toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Go forward to the next HTML page")); - toolBar -> AddSeparator(); - - if (style & wxHF_BOOKMARKS) { - m_Bookmarks = new wxComboBox(toolBar, wxID_HTML_BOOKMARKSLIST, wxEmptyString, - wxDefaultPosition, wxSize(300,-1), 0, NULL, wxCB_READONLY | wxCB_SORT); - m_Bookmarks -> Append(_("")); - for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++) - m_Bookmarks -> Append(m_BookmarksNames[i]); - m_Bookmarks -> SetSelection(0); - toolBar -> AddControl(m_Bookmarks); -#ifdef __WXGTK__ - toolBar -> AddSeparator(); -#endif - toolBar -> AddTool(wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Add current page to bookmarks")); - toolBar -> AddTool(wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Remove current page from bookmarks")); - } - - toolBar -> AddSeparator(); - toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Display options dialog")); - + AddToolbarButtons(toolBar, style); toolBar -> Realize(); } @@ -233,11 +200,74 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti // contents tree panel? if (style & wxHF_CONTENTS) { - m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL, - wxDefaultPosition, wxDefaultSize, - wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); - m_ContentsBox -> SetImageList(m_ContentsImageList); - m_NavigPan -> AddPage(m_ContentsBox, _("Contents")); + wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE); + + if (style & wxHF_BOOKMARKS) { + wxLayoutConstraints *b1 = new wxLayoutConstraints; + wxBitmapButton *bmpbt = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxDefaultPosition, wxSize(20,20)); + + b1 -> top.SameAs (dummy, wxTop, 10); + b1 -> right.SameAs (dummy, wxRight, 10); + b1 -> height.AsIs(); + b1 -> width.AsIs(); + bmpbt -> SetConstraints(b1); + + wxLayoutConstraints *b2 = new wxLayoutConstraints; + wxBitmapButton *bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxDefaultPosition, wxSize(20,20)); + + b2 -> top.SameAs (dummy, wxTop, 10); + b2 -> right.LeftOf (bmpbt, 2); + b2 -> height.AsIs(); + b2 -> width.AsIs(); + bmpbt2 -> SetConstraints(b2); + +#if wxUSE_TOOLTIPS + bmpbt -> SetToolTip(_("Remove current page from bookmarks")); + bmpbt2 -> SetToolTip(_("Add current page to bookmarks")); +#endif //wxUSE_TOOLTIPS + + wxLayoutConstraints *b3 = new wxLayoutConstraints; + m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, wxEmptyString, + wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT); + m_Bookmarks -> Append(_("(bookmarks)")); + for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++) + m_Bookmarks -> Append(m_BookmarksNames[i]); + m_Bookmarks -> SetSelection(0); + + b3 -> centreY.SameAs (bmpbt2, wxCentreY); + b3 -> left.SameAs (dummy, wxLeft, 10); + b3 -> right.LeftOf (bmpbt2, 5); + b3 -> height.AsIs(); + m_Bookmarks -> SetConstraints(b3); + + + wxLayoutConstraints *b4 = new wxLayoutConstraints; + m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL, + wxDefaultPosition, wxDefaultSize, + wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); + m_ContentsBox -> SetImageList(m_ContentsImageList); + + b4 -> top.Below (m_Bookmarks, 10); + b4 -> left.SameAs (dummy, wxLeft, 0); + b4 -> right.SameAs (dummy, wxRight, 0); + b4 -> bottom.SameAs (dummy, wxBottom, 0); + m_ContentsBox -> SetConstraints(b4); + + dummy -> SetAutoLayout(TRUE); + dummy -> Layout(); + + m_NavigPan -> AddPage(dummy, _("Contents")); + } + + else + { + m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL, + wxDefaultPosition, wxDefaultSize, + wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); + m_ContentsBox -> SetImageList(m_ContentsImageList); + m_NavigPan -> AddPage(m_ContentsBox, _("Contents")); + } + m_ContentsPage = notebook_page++; } @@ -311,26 +341,42 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti b1 -> height.AsIs(); m_SearchText -> SetConstraints(b1); + wxLayoutConstraints *b4 = new wxLayoutConstraints; + m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition, + wxDefaultSize); + b4 -> top.Below (m_SearchText, 10); + b4 -> left.SameAs (dummy, wxLeft, 10); + b4 -> right.SameAs (dummy, wxRight, 10); + b4 -> height.AsIs(); + m_SearchChoice -> SetConstraints(b4); + + wxLayoutConstraints *b5 = new wxLayoutConstraints; + m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive")); + b5 -> top.Below (m_SearchChoice, 10); + b5 -> left.SameAs (dummy, wxLeft, 10); + b5 -> width.AsIs(); + b5 -> height.AsIs (); + m_SearchCaseSensitive -> SetConstraints(b5); + + wxLayoutConstraints *b6 = new wxLayoutConstraints; + m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only")); + b6 -> top.Below (m_SearchCaseSensitive, 0); + b6 -> left.SameAs (dummy, wxLeft, 10); + b6 -> width.AsIs(); + b6 -> height.AsIs (); + m_SearchWholeWords -> SetConstraints(b6); + wxLayoutConstraints *b2 = new wxLayoutConstraints; m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search")); #if wxUSE_TOOLTIPS m_SearchButton -> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above")); #endif //wxUSE_TOOLTIPS - b2 -> top.Below (m_SearchText, 10); - b2 -> left.SameAs (dummy, wxLeft, 10); + b2 -> top.Below (m_SearchWholeWords, 0); + b2 -> right.SameAs (dummy, wxRight, 10); b2 -> width.AsIs(); b2 -> height.AsIs(); m_SearchButton -> SetConstraints(b2); - wxLayoutConstraints *b4 = new wxLayoutConstraints; - m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition, - wxDefaultSize); - b4 -> top.Below (m_SearchText, 10); - b4 -> left.SameAs (m_SearchButton, wxRight, 10); - b4 -> right.SameAs (dummy, wxRight, 10); - b4 -> height.AsIs(); - m_SearchChoice -> SetConstraints(b4); - wxLayoutConstraints *b3 = new wxLayoutConstraints; m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_ALWAYS_SB); b3 -> top.Below (m_SearchButton, 10); @@ -346,7 +392,7 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti } m_HtmlWin -> Show(TRUE); - //RefreshLists(); + RefreshLists(); // showtime if (m_NavigPan && m_Splitter) { @@ -371,6 +417,7 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti wxHtmlHelpFrame::~wxHtmlHelpFrame() { + PopEventHandler(); // wxhtmlhelpcontroller delete m_ContentsImageList; if (m_DataCreated) delete m_Data; @@ -378,6 +425,29 @@ wxHtmlHelpFrame::~wxHtmlHelpFrame() if (m_FixedFonts) delete m_FixedFonts; } + +void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style) +{ + toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap, + FALSE, -1, -1, (wxObject *) NULL, + _("Show/hide navigation panel")); + toolBar -> AddSeparator(); + toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap, + FALSE, -1, -1, (wxObject *) NULL, + _("Go back to the previous HTML page")); + toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap, + FALSE, -1, -1, (wxObject *) NULL, + _("Go forward to the next HTML page")); + toolBar -> AddSeparator(); + + toolBar -> AddSeparator(); + toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap, + FALSE, -1, -1, (wxObject *) NULL, + _("Display options dialog")); +} + + + bool wxHtmlHelpFrame::Display(const wxString& x) { wxString url = m_Data->FindPageByName(x); @@ -429,12 +499,14 @@ bool wxHtmlHelpFrame::DisplayIndex() return TRUE; } + + bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) { if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice)) return FALSE; - int foundcnt = 0; + int foundcnt = 0, curi; wxString foundstr; wxString book = wxEmptyString; @@ -451,21 +523,23 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) if (m_SearchChoice->GetSelection() != 0) book = m_SearchChoice->GetStringSelection(); - wxHtmlSearchStatus status(m_Data, keyword, book); + wxHtmlSearchStatus status(m_Data, keyword, + m_SearchCaseSensitive -> GetValue(), m_SearchWholeWords -> GetValue(), + book); wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), status.GetMaxIndex(), this, - wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); + wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE | wxGA_SMOOTH); while (status.IsActive()) { - if (progress.Update(status.GetCurIndex()) == FALSE) + curi = status.GetCurIndex(); + if (curi % 32 == 0 && progress.Update(curi) == FALSE) break; if (status.Search()) { foundstr.Printf(_("Found %i matches"), ++foundcnt); progress.Update(status.GetCurIndex(), foundstr); m_SearchList -> Append(status.GetName(), status.GetContentsItem()); } - wxYield(); } m_SearchButton -> Enable(TRUE); @@ -480,27 +554,18 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) #define MAX_ROOTS 64 -void wxHtmlHelpFrame::CreateContents(bool show_progress) +void wxHtmlHelpFrame::CreateContents() { if (! m_ContentsBox) return ; - wxProgressDialog *progress = NULL; - wxString proginfo; - m_ContentsBox->Clear(); int cnt = m_Data->GetContentsCnt(); - int div = (cnt / PROGRESS_STEP) + 1; int i; wxHtmlContentsItem *it; - if (show_progress) - progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString, - cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | - wxPD_AUTO_HIDE); - wxTreeItemId roots[MAX_ROOTS]; bool imaged[MAX_ROOTS]; @@ -511,12 +576,6 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress) imaged[0] = TRUE; for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) { - if (show_progress && ((i % div) == 0)) { - proginfo.Printf(_("Added %d/%d items"), i, cnt); - if (! progress->Update(i, proginfo)) - break; - wxYield(); - } roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( roots[it -> m_Level], it -> m_Name, IMG_Page, -1, new wxHtmlHelpTreeItemData(it)); @@ -534,20 +593,15 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress) imaged[it -> m_Level] = TRUE; } } - if (show_progress) - delete progress; m_ContentsBox -> Expand(roots[0]); } -void wxHtmlHelpFrame::CreateIndex(bool show_progress) +void wxHtmlHelpFrame::CreateIndex() { if (! m_IndexList) return ; - wxProgressDialog *progress = NULL; - wxString proginfo; - m_IndexList->Clear(); int cnt = m_Data->GetIndexCnt(); @@ -558,26 +612,10 @@ void wxHtmlHelpFrame::CreateIndex(bool show_progress) m_IndexCountInfo -> SetLabel(cnttext); if (cnt > INDEX_IS_SMALL) return; - int div = (cnt / PROGRESS_STEP) + 1; - wxHtmlContentsItem* index = m_Data->GetIndex(); - if (show_progress) - progress = new wxProgressDialog(_("Building index list..."), wxEmptyString, - cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | - wxPD_AUTO_HIDE); - for (int i = 0; i < cnt; i++) { - if (show_progress && ((i % div) == 0)) { - proginfo.Printf(_("Added %d/%d items"), i, cnt); - if (! progress->Update(i, proginfo)) - break; - wxYield(); - } + for (int i = 0; i < cnt; i++) m_IndexList -> Append(index[i].m_Name, (char*)(index + i)); - } - - if (show_progress) - delete progress; } void wxHtmlHelpFrame::CreateSearch() @@ -586,7 +624,7 @@ void wxHtmlHelpFrame::CreateSearch() return ; m_SearchList -> Clear(); m_SearchChoice -> Clear(); - m_SearchChoice -> Append(_("all books")); + m_SearchChoice -> Append(_("Search in all books")); const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); int i, cnt = bookrec.GetCount(); for (i = 0; i < cnt; i++) @@ -595,10 +633,10 @@ void wxHtmlHelpFrame::CreateSearch() } -void wxHtmlHelpFrame::RefreshLists(bool show_progress) +void wxHtmlHelpFrame::RefreshLists() { - CreateContents(show_progress); - CreateIndex(show_progress); + CreateContents(); + CreateIndex(); CreateSearch(); } @@ -609,7 +647,7 @@ void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) if (path != wxEmptyString) { oldpath = cfg -> GetPath(); - cfg -> SetPath(path); + cfg -> SetPath(_T("/") + path); } m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0; @@ -634,7 +672,7 @@ void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) m_BookmarksPages.Clear(); if (m_Bookmarks) { m_Bookmarks -> Clear(); - m_Bookmarks -> Append(_("")); + m_Bookmarks -> Append(_("(bookmarks)")); } for (i = 0; i < cnt; i++) { @@ -650,7 +688,7 @@ void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) } if (m_HtmlWin) - m_HtmlWin->ReadCustomization(cfg, path); + m_HtmlWin->ReadCustomization(cfg); if (path != wxEmptyString) cfg -> SetPath(oldpath); @@ -663,7 +701,7 @@ void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path if (path != wxEmptyString) { oldpath = cfg -> GetPath(); - cfg -> SetPath(path); + cfg -> SetPath(_T("/") + path); } cfg -> Write("hcNavigPanel", m_Cfg.navig_on); @@ -691,7 +729,7 @@ void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path } if (m_HtmlWin) - m_HtmlWin->WriteCustomization(cfg, path); + m_HtmlWin->WriteCustomization(cfg); if (path != wxEmptyString) cfg -> SetPath(oldpath); @@ -1027,7 +1065,7 @@ void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event)) { wxString sr = m_Bookmarks -> GetStringSelection(); - if (sr != wxEmptyString && sr != _("")) + if (sr != wxEmptyString && sr != _("(bookmarks)")) m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]); } @@ -1045,7 +1083,9 @@ void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) } BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) - EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar) + EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar) + EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar) + EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar) EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)