Added wxHelpControllerHtml, derived from wxHtmlHelpControllerBase. API like

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
This commit is contained in:
Karsten Ballüder
1999-07-18 18:09:46 +00:00
parent bfcc7d7fd0
commit 29ea4a2908
8 changed files with 303 additions and 17 deletions

View 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

View 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;

View File

@@ -0,0 +1,75 @@
/*-*- c++ -*-********************************************************
* helpwxht.h - a help controller using wxHTML *
* *
* (C) 1999 by Karsten Ball<6C>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_

View 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__

View File

@@ -17,36 +17,26 @@
// 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");

187
src/generic/helpwxht.cpp Normal file
View File

@@ -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;
}

View File

@@ -121,6 +121,7 @@ libwx_gtk_la_SOURCES = \
fontdlgg.cpp \
gridg.cpp \
helpext.cpp \
helpwxht.cpp \
helphtml.cpp \
imaglist.cpp \
laywin.cpp \

View File

@@ -121,6 +121,7 @@ libwx_gtk_la_SOURCES = \
fontdlgg.cpp \
gridg.cpp \
helpext.cpp \
helpwxht.cpp \
helphtml.cpp \
imaglist.cpp \
laywin.cpp \