more wxHTML Unicode fixes (removed wxPrivate_ReadString), wxSearchEngine-->wxHtmlSearchEngine

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17818 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2002-11-11 00:01:23 +00:00
parent 5a96f6be9c
commit 9cb9c214f6
3 changed files with 27 additions and 32 deletions

View File

@@ -93,23 +93,23 @@ struct wxHtmlContentsItem
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// wxSearchEngine // wxHtmlSearchEngine
// This class takes input streams and scans them for occurence // This class takes input streams and scans them for occurence
// of keyword(s) // of keyword(s)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
class WXDLLEXPORT wxSearchEngine : public wxObject class WXDLLEXPORT wxHtmlSearchEngine : public wxObject
{ {
public: public:
wxSearchEngine() : wxObject() {m_Keyword = NULL; } wxHtmlSearchEngine() : wxObject() {m_Keyword = NULL; }
~wxSearchEngine() {if (m_Keyword) delete[] m_Keyword; } ~wxHtmlSearchEngine() {if (m_Keyword) delete[] m_Keyword; }
// Sets the keyword we will be searching for // Sets the keyword we will be searching for
virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only); virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
// Scans the stream for the keyword. // Scans the stream for the keyword.
// Returns TRUE if the stream contains keyword, fALSE otherwise // Returns TRUE if the stream contains keyword, fALSE otherwise
virtual bool Scan(wxInputStream *stream); virtual bool Scan(const wxFSFile& file);
private: private:
wxChar *m_Keyword; wxChar *m_Keyword;
@@ -139,7 +139,7 @@ public:
private: private:
wxHtmlHelpData* m_Data; wxHtmlHelpData* m_Data;
wxSearchEngine m_Engine; wxHtmlSearchEngine m_Engine;
wxString m_Keyword, m_Name; wxString m_Keyword, m_Name;
wxChar *m_LastPage; wxChar *m_LastPage;
wxHtmlContentsItem* m_ContentsItem; wxHtmlContentsItem* m_ContentsItem;

View File

@@ -40,6 +40,7 @@
#include "wx/log.h" #include "wx/log.h"
#include "wx/html/htmlpars.h" #include "wx/html/htmlpars.h"
#include "wx/html/htmldefs.h" #include "wx/html/htmldefs.h"
#include "wx/html/htmlfilt.h"
#include "wx/filename.h" #include "wx/filename.h"
#include "wx/arrimpl.cpp" #include "wx/arrimpl.cpp"
@@ -250,12 +251,10 @@ wxHtmlHelpData::~wxHtmlHelpData()
} }
} }
// defined in htmlfilt.cpp
void wxPrivate_ReadString(wxString& str, wxInputStream* s, wxMBConv& conv);
bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile) bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile)
{ {
wxFSFile *f; wxFSFile *f;
wxHtmlFilterHTML filter;
wxString buf; wxString buf;
wxString string; wxString string;
@@ -267,27 +266,31 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c
if (f) if (f)
{ {
buf.clear(); buf.clear();
wxPrivate_ReadString(buf, f->GetStream(), wxConvLibc /*FIXME?*/); buf = filter.ReadFile(*f);
delete f; delete f;
handler->ReadIn(m_Contents, m_ContentsCnt); handler->ReadIn(m_Contents, m_ContentsCnt);
parser.Parse(buf); parser.Parse(buf);
handler->WriteOut(m_Contents, m_ContentsCnt); handler->WriteOut(m_Contents, m_ContentsCnt);
} }
else else
{
wxLogError(_("Cannot open contents file: %s"), contentsfile.c_str()); wxLogError(_("Cannot open contents file: %s"), contentsfile.c_str());
}
f = ( indexfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) ); f = ( indexfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) );
if (f) if (f)
{ {
buf.clear(); buf.clear();
wxPrivate_ReadString(buf, f->GetStream(), wxConvLibc /*FIXME?*/); buf = filter.ReadFile(*f);
delete f; delete f;
handler->ReadIn(m_Index, m_IndexCnt); handler->ReadIn(m_Index, m_IndexCnt);
parser.Parse(buf); parser.Parse(buf);
handler->WriteOut(m_Index, m_IndexCnt); handler->WriteOut(m_Index, m_IndexCnt);
} }
else if (!indexfile.IsEmpty()) else if (!indexfile.IsEmpty())
{
wxLogError(_("Cannot open index file: %s"), indexfile.c_str()); wxLogError(_("Cannot open index file: %s"), indexfile.c_str());
}
return TRUE; return TRUE;
} }
@@ -567,7 +570,6 @@ bool wxHtmlHelpData::AddBook(const wxString& book)
{ {
wxFSFile *fi; wxFSFile *fi;
wxFileSystem fsys; wxFileSystem fsys;
wxInputStream *s;
wxString bookFull; wxString bookFull;
wxString title = _("noname"), wxString title = _("noname"),
@@ -594,13 +596,12 @@ bool wxHtmlHelpData::AddBook(const wxString& book)
return FALSE; return FALSE;
} }
fsys.ChangePathTo(bookFull); fsys.ChangePathTo(bookFull);
s = fi->GetStream();
const wxChar *lineptr; const wxChar *lineptr;
wxChar linebuf[300]; wxChar linebuf[300];
wxString tmp; wxString tmp;
wxHtmlFilterPlainText filter;
wxPrivate_ReadString(tmp, s, wxConvLibc /*FIXME?*/); tmp = filter.ReadFile(*fi);
lineptr = tmp.c_str(); lineptr = tmp.c_str();
do do
@@ -785,7 +786,7 @@ bool wxHtmlSearchStatus::Search()
file = fsys.OpenFile(m_Data->m_Contents[i].m_Book->GetFullPath(thepage)); file = fsys.OpenFile(m_Data->m_Contents[i].m_Book->GetFullPath(thepage));
if (file) if (file)
{ {
if (m_Engine.Scan(file->GetStream())) if (m_Engine.Scan(*file))
{ {
m_Name = m_Data->m_Contents[i].m_Name; m_Name = m_Data->m_Contents[i].m_Name;
m_ContentsItem = m_Data->m_Contents + i; m_ContentsItem = m_Data->m_Contents + i;
@@ -804,10 +805,10 @@ bool wxHtmlSearchStatus::Search()
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// wxSearchEngine // wxHtmlSearchEngine
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
void wxSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only) void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only)
{ {
m_CaseSensitive = case_sensitive; m_CaseSensitive = case_sensitive;
m_WholeWords = whole_words_only; m_WholeWords = whole_words_only;
@@ -831,16 +832,15 @@ static inline bool WHITESPACE(wxChar c)
return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t'); return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t');
} }
bool wxSearchEngine::Scan(wxInputStream *stream) bool wxHtmlSearchEngine::Scan(const wxFSFile& file)
{ {
wxASSERT_MSG(m_Keyword != NULL, wxT("wxSearchEngine::LookFor must be called before scanning!")); wxASSERT_MSG(m_Keyword != NULL, wxT("wxHtmlSearchEngine::LookFor must be called before scanning!"));
int i, j; int i, j;
int wrd = wxStrlen(m_Keyword); int wrd = wxStrlen(m_Keyword);
bool found = FALSE; bool found = FALSE;
wxString tmp; wxHtmlFilterHTML filter;
wxPrivate_ReadString(tmp, stream, wxConvLibc); wxString tmp = filter.ReadFile(file);
// FIXME - use wxHtmlFilters instead of wxPrivate_ReadString !!!!!!
int lng = tmp.length(); int lng = tmp.length();
const wxChar *buf = tmp.c_str(); const wxChar *buf = tmp.c_str();

View File

@@ -269,9 +269,6 @@ void wxHtmlPrintout::SetHtmlText(const wxString& html, const wxString &basepath,
m_BasePathIsDir = isdir; m_BasePathIsDir = isdir;
} }
// defined in htmlfilt.cpp
void wxPrivate_ReadString(wxString& str, wxInputStream* s, wxMBConv& conv);
void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile) void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile)
{ {
wxFileSystem fs; wxFileSystem fs;
@@ -283,13 +280,11 @@ void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile)
return; return;
} }
wxInputStream *st = ff->GetStream(); wxHtmlFilterHTML filter;
wxString doc; wxString doc = filter.ReadFile(*ff);
wxPrivate_ReadString(doc, st, wxConvLibc /*FIXME -- use wxHtmlFilter!!*/);
delete ff;
SetHtmlText(doc, htmlfile, FALSE); SetHtmlText(doc, htmlfile, FALSE);
delete ff;
} }