From 69108ccb4e8de4279ffa0fdd4e23ea3666f84e92 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 24 May 2003 11:20:39 +0000 Subject: [PATCH] Removed wxHTMLHelpControllerBase (putting the implementation into wxExtHelpController. wx/helphtml.h now includes wx/html/helpctrl.h. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/msw/tmake/filelist.txt | 3 - include/wx/generic/helpext.h | 112 +++++++++- include/wx/generic/helphtml.h | 152 -------------- src/cocoa/files.lst | 4 - src/generic/helpext.cpp | 303 ++++++++++++++++++++++++++- src/generic/helphtml.cpp | 360 --------------------------------- src/gtk/files.lst | 5 - src/gtk1/files.lst | 5 - src/mac/carbon/files.lst | 4 - src/mac/files.lst | 4 - src/mgl/files.lst | 4 - src/motif/files.lst | 4 - src/msw/files.lst | 2 - src/os2/files.lst | 4 - src/x11/files.lst | 4 - 15 files changed, 406 insertions(+), 564 deletions(-) delete mode 100644 include/wx/generic/helphtml.h delete mode 100644 src/generic/helphtml.cpp diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 829e821468..13303bd38f 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -89,7 +89,6 @@ grid.cpp Generic gridctrl.cpp Generic gridsel.cpp Generic helpext.cpp Generic Generic -helphtml.cpp Generic Generic imaglist.cpp Generic NotWin32 laywin.cpp Generic listctrl.cpp Generic NotWin32 @@ -903,7 +902,6 @@ hash.h WXH Base hashmap.h WXH Base help.h WXH helpbase.h WXH -helphtml.h WXH helpwin.h WXH icon.h WXH iconbndl.h WXH @@ -1586,7 +1584,6 @@ grid.h GenericH gridctrl.h GenericH gridg.h GenericH helpext.h GenericH -helphtml.h GenericH imaglist.h GenericH laywin.h GenericH listctrl.h GenericH NotWin32 diff --git a/include/wx/generic/helpext.h b/include/wx/generic/helpext.h index ac1284f370..03c66e5fe3 100644 --- a/include/wx/generic/helpext.h +++ b/include/wx/generic/helpext.h @@ -15,7 +15,18 @@ # pragma interface "wxexthlp.h" #endif -#include "wx/generic/helphtml.h" +#include "wx/helpbase.h" + +/// Path separator. +#ifdef __WXMSW__ +#define WXEXTHELP_SEPARATOR _T('\\') +#elif defined(__WXMAC__) +#define WXEXTHELP_SEPARATOR _T(':') +#else +#define WXEXTHELP_SEPARATOR _T('/') +#endif + +class WXDLLEXPORT wxExtHelpMapList; #ifndef WXEXTHELP_DEFAULTBROWSER /// Default browser name. @@ -43,11 +54,12 @@ Lines starting with ';' will be ignored. */ -class WXDLLEXPORT wxExtHelpController : public wxHTMLHelpControllerBase +class WXDLLEXPORT wxExtHelpController : public wxHelpControllerBase { DECLARE_CLASS(wxExtHelpController) public: - wxExtHelpController(void); + wxExtHelpController(); + ~wxExtHelpController(); /** Tell it which browser to use. The Netscape support will check whether Netscape is already @@ -58,19 +70,107 @@ DECLARE_CLASS(wxExtHelpController) @param isNetscape Set this to TRUE if the browser is some variant of Netscape. */ // Obsolete form - void SetBrowser(wxString const & browsername = WXEXTHELP_DEFAULTBROWSER, + void SetBrowser(const wxString & browsername = WXEXTHELP_DEFAULTBROWSER, bool isNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE); // Set viewer: new name for SetBrowser virtual void SetViewer(const wxString& viewer = WXEXTHELP_DEFAULTBROWSER, long flags = wxHELP_NETSCAPE); + /** This must be called to tell the controller where to find the + documentation. + If a locale is set, look in file/localename, i.e. + If passed "/usr/local/myapp/help" and the current wxLocale is + set to be "de", then look in "/usr/local/myapp/help/de/" + first and fall back to "/usr/local/myapp/help" if that + doesn't exist. + + @param file - NOT a filename, but a directory name. + @return true on success + */ + virtual bool Initialize(const wxString& dir, int WXUNUSED(server)) + { return Initialize(dir); } + + /** This must be called to tell the controller where to find the + documentation. + If a locale is set, look in file/localename, i.e. + If passed "/usr/local/myapp/help" and the current wxLocale is + set to be "de", then look in "/usr/local/myapp/help/de/" + first and fall back to "/usr/local/myapp/help" if that + doesn't exist. + @param dir - directory name where to fine the help files + @return true on success + */ + virtual bool Initialize(const wxString& dir); + + /** If file is "", reloads file given in Initialize. + @file Name of help directory. + @return true on success + */ + virtual bool LoadFile(const wxString& file = wxT("")); + + /** Display list of all help entries. + @return true on success + */ + virtual bool DisplayContents(void); + /** Display help for id sectionNo. + @return true on success + */ + virtual bool DisplaySection(int sectionNo); + /** Display help for id sectionNo -- identical with DisplaySection(). + @return true on success + */ + virtual bool DisplaySection(const wxString& section); + /** Display help for URL (using DisplayHelp) or keyword (using KeywordSearch) + @return true on success + */ + virtual bool DisplayBlock(long blockNo); + /** Search comment/documentation fields in map file and present a + list to chose from. + @key k string to search for, empty string will list all entries + @return true on success + */ + virtual bool KeywordSearch(const wxString& k); + + /// does nothing + virtual bool Quit(void); + /// does nothing + virtual void OnQuit(void); + + /// Call the browser using a relative URL. + virtual bool DisplayHelp(const wxString &) ; + + /// Allows one to override the default settings for the help frame. + virtual void SetFrameParameters(const wxString& WXUNUSED(title), + const wxSize& WXUNUSED(size), + const wxPoint& WXUNUSED(pos) = wxDefaultPosition, + bool WXUNUSED(newFrameEachTime) = FALSE) + { + // does nothing by default + } + /// Obtains the latest settings used by the help frame and the help + /// frame. + virtual wxFrame *GetFrameParameters(wxSize *WXUNUSED(size) = NULL, + wxPoint *WXUNUSED(pos) = NULL, + bool *WXUNUSED(newFrameEachTime) = NULL) + { + return (wxFrame*) NULL;// does nothing by default + } + + protected: + /// Filename of currently active map file. + wxString m_MapFile; + /// How many entries do we have in the map file? + int m_NumOfEntries; + /// A list containing all id,url,documentation triples. + wxList *m_MapList; + /// Deletes the list and all objects. + void DeleteList(void); + private: /// How to call the html viewer. wxString m_BrowserName; /// Is the viewer a variant of netscape? bool m_BrowserIsNetscape; - /// Call the browser using a relative URL. - virtual bool DisplayHelp(const wxString&); }; #endif // wxUSE_HELP diff --git a/include/wx/generic/helphtml.h b/include/wx/generic/helphtml.h deleted file mode 100644 index 8e81689988..0000000000 --- a/include/wx/generic/helphtml.h +++ /dev/null @@ -1,152 +0,0 @@ -/*-*- c++ -*-******************************************************** - * helphtml.h - base class for html based help controllers * - * * - * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) * - * * - * $Id$ - *******************************************************************/ - -#ifndef __WX_HELPHTML_H_ -#define __WX_HELPHTML_H_ - -#if wxUSE_HELP - -#if defined(__GNUG__) && !defined(__APPLE__) -# pragma interface "helphtml.h" -#endif - -#include "wx/helpbase.h" -#include "wx/frame.h" - -/// Path separator. -#ifdef __WXMSW__ -#define WXEXTHELP_SEPARATOR _T('\\') -#elif defined(__WXMAC__) -#define WXEXTHELP_SEPARATOR _T(':') -#else -#define WXEXTHELP_SEPARATOR _T('/') -#endif - -class WXDLLEXPORT wxExtHelpMapList; - - -/** - This class is the base class for all html help implementations. - 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 wxHTMLHelpControllerBase : public wxHelpControllerBase -{ -DECLARE_ABSTRACT_CLASS(wxHTMLHelpControllerBase) - public: - wxHTMLHelpControllerBase(void); - virtual ~wxHTMLHelpControllerBase(void); - - /** This must be called to tell the controller where to find the - documentation. - If a locale is set, look in file/localename, i.e. - If passed "/usr/local/myapp/help" and the current wxLocale is - set to be "de", then look in "/usr/local/myapp/help/de/" - first and fall back to "/usr/local/myapp/help" if that - doesn't exist. - - @param file - NOT a filename, but a directory name. - @return true on success - */ - virtual bool Initialize(const wxString& dir, int WXUNUSED(server)) - { return Initialize(dir); } - - /** This must be called to tell the controller where to find the - documentation. - If a locale is set, look in file/localename, i.e. - If passed "/usr/local/myapp/help" and the current wxLocale is - set to be "de", then look in "/usr/local/myapp/help/de/" - first and fall back to "/usr/local/myapp/help" if that - doesn't exist. - @param dir - directory name where to fine the help files - @return true on success - */ - virtual bool Initialize(const wxString& dir); - - /** If file is "", reloads file given in Initialize. - @file Name of help directory. - @return true on success - */ - virtual bool LoadFile(const wxString& file = wxT("")); - - /** Display list of all help entries. - @return true on success - */ - virtual bool DisplayContents(void); - /** Display help for id sectionNo. - @return true on success - */ - virtual bool DisplaySection(int sectionNo); - /** Display help for id sectionNo -- identical with DisplaySection(). - @return true on success - */ - virtual bool DisplaySection(const wxString& section); - /** Display help for URL (using DisplayHelp) or keyword (using KeywordSearch) - @return true on success - */ - virtual bool DisplayBlock(long blockNo); - /** Search comment/documentation fields in map file and present a - list to chose from. - @key k string to search for, empty string will list all entries - @return true on success - */ - virtual bool KeywordSearch(const wxString& k); - - /// does nothing - virtual bool Quit(void); - /// does nothing - virtual void OnQuit(void); - - /// Call the browser using a relative URL. - virtual bool DisplayHelp(const wxString &) = 0; - - /// Allows one to override the default settings for the help frame. - virtual void SetFrameParameters(const wxString& WXUNUSED(title), - const wxSize& WXUNUSED(size), - const wxPoint& WXUNUSED(pos) = wxDefaultPosition, - bool WXUNUSED(newFrameEachTime) = FALSE) - { - // does nothing by default - } - /// Obtains the latest settings used by the help frame and the help - /// frame. - virtual wxFrame *GetFrameParameters(wxSize *WXUNUSED(size) = NULL, - wxPoint *WXUNUSED(pos) = NULL, - bool *WXUNUSED(newFrameEachTime) = NULL) - { - return (wxFrame*) NULL;// does nothing by default - } - - protected: - /// Filename of currently active map file. - wxString m_MapFile; - /// How many entries do we have in the map file? - int m_NumOfEntries; - /// A list containing all id,url,documentation triples. - wxList *m_MapList; - /// Deletes the list and all objects. - void DeleteList(void); -}; - -#endif // wxUSE_HELP - -#endif // __WX_HELPHTML_H_ diff --git a/src/cocoa/files.lst b/src/cocoa/files.lst index 7541bb7e80..94cd2e5973 100644 --- a/src/cocoa/files.lst +++ b/src/cocoa/files.lst @@ -19,7 +19,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -357,7 +356,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -555,7 +553,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -757,7 +754,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/generic/helpext.cpp b/src/generic/helpext.cpp index f6e3add7b5..d8649e494f 100644 --- a/src/generic/helpext.cpp +++ b/src/generic/helpext.cpp @@ -44,7 +44,20 @@ #include #endif -IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase) +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +/// Name for map file. +#define WXEXTHELP_MAPFILE _T("wxhelp.map") +/// Maximum line length in map file. +#define WXEXTHELP_BUFLEN 512 +/// Character introducing comments/documentation field in map file. +#define WXEXTHELP_COMMENTCHAR ';' + +#define CONTENTS_ID 0 + +IMPLEMENT_CLASS(wxExtHelpController, wxHelpControllerBase) /// Name of environment variable to set help browser. #define WXEXTHELP_ENVVAR_BROWSER wxT("WX_HELPBROWSER") @@ -57,8 +70,10 @@ IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase) and a file mapping numerical Section numbers to relative URLS. */ -wxExtHelpController::wxExtHelpController(void) +wxExtHelpController::wxExtHelpController() { + m_MapList = (wxList*) NULL; + m_NumOfEntries = 0; m_BrowserName = WXEXTHELP_DEFAULTBROWSER; m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE; @@ -71,8 +86,12 @@ wxExtHelpController::wxExtHelpController(void) } } +wxExtHelpController::~wxExtHelpController() +{ + DeleteList(); +} -void wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape) +void wxExtHelpController::SetBrowser(const wxString& browsername, bool isNetscape) { m_BrowserName = browsername; m_BrowserIsNetscape = isNetscape; @@ -163,5 +182,283 @@ wxExtHelpController::DisplayHelp(const wxString &relativeURL) #endif } +class wxExtHelpMapEntry : public wxObject +{ +public: + int id; + wxString url; + wxString doc; + wxExtHelpMapEntry(int iid, wxString const &iurl, wxString const &idoc) + { id = iid; url = iurl; doc = idoc; } +}; + +void wxExtHelpController::DeleteList() +{ + if(m_MapList) + { + wxNode *node = m_MapList->GetFirst(); + while (node) + { + delete (wxExtHelpMapEntry *)node->GetData(); + delete node; + node = m_MapList->GetFirst(); + } + delete m_MapList; + m_MapList = (wxList*) NULL; + } +} + +/** This must be called to tell the controller where to find the + documentation. + @param file - NOT a filename, but a directory name. + @return true on success +*/ +bool +wxExtHelpController::Initialize(const wxString& file) +{ + return LoadFile(file); +} + + +// ifile is the name of the base help directory +bool wxExtHelpController::LoadFile(const wxString& ifile) +{ + wxString mapFile, file, url, doc; + int id,i,len; + char buffer[WXEXTHELP_BUFLEN]; + + wxBusyCursor b; // display a busy cursor + + if(! ifile.IsEmpty()) + { + file = ifile; + if(! wxIsAbsolutePath(file)) + { + wxChar* f = wxGetWorkingDirectory(); + file = f; + delete[] f; // wxGetWorkingDirectory returns new memory +#ifdef __WXMAC__ + file << ifile; +#else + file << WXEXTHELP_SEPARATOR << ifile; +#endif + } + else + file = ifile; + +#if wxUSE_INTL + // If a locale is set, look in file/localename, i.e. + // If passed "/usr/local/myapp/help" and the current wxLocale is + // set to be "de", then look in "/usr/local/myapp/help/de/" + // first and fall back to "/usr/local/myapp/help" if that + // doesn't exist. + if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty()) + { + wxString newfile; + newfile << WXEXTHELP_SEPARATOR << wxGetLocale()->GetName(); + if(wxDirExists(newfile)) + file = newfile; + else + { + newfile = WXEXTHELP_SEPARATOR; + const wxChar *cptr = wxGetLocale()->GetName().c_str(); + while(*cptr && *cptr != wxT('_')) + newfile << *(cptr++); + if(wxDirExists(newfile)) + file = newfile; + } + } +#endif + + if(! wxDirExists(file)) + return FALSE; + + mapFile << file << WXEXTHELP_SEPARATOR << WXEXTHELP_MAPFILE; + } + else // try to reload old file + mapFile = m_MapFile; + + if(! wxFileExists(mapFile)) + return FALSE; + + DeleteList(); + m_MapList = new wxList; + m_NumOfEntries = 0; + + FILE *input = wxFopen(mapFile,wxT("rt")); + if(! input) + return FALSE; + do + { + if(fgets(buffer,WXEXTHELP_BUFLEN,input) && *buffer != WXEXTHELP_COMMENTCHAR) + { + len = strlen(buffer); + if(buffer[len-1] == '\n') + buffer[len-1] = '\0'; // cut of trailing newline + if(sscanf(buffer,"%d", &id) != 1) + break; // error + for(i=0; isdigit(buffer[i])||isspace(buffer[i])||buffer[i]=='-'; i++) + ; // find begin of URL + url = wxT(""); + while(buffer[i] && ! isspace(buffer[i]) && buffer[i] != + WXEXTHELP_COMMENTCHAR) + url << (wxChar) buffer[i++]; + while(buffer[i] && buffer[i] != WXEXTHELP_COMMENTCHAR) + i++; + doc = wxT(""); + if(buffer[i]) + doc = wxString::FromAscii( (buffer + i + 1) ); // skip the comment character + m_MapList->Append(new wxExtHelpMapEntry(id,url,doc)); + m_NumOfEntries++; + } + }while(! feof(input)); + fclose(input); + + m_MapFile = file; // now it's valid + return TRUE; +} + + +bool +wxExtHelpController::DisplayContents() +{ + if(! m_NumOfEntries) + return FALSE; + + wxString contents; + wxNode *node = m_MapList->GetFirst(); + wxExtHelpMapEntry *entry; + while(node) + { + entry = (wxExtHelpMapEntry *)node->GetData(); + if(entry->id == CONTENTS_ID) + { + contents = entry->url; + break; + } + node = node->GetNext(); + } + + bool rc = FALSE; + wxString file; + file << m_MapFile << WXEXTHELP_SEPARATOR << contents; + if(file.Contains(wxT('#'))) + file = file.BeforeLast(wxT('#')); + if(contents.Length() && wxFileExists(file)) + rc = DisplaySection(CONTENTS_ID); + + // if not found, open homemade toc: + return rc ? TRUE : KeywordSearch(wxT("")); +} + +bool +wxExtHelpController::DisplaySection(int sectionNo) +{ + if(! m_NumOfEntries) + return FALSE; + + wxBusyCursor b; // display a busy cursor + wxNode *node = m_MapList->GetFirst(); + wxExtHelpMapEntry *entry; + while(node) + { + entry = (wxExtHelpMapEntry *)node->GetData(); + if(entry->id == sectionNo) + return DisplayHelp(entry->url); + node = node->GetNext(); + } + return FALSE; +} + +bool wxExtHelpController::DisplaySection(const wxString& section) +{ + bool isFilename = (section.Find(wxT(".htm")) != -1); + + if (isFilename) + return DisplayHelp(section); + else + return KeywordSearch(section); +} + +bool +wxExtHelpController::DisplayBlock(long blockNo) +{ + return DisplaySection((int)blockNo); +} + +bool +wxExtHelpController::KeywordSearch(const wxString& k) +{ + if(! m_NumOfEntries) + return FALSE; + + wxString *choices = new wxString[m_NumOfEntries]; + wxString *urls = new wxString[m_NumOfEntries]; + wxString compA, compB; + + int idx = 0, j; + bool rc; + bool showAll = k.IsEmpty(); + wxNode *node = m_MapList->GetFirst(); + wxExtHelpMapEntry *entry; + + { + wxBusyCursor b; // display a busy cursor + compA = k; compA.LowerCase(); // we compare case insensitive + while(node) + { + entry = (wxExtHelpMapEntry *)node->GetData(); + compB = entry->doc; compB.LowerCase(); + if((showAll || compB.Contains(k)) && ! compB.IsEmpty()) + { + urls[idx] = entry->url; + // doesn't work: + // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR)); + //if(choices[idx].IsEmpty()) // didn't contain the ';' + // choices[idx] = (**i).doc; + choices[idx] = wxT(""); + for(j=0;entry->doc.c_str()[j] + && entry->doc.c_str()[j] != WXEXTHELP_COMMENTCHAR; j++) + choices[idx] << entry->doc.c_str()[j]; + idx++; + } + node = node->GetNext(); + } + } + + if(idx == 1) + rc = DisplayHelp(urls[0]); + else if(idx == 0) + { + wxMessageBox(_("No entries found.")); + rc = FALSE; + } + else + { + idx = wxGetSingleChoiceIndex(showAll ? _("Help Index") : _("Relevant entries:"), + showAll ? _("Help Index") : _("Entries found"), + idx,choices); + if(idx != -1) + rc = DisplayHelp(urls[idx]); + else + rc = FALSE; + } + delete[] urls; + delete[] choices; + + return rc; +} + + +bool wxExtHelpController::Quit() +{ + return TRUE; +} + +void wxExtHelpController::OnQuit() +{ +} + + #endif // wxUSE_HELP diff --git a/src/generic/helphtml.cpp b/src/generic/helphtml.cpp deleted file mode 100644 index 8378a1496f..0000000000 --- a/src/generic/helphtml.cpp +++ /dev/null @@ -1,360 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: helphtml.cpp -// Purpose: base class for html help systems -// Author: Karsten Ballueder -// Modified by: -// Created: 04/01/98 -// RCS-ID: $Id$ -// Copyright: (c) Karsten Ballueder -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -# pragma implementation "helphtml.h" -#endif - -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#if wxUSE_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/msgdlg.h" - #include "wx/choicdlg.h" -#endif - -#include "wx/helpbase.h" -#include "wx/generic/helpext.h" - -#include -#include -#ifndef __MWERKS__ -#include -#endif - -#if !defined(__WINDOWS__) && !defined(__OS2__) - #include -#endif - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -/// Name for map file. -#define WXEXTHELP_MAPFILE _T("wxhelp.map") -/// Maximum line length in map file. -#define WXEXTHELP_BUFLEN 512 -/// Character introducing comments/documentation field in map file. -#define WXEXTHELP_COMMENTCHAR ';' - -#define CONTENTS_ID 0 - -class wxExtHelpMapEntry : public wxObject -{ -public: - int id; - wxString url; - wxString doc; - wxExtHelpMapEntry(int iid, wxString const &iurl, wxString const &idoc) - { id = iid; url = iurl; doc = idoc; } -}; - -IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase, wxHelpControllerBase) - -/** - 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. -*/ - -wxHTMLHelpControllerBase::wxHTMLHelpControllerBase() -{ - m_MapList = (wxList*) NULL; - m_NumOfEntries = 0; -} - -void -wxHTMLHelpControllerBase::DeleteList() -{ - if(m_MapList) - { - wxNode *node = m_MapList->GetFirst(); - while (node) - { - delete (wxExtHelpMapEntry *)node->GetData(); - delete node; - node = m_MapList->GetFirst(); - } - delete m_MapList; - m_MapList = (wxList*) NULL; - } -} - -wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase() -{ - DeleteList(); -} - -/** This must be called to tell the controller where to find the - documentation. - @param file - NOT a filename, but a directory name. - @return true on success -*/ -bool -wxHTMLHelpControllerBase::Initialize(const wxString& file) -{ - return LoadFile(file); -} - - -// ifile is the name of the base help directory -bool -wxHTMLHelpControllerBase::LoadFile(const wxString& ifile) -{ - wxString mapFile, file, url, doc; - int id,i,len; - char buffer[WXEXTHELP_BUFLEN]; - - wxBusyCursor b; // display a busy cursor - - if(! ifile.IsEmpty()) - { - file = ifile; - if(! wxIsAbsolutePath(file)) - { - wxChar* f = wxGetWorkingDirectory(); - file = f; - delete[] f; // wxGetWorkingDirectory returns new memory -#ifdef __WXMAC__ - file << ifile; -#else - file << WXEXTHELP_SEPARATOR << ifile; -#endif - } - else - file = ifile; - -#if wxUSE_INTL - // If a locale is set, look in file/localename, i.e. - // If passed "/usr/local/myapp/help" and the current wxLocale is - // set to be "de", then look in "/usr/local/myapp/help/de/" - // first and fall back to "/usr/local/myapp/help" if that - // doesn't exist. - if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty()) - { - wxString newfile; - newfile << WXEXTHELP_SEPARATOR << wxGetLocale()->GetName(); - if(wxDirExists(newfile)) - file = newfile; - else - { - newfile = WXEXTHELP_SEPARATOR; - const wxChar *cptr = wxGetLocale()->GetName().c_str(); - while(*cptr && *cptr != wxT('_')) - newfile << *(cptr++); - if(wxDirExists(newfile)) - file = newfile; - } - } -#endif - - if(! wxDirExists(file)) - return FALSE; - - mapFile << file << WXEXTHELP_SEPARATOR << WXEXTHELP_MAPFILE; - } - else // try to reload old file - mapFile = m_MapFile; - - if(! wxFileExists(mapFile)) - return FALSE; - - DeleteList(); - m_MapList = new wxList; - m_NumOfEntries = 0; - - FILE *input = wxFopen(mapFile,wxT("rt")); - if(! input) - return FALSE; - do - { - if(fgets(buffer,WXEXTHELP_BUFLEN,input) && *buffer != WXEXTHELP_COMMENTCHAR) - { - len = strlen(buffer); - if(buffer[len-1] == '\n') - buffer[len-1] = '\0'; // cut of trailing newline - if(sscanf(buffer,"%d", &id) != 1) - break; // error - for(i=0; isdigit(buffer[i])||isspace(buffer[i])||buffer[i]=='-'; i++) - ; // find begin of URL - url = wxT(""); - while(buffer[i] && ! isspace(buffer[i]) && buffer[i] != - WXEXTHELP_COMMENTCHAR) - url << (wxChar) buffer[i++]; - while(buffer[i] && buffer[i] != WXEXTHELP_COMMENTCHAR) - i++; - doc = wxT(""); - if(buffer[i]) - doc = wxString::FromAscii( (buffer + i + 1) ); // skip the comment character - m_MapList->Append(new wxExtHelpMapEntry(id,url,doc)); - m_NumOfEntries++; - } - }while(! feof(input)); - fclose(input); - - m_MapFile = file; // now it's valid - return TRUE; -} - - -bool -wxHTMLHelpControllerBase::DisplayContents() -{ - if(! m_NumOfEntries) - return FALSE; - - wxString contents; - wxNode *node = m_MapList->GetFirst(); - wxExtHelpMapEntry *entry; - while(node) - { - entry = (wxExtHelpMapEntry *)node->GetData(); - if(entry->id == CONTENTS_ID) - { - contents = entry->url; - break; - } - node = node->GetNext(); - } - - bool rc = FALSE; - wxString file; - file << m_MapFile << WXEXTHELP_SEPARATOR << contents; - if(file.Contains(wxT('#'))) - file = file.BeforeLast(wxT('#')); - if(contents.Length() && wxFileExists(file)) - rc = DisplaySection(CONTENTS_ID); - - // if not found, open homemade toc: - return rc ? TRUE : KeywordSearch(wxT("")); -} - -bool -wxHTMLHelpControllerBase::DisplaySection(int sectionNo) -{ - if(! m_NumOfEntries) - return FALSE; - - wxBusyCursor b; // display a busy cursor - wxNode *node = m_MapList->GetFirst(); - wxExtHelpMapEntry *entry; - while(node) - { - entry = (wxExtHelpMapEntry *)node->GetData(); - if(entry->id == sectionNo) - return DisplayHelp(entry->url); - node = node->GetNext(); - } - return FALSE; -} - -bool wxHTMLHelpControllerBase::DisplaySection(const wxString& section) -{ - bool isFilename = (section.Find(wxT(".htm")) != -1); - - if (isFilename) - return DisplayHelp(section); - else - return KeywordSearch(section); -} - -bool -wxHTMLHelpControllerBase::DisplayBlock(long blockNo) -{ - return DisplaySection((int)blockNo); -} - -bool -wxHTMLHelpControllerBase::KeywordSearch(const wxString& k) -{ - if(! m_NumOfEntries) - return FALSE; - - wxString *choices = new wxString[m_NumOfEntries]; - wxString *urls = new wxString[m_NumOfEntries]; - wxString compA, compB; - - int idx = 0, j; - bool rc; - bool showAll = k.IsEmpty(); - wxNode *node = m_MapList->GetFirst(); - wxExtHelpMapEntry *entry; - - { - wxBusyCursor b; // display a busy cursor - compA = k; compA.LowerCase(); // we compare case insensitive - while(node) - { - entry = (wxExtHelpMapEntry *)node->GetData(); - compB = entry->doc; compB.LowerCase(); - if((showAll || compB.Contains(k)) && ! compB.IsEmpty()) - { - urls[idx] = entry->url; - // doesn't work: - // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR)); - //if(choices[idx].IsEmpty()) // didn't contain the ';' - // choices[idx] = (**i).doc; - choices[idx] = wxT(""); - for(j=0;entry->doc.c_str()[j] - && entry->doc.c_str()[j] != WXEXTHELP_COMMENTCHAR; j++) - choices[idx] << entry->doc.c_str()[j]; - idx++; - } - node = node->GetNext(); - } - } - - if(idx == 1) - rc = DisplayHelp(urls[0]); - else if(idx == 0) - { - wxMessageBox(_("No entries found.")); - rc = FALSE; - } - else - { - idx = wxGetSingleChoiceIndex(showAll ? _("Help Index") : _("Relevant entries:"), - showAll ? _("Help Index") : _("Entries found"), - idx,choices); - if(idx != -1) - rc = DisplayHelp(urls[idx]); - else - rc = FALSE; - } - delete[] urls; - delete[] choices; - - return rc; -} - - -bool -wxHTMLHelpControllerBase::Quit() -{ - return TRUE; -} - -void -wxHTMLHelpControllerBase::OnQuit() -{ -} - -#endif // wxUSE_HELP diff --git a/src/gtk/files.lst b/src/gtk/files.lst index 10b246e187..359a021ad4 100644 --- a/src/gtk/files.lst +++ b/src/gtk/files.lst @@ -19,7 +19,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -371,7 +370,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -588,7 +586,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -787,7 +784,6 @@ GUIOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ @@ -895,7 +891,6 @@ GUI_LOWLEVEL_OBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/gtk1/files.lst b/src/gtk1/files.lst index 10b246e187..359a021ad4 100644 --- a/src/gtk1/files.lst +++ b/src/gtk1/files.lst @@ -19,7 +19,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -371,7 +370,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -588,7 +586,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -787,7 +784,6 @@ GUIOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ @@ -895,7 +891,6 @@ GUI_LOWLEVEL_OBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/mac/carbon/files.lst b/src/mac/carbon/files.lst index 4851d871fc..446c67b348 100644 --- a/src/mac/carbon/files.lst +++ b/src/mac/carbon/files.lst @@ -17,7 +17,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -372,7 +371,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -608,7 +606,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -806,7 +803,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/mac/files.lst b/src/mac/files.lst index 4851d871fc..446c67b348 100644 --- a/src/mac/files.lst +++ b/src/mac/files.lst @@ -17,7 +17,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -372,7 +371,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -608,7 +606,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -806,7 +803,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/mgl/files.lst b/src/mgl/files.lst index 4415e7ef86..144e894db8 100644 --- a/src/mgl/files.lst +++ b/src/mgl/files.lst @@ -19,7 +19,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -330,7 +329,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -505,7 +503,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -707,7 +704,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/motif/files.lst b/src/motif/files.lst index 0295655a68..2bc3205bfd 100644 --- a/src/motif/files.lst +++ b/src/motif/files.lst @@ -17,7 +17,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -368,7 +367,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -577,7 +575,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -781,7 +778,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/msw/files.lst b/src/msw/files.lst index 8e663169b3..67153e59c3 100644 --- a/src/msw/files.lst +++ b/src/msw/files.lst @@ -391,7 +391,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -646,7 +645,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ diff --git a/src/os2/files.lst b/src/os2/files.lst index 999fd35918..5efee17b82 100644 --- a/src/os2/files.lst +++ b/src/os2/files.lst @@ -15,7 +15,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -367,7 +366,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -591,7 +589,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -783,7 +780,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ diff --git a/src/x11/files.lst b/src/x11/files.lst index ad1bf5cbc3..a7d9c25cf2 100644 --- a/src/x11/files.lst +++ b/src/x11/files.lst @@ -51,7 +51,6 @@ ALL_SOURCES = \ generic/gridctrl.cpp \ generic/gridsel.cpp \ generic/helpext.cpp \ - generic/helphtml.cpp \ generic/imaglist.cpp \ generic/laywin.cpp \ generic/listctrl.cpp \ @@ -341,7 +340,6 @@ ALL_HEADERS = \ hashmap.h \ help.h \ helpbase.h \ - helphtml.h \ helpwin.h \ icon.h \ iconbndl.h \ @@ -564,7 +562,6 @@ ALL_HEADERS = \ generic/gridctrl.h \ generic/gridg.h \ generic/helpext.h \ - generic/helphtml.h \ generic/imaglist.h \ generic/laywin.h \ generic/listctrl.h \ @@ -800,7 +797,6 @@ GENERICOBJS = \ gridctrl.o \ gridsel.o \ helpext.o \ - helphtml.o \ imaglist.o \ laywin.o \ listctrl.o \ -- 2.45.2