]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxHelpControllerHtml, derived from wxHtmlHelpControllerBase. API like
authorKarsten Ballüder <ballueder@usa.net>
Sun, 18 Jul 1999 18:09:46 +0000 (18:09 +0000)
committerKarsten Ballüder <ballueder@usa.net>
Sun, 18 Jul 1999 18:09:46 +0000 (18:09 +0000)
wxExtHelpController and fully backwards compatible with the "old" help
controller. Docs follow tomorrow. Modified sample to use it if wxHTML is
compiled in.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3035 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/helpext.h
include/wx/generic/helphtml.h
include/wx/generic/helpwxht.h [new file with mode: 0644]
include/wx/helpbase.h
samples/help/demo.cpp
src/generic/helpwxht.cpp [new file with mode: 0644]
src/gtk/Makefile.am
src/gtk1/Makefile.am

index 19d5b1e652d9a0907c0cebf484876167ce781e17..3c0b0c0360e1c5223f7eef3fbca6ff1d6e8f3561 100644 (file)
@@ -74,7 +74,7 @@ DECLARE_CLASS(wxExtHelpController)
    /// Is the viewer a variant of netscape?
    bool             m_BrowserIsNetscape;
    /// Call the browser using a relative URL.
-   bool DisplayHelp(wxString const &);
+   virtual bool DisplayHelp(wxString const &);
 };
 
 #endif // wxUSE_HELP
index 83c87fd1a13e8091d9b5314e5063ff20f3ef1664..647d54549c56599259fe34781a70549f3478b938 100644 (file)
@@ -118,6 +118,22 @@ DECLARE_ABSTRACT_CLASS(wxHTMLHelpControllerBase)
    /// Call the browser using a relative URL.
    virtual bool DisplayHelp(wxString const &) = 0;
 
+   /// Allows one to override the default settings for the help frame.
+   virtual void SetFrameParameters(const wxString &title,
+                                   const wxSize &size,
+                                   const wxPoint &pos = wxDefaultPosition,
+                                   bool newFrameEachTime = FALSE)
+      {
+         // does nothing by default
+      }
+   /// Obtains the latest settings used by the help frame.
+   virtual void GetFrameParameters(wxSize *size = NULL,
+                                   wxPoint *pos = NULL,
+                                   bool *newFrameEachTime = NULL)
+      {
+         // does nothing by default
+      }
+
  protected:
    /// Filename of currently active map file.
    wxString         m_MapFile;
diff --git a/include/wx/generic/helpwxht.h b/include/wx/generic/helpwxht.h
new file mode 100644 (file)
index 0000000..18c765a
--- /dev/null
@@ -0,0 +1,75 @@
+/*-*- c++ -*-********************************************************
+ * helpwxht.h - a help controller using wxHTML                      *
+ *                                                                  *
+ * (C) 1999 by Karsten Ballüder (Ballueder@usa.net)                 *
+ *                                                                  *
+ * $Id$
+ *******************************************************************/
+
+#ifndef __WX_HELPWXHT_H_
+#define __WX_HELPWXHT_H_
+
+#if wxUSE_HELP
+#if wxUSE_HTML
+
+#ifdef __GNUG__
+#   pragma interface "helpwxht.h"
+#endif
+
+#include "wx/generic/helphtml.h"
+
+
+/**
+   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.
+
+   The map file contains two or three fields per line:
+   numeric_id  relative_URL  [; comment/documentation]
+
+   The numeric_id is the id used to look up the entry in
+   DisplaySection()/DisplayBlock(). The relative_URL is a filename of
+   an html file, relative to the help directory. The optional
+   comment/documentation field (after a ';') is used for keyword
+   searches, so some meaningful text here does not hurt.
+   If the documentation itself contains a ';', only the part before
+   that will be displayed in the listbox, but all of it used for search.
+
+   Lines starting with ';' will be ignored.
+*/
+
+class WXDLLEXPORT wxHelpControllerHtml : public wxHTMLHelpControllerBase
+{      
+DECLARE_CLASS(wxHelpControllerHtml)
+   public:
+   wxHelpControllerHtml(void);
+   ~wxHelpControllerHtml(void);
+
+   /// Allows one to override the default settings for the help frame.
+   virtual void SetFrameParameters(const wxString &title,
+                                   const wxSize &size,
+                                   const wxPoint &pos = wxDefaultPosition,
+                                   bool newFrameEachTime = FALSE);
+   /// Obtains the latest settings used by the help frame.
+   virtual void GetFrameParameters(wxSize *size = NULL,
+                                   wxPoint *pos = NULL,
+                                   bool *newFrameEachTime = NULL);
+   
+   
+private:
+   /// Call the browser using a relative URL.
+   virtual bool DisplayHelp(wxString const &);
+protected:
+   friend class wxHelpFrame;
+   class wxHelpFrame *m_Frame;
+   wxString    m_FrameTitle;
+   wxPoint     m_FramePosition;
+   wxSize      m_FrameSize;
+   bool        m_NewFrameEachTime;
+   size_t      m_offset;
+};
+
+#endif // wxUSE_HELP
+#endif // wxUSE_HTML
+
+#endif // __WX_HELPEXT_H_
index b93771f8064d14bbbe22f2602b3f0be8b298a578..2594d10f46e6adbeefde3e0b8115a08a5e760ab5 100644 (file)
@@ -52,6 +52,20 @@ class WXDLLEXPORT wxHelpControllerBase: public wxObject
   virtual void OnQuit(void) {};
 };
 
