added bookmarks support

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4829 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
1999-12-05 19:36:20 +00:00
parent fb5700fe76
commit 382e6efee4
5 changed files with 184 additions and 10 deletions

View File

@@ -28,6 +28,7 @@
#include "wx/notebook.h" #include "wx/notebook.h"
#include "wx/listbox.h" #include "wx/listbox.h"
#include "wx/choice.h" #include "wx/choice.h"
#include "wx/combobox.h"
#include "wx/html/htmlwin.h" #include "wx/html/htmlwin.h"
@@ -36,7 +37,8 @@
#define wxHF_CONTENTS 0x0002 #define wxHF_CONTENTS 0x0002
#define wxHF_INDEX 0x0004 #define wxHF_INDEX 0x0004
#define wxHF_SEARCH 0x0008 #define wxHF_SEARCH 0x0008
#define wxHF_DEFAULTSTYLE (wxHF_TOOLBAR | wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH) #define wxHF_BOOKMARKS 0x0010
#define wxHF_DEFAULTSTYLE (wxHF_TOOLBAR | wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH | wxHF_BOOKMARKS)
// Command IDs : // Command IDs :
@@ -46,6 +48,9 @@ enum
wxID_HTML_BACK, wxID_HTML_BACK,
wxID_HTML_FORWARD, wxID_HTML_FORWARD,
wxID_HTML_OPTIONS, wxID_HTML_OPTIONS,
wxID_HTML_BOOKMARKSLIST,
wxID_HTML_BOOKMARKSADD,
wxID_HTML_BOOKMARKSREMOVE,
wxID_HTML_TREECTRL, wxID_HTML_TREECTRL,
wxID_HTML_INDEXPAGE, wxID_HTML_INDEXPAGE,
wxID_HTML_INDEXLIST, wxID_HTML_INDEXLIST,
@@ -156,6 +161,7 @@ class WXDLLEXPORT wxHtmlHelpFrame : public wxFrame
void OnIndexSel(wxCommandEvent& event); void OnIndexSel(wxCommandEvent& event);
void OnSearchSel(wxCommandEvent& event); void OnSearchSel(wxCommandEvent& event);
void OnSearch(wxCommandEvent& event); void OnSearch(wxCommandEvent& event);
void OnBookmarksSel(wxCommandEvent& event);
void OnCloseWindow(wxCloseEvent& event); void OnCloseWindow(wxCloseEvent& event);
// Images: // Images:
@@ -182,6 +188,9 @@ class WXDLLEXPORT wxHtmlHelpFrame : public wxFrame
wxListBox *m_SearchList; wxListBox *m_SearchList;
wxChoice *m_SearchChoice; wxChoice *m_SearchChoice;
wxComboBox *m_Bookmarks;
wxArrayString m_BookmarksNames, m_BookmarksPages;
wxHtmlHelpFrameCfg m_Cfg; wxHtmlHelpFrameCfg m_Cfg;
wxConfigBase *m_Config; wxConfigBase *m_Config;

View File

@@ -10,6 +10,8 @@ wback BITMAP "wx/html/msw/wback.bmp"
wforward BITMAP "wx/html/msw/wforward.bmp" wforward BITMAP "wx/html/msw/wforward.bmp"
wpanel BITMAP "wx/html/msw/wpanel.bmp" wpanel BITMAP "wx/html/msw/wpanel.bmp"
woptions BITMAP "wx/html/msw/woptions.bmp" woptions BITMAP "wx/html/msw/woptions.bmp"
wbkadd BITMAP "wx/html/msw/wbkadd.bmp"
wbkdel BITMAP "wx/html/msw/wbkdel.bmp"
wbook ICON "wx/html/msw/wbook.ico" wbook ICON "wx/html/msw/wbook.ico"
wfolder ICON "wx/html/msw/wfolder.ico" wfolder ICON "wx/html/msw/wfolder.ico"

View File

@@ -0,0 +1,22 @@
/* XPM */
static char * wbkadd_xpm[] = {
"16 16 3 1",
" c None",
". c #33EF0E",
"+ c #000000",
" ",
" ... ",
" ... ",
" ...++ ",
" ...++ ",
" ...++ ",
" ............. ",
" ............. ",
" .............++",
" +++...+++++++",
" +++...+++++++",
" ...++ ",
" ...++ ",
" ...++ ",
" +++ ",
" +++ "};

View File

@@ -0,0 +1,22 @@
/* XPM */
static char * wbkdel_xpm[] = {
"16 16 3 1",
" c None",
". c #FF0000",
"+ c #000000",
" ",
" ... . ",
" .... ..+ ",
" +.... ..+ ",
" ++... ..+ ",
" +.....+ ",
" +...+ ",
" ..... ",
" ...++.. ",
" ...+ +.. ",
" ...+ +. ",
" .... +. ",
" ...+ + ",
" +.+ . ",
" + + ",
" "};

View File

