]> git.saurik.com Git - wxWidgets.git/commitdiff
added bookmarks support
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 5 Dec 1999 19:36:20 +0000 (19:36 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 5 Dec 1999 19:36:20 +0000 (19:36 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4829 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/html/helpfrm.h
include/wx/html/msw/wxhtml.rc
src/html/bitmaps/wbkadd.xpm [new file with mode: 0644]
src/html/bitmaps/wbkdel.xpm [new file with mode: 0644]
src/html/helpfrm.cpp

index 9672fe0a7d7e448452c5a18c98787ae9e05d8e4b..806b7d339b4e7cd8f0252a151c99b96c323acc4a 100644 (file)
@@ -28,6 +28,7 @@
 #include "wx/notebook.h"
 #include "wx/listbox.h"
 #include "wx/choice.h"
+#include "wx/combobox.h"
 #include "wx/html/htmlwin.h"
 
 
@@ -36,7 +37,8 @@
 #define wxHF_CONTENTS     0x0002
 #define wxHF_INDEX        0x0004
 #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 :
@@ -46,6 +48,9 @@ enum
     wxID_HTML_BACK,
     wxID_HTML_FORWARD,
     wxID_HTML_OPTIONS,
+    wxID_HTML_BOOKMARKSLIST,
+    wxID_HTML_BOOKMARKSADD,
+    wxID_HTML_BOOKMARKSREMOVE,
     wxID_HTML_TREECTRL,
     wxID_HTML_INDEXPAGE,
     wxID_HTML_INDEXLIST,
@@ -156,6 +161,7 @@ class WXDLLEXPORT wxHtmlHelpFrame : public wxFrame
         void OnIndexSel(wxCommandEvent& event);
         void OnSearchSel(wxCommandEvent& event);
         void OnSearch(wxCommandEvent& event);
+        void OnBookmarksSel(wxCommandEvent& event);
         void OnCloseWindow(wxCloseEvent& event);
 
         // Images:
@@ -182,6 +188,9 @@ class WXDLLEXPORT wxHtmlHelpFrame : public wxFrame
         wxListBox *m_SearchList;
         wxChoice *m_SearchChoice;
 
+        wxComboBox *m_Bookmarks;
+        wxArrayString m_BookmarksNames, m_BookmarksPages;
+
         wxHtmlHelpFrameCfg m_Cfg;
 
         wxConfigBase *m_Config;
index 72dce41f87e7f6885636ccf0c8eab42a0f8cc890..b60f9b87aa5909d17c57c0c57b2760ecd37eddf3 100644 (file)
@@ -10,6 +10,8 @@ wback     BITMAP "wx/html/msw/wback.bmp"
 wforward  BITMAP "wx/html/msw/wforward.bmp"
 wpanel    BITMAP "wx/html/msw/wpanel.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"
 wfolder   ICON "wx/html/msw/wfolder.ico"
diff --git a/src/html/bitmaps/wbkadd.xpm b/src/html/bitmaps/wbkadd.xpm
new file mode 100644 (file)
index 0000000..2590275
--- /dev/null
@@ -0,0 +1,22 @@
+/* XPM */
+static char * wbkadd_xpm[] = {
+"16 16 3 1",
+"      c None",
+".     c #33EF0E",
+"+     c #000000",
+"                ",
+"      ...       ",
+"      ...       ",
+"      ...++     ",
+"      ...++     ",
+"      ...++     ",
+" .............  ",
+" .............  ",
+" .............++",
+"   +++...+++++++",
+"   +++...+++++++",
+"      ...++     ",
+"      ...++     ",
+"      ...++     ",
+"        +++     ",
+"        +++     "};
diff --git a/src/html/bitmaps/wbkdel.xpm b/src/html/bitmaps/wbkdel.xpm
new file mode 100644 (file)
index 0000000..ca6b6b7
--- /dev/null
@@ -0,0 +1,22 @@
+/* XPM */
+static char * wbkdel_xpm[] = {
+"16 16 3 1",
+"      c None",
+".     c #FF0000",
+"+     c #000000",
+"                ",
+" ...         .  ",
+" ....      ..+  ",
+" +....    ..+   ",
+"  ++...  ..+    ",
+"    +.....+     ",
+"     +...+      ",
+"     .....      ",
+"    ...++..     ",
+"   ...+  +..    ",
+"  ...+    +.    ",
+" ....      +.   ",
+" ...+       +   ",
+" +.+         .  ",
+"  +          +  ",
+"                "};
index 9d86198baec4037743d8d12e4046274e771d4ab5..e41032ab9f00a5ff60db63648034cb9bea0ba2f5 100644 (file)
@@ -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;
 
@@ -172,6 +178,23 @@ 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,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 -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
@@ -439,7 +462,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 +563,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(_("<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)
         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("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);
@@ -614,7 +677,13 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog
                 sizer2 = new wxBoxSizer(wxVERTICAL);
                 sizer2 -> Add(new wxStaticText(this, -1, _("Normal font:")), 
                               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);
 
                 sizer3 = new wxBoxSizer(wxHORIZONTAL);
@@ -629,7 +698,13 @@ class wxHtmlHelpFrameOptionsDialog : public wxDialog
                 sizer2 = new wxBoxSizer(wxVERTICAL);
                 sizer2 -> Add(new wxStaticText(this, -1, _("Fixed font:")), 
                               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);
 
                 sizer3 = new wxBoxSizer(wxHORIZONTAL);
@@ -766,12 +841,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 ;
@@ -786,9 +864,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;
     }
 }
 
@@ -825,6 +935,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 != _("<bookmarks>"))
+        m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
+}
+
 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
 {
     GetSize(&m_Cfg.w, &m_Cfg.h);
@@ -839,13 +957,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