]> git.saurik.com Git - wxWidgets.git/commitdiff
Much improved wxHelpControllerHtml, works under Solaris, too now.
authorKarsten Ballüder <ballueder@usa.net>
Wed, 21 Jul 1999 13:32:08 +0000 (13:32 +0000)
committerKarsten Ballüder <ballueder@usa.net>
Wed, 21 Jul 1999 13:32:08 +0000 (13:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3069 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/help/demo.cpp
src/generic/helphtml.cpp
src/generic/helpwxht.cpp
src/html/htmlfilter.cpp

index a2233f7fa715f76ad6daa879bc73508f88f0c6ef..df29ed2e264fcd8db0c4b86062ce3f2209e55d53 100644 (file)
@@ -32,7 +32,7 @@
 
 // define this to 1 to use HTML help even under Windows (by default, Windows
 // version will HLP-based help)
-#define USE_HTML_HELP 1
+//#define USE_HTML_HELP 1
 #if USE_HTML_HELP
 #   include "wx/helpbase.h"
 #else
index 3c546e1bd2cc79c727c40d127d49fb0cf981042b..cabeb9a82543d98ba224e0350712f6c2539cd7a7 100644 (file)
@@ -197,8 +197,12 @@ wxHTMLHelpControllerBase::DisplayContents()
 {
    if(! m_NumOfEntries)
       return FALSE;
-   wxBusyCursor b; // display a busy cursor
-   return KeywordSearch("");
+
+   // use ID 0 for contents
+   if(! DisplaySection(0))
+      return KeywordSearch("");
+   else
+      return TRUE;
 }
 
 bool
index 7de0850b59e08f8579a537fc822c2d3bf3048adc..e6210c9e1339a3243f340112aadb8988c22bd24e 100644 (file)
 IMPLEMENT_CLASS(wxHelpControllerHtml, wxHTMLHelpControllerBase)
 
 /**
-   This class implements help via an external browser.
+   This class implements help via wxHTML.
    It requires the name of a directory containing the documentation
    and a file mapping numerical Section numbers to relative URLS.
 */
 
-#define FRAME_WIDTH  400
+class wxForceHtmlFilter : public wxHtmlFilter
+{
+public:
+   virtual wxString ReadFile(const wxFSFile& file)
+      {
+         wxInputStream *s = file.GetStream();
+         char *src;
+         wxString doc;
+
+         if (s == NULL) return wxEmptyString;
+         src = new char[s -> StreamSize()+1];
+         src[s -> StreamSize()] = 0;
+         s -> Read(src, s -> StreamSize());
+         doc = src;
+         delete [] src;
+         return doc;
+      }
+   
+    virtual bool CanRead(const wxFSFile& file)
+      {
+         wxString filename = file.GetLocation();
+         if(filename.Length() >= 5 &&
+            (
+               filename.Right(4).MakeUpper() == ".HTM" ||
+               filename.Right(5).MakeUpper() == ".HTML"))
+            return TRUE;
+         else
+            return FALSE;
+      }
+};
+
+#define FRAME_WIDTH  500
 #define FRAME_HEIGHT 400
 #define LAYOUT_X_MARGIN 2
 #define LAYOUT_Y_MARGIN 2
 #define OFFSET 10
+#define BUTTON_WIDTH  70
+#define MAX_COMBO_ENTRIES   25
 
 class wxHelpFrame : public wxFrame
 {
@@ -63,17 +96,43 @@ public:
                wxHelpControllerHtml *controller);
    ~wxHelpFrame();
    void OnClose(wxCloseEvent &ev);
+   void OnButton(wxCommandEvent &ev);
    bool LoadPage(const wxString &url) { return m_htmlwin->LoadPage(url); }
 private:
    wxHelpControllerHtml *m_controller;
    wxHtmlWindow         *m_htmlwin;
+   wxHtmlFilter         *m_filter;
+   wxComboBox           *m_combo;
+   long m_IdBack, m_IdFwd, m_IdContents, m_IdCombo, m_IdSearch;
    DECLARE_EVENT_TABLE()
 };
 
 BEGIN_EVENT_TABLE(wxHelpFrame, wxFrame)
    EVT_CLOSE(wxHelpFrame::OnClose)
+   EVT_BUTTON(-1, wxHelpFrame::OnButton)
 END_EVENT_TABLE()
 