@@ -52,6 +52,8 @@
#include "bitmaps/wpage.xpm" #include "bitmaps/wpage.xpm"
#include "bitmaps/whelp.xpm" #include "bitmaps/whelp.xpm"
#include "bitmaps/whlproot.xpm" #include "bitmaps/whlproot.xpm"
#include "bitmaps/wbkadd.xpm"
#include "bitmaps/wbkdel.xpm"
#endif #endif
#include "wx/stream.h" #include "wx/stream.h"
@@ -61,7 +63,7 @@
#define PROGRESS_STEP 40 #define PROGRESS_STEP 40
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// wxHtmlHelpTreeItemData // wxHtmlHelpTreeItemData (private)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
class wxHtmlHelpTreeItemData : public wxTreeItemData class wxHtmlHelpTreeItemData : public wxTreeItemData
@@ -71,12 +73,15 @@ class wxHtmlHelpTreeItemData : public wxTreeItemData
public: public:
wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData() 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; } const wxString& GetPage() { return m_Page; }
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxHtmlHelpFrame // wxHtmlHelpFrame
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -115,6 +120,7 @@ void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
m_Splitter = NULL; m_Splitter = NULL;
m_NavigPan = NULL; m_NavigPan = NULL;
m_HtmlWin = NULL; m_HtmlWin = NULL;
m_Bookmarks = NULL;
m_Config = NULL; m_Config = NULL;
m_ConfigRoot = wxEmptyString; m_ConfigRoot = wxEmptyString;
@@ -172,6 +178,23 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti
toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap, toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap,
FALSE, -1, -1, (wxObject *) NULL, FALSE, -1, -1, (wxObject *) NULL,
_("Go forward to the next HTML page")); _("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,200), 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);
toolBar -> AddControl(m_Bookmarks);
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 -> AddSeparator();
toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap, toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
@@ -439,7 +462,7 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress)
break; break;
wxYield(); 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, roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
new wxHtmlHelpTreeItemData(it)); new wxHtmlHelpTreeItemData(it));
@@ -540,6 +563,32 @@ void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
m_NormalItalic = cfg -> Read("hcNormalItalic", m_NormalItalic); m_NormalItalic = cfg -> Read("hcNormalItalic", m_NormalItalic);
m_FixedItalic = cfg -> Read("hcFixedItalic", m_FixedItalic); 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(_("<bookmarks>"));
}
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) if (m_HtmlWin)
m_HtmlWin->ReadCustomization(cfg, path); m_HtmlWin->ReadCustomization(cfg, path);
@@ -568,6 +617,20 @@ void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path
cfg -> Write("hcFontSize", (long)m_FontSize); cfg -> Write("hcFontSize", (long)m_FontSize);
cfg -> Write("hcNormalItalic", (long)m_NormalItalic); cfg -> Write("hcNormalItalic", (long)m_NormalItalic);
cfg -> Write("hcFixedItalic", (long)m_FixedItalic); 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) if (m_HtmlWin)
m_HtmlWin->WriteCustomization(cfg, path); m_HtmlWin->WriteCustomization(cfg, path);
@@ -614,7 +677,13 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog
sizer2 = new wxBoxSizer(wxVERTICAL); sizer2 = new wxBoxSizer(wxVERTICAL);
sizer2 -> Add(new wxStaticText(this, -1, _("Normal font:")), sizer2 -> Add(new wxStaticText(this, -1, _("Normal font:")),
0, wxLEFT | wxTOP, 10); 0, wxLEFT | wxTOP, 10);
sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
//#ifdef __WXMSW__
wxSize(200, 200),
//#else
// wxSize(200, -1),
//#endif // FIXME: temporarily commented by VS to demonstrate the problem
0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
1, wxEXPAND | wxLEFT | wxRIGHT, 10); 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
sizer3 = new wxBoxSizer(wxHORIZONTAL); sizer3 = new wxBoxSizer(wxHORIZONTAL);
@@ -629,7 +698,13 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog
sizer2 = new wxBoxSizer(wxVERTICAL); sizer2 = new wxBoxSizer(wxVERTICAL);
sizer2 -> Add(new wxStaticText(this, -1, _("Fixed font:")), sizer2 -> Add(new wxStaticText(this, -1, _("Fixed font:")),
0, wxLEFT | wxTOP, 10); 0, wxLEFT | wxTOP, 10);
sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY), sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
//#ifdef __WXMSW__
wxSize(200, 200),
//#else
// wxSize(200, -1),
//#endif // FIXME: temporarily commented by VS to demonstrate the problem
0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
1, wxEXPAND | wxLEFT | wxRIGHT, 10); 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
sizer3 = new wxBoxSizer(wxHORIZONTAL); sizer3 = new wxBoxSizer(wxHORIZONTAL);
@@ -766,12 +841,15 @@ EVENT HANDLING :
void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
{ {
switch (event.GetId()) { switch (event.GetId()) {
case wxID_HTML_BACK : case wxID_HTML_BACK :
m_HtmlWin -> HistoryBack(); m_HtmlWin -> HistoryBack();
break; break;
case wxID_HTML_FORWARD : case wxID_HTML_FORWARD :
m_HtmlWin -> HistoryForward(); m_HtmlWin -> HistoryForward();
break; break;
case wxID_HTML_PANEL : case wxID_HTML_PANEL :
if (! (m_Splitter && m_NavigPan)) if (! (m_Splitter && m_NavigPan))
return ; return ;
@@ -786,9 +864,41 @@ void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
m_Cfg.navig_on = TRUE; m_Cfg.navig_on = TRUE;
} }
break; break;
case wxID_HTML_OPTIONS : case wxID_HTML_OPTIONS :
OptionsDialog(); OptionsDialog();
break; 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;
} }
} }
@@ -825,6 +935,14 @@ void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
if (sr != wxEmptyString) KeywordSearch(sr); if (sr != wxEmptyString) KeywordSearch(sr);
} }
void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
{
wxString sr = m_Bookmarks -> GetStringSelection();
if (sr != wxEmptyString && sr != _("<bookmarks>"))
m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
}
void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
{ {
GetSize(&m_Cfg.w, &m_Cfg.h); GetSize(&m_Cfg.w, &m_Cfg.h);
@@ -839,13 +957,14 @@ void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
} }
BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) 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_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, 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() END_EVENT_TABLE()
#endif #endif