+
+/* By default, if wxHTML is compiled in, use the
+   wxHelpControllerHtml. If not, use the external help controller. */
+#if wxUSE_HTML
+#   include "wx/generic/helpwxht.h"
+#   define wxHelpController wxHelpControllerHtml
+#   define sm_classwxHelpController sm_classwxHelpControllerHtml
+#else
+#   include "wx/generic/helpext.h"
+#   define wxHelpController wxExtHelpController
+#   define sm_classwxHelpController sm_classwxExtHelpController
+#endif
+
+
 #endif // wxUSE_HELP
 #endif
     // _WX_HELPBASEH__
index f8f5312abf41334fa8411a598a48ee577994ac92..a2233f7fa715f76ad6daa879bc73508f88f0c6ef 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
-    #pragma implementation "demo.cpp"
-    #pragma interface "demo.cpp"
-#endif
-
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-    #pragma hdrstop
+#   pragma hdrstop
 #endif
 
 // for all others, include the necessary headers (this file is usually all you
 // need because it includes almost all "standard" wxWindows headers
 #ifndef WX_PRECOMP
-    #include "wx/wx.h"
+#   include "wx/wx.h"
 #endif
 
-// defien this to 1 to use HTML help even under Windows (by default, Windows
+// define this to 1 to use HTML help even under Windows (by default, Windows
 // version will HLP-based help)
 #define USE_HTML_HELP 1
-
 #if USE_HTML_HELP
-    #include "wx/helpbase.h"
-    #include "wx/generic/helpext.h"
-
-    #define wxHelpController wxExtHelpController
-    #define sm_classwxHelpController sm_classwxExtHelpController
+#   include "wx/helpbase.h"
 #else
-    #include "wx/help.h"
+#   include "wx/help.h"
 #endif
 
 // ----------------------------------------------------------------------------
@@ -183,11 +173,13 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     menuFile->Append(HelpDemo_Help_Help, "&About Help Demo...");
     menuFile->AppendSeparator();
     menuFile->Append(HelpDemo_Help_Search, "&Search help...");
-#ifdef __WXGTK__
+#ifndef __WXMSW__
+#ifndef wxUSE_HTML
     menuFile->AppendSeparator();
     menuFile->Append(HelpDemo_Help_KDE, "Use &KDE");
     menuFile->Append(HelpDemo_Help_GNOME, "Use &GNOME");
     menuFile->Append(HelpDemo_Help_Netscape, "Use &Netscape");
+#endif
 #endif
     menuFile->AppendSeparator();
     menuFile->Append(HelpDemo_Quit, "E&xit");
