]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/helpwxht.cpp
update focus rectangle width when the columns are being added/removed on the fly
[wxWidgets.git] / src / generic / helpwxht.cpp
index 5e4ad3fa930c213a81643f2406327999a08c72bc..0ee358cc5d350438540aa32f2824b76510b993a6 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        helpext.cpp
-// Purpose:     an external help controller for wxWindows
+// Name:        helpwxht.cpp
+// Purpose:     A help controller using the wxHTML classes
 // Author:      Karsten Ballueder
 // Modified by:
 // Created:     04/01/98
 #   pragma hdrstop
 #endif
 
+#if wxUSE_WXHTML_HELP
+
 #ifndef WX_PRECOMP
-#   include "wx/setup.h"
-#   include "wx/string.h"
-#   include "wx/utils.h"
-#   include "wx/list.h"
-#   include "wx/intl.h"
-#   include "wx/layout.h"
+    #include "wx/string.h"
+    #include "wx/utils.h"
+    #include "wx/list.h"
+    #include "wx/intl.h"
+    #include "wx/layout.h"
+    #include "wx/combobox.h"
+    #include "wx/button.h"
 #endif
 
 #include "wx/helpbase.h"
 
 #include <stdio.h>
 #include <ctype.h>
+#ifndef __MWERKS__
 #include <sys/stat.h>
+#endif
 
-#ifndef __WINDOWS__
+#if !defined(__WINDOWS__) && !defined(__OS2__)
 #   include   <unistd.h>
 #endif
 
+#ifdef __WXMAC__
+    #include "wx/mac/private.h"
+#endif
+
 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
-#define FRAME_HEIGHT 400   
+class wxForceHtmlFilter : public wxHtmlFilter
+{
+public:
+   virtual wxString ReadFile(const wxFSFile& file) const
+      {
+         wxInputStream *s = file.GetStream();
+         char *src;
+         wxString doc;
+
+         if (s == NULL) return wxEmptyString;
+         src = new char[s -> GetSize()+1];
+         src[s -> GetSize()] = 0;
+         s -> Read(src, s -> GetSize());
+         doc = src;
+         delete [] src;
+         return doc;
+      }
+
+    virtual bool CanRead(const wxFSFile& file) const
+      {
+         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
 {
 public:
@@ -62,17 +104,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->GetCount() < 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,
@@ -81,18 +149,81 @@ wxHelpFrame::wxHelpFrame(wxWindow *parent, int id,
 {
 
    m_controller = controller;
-   m_htmlwin = new wxHtmlWindow(this,-1,wxDefaultPosition,wxSize(FRAME_WIDTH, 
+   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);
+
+#ifdef __WXMOTIF__
+   // Motif needs a nudge to get it to resize properly
+   // when shown
+   wxSizeEvent event(size, GetId());
+   GetEventHandler()->ProcessEvent(event);
+#endif
+
    Show(TRUE);
 }
 
@@ -101,7 +232,7 @@ wxHelpFrame::~wxHelpFrame()
 }
 
 void
-wxHelpFrame::OnClose(wxCloseEvent &ev)
+wxHelpFrame::OnClose(wxCloseEvent &WXUNUSED(ev))
 {
    wxASSERT(m_controller);
    m_controller->m_Frame = NULL;
@@ -120,8 +251,8 @@ wxHelpControllerHtml::wxHelpControllerHtml(void)
 {
    m_Frame = NULL;
    m_offset = 0;
-   
-   SetFrameParameters(_("Help"),
+
+   SetFrameParameters(_("Help: %s"),
                       wxSize(FRAME_WIDTH, FRAME_HEIGHT),
                       wxDefaultPosition);
 }
@@ -140,12 +271,16 @@ wxHelpControllerHtml::~wxHelpControllerHtml(void)
 #endif
 
 bool
-wxHelpControllerHtml::DisplayHelp(wxString const &relativeURL)
+wxHelpControllerHtml::DisplayHelp(const wxString &relativeURL)
 {
    wxBusyCursor b; // display a busy cursor
 
    wxString url;
-   url << m_MapFile << SEP<< relativeURL;
+   wxString mapfileurl = m_MapFile ;
+#if defined(__WXMAC__) && !defined(__DARWIN__)
+    mapfileurl = wxMac2UnixFilename(m_MapFile) ;
+#endif
+   url << mapfileurl << SEP<< relativeURL;
    if(! m_Frame || m_NewFrameEachTime)
    {
       m_Frame = new wxHelpFrame(NULL, -1, m_FrameTitle,
@@ -158,8 +293,9 @@ wxHelpControllerHtml::DisplayHelp(wxString const &relativeURL)
          if(m_offset > 200)
             m_offset = 0;
       }
-      
+
    }
+   m_Frame->Raise();
    return m_Frame->LoadPage(url);
 }
 
@@ -176,12 +312,16 @@ wxHelpControllerHtml::SetFrameParameters(const wxString &title,
    m_NewFrameEachTime = newFrame;
 }
 
-void
-wxHelpControllerHtml::GetFrameParameters(wxSize *size = NULL,
-                                         wxPoint *pos = NULL,
-                                         bool *newframe = NULL)
+wxFrame *
+wxHelpControllerHtml::GetFrameParameters(wxSize *size,
+                                         wxPoint *pos,
+                                         bool *newframe)
 {
    if(size) *size = m_FrameSize;
    if(pos) *pos = m_FramePosition;
    if(newframe) *newframe = m_NewFrameEachTime;
+   return m_Frame;
 }
+
+#endif // wxUSE_WXHTML_HELP
+