From 0f770650cc42397ebf614a0ba77d7c17a9cd1a28 Mon Sep 17 00:00:00 2001 From: joostverburg Date: Mon, 22 Sep 2003 19:28:09 +0000 Subject: [PATCH] NSIS Menu updates: new design, source fixes, use wxWindows 2.4.2 git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2948 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/NSIS Menu/Info.txt | 7 +- Contrib/NSIS Menu/nsismenu/nsisicon.ico | Bin 13590 -> 13902 bytes Contrib/NSIS Menu/nsismenu/nsismenu.cpp | 5 - Contrib/NSIS Menu/nsismenu/nsismenu.sln | 10 +- Contrib/NSIS Menu/nsismenu/nsismenu.vcproj | 30 +- Contrib/NSIS Menu/src/html/helpctrl.cpp | 331 ----- Contrib/NSIS Menu/src/html/helpdata.cpp | 866 ----------- Contrib/NSIS Menu/src/html/helpfrm.cpp | 1515 -------------------- Contrib/NSIS Menu/src/html/htmlcell.cpp | 728 ---------- Contrib/NSIS Menu/src/html/htmlfilt.cpp | 229 --- Contrib/NSIS Menu/src/html/htmlpars.cpp | 888 ------------ Contrib/NSIS Menu/src/html/htmltag.cpp | 450 ------ Contrib/NSIS Menu/src/html/htmlwin.cpp | 18 +- Contrib/NSIS Menu/src/html/htmprint.cpp | 599 -------- Contrib/NSIS Menu/src/html/m_dflist.cpp | 90 -- Contrib/NSIS Menu/src/html/m_fonts.cpp | 321 ----- Contrib/NSIS Menu/src/html/m_hline.cpp | 34 - Contrib/NSIS Menu/src/html/m_image.cpp | 727 ---------- Contrib/NSIS Menu/src/html/m_layout.cpp | 242 ---- Contrib/NSIS Menu/src/html/m_links.cpp | 4 +- Contrib/NSIS Menu/src/html/m_list.cpp | 33 - Contrib/NSIS Menu/src/html/m_pre.cpp | 32 - Contrib/NSIS Menu/src/html/m_style.cpp | 51 - Contrib/NSIS Menu/src/html/m_tables.cpp | 623 -------- Contrib/NSIS Menu/src/html/winpars.cpp | 511 ------- Menu/compiler.html | 29 +- Menu/docs.html | 44 +- Menu/images/btn-compiler.gif | Bin 2568 -> 0 bytes Menu/images/btn-docs.gif | Bin 2740 -> 0 bytes Menu/images/btn-update.gif | Bin 2494 -> 0 bytes Menu/images/btn-websites.gif | Bin 2561 -> 0 bytes Menu/images/btn-welcome.gif | Bin 2578 -> 0 bytes Menu/images/header.gif | Bin 5130 -> 4861 bytes Menu/images/line.gif | Bin 0 -> 45 bytes Menu/images/silver.gif | Bin 35 -> 0 bytes Menu/images/version.gif | Bin 1108 -> 844 bytes Menu/index.html | 32 +- Menu/notinstalled.html | 24 +- Menu/update.html | 32 +- Menu/websites.html | 37 +- 40 files changed, 141 insertions(+), 8401 deletions(-) delete mode 100644 Contrib/NSIS Menu/src/html/helpctrl.cpp delete mode 100644 Contrib/NSIS Menu/src/html/helpdata.cpp delete mode 100644 Contrib/NSIS Menu/src/html/helpfrm.cpp delete mode 100644 Contrib/NSIS Menu/src/html/htmlcell.cpp delete mode 100644 Contrib/NSIS Menu/src/html/htmlfilt.cpp delete mode 100644 Contrib/NSIS Menu/src/html/htmlpars.cpp delete mode 100644 Contrib/NSIS Menu/src/html/htmltag.cpp delete mode 100644 Contrib/NSIS Menu/src/html/htmprint.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_dflist.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_fonts.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_hline.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_image.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_layout.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_list.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_pre.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_style.cpp delete mode 100644 Contrib/NSIS Menu/src/html/m_tables.cpp delete mode 100644 Contrib/NSIS Menu/src/html/winpars.cpp delete mode 100644 Menu/images/btn-compiler.gif delete mode 100644 Menu/images/btn-docs.gif delete mode 100644 Menu/images/btn-update.gif delete mode 100644 Menu/images/btn-websites.gif delete mode 100644 Menu/images/btn-welcome.gif create mode 100644 Menu/images/line.gif delete mode 100644 Menu/images/silver.gif diff --git a/Contrib/NSIS Menu/Info.txt b/Contrib/NSIS Menu/Info.txt index a31dc39f..0cffde65 100644 --- a/Contrib/NSIS Menu/Info.txt +++ b/Contrib/NSIS Menu/Info.txt @@ -1,10 +1,11 @@ NSIS Menu - by Joost Verburg +---------------------------- -Based on wxWindows 2.4.0 / wxHtml +Based on wxWindows 2.4.2 / wxHtml Compile using the wxWindows framework: http://www.wxwindows.org/ -Modified wxWindows / wxHtml sources included. -Copy the data from this folder to the wxWindows folder. +Modified wxWindows / wxHtml sources included, copy the data from this folder to the wxWindows folder. +You have to compile wxWindows and the libraries with the Multi-threaded (/MT) option. The NSIS Menu binary is compressed using UPX: http://upx.sourceforge.net/ \ No newline at end of file diff --git a/Contrib/NSIS Menu/nsismenu/nsisicon.ico b/Contrib/NSIS Menu/nsismenu/nsisicon.ico index 49194a59e6d964c22c99cfe10cc304fbf4b0b8b8..f8fbd5ffa910bd7e090becb3ec78fda3cfa4dd8f 100644 GIT binary patch delta 719 zcmbVJEl&eM5PjQn+#(cqA0+2q<|?!h6)97X5*``NuC-hr@L{LfsnXe|WkW8uICj@-R z*X`DP0`$&M?<@2VfVOl)UtuC=9xj0SYvZ$JDfTzFL;RS%1>#~2BvxnB5F~aGktsIm zR96M@hB(pbdtmV#8&jluwDbk + @@ -40,7 +40,7 @@ + + + + + + + + @@ -135,16 +149,16 @@ - - + + - \ No newline at end of file + diff --git a/Contrib/NSIS Menu/src/html/helpctrl.cpp b/Contrib/NSIS Menu/src/html/helpctrl.cpp deleted file mode 100644 index 5c56052d..00000000 --- a/Contrib/NSIS Menu/src/html/helpctrl.cpp +++ /dev/null @@ -1,331 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: helpctrl.cpp -// Purpose: wxHtmlHelpController -// Notes: Based on htmlhelp.cpp, implementing a monolithic -// HTML Help controller class, by Vaclav Slavik -// Author: Harm van der Heijden and Vaclav Slavik -// RCS-ID: $Id: helpctrl.cpp,v 1.26.2.3 2002/12/29 05:52:26 RL Exp $ -// Copyright: (c) Harm van der Heijden and Vaclav Slavik -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "helpctrl.h" -#endif - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#if wxUSE_WXHTML_HELP - -#ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/intl.h" -#endif // WX_PRECOMP - -#include "wx/html/helpctrl.h" -#include "wx/busyinfo.h" - -#ifdef __WXGTK__ - // for the hack in AddGrabIfNeeded() - #include "wx/dialog.h" -#endif // __WXGTK__ - -#if wxUSE_HELP - #include "wx/tipwin.h" -#endif - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase) - -wxHtmlHelpController::wxHtmlHelpController(int style) -{ - m_helpFrame = NULL; - m_Config = NULL; - m_ConfigRoot = wxEmptyString; - m_titleFormat = _("Help: %s"); - m_FrameStyle = style; -} - -wxHtmlHelpController::~wxHtmlHelpController() -{ - if (m_Config) - WriteCustomization(m_Config, m_ConfigRoot); - if (m_helpFrame) - DestroyHelpWindow(); -} - - -void wxHtmlHelpController::DestroyHelpWindow() -{ - //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot); - if (m_helpFrame) - m_helpFrame->Destroy(); -} - -void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt) -{ - evt.Skip(); - - OnQuit(); - - m_helpFrame->SetController((wxHelpControllerBase*) NULL); - m_helpFrame = NULL; -} - -void wxHtmlHelpController::SetTitleFormat(const wxString& title) -{ - m_titleFormat = title; - if (m_helpFrame) - m_helpFrame->SetTitleFormat(title); -} - - -bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg) -{ - return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg); -} - -bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg) -{ - wxBusyCursor cur; -#if wxUSE_BUSYINFO - wxBusyInfo* busy = NULL; - wxString info; - if (show_wait_msg) - { - info.Printf(_("Adding book %s"), book.c_str()); - busy = new wxBusyInfo(info); - } -#endif - bool retval = m_helpData.AddBook(book); -#if wxUSE_BUSYINFO - if (show_wait_msg) - delete busy; -#endif - if (m_helpFrame) - m_helpFrame->RefreshLists(); - return retval; -} - - - -wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data) -{ - return new wxHtmlHelpFrame(data); -} - - -void wxHtmlHelpController::CreateHelpWindow() -{ - if (m_helpFrame) - { - m_helpFrame->Raise(); - return ; - } - - if (m_Config == NULL) - { - m_Config = wxConfigBase::Get(FALSE); - if (m_Config != NULL) - m_ConfigRoot = _T("wxWindows/wxHtmlHelpController"); - } - - m_helpFrame = CreateHelpFrame(&m_helpData); - m_helpFrame->SetController(this); - - if (m_Config) - m_helpFrame->UseConfig(m_Config, m_ConfigRoot); - - m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle); - m_helpFrame->SetTitleFormat(m_titleFormat); - m_helpFrame->Show(TRUE); -} - -void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path) -{ - /* should not be called by the user; call UseConfig, and the controller - * will do the rest */ - if (m_helpFrame && cfg) - m_helpFrame->ReadCustomization(cfg, path); -} - -void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path) -{ - /* typically called by the controllers OnCloseFrame handler */ - if (m_helpFrame && cfg) - m_helpFrame->WriteCustomization(cfg, path); -} - -void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath) -{ - m_Config = config; - m_ConfigRoot = rootpath; - if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath); - ReadCustomization(config, rootpath); -} - -//// Backward compatibility with wxHelpController API - -bool wxHtmlHelpController::Initialize(const wxString& file) -{ - wxString dir, filename, ext; - wxSplitPath(file, & dir, & filename, & ext); - - if (!dir.IsEmpty()) - dir = dir + wxFILE_SEP_PATH; - - // Try to find a suitable file - wxString actualFilename = dir + filename + wxString(wxT(".zip")); - if (!wxFileExists(actualFilename)) - { - actualFilename = dir + filename + wxString(wxT(".htb")); - if (!wxFileExists(actualFilename)) - { - actualFilename = dir + filename + wxString(wxT(".hhp")); - if (!wxFileExists(actualFilename)) - return FALSE; - } - } - - return AddBook(wxFileName(actualFilename)); -} - -bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file)) -{ - // Don't reload the file or we'll have it appear again, presumably. - return TRUE; -} - -bool wxHtmlHelpController::DisplaySection(int sectionNo) -{ - return Display(sectionNo); -} - -bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos)) -{ -#if wxUSE_TIPWINDOW - static wxTipWindow* s_tipWindow = NULL; - - if (s_tipWindow) - { - // Prevent s_tipWindow being nulled in OnIdle, - // thereby removing the chance for the window to be closed by ShowHelp - s_tipWindow->SetTipWindowPtr(NULL); - s_tipWindow->Close(); - } - s_tipWindow = NULL; - - if ( !text.empty() ) - { - s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow); - - return TRUE; - } -#endif // wxUSE_TIPWINDOW - - return FALSE; -} - -void wxHtmlHelpController::SetFrameParameters(const wxString& title, - const wxSize& size, - const wxPoint& pos, - bool WXUNUSED(newFrameEachTime)) -{ - SetTitleFormat(title); - if (m_helpFrame) - { - m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y); - } -} - -wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size, - wxPoint *pos, - bool *newFrameEachTime) -{ - if (newFrameEachTime) - (* newFrameEachTime) = FALSE; - if (size && m_helpFrame) - (* size) = m_helpFrame->GetSize(); - if (pos && m_helpFrame) - (* pos) = m_helpFrame->GetPosition(); - return m_helpFrame; -} - -bool wxHtmlHelpController::Quit() -{ - DestroyHelpWindow(); - return TRUE; -} - -// Make the help controller's frame 'modal' if -// needed -void wxHtmlHelpController::AddGrabIfNeeded() -{ - // So far, wxGTK only -#ifdef __WXGTK__ - bool needGrab = FALSE; - - // Check if there are any modal windows present, - // in which case we need to add a grab. - for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst(); - node; - node = node->GetNext() ) - { - wxWindow *win = node->GetData(); - wxDialog *dialog = wxDynamicCast(win, wxDialog); - - if (dialog && dialog->IsModal()) - needGrab = TRUE; - } - - if (needGrab && m_helpFrame) - m_helpFrame->AddGrab(); -#endif // __WXGTK__ -} - -bool wxHtmlHelpController::Display(const wxString& x) -{ - CreateHelpWindow(); - bool success = m_helpFrame->Display(x); - AddGrabIfNeeded(); - return success; -} - -bool wxHtmlHelpController::Display(int id) -{ - CreateHelpWindow(); - bool success = m_helpFrame->Display(id); - AddGrabIfNeeded(); - return success; -} - -bool wxHtmlHelpController::DisplayContents() -{ - CreateHelpWindow(); - bool success = m_helpFrame->DisplayContents(); - AddGrabIfNeeded(); - return success; -} - -bool wxHtmlHelpController::DisplayIndex() -{ - CreateHelpWindow(); - bool success = m_helpFrame->DisplayIndex(); - AddGrabIfNeeded(); - return success; -} - -bool wxHtmlHelpController::KeywordSearch(const wxString& keyword) -{ - CreateHelpWindow(); - bool success = m_helpFrame->KeywordSearch(keyword); - AddGrabIfNeeded(); - return success; -} - -#endif // wxUSE_WXHTML_HELP - diff --git a/Contrib/NSIS Menu/src/html/helpdata.cpp b/Contrib/NSIS Menu/src/html/helpdata.cpp deleted file mode 100644 index f393a994..00000000 --- a/Contrib/NSIS Menu/src/html/helpdata.cpp +++ /dev/null @@ -1,866 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: helpdata.cpp -// Purpose: wxHtmlHelpData -// Notes: Based on htmlhelp.cpp, implementing a monolithic -// HTML Help controller class, by Vaclav Slavik -// Author: Harm van der Heijden and Vaclav Slavik -// RCS-ID: $Id: helpdata.cpp,v 1.59.2.5 2002/12/16 10:23:20 JS Exp $ -// Copyright: (c) Harm van der Heijden and Vaclav Slavik -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "helpdata.h" -#endif - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#include "wx/defs.h" - -#if wxUSE_HTML && wxUSE_STREAMS - -#ifndef WXPRECOMP - #include "wx/intl.h" - #include "wx/log.h" -#endif - -#include - -#include "wx/html/helpdata.h" -#include "wx/tokenzr.h" -#include "wx/wfstream.h" -#include "wx/busyinfo.h" -#include "wx/encconv.h" -#include "wx/fontmap.h" -#include "wx/log.h" -#include "wx/html/htmlpars.h" -#include "wx/html/htmldefs.h" -#include "wx/html/htmlfilt.h" -#include "wx/filename.h" - -#include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxHtmlBookRecArray) - -//----------------------------------------------------------------------------- -// static helper functions -//----------------------------------------------------------------------------- - -// Reads one line, stores it into buf and returns pointer to new line or NULL. -static const wxChar* ReadLine(const wxChar *line, wxChar *buf, size_t bufsize) -{ - wxChar *writeptr = buf; - wxChar *endptr = buf + bufsize - 1; - const wxChar *readptr = line; - - while (*readptr != 0 && *readptr != _T('\r') && *readptr != _T('\n') && - writeptr != endptr) - *(writeptr++) = *(readptr++); - *writeptr = 0; - while (*readptr == _T('\r') || *readptr == _T('\n')) - readptr++; - if (*readptr == 0) - return NULL; - else - return readptr; -} - - - -extern "C" int LINKAGEMODE -wxHtmlHelpIndexCompareFunc(const void *a, const void *b) -{ - return wxStricmp(((wxHtmlContentsItem*)a)->m_Name, ((wxHtmlContentsItem*)b)->m_Name); -} - - -//----------------------------------------------------------------------------- -// HP_Parser -//----------------------------------------------------------------------------- - -class HP_Parser : public wxHtmlParser -{ -public: - wxObject* GetProduct() { return NULL; } -protected: - virtual void AddText(const wxChar* WXUNUSED(txt)) {} -}; - - -//----------------------------------------------------------------------------- -// HP_TagHandler -//----------------------------------------------------------------------------- - -class HP_TagHandler : public wxHtmlTagHandler -{ - private: - wxString m_Name, m_Page; - int m_Level; - int m_ID; - int m_Index; - wxHtmlContentsItem *m_Items; - int m_ItemsCnt; - wxHtmlBookRecord *m_Book; - - public: - HP_TagHandler(wxHtmlBookRecord *b) : wxHtmlTagHandler() - { m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; - m_Level = 0; m_ID = -1; } - wxString GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); } - bool HandleTag(const wxHtmlTag& tag); - void WriteOut(wxHtmlContentsItem*& array, int& size); - void ReadIn(wxHtmlContentsItem* array, int size); -}; - - -bool HP_TagHandler::HandleTag(const wxHtmlTag& tag) -{ - if (tag.GetName() == wxT("UL")) - { - m_Level++; - ParseInner(tag); - m_Level--; - return TRUE; - } - else if (tag.GetName() == wxT("OBJECT")) - { - m_Name = m_Page = wxEmptyString; - ParseInner(tag); - -#if 0 - if (!m_Page.IsEmpty()) - /* Valid HHW's file may contain only two object tags: - - - - - - or - - - - - - - We're interested in the latter. !m_Page.IsEmpty() is valid - condition because text/site properties does not contain Local param - */ -#endif - if (tag.GetParam(wxT("TYPE")) == wxT("text/sitemap")) - { - if (m_ItemsCnt % wxHTML_REALLOC_STEP == 0) - m_Items = (wxHtmlContentsItem*) realloc(m_Items, - (m_ItemsCnt + wxHTML_REALLOC_STEP) * - sizeof(wxHtmlContentsItem)); - - m_Items[m_ItemsCnt].m_Level = m_Level; - m_Items[m_ItemsCnt].m_ID = m_ID; - m_Items[m_ItemsCnt].m_Page = new wxChar[m_Page.Length() + 1]; - wxStrcpy(m_Items[m_ItemsCnt].m_Page, m_Page.c_str()); - m_Items[m_ItemsCnt].m_Name = new wxChar [m_Name.Length() + 1]; - wxStrcpy(m_Items[m_ItemsCnt].m_Name, m_Name.c_str()); - m_Items[m_ItemsCnt].m_Book = m_Book; - m_ItemsCnt++; - } - - return TRUE; - } - else - { // "PARAM" - if (m_Name == wxEmptyString && tag.GetParam(wxT("NAME")) == wxT("Name")) - m_Name = tag.GetParam(wxT("VALUE")); - if (tag.GetParam(wxT("NAME")) == wxT("Local")) - m_Page = tag.GetParam(wxT("VALUE")); - if (tag.GetParam(wxT("NAME")) == wxT("ID")) - tag.GetParamAsInt(wxT("VALUE"), &m_ID); - return FALSE; - } -} - - - -void HP_TagHandler::WriteOut(wxHtmlContentsItem*& array, int& size) -{ - array = m_Items; - size = m_ItemsCnt; - m_Items = NULL; - m_ItemsCnt = 0; -} - -void HP_TagHandler::ReadIn(wxHtmlContentsItem* array, int size) -{ - m_Items = array; - m_ItemsCnt = size; -} - - - - -//----------------------------------------------------------------------------- -// wxHtmlHelpData -//----------------------------------------------------------------------------- - -wxString wxHtmlBookRecord::GetFullPath(const wxString &page) const -{ - if (wxIsAbsolutePath(page)) - return page; - else - return m_BasePath + page; -} - - - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData, wxObject) - -wxHtmlHelpData::wxHtmlHelpData() -{ - m_TempPath = wxEmptyString; - - m_Contents = NULL; - m_ContentsCnt = 0; - m_Index = NULL; - m_IndexCnt = 0; -} - -wxHtmlHelpData::~wxHtmlHelpData() -{ - int i; - - m_BookRecords.Empty(); - if (m_Contents) - { - for (i = 0; i < m_ContentsCnt; i++) - { - delete[] m_Contents[i].m_Page; - delete[] m_Contents[i].m_Name; - } - free(m_Contents); - } - if (m_Index) - { - for (i = 0; i < m_IndexCnt; i++) - { - delete[] m_Index[i].m_Page; - delete[] m_Index[i].m_Name; - } - free(m_Index); - } -} - -bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile) -{ - wxFSFile *f; - wxHtmlFilterHTML filter; - wxString buf; - wxString string; - - HP_Parser parser; - HP_TagHandler *handler = new HP_TagHandler(book); - parser.AddTagHandler(handler); - - f = ( contentsfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(contentsfile) ); - if (f) - { - buf.clear(); - buf = filter.ReadFile(*f); - delete f; - handler->ReadIn(m_Contents, m_ContentsCnt); - parser.Parse(buf); - handler->WriteOut(m_Contents, m_ContentsCnt); - } - else - { - wxLogError(_("Cannot open contents file: %s"), contentsfile.c_str()); - } - - f = ( indexfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) ); - if (f) - { - buf.clear(); - buf = filter.ReadFile(*f); - delete f; - handler->ReadIn(m_Index, m_IndexCnt); - parser.Parse(buf); - handler->WriteOut(m_Index, m_IndexCnt); - } - else if (!indexfile.IsEmpty()) - { - wxLogError(_("Cannot open index file: %s"), indexfile.c_str()); - } - return TRUE; -} - - - -inline static void CacheWriteInt32(wxOutputStream *f, wxInt32 value) -{ - wxInt32 x = wxINT32_SWAP_ON_BE(value); - f->Write(&x, sizeof(x)); -} - -inline static wxInt32 CacheReadInt32(wxInputStream *f) -{ - wxInt32 x; - f->Read(&x, sizeof(x)); - return wxINT32_SWAP_ON_BE(x); -} - -inline static void CacheWriteString(wxOutputStream *f, const wxChar *str) -{ -#if wxUSE_UNICODE - wxWX2MBbuf mbstr(wxConvUTF8.cWX2MB(str)); -#else - const wxChar *mbstr = str; -#endif - size_t len = strlen(mbstr)+1; - CacheWriteInt32(f, len); - f->Write(mbstr, len); -} - -inline static wxChar* CacheReadString(wxInputStream *f) -{ - char *str; - size_t len = (size_t)CacheReadInt32(f); - str = new char[len]; - f->Read(str, len); -#if !wxUSE_UNICODE - return str; -#else - wxMB2WXbuf wxstr(wxConvUTF8.cMB2WX(str)); - wxChar *outstr = new wxChar[wxStrlen(wxstr)+1]; - wxStrcpy(outstr, wxstr); - return outstr; -#endif -} - -#define CURRENT_CACHED_BOOK_VERSION 3 - -bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f) -{ - int i, st; - wxInt32 version; - - /* load header - version info : */ - version = CacheReadInt32(f); - - if (version != CURRENT_CACHED_BOOK_VERSION) - { - // NB: We can just silently return FALSE here and don't worry about - // it anymore, because AddBookParam will load the MS project in - // absence of (properly versioned) .cached file and automatically - // create new .cached file immediately afterward. - return FALSE; - } - - /* load contents : */ - st = m_ContentsCnt; - m_ContentsCnt += CacheReadInt32(f); - m_Contents = (wxHtmlContentsItem*) realloc(m_Contents, - (m_ContentsCnt / wxHTML_REALLOC_STEP + 1) * - wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem)); - for (i = st; i < m_ContentsCnt; i++) - { - m_Contents[i].m_Level = CacheReadInt32(f); - m_Contents[i].m_ID = CacheReadInt32(f); - m_Contents[i].m_Name = CacheReadString(f); - m_Contents[i].m_Page = CacheReadString(f); - m_Contents[i].m_Book = book; - } - - /* load index : */ - st = m_IndexCnt; - m_IndexCnt += CacheReadInt32(f); - m_Index = (wxHtmlContentsItem*) realloc(m_Index, (m_IndexCnt / wxHTML_REALLOC_STEP + 1) * - wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem)); - for (i = st; i < m_IndexCnt; i++) - { - m_Index[i].m_Name = CacheReadString(f); - m_Index[i].m_Page = CacheReadString(f); - m_Index[i].m_Book = book; - } - return TRUE; -} - - -bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f) -{ - int i; - wxInt32 cnt; - - /* save header - version info : */ - CacheWriteInt32(f, CURRENT_CACHED_BOOK_VERSION); - - /* save contents : */ - for (cnt = 0, i = 0; i < m_ContentsCnt; i++) - if (m_Contents[i].m_Book == book && m_Contents[i].m_Level > 0) - cnt++; - CacheWriteInt32(f, cnt); - - for (i = 0; i < m_ContentsCnt; i++) - { - if (m_Contents[i].m_Book != book || m_Contents[i].m_Level == 0) - continue; - CacheWriteInt32(f, m_Contents[i].m_Level); - CacheWriteInt32(f, m_Contents[i].m_ID); - CacheWriteString(f, m_Contents[i].m_Name); - CacheWriteString(f, m_Contents[i].m_Page); - } - - /* save index : */ - for (cnt = 0, i = 0; i < m_IndexCnt; i++) - if (m_Index[i].m_Book == book && m_Index[i].m_Level > 0) - cnt++; - CacheWriteInt32(f, cnt); - - for (i = 0; i < m_IndexCnt; i++) - { - if (m_Index[i].m_Book != book || m_Index[i].m_Level == 0) - continue; - CacheWriteString(f, m_Index[i].m_Name); - CacheWriteString(f, m_Index[i].m_Page); - } - return TRUE; -} - - -void wxHtmlHelpData::SetTempDir(const wxString& path) -{ - if (path == wxEmptyString) m_TempPath = path; - else - { - if (wxIsAbsolutePath(path)) m_TempPath = path; - else m_TempPath = wxGetCwd() + _T("/") + path; - - if (m_TempPath[m_TempPath.Length() - 1] != _T('/')) - m_TempPath << _T('/'); - } -} - - - -static wxString SafeFileName(const wxString& s) -{ - wxString res(s); - res.Replace(wxT("#"), wxT("_")); - res.Replace(wxT(":"), wxT("_")); - res.Replace(wxT("\\"), wxT("_")); - res.Replace(wxT("/"), wxT("_")); - return res; -} - -bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, - wxFontEncoding encoding, - const wxString& title, const wxString& contfile, - const wxString& indexfile, const wxString& deftopic, - const wxString& path) -{ - wxFileSystem fsys; - wxFSFile *fi; - wxHtmlBookRecord *bookr; - - int IndexOld = m_IndexCnt, - ContentsOld = m_ContentsCnt; - - if (!path.IsEmpty()) - fsys.ChangePathTo(path, TRUE); - - size_t booksCnt = m_BookRecords.GetCount(); - for (size_t i = 0; i < booksCnt; i++) - { - if ( m_BookRecords[i].GetBookFile() == bookfile.GetLocation() ) - return TRUE; // book is (was) loaded - } - - bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title, deftopic); - - if (m_ContentsCnt % wxHTML_REALLOC_STEP == 0) - m_Contents = (wxHtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + wxHTML_REALLOC_STEP) * sizeof(wxHtmlContentsItem)); - m_Contents[m_ContentsCnt].m_Level = 0; - m_Contents[m_ContentsCnt].m_ID = 0; - m_Contents[m_ContentsCnt].m_Page = new wxChar[deftopic.Length() + 1]; - wxStrcpy(m_Contents[m_ContentsCnt].m_Page, deftopic.c_str()); - m_Contents[m_ContentsCnt].m_Name = new wxChar [title.Length() + 1]; - wxStrcpy(m_Contents[m_ContentsCnt].m_Name, title.c_str()); - m_Contents[m_ContentsCnt].m_Book = bookr; - - // store the contents index for later - int cont_start = m_ContentsCnt++; - - // Try to find cached binary versions: - // 1. save file as book, but with .hhp.cached extension - // 2. same as 1. but in temp path - // 3. otherwise or if cache load failed, load it from MS. - - fi = fsys.OpenFile(bookfile.GetLocation() + wxT(".cached")); - - if (fi == NULL || - fi->GetModificationTime() < bookfile.GetModificationTime() || - !LoadCachedBook(bookr, fi->GetStream())) - { - if (fi != NULL) delete fi; - fi = fsys.OpenFile(m_TempPath + wxFileNameFromPath(bookfile.GetLocation()) + wxT(".cached")); - if (m_TempPath == wxEmptyString || fi == NULL || - fi->GetModificationTime() < bookfile.GetModificationTime() || - !LoadCachedBook(bookr, fi->GetStream())) - { - LoadMSProject(bookr, fsys, indexfile, contfile); - if (m_TempPath != wxEmptyString) - { - wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + - SafeFileName(wxFileNameFromPath(bookfile.GetLocation())) + wxT(".cached")); - SaveCachedBook(bookr, outs); - delete outs; - } - } - } - - if (fi != NULL) delete fi; - - // Now store the contents range - bookr->SetContentsRange(cont_start, m_ContentsCnt); - - // Convert encoding, if neccessary: - if (encoding != wxFONTENCODING_SYSTEM) - { - wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(encoding); - if (a.GetCount() != 0 && a[0] != encoding) - { - int i; - wxEncodingConverter conv; - conv.Init(encoding, a[0]); - - for (i = IndexOld; i < m_IndexCnt; i++) - conv.Convert(m_Index[i].m_Name); - for (i = ContentsOld; i < m_ContentsCnt; i++) - conv.Convert(m_Contents[i].m_Name); - } - } - - m_BookRecords.Add(bookr); - if (m_IndexCnt > 0) - qsort(m_Index, m_IndexCnt, sizeof(wxHtmlContentsItem), wxHtmlHelpIndexCompareFunc); - - return TRUE; -} - - -bool wxHtmlHelpData::AddBook(const wxString& book) -{ - if (book.Right(4).Lower() == wxT(".zip") || - book.Right(4).Lower() == wxT(".htb") /*html book*/) - { - wxFileSystem fsys; - wxString s; - bool rt = FALSE; - - s = fsys.FindFirst(book + wxT("#zip:") + wxT("*.hhp"), wxFILE); - while (!s.IsEmpty()) - { - if (AddBook(s)) rt = TRUE; - s = fsys.FindNext(); - } - - return rt; - } - else - { - wxFSFile *fi; - wxFileSystem fsys; - - wxString title = _("noname"), - safetitle, - start = wxEmptyString, - contents = wxEmptyString, - index = wxEmptyString, - charset = wxEmptyString; - - fi = fsys.OpenFile(book); - if (fi == NULL) - { - wxLogError(_("Cannot open HTML help book: %s"), book.c_str()); - return FALSE; - } - fsys.ChangePathTo(book); - - const wxChar *lineptr; - wxChar linebuf[300]; - wxString tmp; - wxHtmlFilterPlainText filter; - tmp = filter.ReadFile(*fi); - lineptr = tmp.c_str(); - - do - { - lineptr = ReadLine(lineptr, linebuf, 300); - - for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++) - *ch = tolower(*ch); - - if (wxStrstr(linebuf, _T("title=")) == linebuf) - title = linebuf + wxStrlen(_T("title=")); - if (wxStrstr(linebuf, _T("default topic=")) == linebuf) - start = linebuf + wxStrlen(_T("default topic=")); - if (wxStrstr(linebuf, _T("index file=")) == linebuf) - index = linebuf + wxStrlen(_T("index file=")); - if (wxStrstr(linebuf, _T("contents file=")) == linebuf) - contents = linebuf + wxStrlen(_T("contents file=")); - if (wxStrstr(linebuf, _T("charset=")) == linebuf) - charset = linebuf + wxStrlen(_T("charset=")); - } while (lineptr != NULL); - - wxFontEncoding enc; - if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM; - else enc = wxFontMapper::Get()->CharsetToEncoding(charset); - bool rtval = AddBookParam(*fi, enc, - title, contents, index, start, fsys.GetPath()); - delete fi; - return rtval; - } -} - -wxString wxHtmlHelpData::FindPageByName(const wxString& x) -{ - int cnt; - int i; - wxFileSystem fsys; - wxFSFile *f; - wxString url(wxEmptyString); - - /* 1. try to open given file: */ - - cnt = m_BookRecords.GetCount(); - for (i = 0; i < cnt; i++) - { - f = fsys.OpenFile(m_BookRecords[i].GetFullPath(x)); - if (f) - { - url = m_BookRecords[i].GetFullPath(x); - delete f; - return url; - } - } - - - /* 2. try to find a book: */ - - for (i = 0; i < cnt; i++) - { - if (m_BookRecords[i].GetTitle() == x) - { - url = m_BookRecords[i].GetFullPath(m_BookRecords[i].GetStart()); - return url; - } - } - - /* 3. try to find in contents: */ - - cnt = m_ContentsCnt; - for (i = 0; i < cnt; i++) - { - if (wxStrcmp(m_Contents[i].m_Name, x) == 0) - { - url = m_Contents[i].GetFullPath(); - return url; - } - } - - - /* 4. try to find in index: */ - - cnt = m_IndexCnt; - for (i = 0; i < cnt; i++) - { - if (wxStrcmp(m_Index[i].m_Name, x) == 0) - { - url = m_Index[i].GetFullPath(); - return url; - } - } - - return url; -} - -wxString wxHtmlHelpData::FindPageById(int id) -{ - int i; - wxString url(wxEmptyString); - - for (i = 0; i < m_ContentsCnt; i++) - { - if (m_Contents[i].m_ID == id) - { - url = m_Contents[i].GetFullPath(); - return url; - } - } - - return url; -} - -//---------------------------------------------------------------------------------- -// wxHtmlSearchStatus functions -//---------------------------------------------------------------------------------- - -wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData* data, const wxString& keyword, - bool case_sensitive, bool whole_words_only, - const wxString& book) -{ - m_Data = data; - m_Keyword = keyword; - wxHtmlBookRecord* bookr = NULL; - if (book != wxEmptyString) - { - // we have to search in a specific book. Find it first - int i, cnt = data->m_BookRecords.GetCount(); - for (i = 0; i < cnt; i++) - if (data->m_BookRecords[i].GetTitle() == book) - { - bookr = &(data->m_BookRecords[i]); - m_CurIndex = bookr->GetContentsStart(); - m_MaxIndex = bookr->GetContentsEnd(); - break; - } - // check; we won't crash if the book doesn't exist, but it's Bad Anyway. - wxASSERT(bookr); - } - if (! bookr) - { - // no book specified; search all books - m_CurIndex = 0; - m_MaxIndex = m_Data->m_ContentsCnt; - } - m_Engine.LookFor(keyword, case_sensitive, whole_words_only); - m_Active = (m_CurIndex < m_MaxIndex); - m_LastPage = NULL; -} - -bool wxHtmlSearchStatus::Search() -{ - wxFSFile *file; - int i = m_CurIndex; // shortcut - bool found = FALSE; - wxChar *thepage; - - if (!m_Active) - { - // sanity check. Illegal use, but we'll try to prevent a crash anyway - wxASSERT(m_Active); - return FALSE; - } - - m_Name = wxEmptyString; - m_ContentsItem = NULL; - thepage = m_Data->m_Contents[i].m_Page; - - m_Active = (++m_CurIndex < m_MaxIndex); - // check if it is same page with different anchor: - if (m_LastPage != NULL) - { - wxChar *p1, *p2; - for (p1 = thepage, p2 = m_LastPage; - *p1 != 0 && *p1 != _T('#') && *p1 == *p2; p1++, p2++) {} - - m_LastPage = thepage; - - if (*p1 == 0 || *p1 == _T('#')) - return FALSE; - } - else m_LastPage = thepage; - - wxFileSystem fsys; - file = fsys.OpenFile(m_Data->m_Contents[i].m_Book->GetFullPath(thepage)); - if (file) - { - if (m_Engine.Scan(*file)) - { - m_Name = m_Data->m_Contents[i].m_Name; - m_ContentsItem = m_Data->m_Contents + i; - found = TRUE; - } - delete file; - } - return found; -} - - - - - - - - -//-------------------------------------------------------------------------------- -// wxHtmlSearchEngine -//-------------------------------------------------------------------------------- - -void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only) -{ - m_CaseSensitive = case_sensitive; - m_WholeWords = whole_words_only; - if (m_Keyword) delete[] m_Keyword; - m_Keyword = new wxChar[keyword.Length() + 1]; - wxStrcpy(m_Keyword, keyword.c_str()); - - if (!m_CaseSensitive) - { - for (int i = wxStrlen(m_Keyword) - 1; i >= 0; i--) - { - if ((m_Keyword[i] >= wxT('A')) && (m_Keyword[i] <= wxT('Z'))) - m_Keyword[i] += wxT('a') - wxT('A'); - } - } -} - - -static inline bool WHITESPACE(wxChar c) -{ - return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t'); -} - -bool wxHtmlSearchEngine::Scan(const wxFSFile& file) -{ - wxASSERT_MSG(m_Keyword != NULL, wxT("wxHtmlSearchEngine::LookFor must be called before scanning!")); - - int i, j; - int wrd = wxStrlen(m_Keyword); - bool found = FALSE; - wxHtmlFilterHTML filter; - wxString tmp = filter.ReadFile(file); - int lng = tmp.length(); - const wxChar *buf = tmp.c_str(); - - if (!m_CaseSensitive) - for (i = 0; i < lng; i++) - tmp[(size_t)i] = (wxChar)wxTolower(tmp[(size_t)i]); - - if (m_WholeWords) - { - for (i = 0; i < lng - wrd; i++) - { - if (WHITESPACE(buf[i])) continue; - j = 0; - while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++; - if (j == wrd && WHITESPACE(buf[i + j])) { found = TRUE; break; } - } - } - - else - { - for (i = 0; i < lng - wrd; i++) - { - j = 0; - while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++; - if (j == wrd) { found = TRUE; break; } - } - } - - return found; -} - - - -#endif diff --git a/Contrib/NSIS Menu/src/html/helpfrm.cpp b/Contrib/NSIS Menu/src/html/helpfrm.cpp deleted file mode 100644 index 26a4c91d..00000000 --- a/Contrib/NSIS Menu/src/html/helpfrm.cpp +++ /dev/null @@ -1,1515 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: helpfrm.cpp -// Purpose: wxHtmlHelpFrame -// Notes: Based on htmlhelp.cpp, implementing a monolithic -// HTML Help controller class, by Vaclav Slavik -// Author: Harm van der Heijden and Vaclav Slavik -// RCS-ID: $Id: helpfrm.cpp,v 1.72.2.3 2002/12/16 10:23:20 JS Exp $ -// Copyright: (c) Harm van der Heijden and Vaclav Slavik -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "helpfrm.h" -#endif - -// For compilers that support precompilation, includes "wx.h" - -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#if wxUSE_WXHTML_HELP - -#ifndef WXPRECOMP - #include "wx/intl.h" - #include "wx/log.h" - - #include "wx/object.h" - #include "wx/sizer.h" - - #include "wx/bmpbuttn.h" - #include "wx/statbox.h" - #include "wx/radiobox.h" -#endif // WXPRECOMP - -#include "wx/html/helpfrm.h" -#include "wx/html/helpctrl.h" -#include "wx/textctrl.h" -#include "wx/notebook.h" -#include "wx/imaglist.h" -#include "wx/treectrl.h" -#include "wx/tokenzr.h" -#include "wx/wfstream.h" -#include "wx/html/htmlwin.h" -#include "wx/busyinfo.h" -#include "wx/progdlg.h" -#include "wx/toolbar.h" -#include "wx/fontenum.h" -#include "wx/stream.h" -#include "wx/filedlg.h" -#include "wx/artprov.h" -#include "wx/spinctrl.h" - -// what is considered "small index"? -#define INDEX_IS_SMALL 100 - -/* Motif defines this as a macro */ -#ifdef Below -#undef Below -#endif - -//-------------------------------------------------------------------------- -// wxHtmlHelpTreeItemData (private) -//-------------------------------------------------------------------------- - -class wxHtmlHelpTreeItemData : public wxTreeItemData -{ - public: -#if defined(__VISAGECPP__) -// VA needs a default ctor for some reason.... - wxHtmlHelpTreeItemData() : wxTreeItemData() - { m_Id = 0; } -#endif - wxHtmlHelpTreeItemData(int id) : wxTreeItemData() - { m_Id = id;} - - int m_Id; -}; - - -//-------------------------------------------------------------------------- -// wxHtmlHelpHashData (private) -//-------------------------------------------------------------------------- - -class wxHtmlHelpHashData : public wxObject -{ - public: - wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject() - { m_Index = index; m_Id = id;} - ~wxHtmlHelpHashData() {} - - int m_Index; - wxTreeItemId m_Id; -}; - - -//-------------------------------------------------------------------------- -// wxHtmlHelpHtmlWindow (private) -//-------------------------------------------------------------------------- - -class wxHtmlHelpHtmlWindow : public wxHtmlWindow -{ - public: - wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent) : wxHtmlWindow(parent), m_Frame(fr) {} - - virtual void OnLinkClicked(const wxHtmlLinkInfo& link) - { - wxHtmlWindow::OnLinkClicked(link); - m_Frame->NotifyPageChanged(); - } - - private: - wxHtmlHelpFrame *m_Frame; -}; - - - -//--------------------------------------------------------------------------- -// wxHtmlHelpFrame -//--------------------------------------------------------------------------- - -// Command IDs : -enum -{ - //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1, - wxID_HTML_PANEL = wxID_HIGHEST + 2, - wxID_HTML_BACK, - wxID_HTML_FORWARD, - wxID_HTML_UPNODE, - wxID_HTML_UP, - wxID_HTML_DOWN, - wxID_HTML_PRINT, - wxID_HTML_OPENFILE, - wxID_HTML_OPTIONS, - wxID_HTML_BOOKMARKSLIST, - wxID_HTML_BOOKMARKSADD, - wxID_HTML_BOOKMARKSREMOVE, - wxID_HTML_TREECTRL, - wxID_HTML_INDEXPAGE, - wxID_HTML_INDEXLIST, - wxID_HTML_INDEXTEXT, - wxID_HTML_INDEXBUTTON, - wxID_HTML_INDEXBUTTONALL, - wxID_HTML_NOTEBOOK, - wxID_HTML_SEARCHPAGE, - wxID_HTML_SEARCHTEXT, - wxID_HTML_SEARCHLIST, - wxID_HTML_SEARCHBUTTON, - wxID_HTML_SEARCHCHOICE, - wxID_HTML_COUNTINFO -}; - - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame) - -wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title, - int style, wxHtmlHelpData* data) -{ - Init(data); - Create(parent, id, title, style); -} - -void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) -{ - if (data) - { - m_Data = data; - m_DataCreated = FALSE; - } else - { - m_Data = new wxHtmlHelpData(); - m_DataCreated = TRUE; - } - - m_ContentsBox = NULL; - m_IndexList = NULL; - m_IndexButton = NULL; - m_IndexButtonAll = NULL; - m_IndexText = NULL; - m_SearchList = NULL; - m_SearchButton = NULL; - m_SearchText = NULL; - m_SearchChoice = NULL; - m_IndexCountInfo = NULL; - m_Splitter = NULL; - m_NavigPan = NULL; - m_NavigNotebook = NULL; - m_HtmlWin = NULL; - m_Bookmarks = NULL; - m_SearchCaseSensitive = NULL; - m_SearchWholeWords = NULL; - - m_Config = NULL; - m_ConfigRoot = wxEmptyString; - - m_Cfg.x = m_Cfg.y = 0; - m_Cfg.w = 700; - m_Cfg.h = 480; - m_Cfg.sashpos = 240; - m_Cfg.navig_on = TRUE; - - m_NormalFonts = m_FixedFonts = NULL; - m_NormalFace = m_FixedFace = wxEmptyString; -#ifdef __WXMSW__ - m_FontSize = 10; -#else - m_FontSize = 14; -#endif - -#if wxUSE_PRINTING_ARCHITECTURE - m_Printer = NULL; -#endif - - m_PagesHash = NULL; - m_UpdateContents = TRUE; - m_helpController = (wxHelpControllerBase*) NULL; -} - -// Create: builds the GUI components. -// with the style flag it's possible to toggle the toolbar, contents, index and search -// controls. -// m_HtmlWin will *always* be created, but it's important to realize that -// m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and -// m_SearchButton may be NULL. -// moreover, if no contents, index or searchpage is needed, m_Splitter and -// m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame) - -bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, - const wxString& WXUNUSED(title), int style) -{ - m_hfStyle = style; - - wxImageList *ContentsImageList = new wxImageList(16, 16); - ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK, wxART_HELP_BROWSER)); - ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER, wxART_HELP_BROWSER)); - ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE, wxART_HELP_BROWSER)); - - // Do the config in two steps. We read the HtmlWindow customization after we - // create the window. - if (m_Config) - ReadCustomization(m_Config, m_ConfigRoot); - - wxFrame::Create(parent, id, _("Help"), - wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), - wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp")); - - GetPosition(&m_Cfg.x, &m_Cfg.y); - - SetIcon(wxArtProvider::GetIcon(wxART_HELP, wxART_HELP_BROWSER)); - - int notebook_page = 0; - - CreateStatusBar(); - - // toolbar? - if (style & (wxHF_TOOLBAR | wxHF_FLAT_TOOLBAR)) - { - wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | - wxTB_DOCKABLE | - (style & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0)); - toolBar->SetMargins( 2, 2 ); - AddToolbarButtons(toolBar, style); - toolBar->Realize(); - } - - wxSizer *navigSizer = NULL; - - if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) - { - // traditional help controller; splitter window with html page on the - // right and a notebook containing various pages on the left - m_Splitter = new wxSplitterWindow(this); - - m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter); - m_NavigPan = new wxPanel(m_Splitter, -1); - m_NavigNotebook = new wxNotebook(m_NavigPan, wxID_HTML_NOTEBOOK, - wxDefaultPosition, wxDefaultSize); - wxNotebookSizer *nbs = new wxNotebookSizer(m_NavigNotebook); - - navigSizer = new wxBoxSizer(wxVERTICAL); - navigSizer->Add(nbs, 1, wxEXPAND); - - m_NavigPan->SetAutoLayout(TRUE); - m_NavigPan->SetSizer(navigSizer); - } - else - { // only html window, no notebook with index,contents etc - m_HtmlWin = new wxHtmlWindow(this); - } - - m_HtmlWin->SetRelatedFrame(this, m_TitleFormat); - m_HtmlWin->SetRelatedStatusBar(0); - if ( m_Config ) - m_HtmlWin->ReadCustomization(m_Config, m_ConfigRoot); - - // contents tree panel? - if ( style & wxHF_CONTENTS ) - { - wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE); - wxSizer *topsizer = new wxBoxSizer(wxVERTICAL); - - topsizer->Add(0, 10); - - dummy->SetAutoLayout(TRUE); - dummy->SetSizer(topsizer); - - if ( style & wxHF_BOOKMARKS ) - { - m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, - wxEmptyString, - wxDefaultPosition, wxDefaultSize, - 0, NULL, wxCB_READONLY | wxCB_SORT); - m_Bookmarks->Append(_("(bookmarks)")); - for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++) - m_Bookmarks->Append(m_BookmarksNames[i]); - m_Bookmarks->SetSelection(0); - - wxBitmapButton *bmpbt1, *bmpbt2; - bmpbt1 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, - wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, - wxART_HELP_BROWSER)); - bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, - wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK, - wxART_HELP_BROWSER)); -#if wxUSE_TOOLTIPS - bmpbt1->SetToolTip(_("Add current page to bookmarks")); - bmpbt2->SetToolTip(_("Remove current page from bookmarks")); -#endif // wxUSE_TOOLTIPS - - wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); - - sizer->Add(m_Bookmarks, 1, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5); - sizer->Add(bmpbt1, 0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 2); - sizer->Add(bmpbt2, 0, wxALIGN_CENTRE_VERTICAL, 0); - - topsizer->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 10); - } - - m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL, - wxDefaultPosition, wxDefaultSize, - wxSUNKEN_BORDER | - wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | - wxTR_LINES_AT_ROOT); - - m_ContentsBox->AssignImageList(ContentsImageList); - - topsizer->Add(m_ContentsBox, 1, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 2); - - m_NavigNotebook->AddPage(dummy, _("Contents")); - m_ContentsPage = notebook_page++; - } - - // index listbox panel? - if ( style & wxHF_INDEX ) - { - wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE); - wxSizer *topsizer = new wxBoxSizer(wxVERTICAL); - - dummy->SetAutoLayout(TRUE); - dummy->SetSizer(topsizer); - - m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, - wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER); - m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find")); - m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, - _("Show all")); - m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, - wxEmptyString, wxDefaultPosition, - wxDefaultSize, - wxALIGN_RIGHT | wxST_NO_AUTORESIZE); - m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, - wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_SINGLE); - -#if wxUSE_TOOLTIPS - m_IndexButton->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive.")); - m_IndexButtonAll->SetToolTip(_("Show all items in index")); -#endif //wxUSE_TOOLTIPS - - topsizer->Add(m_IndexText, 0, wxEXPAND | wxALL, 10); - wxSizer *btsizer = new wxBoxSizer(wxHORIZONTAL); - btsizer->Add(m_IndexButton, 0, wxRIGHT, 2); - btsizer->Add(m_IndexButtonAll); - topsizer->Add(btsizer, 0, - wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 10); - topsizer->Add(m_IndexCountInfo, 0, wxEXPAND | wxLEFT | wxRIGHT, 2); - topsizer->Add(m_IndexList, 1, wxEXPAND | wxALL, 2); - - m_NavigNotebook->AddPage(dummy, _("Index")); - m_IndexPage = notebook_page++; - } - - // search list panel? - if ( style & wxHF_SEARCH ) - { - wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE); - wxSizer *sizer = new wxBoxSizer(wxVERTICAL); - - dummy->SetAutoLayout(TRUE); - dummy->SetSizer(sizer); - - m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, - wxEmptyString, - wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER); - m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, - wxDefaultPosition, wxDefaultSize); - m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive")); - m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only")); - m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search")); -#if wxUSE_TOOLTIPS - m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above")); -#endif //wxUSE_TOOLTIPS - m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, - wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_SINGLE); - - sizer->Add(m_SearchText, 0, wxEXPAND | wxALL, 10); - sizer->Add(m_SearchChoice, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10); - sizer->Add(m_SearchCaseSensitive, 0, wxLEFT | wxRIGHT, 10); - sizer->Add(m_SearchWholeWords, 0, wxLEFT | wxRIGHT, 10); - sizer->Add(m_SearchButton, 0, wxALL | wxALIGN_RIGHT, 8); - sizer->Add(m_SearchList, 1, wxALL | wxEXPAND, 2); - - m_NavigNotebook->AddPage(dummy, _("Search")); - m_SearchPage = notebook_page++; - } - - m_HtmlWin->Show(TRUE); - - RefreshLists(); - - if ( navigSizer ) - { - navigSizer->SetSizeHints(m_NavigPan); - m_NavigPan->Layout(); - } - - // showtime - if ( m_NavigPan && m_Splitter ) - { - m_Splitter->SetMinimumPaneSize(20); - if ( m_Cfg.navig_on ) - m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); - - if ( m_Cfg.navig_on ) - { - m_NavigPan->Show(TRUE); - m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); - } - else - { - m_NavigPan->Show(FALSE); - m_Splitter->Initialize(m_HtmlWin); - } - } - - return TRUE; -} - -wxHtmlHelpFrame::~wxHtmlHelpFrame() -{ - // PopEventHandler(); // wxhtmlhelpcontroller (not any more!) - if (m_DataCreated) - delete m_Data; - if (m_NormalFonts) delete m_NormalFonts; - if (m_FixedFonts) delete m_FixedFonts; - if (m_PagesHash) delete m_PagesHash; -} - - -void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style) -{ - wxBitmap wpanelBitmap = - wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL, wxART_HELP_BROWSER); - wxBitmap wbackBitmap = - wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_HELP_BROWSER); - wxBitmap wforwardBitmap = - wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_HELP_BROWSER); - wxBitmap wupnodeBitmap = - wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_HELP_BROWSER); - wxBitmap wupBitmap = - wxArtProvider::GetBitmap(wxART_GO_UP, wxART_HELP_BROWSER); - wxBitmap wdownBitmap = - wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_HELP_BROWSER); - wxBitmap wopenBitmap = - wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_HELP_BROWSER); - wxBitmap wprintBitmap = - wxArtProvider::GetBitmap(wxART_PRINT, wxART_HELP_BROWSER); - wxBitmap woptionsBitmap = - wxArtProvider::GetBitmap(wxART_HELP_SETTINGS, wxART_HELP_BROWSER); - - wxASSERT_MSG( (wpanelBitmap.Ok() && wbackBitmap.Ok() && - wforwardBitmap.Ok() && wupnodeBitmap.Ok() && - wupBitmap.Ok() && wdownBitmap.Ok() && - wopenBitmap.Ok() && wprintBitmap.Ok() && - woptionsBitmap.Ok()), - wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ; - - - toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Show/hide navigation panel")); - - toolBar->AddSeparator(); - toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Go back")); - toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Go forward")); - toolBar->AddSeparator(); - - toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Go one level up in document hierarchy")); - toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Previous page")); - toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Next page")); - - if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES)) - toolBar->AddSeparator(); - - if (style & wxHF_OPEN_FILES) - toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Open HTML document")); - -#if wxUSE_PRINTING_ARCHITECTURE - if (style & wxHF_PRINT) - toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Print this page")); -#endif - - toolBar->AddSeparator(); - toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap, - FALSE, -1, -1, (wxObject *) NULL, - _("Display options dialog")); -} - - -void wxHtmlHelpFrame::SetTitleFormat(const wxString& format) -{ - if (m_HtmlWin) - m_HtmlWin->SetRelatedFrame(this, format); - m_TitleFormat = format; -} - - -bool wxHtmlHelpFrame::Display(const wxString& x) -{ - wxString url = m_Data->FindPageByName(x); - if (!url.IsEmpty()) - { - m_HtmlWin->LoadPage(url); - NotifyPageChanged(); - return TRUE; - } - return FALSE; -} - -bool wxHtmlHelpFrame::Display(const int id) -{ - wxString url = m_Data->FindPageById(id); - if (!url.IsEmpty()) - { - m_HtmlWin->LoadPage(url); - NotifyPageChanged(); - return TRUE; - } - return FALSE; -} - - - -bool wxHtmlHelpFrame::DisplayContents() -{ - if (! m_ContentsBox) - return FALSE; - if (!m_Splitter->IsSplit()) - { - m_NavigPan->Show(TRUE); - m_HtmlWin->Show(TRUE); - m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); - m_Cfg.navig_on = TRUE; - } - m_NavigNotebook->SetSelection(0); - if (m_Data->GetBookRecArray().GetCount() > 0) - { - wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0]; - if (!book.GetStart().IsEmpty()) - m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart())); - } - return TRUE; -} - - - -bool wxHtmlHelpFrame::DisplayIndex() -{ - if (! m_IndexList) - return FALSE; - if (!m_Splitter->IsSplit()) - { - m_NavigPan->Show(TRUE); - m_HtmlWin->Show(TRUE); - m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); - } - m_NavigNotebook->SetSelection(1); - if (m_Data->GetBookRecArray().GetCount() > 0) - { - wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0]; - if (!book.GetStart().IsEmpty()) - m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart())); - } - return TRUE; -} - - - -bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword) -{ - if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice)) - return FALSE; - - int foundcnt = 0, curi; - wxString foundstr; - wxString book = wxEmptyString; - - if (!m_Splitter->IsSplit()) - { - m_NavigPan->Show(TRUE); - m_HtmlWin->Show(TRUE); - m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); - } - m_NavigNotebook->SetSelection(m_SearchPage); - m_SearchList->Clear(); - m_SearchText->SetValue(keyword); - m_SearchButton->Enable(FALSE); - - if (m_SearchChoice->GetSelection() != 0) - book = m_SearchChoice->GetStringSelection(); - - wxHtmlSearchStatus status(m_Data, keyword, - m_SearchCaseSensitive->GetValue(), m_SearchWholeWords->GetValue(), - book); - - wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), - status.GetMaxIndex(), this, - wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); - - while (status.IsActive()) - { - curi = status.GetCurIndex(); - if (curi % 32 == 0 && progress.Update(curi) == FALSE) - break; - if (status.Search()) - { - foundstr.Printf(_("Found %i matches"), ++foundcnt); - progress.Update(status.GetCurIndex(), foundstr); - m_SearchList->Append(status.GetName(), status.GetContentsItem()); - } - } - - m_SearchButton->Enable(TRUE); - m_SearchText->SetSelection(0, keyword.Length()); - m_SearchText->SetFocus(); - if (foundcnt) - { - wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(0); - if (it) - { - m_HtmlWin->LoadPage(it->GetFullPath()); - NotifyPageChanged(); - } - } - return (foundcnt > 0); -} - -void wxHtmlHelpFrame::CreateContents() -{ - if (! m_ContentsBox) - return ; - - m_ContentsBox->Clear(); - - if (m_PagesHash) delete m_PagesHash; - m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data->GetContentsCnt()); - m_PagesHash->DeleteContents(TRUE); - - int cnt = m_Data->GetContentsCnt(); - int i; - - wxHtmlContentsItem *it; - - const int MAX_ROOTS = 64; - wxTreeItemId roots[MAX_ROOTS]; - // VS: this array holds information about whether we've set item icon at - // given level. This is neccessary because m_Data has flat structure - // and there's no way of recognizing if some item has subitems or not. - // We set the icon later: when we find an item with level=n, we know - // that the last item with level=n-1 was folder with subitems, so we - // set its icon accordingly - bool imaged[MAX_ROOTS]; - m_ContentsBox->DeleteAllItems(); - - roots[0] = m_ContentsBox->AddRoot(_("(Help)")); - imaged[0] = TRUE; - - for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) - { - // Handle books: - if (it->m_Level == 0) - { - if (m_hfStyle & wxHF_MERGE_BOOKS) - // VS: we don't want book nodes, books' content should - // appear under tree's root. This line will create "fake" - // record about book node so that the rest of this look - // will believe there really _is_ book node and will - // behave correctly. - roots[1] = roots[0]; - else - { - roots[1] = m_ContentsBox->AppendItem(roots[0], - it->m_Name, IMG_Book, -1, - new wxHtmlHelpTreeItemData(i)); - m_ContentsBox->SetItemBold(roots[1], TRUE); - } - imaged[1] = TRUE; - } - // ...and their contents: - else - { - roots[it->m_Level + 1] = m_ContentsBox->AppendItem( - roots[it->m_Level], it->m_Name, IMG_Page, - -1, new wxHtmlHelpTreeItemData(i)); - imaged[it->m_Level + 1] = FALSE; - } - - m_PagesHash->Put(it->GetFullPath(), - new wxHtmlHelpHashData(i, roots[it->m_Level + 1])); - - // Set the icon for the node one level up in the hiearachy, - // unless already done (see comment above imaged[] declaration) - if (!imaged[it->m_Level]) - { - int image = IMG_Folder; - if (m_hfStyle & wxHF_ICONS_BOOK) - image = IMG_Book; - else if (m_hfStyle & wxHF_ICONS_BOOK_CHAPTER) - image = (it->m_Level == 1) ? IMG_Book : IMG_Folder; - m_ContentsBox->SetItemImage(roots[it->m_Level], image); - m_ContentsBox->SetItemSelectedImage(roots[it->m_Level], image); - imaged[it->m_Level] = TRUE; - } - } -} - - -void wxHtmlHelpFrame::CreateIndex() -{ - if (! m_IndexList) - return ; - - m_IndexList->Clear(); - - int cnt = m_Data->GetIndexCnt(); - - wxString cnttext; - if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt); - else cnttext.Printf(_("%i of %i"), cnt, cnt); - m_IndexCountInfo->SetLabel(cnttext); - if (cnt > INDEX_IS_SMALL) return; - - wxHtmlContentsItem* index = m_Data->GetIndex(); - - for (int i = 0; i < cnt; i++) - m_IndexList->Append(index[i].m_Name, (char*)(index + i)); -} - -void wxHtmlHelpFrame::CreateSearch() -{ - if (! (m_SearchList && m_SearchChoice)) - return ; - m_SearchList->Clear(); - m_SearchChoice->Clear(); - m_SearchChoice->Append(_("Search in all books")); - const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); - int i, cnt = bookrec.GetCount(); - for (i = 0; i < cnt; i++) - m_SearchChoice->Append(bookrec[i].GetTitle()); - m_SearchChoice->SetSelection(0); -} - - -void wxHtmlHelpFrame::RefreshLists() -{ - CreateContents(); - CreateIndex(); - CreateSearch(); -} - -void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) -{ - wxString oldpath; - wxString tmp; - - if (path != wxEmptyString) - { - oldpath = cfg->GetPath(); - cfg->SetPath(_T("/") + path); - } - - m_Cfg.navig_on = cfg->Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0; - m_Cfg.sashpos = cfg->Read(wxT("hcSashPos"), m_Cfg.sashpos); - m_Cfg.x = cfg->Read(wxT("hcX"), m_Cfg.x); - m_Cfg.y = cfg->Read(wxT("hcY"), m_Cfg.y); - m_Cfg.w = cfg->Read(wxT("hcW"), m_Cfg.w); - m_Cfg.h = cfg->Read(wxT("hcH"), m_Cfg.h); - - m_FixedFace = cfg->Read(wxT("hcFixedFace"), m_FixedFace); - m_NormalFace = cfg->Read(wxT("hcNormalFace"), m_NormalFace); - m_FontSize = cfg->Read(wxT("hcBaseFontSize"), m_FontSize); - - { - int i; - int cnt; - wxString val, s; - - cnt = cfg->Read(wxT("hcBookmarksCnt"), 0L); - if (cnt != 0) - { - m_BookmarksNames.Clear(); - m_BookmarksPages.Clear(); - if (m_Bookmarks) - { - m_Bookmarks->Clear(); - m_Bookmarks->Append(_("(bookmarks)")); - } - - for (i = 0; i < cnt; i++) - { - val.Printf(wxT("hcBookmark_%i"), i); - s = cfg->Read(val); - m_BookmarksNames.Add(s); - if (m_Bookmarks) m_Bookmarks->Append(s); - val.Printf(wxT("hcBookmark_%i_url"), i); - s = cfg->Read(val); - m_BookmarksPages.Add(s); - } - } - } - - if (m_HtmlWin) - m_HtmlWin->ReadCustomization(cfg); - - if (path != wxEmptyString) - cfg->SetPath(oldpath); -} - -void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path) -{ - wxString oldpath; - wxString tmp; - - if (path != wxEmptyString) - { - oldpath = cfg->GetPath(); - cfg->SetPath(_T("/") + path); - } - - cfg->Write(wxT("hcNavigPanel"), m_Cfg.navig_on); - cfg->Write(wxT("hcSashPos"), (long)m_Cfg.sashpos); - if ( !IsIconized() ) - { - // Don't write if iconized as this would make the window - // disappear next time it is shown! - cfg->Write(wxT("hcX"), (long)m_Cfg.x); - cfg->Write(wxT("hcY"), (long)m_Cfg.y); - cfg->Write(wxT("hcW"), (long)m_Cfg.w); - cfg->Write(wxT("hcH"), (long)m_Cfg.h); - } - cfg->Write(wxT("hcFixedFace"), m_FixedFace); - cfg->Write(wxT("hcNormalFace"), m_NormalFace); - cfg->Write(wxT("hcBaseFontSize"), (long)m_FontSize); - - if (m_Bookmarks) - { - int i; - int cnt = m_BookmarksNames.GetCount(); - wxString val; - - cfg->Write(wxT("hcBookmarksCnt"), (long)cnt); - for (i = 0; i < cnt; i++) - { - val.Printf(wxT("hcBookmark_%i"), i); - cfg->Write(val, m_BookmarksNames[i]); - val.Printf(wxT("hcBookmark_%i_url"), i); - cfg->Write(val, m_BookmarksPages[i]); - } - } - - if (m_HtmlWin) - m_HtmlWin->WriteCustomization(cfg); - - if (path != wxEmptyString) - cfg->SetPath(oldpath); -} - - - - - -static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size) -{ - int f_sizes[7]; - f_sizes[0] = int(size * 0.6); - f_sizes[1] = int(size * 0.8); - f_sizes[2] = size; - f_sizes[3] = int(size * 1.2); - f_sizes[4] = int(size * 1.4); - f_sizes[5] = int(size * 1.6); - f_sizes[6] = int(size * 1.8); - - win->SetFonts(scalf, fixf, f_sizes); -} - - -class wxHtmlHelpFrameOptionsDialog : public wxDialog -{ -public: - wxComboBox *NormalFont, *FixedFont; - wxSpinCtrl *FontSize; - wxHtmlWindow *TestWin; - - wxHtmlHelpFrameOptionsDialog(wxWindow *parent) - : wxDialog(parent, -1, wxString(_("Help Browser Options"))) - { - wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL); - wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 3, 2, 5); - - sizer->Add(new wxStaticText(this, -1, _("Normal font:"))); - sizer->Add(new wxStaticText(this, -1, _("Fixed font:"))); - sizer->Add(new wxStaticText(this, -1, _("Font size:"))); - - sizer->Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, - wxSize(200, 200), - 0, NULL, wxCB_DROPDOWN | wxCB_READONLY)); - - sizer->Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, - wxSize(200, 200), - 0, NULL, wxCB_DROPDOWN | wxCB_READONLY)); - - sizer->Add(FontSize = new wxSpinCtrl(this, -1)); - FontSize->SetRange(2, 100); - - topsizer->Add(sizer, 0, wxLEFT|wxRIGHT|wxTOP, 10); - - topsizer->Add(new wxStaticText(this, -1, _("Preview:")), - 0, wxLEFT | wxTOP, 10); - topsizer->Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(20, 150), - wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER), - 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10); - - wxBoxSizer *sizer2 = new wxBoxSizer(wxHORIZONTAL); - wxButton *ok; - sizer2->Add(ok = new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10); - ok->SetDefault(); - sizer2->Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10); - topsizer->Add(sizer2, 0, wxALIGN_RIGHT); - - SetAutoLayout(TRUE); - SetSizer(topsizer); - topsizer->Fit(this); - Centre(wxBOTH); - } - - - void UpdateTestWin() - { - wxBusyCursor bcur; - SetFontsToHtmlWin(TestWin, - NormalFont->GetStringSelection(), - FixedFont->GetStringSelection(), - FontSize->GetValue()); - TestWin->SetPage(_( -"\ -
\ -Normal face
(and underlined. Italic face. \ -Bold face. Bold italic face.
\ -font size -2
\ -font size -1
\ -font size +0
\ -font size +1
\ -font size +2
\ -font size +3
\ -font size +4
\ -
\ -

Fixed size face.
bold italic \ -bold italic underlined
\ -font size -2
\ -font size -1
\ -font size +0
\ -font size +1
\ -font size +2
\ -font size +3
\ -font size +4
\ -

" - )); - } - - void OnUpdate(wxCommandEvent& WXUNUSED(event)) - { - UpdateTestWin(); - } - void OnUpdateSpin(wxSpinEvent& WXUNUSED(event)) - { - UpdateTestWin(); - } - - DECLARE_EVENT_TABLE() -}; - -BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog) - EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate) - EVT_SPINCTRL(-1, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin) -END_EVENT_TABLE() - - -void wxHtmlHelpFrame::OptionsDialog() -{ - wxHtmlHelpFrameOptionsDialog dlg(this); - unsigned i; - - if (m_NormalFonts == NULL) - { - wxFontEnumerator enu; - enu.EnumerateFacenames(); - m_NormalFonts = new wxArrayString; - *m_NormalFonts = *enu.GetFacenames(); - m_NormalFonts->Sort(); - } - if (m_FixedFonts == NULL) - { - wxFontEnumerator enu; - enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE); - m_FixedFonts = new wxArrayString; - *m_FixedFonts = *enu.GetFacenames(); - m_FixedFonts->Sort(); - } - - // VS: We want to show the font that is actually used by wxHtmlWindow. - // If customization dialog wasn't used yet, facenames are empty and - // wxHtmlWindow uses default fonts -- let's find out what they - // are so that we can pass them to the dialog: - if (m_NormalFace.empty()) - { - wxFont fnt(m_FontSize, wxSWISS, wxNORMAL, wxNORMAL, FALSE); - m_NormalFace = fnt.GetFaceName(); - } - if (m_FixedFace.empty()) - { - wxFont fnt(m_FontSize, wxMODERN, wxNORMAL, wxNORMAL, FALSE); - m_FixedFace = fnt.GetFaceName(); - } - - for (i = 0; i < m_NormalFonts->GetCount(); i++) - dlg.NormalFont->Append((*m_NormalFonts)[i]); - for (i = 0; i < m_FixedFonts->GetCount(); i++) - dlg.FixedFont->Append((*m_FixedFonts)[i]); - if (!m_NormalFace.empty()) - dlg.NormalFont->SetStringSelection(m_NormalFace); - else - dlg.NormalFont->SetSelection(0); - if (!m_FixedFace.empty()) - dlg.FixedFont->SetStringSelection(m_FixedFace); - else - dlg.FixedFont->SetSelection(0); - dlg.FontSize->SetValue(m_FontSize); - dlg.UpdateTestWin(); - - if (dlg.ShowModal() == wxID_OK) - { - m_NormalFace = dlg.NormalFont->GetStringSelection(); - m_FixedFace = dlg.FixedFont->GetStringSelection(); - m_FontSize = dlg.FontSize->GetValue(); - SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize); - } -} - - - -void wxHtmlHelpFrame::NotifyPageChanged() -{ - if (m_UpdateContents && m_PagesHash) - { - wxString an = m_HtmlWin->GetOpenedAnchor(); - wxHtmlHelpHashData *ha; - if (an.IsEmpty()) - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage()); - else - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an); - if (ha) - { - bool olduc = m_UpdateContents; - m_UpdateContents = FALSE; - m_ContentsBox->SelectItem(ha->m_Id); - m_ContentsBox->EnsureVisible(ha->m_Id); - m_UpdateContents = olduc; - } - } -} - - - -/* -EVENT HANDLING : -*/ - - -void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event) -{ - // This saves one mouse click when using the - // wxHTML for context sensitive help systems -#ifndef __WXGTK__ - // NB: wxActivateEvent is a bit broken in wxGTK - // and is sometimes sent when it should not be - if (event.GetActive() && m_HtmlWin) - m_HtmlWin->SetFocus(); -#endif - - event.Skip(); -} - -void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) -{ - switch (event.GetId()) - { - case wxID_HTML_BACK : - m_HtmlWin->HistoryBack(); - NotifyPageChanged(); - break; - - case wxID_HTML_FORWARD : - m_HtmlWin->HistoryForward(); - NotifyPageChanged(); - break; - - case wxID_HTML_UP : - if (m_PagesHash) - { - wxString an = m_HtmlWin->GetOpenedAnchor(); - wxHtmlHelpHashData *ha; - if (an.IsEmpty()) - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage()); - else - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an); - if (ha && ha->m_Index > 0) - { - wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index - 1); - if (it->m_Page[0] != 0) - { - m_HtmlWin->LoadPage(it->GetFullPath()); - NotifyPageChanged(); - } - } - } - break; - - case wxID_HTML_UPNODE : - if (m_PagesHash) - { - wxString an = m_HtmlWin->GetOpenedAnchor(); - wxHtmlHelpHashData *ha; - if (an.IsEmpty()) - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage()); - else - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an); - if (ha && ha->m_Index > 0) - { - int level = m_Data->GetContents()[ha->m_Index].m_Level - 1; - wxHtmlContentsItem *it; - int ind = ha->m_Index - 1; - - it = m_Data->GetContents() + ind; - while (ind >= 0 && it->m_Level != level) ind--, it--; - if (ind >= 0) - { - if (it->m_Page[0] != 0) - { - m_HtmlWin->LoadPage(it->GetFullPath()); - NotifyPageChanged(); - } - } - } - } - break; - - case wxID_HTML_DOWN : - if (m_PagesHash) - { - wxString an = m_HtmlWin->GetOpenedAnchor(); - wxString adr; - wxHtmlHelpHashData *ha; - - if (an.IsEmpty()) adr = m_HtmlWin->GetOpenedPage(); - else adr = m_HtmlWin->GetOpenedPage() + wxT("#") + an; - - ha = (wxHtmlHelpHashData*) m_PagesHash->Get(adr); - - if (ha && ha->m_Index < m_Data->GetContentsCnt() - 1) - { - wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index + 1); - - while (it->GetFullPath() == adr) it++; - - if (it->m_Page[0] != 0) - { - m_HtmlWin->LoadPage(it->GetFullPath()); - NotifyPageChanged(); - } - } - } - break; - - case wxID_HTML_PANEL : - { - if (! (m_Splitter && m_NavigPan)) - return ; - if (m_Splitter->IsSplit()) - { - m_Cfg.sashpos = m_Splitter->GetSashPosition(); - m_Splitter->Unsplit(m_NavigPan); - m_Cfg.navig_on = FALSE; - } - else - { - m_NavigPan->Show(TRUE); - m_HtmlWin->Show(TRUE); - m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); - m_Cfg.navig_on = TRUE; - } - } - break; - - case wxID_HTML_OPTIONS : - OptionsDialog(); - break; - - case wxID_HTML_BOOKMARKSADD : - { - wxString item; - wxString url; - - item = m_HtmlWin->GetOpenedPageTitle(); - url = m_HtmlWin->GetOpenedPage(); - if (item == wxEmptyString) - item = url.AfterLast(wxT('/')); - if (m_BookmarksPages.Index(url) == wxNOT_FOUND) - { - m_Bookmarks->Append(item); - m_BookmarksNames.Add(item); - m_BookmarksPages.Add(url); - } - } - break; - - case wxID_HTML_BOOKMARKSREMOVE : - { - wxString item; - int pos; - - item = m_Bookmarks->GetStringSelection(); - pos = m_BookmarksNames.Index(item); - if (pos != wxNOT_FOUND) - { - m_BookmarksNames.Remove(pos); - m_BookmarksPages.Remove(pos); - m_Bookmarks->Delete(m_Bookmarks->GetSelection()); - } - } - break; - -#if wxUSE_PRINTING_ARCHITECTURE - case wxID_HTML_PRINT : - { - if (m_Printer == NULL) - m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this); - if (!m_HtmlWin->GetOpenedPage()) - wxLogWarning(_("Cannot print empty page.")); - else - m_Printer->PrintFile(m_HtmlWin->GetOpenedPage()); - } - break; -#endif - - case wxID_HTML_OPENFILE : - { - wxString s = wxFileSelector(_("Open HTML document"), - wxEmptyString, - wxEmptyString, - wxEmptyString, - _( -"HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|\ -Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\ -HTML Help Project (*.hhp)|*.hhp|\ -All files (*.*)|*" - ), - wxOPEN | wxFILE_MUST_EXIST, - this); - if (!s.IsEmpty()) - { - wxString ext = s.Right(4).Lower(); - if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp")) - { - wxBusyCursor bcur; - m_Data->AddBook(s); - RefreshLists(); - } - else - m_HtmlWin->LoadPage(s); - } - } - break; - } -} - - - -void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event) -{ - wxHtmlHelpTreeItemData *pg; - wxHtmlContentsItem *it; - - pg = (wxHtmlHelpTreeItemData*) m_ContentsBox->GetItemData(event.GetItem()); - - if (pg && m_UpdateContents) - { - it = m_Data->GetContents() + (pg->m_Id); - m_UpdateContents = FALSE; - if (it->m_Page[0] != 0) - m_HtmlWin->LoadPage(it->GetFullPath()); - m_UpdateContents = TRUE; - } -} - - - -void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event)) -{ - wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList->GetClientData(m_IndexList->GetSelection()); - if (it->m_Page[0] != 0) - m_HtmlWin->LoadPage(it->GetFullPath()); - NotifyPageChanged(); -} - - -void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event) -{ - wxString sr = m_IndexText->GetLineText(0); - sr.MakeLower(); - if (sr == wxEmptyString) - { - OnIndexAll(event); - } - else - { - wxBusyCursor bcur; - const wxChar *cstr = sr.c_str(); - wxChar mybuff[512]; - wxChar *ptr; - bool first = TRUE; - - m_IndexList->Clear(); - int cnt = m_Data->GetIndexCnt(); - wxHtmlContentsItem* index = m_Data->GetIndex(); - - int displ = 0; - for (int i = 0; i < cnt; i++) - { - wxStrncpy(mybuff, index[i].m_Name, 512); - mybuff[511] = _T('\0'); - for (ptr = mybuff; *ptr != 0; ptr++) - if (*ptr >= _T('A') && *ptr <= _T('Z')) - *ptr -= (wxChar)(_T('A') - _T('a')); - if (wxStrstr(mybuff, cstr) != NULL) - { - m_IndexList->Append(index[i].m_Name, (char*)(index + i)); - displ++; - if (first) - { - if (index[i].m_Page[0] != 0) - m_HtmlWin->LoadPage(index[i].GetFullPath()); - NotifyPageChanged(); - first = FALSE; - } - } - } - - wxString cnttext; - cnttext.Printf(_("%i of %i"), displ, cnt); - m_IndexCountInfo->SetLabel(cnttext); - - m_IndexText->SetSelection(0, sr.Length()); - m_IndexText->SetFocus(); - } -} - -void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event)) -{ - wxBusyCursor bcur; - - m_IndexList->Clear(); - int cnt = m_Data->GetIndexCnt(); - bool first = TRUE; - wxHtmlContentsItem* index = m_Data->GetIndex(); - - for (int i = 0; i < cnt; i++) - { - m_IndexList->Append(index[i].m_Name, (char*)(index + i)); - if (first) - { - if (index[i].m_Page[0] != 0) - m_HtmlWin->LoadPage(index[i].GetFullPath()); - NotifyPageChanged(); - first = FALSE; - } - } - - wxString cnttext; - cnttext.Printf(_("%i of %i"), cnt, cnt); - m_IndexCountInfo->SetLabel(cnttext); -} - - -void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event)) -{ - wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(m_SearchList->GetSelection()); - if (it) - { - if (it->m_Page[0] != 0) - m_HtmlWin->LoadPage(it->GetFullPath()); - NotifyPageChanged(); - } -} - -void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) -{ - wxString sr = m_SearchText->GetLineText(0); - - if (sr != wxEmptyString) KeywordSearch(sr); -} - -void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event)) -{ - wxString sr = m_Bookmarks->GetStringSelection(); - - if (sr != wxEmptyString && sr != _("(bookmarks)")) - { - m_HtmlWin->LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]); - NotifyPageChanged(); - } -} - -void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) -{ - GetSize(&m_Cfg.w, &m_Cfg.h); - GetPosition(&m_Cfg.x, &m_Cfg.y); - -#ifdef __WXGTK__ - if (IsGrabbed()) - { - RemoveGrab(); - } -#endif - - if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition(); - - if (m_Config) - WriteCustomization(m_Config, m_ConfigRoot); - - if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController))) - { - ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt); - } - - evt.Skip(); -} - -BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) - EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate) - EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar) - EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar) - EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar) - EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) - EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) - EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) - EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) - EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) - EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind) - EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind) - EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll) - EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel) - EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) -END_EVENT_TABLE() - -#endif // wxUSE_WXHTML_HELP - diff --git a/Contrib/NSIS Menu/src/html/htmlcell.cpp b/Contrib/NSIS Menu/src/html/htmlcell.cpp deleted file mode 100644 index 018445ff..00000000 --- a/Contrib/NSIS Menu/src/html/htmlcell.cpp +++ /dev/null @@ -1,728 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: htmlcell.cpp -// Purpose: wxHtmlCell - basic element of HTML output -// Author: Vaclav Slavik -// RCS-ID: $Id: htmlcell.cpp,v 1.50.2.10 2002/12/19 22:15:45 VS Exp $ -// Copyright: (c) 1999 Vaclav Slavik -// Licence: wxWindows Licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "htmlcell.h" -#endif - -#include "wx/wxprec.h" - -#include "wx/defs.h" - -#if wxUSE_HTML && wxUSE_STREAMS - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WXPRECOMP - #include "wx/brush.h" - #include "wx/colour.h" - #include "wx/dc.h" -#endif - -#include "wx/html/htmlcell.h" -#include "wx/html/htmlwin.h" -#include - - -//----------------------------------------------------------------------------- -// wxHtmlCell -//----------------------------------------------------------------------------- - -wxHtmlCell::wxHtmlCell() : wxObject() -{ - m_Next = NULL; - m_Parent = NULL; - m_Width = m_Height = m_Descent = 0; - m_CanLiveOnPagebreak = TRUE; - m_Link = NULL; -} - -wxHtmlCell::~wxHtmlCell() -{ - delete m_Link; -} - - -void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, - const wxMouseEvent& event) -{ - wxHtmlLinkInfo *lnk = GetLink(x, y); - if (lnk != NULL) - { - wxHtmlLinkInfo lnk2(*lnk); - lnk2.SetEvent(&event); - lnk2.SetHtmlCell(this); - - // note : this cast is legal because parent is *always* wxHtmlWindow - wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2); - } -} - - - -bool wxHtmlCell::AdjustPagebreak(int *pagebreak) const -{ - if ((!m_CanLiveOnPagebreak) && - m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) - { - *pagebreak = m_PosY; - return TRUE; - } - - return FALSE; -} - - - -void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) -{ - if (m_Link) delete m_Link; - m_Link = NULL; - if (link.GetHref() != wxEmptyString) - m_Link = new wxHtmlLinkInfo(link); -} - - - -void wxHtmlCell::Layout(int WXUNUSED(w)) -{ - SetPos(0, 0); -} - - - -void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const -{ - if (left) - *left = m_PosX; - if (right) - *right = m_PosX + m_Width; -} - - - -const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const -{ - return NULL; -} - - -wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y) const -{ - if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height ) - return wxConstCast(this, wxHtmlCell); - - return NULL; -} - - -//----------------------------------------------------------------------------- -// wxHtmlWordCell -//----------------------------------------------------------------------------- - -wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() -{ - m_Word = word; - dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); - SetCanLiveOnPagebreak(FALSE); -} - - - -void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, int WXUNUSED(view_y1), int WXUNUSED(view_y2)) -{ - dc.DrawText(m_Word, x + m_PosX, y + m_PosY); -} - - - -//----------------------------------------------------------------------------- -// wxHtmlContainerCell -//----------------------------------------------------------------------------- - - -wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() -{ - m_Cells = m_LastCell = NULL; - m_Parent = parent; - if (m_Parent) m_Parent->InsertCell(this); - m_AlignHor = wxHTML_ALIGN_LEFT; - m_AlignVer = wxHTML_ALIGN_BOTTOM; - m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; - m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; - m_UseBkColour = FALSE; - m_UseBorder = FALSE; - m_MinHeight = 0; - m_MinHeightAlign = wxHTML_ALIGN_TOP; - m_LastLayout = -1; -} - -wxHtmlContainerCell::~wxHtmlContainerCell() -{ - wxHtmlCell *cell = m_Cells; - while ( cell ) - { - wxHtmlCell *cellNext = cell->GetNext(); - delete cell; - cell = cellNext; - } -} - - - -void wxHtmlContainerCell::SetIndent(int i, int what, int units) -{ - int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; - if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; - if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; - if (what & wxHTML_INDENT_TOP) m_IndentTop = val; - if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; - m_LastLayout = -1; -} - - - -int wxHtmlContainerCell::GetIndent(int ind) const -{ - if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; - else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; - else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; - else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; - else return -1; /* BUG! Should not be called... */ -} - - - - -int wxHtmlContainerCell::GetIndentUnits(int ind) const -{ - bool p = FALSE; - if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; - else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; - else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; - else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; - if (p) return wxHTML_UNITS_PERCENT; - else return wxHTML_UNITS_PIXELS; -} - - - -bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak) const -{ - if (!m_CanLiveOnPagebreak) - return wxHtmlCell::AdjustPagebreak(pagebreak); - - else - { - wxHtmlCell *c = GetFirstCell(); - bool rt = FALSE; - int pbrk = *pagebreak - m_PosY; - - while (c) - { - if (c->AdjustPagebreak(&pbrk)) - rt = TRUE; - c = c->GetNext(); - } - if (rt) - *pagebreak = pbrk + m_PosY; - return rt; - } -} - - - -void wxHtmlContainerCell::Layout(int w) -{ - wxHtmlCell::Layout(w); - - if (m_LastLayout == w) return; - - // VS: Any attempt to layout with negative or zero width leads to hell, - // but we can't ignore such attempts completely, since it sometimes - // happen (e.g. when trying how small a table can be). The best thing we - // can do is to set the width of child cells to zero - if (w < 1) - { - m_Width = 0; - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - cell->Layout(0); - // this does two things: it recursively calls this code on all - // child contrainers and resets children's position to (0,0) - return; - } - - wxHtmlCell *cell = m_Cells, *line = m_Cells; - long xpos = 0, ypos = m_IndentTop; - int xdelta = 0, ybasicpos = 0, ydiff; - int s_width, s_indent; - int ysizeup = 0, ysizedown = 0; - int MaxLineWidth = 0; - int xcnt = 0; - - - /* - - WIDTH ADJUSTING : - - */ - - if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) - { - if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; - else m_Width = m_WidthFloat * w / 100; - } - else - { - if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; - else m_Width = m_WidthFloat; - } - - if (m_Cells) - { - int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; - int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - cell->Layout(m_Width - (l + r)); - } - - /* - - LAYOUTING : - - */ - - // adjust indentation: - s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; - s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); - - // my own layouting: - while (cell != NULL) - { - switch (m_AlignVer) - { - case wxHTML_ALIGN_TOP : ybasicpos = 0; break; - case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; - case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; - } - ydiff = cell->GetHeight() + ybasicpos; - - if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; - if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); - - cell->SetPos(xpos, ybasicpos + cell->GetDescent()); - xpos += cell->GetWidth(); - cell = cell->GetNext(); - xcnt++; - - // force new line if occured: - if ((cell == NULL) || (xpos + cell->GetWidth() > s_width)) - { - if (xpos > MaxLineWidth) MaxLineWidth = xpos; - if (ysizeup < 0) ysizeup = 0; - if (ysizedown < 0) ysizedown = 0; - switch (m_AlignHor) { - case wxHTML_ALIGN_LEFT : - case wxHTML_ALIGN_JUSTIFY : - xdelta = 0; - break; - case wxHTML_ALIGN_RIGHT : - xdelta = 0 + (s_width - xpos); - break; - case wxHTML_ALIGN_CENTER : - xdelta = 0 + (s_width - xpos) / 2; - break; - } - if (xdelta < 0) xdelta = 0; - xdelta += s_indent; - - ypos += ysizeup; - - if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) - while (line != cell) - { - line->SetPos(line->GetPosX() + xdelta, - ypos + line->GetPosY()); - line = line->GetNext(); - } - else - { - int counter = 0; - int step = (s_width - xpos); - if (step < 0) step = 0; - xcnt--; - if (xcnt > 0) while (line != cell) - { - line->SetPos(line->GetPosX() + s_indent + - (counter++ * step / xcnt), - ypos + line->GetPosY()); - line = line->GetNext(); - } - xcnt++; - } - - ypos += ysizedown; - xpos = xcnt = 0; - ysizeup = ysizedown = 0; - line = cell; - } - } - - // setup height & width, depending on container layout: - m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; - - if (m_Height < m_MinHeight) - { - if (m_MinHeightAlign != wxHTML_ALIGN_TOP) - { - int diff = m_MinHeight - m_Height; - if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; - cell = m_Cells; - while (cell) - { - cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); - cell = cell->GetNext(); - } - } - m_Height = m_MinHeight; - } - - MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); - if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; - - m_LastLayout = w; -} - - -#define mMin(a, b) (((a) < (b)) ? (a) : (b)) -#define mMax(a, b) (((a) < (b)) ? (b) : (a)) - -void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) -{ - // container visible, draw it: - if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) - { - if (m_UseBkColour) - { - wxBrush myb = wxBrush(m_BkColour, wxSOLID); - - int real_y1 = mMax(y + m_PosY, view_y1); - int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); - - dc.SetBrush(myb); - dc.SetPen(*wxTRANSPARENT_PEN); - dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); - } - - if (m_UseBorder) - { - wxPen mypen1(m_BorderColour1, 1, wxSOLID); - wxPen mypen2(m_BorderColour2, 1, wxSOLID); - - dc.SetPen(mypen1); - dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); - dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY); - dc.SetPen(mypen2); - dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); - dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1); - } - - if (m_Cells) - { - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - cell->Draw(dc, x + m_PosX, y + m_PosY, view_y1, view_y2); - } - } - // container invisible, just proceed font+color changing: - else - { - if (m_Cells) - { - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - cell->DrawInvisible(dc, x + m_PosX, y + m_PosY); - } - } -} - - - -void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y) -{ - if (m_Cells) - { - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - cell->DrawInvisible(dc, x + m_PosX, y + m_PosY); - } -} - - -wxColour wxHtmlContainerCell::GetBackgroundColour() -{ - if (m_UseBkColour) - return m_BkColour; - else - return wxNullColour; -} - - - -wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const -{ - wxHtmlCell *cell = FindCellByPos(x, y); - - // VZ: I don't know if we should pass absolute or relative coords to - // wxHtmlCell::GetLink()? As the base class version just ignores them - // anyhow, it hardly matters right now but should still be clarified - return cell ? cell->GetLink(x, y) : NULL; -} - - - -void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) -{ - if (!m_Cells) m_Cells = m_LastCell = f; - else - { - m_LastCell->SetNext(f); - m_LastCell = f; - if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); - } - f->SetParent(this); - m_LastLayout = -1; -} - - - -void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) -{ - if (tag.HasParam(wxT("ALIGN"))) - { - wxString alg = tag.GetParam(wxT("ALIGN")); - alg.MakeUpper(); - if (alg == wxT("CENTER")) - SetAlignHor(wxHTML_ALIGN_CENTER); - else if (alg == wxT("LEFT")) - SetAlignHor(wxHTML_ALIGN_LEFT); - else if (alg == wxT("JUSTIFY")) - SetAlignHor(wxHTML_ALIGN_JUSTIFY); - else if (alg == wxT("RIGHT")) - SetAlignHor(wxHTML_ALIGN_RIGHT); - m_LastLayout = -1; - } -} - - - -void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) -{ - if (tag.HasParam(wxT("WIDTH"))) - { - int wdi; - wxString wd = tag.GetParam(wxT("WIDTH")); - - if (wd[wd.Length()-1] == wxT('%')) - { - wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); - SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); - } - else - { - wxSscanf(wd.c_str(), wxT("%i"), &wdi); - SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); - } - m_LastLayout = -1; - } -} - - - -const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const -{ - if (m_Cells) - { - const wxHtmlCell *r = NULL; - - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - { - r = cell->Find(condition, param); - if (r) return r; - } - } - return NULL; -} - - -wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y) const -{ - for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) - { - int cx = cell->GetPosX(), - cy = cell->GetPosY(); - - if ( (cx <= x) && (cx + cell->GetWidth() > x) && - (cy <= y) && (cy + cell->GetHeight() > y) ) - { - return cell->FindCellByPos(x - cx, y - cy); - } - } - - return NULL; -} - - -void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) -{ - wxHtmlCell *cell = FindCellByPos(x, y); - if ( cell ) - cell->OnMouseClick(parent, x, y, event); -} - - - -void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const -{ - int cleft = m_PosX + m_Width, cright = m_PosX; // worst case - int l, r; - - for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) - { - cell->GetHorizontalConstraints(&l, &r); - if (l < cleft) - cleft = l; - if (r > cright) - cright = r; - } - - cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; - cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; - - if (left) - *left = cleft; - if (right) - *right = cright; -} - - - - - -//-------------------------------------------------------------------------------- -// wxHtmlColourCell -//-------------------------------------------------------------------------------- - -void wxHtmlColourCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) -{ - if (m_Flags & wxHTML_CLR_FOREGROUND) - dc.SetTextForeground(m_Colour); - if (m_Flags & wxHTML_CLR_BACKGROUND) - { - dc.SetBackground(wxBrush(m_Colour, wxSOLID)); - dc.SetTextBackground(m_Colour); - } -} - -void wxHtmlColourCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y)) -{ - if (m_Flags & wxHTML_CLR_FOREGROUND) - dc.SetTextForeground(m_Colour); - if (m_Flags & wxHTML_CLR_BACKGROUND) - { - dc.SetBackground(wxBrush(m_Colour, wxSOLID)); - dc.SetTextBackground(m_Colour); - } -} - - - - -//-------------------------------------------------------------------------------- -// wxHtmlFontCell -//-------------------------------------------------------------------------------- - -void wxHtmlFontCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) -{ - dc.SetFont(m_Font); -} - -void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y)) -{ - dc.SetFont(m_Font); -} - - - - - - - - -//-------------------------------------------------------------------------------- -// wxHtmlWidgetCell -//-------------------------------------------------------------------------------- - -wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) -{ - int sx, sy; - m_Wnd = wnd; - m_Wnd->GetSize(&sx, &sy); - m_Width = sx, m_Height = sy; - m_WidthFloat = w; -} - - -void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) -{ - int absx = 0, absy = 0, stx, sty; - wxHtmlCell *c = this; - - while (c) - { - absx += c->GetPosX(); - absy += c->GetPosY(); - c = c->GetParent(); - } - - ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); - m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); -} - - - -void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) -{ - int absx = 0, absy = 0, stx, sty; - wxHtmlCell *c = this; - - while (c) - { - absx += c->GetPosX(); - absy += c->GetPosY(); - c = c->GetParent(); - } - - ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); - m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); -} - - - -void wxHtmlWidgetCell::Layout(int w) -{ - if (m_WidthFloat != 0) - { - m_Width = (w * m_WidthFloat) / 100; - m_Wnd->SetSize(m_Width, m_Height); - } - - wxHtmlCell::Layout(w); -} - -#endif diff --git a/Contrib/NSIS Menu/src/html/htmlfilt.cpp b/Contrib/NSIS Menu/src/html/htmlfilt.cpp deleted file mode 100644 index 017f2e6e..00000000 --- a/Contrib/NSIS Menu/src/html/htmlfilt.cpp +++ /dev/null @@ -1,229 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: htmlfilt.cpp -// Purpose: wxHtmlFilter - input filter for translating into HTML format -// Author: Vaclav Slavik -// RCS-ID: $Id: htmlfilt.cpp,v 1.16.2.4 2002/11/11 00:15:57 VS Exp $ -// Copyright: (c) 1999 Vaclav Slavik -// Licence: wxWindows Licence -///////////////////////////////////////////////////////////////////////////// - - -#ifdef __GNUG__ -#pragma implementation "htmlfilt.h" -#endif - -#include "wx/wxprec.h" - -#include "wx/defs.h" -#if wxUSE_HTML && wxUSE_STREAMS - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WXPRECOMP - #include "wx/log.h" - #include "wx/intl.h" -#endif - -#include "wx/strconv.h" -#include "wx/html/htmlfilt.h" -#include "wx/html/htmlwin.h" - -// utility function: read a wxString from a wxInputStream -static void ReadString(wxString& str, wxInputStream* s, wxMBConv& conv) -{ - size_t streamSize = s->GetSize(); - - if (streamSize == ~(size_t)0) - { - const size_t bufSize = 4095; - char buffer[bufSize+1]; - size_t lastRead; - - do - { - s->Read(buffer, bufSize); - lastRead = s->LastRead(); - buffer[lastRead] = 0; - str.Append(wxString(buffer, conv)); - } - while (lastRead == bufSize); - } - else - { - char* src = new char[streamSize+1]; - s->Read(src, streamSize); - src[streamSize] = 0; - str = wxString(src, conv); - delete[] src; - } -} - -/* - -There is code for several default filters: - -*/ - -IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter, wxObject) - -//-------------------------------------------------------------------------------- -// wxHtmlFilterPlainText -// filter for text/plain or uknown -//-------------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText, wxHtmlFilter) - -bool wxHtmlFilterPlainText::CanRead(const wxFSFile& WXUNUSED(file)) const -{ - return TRUE; -} - - - -wxString wxHtmlFilterPlainText::ReadFile(const wxFSFile& file) const -{ - wxInputStream *s = file.GetStream(); - wxString doc, doc2; - - if (s == NULL) return wxEmptyString; - ReadString(doc, s, wxConvISO8859_1); - - doc.Replace(wxT("&"), wxT("&"), TRUE); - doc.Replace(wxT("<"), wxT("<"), TRUE); - doc.Replace(wxT(">"), wxT(">"), TRUE); - doc2 = wxT("
\n") + doc + wxT("\n
"); - return doc2; -} - - - - - -//-------------------------------------------------------------------------------- -// wxHtmlFilterImage -// filter for image/* -//-------------------------------------------------------------------------------- - -class wxHtmlFilterImage : public wxHtmlFilter -{ - DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage) - - public: - virtual bool CanRead(const wxFSFile& file) const; - virtual wxString ReadFile(const wxFSFile& file) const; -}; - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage, wxHtmlFilter) - - - -bool wxHtmlFilterImage::CanRead(const wxFSFile& file) const -{ - return (file.GetMimeType().Left(6) == wxT("image/")); -} - - - -wxString wxHtmlFilterImage::ReadFile(const wxFSFile& file) const -{ - wxString res = wxT(""); - return res; -} - - - - -//-------------------------------------------------------------------------------- -// wxHtmlFilterHTML -// filter for text/html -//-------------------------------------------------------------------------------- - - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML, wxHtmlFilter) - -bool wxHtmlFilterHTML::CanRead(const wxFSFile& file) const -{ -// return (file.GetMimeType() == "text/html"); -// This is true in most case but some page can return: -// "text/html; char-encoding=...." -// So we use Find instead - return (file.GetMimeType().Find(wxT("text/html")) == 0); -} - - - -wxString wxHtmlFilterHTML::ReadFile(const wxFSFile& file) const -{ - wxInputStream *s = file.GetStream(); - wxString doc; - - if (s == NULL) - { - wxLogError(_("Cannot open HTML document: %s"), file.GetLocation().c_str()); - return wxEmptyString; - } - - // NB: We convert input file to wchar_t here in Unicode mode, based on - // either Content-Type header or tags. In ANSI mode, we don't - // do it as it is done by wxHtmlParser (for this reason, we add - // tag if we used Content-Type header). -#if wxUSE_UNICODE - int charsetPos; - if ((charsetPos = file.GetMimeType().Find(_T("; charset="))) != wxNOT_FOUND) - { - wxString charset = file.GetMimeType().Mid(charsetPos + 10); - wxCSConv conv(charset); - ReadString(doc, s, conv); - } - else - { - wxString tmpdoc; - ReadString(tmpdoc, s, wxConvISO8859_1); - wxString charset = wxHtmlParser::ExtractCharsetInformation(tmpdoc); - if (charset.empty()) - doc = tmpdoc; - else - { - wxCSConv conv(charset); - doc = wxString(tmpdoc.mb_str(wxConvISO8859_1), conv); - } - } -#else // !wxUSE_UNICODE - ReadString(doc, s, wxConvLibc); - // add meta tag if we obtained this through http: - if (!file.GetMimeType().empty()) - { - wxString hdr; - wxString mime = file.GetMimeType(); - hdr.Printf(_T(""), mime.c_str()); - return hdr+doc; - } -#endif - - return doc; -} - - - - -///// Module: - -class wxHtmlFilterModule : public wxModule -{ - DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule) - - public: - virtual bool OnInit() - { - wxHtmlWindow::AddFilter(new wxHtmlFilterHTML); - wxHtmlWindow::AddFilter(new wxHtmlFilterImage); - return TRUE; - } - virtual void OnExit() {} -}; - -IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule, wxModule) - -#endif diff --git a/Contrib/NSIS Menu/src/html/htmlpars.cpp b/Contrib/NSIS Menu/src/html/htmlpars.cpp deleted file mode 100644 index 2d6ee511..00000000 --- a/Contrib/NSIS Menu/src/html/htmlpars.cpp +++ /dev/null @@ -1,888 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: htmlpars.cpp -// Purpose: wxHtmlParser class (generic parser) -// Author: Vaclav Slavik -// RCS-ID: $Id: htmlpars.cpp,v 1.28.2.5 2002/11/10 00:05:39 VS Exp $ -// Copyright: (c) 1999 Vaclav Slavik -// Licence: wxWindows Licence -///////////////////////////////////////////////////////////////////////////// - - -#ifdef __GNUG__ -#pragma implementation "htmlpars.h" -#endif - -#include "wx/wxprec.h" - -#include "wx/defs.h" -#if wxUSE_HTML && wxUSE_STREAMS - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WXPRECOMP - #include "wx/log.h" - #include "wx/intl.h" -#endif - -#include "wx/tokenzr.h" -#include "wx/wfstream.h" -#include "wx/url.h" -#include "wx/fontmap.h" -#include "wx/html/htmldefs.h" -#include "wx/html/htmlpars.h" -#include "wx/dynarray.h" -#include "wx/arrimpl.cpp" - -//----------------------------------------------------------------------------- -// wxHtmlParser helpers -//----------------------------------------------------------------------------- - -class wxHtmlTextPiece -{ -public: - wxHtmlTextPiece(int pos, int lng) : m_pos(pos), m_lng(lng) {} - int m_pos, m_lng; -}; - -WX_DECLARE_OBJARRAY(wxHtmlTextPiece, wxHtmlTextPieces); -WX_DEFINE_OBJARRAY(wxHtmlTextPieces); - -class wxHtmlParserState -{ -public: - wxHtmlTag *m_curTag; - wxHtmlTag *m_tags; - wxHtmlTextPieces *m_textPieces; - int m_curTextPiece; - wxString m_source; - wxHtmlParserState *m_nextState; -}; - -//----------------------------------------------------------------------------- -// wxHtmlParser -//----------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject) - -wxHtmlParser::wxHtmlParser() - : wxObject(), m_HandlersHash(wxKEY_STRING), - m_FS(NULL), m_HandlersStack(NULL) -{ - m_entitiesParser = new wxHtmlEntitiesParser; - m_Tags = NULL; - m_CurTag = NULL; - m_TextPieces = NULL; - m_CurTextPiece = 0; - m_SavedStates = NULL; -} - -wxHtmlParser::~wxHtmlParser() -{ - while (RestoreState()) {} - DestroyDOMTree(); - - delete m_HandlersStack; - m_HandlersHash.Clear(); - m_HandlersList.DeleteContents(TRUE); - m_HandlersList.Clear(); - delete m_entitiesParser; -} - -wxObject* wxHtmlParser::Parse(const wxString& source) -{ - InitParser(source); - DoParsing(); - wxObject *result = GetProduct(); - DoneParser(); - return result; -} - -void wxHtmlParser::InitParser(const wxString& source) -{ - SetSource(source); - m_stopParsing = FALSE; -} - -void wxHtmlParser::DoneParser() -{ - DestroyDOMTree(); -} - -void wxHtmlParser::SetSource(const wxString& src) -{ - DestroyDOMTree(); - m_Source = src; - CreateDOMTree(); - m_CurTag = NULL; - m_CurTextPiece = 0; -} - -void wxHtmlParser::CreateDOMTree() -{ - wxHtmlTagsCache cache(m_Source); - m_TextPieces = new wxHtmlTextPieces; - CreateDOMSubTree(NULL, 0, m_Source.Length(), &cache); - m_CurTextPiece = 0; -} - -void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur, - int begin_pos, int end_pos, - wxHtmlTagsCache *cache) -{ - if (end_pos <= begin_pos) return; - - wxChar c; - int i = begin_pos; - int textBeginning = begin_pos; - - while (i < end_pos) - { - c = m_Source.GetChar(i); - - if (c == wxT('<')) - { - // add text to m_TextPieces: - if (i - textBeginning > 0) - m_TextPieces->Add( - wxHtmlTextPiece(textBeginning, i - textBeginning)); - - // if it is a comment, skip it: - if (i < end_pos-6 && m_Source.GetChar(i+1) == wxT('!') && - m_Source.GetChar(i+2) == wxT('-') && - m_Source.GetChar(i+3) == wxT('-')) - { - // Comments begin with "