diff --git a/src/generic/helpwxht.cpp b/src/generic/helpwxht.cpp
new file mode 100644 (file)
index 0000000..5e4ad3f
--- /dev/null
@@ -0,0 +1,187 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        helpext.cpp
+// Purpose:     an external help controller for wxWindows
+// Author:      Karsten Ballueder
+// Modified by:
+// Created:     04/01/98
+// RCS-ID:      $Id$
+// Copyright:   (c) Karsten Ballueder
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#   pragma implementation "helpwxht.h"
+#endif
+
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#   pragma hdrstop
+#endif
+
+#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"
+#endif
+
+#include "wx/helpbase.h"
+#include "wx/generic/helpwxht.h"
+#include "wx/html/htmlwin.h"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <sys/stat.h>
+
+#ifndef __WINDOWS__
+#   include   <unistd.h>
+#endif
+
+IMPLEMENT_CLASS(wxHelpControllerHtml, wxHTMLHelpControllerBase)
+   
+/**
+   This class implements help via an external browser.
+   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   
+#define LAYOUT_X_MARGIN 2
+#define LAYOUT_Y_MARGIN 2
+#define OFFSET 10
+   
+class wxHelpFrame : public wxFrame
+{
+public:
+   wxHelpFrame(wxWindow *parent, int id, const wxString &title,
+               const wxPoint &pos, const wxSize &size,
+               wxHelpControllerHtml *controller);
+   ~wxHelpFrame();
+   void OnClose(wxCloseEvent &ev);
+   bool LoadPage(const wxString &url) { return m_htmlwin->LoadPage(url); }
+private:
+   wxHelpControllerHtml *m_controller;
+   wxHtmlWindow         *m_htmlwin;
+   DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxHelpFrame, wxFrame)
+   EVT_CLOSE(wxHelpFrame::OnClose)
+END_EVENT_TABLE()
+
+wxHelpFrame::wxHelpFrame(wxWindow *parent, int id,
+                         const wxString &title,
+                         const wxPoint &pos, const wxSize &size,
+                         wxHelpControllerHtml *controller)
+   : wxFrame(parent, id, title, pos, size)
+{
+
+   m_controller = controller;
+   m_htmlwin = new wxHtmlWindow(this,-1,wxDefaultPosition,wxSize(FRAME_WIDTH, 
+                                                          FRAME_HEIGHT));
+   
+   wxLayoutConstraints *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(this, wxTop, 2*LAYOUT_Y_MARGIN);
+   c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
+   m_htmlwin->SetConstraints(c);
+   SetAutoLayout(TRUE);
+   Show(TRUE);
+}
+
+wxHelpFrame::~wxHelpFrame()
+{
+}
+
+void
+wxHelpFrame::OnClose(wxCloseEvent &ev)
+{
+   wxASSERT(m_controller);
+   m_controller->m_Frame = NULL;
+   bool newFrame;
+   int x,y;
+   GetPosition(&x,&y);
+
+   m_controller->GetFrameParameters(NULL, NULL, &newFrame);
+   m_controller->SetFrameParameters(GetTitle(), GetSize(),
+                                    wxPoint(x,y),
+                                    newFrame);
+   Destroy();
+}
+
+wxHelpControllerHtml::wxHelpControllerHtml(void)
+{
+   m_Frame = NULL;
+   m_offset = 0;
+   
+   SetFrameParameters(_("Help"),
+                      wxSize(FRAME_WIDTH, FRAME_HEIGHT),
+                      wxDefaultPosition);
+}
+
+wxHelpControllerHtml::~wxHelpControllerHtml(void)
+{
+   if(m_Frame && ! m_NewFrameEachTime)
+      m_Frame->Close();
+}
+
+
+#ifdef __WXMSW__
+#   define   SEP   '\\'
+#else
+#   define   SEP   '/'
+#endif
+
+bool
+wxHelpControllerHtml::DisplayHelp(wxString const &relativeURL)
+{
+   wxBusyCursor b; // display a busy cursor
+
+   wxString url;
+   url << m_MapFile << SEP<< relativeURL;
+   if(! m_Frame || m_NewFrameEachTime)
+   {
+      m_Frame = new wxHelpFrame(NULL, -1, m_FrameTitle,
+                                m_FramePosition+wxPoint(m_offset,m_offset),
+                                m_FrameSize,
+                                this);
+      if(m_NewFrameEachTime)
+      {
+         m_offset += OFFSET;
+         if(m_offset > 200)
+            m_offset = 0;
+      }
+      
+   }
+   return m_Frame->LoadPage(url);
+}
+
+
+void
+wxHelpControllerHtml::SetFrameParameters(const wxString &title,
+                                         const wxSize &size,
+                                         const wxPoint &pos,
+                                         bool newFrame)
+{
+   m_FrameTitle = title;
+   m_FrameSize = size;
+   m_FramePosition = pos;
+   m_NewFrameEachTime = newFrame;
+}
+
+void
+wxHelpControllerHtml::GetFrameParameters(wxSize *size = NULL,
+                                         wxPoint *pos = NULL,
+                                         bool *newframe = NULL)
+{
+   if(size) *size = m_FrameSize;
+   if(pos) *pos = m_FramePosition;
+   if(newframe) *newframe = m_NewFrameEachTime;
+}
index edda346de00d9f54be242ae2c0ab1a580dfa5b70..83384cee93de67f89b87166ff3419df972d1ee92 100644 (file)
@@ -121,6 +121,7 @@ libwx_gtk_la_SOURCES = \
  fontdlgg.cpp \
  gridg.cpp \
  helpext.cpp \
+ helpwxht.cpp \
  helphtml.cpp \
  imaglist.cpp \
  laywin.cpp \
index edda346de00d9f54be242ae2c0ab1a580dfa5b70..83384cee93de67f89b87166ff3419df972d1ee92 100644 (file)
@@ -121,6 +121,7 @@ libwx_gtk_la_SOURCES = \
  fontdlgg.cpp \
  gridg.cpp \
  helpext.cpp \
+ helpwxht.cpp \
  helphtml.cpp \
  imaglist.cpp \
  laywin.cpp \