+
+void
+wxHelpFrame::OnButton(wxCommandEvent &ev)
+{
+   long id =ev.GetId();
+
+   if(id == m_IdBack)
+      m_htmlwin->HistoryBack();
+   else if(id == m_IdFwd)
+      m_htmlwin->HistoryForward();
+   else if(id == m_IdContents)
+      m_controller->DisplayContents();
+   else if(id == m_IdSearch)
+   {
+      wxString str = m_combo->GetValue();
+      if(m_combo->FindString(str) == -1 && m_combo->Number() < MAX_COMBO_ENTRIES)
+         m_combo->Append(str);
+      m_controller->KeywordSearch(str);
+   }
+}
+
 wxHelpFrame::wxHelpFrame(wxWindow *parent, int id,
                          const wxString &title,
                          const wxPoint &pos, const wxSize &size,
@@ -85,20 +144,77 @@ wxHelpFrame::wxHelpFrame(wxWindow *parent, int id,
    m_htmlwin = new wxHtmlWindow(this,-1,wxDefaultPosition,wxSize(FRAME_WIDTH,
                                                           FRAME_HEIGHT));
 
+   m_IdBack = wxWindow::NewControlId();
+   m_IdFwd = wxWindow::NewControlId();
+   m_IdContents = wxWindow::NewControlId();
+   m_IdCombo = wxWindow::NewControlId();
+   m_IdSearch = wxWindow::NewControlId();
+
+   wxButton *btn_back = new wxButton(this, m_IdBack, _("Back"));
+   wxButton *btn_fwd = new wxButton(this, m_IdFwd, _("Forward"));
+   wxButton *btn_contents = new wxButton(this, m_IdContents, _("Contents"));
+   m_combo = new wxComboBox(this, m_IdCombo);
+   wxButton *btn_search = new wxButton(this, m_IdSearch, _("Search"));
+   
+   m_filter = new wxForceHtmlFilter;
+
    wxLayoutConstraints *c;
 
    c = new wxLayoutConstraints;
    c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN);
-   c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
+   c->width.Absolute(BUTTON_WIDTH);
    c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN);
+   c->height.AsIs();
+   btn_back->SetConstraints(c);
+
+   c = new wxLayoutConstraints;
+   c->left.SameAs(btn_back, wxRight, 2*LAYOUT_X_MARGIN);
+   c->width.Absolute(BUTTON_WIDTH);
+   c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN);
+   c->height.AsIs();
+   btn_fwd->SetConstraints(c);
+   
+   c = new wxLayoutConstraints;
+   c->left.SameAs(btn_fwd, wxRight, 2*LAYOUT_X_MARGIN);
+   c->width.Absolute(BUTTON_WIDTH);
+   c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN);
+   c->height.AsIs();
+   btn_contents->SetConstraints(c);
+
+   c = new wxLayoutConstraints;
+   c->left.SameAs(btn_contents, wxRight, 2*LAYOUT_X_MARGIN);
+   c->width.Absolute(3*BUTTON_WIDTH);
+   c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN);
+   c->height.AsIs();
+   m_combo->SetConstraints(c);
+
+   c = new wxLayoutConstraints;
+   c->left.SameAs(m_combo, wxRight, 2*LAYOUT_X_MARGIN);
+   c->width.Absolute(BUTTON_WIDTH);
+   c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN);
+   c->height.AsIs();
+   btn_search->SetConstraints(c);
+
+
+   c = new wxLayoutConstraints;
+   c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN);
+   c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
+   c->top.SameAs(btn_back, wxBottom, 2*LAYOUT_Y_MARGIN);
    c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
    m_htmlwin->SetConstraints(c);
    SetAutoLayout(TRUE);
+   CreateStatusBar();
+   m_htmlwin->SetRelatedFrame(this, title);
+   m_htmlwin->SetRelatedStatusBar(0);
+   m_htmlwin->AddFilter(m_filter);
+
    Show(TRUE);
 }
 
 wxHelpFrame::~wxHelpFrame()
 {
+//   delete m_filter;
 }
 
 void
@@ -122,7 +238,7 @@ wxHelpControllerHtml::wxHelpControllerHtml(void)
    m_Frame = NULL;
    m_offset = 0;
 
-   SetFrameParameters(_("Help"),
+   SetFrameParameters(_("Help: %s"),
                       wxSize(FRAME_WIDTH, FRAME_HEIGHT),
                       wxDefaultPosition);
 }
@@ -161,6 +277,7 @@ wxHelpControllerHtml::DisplayHelp(wxString const &relativeURL)
       }
 
    }
+   m_Frame->Raise();
    return m_Frame->LoadPage(url);
 }
 
index 792240be7e4f6bf98ba3429de6622e1bc65de303..8673e543571ecfd1059a386f0904fbdd068152a5 100644 (file)
@@ -57,11 +57,11 @@ wxString wxHtmlFilterPlainText::ReadFile(const wxFSFile& file)
     wxString doc, doc2;
 
     if (s == NULL) return wxEmptyString;
-    src = (char*) malloc(s -> StreamSize());
+    src = new char[s -> StreamSize()+1];
     src[s -> StreamSize()] = 0;
     s -> Read(src, s -> StreamSize());
     doc = src;
-    free(src);
+    delete [] src;
 
     doc.Replace("<", "&lt;", TRUE);
     doc.Replace(">", "&gt;", TRUE);
@@ -167,4 +167,4 @@ class wxHtmlFilterModule : public wxModule
 
 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule, wxModule)
 
-#endif
\ No newline at end of file
+#endif