X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83efdf3393ca396e96d44892eae0a77cb772f6f2..b4d1ebf058c64f5b9e0ddf3264ce8a801eae4f79:/src/html/helpfrm.cpp diff --git a/src/html/helpfrm.cpp b/src/html/helpfrm.cpp index 246f238678..573121b725 100644 --- a/src/html/helpfrm.cpp +++ b/src/html/helpfrm.cpp @@ -52,6 +52,8 @@ #include "bitmaps/wpage.xpm" #include "bitmaps/whelp.xpm" #include "bitmaps/whlproot.xpm" +#include "bitmaps/wbkadd.xpm" +#include "bitmaps/wbkdel.xpm" #endif #include "wx/stream.h" @@ -61,7 +63,7 @@ #define PROGRESS_STEP 40 //-------------------------------------------------------------------------- -// wxHtmlHelpTreeItemData +// wxHtmlHelpTreeItemData (private) //-------------------------------------------------------------------------- class wxHtmlHelpTreeItemData : public wxTreeItemData @@ -71,12 +73,15 @@ class wxHtmlHelpTreeItemData : public wxTreeItemData public: wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData() - { - m_Page = it -> m_Book -> GetBasePath() + it -> m_Page; - } + { + m_Page = it -> m_Book -> GetBasePath() + it -> m_Page; + } const wxString& GetPage() { return m_Page; } }; + + + //--------------------------------------------------------------------------- // wxHtmlHelpFrame //--------------------------------------------------------------------------- @@ -115,6 +120,7 @@ void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) m_Splitter = NULL; m_NavigPan = NULL; m_HtmlWin = NULL; + m_Bookmarks = NULL; m_Config = NULL; m_ConfigRoot = wxEmptyString; @@ -160,7 +166,7 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti // toolbar? if (style & wxHF_TOOLBAR) { wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE); - toolBar -> SetMargins(2, 2); + toolBar->SetMargins( 2, 2 ); toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, @@ -172,6 +178,26 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti 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, @@ -439,7 +465,7 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress) break; wxYield(); } - roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( + roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem( roots[it -> m_Level], it -> m_Name, IMG_Page, -1, new wxHtmlHelpTreeItemData(it)); @@ -540,6 +566,32 @@ void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) m_NormalItalic = cfg -> Read("hcNormalItalic", m_NormalItalic); m_FixedItalic = cfg -> Read("hcFixedItalic", m_FixedItalic); + { + int i; + int cnt; + wxString val, s; + + cnt = cfg -> Read("hcBookmarksCnt", 0L); + if (cnt != 0) { + m_BookmarksNames.Clear(); + m_BookmarksPages.Clear(); + if (m_Bookmarks) { + m_Bookmarks -> Clear(); + m_Bookmarks -> Append(_("")); + } + + for (i = 0; i < cnt; i++) { + val.Printf("hcBookmark_%i", i); + s = cfg -> Read(val); + m_BookmarksNames.Add(s); + if (m_Bookmarks) m_Bookmarks -> Append(s); + val.Printf("hcBookmark_%i_url", i); + s = cfg -> Read(val); + m_BookmarksPages.Add(s); + } + } + } + if (m_HtmlWin) m_HtmlWin->ReadCustomization(cfg, path); @@ -568,6 +620,20 @@ void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path cfg -> Write("hcFontSize", (long)m_FontSize); cfg -> Write("hcNormalItalic", (long)m_NormalItalic); cfg -> Write("hcFixedItalic", (long)m_FixedItalic); + + if (m_Bookmarks) { + int i; + int cnt = m_BookmarksNames.GetCount(); + wxString val; + + cfg -> Write("hcBookmarksCnt", (long)cnt); + for (i = 0; i < cnt; i++) { + val.Printf("hcBookmark_%i", i); + cfg -> Write(val, m_BookmarksNames[i]); + val.Printf("hcBookmark_%i_url", i); + cfg -> Write(val, m_BookmarksPages[i]); + } + } if (m_HtmlWin) m_HtmlWin->WriteCustomization(cfg, path); @@ -582,21 +648,13 @@ void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, int scalit, wxString fixf, int fixit, int size) { -#ifdef __WXMSW__ - static int f_sizes[3][7] = - { - {10, 12, 14, 16, 19, 24, 32}, - {12, 14, 16, 18, 24, 32, 38}, - {14, 16, 18, 24, 32, 38, 45} - }; -#else static int f_sizes[3][7] = { + { 8, 9, 12, 14, 16, 19, 22}, {10, 12, 14, 16, 19, 24, 32}, - {12, 14, 16, 18, 24, 32, 38}, {14, 16, 18, 24, 32, 38, 45} }; -#endif + win -> SetFonts(scalf, scalit, fixf, fixit, f_sizes[size]); } @@ -604,15 +662,15 @@ static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, int scalit, wxS class wxHtmlHelpFrameOptionsDialog : public wxDialog { public: - wxListBox *NormalFont, *FixedFont; + wxComboBox *NormalFont, *FixedFont; wxRadioButton *SFI_i, *SFI_s, *FFI_i, *FFI_s; wxRadioBox *RadioBox; wxHtmlWindow *TestWin; wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options"))) { - static wxString choices[3] = {_("small"), _("medium"), _("large")}; - static wxString choices2[2] = {_("italic"), _("slant")}; + wxString choices[3] = {_("small"), _("medium"), _("large")}; + wxString choices2[2] = {_("italic"), _("slant")}; wxBoxSizer *topsizer, *sizer, *sizer2, *sizer3; topsizer = new wxBoxSizer(wxVERTICAL); @@ -622,7 +680,9 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog sizer2 = new wxBoxSizer(wxVERTICAL); sizer2 -> Add(new wxStaticText(this, -1, _("Normal font:")), 0, wxLEFT | wxTOP, 10); - sizer2 -> Add(NormalFont = new wxListBox(this, -1, wxDefaultPosition, wxSize(200, 150)), + sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, + wxSize(200, 200), + 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), 1, wxEXPAND | wxLEFT | wxRIGHT, 10); sizer3 = new wxBoxSizer(wxHORIZONTAL); @@ -637,7 +697,9 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog sizer2 = new wxBoxSizer(wxVERTICAL); sizer2 -> Add(new wxStaticText(this, -1, _("Fixed font:")), 0, wxLEFT | wxTOP, 10); - sizer2 -> Add(FixedFont = new wxListBox(this, -1, wxDefaultPosition, wxSize(200, 150)), + sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, + wxSize(200, 200), + 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), 1, wxEXPAND | wxLEFT | wxRIGHT, 10); sizer3 = new wxBoxSizer(wxHORIZONTAL); @@ -711,7 +773,7 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog }; BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog) - EVT_LISTBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) + EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) EVT_RADIOBUTTON(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) END_EVENT_TABLE() @@ -774,12 +836,15 @@ EVENT HANDLING : void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) { switch (event.GetId()) { + case wxID_HTML_BACK : m_HtmlWin -> HistoryBack(); break; + case wxID_HTML_FORWARD : m_HtmlWin -> HistoryForward(); break; + case wxID_HTML_PANEL : if (! (m_Splitter && m_NavigPan)) return ; @@ -794,9 +859,41 @@ void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) m_Cfg.navig_on = TRUE; } break; + case wxID_HTML_OPTIONS : OptionsDialog(); break; + + case wxID_HTML_BOOKMARKSADD : + { + wxString item; + wxString url; + + item = m_HtmlWin -> GetOpenedPageTitle(); + url = m_HtmlWin -> GetOpenedPage(); + if (item == wxEmptyString) item = url.AfterLast(wxT('/')); + if (m_BookmarksPages.Index(url) == wxNOT_FOUND) { + m_Bookmarks -> Append(item); + m_BookmarksNames.Add(item); + m_BookmarksPages.Add(url); + } + } + break; + + case wxID_HTML_BOOKMARKSREMOVE : + { + wxString item; + int pos; + + item = m_Bookmarks -> GetStringSelection(); + pos = m_BookmarksNames.Index(item); + if (pos != wxNOT_FOUND) { + m_BookmarksNames.Remove(pos); + m_BookmarksPages.Remove(pos); + m_Bookmarks -> Delete(m_Bookmarks -> GetSelection()); + } + } + break; } } @@ -833,6 +930,14 @@ void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) if (sr != wxEmptyString) KeywordSearch(sr); } +void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event)) +{ + wxString sr = m_Bookmarks -> GetStringSelection(); + + if (sr != wxEmptyString && sr != _("")) + m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]); +} + void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) { GetSize(&m_Cfg.w, &m_Cfg.h); @@ -847,13 +952,14 @@ void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) } BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) - EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar) + EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_BOOKMARKSREMOVE, 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) EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) - EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) + EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel) + EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) END_EVENT_TABLE() #endif