*** empty log message ***
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2963 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
294
src/common/filesys.cpp
Normal file
294
src/common/filesys.cpp
Normal file
@@ -0,0 +1,294 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: filesys.cpp
|
||||
// Purpose: wxFileSystem class - interface for opening files
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/url.h>
|
||||
#include <wx/module.h>
|
||||
#include <wx/filesys.h>
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxFileSystemHandler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject)
|
||||
|
||||
wxMimeTypesManager wxFileSystemHandler::m_MimeMng;
|
||||
|
||||
|
||||
wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
|
||||
{
|
||||
wxString ext = wxEmptyString, mime = wxEmptyString;
|
||||
wxString loc = GetRightLocation(location);
|
||||
char c;
|
||||
int l = loc.Length(), l2;
|
||||
wxFileType *ft;
|
||||
|
||||
l2 = l;
|
||||
for (int i = l-1; i >= 0; i--) {
|
||||
c = loc[i];
|
||||
if (c == '#') l2 = i + 1;
|
||||
if (c == '.') {ext = loc.Right(l2-i-1); break;}
|
||||
if ((c == '/') || (c == '\\') || (c == ':')) {return wxEmptyString;}
|
||||
}
|
||||
ft = m_MimeMng.GetFileTypeFromExtension(ext);
|
||||
if (ft && (ft -> GetMimeType(&mime))) return mime;
|
||||
else return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxFileSystemHandler::GetProtocol(const wxString& location) const
|
||||
{
|
||||
wxString s = wxEmptyString;
|
||||
int i, l = location.Length();
|
||||
bool fnd;
|
||||
|
||||
fnd = FALSE;
|
||||
for (i = l-1; (i >= 0) && ((location[i] != '#') || (!fnd)); i--) {
|
||||
if ((location[i] == ':') && (i != 1 /*win: C:\path*/)) fnd = TRUE;
|
||||
}
|
||||
if (!fnd) return "file";
|
||||
for (++i; (i < l) && (location[i] != ':'); i++) s << location[i];
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const
|
||||
{
|
||||
int i;
|
||||
bool fnd;
|
||||
|
||||
fnd = FALSE;
|
||||
for (i = location.Length()-1; i >= 0; i--) {
|
||||
if ((location[i] == ':') && (i != 1 /*win: C:\path*/)) fnd = TRUE;
|
||||
else if (fnd && (location[i] == '#')) return location.Left(i);
|
||||
}
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxFileSystemHandler::GetRightLocation(const wxString& location) const
|
||||
{
|
||||
int i, l = location.Length();
|
||||
int l2 = l + 1;
|
||||
for (i = l-1; (i >= 0) && ((location[i] != ':') || (i == 1) || (location[i-2] == ':')); i--) {if (location[i] == '#') l2 = i + 1;}
|
||||
if (i == 0) return wxEmptyString;
|
||||
else return location.Mid(i + 1, l2 - i - 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxFileSystemHandler::GetAnchor(const wxString& location) const
|
||||
{
|
||||
char c;
|
||||
int l = location.Length();
|
||||
|
||||
for (int i = l-1; i >= 0; i--) {
|
||||
c = location[i];
|
||||
if (c == '#') return location.Right(l-i-1);
|
||||
else if ((c == '.') || (c == '/') || (c == '\\') || (c == ':')) return wxEmptyString;
|
||||
}
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxLocalFSHandler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
class wxLocalFSHandler : public wxFileSystemHandler
|
||||
{
|
||||
public:
|
||||
virtual bool CanOpen(const wxString& location);
|
||||
virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool wxLocalFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
return GetProtocol(location) == "file";
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
|
||||
{
|
||||
wxString right = GetRightLocation(location);
|
||||
if (wxFileExists(right))
|
||||
return new wxFSFile(new wxFileInputStream(right),
|
||||
right,
|
||||
GetMimeTypeFromExt(location),
|
||||
GetAnchor(location));
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxFileSystem
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileSystem, wxObject)
|
||||
|
||||
|
||||
wxList wxFileSystem::m_Handlers;
|
||||
|
||||
|
||||
|
||||
void wxFileSystem::ChangePathTo(const wxString& location, bool is_dir)
|
||||
{
|
||||
int i, pathpos = -1;
|
||||
m_Path = location;
|
||||
|
||||
for (i = m_Path.Length()-1; i >= 0; i--)
|
||||
if (m_Path[i] == '\\') m_Path.GetWritableChar(i) = '/'; // wanna be windows-safe
|
||||
|
||||
if (is_dir == FALSE) {
|
||||
for (i = m_Path.Length()-1; i >= 0; i--) {
|
||||
if (m_Path[i] == '/') {
|
||||
if ((i > 1) && (m_Path[i-1] == '/') && (m_Path[i-2] == ':')) {
|
||||
i -= 2;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
pathpos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_Path[i] == ':') {
|
||||
pathpos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pathpos == -1) {
|
||||
for (i = 0; i < (int) m_Path.Length(); i++) {
|
||||
if (m_Path[i] == ':') {
|
||||
//m_Path << '/';
|
||||
m_Path.Remove(i+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == (int) m_Path.Length()) m_Path = wxEmptyString;
|
||||
}
|
||||
else {
|
||||
if (m_Path[m_Path.Length()-1] != '/') m_Path << '/';
|
||||
m_Path.Remove(pathpos+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxFSFile* wxFileSystem::OpenFile(const wxString& location)
|
||||
{
|
||||
wxString loc = location;
|
||||
int i, ln;
|
||||
char meta;
|
||||
wxFSFile *s = NULL;
|
||||
wxNode *node;
|
||||
|
||||
ln = loc.Length();
|
||||
meta = 0;
|
||||
for (i = 0; i < ln; i++) {
|
||||
if (loc[i] == '\\') loc.GetWritableChar(i) = '/'; // wanna be windows-safe
|
||||
if (!meta) switch (loc[i]) {
|
||||
case '/' : case ':' : case '#' : meta = loc[i];
|
||||
}
|
||||
}
|
||||
m_LastName = wxEmptyString;
|
||||
|
||||
// try relative paths first :
|
||||
if (meta != ':') {
|
||||
node = m_Handlers.GetFirst();
|
||||
while (node){
|
||||
wxFileSystemHandler *h = (wxFileSystemHandler*) node -> GetData();
|
||||
if (h -> CanOpen(m_Path + location)) {
|
||||
s = h -> OpenFile(*this, m_Path + location);
|
||||
if (s) {m_LastName = m_Path + location; break;}
|
||||
}
|
||||
node = node -> GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
// if failed, try absolute paths :
|
||||
if (s == NULL) {
|
||||
node = m_Handlers.GetFirst();
|
||||
while (node){
|
||||
wxFileSystemHandler *h = (wxFileSystemHandler*) node -> GetData();
|
||||
if (h -> CanOpen(location)) {
|
||||
s = h -> OpenFile(*this, location);
|
||||
if (s) {m_LastName = location; break; }
|
||||
}
|
||||
node = node -> GetNext();
|
||||
}
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxFileSystem::AddHandler(wxFileSystemHandler *handler)
|
||||
{
|
||||
m_Handlers.Append(handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///// Module:
|
||||
|
||||
class wxFileSystemModule : public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxFileSystemModule)
|
||||
|
||||
public:
|
||||
virtual bool OnInit()
|
||||
{
|
||||
wxFileSystem::AddHandler(new wxLocalFSHandler);
|
||||
return TRUE;
|
||||
}
|
||||
virtual void OnExit() {}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileSystemModule, wxModule)
|
||||
|
||||
|
||||
|
||||
|
130
src/common/fs_inet.cpp
Normal file
130
src/common/fs_inet.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: fs_inet.cpp
|
||||
// Purpose: HTTP and FTP file system
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
|
||||
REMARKS :
|
||||
|
||||
This FS creates local cache (in /tmp directory). The cache is freed
|
||||
on program exit.
|
||||
|
||||
Size of cache is limited to cca 1000 items (due to GetTempFileName
|
||||
limitation)
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/url.h"
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/fs_inet.h"
|
||||
|
||||
class wxInetCacheNode : public wxObject
|
||||
{
|
||||
private:
|
||||
wxString m_Temp;
|
||||
wxString m_Mime;
|
||||
|
||||
public:
|
||||
wxInetCacheNode(const wxString& l, const wxString& m) : wxObject() {m_Temp = l; m_Mime = m;}
|
||||
const wxString& GetTemp() const {return m_Temp;}
|
||||
const wxString& GetMime() const {return m_Mime;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxInternetFSHandler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool wxInternetFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
wxString p = GetProtocol(location);
|
||||
return (p == "http") || (p == "ftp");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
|
||||
{
|
||||
wxString right = GetProtocol(location) + ":" + GetRightLocation(location);
|
||||
wxInputStream *s;
|
||||
wxString content;
|
||||
wxInetCacheNode *info;
|
||||
|
||||
info = (wxInetCacheNode*) m_Cache.Get(right);
|
||||
|
||||
// Add item into cache:
|
||||
if (info == NULL) {
|
||||
wxURL url(right);
|
||||
s = url.GetInputStream();
|
||||
content = url.GetProtocol().GetContentType();
|
||||
if (content == wxEmptyString) content = GetMimeTypeFromExt(location);
|
||||
if (s) {
|
||||
char buf[256];
|
||||
|
||||
wxGetTempFileName("wxhtml", buf);
|
||||
info = new wxInetCacheNode(buf, content);
|
||||
m_Cache.Put(right, info);
|
||||
|
||||
{ // ok, now copy it:
|
||||
wxFileOutputStream sout(buf);
|
||||
s -> Read(sout); // copy the stream
|
||||
}
|
||||
delete s;
|
||||
}
|
||||
else return NULL; //we can't open the URL
|
||||
}
|
||||
|
||||
// Load item from cache:
|
||||
s = new wxFileInputStream(info -> GetTemp());
|
||||
if (s) {
|
||||
return new wxFSFile(s,
|
||||
right,
|
||||
info -> GetMime(),
|
||||
GetAnchor(location));
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxInternetFSHandler::~wxInternetFSHandler()
|
||||
{
|
||||
wxNode *n;
|
||||
wxInetCacheNode *n2;
|
||||
|
||||
m_Cache.BeginFind();
|
||||
while ((n = m_Cache.Next()) != NULL) {
|
||||
n2 = (wxInetCacheNode*) n -> GetData();
|
||||
wxRemoveFile(n2 -> GetTemp());
|
||||
delete n2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
75
src/common/fs_zip.cpp
Normal file
75
src/common/fs_zip.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: fs_zip.cpp
|
||||
// Purpose: ZIP file system
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/zipstream.h"
|
||||
#include "wx/fs_zip.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxZipFSHandler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
bool wxZipFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
wxString p = GetProtocol(location);
|
||||
return (p == "zip");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
|
||||
{
|
||||
wxString right = GetRightLocation(location);
|
||||
wxString left = GetLeftLocation(location);
|
||||
wxInputStream *s;
|
||||
|
||||
if (GetProtocol(left) != "file") {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = new wxZipInputStream(left, right);
|
||||
if (s && (s -> LastError() == wxStream_NOERROR)) {
|
||||
return new wxFSFile(s,
|
||||
left + "#zip:" + right,
|
||||
GetMimeTypeFromExt(location),
|
||||
GetAnchor(location));
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxZipFSHandler::~wxZipFSHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
1294
src/common/unzip.c
Normal file
1294
src/common/unzip.c
Normal file
File diff suppressed because it is too large
Load Diff
275
src/common/unzip.h
Normal file
275
src/common/unzip.h
Normal file
@@ -0,0 +1,275 @@
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 0.15 beta, Mar 19th, 1998,
|
||||
|
||||
Copyright (C) 1998 Gilles Vollant
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Encryption and multi volume ZipFile (span) are not supported.
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
|
||||
CAN CHANGE IN FUTURE VERSION !!
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
/* for more info about .ZIP format, see
|
||||
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip */
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
|
||||
"zlib/zlib111.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
110
src/common/zipstream.cpp
Normal file
110
src/common/zipstream.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: zipstream.cpp
|
||||
// Purpose: input stream for ZIP archive access
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/stream.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/zipstream.h>
|
||||
#include "unzip.h"
|
||||
|
||||
|
||||
|
||||
|
||||
wxZipInputStream::wxZipInputStream(const wxString& archive, const wxString& file) : wxInputStream()
|
||||
{
|
||||
unz_file_info zinfo;
|
||||
|
||||
m_Pos = 0;
|
||||
m_Size = 0;
|
||||
m_Archive = (void*) unzOpen(archive);
|
||||
if (m_Archive == NULL) {
|
||||
m_lasterror = wxStream_READ_ERR;
|
||||
return;
|
||||
}
|
||||
if (unzLocateFile((unzFile)m_Archive, file, 0) != UNZ_OK) {
|
||||
m_lasterror = wxStream_READ_ERR;
|
||||
return;
|
||||
}
|
||||
unzGetCurrentFileInfo((unzFile)m_Archive, &zinfo, NULL, 0, NULL, 0, NULL, 0);
|
||||
|
||||
if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK) {
|
||||
m_lasterror = wxStream_READ_ERR;
|
||||
return;
|
||||
}
|
||||
m_Size = zinfo.uncompressed_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxZipInputStream::~wxZipInputStream()
|
||||
{
|
||||
if (m_Archive) {
|
||||
if (m_Size != 0)
|
||||
unzCloseCurrentFile((unzFile)m_Archive);
|
||||
unzClose((unzFile)m_Archive);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize)
|
||||
{
|
||||
if (m_Pos + bufsize > m_Size) bufsize = m_Size - m_Pos;
|
||||
unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize);
|
||||
m_Pos += bufsize;
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
|
||||
{
|
||||
off_t nextpos;
|
||||
void *buf;
|
||||
|
||||
switch (mode) {
|
||||
case wxFromCurrent : nextpos = seek + m_Pos; break;
|
||||
case wxFromStart : nextpos = seek; break;
|
||||
case wxFromEnd : nextpos = m_Size - 1 + seek; break;
|
||||
default : nextpos = m_Pos; break; /* just to fool compiler, never happens */
|
||||
}
|
||||
|
||||
// cheated seeking :
|
||||
if (nextpos > m_Pos) {
|
||||
buf = malloc(nextpos - m_Pos);
|
||||
unzReadCurrentFile((unzFile)m_Archive, buf, nextpos - m_Pos);
|
||||
free(buf);
|
||||
}
|
||||
else if (nextpos < m_Pos) {
|
||||
unzCloseCurrentFile((unzFile)m_Archive);
|
||||
if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK) {
|
||||
m_lasterror = wxStream_READ_ERR;
|
||||
return m_Pos;
|
||||
}
|
||||
buf = malloc(nextpos);
|
||||
unzReadCurrentFile((unzFile)m_Archive, buf, nextpos);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
m_Pos = nextpos;
|
||||
return m_Pos;
|
||||
}
|
||||
|
69
src/generic/busyinfo.cpp
Normal file
69
src/generic/busyinfo.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: busyinfo.cpp
|
||||
// Purpose: Information window when app is busy
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include "wx/busyinfo.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
wxInfoFrame::wxInfoFrame(wxWindow *parent, const wxString& message)
|
||||
: wxFrame(parent, -1, "", wxPoint(0, 0), wxSize(400, 80), wxTHICK_FRAME | wxSIMPLE_BORDER | wxFRAME_TOOL_WINDOW)
|
||||
{
|
||||
wxPanel *p = new wxPanel(this);
|
||||
wxStaticText *s = new wxStaticText(p, -1, message, wxPoint(20, 20), wxSize(360, 40), wxALIGN_CENTER);
|
||||
Centre(wxBOTH);
|
||||
p -> SetCursor(*wxHOURGLASS_CURSOR);
|
||||
s -> SetCursor(*wxHOURGLASS_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wxBusyInfo::wxBusyInfo(const wxString& message) : wxObject()
|
||||
{
|
||||
m_InfoFrame = new wxInfoFrame(NULL, message);
|
||||
m_InfoFrame -> Show(TRUE);
|
||||
wxYield();
|
||||
m_InfoFrame -> Refresh();
|
||||
wxYield();
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxBusyInfo::~wxBusyInfo()
|
||||
{
|
||||
m_InfoFrame -> Show(FALSE);
|
||||
m_InfoFrame -> Close();
|
||||
wxYield();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -12,7 +12,7 @@ SUFFIXES = .cpp .c
|
||||
DEFS = $(TOOLKIT_DEF) $(WXDEBUG_DEFINE)
|
||||
LIBS = $(GUILIBS)
|
||||
|
||||
VPATH = .:${srcdir}:${srcdir}/../common:${srcdir}/../generic:${EXTRA_VPATH}
|
||||
VPATH = .:${srcdir}:${srcdir}/../common:${srcdir}/../generic:${srcdir}/../html:${EXTRA_VPATH}
|
||||
|
||||
lib_LTLIBRARIES = @WX_LIBRARY_NAME@
|
||||
EXTRA_LTLIBRARIES = libwx_gtk.la libwx_motif.la libwx_msw.la
|
||||
@@ -44,7 +44,10 @@ libwx_gtk_la_SOURCES = \
|
||||
file.cpp \
|
||||
fileconf.cpp \
|
||||
filefn.cpp \
|
||||
filesys.cpp \
|
||||
framecmn.cpp \
|
||||
fs_inet.cpp \
|
||||
fs_zip.cpp \
|
||||
ftp.cpp \
|
||||
gdicmn.cpp \
|
||||
hash.cpp \
|
||||
@@ -90,6 +93,7 @@ libwx_gtk_la_SOURCES = \
|
||||
time.cpp \
|
||||
timercmn.cpp \
|
||||
tokenzr.cpp \
|
||||
unzip.c \
|
||||
url.cpp \
|
||||
utilscmn.cpp \
|
||||
valgen.cpp \
|
||||
@@ -101,10 +105,12 @@ libwx_gtk_la_SOURCES = \
|
||||
wxchar.cpp \
|
||||
wxexpr.cpp \
|
||||
zstream.cpp \
|
||||
zipstream.cpp \
|
||||
\
|
||||
db.cpp \
|
||||
dbtable.cpp \
|
||||
\
|
||||
busyinfo.cpp \
|
||||
caret.cpp \
|
||||
colrdlgg.cpp \
|
||||
dcpsg.cpp \
|
||||
@@ -192,7 +198,26 @@ libwx_gtk_la_SOURCES = \
|
||||
utilsgtk.cpp \
|
||||
utilsres.cpp \
|
||||
wave.cpp \
|
||||
window.cpp
|
||||
window.cpp \
|
||||
\
|
||||
htmlcell.cpp \
|
||||
htmlfilter.cpp \
|
||||
htmlhelp.cpp \
|
||||
htmlhelp_io.cpp \
|
||||
htmlparser.cpp \
|
||||
htmltag.cpp \
|
||||
htmlwin.cpp \
|
||||
htmlwinparser.cpp \
|
||||
mod_fonts.cpp \
|
||||
mod_hline.cpp \
|
||||
mod_image.cpp \
|
||||
mod_layout.cpp \
|
||||
mod_links.cpp \
|
||||
mod_list.cpp \
|
||||
mod_pre.cpp \
|
||||
mod_tables.cpp \
|
||||
search.cpp
|
||||
|
||||
|
||||
# these are the sources which we build by our own rules
|
||||
#
|
||||
|
@@ -12,7 +12,7 @@ SUFFIXES = .cpp .c
|
||||
DEFS = $(TOOLKIT_DEF) $(WXDEBUG_DEFINE)
|
||||
LIBS = $(GUILIBS)
|
||||
|
||||
VPATH = .:${srcdir}:${srcdir}/../common:${srcdir}/../generic:${EXTRA_VPATH}
|
||||
VPATH = .:${srcdir}:${srcdir}/../common:${srcdir}/../generic:${srcdir}/../html:${EXTRA_VPATH}
|
||||
|
||||
lib_LTLIBRARIES = @WX_LIBRARY_NAME@
|
||||
EXTRA_LTLIBRARIES = libwx_gtk.la libwx_motif.la libwx_msw.la
|
||||
@@ -44,7 +44,10 @@ libwx_gtk_la_SOURCES = \
|
||||
file.cpp \
|
||||
fileconf.cpp \
|
||||
filefn.cpp \
|
||||
filesys.cpp \
|
||||
framecmn.cpp \
|
||||
fs_inet.cpp \
|
||||
fs_zip.cpp \
|
||||
ftp.cpp \
|
||||
gdicmn.cpp \
|
||||
hash.cpp \
|
||||
@@ -90,6 +93,7 @@ libwx_gtk_la_SOURCES = \
|
||||
time.cpp \
|
||||
timercmn.cpp \
|
||||
tokenzr.cpp \
|
||||
unzip.c \
|
||||
url.cpp \
|
||||
utilscmn.cpp \
|
||||
valgen.cpp \
|
||||
@@ -101,10 +105,12 @@ libwx_gtk_la_SOURCES = \
|
||||
wxchar.cpp \
|
||||
wxexpr.cpp \
|
||||
zstream.cpp \
|
||||
zipstream.cpp \
|
||||
\
|
||||
db.cpp \
|
||||
dbtable.cpp \
|
||||
\
|
||||
busyinfo.cpp \
|
||||
caret.cpp \
|
||||
colrdlgg.cpp \
|
||||
dcpsg.cpp \
|
||||
@@ -192,7 +198,26 @@ libwx_gtk_la_SOURCES = \
|
||||
utilsgtk.cpp \
|
||||
utilsres.cpp \
|
||||
wave.cpp \
|
||||
window.cpp
|
||||
window.cpp \
|
||||
\
|
||||
htmlcell.cpp \
|
||||
htmlfilter.cpp \
|
||||
htmlhelp.cpp \
|
||||
htmlhelp_io.cpp \
|
||||
htmlparser.cpp \
|
||||
htmltag.cpp \
|
||||
htmlwin.cpp \
|
||||
htmlwinparser.cpp \
|
||||
mod_fonts.cpp \
|
||||
mod_hline.cpp \
|
||||
mod_image.cpp \
|
||||
mod_layout.cpp \
|
||||
mod_links.cpp \
|
||||
mod_list.cpp \
|
||||
mod_pre.cpp \
|
||||
mod_tables.cpp \
|
||||
search.cpp
|
||||
|
||||
|
||||
# these are the sources which we build by our own rules
|
||||
#
|
||||
|
24
src/html/bitmaps/back.xpm
Normal file
24
src/html/bitmaps/back.xpm
Normal file
@@ -0,0 +1,24 @@
|
||||
/* XPM */
|
||||
static char * back_xpm[] = {
|
||||
"16 16 5 1",
|
||||
" c None",
|
||||
". c #000000",
|
||||
"+ c #C0E4CB",
|
||||
"@ c #77C490",
|
||||
"# c #808080",
|
||||
" ",
|
||||
" ",
|
||||
" . ",
|
||||
" .. ",
|
||||
" .+. ",
|
||||
" .++........ ",
|
||||
" .++@+++++++. ",
|
||||
" .++@@@@@@@@@. ",
|
||||
" .+@@@@@@@@@. ",
|
||||
" #.+@........ ",
|
||||
" #.+.####### ",
|
||||
" #..# ",
|
||||
" #.# ",
|
||||
" ## ",
|
||||
" # ",
|
||||
" "};
|
40
src/html/bitmaps/book.xpm
Normal file
40
src/html/bitmaps/book.xpm
Normal file
@@ -0,0 +1,40 @@
|
||||
/* XPM */
|
||||
static char * book_xpm[] = {
|
||||
"16 16 21 1",
|
||||
" c None",
|
||||
". c #007F7F",
|
||||
"+ c #660000",
|
||||
"@ c #CC0000",
|
||||
"# c #E50000",
|
||||
"$ c #FF0000",
|
||||
"% c #F20000",
|
||||
"& c #D80000",
|
||||
"* c #720000",
|
||||
"= c #7F0000",
|
||||
"- c #BFBFBF",
|
||||
"; c #E57F7F",
|
||||
"> c #7F7F7F",
|
||||
", c #FFFFFF",
|
||||
"' c #F2BFBF",
|
||||
") c #723F3F",
|
||||
"! c #A5A5A5",
|
||||
"~ c #E5E5E5",
|
||||
"{ c #B2B2B2",
|
||||
"] c #003F3F",
|
||||
"^ c #000000",
|
||||
" ",
|
||||
" ......... ",
|
||||
" +@#$$$$$%&+ ",
|
||||
" +##$$$$$$$* ",
|
||||
" +##$$$$$$$=- ",
|
||||
" +##$$$$$$$=;> ",
|
||||
" +##$$$$$$$=;,. ",
|
||||
" +##$$$$$$$=;,. ",
|
||||
" +##$$$$$$$=''. ",
|
||||
" +##$$$$$$$=,;. ",
|
||||
" +##$$$$$$%+,;. ",
|
||||
" +&++++++++),;. ",
|
||||
" ++!~~~~~~~~~,. ",
|
||||
" ++!~~~~~~~~~{. ",
|
||||
" ]^^^^^^^^^^^ ",
|
||||
" "};
|
50
src/html/bitmaps/folder.xpm
Normal file
50
src/html/bitmaps/folder.xpm
Normal file
@@ -0,0 +1,50 @@
|
||||
/* XPM */
|
||||
static char * folder_xpm[] = {
|
||||
"16 16 31 1",
|
||||
" c None",
|
||||
". c #000000",
|
||||
"+ c #7F6E54",
|
||||
"@ c #555555",
|
||||
"# c #7F6140",
|
||||
"$ c #FFCF94",
|
||||
"% c #FFFFFF",
|
||||
"& c #D5D5D5",
|
||||
"* c #4B4336",
|
||||
"= c #FFDCA8",
|
||||
"- c #BFA57E",
|
||||
"; c #EFEFEF",
|
||||
"> c #DFDFDF",
|
||||
", c #B8B8B9",
|
||||
"' c #6E6E6F",
|
||||
") c #BF7E42",
|
||||
"! c #FFA858",
|
||||
"~ c #FFC280",
|
||||
"{ c #CFCFCF",
|
||||
"] c #55402C",
|
||||
"^ c #3C2C2C",
|
||||
"/ c #7F542C",
|
||||
"( c #C0C0C0",
|
||||
"_ c #B0B0B2",
|
||||
": c #969698",
|
||||
"< c #A8A8AB",
|
||||
"[ c #A0A0A4",
|
||||
"} c #2C2C2C",
|
||||
"| c #7C7C7E",
|
||||
"1 c #161616",
|
||||
"2 c #3F2A16",
|
||||
" .+. ",
|
||||
".@#$+. ",
|
||||
".%&@#$+.+* ",
|
||||
".%%%&@#$==-. ",
|
||||
".%%;>,')!~$+ ",
|
||||
".%;>{{,']^/~. ",
|
||||
".;>{{((,,_:]/ ",
|
||||
".>{{((,,_<[}/ ",
|
||||
".{{((,,_<[[^/ ",
|
||||
"._((,,_<[[[}/ ",
|
||||
" }|_,_<[[[[}/ ",
|
||||
" .}|<[[[[[}/ ",
|
||||
" .}|[[[[}/ ",
|
||||
" .}|[[}/.. ",
|
||||
" .}|}/.. ",
|
||||
" .12. "};
|
24
src/html/bitmaps/forward.xpm
Normal file
24
src/html/bitmaps/forward.xpm
Normal file
@@ -0,0 +1,24 @@
|
||||
/* XPM */
|
||||
static char * forward_xpm[] = {
|
||||
"16 16 5 1",
|
||||
" c None",
|
||||
". c #000000",
|
||||
"+ c #C0E4CB",
|
||||
"@ c #77C490",
|
||||
"# c #808080",
|
||||
" ",
|
||||
" ",
|
||||
" . ",
|
||||
" .. ",
|
||||
" .+. ",
|
||||
" ........++. ",
|
||||
" .+++++++@++. ",
|
||||
" .@@@@@@@@@++. ",
|
||||
" .@@@@@@@@@+. ",
|
||||
" ........@+.# ",
|
||||
" #######.+.# ",
|
||||
" #..# ",
|
||||
" #.# ",
|
||||
" ## ",
|
||||
" # ",
|
||||
" "};
|
25
src/html/bitmaps/page.xpm
Normal file
25
src/html/bitmaps/page.xpm
Normal file
@@ -0,0 +1,25 @@
|
||||
/* XPM */
|
||||
static char * page_xpm[] = {
|
||||
/* width height ncolors chars_per_pixel */
|
||||
"16 16 3 1",
|
||||
/* colors */
|
||||
" s None c None",
|
||||
". c #000000",
|
||||
"+ c #ffffff",
|
||||
/* pixels */
|
||||
" ",
|
||||
" ........ ",
|
||||
" .++++++.. ",
|
||||
" .+.+.++.+. ",
|
||||
" .++++++.... ",
|
||||
" .+.+.+++++. ",
|
||||
" .+++++++++. ",
|
||||
" .+.+.+.+.+. ",
|
||||
" .+++++++++. ",
|
||||
" .+.+.+.+.+. ",
|
||||
" .+++++++++. ",
|
||||
" .+.+.+.+.+. ",
|
||||
" .+++++++++. ",
|
||||
" ........... ",
|
||||
" ",
|
||||
" "};
|
122
src/html/bitmaps/panel.xpm
Normal file
122
src/html/bitmaps/panel.xpm
Normal file
@@ -0,0 +1,122 @@
|
||||
/* XPM */
|
||||
static char * panel_xpm[] = {
|
||||
"16 15 104 2",
|
||||
" c None",
|
||||
". c #7F7C7C",
|
||||
"+ c #8A8E8E",
|
||||
"@ c #D03232",
|
||||
"# c #BA7E7E",
|
||||
"$ c #555858",
|
||||
"% c #5F5F5F",
|
||||
"& c #656565",
|
||||
"* c #5D5D5D",
|
||||
"= c #939696",
|
||||
"- c #FFFFFF",
|
||||
"; c #F4C8C8",
|
||||
"> c #DCDCF4",
|
||||
", c #D3D3D3",
|
||||
"' c #4E5151",
|
||||
") c #7E7E7E",
|
||||
"! c #9E9E9E",
|
||||
"~ c #A7A7A7",
|
||||
"{ c #5C5C5C",
|
||||
"] c #9B9E9E",
|
||||
"^ c #A3A3FF",
|
||||
"/ c #BBBBFF",
|
||||
"( c #DBDBDB",
|
||||
"_ c #808B8B",
|
||||
": c #5E5E5E",
|
||||
"< c #858571",
|
||||
"[ c #AEAE4B",
|
||||
"} c #90902D",
|
||||
"| c #8B8B8B",
|
||||
"1 c #000027",
|
||||
"2 c #D7D7FF",
|
||||
"3 c #C3C3FF",
|
||||
"4 c #A7A7FF",
|
||||
"5 c #9B9BFF",
|
||||
"6 c #D7D7D7",
|
||||
"7 c #717474",
|
||||
"8 c #727D7D",
|
||||
"9 c #575721",
|
||||
"0 c #BFBF7F",
|
||||
"a c #DFDF8F",
|
||||
"b c #DFDF60",
|
||||
"c c #7F7F3B",
|
||||
"d c #2F2F7F",
|
||||
"e c #AFAFF3",
|
||||
"f c #E7E7E7",
|
||||
"g c #9797E7",
|
||||
"h c #8787F3",
|
||||
"i c #AFAFC3",
|
||||
"j c #4F4F37",
|
||||
"k c #8E9898",
|
||||
"l c #484824",
|
||||
"m c #4D4D0B",
|
||||
"n c #8C8C8C",
|
||||
"o c #7D7D36",
|
||||
"p c #74742D",
|
||||
"q c #535353",
|
||||
"r c #636363",
|
||||
"s c #5C5C4C",
|
||||
"t c #818149",
|
||||
"u c #78784C",
|
||||
"v c #787840",
|
||||
"w c #7E7E40",
|
||||
"x c #787E46",
|
||||
"y c #757F7F",
|
||||
"z c #616121",
|
||||
"A c #87874B",
|
||||
"B c #C8C88C",
|
||||
"C c #F6F6B6",
|
||||
"D c #D4D498",
|
||||
"E c #6C6C30",
|
||||
"F c #424242",
|
||||
"G c #9D9D23",
|
||||
"H c #FDFD7B",
|
||||
"I c #FFFF7F",
|
||||
"J c #7F7F3F",
|
||||
"K c #737C7C",
|
||||
"L c #808038",
|
||||
"M c #6B6B5F",
|
||||
"N c #797935",
|
||||
"O c #6E6E62",
|
||||
"P c #8B8B43",
|
||||
"Q c #8D8D8D",
|
||||
"R c #1C4B4B",
|
||||
"S c #959523",
|
||||
"T c #F9F973",
|
||||
"U c #7F7F43",
|
||||
"V c #737D7D",
|
||||
"W c #939343",
|
||||
"X c #4FD3D3",
|
||||
"Y c #185353",
|
||||
"Z c #8D8D27",
|
||||
"` c #F5F56B",
|
||||
" . c #9B9B43",
|
||||
".. c #57CFCF",
|
||||
"+. c #145B5B",
|
||||
"@. c #85851E",
|
||||
"#. c #A3A343",
|
||||
"$. c #3BA7A7",
|
||||
"%. c #636300",
|
||||
"&. c #CFCF67",
|
||||
"*. c #F3F367",
|
||||
"=. c #909A9A",
|
||||
"-. c #4B4B07",
|
||||
";. c #434325",
|
||||
" . ",
|
||||
" + @ # ",
|
||||
" $ % & * = - ; > , ",
|
||||
" ' ) ! ~ ~ { ] - - ^ / - ( ",
|
||||
"_ : < [ [ } | 1 2 - 3 / 4 5 6 7 ",
|
||||
"8 9 0 a b c 3 d e f f g h i j ",
|
||||
"k l m n o p q r s t t t u v w x ",
|
||||
"y z A B C D E F G H I I I I I J ",
|
||||
"K I L M N O P Q R S T I I I I U ",
|
||||
"V I I I I I I W X Y Z ` I I I U ",
|
||||
"8 I I I I I I I ...+.@.I I I U ",
|
||||
"K I I I I I I I I #.$.%.I I I U ",
|
||||
"8 I I I I I I I I I &.*.I I I U ",
|
||||
"V I I I I I I I I I I I I I I U ",
|
||||
"=.-.-.-.-.-.-.-.-.-.-.-.-.-.-.;."};
|
507
src/html/htmlcell.cpp
Normal file
507
src/html/htmlcell.cpp
Normal file
@@ -0,0 +1,507 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: htmlcell.cpp
|
||||
// Purpose: wxHtmlCell - basic element of HTML output
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/html/htmlcell.h>
|
||||
#include <wx/html/htmlwin.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right)
|
||||
{
|
||||
if (GetLink() != wxEmptyString)
|
||||
((wxHtmlWindow*)parent) -> OnLinkClicked(GetLink());
|
||||
// note : this overcasting is legal because parent is *always* wxHtmlWindow
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlWordCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell()
|
||||
{
|
||||
m_Word = word;
|
||||
m_Word.Replace(" ", " ", TRUE);
|
||||
m_Word.Replace(""", "\"", TRUE);
|
||||
m_Word.Replace("<", "<", TRUE);
|
||||
m_Word.Replace(">", ">", TRUE);
|
||||
m_Word.Replace("&", "&", TRUE);
|
||||
dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlContainerCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
|
||||
{
|
||||
m_Cells = m_LastCell = NULL;
|
||||
m_Parent = parent;
|
||||
if (m_Parent) m_Parent -> InsertCell(this);
|
||||
m_AlignHor = HTML_ALIGN_LEFT;
|
||||
m_AlignVer = HTML_ALIGN_BOTTOM;
|
||||
m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
|
||||
m_WidthFloat = 100; m_WidthFloatUnits = HTML_UNITS_PERCENT;
|
||||
m_UseBkColour = FALSE;
|
||||
m_UseBorder = FALSE;
|
||||
m_MinHeight = m_MaxLineWidth = 0;
|
||||
m_MinHeightAlign = HTML_ALIGN_TOP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlContainerCell::SetIndent(int i, int what, int units)
|
||||
{
|
||||
int val = (units == HTML_UNITS_PIXELS) ? i : -i;
|
||||
if (what & HTML_INDENT_LEFT) m_IndentLeft = val;
|
||||
if (what & HTML_INDENT_RIGHT) m_IndentRight = val;
|
||||
if (what & HTML_INDENT_TOP) m_IndentTop = val;
|
||||
if (what & HTML_INDENT_BOTTOM) m_IndentBottom = val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int wxHtmlContainerCell::GetIndent(int ind) const
|
||||
{
|
||||
if (ind & HTML_INDENT_LEFT) return m_IndentLeft;
|
||||
else if (ind & HTML_INDENT_RIGHT) return m_IndentRight;
|
||||
else if (ind & HTML_INDENT_TOP) return m_IndentTop;
|
||||
else if (ind & HTML_INDENT_BOTTOM) return m_IndentBottom;
|
||||
else return -1; /* BUG! Should not be called... */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int wxHtmlContainerCell::GetIndentUnits(int ind) const
|
||||
{
|
||||
bool p = FALSE;
|
||||
if (ind & HTML_INDENT_LEFT) p = m_IndentLeft < 0;
|
||||
else if (ind & HTML_INDENT_RIGHT) p = m_IndentRight < 0;
|
||||
else if (ind & HTML_INDENT_TOP) p = m_IndentTop < 0;
|
||||
else if (ind & HTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
|
||||
if (p) return HTML_UNITS_PERCENT;
|
||||
else return HTML_UNITS_PIXELS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlContainerCell::Layout(int w)
|
||||
{
|
||||
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;
|
||||
|
||||
/*
|
||||
|
||||
WIDTH ADJUSTING :
|
||||
|
||||
*/
|
||||
|
||||
if (m_WidthFloatUnits == HTML_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;
|
||||
m_Cells -> 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);
|
||||
|
||||
m_MaxLineWidth = 0;
|
||||
|
||||
// my own layouting:
|
||||
while (cell != NULL) {
|
||||
switch (m_AlignVer) {
|
||||
case HTML_ALIGN_TOP : ybasicpos = 0; break;
|
||||
case HTML_ALIGN_BOTTOM : ybasicpos = - cell -> GetHeight(); break;
|
||||
case HTML_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();
|
||||
|
||||
// force new line if occured:
|
||||
if ((cell == NULL) || (xpos + cell -> GetWidth() > s_width)) {
|
||||
if (xpos > m_MaxLineWidth) m_MaxLineWidth = xpos;
|
||||
if (ysizeup < 0) ysizeup = 0;
|
||||
if (ysizedown < 0) ysizedown = 0;
|
||||
switch (m_AlignHor) {
|
||||
case HTML_ALIGN_LEFT : xdelta = 0; break;
|
||||
case HTML_ALIGN_RIGHT : xdelta = 0 + (s_width - xpos); break;
|
||||
case HTML_ALIGN_CENTER : xdelta = 0 + (s_width - xpos) / 2; break;
|
||||
}
|
||||
if (xdelta < 0) xdelta = 0;
|
||||
xdelta += s_indent;
|
||||
|
||||
ypos += ysizeup;
|
||||
while (line != cell) {
|
||||
line -> SetPos(line -> GetPosX() + xdelta, ypos + line -> GetPosY());
|
||||
line = line -> GetNext();
|
||||
}
|
||||
|
||||
ypos += ysizedown;
|
||||
xpos = 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 != HTML_ALIGN_TOP) {
|
||||
int diff = m_MinHeight - m_Height;
|
||||
if (m_MinHeightAlign == HTML_ALIGN_CENTER) diff /= 2;
|
||||
cell = m_Cells;
|
||||
while (cell) {
|
||||
cell -> SetPos(cell -> GetPosX(), cell -> GetPosY() + diff);
|
||||
cell = cell -> GetNext();
|
||||
}
|
||||
}
|
||||
m_Height = m_MinHeight;
|
||||
}
|
||||
|
||||
m_MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
|
||||
if (m_Width < m_MaxLineWidth) m_Width = m_MaxLineWidth;
|
||||
|
||||
wxHtmlCell::Layout(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 - 1, 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 - 1, y + m_PosY + m_Height - 1);
|
||||
}
|
||||
|
||||
if (m_Cells) m_Cells -> Draw(dc, x + m_PosX, y + m_PosY, view_y1, view_y2);
|
||||
}
|
||||
// container invisible, just proceed font+color changing:
|
||||
else {
|
||||
if (m_Cells) m_Cells -> DrawInvisible(dc, x + m_PosX, y + m_PosY);
|
||||
}
|
||||
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y)
|
||||
{
|
||||
if (m_Cells) m_Cells -> DrawInvisible(dc, x + m_PosX, y + m_PosY);
|
||||
wxHtmlCell::DrawInvisible(dc, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxHtmlContainerCell::GetLink(int x, int y) const
|
||||
{
|
||||
wxHtmlCell *c = m_Cells;
|
||||
int cx, cy, cw, ch;
|
||||
|
||||
while (c) {
|
||||
cx = c -> GetPosX(), cy = c -> GetPosY();
|
||||
cw = c -> GetWidth(), ch = c -> GetHeight();
|
||||
if ((x >= cx) && (x < cx + cw) && (y >= cy) && (y < cy + ch))
|
||||
return c -> GetLink(x - cx, y - cy);
|
||||
c = c -> GetNext();
|
||||
}
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
|
||||
{
|
||||
if (tag.HasParam("ALIGN")) {
|
||||
wxString alg = tag.GetParam("ALIGN");
|
||||
alg.MakeUpper();
|
||||
if (alg == "CENTER")
|
||||
SetAlignHor(HTML_ALIGN_CENTER);
|
||||
else if (alg == "LEFT")
|
||||
SetAlignHor(HTML_ALIGN_LEFT);
|
||||
else if (alg == "RIGHT")
|
||||
SetAlignHor(HTML_ALIGN_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag)
|
||||
{
|
||||
if (tag.HasParam("WIDTH")) {
|
||||
int wdi;
|
||||
wxString wd = tag.GetParam("WIDTH");
|
||||
|
||||
if (wd[wd.Length()-1] == '%') {
|
||||
sscanf(wd.c_str(), "%i%%", &wdi);
|
||||
SetWidthFloat(wdi, HTML_UNITS_PERCENT);
|
||||
}
|
||||
else {
|
||||
sscanf(wd.c_str(), "%i", &wdi);
|
||||
SetWidthFloat(wdi, HTML_UNITS_PIXELS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
|
||||
{
|
||||
const wxHtmlCell *r = NULL;
|
||||
|
||||
if (m_Cells) {
|
||||
r = m_Cells -> Find(condition, param);
|
||||
if (r) return r;
|
||||
}
|
||||
|
||||
return wxHtmlCell::Find(condition, param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right)
|
||||
{
|
||||
if (m_Cells) {
|
||||
wxHtmlCell *c = m_Cells;
|
||||
while (c) {
|
||||
if ( (c -> GetPosX() <= x) &&
|
||||
(c -> GetPosY() <= y) &&
|
||||
(c -> GetPosX() + c -> GetWidth() > x) &&
|
||||
(c -> GetPosY() + c -> GetHeight() > y)) {
|
||||
c -> OnMouseClick(parent, x - c -> GetPosX(), y - c -> GetPosY(), left, middle, right);
|
||||
break;
|
||||
}
|
||||
c = c -> GetNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxHtmlColourCell
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
void wxHtmlColourCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
if (m_Flags & HTML_CLR_FOREGROUND)
|
||||
dc.SetTextForeground(m_Colour);
|
||||
if (m_Flags & HTML_CLR_BACKGROUND) {
|
||||
dc.SetBackground(wxBrush(m_Colour, wxSOLID));
|
||||
dc.SetTextBackground(m_Colour);
|
||||
}
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
void wxHtmlColourCell::DrawInvisible(wxDC& dc, int x, int y)
|
||||
{
|
||||
if (m_Flags & HTML_CLR_FOREGROUND)
|
||||
dc.SetTextForeground(m_Colour);
|
||||
if (m_Flags & HTML_CLR_BACKGROUND) {
|
||||
dc.SetBackground(wxBrush(m_Colour, wxSOLID));
|
||||
dc.SetTextBackground(m_Colour);
|
||||
}
|
||||
wxHtmlCell::DrawInvisible(dc, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxHtmlFontCell
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
void wxHtmlFontCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
dc.SetFont(*m_Font);
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
void wxHtmlFontCell::DrawInvisible(wxDC& dc, int x, int y)
|
||||
{
|
||||
dc.SetFont(*m_Font);
|
||||
wxHtmlCell::DrawInvisible(dc, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 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& dc, int x, int y, int view_y1, int 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())) -> ViewStart(&stx, &sty);
|
||||
|
||||
m_Wnd -> SetSize(absx - HTML_SCROLL_STEP * stx, absy - HTML_SCROLL_STEP * sty, m_Width, m_Height);
|
||||
// m_Wnd -> Refresh();
|
||||
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWidgetCell::DrawInvisible(wxDC& dc, int x, int 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())) -> ViewStart(&stx, &sty);
|
||||
|
||||
m_Wnd -> SetSize(absx - HTML_SCROLL_STEP * stx, absy - HTML_SCROLL_STEP * sty, m_Width, m_Height);
|
||||
wxHtmlCell::DrawInvisible(dc, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
|
170
src/html/htmlfilter.cpp
Normal file
170
src/html/htmlfilter.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: filter.cpp
|
||||
// Purpose: wxHtmlFilter - input filter for translating into HTML format
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/html/htmlfilter.h>
|
||||
#include <wx/html/htmlwin.h>
|
||||
|
||||
|
||||
/*
|
||||
|
||||
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& file)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxHtmlFilterPlainText::ReadFile(const wxFSFile& file)
|
||||
{
|
||||
wxInputStream *s = file.GetStream();
|
||||
char *src;
|
||||
wxString doc, doc2;
|
||||
|
||||
if (s == NULL) return wxEmptyString;
|
||||
src = (char*) malloc(s -> StreamSize());
|
||||
src[s -> StreamSize()] = 0;
|
||||
s -> Read(src, s -> StreamSize());
|
||||
doc = src;
|
||||
free(src);
|
||||
|
||||
doc.Replace("<", "<", TRUE);
|
||||
doc.Replace(">", ">", TRUE);
|
||||
doc2 = "<HTML><BODY><PRE>\n" + doc + "\n</PRE></BODY></HTML>";
|
||||
return doc2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxHtmlFilterImage
|
||||
// filter for image/*
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
class wxHtmlFilterImage : public wxHtmlFilter
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage)
|
||||
|
||||
public:
|
||||
virtual bool CanRead(const wxFSFile& file);
|
||||
virtual wxString ReadFile(const wxFSFile& file);
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage, wxHtmlFilter)
|
||||
|
||||
|
||||
|
||||
bool wxHtmlFilterImage::CanRead(const wxFSFile& file)
|
||||
{
|
||||
return (file.GetMimeType().Left(6) == "image/");
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxHtmlFilterImage::ReadFile(const wxFSFile& file)
|
||||
{
|
||||
return ("<HTML><BODY><IMG SRC=\"" + file.GetLocation() + "\"></BODY></HTML>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxHtmlFilterPlainText
|
||||
// filter for text/plain or uknown
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
class wxHtmlFilterHTML : public wxHtmlFilter
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML)
|
||||
|
||||
public:
|
||||
virtual bool CanRead(const wxFSFile& file);
|
||||
virtual wxString ReadFile(const wxFSFile& file);
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML, wxHtmlFilter)
|
||||
|
||||
bool wxHtmlFilterHTML::CanRead(const wxFSFile& file)
|
||||
{
|
||||
return (file.GetMimeType() == "text/html");
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxHtmlFilterHTML::ReadFile(const wxFSFile& file)
|
||||
{
|
||||
wxInputStream *s = file.GetStream();
|
||||
char *src;
|
||||
wxString doc;
|
||||
|
||||
if (s == NULL) return wxEmptyString;
|
||||
src = (char*) malloc(s -> StreamSize() + 1);
|
||||
src[s -> StreamSize()] = 0;
|
||||
s -> Read(src, s -> StreamSize());
|
||||
doc = src;
|
||||
free(src);
|
||||
|
||||
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
|
864
src/html/htmlhelp.cpp
Normal file
864
src/html/htmlhelp.cpp
Normal file
@@ -0,0 +1,864 @@
|
||||
// Name: htmlhelp.cpp
|
||||
// Purpose: Help controller
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
|
||||
#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/html/htmlhelp.h>
|
||||
#include <wx/busyinfo.h>
|
||||
|
||||
#if !((wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)))
|
||||
#include <wx/progdlg.h>
|
||||
#endif
|
||||
|
||||
|
||||
// Bitmaps:
|
||||
|
||||
#ifndef __WXMSW__
|
||||
#include "bitmaps/panel.xpm"
|
||||
#include "bitmaps/back.xpm"
|
||||
#include "bitmaps/forward.xpm"
|
||||
#include "bitmaps/book.xpm"
|
||||
#include "bitmaps/folder.xpm"
|
||||
#include "bitmaps/page.xpm"
|
||||
#endif
|
||||
|
||||
#include "search.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper constants
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Command IDs :
|
||||
|
||||
enum {
|
||||
wxID_HTML_PANEL = wxID_HIGHEST + 1,
|
||||
wxID_HTML_BACK,
|
||||
wxID_HTML_FORWARD,
|
||||
wxID_HTML_TREECTRL,
|
||||
wxID_HTML_INDEXPAGE,
|
||||
wxID_HTML_INDEXLIST,
|
||||
wxID_HTML_NOTEBOOK,
|
||||
wxID_HTML_SEARCHPAGE,
|
||||
wxID_HTML_SEARCHTEXT,
|
||||
wxID_HTML_SEARCHLIST,
|
||||
wxID_HTML_SEARCHBUTTON
|
||||
};
|
||||
|
||||
|
||||
// Images:
|
||||
|
||||
enum {
|
||||
IMG_Book = 0,
|
||||
IMG_Folder,
|
||||
IMG_Page
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class HtmlHelpTreeItemData : public wxTreeItemData
|
||||
{
|
||||
private:
|
||||
wxString m_Page;
|
||||
|
||||
public:
|
||||
HtmlHelpTreeItemData(HtmlContentsItem *it) : wxTreeItemData() {m_Page = it -> m_Book -> GetBasePath() + it -> m_Page;}
|
||||
const wxString& GetPage() {return m_Page;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <wx/arrimpl.cpp>
|
||||
WX_DEFINE_OBJARRAY(HtmlBookRecArray)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlHelpController
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxEvtHandler)
|
||||
|
||||
|
||||
wxHtmlHelpController::wxHtmlHelpController() : wxEvtHandler()
|
||||
{
|
||||
m_Frame = NULL;
|
||||
m_Config = NULL;
|
||||
m_ConfigRoot = wxEmptyString;
|
||||
m_TitleFormat = _("Help : %s");
|
||||
m_TempPath = 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_ContentsImageList = new wxImageList(12, 12);
|
||||
m_ContentsImageList -> Add(wxICON(book));
|
||||
m_ContentsImageList -> Add(wxICON(folder));
|
||||
m_ContentsImageList -> Add(wxICON(page));
|
||||
|
||||
m_Contents = NULL;
|
||||
m_ContentsCnt = 0;
|
||||
m_Index = NULL;
|
||||
m_IndexCnt = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlHelpController::~wxHtmlHelpController()
|
||||
{
|
||||
int i;
|
||||
|
||||
m_BookRecords.Empty();
|
||||
delete m_ContentsImageList;
|
||||
if (m_Contents) {
|
||||
for (i = 0; i < m_ContentsCnt; i++) {
|
||||
free(m_Contents[i].m_Page);
|
||||
free(m_Contents[i].m_Name);
|
||||
}
|
||||
free(m_Contents);
|
||||
}
|
||||
if (m_Index) {
|
||||
for (i = 0; i < m_IndexCnt; i++) {
|
||||
free(m_Index[i].m_Page);
|
||||
free(m_Index[i].m_Name);
|
||||
}
|
||||
free(m_Index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::SetTempDir(const wxString& path)
|
||||
{
|
||||
if (path == wxEmptyString) m_TempPath = path;
|
||||
else {
|
||||
if (wxIsAbsolutePath(path)) m_TempPath = path;
|
||||
else m_TempPath = wxGetCwd() + "/" + path;
|
||||
|
||||
if (m_TempPath[m_TempPath.Length() - 1] != '/')
|
||||
m_TempPath << "/";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Reads one line, stores it into buf and returns pointer to new line or NULL.
|
||||
static char* ReadLine(char *line, char *buf)
|
||||
{
|
||||
char *writeptr = buf, *readptr = line;
|
||||
|
||||
while (*readptr != 0 && *readptr != '\r' && *readptr != '\n') *(writeptr++) = *(readptr++);
|
||||
*writeptr = 0;
|
||||
while (*readptr == '\r' || *readptr == '\n') readptr++;
|
||||
if (*readptr == 0) return NULL;
|
||||
else return readptr;
|
||||
}
|
||||
|
||||
|
||||
static wxString SafeFileName(const wxString& s)
|
||||
{
|
||||
wxString res = s;
|
||||
res.Replace(":", "_", TRUE);
|
||||
res.Replace(" ", "_", TRUE);
|
||||
res.Replace("/", "_", TRUE);
|
||||
res.Replace("\\", "_", TRUE);
|
||||
res.Replace("#", "_", TRUE);
|
||||
res.Replace(".", "_", TRUE);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static int IndexCompareFunc(const void *a, const void *b)
|
||||
{
|
||||
return strcmp(((HtmlContentsItem*)a) -> m_Name, ((HtmlContentsItem*)b) -> m_Name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FALSE)
|
||||
{
|
||||
wxFSFile *fi;
|
||||
wxFileSystem fsys;
|
||||
wxInputStream *s;
|
||||
HtmlBookRecord *bookr;
|
||||
wxString bookFull;
|
||||
|
||||
int sz;
|
||||
char *buff, *lineptr;
|
||||
char linebuf[300];
|
||||
|
||||
wxString title = _("noname"),
|
||||
safetitle,
|
||||
start = wxEmptyString,
|
||||
contents = wxEmptyString, index = wxEmptyString;
|
||||
|
||||
if (wxIsAbsolutePath(book)) bookFull = book;
|
||||
else bookFull = wxGetCwd() + "/" + book;
|
||||
|
||||
fi = fsys.OpenFile(bookFull);
|
||||
if (fi == NULL) return FALSE;
|
||||
fsys.ChangePathTo(bookFull);
|
||||
s = fi -> GetStream();
|
||||
sz = s -> StreamSize();
|
||||
buff = (char*) malloc(sz+1);
|
||||
buff[sz] = 0;
|
||||
s -> Read(buff, sz);
|
||||
lineptr = buff;
|
||||
delete fi;
|
||||
|
||||
while ((lineptr = ReadLine(lineptr, linebuf)) != NULL) {
|
||||
if (strstr(linebuf, "Title=") == linebuf)
|
||||
title = linebuf + strlen("Title=");
|
||||
if (strstr(linebuf, "Default topic=") == linebuf)
|
||||
start = linebuf + strlen("Default topic=");
|
||||
if (strstr(linebuf, "Index file=") == linebuf)
|
||||
index = linebuf + strlen("Index file=");
|
||||
if (strstr(linebuf, "Contents file=") == linebuf)
|
||||
contents = linebuf + strlen("Contents file=");
|
||||
}
|
||||
free(buff);
|
||||
|
||||
bookr = new HtmlBookRecord(fsys.GetPath(), title, start);
|
||||
|
||||
if (m_ContentsCnt % HTML_REALLOC_STEP == 0)
|
||||
m_Contents = (HtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + HTML_REALLOC_STEP) * sizeof(HtmlContentsItem));
|
||||
m_Contents[m_ContentsCnt].m_Level = 0;
|
||||
m_Contents[m_ContentsCnt].m_ID = 0;
|
||||
m_Contents[m_ContentsCnt].m_Page = (char*) malloc(start.Length() + 1);
|
||||
strcpy(m_Contents[m_ContentsCnt].m_Page, start.c_str());
|
||||
m_Contents[m_ContentsCnt].m_Name = (char*) malloc(title.Length() + 1);
|
||||
strcpy(m_Contents[m_ContentsCnt].m_Name, title.c_str());
|
||||
m_Contents[m_ContentsCnt].m_Book = bookr;
|
||||
m_ContentsCnt++;
|
||||
|
||||
// Try to find cached binary versions:
|
||||
safetitle = SafeFileName(title);
|
||||
fi = fsys.OpenFile(safetitle + ".cached");
|
||||
if (fi == NULL) fi = fsys.OpenFile(m_TempPath + safetitle + ".cached");
|
||||
if ((fi == NULL) || (m_TempPath == wxEmptyString)) {
|
||||
LoadMSProject(bookr, fsys, index, contents, show_wait_msg);
|
||||
if (m_TempPath != wxEmptyString) {
|
||||
wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + safetitle + ".cached");
|
||||
SaveCachedBook(bookr, outs);
|
||||
delete outs;
|
||||
}
|
||||
}
|
||||
else {
|
||||
LoadCachedBook(bookr, fi -> GetStream());
|
||||
delete fi;
|
||||
}
|
||||
|
||||
m_BookRecords.Add(bookr);
|
||||
if (m_IndexCnt > 0)
|
||||
qsort(m_Index, m_IndexCnt, sizeof(HtmlContentsItem), IndexCompareFunc);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::Display(const wxString& x)
|
||||
{
|
||||
int cnt;
|
||||
int i;
|
||||
wxFileSystem fsys;
|
||||
wxFSFile *f;
|
||||
|
||||
CreateHelpWindow();
|
||||
|
||||
/* 1. try to open given file: */
|
||||
|
||||
cnt = m_BookRecords.GetCount();
|
||||
for (i = 0; i < cnt; i++) {
|
||||
f = fsys.OpenFile(m_BookRecords[i].GetBasePath() + x);
|
||||
if (f) {
|
||||
m_HtmlWin -> LoadPage(m_BookRecords[i].GetBasePath() + x);
|
||||
delete f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 2. try to find a book: */
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (m_BookRecords[i].GetTitle() == x) {
|
||||
m_HtmlWin -> LoadPage(m_BookRecords[i].GetBasePath() + m_BookRecords[i].GetStart());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* 3. try to find in contents: */
|
||||
|
||||
cnt = m_ContentsCnt;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (strcmp(m_Contents[i].m_Name, x) == 0) {
|
||||
m_HtmlWin -> LoadPage(m_Contents[i].m_Book -> GetBasePath() + m_Contents[i].m_Page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 4. try to find in index: */
|
||||
|
||||
cnt = m_IndexCnt;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (strcmp(m_Index[i].m_Name, x) == 0) {
|
||||
m_HtmlWin -> LoadPage(m_Index[i].m_Book -> GetBasePath() + m_Index[i].m_Page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 5. if everything failed, search the documents: */
|
||||
|
||||
KeywordSearch(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::Display(const int id)
|
||||
{
|
||||
CreateHelpWindow();
|
||||
|
||||
for (int i = 0; i < m_ContentsCnt; i++) {
|
||||
if (m_Contents[i].m_ID == id) {
|
||||
m_HtmlWin -> LoadPage(m_Contents[i].m_Book -> GetBasePath() + m_Contents[i].m_Page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::DisplayContents()
|
||||
{
|
||||
CreateHelpWindow();
|
||||
m_Frame -> Raise();
|
||||
if (!m_Splitter -> IsSplit()) {
|
||||
m_NavigPan -> Show(TRUE);
|
||||
m_HtmlWin -> Show(TRUE);
|
||||
m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
|
||||
}
|
||||
m_NavigPan -> SetSelection(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::DisplayIndex()
|
||||
{
|
||||
CreateHelpWindow();
|
||||
m_Frame -> Raise();
|
||||
if (!m_Splitter -> IsSplit()) {
|
||||
m_NavigPan -> Show(TRUE);
|
||||
m_HtmlWin -> Show(TRUE);
|
||||
m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
|
||||
}
|
||||
m_NavigPan -> SetSelection(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
|
||||
|
||||
class MyProgressDlg : public wxDialog
|
||||
{
|
||||
public:
|
||||
bool m_Canceled;
|
||||
|
||||
MyProgressDlg(wxWindow *parent) : wxDialog(parent, -1,
|
||||
_("Searching..."),
|
||||
wxPoint(0, 0),
|
||||
#ifdef __WXGTK__
|
||||
wxSize(300, 110))
|
||||
#else
|
||||
wxSize(300, 130))
|
||||
#endif
|
||||
{m_Canceled = FALSE;}
|
||||
void OnCancel(wxCommandEvent& event) {m_Canceled = TRUE;}
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
BEGIN_EVENT_TABLE(MyProgressDlg, wxDialog)
|
||||
EVT_BUTTON(wxID_CANCEL, MyProgressDlg::OnCancel)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
|
||||
{
|
||||
int foundcnt = 0;
|
||||
|
||||
CreateHelpWindow();
|
||||
m_Frame -> Raise();
|
||||
if (!m_Splitter -> IsSplit()) {
|
||||
m_NavigPan -> Show(TRUE);
|
||||
m_HtmlWin -> Show(TRUE);
|
||||
m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
|
||||
}
|
||||
m_NavigPan -> SetSelection(2);
|
||||
m_SearchList -> Clear();
|
||||
m_SearchText -> SetValue(keyword);
|
||||
m_SearchButton -> Enable(FALSE);
|
||||
|
||||
{
|
||||
int cnt = m_ContentsCnt;
|
||||
wxSearchEngine engine;
|
||||
wxFileSystem fsys;
|
||||
wxFSFile *file;
|
||||
wxString lastpage = wxEmptyString;
|
||||
wxString foundstr;
|
||||
|
||||
#if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
|
||||
MyProgressDlg progress(m_Frame);
|
||||
|
||||
wxStaticText *prompt = new wxStaticText(&progress, -1, "", wxPoint(20, 50), wxSize(260, 25), wxALIGN_CENTER);
|
||||
wxGauge *gauge = new wxGauge(&progress, -1, cnt, wxPoint(20, 20), wxSize(260, 25));
|
||||
wxButton *btn = new wxButton(&progress, wxID_CANCEL, _("Cancel"), wxPoint(110, 70), wxSize(80, 25));
|
||||
btn = btn; /* fool compiler :-) */
|
||||
prompt -> SetLabel(_("No matching page found yet"));
|
||||
|
||||
progress.Centre(wxBOTH);
|
||||
progress.Show(TRUE);
|
||||
#else
|
||||
wxProgressDialog progress(_("Searching..."), _("No matching page found yet"), cnt, m_Frame, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
|
||||
#endif
|
||||
|
||||
engine.LookFor(keyword);
|
||||
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
#if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
|
||||
gauge -> SetValue(i);
|
||||
if (progress.m_Canceled) break;
|
||||
#else
|
||||
if (progress.Update(i) == FALSE) break;
|
||||
#endif
|
||||
wxYield();
|
||||
|
||||
file = fsys.OpenFile(m_Contents[i].m_Book -> GetBasePath() + m_Contents[i].m_Page);
|
||||
if (file) {
|
||||
if (lastpage != file -> GetLocation()) {
|
||||
lastpage = file -> GetLocation();
|
||||
if (engine.Scan(file -> GetStream())) {
|
||||
foundstr.Printf(_("Found %i matches"), ++foundcnt);
|
||||
#if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
|
||||
prompt -> SetLabel(foundstr);
|
||||
#else
|
||||
progress.Update(i, foundstr);
|
||||
#endif
|
||||
wxYield();
|
||||
m_SearchList -> Append(m_Contents[i].m_Name, (char*)(m_Contents + i));
|
||||
}
|
||||
}
|
||||
delete file;
|
||||
}
|
||||
}
|
||||
|
||||
#if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
|
||||
progress.Close(TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
m_SearchButton -> Enable(TRUE);
|
||||
m_SearchText -> SetSelection(0, keyword.Length());
|
||||
m_SearchText -> SetFocus();
|
||||
if (foundcnt) {
|
||||
HtmlContentsItem *it = (HtmlContentsItem*) m_SearchList -> GetClientData(0);
|
||||
if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
|
||||
}
|
||||
return (foundcnt > 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::CreateHelpWindow()
|
||||
{
|
||||
wxBusyCursor cur;
|
||||
wxString oldpath;
|
||||
wxStatusBar *sbar;
|
||||
|
||||
if (m_Frame) {
|
||||
m_Frame -> Raise();
|
||||
m_Frame -> Show(TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
wxBusyInfo busyinfo(_("Preparing help window..."));
|
||||
|
||||
if (m_Config) ReadCustomization(m_Config, m_ConfigRoot);
|
||||
|
||||
m_Frame = new wxFrame(NULL, -1, "", wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h));
|
||||
m_Frame -> PushEventHandler(this);
|
||||
sbar = m_Frame -> CreateStatusBar();
|
||||
|
||||
{
|
||||
wxToolBar *toolBar;
|
||||
toolBar = m_Frame -> CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE);
|
||||
toolBar -> SetMargins(2, 2);
|
||||
wxBitmap* toolBarBitmaps[3];
|
||||
|
||||
#ifdef __WXMSW__
|
||||
toolBarBitmaps[0] = new wxBitmap("panel");
|
||||
toolBarBitmaps[1] = new wxBitmap("back");
|
||||
toolBarBitmaps[2] = new wxBitmap("forward");
|
||||
int width = 24;
|
||||
#else
|
||||
toolBarBitmaps[0] = new wxBitmap(panel_xpm);
|
||||
toolBarBitmaps[1] = new wxBitmap(back_xpm);
|
||||
toolBarBitmaps[2] = new wxBitmap(forward_xpm);
|
||||
int width = 16;
|
||||
#endif
|
||||
|
||||
int currentX = 5;
|
||||
|
||||
toolBar -> AddTool(wxID_HTML_PANEL, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, _("Show/hide navigation panel"));
|
||||
currentX += width + 5;
|
||||
toolBar -> AddSeparator();
|
||||
toolBar -> AddTool(wxID_HTML_BACK, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, _("Go back to the previous HTML page"));
|
||||
currentX += width + 5;
|
||||
toolBar -> AddTool(wxID_HTML_FORWARD, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, _("Go forward to the next HTML page"));
|
||||
currentX += width + 5;
|
||||
|
||||
toolBar -> Realize();
|
||||
|
||||
// Can delete the bitmaps since they're reference counted
|
||||
for (int i = 0; i < 3; i++) delete toolBarBitmaps[i];
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
m_Splitter = new wxSplitterWindow(m_Frame);
|
||||
|
||||
m_HtmlWin = new wxHtmlWindow(m_Splitter);
|
||||
m_HtmlWin -> SetRelatedFrame(m_Frame, m_TitleFormat);
|
||||
m_HtmlWin -> SetRelatedStatusBar(0);
|
||||
if (m_Config) m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
|
||||
|
||||
m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK, wxDefaultPosition, wxDefaultSize);
|
||||
{
|
||||
m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
|
||||
m_ContentsBox -> SetImageList(m_ContentsImageList);
|
||||
m_NavigPan -> AddPage(m_ContentsBox, _("Contents"));
|
||||
}
|
||||
|
||||
{
|
||||
wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
|
||||
wxLayoutConstraints *b1 = new wxLayoutConstraints;
|
||||
b1 -> top.SameAs (dummy, wxTop, 0);
|
||||
b1 -> left.SameAs (dummy, wxLeft, 0);
|
||||
b1 -> width.PercentOf (dummy, wxWidth, 100);
|
||||
b1 -> bottom.SameAs (dummy, wxBottom, 0);
|
||||
m_IndexBox = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_IndexBox -> SetConstraints(b1);
|
||||
dummy -> SetAutoLayout(TRUE);
|
||||
m_NavigPan -> AddPage(dummy, _("Index"));
|
||||
}
|
||||
|
||||
{
|
||||
wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
|
||||
|
||||
wxLayoutConstraints *b1 = new wxLayoutConstraints;
|
||||
m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT);
|
||||
b1 -> top.SameAs (dummy, wxTop, 0);
|
||||
b1 -> left.SameAs (dummy, wxLeft, 0);
|
||||
b1 -> right.SameAs (dummy, wxRight, 0);
|
||||
b1 -> height.AsIs();
|
||||
m_SearchText -> SetConstraints(b1);
|
||||
|
||||
wxLayoutConstraints *b2 = new wxLayoutConstraints;
|
||||
m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search!"));
|
||||
b2 -> top.Below (m_SearchText, 10);
|
||||
b2 -> right.SameAs (dummy, wxRight, 10);
|
||||
b2 -> width.AsIs();
|
||||
b2 -> height.AsIs();
|
||||
m_SearchButton -> SetConstraints(b2);
|
||||
|
||||
wxLayoutConstraints *b3 = new wxLayoutConstraints;
|
||||
m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0);
|
||||
b3 -> top.Below (m_SearchButton, 10);
|
||||
b3 -> left.SameAs (dummy, wxLeft, 0);
|
||||
b3 -> right.SameAs (dummy, wxRight, 0);
|
||||
b3 -> bottom.SameAs (dummy, wxBottom, 0);
|
||||
m_SearchList -> SetConstraints(b3);
|
||||
|
||||
dummy -> SetAutoLayout(TRUE);
|
||||
dummy -> Layout();
|
||||
m_NavigPan -> AddPage(dummy, _("Search"));
|
||||
}
|
||||
|
||||
RefreshLists();
|
||||
m_NavigPan -> Show(TRUE);
|
||||
m_HtmlWin -> Show(TRUE);
|
||||
m_Splitter -> SetMinimumPaneSize(20);
|
||||
m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
|
||||
if (!m_Cfg.navig_on) m_Splitter -> Unsplit(m_NavigPan);
|
||||
wxYield();
|
||||
}
|
||||
|
||||
m_Frame -> Show(TRUE);
|
||||
wxYield();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define MAX_ROOTS 64
|
||||
|
||||
void wxHtmlHelpController::CreateContents()
|
||||
{
|
||||
HtmlContentsItem *it;
|
||||
wxTreeItemId roots[MAX_ROOTS];
|
||||
bool imaged[MAX_ROOTS];
|
||||
int count = m_ContentsCnt;
|
||||
|
||||
m_ContentsBox -> DeleteAllItems();
|
||||
roots[0] = m_ContentsBox -> AddRoot(_("(Help)"));
|
||||
imaged[0] = TRUE;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
it = m_Contents + i;
|
||||
roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(roots[it -> m_Level], it -> m_Name, IMG_Page, -1, new HtmlHelpTreeItemData(it));
|
||||
if (it -> m_Level == 0) {
|
||||
m_ContentsBox -> SetItemBold(roots[1], TRUE);
|
||||
m_ContentsBox -> SetItemImage(roots[1], IMG_Book);
|
||||
m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book);
|
||||
imaged[1] = TRUE;
|
||||
}
|
||||
else imaged[it -> m_Level + 1] = FALSE;
|
||||
|
||||
if (!imaged[it -> m_Level]) {
|
||||
m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder);
|
||||
m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder);
|
||||
imaged[it -> m_Level] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
m_ContentsBox -> Expand(roots[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::CreateIndex()
|
||||
{
|
||||
m_IndexBox -> Clear();
|
||||
|
||||
for (int i = 0; i < m_IndexCnt; i++)
|
||||
m_IndexBox -> Append(m_Index[i].m_Name, (char*)(m_Index + i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::RefreshLists()
|
||||
{
|
||||
if (m_Frame) {
|
||||
CreateContents();
|
||||
CreateIndex();
|
||||
m_SearchList -> Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::ReadCustomization(wxConfigBase *cfg, wxString path)
|
||||
{
|
||||
wxString oldpath;
|
||||
wxString tmp;
|
||||
|
||||
if (path != wxEmptyString) {
|
||||
oldpath = cfg -> GetPath();
|
||||
cfg -> SetPath(path);
|
||||
}
|
||||
|
||||
m_Cfg.navig_on = (bool) cfg -> Read("hcNavigPanel", m_Cfg.navig_on);
|
||||
m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos);
|
||||
m_Cfg.x = cfg -> Read("hcX", m_Cfg.x);
|
||||
m_Cfg.y = cfg -> Read("hcY", m_Cfg.y);
|
||||
m_Cfg.w = cfg -> Read("hcW", m_Cfg.w);
|
||||
m_Cfg.h = cfg -> Read("hcH", m_Cfg.h);
|
||||
|
||||
if (path != wxEmptyString)
|
||||
cfg -> SetPath(oldpath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::WriteCustomization(wxConfigBase *cfg, wxString path)
|
||||
{
|
||||
wxString oldpath;
|
||||
wxString tmp;
|
||||
|
||||
if (path != wxEmptyString) {
|
||||
oldpath = cfg -> GetPath();
|
||||
cfg -> SetPath(path);
|
||||
}
|
||||
|
||||
cfg -> Write("hcNavigPanel", m_Cfg.navig_on);
|
||||
cfg -> Write("hcSashPos", (long)m_Cfg.sashpos);
|
||||
cfg -> Write("hcX", (long)m_Cfg.x);
|
||||
cfg -> Write("hcY", (long)m_Cfg.y);
|
||||
cfg -> Write("hcW", (long)m_Cfg.w);
|
||||
cfg -> Write("hcH", (long)m_Cfg.h);
|
||||
|
||||
if (path != wxEmptyString)
|
||||
cfg -> SetPath(oldpath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
EVENT HANDLING :
|
||||
*/
|
||||
|
||||
|
||||
void wxHtmlHelpController::OnToolbar(wxCommandEvent& event)
|
||||
{
|
||||
switch (event.GetId()) {
|
||||
case wxID_HTML_BACK :
|
||||
m_HtmlWin -> HistoryBack();
|
||||
break;
|
||||
case wxID_HTML_FORWARD :
|
||||
m_HtmlWin -> HistoryForward();
|
||||
break;
|
||||
case wxID_HTML_PANEL :
|
||||
if (m_Splitter -> IsSplit()) {
|
||||
m_Cfg.sashpos = m_Splitter -> GetSashPosition();
|
||||
m_Splitter -> Unsplit(m_NavigPan);
|
||||
}
|
||||
else {
|
||||
m_NavigPan -> Show(TRUE);
|
||||
m_HtmlWin -> Show(TRUE);
|
||||
m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::OnContentsSel(wxTreeEvent& event)
|
||||
{
|
||||
HtmlHelpTreeItemData *pg;
|
||||
|
||||
pg = (HtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
|
||||
if (pg) m_HtmlWin -> LoadPage(pg -> GetPage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::OnIndexSel(wxCommandEvent& event)
|
||||
{
|
||||
HtmlContentsItem *it = (HtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection());
|
||||
if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::OnSearchSel(wxCommandEvent& event)
|
||||
{
|
||||
HtmlContentsItem *it = (HtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
|
||||
if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
m_Cfg.navig_on = m_Splitter -> IsSplit();
|
||||
if (m_Cfg.navig_on)
|
||||
m_Cfg.sashpos = m_Splitter -> GetSashPosition();
|
||||
m_Frame -> GetPosition(&a, &b);
|
||||
m_Cfg.x = a, m_Cfg.y = b;
|
||||
m_Frame -> GetSize(&a, &b);
|
||||
m_Cfg.w = a, m_Cfg.h = b;
|
||||
|
||||
if (m_Config) {
|
||||
WriteCustomization(m_Config, m_ConfigRoot);
|
||||
m_HtmlWin -> WriteCustomization(m_Config, m_ConfigRoot);
|
||||
}
|
||||
m_Frame = NULL;
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::OnSearch(wxCommandEvent& event)
|
||||
{
|
||||
wxString sr = m_SearchText -> GetLineText(0);
|
||||
|
||||
if (sr != wxEmptyString) KeywordSearch(sr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BEGIN_EVENT_TABLE(wxHtmlHelpController, wxEvtHandler)
|
||||
EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_FORWARD, wxHtmlHelpController::OnToolbar)
|
||||
EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpController::OnContentsSel)
|
||||
EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpController::OnIndexSel)
|
||||
EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpController::OnSearchSel)
|
||||
EVT_CLOSE(wxHtmlHelpController::OnCloseWindow)
|
||||
EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpController::OnSearch)
|
||||
EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpController::OnSearch)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
250
src/html/htmlhelp_io.cpp
Normal file
250
src/html/htmlhelp_io.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: htmlhelp.cpp
|
||||
// Purpose: Help controller
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//#ifdef __GNUG__
|
||||
//#pragma implementation "htmlhelp.h"
|
||||
//#endif
|
||||
// --- already in htmlhelp.cpp
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <wx/wxhtml.h>
|
||||
#include <wx/busyinfo.h>
|
||||
|
||||
|
||||
|
||||
|
||||
class HP_Parser : public wxHtmlParser
|
||||
{
|
||||
public:
|
||||
void AddText(const char* text) {}
|
||||
wxObject* GetProduct() {return NULL;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HP_TagHandler : public wxHtmlTagHandler
|
||||
{
|
||||
private:
|
||||
wxString m_Name, m_Page;
|
||||
int m_Level;
|
||||
int m_ID;
|
||||
int m_Index;
|
||||
HtmlContentsItem *m_Items;
|
||||
int m_ItemsCnt;
|
||||
HtmlBookRecord *m_Book;
|
||||
|
||||
public:
|
||||
HP_TagHandler(HtmlBookRecord *b) : wxHtmlTagHandler() {m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; m_Level = 0;}
|
||||
wxString GetSupportedTags() {return "UL,OBJECT,PARAM";}
|
||||
bool HandleTag(const wxHtmlTag& tag);
|
||||
void WriteOut(HtmlContentsItem*& array, int& size);
|
||||
void ReadIn(HtmlContentsItem* array, int size);
|
||||
};
|
||||
|
||||
|
||||
bool HP_TagHandler::HandleTag(const wxHtmlTag& tag)
|
||||
{
|
||||
if (tag.GetName() == "UL") {
|
||||
m_Level++;
|
||||
ParseInner(tag);
|
||||
m_Level--;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
else if (tag.GetName() == "OBJECT") {
|
||||
m_Name = m_Page = wxEmptyString;
|
||||
ParseInner(tag);
|
||||
if (m_Page != wxEmptyString) {
|
||||
if (m_ItemsCnt % HTML_REALLOC_STEP == 0)
|
||||
m_Items = (HtmlContentsItem*) realloc(m_Items, (m_ItemsCnt + HTML_REALLOC_STEP) * sizeof(HtmlContentsItem));
|
||||
m_Items[m_ItemsCnt].m_Level = m_Level;
|
||||
m_Items[m_ItemsCnt].m_ID = m_ID;
|
||||
m_Items[m_ItemsCnt].m_Page = (char*) malloc(m_Page.Length() + 1);
|
||||
strcpy(m_Items[m_ItemsCnt].m_Page, m_Page.c_str());
|
||||
m_Items[m_ItemsCnt].m_Name = (char*) malloc(m_Name.Length() + 1);
|
||||
strcpy(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("NAME") == "Name") m_Name = tag.GetParam("VALUE");
|
||||
if (tag.GetParam("NAME") == "Local") m_Page = tag.GetParam("VALUE");
|
||||
if (tag.GetParam("NAME") == "ID") tag.ScanParam("VALUE", "%i", &m_ID);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HP_TagHandler::WriteOut(HtmlContentsItem*& array, int& size)
|
||||
{
|
||||
array = m_Items;
|
||||
size = m_ItemsCnt;
|
||||
m_Items = NULL;
|
||||
m_ItemsCnt = 0;
|
||||
}
|
||||
|
||||
void HP_TagHandler::ReadIn(HtmlContentsItem* array, int size)
|
||||
{
|
||||
m_Items = array;
|
||||
m_ItemsCnt = size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::LoadMSProject(HtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile, bool show_wait_msg)
|
||||
{
|
||||
wxFSFile *f;
|
||||
char *buf;
|
||||
int sz;
|
||||
wxString string;
|
||||
wxBusyInfo *busyinfo = (show_wait_msg) ? new wxBusyInfo(_("Importing help file : \n") + book -> m_Title) : NULL;
|
||||
|
||||
HP_Parser parser;
|
||||
HP_TagHandler *handler = new HP_TagHandler(book);
|
||||
parser.AddTagHandler(handler);
|
||||
|
||||
f = fsys.OpenFile(contentsfile);
|
||||
if (f) {
|
||||
sz = f -> GetStream() -> StreamSize();
|
||||
buf = (char*) malloc(sz+1);
|
||||
buf[sz] = 0;
|
||||
f -> GetStream() -> Read(buf, sz);
|
||||
delete f;
|
||||
handler -> ReadIn(m_Contents, m_ContentsCnt);
|
||||
parser.Parse(buf);
|
||||
handler -> WriteOut(m_Contents, m_ContentsCnt);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
f = fsys.OpenFile(indexfile);
|
||||
if (f) {
|
||||
sz = f -> GetStream() -> StreamSize();
|
||||
buf = (char*) malloc(sz+1);
|
||||
buf[sz] = 0;
|
||||
f -> GetStream() -> Read(buf, sz);
|
||||
delete f;
|
||||
handler -> ReadIn(m_Index, m_IndexCnt);
|
||||
parser.Parse(buf);
|
||||
handler -> WriteOut(m_Index, m_IndexCnt);
|
||||
free(buf);
|
||||
}
|
||||
if (show_wait_msg) delete busyinfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::LoadCachedBook(HtmlBookRecord *book, wxInputStream *f)
|
||||
{
|
||||
int i, st;
|
||||
int x;
|
||||
|
||||
/* load contents : */
|
||||
|
||||
f -> Read(&x, sizeof(x));
|
||||
st = m_ContentsCnt;
|
||||
m_ContentsCnt += x;
|
||||
m_Contents = (HtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt / HTML_REALLOC_STEP + 1) * HTML_REALLOC_STEP * sizeof(HtmlContentsItem));
|
||||
for (i = st; i < m_ContentsCnt; i++) {
|
||||
f -> Read(&x, sizeof(x));
|
||||
m_Contents[i].m_Level = x;
|
||||
f -> Read(&x, sizeof(x));
|
||||
m_Contents[i].m_ID = x;
|
||||
f -> Read(&x, sizeof(x));
|
||||
m_Contents[i].m_Name = (char*) malloc(x);
|
||||
f -> Read(m_Contents[i].m_Name, x);
|
||||
f -> Read(&x, sizeof(x));
|
||||
m_Contents[i].m_Page = (char*) malloc(x);
|
||||
f -> Read(m_Contents[i].m_Page, x);
|
||||
m_Contents[i].m_Book = book;
|
||||
}
|
||||
|
||||
/* load index : */
|
||||
|
||||
f -> Read(&x, sizeof(x));
|
||||
st = m_IndexCnt;
|
||||
m_IndexCnt += x;
|
||||
m_Index = (HtmlContentsItem*) realloc(m_Index, (m_IndexCnt / HTML_REALLOC_STEP + 1) * HTML_REALLOC_STEP * sizeof(HtmlContentsItem));
|
||||
for (i = st; i < m_IndexCnt; i++) {
|
||||
f -> Read(&x, sizeof(x));
|
||||
m_Index[i].m_Name = (char*) malloc(x);
|
||||
f -> Read(m_Index[i].m_Name, x);
|
||||
f -> Read(&x, sizeof(x));
|
||||
m_Index[i].m_Page = (char*) malloc(x);
|
||||
f -> Read(m_Index[i].m_Page, x);
|
||||
m_Index[i].m_Book = book;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlHelpController::SaveCachedBook(HtmlBookRecord *book, wxOutputStream *f)
|
||||
{
|
||||
int i;
|
||||
int x;
|
||||
|
||||
/* save contents : */
|
||||
|
||||
x = 0;
|
||||
for (i = 0; i < m_ContentsCnt; i++) if (m_Contents[i].m_Book == book && m_Contents[i].m_Level > 0) x++;
|
||||
f -> Write(&x, sizeof(x));
|
||||
for (i = 0; i < m_ContentsCnt; i++) {
|
||||
if (m_Contents[i].m_Book != book || m_Contents[i].m_Level == 0) continue;
|
||||
x = m_Contents[i].m_Level;
|
||||
f -> Write(&x, sizeof(x));
|
||||
x = m_Contents[i].m_ID;
|
||||
f -> Write(&x, sizeof(x));
|
||||
x = strlen(m_Contents[i].m_Name) + 1;
|
||||
f -> Write(&x, sizeof(x));
|
||||
f -> Write(m_Contents[i].m_Name, x);
|
||||
x = strlen(m_Contents[i].m_Page) + 1;
|
||||
f -> Write(&x, sizeof(x));
|
||||
f -> Write(m_Contents[i].m_Page, x);
|
||||
}
|
||||
|
||||
/* save index : */
|
||||
|
||||
x = 0;
|
||||
for (i = 0; i < m_IndexCnt; i++) if (m_Index[i].m_Book == book && m_Index[i].m_Level > 0) x++;
|
||||
f -> Write(&x, sizeof(x));
|
||||
for (i = 0; i < m_IndexCnt; i++) {
|
||||
if (m_Index[i].m_Book != book || m_Index[i].m_Level == 0) continue;
|
||||
x = strlen(m_Index[i].m_Name) + 1;
|
||||
f -> Write(&x, sizeof(x));
|
||||
f -> Write(m_Index[i].m_Name, x);
|
||||
x = strlen(m_Index[i].m_Page) + 1;
|
||||
f -> Write(&x, sizeof(x));
|
||||
f -> Write(m_Index[i].m_Page, x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
169
src/html/htmlparser.cpp
Normal file
169
src/html/htmlparser.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: htmlparser.cpp
|
||||
// Purpose: wxHtmlParser class (generic parser)
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/url.h>
|
||||
#include <wx/html/htmldefs.h>
|
||||
#include <wx/html/htmlparser.h>
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlParser
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
|
||||
|
||||
|
||||
wxObject* wxHtmlParser::Parse(const wxString& source)
|
||||
{
|
||||
wxObject *result;
|
||||
|
||||
InitParser(source);
|
||||
DoParsing();
|
||||
result = GetProduct();
|
||||
DoneParser();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlParser::InitParser(const wxString& source)
|
||||
{
|
||||
m_Source = source;
|
||||
m_Cache = new wxHtmlTagsCache(m_Source);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlParser::DoneParser()
|
||||
{
|
||||
delete m_Cache;
|
||||
m_Cache = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define HTML_MAX_BUFLEN 1024
|
||||
|
||||
void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
|
||||
{
|
||||
char temp[HTML_BUFLEN], c;
|
||||
int i;
|
||||
int templen;
|
||||
|
||||
templen = 0;
|
||||
i = begin_pos;
|
||||
|
||||
while (i < end_pos) {
|
||||
c = m_Source[i];
|
||||
|
||||
// continue building word:
|
||||
if (c != '<') {
|
||||
temp[templen++] = c;
|
||||
if (templen == HTML_BUFLEN-1) {
|
||||
temp[templen] = 0;
|
||||
AddText(temp);
|
||||
templen = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
else if (c == '<') {
|
||||
wxHtmlTag tag(m_Source, i, end_pos, m_Cache);
|
||||
|
||||
if (templen) {
|
||||
temp[templen] = 0;
|
||||
AddText(temp);
|
||||
templen = 0;
|
||||
}
|
||||
AddTag(tag);
|
||||
if (tag.HasEnding()) i = tag.GetEndPos2();
|
||||
else i = tag.GetBeginPos();
|
||||
}
|
||||
}
|
||||
|
||||
if (templen) { // last word of block :-(
|
||||
temp[templen] = 0;
|
||||
AddText(temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlParser::AddTag(const wxHtmlTag& tag)
|
||||
{
|
||||
wxHtmlTagHandler *h;
|
||||
bool inner = FALSE;
|
||||
|
||||
h = (wxHtmlTagHandler*) m_HandlersHash.Get(tag.GetName());
|
||||
if (h)
|
||||
inner = h -> HandleTag(tag);
|
||||
if (!inner) {
|
||||
if (tag.HasEnding())
|
||||
DoParsing(tag.GetBeginPos(), tag.GetEndPos1());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
|
||||
{
|
||||
wxString s(handler -> GetSupportedTags());
|
||||
wxStringTokenizer tokenizer(s, ", ");
|
||||
|
||||
#if (wxVERSION_NUMBER < 2100)
|
||||
while (tokenizer.HasMoreToken())
|
||||
#else
|
||||
while (tokenizer.HasMoreTokens())
|
||||
#endif
|
||||
m_HandlersHash.Put(tokenizer.NextToken(), handler);
|
||||
|
||||
if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
|
||||
m_HandlersList.Append(handler);
|
||||
|
||||
handler -> SetParser(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlParser::~wxHtmlParser()
|
||||
{
|
||||
m_HandlersHash.Clear();
|
||||
m_HandlersList.DeleteContents(TRUE);
|
||||
m_HandlersList.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlTagHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler,wxObject)
|
||||
|
||||
#endif
|
248
src/html/htmltag.cpp
Normal file
248
src/html/htmltag.cpp
Normal file
@@ -0,0 +1,248 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: htmltag.cpp
|
||||
// Purpose: wxHtmlTag class (represents single tag)
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/html/htmltag.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlTagsCache
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS(wxHtmlTagsCache,wxObject)
|
||||
|
||||
#define CACHE_INCREMENT 64
|
||||
|
||||
wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source)
|
||||
{
|
||||
const char *src = source.c_str();
|
||||
int i, tg, pos, stpos;
|
||||
int lng = source.Length();
|
||||
char dummy[256];
|
||||
|
||||
m_Cache = NULL;
|
||||
m_CacheSize = 0;
|
||||
m_CachePos = 0;
|
||||
|
||||
pos = 0;
|
||||
while (pos < lng) {
|
||||
if (src[pos] == '<') { // tag found:
|
||||
if (m_CacheSize % CACHE_INCREMENT == 0)
|
||||
m_Cache = (sCacheItem*) realloc(m_Cache, (m_CacheSize + CACHE_INCREMENT) * sizeof(sCacheItem));
|
||||
tg = m_CacheSize++;
|
||||
m_Cache[tg].Key = stpos = pos++;
|
||||
dummy[0] = 0; i = 0;
|
||||
while ((src[pos] != '>') && (src[pos] != ' ')) {
|
||||
dummy[i] = src[pos++];
|
||||
if ((dummy[i] >= 'a') && (dummy[i] <= 'z')) dummy[i] -= ('a' - 'A');
|
||||
i++;
|
||||
}
|
||||
dummy[i] = 0;
|
||||
m_Cache[tg].Name = (char*) malloc(i+1);
|
||||
memcpy(m_Cache[tg].Name, dummy, i+1);
|
||||
|
||||
while (src[pos] != '>') pos++;
|
||||
|
||||
if (src[stpos+1] == '/') { // ending tag:
|
||||
m_Cache[tg].End1 = m_Cache[tg].End2 = -2;
|
||||
// find matching begin tag:
|
||||
for (i = tg; i >= 0; i--)
|
||||
if ((m_Cache[i].End1 == -1) && (strcmp(m_Cache[i].Name, dummy+1) == 0)) {
|
||||
m_Cache[i].End1 = stpos;
|
||||
m_Cache[i].End2 = pos + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_Cache[tg].End1 = m_Cache[tg].End2 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
// ok, we're done, now we'll free .Name members of cache - we don't need it anymore:
|
||||
for (i = 0; i < m_CacheSize; i++) {
|
||||
free(m_Cache[i].Name);
|
||||
m_Cache[i].Name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTagsCache::QueryTag(int at, int* end1, int* end2)
|
||||
{
|
||||
if (m_Cache == NULL) return;
|
||||
if (m_Cache[m_CachePos].Key != at) {
|
||||
int delta = (at < m_Cache[m_CachePos].Key) ? -1 : 1;
|
||||
do {m_CachePos += delta;} while (m_Cache[m_CachePos].Key != at);
|
||||
}
|
||||
*end1 = m_Cache[m_CachePos].End1;
|
||||
*end2 = m_Cache[m_CachePos].End2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlTag
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS(wxHtmlTag,wxObject)
|
||||
|
||||
wxHtmlTag::wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache) : wxObject()
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
|
||||
// fill-in name, params and begin pos:
|
||||
m_Name = m_Params = wxEmptyString;
|
||||
i = pos+1;
|
||||
if (source[i] == '/') {m_Ending = TRUE; i++;}
|
||||
else m_Ending = FALSE;
|
||||
|
||||
while ((i < end_pos) && ((c = source[i++]) != ' ') && (c != '>')) {
|
||||
if ((c >= 'a') && (c <= 'z')) c -= ('a' - 'A');
|
||||
m_Name += c;
|
||||
}
|
||||
|
||||
if (source[i-1] != '>')
|
||||
while ((i < end_pos) && ((c = source[i++]) != '>')) {
|
||||
if ((c >= 'a') && (c <= 'z')) c -= ('a' - 'A');
|
||||
m_Params += c;
|
||||
if (c == '"') {
|
||||
while ((i < end_pos) && ((c = source[i++]) != '"')) m_Params += c;
|
||||
m_Params += c;
|
||||
}
|
||||
}
|
||||
m_Begin = i;
|
||||
|
||||
cache -> QueryTag(pos, &m_End1, &m_End2);
|
||||
if (m_End1 > end_pos) m_End1 = end_pos;
|
||||
if (m_End2 > end_pos) m_End2 = end_pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlTag::HasParam(const wxString& par) const
|
||||
{
|
||||
const char *st = m_Params, *p = par;
|
||||
const char *st2, *p2;
|
||||
|
||||
if (*st == 0) return FALSE;
|
||||
if (*p == 0) return FALSE;
|
||||
for (st2 = st, p2 = p; ; st2++) {
|
||||
if (*p2 == 0) return TRUE;
|
||||
if (*st2 == 0) return FALSE;
|
||||
if (*p2 != *st2) p2 = p;
|
||||
if (*p2 == *st2) p2++;
|
||||
if (*st2 == ' ') p2 = p;
|
||||
else if (*st2 == '=') {
|
||||
p2 = p;
|
||||
while (*st2 != ' ') {
|
||||
if (*st2 == '"') {
|
||||
st2++;
|
||||
while (*st2 != '"') st2++;
|
||||
}
|
||||
st2++;
|
||||
if (*st2 == 0) return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxHtmlTag::GetParam(const wxString& par, bool with_commas) const
|
||||
{
|
||||
const char *st = m_Params, *p = par;
|
||||
const char *st2, *p2;
|
||||
bool comma;
|
||||
|
||||
if (*st == 0) return "";
|
||||
if (*p == 0) return "";
|
||||
for (st2 = st, p2 = p; ; st2++) {
|
||||
if (*p2 == 0) { // found
|
||||
wxString fnd = "";
|
||||
st2++; // '=' character
|
||||
comma = FALSE;
|
||||
if (!with_commas && (*(st2) == '"')) {st2++; comma = TRUE;}
|
||||
while (*st2 != 0) {
|
||||
if (*st2 == '"') comma = !comma;
|
||||
else if ((*st2 == ' ') && (!comma)) break;
|
||||
fnd += (*(st2++));
|
||||
}
|
||||
if (!with_commas && (*(st2-1) == '"')) fnd.RemoveLast();
|
||||
return fnd;
|
||||
}
|
||||
if (*st2 == 0) return "";
|
||||
if (*p2 != *st2) p2 = p;
|
||||
if (*p2 == *st2) p2++;
|
||||
if (*st2 == ' ') p2 = p;
|
||||
else if (*st2 == '=') {
|
||||
p2 = p;
|
||||
while (*st2 != ' ') {
|
||||
if (*st2 == '"') {
|
||||
st2++;
|
||||
while (*st2 != '"') st2++;
|
||||
}
|
||||
st2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTag::ScanParam(const wxString& par, char *format, ...) const
|
||||
{
|
||||
va_list argptr;
|
||||
wxString parval = GetParam(par);
|
||||
|
||||
va_start(argptr, format);
|
||||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__VISUALC__)
|
||||
sscanf((const char*)parval, format, va_arg(argptr, void *));
|
||||
#else
|
||||
vsscanf((const char*)parval, format, argptr);
|
||||
#endif
|
||||
|
||||
/*
|
||||
--- vsscanf is not defined under Cygwin or Mingw32 or M$ Visual C++ environment
|
||||
if this module doesn't compile with your compiler,
|
||||
modify the def statement and let me know. Thanks...
|
||||
|
||||
So far wxHtml functions are scanning only _one_ value
|
||||
so I workarounded this by supposing that there is only
|
||||
one ...-parameter
|
||||
*/
|
||||
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
#endif
|
542
src/html/htmlwin.cpp
Normal file
542
src/html/htmlwin.cpp
Normal file
@@ -0,0 +1,542 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: htmlwin.cpp
|
||||
// Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation)
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/html/htmlwin.h>
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
|
||||
///// This is my own wxBusyCursor. It works only with one window.
|
||||
|
||||
#if (defined __WXGTK__) && (wxVERSION_NUMBER < 2100)
|
||||
class wxLocalBusyCursor
|
||||
#else
|
||||
class wxLocalBusyCursor : public wxBusyCursor
|
||||
#endif
|
||||
{
|
||||
private:
|
||||
wxWindow *m_Wnd;
|
||||
public:
|
||||
#if (defined __WXGTK__) && (wxVERSION_NUMBER < 2100)
|
||||
wxLocalBusyCursor(wxWindow *w) {m_Wnd = w; m_Wnd -> SetCursor(*wxHOURGLASS_CURSOR);}
|
||||
~wxLocalBusyCursor() {m_Wnd -> SetCursor(*wxSTANDARD_CURSOR);}
|
||||
#else
|
||||
wxLocalBusyCursor(wxWindow *w) : wxBusyCursor() {}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlWindow
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#include <wx/arrimpl.cpp>
|
||||
WX_DEFINE_OBJARRAY(HtmlHistoryArray)
|
||||
|
||||
|
||||
wxHtmlWindow::wxHtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
|
||||
const wxString& name, bool scrollable) : wxScrolledWindow(parent, id, pos, size, wxVSCROLL, name)
|
||||
{
|
||||
m_tmpMouseMoved = FALSE;
|
||||
m_tmpCanDraw = TRUE;
|
||||
m_FS = new wxFileSystem();
|
||||
m_RelatedStatusBar = -1;
|
||||
m_RelatedFrame = NULL;
|
||||
m_TitleFormat = "%s";
|
||||
m_OpenedPage = m_OpenedAnchor = wxEmptyString;
|
||||
m_Cell = NULL;
|
||||
m_Parser = new wxHtmlWinParser(this);
|
||||
m_Parser -> SetFS(m_FS);
|
||||
SetBorders(10);
|
||||
m_HistoryPos = -1;
|
||||
m_HistoryOn = TRUE;
|
||||
m_Scrollable = scrollable;
|
||||
SetPage("<html><body></body></html>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlWindow::~wxHtmlWindow()
|
||||
{
|
||||
HistoryClear();
|
||||
|
||||
if (m_Cell) delete m_Cell;
|
||||
|
||||
wxList *parser_data = m_Parser -> GetTempData();
|
||||
if (parser_data) delete parser_data;
|
||||
|
||||
delete m_Parser;
|
||||
delete m_FS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format)
|
||||
{
|
||||
m_RelatedFrame = frame;
|
||||
m_TitleFormat = format;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::SetRelatedStatusBar(int bar)
|
||||
{
|
||||
m_RelatedStatusBar = bar;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes)
|
||||
{
|
||||
m_Parser -> SetFonts(normal_face, normal_italic_mode, fixed_face, fixed_italic_mode, sizes);
|
||||
if (!m_OpenedPage.IsEmpty()) LoadPage(m_OpenedPage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlWindow::SetPage(const wxString& source)
|
||||
{
|
||||
wxClientDC *dc = new wxClientDC(this);
|
||||
|
||||
dc -> SetMapMode(wxMM_TEXT);
|
||||
SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
|
||||
m_OpenedPage = m_OpenedAnchor = wxEmptyString;
|
||||
m_Parser -> SetDC(dc);
|
||||
if (m_Cell) delete m_Cell;
|
||||
m_Cell = (wxHtmlContainerCell*) m_Parser -> Parse(source);
|
||||
delete dc;
|
||||
m_Cell -> SetIndent(m_Borders, HTML_INDENT_ALL, HTML_UNITS_PIXELS);
|
||||
m_Cell -> SetAlignHor(HTML_ALIGN_CENTER);
|
||||
CreateLayout();
|
||||
Refresh();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool wxHtmlWindow::LoadPage(const wxString& location)
|
||||
{
|
||||
wxFSFile *f;
|
||||
bool rt_val;
|
||||
wxLocalBusyCursor b(this);
|
||||
|
||||
m_tmpCanDraw = FALSE;
|
||||
if (m_HistoryOn && (m_HistoryPos != -1)) { // store scroll position into history item
|
||||
int x, y;
|
||||
ViewStart(&x, &y);
|
||||
m_History[m_HistoryPos].SetPos(y);
|
||||
}
|
||||
|
||||
if (location[0] == '#') { // local anchor
|
||||
wxString anch = location.Mid(1) /*1 to end*/;
|
||||
m_tmpCanDraw = TRUE;
|
||||
rt_val = ScrollToAnchor(anch);
|
||||
}
|
||||
|
||||
else {
|
||||
// load&display it:
|
||||
if (m_RelatedStatusBar != -1) {
|
||||
m_RelatedFrame -> SetStatusText(_("Connecting..."), m_RelatedStatusBar);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
f = m_FS -> OpenFile(location);
|
||||
if (f == NULL) {
|
||||
wxString err;
|
||||
|
||||
err.Printf(_("The browser is unable to open requested location :\n\n%s"), WXSTRINGCAST location);
|
||||
wxMessageBox(err, "Error");
|
||||
m_tmpCanDraw = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
else {
|
||||
wxNode *node;
|
||||
wxString src = wxEmptyString;
|
||||
|
||||
if (m_RelatedStatusBar != -1) {
|
||||
wxString msg = _("Loading : ") + location;
|
||||
m_RelatedFrame -> SetStatusText(msg, m_RelatedStatusBar);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
node = m_Filters.GetFirst();
|
||||
while (node){
|
||||
wxHtmlFilter *h = (wxHtmlFilter*) node -> GetData();
|
||||
if (h -> CanRead(*f)) {
|
||||
src = h -> ReadFile(*f);
|
||||
break;
|
||||
}
|
||||
node = node -> GetNext();
|
||||
}
|
||||
if (src == wxEmptyString) src = m_DefaultFilter.ReadFile(*f);
|
||||
|
||||
m_FS -> ChangePathTo(f -> GetLocation());
|
||||
rt_val = SetPage(src);
|
||||
m_OpenedPage = f -> GetLocation();
|
||||
if (f -> GetAnchor() != wxEmptyString) {
|
||||
m_tmpCanDraw = TRUE;
|
||||
ScrollToAnchor(f -> GetAnchor());
|
||||
m_tmpCanDraw = FALSE;
|
||||
}
|
||||
|
||||
delete f;
|
||||
|
||||
if (m_RelatedStatusBar != -1) m_RelatedFrame -> SetStatusText(_("Done"), m_RelatedStatusBar);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_HistoryOn) { // add this page to history there:
|
||||
int c = m_History.GetCount() - (m_HistoryPos + 1);
|
||||
|
||||
m_HistoryPos++;
|
||||
for (int i = 0; i < c; i++)
|
||||
m_History.Remove(m_HistoryPos);
|
||||
m_History.Add(new HtmlHistoryItem(m_OpenedPage, m_OpenedAnchor));
|
||||
}
|
||||
|
||||
m_tmpCanDraw = TRUE;
|
||||
Refresh();
|
||||
return rt_val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor)
|
||||
{
|
||||
const wxHtmlCell *c = m_Cell -> Find(HTML_COND_ISANCHOR, &anchor);
|
||||
if (!c) return FALSE;
|
||||
else {
|
||||
int y;
|
||||
|
||||
for (y = 0; c != NULL; c = c -> GetParent()) y += c -> GetPosY();
|
||||
Scroll(-1, y / HTML_SCROLL_STEP);
|
||||
m_OpenedAnchor = anchor;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxHtmlWindow::SetTitle(const wxString& title)
|
||||
{
|
||||
if (m_RelatedFrame) {
|
||||
wxString tit;
|
||||
tit.Printf(m_TitleFormat, title.c_str());
|
||||
m_RelatedFrame -> SetTitle(tit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::CreateLayout()
|
||||
{
|
||||
int ClientWidth, ClientHeight;
|
||||
|
||||
if (!m_Cell) return;
|
||||
GetClientSize(&ClientWidth, &ClientHeight);
|
||||
m_Cell -> Layout(ClientWidth);
|
||||
if (m_Scrollable)
|
||||
SetScrollbars(HTML_SCROLL_STEP, HTML_SCROLL_STEP,
|
||||
m_Cell -> GetWidth() / HTML_SCROLL_STEP,
|
||||
m_Cell -> GetHeight() / HTML_SCROLL_STEP
|
||||
/*cheat: top-level frag is always container*/ );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path)
|
||||
{
|
||||
wxString oldpath;
|
||||
wxString tmp;
|
||||
|
||||
if (path != wxEmptyString) {
|
||||
oldpath = cfg -> GetPath();
|
||||
cfg -> SetPath(path);
|
||||
}
|
||||
|
||||
m_Borders = cfg -> Read("wxHtmlWindow/Borders", m_Borders);
|
||||
m_Parser -> m_FontFaceFixed = cfg -> Read("wxHtmlWindow/FontFaceFixed", m_Parser -> m_FontFaceFixed);
|
||||
m_Parser -> m_FontFaceNormal = cfg -> Read("wxHtmlWindow/FontFaceNormal", m_Parser -> m_FontFaceNormal);
|
||||
m_Parser -> m_ItalicModeFixed = cfg -> Read("wxHtmlWindow/ItalicModeFixed", m_Parser -> m_ItalicModeFixed);
|
||||
m_Parser -> m_ItalicModeNormal = cfg -> Read("wxHtmlWindow/ItalicModeNormal", m_Parser -> m_ItalicModeNormal);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
tmp.Printf("wxHtmlWindow/FontsSize%i", i);
|
||||
m_Parser -> m_FontsSizes[i] = cfg -> Read(tmp, m_Parser -> m_FontsSizes[i]);
|
||||
}
|
||||
|
||||
if (path != wxEmptyString)
|
||||
cfg -> SetPath(oldpath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path)
|
||||
{
|
||||
wxString oldpath;
|
||||
wxString tmp;
|
||||
|
||||
if (path != wxEmptyString) {
|
||||
oldpath = cfg -> GetPath();
|
||||
cfg -> SetPath(path);
|
||||
}
|
||||
|
||||
cfg -> Write("wxHtmlWindow/Borders", (long) m_Borders);
|
||||
cfg -> Write("wxHtmlWindow/FontFaceFixed", m_Parser -> m_FontFaceFixed);
|
||||
cfg -> Write("wxHtmlWindow/FontFaceNormal", m_Parser -> m_FontFaceNormal);
|
||||
cfg -> Write("wxHtmlWindow/ItalicModeFixed", (long) m_Parser -> m_ItalicModeFixed);
|
||||
cfg -> Write("wxHtmlWindow/ItalicModeNormal", (long) m_Parser -> m_ItalicModeNormal);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
tmp.Printf("wxHtmlWindow/FontsSize%i", i);
|
||||
cfg -> Write(tmp, (long) m_Parser -> m_FontsSizes[i]);
|
||||
}
|
||||
|
||||
if (path != wxEmptyString)
|
||||
cfg -> SetPath(oldpath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlWindow::HistoryBack()
|
||||
{
|
||||
wxString a, l;
|
||||
|
||||
if (m_HistoryPos < 1) return FALSE;
|
||||
|
||||
m_HistoryPos--;
|
||||
|
||||
l = m_History[m_HistoryPos].GetPage();
|
||||
a = m_History[m_HistoryPos].GetAnchor();
|
||||
m_HistoryOn = FALSE;
|
||||
if (a == wxEmptyString) LoadPage(l);
|
||||
else LoadPage(l + "#" + a);
|
||||
m_HistoryOn = TRUE;
|
||||
Scroll(0, m_History[m_HistoryPos].GetPos());
|
||||
Refresh();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlWindow::HistoryForward()
|
||||
{
|
||||
wxString a, l;
|
||||
|
||||
if (m_HistoryPos == -1) return FALSE;
|
||||
if (m_HistoryPos >= (int)m_History.GetCount() - 1)return FALSE;
|
||||
|
||||
m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage()
|
||||
|
||||
m_HistoryPos++;
|
||||
l = m_History[m_HistoryPos].GetPage();
|
||||
a = m_History[m_HistoryPos].GetAnchor();
|
||||
m_HistoryOn = FALSE;
|
||||
if (a == wxEmptyString) LoadPage(l);
|
||||
else LoadPage(l + "#" + a);
|
||||
m_HistoryOn = TRUE;
|
||||
Scroll(0, m_History[m_HistoryPos].GetPos());
|
||||
Refresh();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::HistoryClear()
|
||||
{
|
||||
m_History.Empty();
|
||||
m_HistoryPos = -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxList wxHtmlWindow::m_Filters;
|
||||
wxHtmlFilterPlainText wxHtmlWindow::m_DefaultFilter;
|
||||
|
||||
void wxHtmlWindow::AddFilter(wxHtmlFilter *filter)
|
||||
{
|
||||
m_Filters.DeleteContents(TRUE);
|
||||
m_Filters.Append(filter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::OnLinkClicked(const wxString& link)
|
||||
{
|
||||
LoadPage(link);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::OnDraw(wxDC& dc)
|
||||
{
|
||||
int x, y;
|
||||
wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
|
||||
int v_y, v_h;
|
||||
|
||||
if (!m_tmpCanDraw) return;
|
||||
dc.SetMapMode(wxMM_TEXT);
|
||||
#if defined(_MSC_VER) && (_MSC_VER == 1200)
|
||||
::SetMapMode((HDC)dc.GetHDC(), MM_TEXT);
|
||||
#endif
|
||||
dc.SetBackgroundMode(wxTRANSPARENT);
|
||||
ViewStart(&x, &y);
|
||||
|
||||
while (upd) {
|
||||
v_y = upd.GetY();
|
||||
v_h = upd.GetH();
|
||||
if (m_Cell) m_Cell -> Draw(dc, 0, 0, y * HTML_SCROLL_STEP + v_y, y * HTML_SCROLL_STEP + v_h + v_y);
|
||||
upd++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
wxScrolledWindow::OnSize(event);
|
||||
CreateLayout();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::OnKeyDown(wxKeyEvent& event)
|
||||
{
|
||||
int dummy;
|
||||
int sty, szy, cliy;
|
||||
|
||||
ViewStart(&dummy, &sty);
|
||||
GetClientSize(&dummy, &cliy); cliy /= HTML_SCROLL_STEP;
|
||||
GetVirtualSize(&dummy, &szy); szy /= HTML_SCROLL_STEP;
|
||||
|
||||
switch (event.KeyCode()) {
|
||||
case WXK_PAGEUP :
|
||||
case WXK_PRIOR :
|
||||
Scroll(-1, sty - cliy);
|
||||
break;
|
||||
case WXK_PAGEDOWN :
|
||||
case WXK_NEXT :
|
||||
Scroll(-1, sty + cliy);
|
||||
break;
|
||||
case WXK_HOME :
|
||||
Scroll(-1, 0);
|
||||
break;
|
||||
case WXK_END :
|
||||
Scroll(-1, szy - cliy);
|
||||
break;
|
||||
case WXK_UP :
|
||||
Scroll(-1, sty - 1);
|
||||
break;
|
||||
case WXK_DOWN :
|
||||
Scroll(-1, sty + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
m_tmpMouseMoved = TRUE;
|
||||
|
||||
if (event.ButtonDown()) {
|
||||
int sx, sy;
|
||||
wxPoint pos;
|
||||
wxString lnk;
|
||||
|
||||
ViewStart(&sx, &sy); sx *= HTML_SCROLL_STEP; sy *= HTML_SCROLL_STEP;
|
||||
pos = event.GetPosition();
|
||||
|
||||
if (m_Cell)
|
||||
m_Cell -> OnMouseClick(this, sx + pos.x, sy + pos.y, event.ButtonDown(1), event.ButtonDown(2), event.ButtonDown(3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWindow::OnIdle(wxIdleEvent& event)
|
||||
{
|
||||
static wxCursor cur_hand(wxCURSOR_HAND), cur_arrow(wxCURSOR_ARROW);
|
||||
|
||||
if (m_tmpMouseMoved && (m_Cell != NULL)) {
|
||||
int sx, sy;
|
||||
int x, y;
|
||||
wxString lnk;
|
||||
|
||||
ViewStart(&sx, &sy); sx *= HTML_SCROLL_STEP; sy *= HTML_SCROLL_STEP;
|
||||
wxGetMousePosition(&x, &y);
|
||||
ScreenToClient(&x, &y);
|
||||
lnk = m_Cell -> GetLink(sx + x, sy + y);
|
||||
|
||||
if (lnk == wxEmptyString) {
|
||||
SetCursor(cur_arrow);
|
||||
if (m_RelatedStatusBar != -1) m_RelatedFrame -> SetStatusText(wxEmptyString, m_RelatedStatusBar);
|
||||
}
|
||||
else {
|
||||
SetCursor(cur_hand);
|
||||
if (m_RelatedStatusBar != -1) m_RelatedFrame -> SetStatusText(lnk, m_RelatedStatusBar);
|
||||
}
|
||||
m_tmpMouseMoved = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
|
||||
EVT_SIZE(wxHtmlWindow::OnSize)
|
||||
EVT_LEFT_DOWN(wxHtmlWindow::OnMouseEvent)
|
||||
EVT_MOTION(wxHtmlWindow::OnMouseEvent)
|
||||
EVT_IDLE(wxHtmlWindow::OnIdle)
|
||||
EVT_KEY_DOWN(wxHtmlWindow::OnKeyDown)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///// default mod handlers are forced there:
|
||||
|
||||
FORCE_LINK(mod_layout)
|
||||
FORCE_LINK(mod_fonts)
|
||||
FORCE_LINK(mod_image)
|
||||
FORCE_LINK(mod_list)
|
||||
FORCE_LINK(mod_pre)
|
||||
FORCE_LINK(mod_hline)
|
||||
FORCE_LINK(mod_links)
|
||||
FORCE_LINK(mod_tables)
|
||||
|
||||
|
||||
#endif
|
288
src/html/htmlwinparser.cpp
Normal file
288
src/html/htmlwinparser.cpp
Normal file
@@ -0,0 +1,288 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: htmlwinparser.cpp
|
||||
// Purpose: wxHtmlParser class (generic parser)
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include <wx/html/htmldefs.h>
|
||||
#include <wx/html/htmlwinparser.h>
|
||||
#include <wx/html/htmlwin.h>
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlWinParser
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinParser,wxHtmlParser)
|
||||
|
||||
wxList wxHtmlWinParser::m_Modules;
|
||||
|
||||
wxHtmlWinParser::wxHtmlWinParser(wxWindow *wnd) : wxHtmlParser()
|
||||
{
|
||||
m_Window = wnd;
|
||||
m_Container = NULL;
|
||||
m_DC = NULL;
|
||||
m_CharHeight = m_CharWidth = 0;
|
||||
m_UseLink = FALSE;
|
||||
|
||||
{
|
||||
int i, j, k, l, m;
|
||||
for (i = 0; i < 2; i++)
|
||||
for (j = 0; j < 2; j++)
|
||||
for (k = 0; k < 2; k++)
|
||||
for (l = 0; l < 2; l++)
|
||||
for (m = 0; m < 7; m++)
|
||||
m_FontsTable[i][j][k][l][m] = NULL;
|
||||
#ifdef __WXMSW__
|
||||
int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
|
||||
#else
|
||||
int default_sizes[7] = {10, 12, 14, 16, 19, 24, 32};
|
||||
#endif
|
||||
SetFonts("", wxSLANT, "", wxSLANT, default_sizes);
|
||||
}
|
||||
|
||||
// fill in wxHtmlParser's tables:
|
||||
wxNode *node = m_Modules.GetFirst();
|
||||
while (node){
|
||||
wxHtmlTagsModule *mod = (wxHtmlTagsModule*) node -> GetData();
|
||||
mod -> FillHandlersTable(this);
|
||||
node = node -> GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWinParser::AddModule(wxHtmlTagsModule *module)
|
||||
{
|
||||
m_Modules.Append(module);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWinParser::SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes)
|
||||
{
|
||||
for (int i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];
|
||||
m_FontFaceFixed = fixed_face;
|
||||
m_FontFaceNormal = normal_face;
|
||||
m_ItalicModeFixed = fixed_italic_mode;
|
||||
m_ItalicModeNormal = normal_italic_mode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWinParser::InitParser(const wxString& source)
|
||||
{
|
||||
wxHtmlParser::InitParser(source);
|
||||
wxASSERT_MSG(m_DC != NULL, _("no DC assigned to wxHtmlWinParser!!"));
|
||||
|
||||
m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE;
|
||||
m_FontSize = 0;
|
||||
CreateCurrentFont(); // we're selecting default font into
|
||||
m_DC -> GetTextExtent("H", &m_CharWidth, &m_CharHeight);
|
||||
/* NOTE : we're not using GetCharWidth/Height() because
|
||||
of differences under X and win
|
||||
*/
|
||||
|
||||
m_Link = "";
|
||||
m_LinkColor.Set(0, 0, 0xFF);
|
||||
m_ActualColor.Set(0, 0, 0);
|
||||
m_Align = HTML_ALIGN_LEFT;
|
||||
m_tmpLastWasSpace = FALSE;
|
||||
|
||||
OpenContainer();
|
||||
|
||||
OpenContainer();
|
||||
m_Container -> InsertCell(new wxHtmlColourCell(m_ActualColor));
|
||||
m_Container -> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWinParser::DoneParser()
|
||||
{
|
||||
m_Container = NULL;
|
||||
wxHtmlParser::DoneParser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject* wxHtmlWinParser::GetProduct()
|
||||
{
|
||||
wxHtmlContainerCell *top;
|
||||
|
||||
CloseContainer();
|
||||
OpenContainer();
|
||||
GetContainer() -> SetIndent(m_CharHeight, HTML_INDENT_TOP);
|
||||
top = m_Container;
|
||||
while (top -> GetParent()) top = top -> GetParent();
|
||||
return top;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxList* wxHtmlWinParser::GetTempData()
|
||||
{
|
||||
int i, j, k, l, m;
|
||||
wxFont *f;
|
||||
wxList *lst = wxHtmlParser::GetTempData();
|
||||
|
||||
if (lst == NULL) lst = new wxList;
|
||||
lst -> DeleteContents(TRUE);
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
for (j = 0; j < 2; j++)
|
||||
for (k = 0; k < 2; k++)
|
||||
for (l = 0; l < 2; l++)
|
||||
for (m = 0; m < 7; m++) {
|
||||
f = m_FontsTable[i][j][k][l][m];
|
||||
if (f) lst -> Append(f);
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWinParser::AddText(const char* txt)
|
||||
{
|
||||
wxHtmlCell *c;
|
||||
int i = 0, x, lng = strlen(txt);
|
||||
char temp[HTML_BUFLEN];
|
||||
register char d;
|
||||
int templen = 0;
|
||||
|
||||
if (m_tmpLastWasSpace) {
|
||||
while ((i < lng) && ((txt[i] == '\n') || (txt[i] == '\r') || (txt[i] == ' ') || (txt[i] == '\t'))) i++;
|
||||
}
|
||||
|
||||
while (i < lng) {
|
||||
x = 0;
|
||||
d = temp[templen++] = txt[i];
|
||||
if ((d == '\n') || (d == '\r') || (d == ' ') || (d == '\t')) {
|
||||
i++, x++;
|
||||
while ((i < lng) && ((txt[i] == '\n') || (txt[i] == '\r') || (txt[i] == ' ') || (txt[i] == '\t'))) i++, x++;
|
||||
}
|
||||
else i++;
|
||||
|
||||
if (x) {
|
||||
temp[templen-1] = ' ';
|
||||
temp[templen] = 0;
|
||||
templen = 0;
|
||||
c = new wxHtmlWordCell(temp, *(GetDC()));
|
||||
if (m_UseLink) c -> SetLink(m_Link);
|
||||
m_Container -> InsertCell(c);
|
||||
m_tmpLastWasSpace = TRUE;
|
||||
}
|
||||
}
|
||||
if (templen) {
|
||||
temp[templen] = 0;
|
||||
c = new wxHtmlWordCell(temp, *(GetDC()));
|
||||
if (m_UseLink) c -> SetLink(m_Link);
|
||||
m_Container -> InsertCell(c);
|
||||
m_tmpLastWasSpace = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlContainerCell* wxHtmlWinParser::OpenContainer()
|
||||
{
|
||||
m_Container = new wxHtmlContainerCell(m_Container);
|
||||
m_Container -> SetAlignHor(m_Align);
|
||||
m_tmpLastWasSpace = TRUE;
|
||||
/* to avoid space being first character in paragraph */
|
||||
return m_Container;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c)
|
||||
{
|
||||
m_tmpLastWasSpace = TRUE;
|
||||
/* to avoid space being first character in paragraph */
|
||||
return m_Container = c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlContainerCell* wxHtmlWinParser::CloseContainer()
|
||||
{
|
||||
m_Container = m_Container -> GetParent();
|
||||
return m_Container;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxFont* wxHtmlWinParser::CreateCurrentFont()
|
||||
{
|
||||
int fb = GetFontBold(),
|
||||
fi = GetFontItalic(),
|
||||
fu = GetFontUnderlined(),
|
||||
ff = GetFontFixed(),
|
||||
fs = GetFontSize() + 2 /*remap from <-2;4> to <0;7>*/ ;
|
||||
|
||||
if (m_FontsTable[fb][fi][fu][ff][fs] == NULL) {
|
||||
m_FontsTable[fb][fi][fu][ff][fs] =
|
||||
//wxTheFontList -> FindOrCreateFont(
|
||||
new wxFont(
|
||||
m_FontsSizes[fs],
|
||||
ff ? wxMODERN : wxSWISS,
|
||||
fi ? (ff ? m_ItalicModeFixed : m_ItalicModeNormal) : wxNORMAL,
|
||||
fb ? wxBOLD : wxNORMAL,
|
||||
fu ? TRUE : FALSE, ff ? m_FontFaceFixed : m_FontFaceNormal);
|
||||
}
|
||||
m_DC -> SetFont(*(m_FontsTable[fb][fi][fu][ff][fs]));
|
||||
return (m_FontsTable[fb][fi][fu][ff][fs]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlWinTagHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler)
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlTagsModule
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule)
|
||||
|
||||
|
||||
bool wxHtmlTagsModule::OnInit()
|
||||
{
|
||||
wxHtmlWinParser::AddModule(this);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTagsModule::OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
175
src/html/mod_fonts.cpp
Normal file
175
src/html/mod_fonts.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_fonts.cpp
|
||||
// Purpose: wxHtml module for fonts & colors of fonts
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
FORCE_LINK_ME(mod_fonts)
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(FONT, "FONT")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
unsigned long tmp;
|
||||
wxColour oldclr = m_WParser -> GetActualColor();
|
||||
int oldsize = m_WParser -> GetFontSize();
|
||||
|
||||
if (tag.HasParam("COLOR")) {
|
||||
wxColour clr;
|
||||
tag.ScanParam("COLOR", "#%lX", &tmp);
|
||||
clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
|
||||
m_WParser -> SetActualColor(clr);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr));
|
||||
}
|
||||
|
||||
if (tag.HasParam("SIZE")) {
|
||||
tag.ScanParam("SIZE", "%li", &tmp);
|
||||
m_WParser -> SetFontSize(tmp);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
}
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
if (oldclr != m_WParser -> GetActualColor()) {
|
||||
m_WParser -> SetActualColor(oldclr);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
|
||||
}
|
||||
if (oldsize != m_WParser -> GetFontSize()) {
|
||||
m_WParser -> SetFontSize(oldsize);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(FONT)
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(FACES, "U,I,B,TT")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
int fixed = m_WParser -> GetFontFixed(),
|
||||
italic = m_WParser -> GetFontItalic(),
|
||||
underlined = m_WParser -> GetFontUnderlined(),
|
||||
bold = m_WParser -> GetFontBold();
|
||||
|
||||
if (tag.GetName() == "U")
|
||||
m_WParser -> SetFontUnderlined(TRUE);
|
||||
else if (tag.GetName() == "B")
|
||||
m_WParser -> SetFontBold(TRUE);
|
||||
else if (tag.GetName() == "I")
|
||||
m_WParser -> SetFontItalic(TRUE);
|
||||
else
|
||||
m_WParser -> SetFontFixed(TRUE);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
m_WParser -> SetFontUnderlined(underlined);
|
||||
m_WParser -> SetFontBold(bold);
|
||||
m_WParser -> SetFontItalic(italic);
|
||||
m_WParser -> SetFontFixed(fixed);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(FACES)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
int old_size, old_b, old_i, old_u, old_f, old_al;
|
||||
wxHtmlContainerCell *c;
|
||||
|
||||
old_size = m_WParser -> GetFontSize();
|
||||
old_b = m_WParser -> GetFontBold();
|
||||
old_i = m_WParser -> GetFontItalic();
|
||||
old_u = m_WParser -> GetFontUnderlined();
|
||||
old_f = m_WParser -> GetFontFixed();
|
||||
old_al = m_WParser -> GetAlign();
|
||||
|
||||
m_WParser -> SetFontBold(TRUE);
|
||||
m_WParser -> SetFontItalic(FALSE);
|
||||
m_WParser -> SetFontUnderlined(FALSE);
|
||||
m_WParser -> SetFontFixed(FALSE);
|
||||
|
||||
if (tag.GetName() == "H1")
|
||||
m_WParser -> SetFontSize(+4);
|
||||
else if (tag.GetName() == "H2")
|
||||
m_WParser -> SetFontSize(+3);
|
||||
else if (tag.GetName() == "H3")
|
||||
m_WParser -> SetFontSize(+2);
|
||||
else if (tag.GetName() == "H4") {
|
||||
m_WParser -> SetFontSize(+2);
|
||||
m_WParser -> SetFontItalic(TRUE);
|
||||
m_WParser -> SetFontBold(FALSE);
|
||||
}
|
||||
else if (tag.GetName() == "H5")
|
||||
m_WParser -> SetFontSize(+1);
|
||||
else if (tag.GetName() == "H6") {
|
||||
m_WParser -> SetFontSize(+1);
|
||||
m_WParser -> SetFontItalic(TRUE);
|
||||
m_WParser -> SetFontBold(FALSE);
|
||||
}
|
||||
|
||||
c = m_WParser -> GetContainer();
|
||||
if (c -> GetFirstCell()) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
c = m_WParser -> GetContainer();
|
||||
}
|
||||
c = m_WParser -> GetContainer();
|
||||
|
||||
c -> SetAlign(tag);
|
||||
c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
|
||||
m_WParser -> SetAlign(c -> GetAlignHor());
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
m_WParser -> SetFontSize(old_size);
|
||||
m_WParser -> SetFontBold(old_b);
|
||||
m_WParser -> SetFontItalic(old_i);
|
||||
m_WParser -> SetFontUnderlined(old_u);
|
||||
m_WParser -> SetFontFixed(old_f);
|
||||
m_WParser -> SetAlign(old_al);
|
||||
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
c = m_WParser -> GetContainer();
|
||||
c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(Hx)
|
||||
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Fonts)
|
||||
|
||||
TAGS_MODULE_ADD(FONT)
|
||||
TAGS_MODULE_ADD(FACES)
|
||||
TAGS_MODULE_ADD(Hx)
|
||||
|
||||
TAGS_MODULE_END(Fonts)
|
||||
|
||||
|
||||
#endif
|
88
src/html/mod_hline.cpp
Normal file
88
src/html/mod_hline.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_hline.cpp
|
||||
// Purpose: wxHtml module for horizontal line (HR tag)
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
#include <wx/html/htmlcell.h>
|
||||
|
||||
FORCE_LINK_ME(mod_hline)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlLineCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxHtmlLineCell : public wxHtmlCell
|
||||
{
|
||||
public:
|
||||
wxHtmlLineCell(int size) : wxHtmlCell() {m_Height = size;}
|
||||
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
|
||||
void Layout(int w) {m_Width = w; if (m_Next) m_Next -> Layout(w);}
|
||||
};
|
||||
|
||||
|
||||
void wxHtmlLineCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
wxBrush mybrush("BLACK", wxSOLID);
|
||||
wxPen mypen("BLACK", 1, wxSOLID);
|
||||
dc.SetBrush(mybrush);
|
||||
dc.SetPen(mypen);
|
||||
dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height);
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The list handler:
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(HR, "HR")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
wxHtmlContainerCell *c;
|
||||
int sz;
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
c = m_WParser -> OpenContainer();
|
||||
|
||||
c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_VERTICAL);
|
||||
c -> SetAlignHor(HTML_ALIGN_CENTER);
|
||||
c -> SetAlign(tag);
|
||||
c -> SetWidthFloat(tag);
|
||||
if (tag.HasParam("SIZE")) tag.ScanParam("SIZE", "%i", &sz);
|
||||
else sz = 1;
|
||||
c -> InsertCell(new wxHtmlLineCell(sz));
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(HR)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(HLine)
|
||||
|
||||
TAGS_MODULE_ADD(HR)
|
||||
|
||||
TAGS_MODULE_END(HLine)
|
||||
|
||||
#endif
|
147
src/html/mod_image.cpp
Normal file
147
src/html/mod_image.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_image.cpp
|
||||
// Purpose: wxHtml module for displaying images
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
#include <wx/wxhtml.h>
|
||||
#include <wx/image.h>
|
||||
|
||||
FORCE_LINK_ME(mod_image)
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxHtmlImageCell
|
||||
// Image/bitmap
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
class wxHtmlImageCell : public wxHtmlCell
|
||||
{
|
||||
public:
|
||||
wxBitmap *m_Image;
|
||||
|
||||
wxHtmlImageCell(wxFSFile *input, int w = -1, int h = -1, int align = HTML_ALIGN_BOTTOM);
|
||||
~wxHtmlImageCell() {if (m_Image) delete m_Image;}
|
||||
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxHtmlImageCell
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
wxHtmlImageCell::wxHtmlImageCell(wxFSFile *input, int w, int h, int align) : wxHtmlCell()
|
||||
{
|
||||
wxImage *img;
|
||||
int ww, hh;
|
||||
wxString m = input -> GetMimeType();
|
||||
wxInputStream *s = input -> GetStream();
|
||||
|
||||
#if wxVERSION_NUMBER < 2100
|
||||
/* NOTE : use this *old* code only if you have old 2.0.1 wxWindows distribution
|
||||
and don't want to upgrade it with stuffs from add-on/wxwin201 */
|
||||
if (wxMimeTypesManager::IsOfType(m, "image/png")) img = new wxImage(*s, wxBITMAP_TYPE_PNG);
|
||||
else if (wxMimeTypesManager::IsOfType(m, "image/jpeg")) img = new wxImage(*s, wxBITMAP_TYPE_JPEG);
|
||||
else if (wxMimeTypesManager::IsOfType(m, "image/bmp")) img = new wxImage(*s, wxBITMAP_TYPE_BMP);
|
||||
else if (wxMimeTypesManager::IsOfType(m, "image/gif")) img = new wxImage(*s, wxBITMAP_TYPE_GIF);
|
||||
else if (wxMimeTypesManager::IsOfType(m, "image/tiff")) img = new wxImage(*s, wxBITMAP_TYPE_TIF);
|
||||
else if (wxMimeTypesManager::IsOfType(m, "image/xpm")) img = new wxImage(*s, wxBITMAP_TYPE_XPM);
|
||||
else if (wxMimeTypesManager::IsOfType(m, "image/xbm")) img = new wxImage(*s, wxBITMAP_TYPE_XBM);
|
||||
else img = NULL;
|
||||
#else
|
||||
img = new wxImage(*s, m);
|
||||
#endif
|
||||
|
||||
m_Image = NULL;
|
||||
if (img && (img -> Ok())) {
|
||||
ww = img -> GetWidth();
|
||||
hh = img -> GetHeight();
|
||||
if (w != -1) m_Width = w; else m_Width = ww;
|
||||
if (h != -1) m_Height = h; else m_Height = hh;
|
||||
if ((m_Width != ww) || (m_Height != hh)) {
|
||||
wxImage img2 = img -> Scale(m_Width, m_Height);
|
||||
m_Image = new wxBitmap(img2.ConvertToBitmap());
|
||||
}
|
||||
else
|
||||
m_Image = new wxBitmap(img -> ConvertToBitmap());
|
||||
delete img;
|
||||
}
|
||||
switch (align) {
|
||||
case HTML_ALIGN_TOP :
|
||||
m_Descent = m_Height; break;
|
||||
case HTML_ALIGN_CENTER :
|
||||
m_Descent = m_Height / 2; break;
|
||||
case HTML_ALIGN_BOTTOM : default :
|
||||
m_Descent = 0; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
if (m_Image)
|
||||
dc.DrawBitmap(*m_Image, x + m_PosX, y + m_PosY, TRUE);
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// tag handler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
TAG_HANDLER_BEGIN(IMG, "IMG")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
if (tag.HasParam("SRC")) {
|
||||
int w = -1, h = -1;
|
||||
int al;
|
||||
wxFSFile *str;
|
||||
wxString tmp = tag.GetParam("SRC");
|
||||
|
||||
str = m_WParser -> GetFS() -> OpenFile(tmp);
|
||||
if (tag.HasParam("WIDTH")) tag.ScanParam("WIDTH", "%i", &w);
|
||||
if (tag.HasParam("HEIGHT")) tag.ScanParam("HEIGHT", "%i", &h);
|
||||
al = HTML_ALIGN_BOTTOM;
|
||||
if (tag.HasParam("ALIGN")) {
|
||||
wxString alstr = tag.GetParam("ALIGN");
|
||||
alstr.MakeUpper(); // for the case alignment was in ".."
|
||||
if (alstr == "TEXTTOP") al = HTML_ALIGN_TOP;
|
||||
else if ((alstr == "CENTER") || (alstr == "ABSCENTER")) al = HTML_ALIGN_CENTER;
|
||||
}
|
||||
if (str) {
|
||||
wxHtmlCell *cel = new wxHtmlImageCell(str, w, h, al);
|
||||
cel -> SetLink(m_WParser -> GetLink());
|
||||
m_WParser -> GetContainer() -> InsertCell(cel);
|
||||
delete str;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(IMAGE)
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Image)
|
||||
|
||||
TAGS_MODULE_ADD(IMG)
|
||||
|
||||
TAGS_MODULE_END(Image)
|
||||
|
||||
|
||||
#endif
|
223
src/html/mod_layout.cpp
Normal file
223
src/html/mod_layout.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_layout.cpp
|
||||
// Purpose: wxHtml module for basic paragraphs/layout handling
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
#include <wx/html/htmlwin.h>
|
||||
|
||||
FORCE_LINK_ME(mod_layout)
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(P, "P")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
if (m_WParser -> GetContainer() -> GetFirstCell() != NULL) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
}
|
||||
m_WParser -> GetContainer() -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
|
||||
m_WParser -> GetContainer() -> SetAlign(tag);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(P)
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(BR, "BR")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
int al = m_WParser -> GetContainer() -> GetAlignHor();
|
||||
wxHtmlContainerCell *c;
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
c = m_WParser -> OpenContainer();
|
||||
c -> SetAlignHor(al);
|
||||
c -> SetAlign(tag);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(BR)
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(CENTER, "CENTER")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
int old = m_WParser -> GetAlign();
|
||||
wxHtmlContainerCell *c = m_WParser -> GetContainer();
|
||||
|
||||
m_WParser -> SetAlign(HTML_ALIGN_CENTER);
|
||||
if (c -> GetFirstCell() != NULL) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
}
|
||||
else
|
||||
c -> SetAlignHor(HTML_ALIGN_CENTER);
|
||||
|
||||
if (tag.HasEnding()) {
|
||||
ParseInner(tag);
|
||||
|
||||
m_WParser -> SetAlign(old);
|
||||
if (c -> GetFirstCell() != NULL) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
}
|
||||
else
|
||||
c -> SetAlignHor(old);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(CENTER)
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(DIV, "DIV")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
int old = m_WParser -> GetAlign();
|
||||
wxHtmlContainerCell *c = m_WParser -> GetContainer();
|
||||
if (c -> GetFirstCell() != NULL) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
c = m_WParser -> GetContainer();
|
||||
c -> SetAlign(tag);
|
||||
m_WParser -> SetAlign(c -> GetAlignHor());
|
||||
}
|
||||
else {
|
||||
c -> SetAlign(tag);
|
||||
m_WParser -> SetAlign(c -> GetAlignHor());
|
||||
}
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
m_WParser -> SetAlign(old);
|
||||
if (c -> GetFirstCell() != NULL) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
}
|
||||
else
|
||||
c -> SetAlignHor(old);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(DIV)
|
||||
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(TITLE, "TITLE")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
if (m_WParser -> GetWindow()) {
|
||||
wxHtmlWindow *wfr = (wxHtmlWindow*)(m_WParser -> GetWindow());
|
||||
if (wfr) {
|
||||
wxString title = "";
|
||||
wxString *src = m_WParser -> GetSource();
|
||||
|
||||
for (int i = tag.GetBeginPos(); i < tag.GetEndPos1(); i++) title += (*src)[i];
|
||||
wfr -> SetTitle(title);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(TITLE)
|
||||
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(BODY, "BODY")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
unsigned long tmp;
|
||||
wxColour clr;
|
||||
|
||||
if (tag.HasParam("TEXT")) {
|
||||
tag.ScanParam("TEXT", "#%lX", &tmp);
|
||||
clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
|
||||
m_WParser -> SetActualColor(clr);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr));
|
||||
}
|
||||
|
||||
if (tag.HasParam("LINK")) {
|
||||
tag.ScanParam("LINK", "#%lX", &tmp);
|
||||
clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
|
||||
m_WParser -> SetLinkColor(clr);
|
||||
}
|
||||
|
||||
if (tag.HasParam("BGCOLOR")) {
|
||||
tag.ScanParam("BGCOLOR", "#%lX", &tmp);
|
||||
clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr, HTML_CLR_BACKGROUND));
|
||||
if (m_WParser -> GetWindow() != NULL)
|
||||
m_WParser -> GetWindow() -> SetBackgroundColour(clr);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(BODY)
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(BLOCKQUOTE, "BLOCKQUOTE")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
wxHtmlContainerCell *c;
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
c = m_WParser -> OpenContainer();
|
||||
if (c -> GetAlignHor() == HTML_ALIGN_RIGHT)
|
||||
c -> SetIndent(5 * m_WParser -> GetCharWidth(), HTML_INDENT_RIGHT);
|
||||
else
|
||||
c -> SetIndent(5 * m_WParser -> GetCharWidth(), HTML_INDENT_LEFT);
|
||||
c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
|
||||
m_WParser -> OpenContainer();
|
||||
ParseInner(tag);
|
||||
c = m_WParser -> CloseContainer();
|
||||
c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_BOTTOM);
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(BLOCKQUOTE)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Layout)
|
||||
|
||||
TAGS_MODULE_ADD(P)
|
||||
TAGS_MODULE_ADD(BR)
|
||||
TAGS_MODULE_ADD(CENTER)
|
||||
TAGS_MODULE_ADD(DIV)
|
||||
TAGS_MODULE_ADD(TITLE)
|
||||
TAGS_MODULE_ADD(BODY)
|
||||
TAGS_MODULE_ADD(BLOCKQUOTE)
|
||||
|
||||
TAGS_MODULE_END(Layout)
|
||||
|
||||
#endif
|
80
src/html/mod_links.cpp
Normal file
80
src/html/mod_links.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_links.cpp
|
||||
// Purpose: wxHtml module for links & anchors
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
#include <wx/wxhtml.h>
|
||||
|
||||
FORCE_LINK_ME(mod_links)
|
||||
|
||||
|
||||
class wxHtmlAnchorCell : public wxHtmlCell
|
||||
{
|
||||
private:
|
||||
wxString m_AnchorName;
|
||||
|
||||
public:
|
||||
wxHtmlAnchorCell(const wxString& name) : wxHtmlCell() {m_AnchorName = name;}
|
||||
virtual const wxHtmlCell* Find(int condition, const void* param) const
|
||||
{
|
||||
if ((condition == HTML_COND_ISANCHOR) && (m_AnchorName == (*((const wxString*)param))))
|
||||
return this;
|
||||
else
|
||||
return wxHtmlCell::Find(condition, param);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(A, "A")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
if (tag.HasParam("NAME")) {
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlAnchorCell(tag.GetParam("NAME")));
|
||||
}
|
||||
|
||||
if (tag.HasParam("HREF")) {
|
||||
wxString oldlnk = m_WParser -> GetLink();
|
||||
wxColour oldclr = m_WParser -> GetActualColor();
|
||||
int oldund = m_WParser -> GetFontUnderlined();
|
||||
|
||||
m_WParser -> SetActualColor(m_WParser -> GetLinkColor());
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(m_WParser -> GetLinkColor()));
|
||||
m_WParser -> SetFontUnderlined(TRUE);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
m_WParser -> SetLink(tag.GetParam("HREF"));
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
m_WParser -> SetLink(oldlnk);
|
||||
m_WParser -> SetFontUnderlined(oldund);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
m_WParser -> SetActualColor(oldclr);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(A)
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Links)
|
||||
|
||||
TAGS_MODULE_ADD(A)
|
||||
|
||||
TAGS_MODULE_END(Links)
|
||||
|
||||
|
||||
#endif
|
142
src/html/mod_list.cpp
Normal file
142
src/html/mod_list.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_list.cpp
|
||||
// Purpose: wxHtml module for lists
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
#include <wx/html/htmlcell.h>
|
||||
|
||||
FORCE_LINK_ME(mod_list)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlListmarkCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxHtmlListmarkCell : public wxHtmlCell
|
||||
{
|
||||
private:
|
||||
wxBrush m_Brush;
|
||||
public:
|
||||
wxHtmlListmarkCell(wxDC *dc, const wxColour& clr);
|
||||
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
|
||||
};
|
||||
|
||||
wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxSOLID)
|
||||
{
|
||||
m_Width = dc -> GetCharWidth();
|
||||
m_Height = dc -> GetCharHeight();
|
||||
m_Descent = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
dc.SetBrush(m_Brush);
|
||||
dc.DrawEllipse(x + m_PosX + m_Width / 4, y + m_PosY + m_Height / 4, m_Width / 2, m_Width / 2);
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The list handler:
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
|
||||
|
||||
TAG_HANDLER_VARS
|
||||
int m_Numbering;
|
||||
// this is number of actual item of list or 0 for dots
|
||||
|
||||
TAG_HANDLER_CONSTR(OLULLI)
|
||||
{
|
||||
m_Numbering = 0;
|
||||
}
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
wxHtmlContainerCell *c;
|
||||
|
||||
// List Item:
|
||||
if (tag.GetName() == "LI") {
|
||||
if (!tag.IsEnding()) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> CloseContainer();
|
||||
|
||||
c = m_WParser -> OpenContainer();
|
||||
c -> SetWidthFloat(2 * m_WParser -> GetCharWidth(), HTML_UNITS_PIXELS);
|
||||
c -> SetAlignHor(HTML_ALIGN_RIGHT);
|
||||
if (m_Numbering == 0)
|
||||
c -> InsertCell(new wxHtmlListmarkCell(m_WParser -> GetDC(), m_WParser -> GetActualColor()));
|
||||
else {
|
||||
wxString mark;
|
||||
mark.Printf("%i.", m_Numbering);
|
||||
c -> InsertCell(new wxHtmlWordCell(mark, *(m_WParser -> GetDC())));
|
||||
}
|
||||
m_WParser -> CloseContainer();
|
||||
|
||||
c = m_WParser -> OpenContainer();
|
||||
c -> SetIndent(m_WParser -> GetCharWidth() / 4, HTML_INDENT_LEFT);
|
||||
c -> SetWidthFloat(-2 * m_WParser -> GetCharWidth(), HTML_UNITS_PIXELS);
|
||||
|
||||
m_WParser -> OpenContainer();
|
||||
|
||||
if (m_Numbering != 0) m_Numbering++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Begin of List (not-numbered): "UL", "OL"
|
||||
else {
|
||||
int oldnum = m_Numbering;
|
||||
|
||||
if (tag.GetName() == "UL") m_Numbering = 0;
|
||||
else m_Numbering = 1;
|
||||
|
||||
c = m_WParser -> GetContainer();
|
||||
if (c -> GetFirstCell() != NULL) {
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
c = m_WParser -> GetContainer();
|
||||
}
|
||||
c -> SetAlignHor(HTML_ALIGN_LEFT);
|
||||
c -> SetIndent(2 * m_WParser -> GetCharWidth(), HTML_INDENT_LEFT);
|
||||
m_WParser -> OpenContainer() -> SetAlignVer(HTML_ALIGN_TOP);
|
||||
|
||||
m_WParser -> OpenContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
ParseInner(tag);
|
||||
m_WParser -> CloseContainer();
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
|
||||
m_Numbering = oldnum;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(OLULLI)
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(List)
|
||||
|
||||
TAGS_MODULE_ADD(OLULLI)
|
||||
|
||||
TAGS_MODULE_END(List)
|
||||
|
||||
#endif
|
157
src/html/mod_pre.cpp
Normal file
157
src/html/mod_pre.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_pre.cpp
|
||||
// Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
#include <wx/html/htmlcell.h>
|
||||
#include <wx/tokenzr.h>
|
||||
|
||||
FORCE_LINK_ME(mod_pre)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlCodeCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxHtmlPRECell : public wxHtmlCell
|
||||
{
|
||||
private:
|
||||
wxString** m_Text;
|
||||
// list of wxString objects.
|
||||
int m_LinesCnt;
|
||||
// number of lines
|
||||
int m_LineHeight;
|
||||
// height of single line of text
|
||||
|
||||
public:
|
||||
wxHtmlPRECell(const wxString& s, wxDC& dc);
|
||||
~wxHtmlPRECell();
|
||||
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
|
||||
};
|
||||
|
||||
|
||||
wxHtmlPRECell::wxHtmlPRECell(const wxString& s, wxDC& dc) : wxHtmlCell()
|
||||
{
|
||||
wxStringTokenizer tokenizer(s, "\n");
|
||||
wxString tmp;
|
||||
long int x, z;
|
||||
int i;
|
||||
|
||||
m_LineHeight = dc.GetCharHeight();
|
||||
m_LinesCnt = 0;
|
||||
m_Text = NULL;
|
||||
m_Width = m_Height = 0;
|
||||
|
||||
i = 0;
|
||||
#if (wxVERSION_NUMBER < 2100)
|
||||
while (tokenizer.HasMoreToken()) {
|
||||
#else
|
||||
while (tokenizer.HasMoreTokens()) {
|
||||
#endif
|
||||
if (i % 10 == 0) m_Text = (wxString**) realloc(m_Text, sizeof(wxString*) * (i + 10));
|
||||
tmp = tokenizer.NextToken();
|
||||
tmp.Replace(" ", " ", TRUE);
|
||||
tmp.Replace(""", "\"", TRUE);
|
||||
tmp.Replace("<", "<", TRUE);
|
||||
tmp.Replace(">", ">", TRUE);
|
||||
tmp.Replace("&", "&", TRUE);
|
||||
tmp.Replace("\t", " ", TRUE);
|
||||
tmp.Replace("\r", "", TRUE);
|
||||
m_Text[i++] = new wxString(tmp);
|
||||
|
||||
dc.GetTextExtent(tmp, &x, &z, &z);
|
||||
if (x > m_Width) m_Width = x;
|
||||
m_Height += m_LineHeight;
|
||||
m_LinesCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlPRECell::~wxHtmlPRECell()
|
||||
{
|
||||
for (int i = 0; i < m_LinesCnt; i++) delete m_Text[i];
|
||||
free(m_Text);
|
||||
}
|
||||
|
||||
|
||||
void wxHtmlPRECell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||
{
|
||||
for (int i = 0; i < m_LinesCnt; i++)
|
||||
dc.DrawText(*(m_Text[i]), x + m_PosX, y + m_PosY + m_LineHeight * i);
|
||||
|
||||
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The list handler:
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(PRE, "PRE")
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
wxHtmlContainerCell *c;
|
||||
|
||||
int fixed = m_WParser -> GetFontFixed(),
|
||||
italic = m_WParser -> GetFontItalic(),
|
||||
underlined = m_WParser -> GetFontUnderlined(),
|
||||
bold = m_WParser -> GetFontBold(),
|
||||
fsize = m_WParser -> GetFontSize();
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
c = m_WParser -> OpenContainer();
|
||||
c -> SetAlignHor(HTML_ALIGN_LEFT);
|
||||
c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_VERTICAL);
|
||||
|
||||
m_WParser -> SetFontUnderlined(FALSE);
|
||||
m_WParser -> SetFontBold(FALSE);
|
||||
m_WParser -> SetFontItalic(FALSE);
|
||||
m_WParser -> SetFontFixed(TRUE);
|
||||
m_WParser -> SetFontSize(0);
|
||||
c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
|
||||
{
|
||||
wxString cit;
|
||||
cit = m_WParser -> GetSource() -> Mid(tag.GetBeginPos(), tag.GetEndPos1() - tag.GetBeginPos());
|
||||
c -> InsertCell(new wxHtmlPRECell(cit, *(m_WParser -> GetDC())));
|
||||
}
|
||||
|
||||
m_WParser -> SetFontUnderlined(underlined);
|
||||
m_WParser -> SetFontBold(bold);
|
||||
m_WParser -> SetFontItalic(italic);
|
||||
m_WParser -> SetFontFixed(fixed);
|
||||
m_WParser -> SetFontSize(fsize);
|
||||
c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
|
||||
m_WParser -> CloseContainer();
|
||||
m_WParser -> OpenContainer();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(PRE)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Pre)
|
||||
|
||||
TAGS_MODULE_ADD(PRE)
|
||||
|
||||
TAGS_MODULE_END(Pre)
|
||||
|
||||
#endif
|
480
src/html/mod_tables.cpp
Normal file
480
src/html/mod_tables.cpp
Normal file
@@ -0,0 +1,480 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mod_tables.cpp
|
||||
// Purpose: wxHtml module for tables
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/defs.h"
|
||||
#if wxUSE_HTML
|
||||
|
||||
/*
|
||||
REMARKS:
|
||||
1. This version of mod_tables doesn't support auto-layout algorithm.
|
||||
This means that all columns are of same width unless explicitly specified.
|
||||
*/
|
||||
|
||||
|
||||
#include <wx/html/forcelink.h>
|
||||
#include <wx/html/mod_templ.h>
|
||||
|
||||
#include <wx/html/htmlcell.h>
|
||||
|
||||
FORCE_LINK_ME(mod_tables)
|
||||
|
||||
|
||||
#define TABLE_BORDER_CLR_1 wxColour(0xC5, 0xC2, 0xC5)
|
||||
#define TABLE_BORDER_CLR_2 wxColour(0x62, 0x61, 0x62)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxHtmlTableCell
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
typedef struct {
|
||||
int width, units; // universal
|
||||
int leftpos, pixwidth, maxrealwidth; // temporary (depends on width of table)
|
||||
} colStruct;
|
||||
|
||||
typedef enum {
|
||||
cellSpan,
|
||||
cellUsed,
|
||||
cellFree
|
||||
} cellState;
|
||||
|
||||
typedef struct {
|
||||
wxHtmlContainerCell *cont;
|
||||
int colspan, rowspan;
|
||||
int minheight, valign;
|
||||
cellState flag;
|
||||
} cellStruct;
|
||||
|
||||
|
||||
class wxHtmlTableCell : public wxHtmlContainerCell
|
||||
{
|
||||
protected:
|
||||
/* These are real attributes: */
|
||||
bool m_HasBorders;
|
||||
// should we draw borders or not?
|
||||
int m_NumCols, m_NumRows;
|
||||
// number of columns; rows
|
||||
colStruct *m_ColsInfo;
|
||||
// array of column information
|
||||
cellStruct **m_CellInfo;
|
||||
// 2D array of all cells in the table : m_CellInfo[row][column]
|
||||
int m_Spacing;
|
||||
// spaces between cells
|
||||
int m_Padding;
|
||||
// cells internal indentation
|
||||
|
||||
private:
|
||||
/* ...and these are valid only during parsing of table: */
|
||||
int m_ActualCol, m_ActualRow;
|
||||
// number of actual column (ranging from 0..m_NumCols)
|
||||
|
||||
// default values (for table and row):
|
||||
int m_tBkg, m_rBkg;
|
||||
wxString m_tValign, m_rValign;
|
||||
|
||||
|
||||
public:
|
||||
wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& tag);
|
||||
~wxHtmlTableCell();
|
||||
virtual void Layout(int w);
|
||||
|
||||
void AddRow(const wxHtmlTag& tag);
|
||||
void AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag);
|
||||
private:
|
||||
void ReallocCols(int cols);
|
||||
void ReallocRows(int rows);
|
||||
// reallocates memory to given number of cols/rows
|
||||
// and changes m_NumCols/m_NumRows value to reflect this change
|
||||
// NOTE! You CAN'T change m_NumCols/m_NumRows before calling this!!
|
||||
};
|
||||
|
||||
|
||||
|
||||
wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& tag)
|
||||
: wxHtmlContainerCell(parent)
|
||||
{
|
||||
m_HasBorders = tag.HasParam("BORDER");
|
||||
m_ColsInfo = NULL;
|
||||
m_NumCols = m_NumRows = 0;
|
||||
m_CellInfo = NULL;
|
||||
m_ActualCol = m_ActualRow = -1;
|
||||
|
||||
/* scan params: */
|
||||
m_tBkg = m_rBkg = -1;
|
||||
if (tag.HasParam("BGCOLOR")) tag.ScanParam("BGCOLOR", "#%lX", &m_tBkg);
|
||||
if (tag.HasParam("VALIGN")) m_tValign = tag.GetParam("VALIGN"); else m_tValign = wxEmptyString;
|
||||
if (tag.HasParam("CELLSPACING")) tag.ScanParam("CELLSPACING", "%i", &m_Spacing); else m_Spacing = 2;
|
||||
if (tag.HasParam("CELLPADDING")) tag.ScanParam("CELLPADDING", "%i", &m_Padding); else m_Padding = 3;
|
||||
|
||||
if (m_HasBorders)
|
||||
SetBorder(TABLE_BORDER_CLR_1, TABLE_BORDER_CLR_2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxHtmlTableCell::~wxHtmlTableCell()
|
||||
{
|
||||
if (m_ColsInfo) free(m_ColsInfo);
|
||||
if (m_CellInfo) {
|
||||
for (int i = 0; i < m_NumRows; i++)
|
||||
free(m_CellInfo[i]);
|
||||
free(m_CellInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTableCell::ReallocCols(int cols)
|
||||
{
|
||||
int i,j;
|
||||
|
||||
for (i = 0; i < m_NumRows; i++) {
|
||||
m_CellInfo[i] = (cellStruct*) realloc(m_CellInfo[i], sizeof(cellStruct) * cols);
|
||||
for (j = m_NumCols; j < cols; j++)
|
||||
m_CellInfo[i][j].flag = cellFree;
|
||||
}
|
||||
|
||||
m_ColsInfo = (colStruct*) realloc(m_ColsInfo, sizeof(colStruct) * cols);
|
||||
for (j = m_NumCols; j < cols; j++) {
|
||||
m_ColsInfo[j].width = 0;
|
||||
m_ColsInfo[j].units = HTML_UNITS_PERCENT;
|
||||
}
|
||||
|
||||
m_NumCols = cols;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTableCell::ReallocRows(int rows)
|
||||
{
|
||||
m_CellInfo = (cellStruct**) realloc(m_CellInfo, sizeof(cellStruct*) * rows);
|
||||
if (m_NumCols != 0) {
|
||||
int x = rows - 1;
|
||||
m_CellInfo[x] = (cellStruct*) malloc(sizeof(cellStruct) * m_NumCols);
|
||||
for (int i = 0; i < m_NumCols; i++)
|
||||
m_CellInfo[x][i].flag = cellFree;
|
||||
}
|
||||
else
|
||||
m_CellInfo[rows - 1] = NULL;
|
||||
m_NumRows = rows;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTableCell::AddRow(const wxHtmlTag& tag)
|
||||
{
|
||||
if (m_ActualRow + 1 > m_NumRows - 1)
|
||||
ReallocRows(m_ActualRow + 2);
|
||||
m_ActualRow++;
|
||||
m_ActualCol = -1;
|
||||
|
||||
/* scan params: */
|
||||
m_rBkg = m_tBkg;
|
||||
if (tag.HasParam("BGCOLOR")) tag.ScanParam("BGCOLOR", "#%lX", &m_rBkg);
|
||||
if (tag.HasParam("VALIGN")) m_rValign = tag.GetParam("VALIGN"); else m_rValign = m_tValign;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
||||
{
|
||||
do {
|
||||
m_ActualCol++;
|
||||
} while ((m_ActualCol < m_NumCols) && (m_CellInfo[m_ActualRow][m_ActualCol].flag != cellFree));
|
||||
if (m_ActualCol > m_NumCols - 1)
|
||||
ReallocCols(m_ActualCol + 1);
|
||||
|
||||
int r = m_ActualRow, c = m_ActualCol;
|
||||
|
||||
m_CellInfo[r][c].cont = cell;
|
||||
m_CellInfo[r][c].colspan = 1;
|
||||
m_CellInfo[r][c].rowspan = 1;
|
||||
m_CellInfo[r][c].flag = cellUsed;
|
||||
m_CellInfo[r][c].minheight = 0;
|
||||
m_CellInfo[r][c].valign = HTML_ALIGN_TOP;
|
||||
|
||||
/* scan for parameters: */
|
||||
|
||||
// width:
|
||||
{
|
||||
if (tag.HasParam("WIDTH")) {
|
||||
wxString wd = tag.GetParam("WIDTH");
|
||||
|
||||
if (wd[wd.Length()-1] == '%') {
|
||||
sscanf(wd.c_str(), "%i%%", &m_ColsInfo[c].width);
|
||||
m_ColsInfo[c].units = HTML_UNITS_PERCENT;
|
||||
}
|
||||
else {
|
||||
sscanf(wd.c_str(), "%i", &m_ColsInfo[c].width);
|
||||
m_ColsInfo[c].units = HTML_UNITS_PIXELS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// spanning:
|
||||
{
|
||||
if (tag.HasParam("COLSPAN")) tag.ScanParam("COLSPAN", "%i", &m_CellInfo[r][c].colspan);
|
||||
if (tag.HasParam("ROWSPAN")) tag.ScanParam("ROWSPAN", "%i", &m_CellInfo[r][c].rowspan);
|
||||
if ((m_CellInfo[r][c].colspan != 1) || (m_CellInfo[r][c].rowspan != 1)) {
|
||||
int i, j;
|
||||
|
||||
if (r + m_CellInfo[r][c].rowspan > m_NumRows) ReallocRows(r + m_CellInfo[r][c].rowspan);
|
||||
if (c + m_CellInfo[r][c].colspan > m_NumCols) ReallocCols(c + m_CellInfo[r][c].colspan);
|
||||
for (i = r; i < r + m_CellInfo[r][c].rowspan; i++)
|
||||
for (j = c; j < c + m_CellInfo[r][c].colspan; j++)
|
||||
m_CellInfo[i][j].flag = cellSpan;
|
||||
m_CellInfo[r][c].flag = cellUsed;
|
||||
}
|
||||
}
|
||||
|
||||
//background color:
|
||||
{
|
||||
int bk = m_rBkg;
|
||||
if (tag.HasParam("BGCOLOR")) tag.ScanParam("BGCOLOR", "#%lX", &bk);
|
||||
if (bk != -1) {
|
||||
wxColour clr = wxColour((bk & 0xFF0000) >> 16 , (bk & 0x00FF00) >> 8, (bk & 0x0000FF));
|
||||
cell -> SetBackgroundColour(clr);
|
||||
}
|
||||
}
|
||||
if (m_HasBorders)
|
||||
cell -> SetBorder(TABLE_BORDER_CLR_2, TABLE_BORDER_CLR_1);
|
||||
|
||||
// vertical alignment:
|
||||
{
|
||||
wxString valign;
|
||||
if (tag.HasParam("VALIGN")) valign = tag.GetParam("VALIGN"); else valign = m_tValign;
|
||||
valign.MakeUpper();
|
||||
if (valign == "TOP") m_CellInfo[r][c].valign = HTML_ALIGN_TOP;
|
||||
else if (valign == "BOTTOM") m_CellInfo[r][c].valign = HTML_ALIGN_BOTTOM;
|
||||
else m_CellInfo[r][c].valign = HTML_ALIGN_CENTER;
|
||||
}
|
||||
|
||||
cell -> SetIndent(m_Padding, HTML_INDENT_ALL, HTML_UNITS_PIXELS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void wxHtmlTableCell::Layout(int w)
|
||||
{
|
||||
/*
|
||||
|
||||
WIDTH ADJUSTING :
|
||||
|
||||
*/
|
||||
|
||||
if (m_WidthFloatUnits == HTML_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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
LAYOUTING :
|
||||
|
||||
*/
|
||||
|
||||
/* 1. setup columns widths: */
|
||||
{
|
||||
int wpix = m_Width - (m_NumCols + 1) * m_Spacing;
|
||||
int i, j;
|
||||
int wtemp = 0;
|
||||
|
||||
// 1a. setup fixed-width columns:
|
||||
for (i = 0; i < m_NumCols; i++)
|
||||
if (m_ColsInfo[i].units == HTML_UNITS_PIXELS)
|
||||
wpix -= (m_ColsInfo[i].pixwidth = m_ColsInfo[i].width);
|
||||
|
||||
// 1b. setup floating-width columns:
|
||||
for (i = 0; i < m_NumCols; i++)
|
||||
if ((m_ColsInfo[i].units == HTML_UNITS_PERCENT) && (m_ColsInfo[i].width != 0))
|
||||
wtemp += (m_ColsInfo[i].pixwidth = m_ColsInfo[i].width * wpix / 100);
|
||||
wpix -= wtemp;
|
||||
|
||||
// 1c. setup defalut columns (no width specification supplied):
|
||||
// NOTE! This algorithm doesn't conform to HTML standard : it assigns equal widths
|
||||
// instead of optimal
|
||||
for (i = j = 0; i < m_NumCols; i++)
|
||||
if (m_ColsInfo[i].width == 0) j++;
|
||||
for (i = 0; i < m_NumCols; i++)
|
||||
if (m_ColsInfo[i].width == 0)
|
||||
m_ColsInfo[i].pixwidth = wpix / j;
|
||||
}
|
||||
|
||||
/* 2. compute positions of columns: */
|
||||
{
|
||||
int wpos = m_Spacing;
|
||||
for (int i = 0; i < m_NumCols; i++) {
|
||||
m_ColsInfo[i].leftpos = wpos;
|
||||
wpos += m_ColsInfo[i].pixwidth + m_Spacing;
|
||||
}
|
||||
}
|
||||
|
||||
/* 3. sub-layout all cells: */
|
||||
{
|
||||
int *ypos = (int*) malloc(sizeof(int) * (m_NumRows + 1));
|
||||
|
||||
int actcol, actrow;
|
||||
int fullwid;
|
||||
wxHtmlContainerCell *actcell;
|
||||
|
||||
for (actrow = 0; actrow <= m_NumRows; actrow++) ypos[actrow] = m_Spacing;
|
||||
|
||||
for (actrow = 0; actrow < m_NumRows; actrow++) {
|
||||
|
||||
// 3a. sub-layout and detect max height:
|
||||
|
||||
for (actcol = 0; actcol < m_NumCols; actcol++) {
|
||||
if (m_CellInfo[actrow][actcol].flag != cellUsed) continue;
|
||||
actcell = m_CellInfo[actrow][actcol].cont;
|
||||
fullwid = 0;
|
||||
for (int i = actcol; i < m_CellInfo[actrow][actcol].colspan + actcol; i++)
|
||||
fullwid += m_ColsInfo[i].pixwidth;
|
||||
actcell -> SetMinHeight(m_CellInfo[actrow][actcol].minheight, m_CellInfo[actrow][actcol].valign);
|
||||
actcell -> Layout(fullwid);
|
||||
|
||||
if (ypos[actrow] + actcell -> GetHeight() + m_CellInfo[actrow][actcol].rowspan * m_Spacing > ypos[actrow + m_CellInfo[actrow][actcol].rowspan])
|
||||
ypos[actrow + m_CellInfo[actrow][actcol].rowspan] =
|
||||
ypos[actrow] + actcell -> GetHeight() + m_CellInfo[actrow][actcol].rowspan * m_Spacing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (actrow = 0; actrow < m_NumRows; actrow++) {
|
||||
|
||||
// 3b. place cells in row & let'em all have same height:
|
||||
|
||||
for (actcol = 0; actcol < m_NumCols; actcol++) {
|
||||
if (m_CellInfo[actrow][actcol].flag != cellUsed) continue;
|
||||
actcell = m_CellInfo[actrow][actcol].cont;
|
||||
actcell -> SetMinHeight(
|
||||
ypos[actrow + m_CellInfo[actrow][actcol].rowspan] - ypos[actrow] - m_CellInfo[actrow][actcol].rowspan * m_Spacing,
|
||||
m_CellInfo[actrow][actcol].valign);
|
||||
fullwid = 0;
|
||||
for (int i = actcol; i < m_CellInfo[actrow][actcol].colspan + actcol; i++)
|
||||
fullwid += m_ColsInfo[i].pixwidth;
|
||||
actcell -> Layout(fullwid);
|
||||
actcell -> SetPos(m_ColsInfo[actcol].leftpos, ypos[actrow]);
|
||||
}
|
||||
|
||||
}
|
||||
m_Height = ypos[m_NumRows];
|
||||
free(ypos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The tables handler:
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
|
||||
|
||||
TAG_HANDLER_VARS
|
||||
wxHtmlTableCell* m_Table;
|
||||
wxString m_tAlign, m_rAlign;
|
||||
int m_OldAlign;
|
||||
|
||||
TAG_HANDLER_CONSTR(TABLE)
|
||||
{
|
||||
m_Table = NULL;
|
||||
m_tAlign = m_rAlign = wxEmptyString;
|
||||
m_OldAlign = HTML_ALIGN_LEFT;
|
||||
}
|
||||
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
wxHtmlContainerCell *c;
|
||||
|
||||
// new table started, backup upper-level table (if any) and create new:
|
||||
if (tag.GetName() == "TABLE") {
|
||||
wxHtmlTableCell *oldt = m_Table;
|
||||
wxHtmlContainerCell *oldcont;
|
||||
int m_OldAlign;
|
||||
|
||||
oldcont = c = m_WParser -> OpenContainer();
|
||||
|
||||
c -> SetWidthFloat(tag);
|
||||
m_Table = new wxHtmlTableCell(c, tag);
|
||||
m_OldAlign = m_WParser -> GetAlign();
|
||||
m_tAlign = wxEmptyString;
|
||||
if (tag.HasParam("ALIGN")) m_tAlign = tag.GetParam("ALIGN");
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
m_WParser -> SetAlign(m_OldAlign);
|
||||
m_WParser -> SetContainer(oldcont);
|
||||
m_WParser -> CloseContainer();
|
||||
m_Table = oldt;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
else if (m_Table && !tag.IsEnding()) {
|
||||
// new row in table
|
||||
if (tag.GetName() == "TR") {
|
||||
m_Table -> AddRow(tag);
|
||||
m_rAlign = m_tAlign;
|
||||
if (tag.HasParam("ALIGN")) m_rAlign = tag.GetParam("ALIGN");
|
||||
}
|
||||
|
||||
// new cell
|
||||
else {
|
||||
m_WParser -> SetAlign(m_OldAlign);
|
||||
c = m_WParser -> SetContainer(new wxHtmlContainerCell(m_Table));
|
||||
m_Table -> AddCell(c, tag);
|
||||
|
||||
m_WParser -> OpenContainer();
|
||||
|
||||
if (tag.GetName() == "TH") /*header style*/ {
|
||||
m_WParser -> SetAlign(HTML_ALIGN_CENTER);
|
||||
}
|
||||
|
||||
{
|
||||
wxString als;
|
||||
|
||||
als = m_rAlign;
|
||||
if (tag.HasParam("ALIGN")) als = tag.GetParam("ALIGN");
|
||||
als.MakeUpper();
|
||||
if (als == "RIGHT") m_WParser -> SetAlign(HTML_ALIGN_RIGHT);
|
||||
else if (als == "CENTER") m_WParser -> SetAlign(HTML_ALIGN_CENTER);
|
||||
}
|
||||
m_WParser -> OpenContainer();
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TAG_HANDLER_END(TABLE)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Tables)
|
||||
|
||||
TAGS_MODULE_ADD(TABLE)
|
||||
|
||||
TAGS_MODULE_END(Tables)
|
||||
|
||||
|
||||
#endif
|
73
src/html/search.cpp
Normal file
73
src/html/search.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: search.cpp
|
||||
// Purpose: search engine
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#include <wx/defs.h>
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORDLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
#include "search.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxSearchEngine
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
void wxSearchEngine::LookFor(const wxString& keyword)
|
||||
{
|
||||
if (m_Keyword) free(m_Keyword);
|
||||
m_Keyword = (char*) malloc(keyword.Length() + 1);
|
||||
strcpy(m_Keyword, keyword.c_str());
|
||||
for (int i = strlen(m_Keyword) - 1; i >= 0; i--)
|
||||
if ((m_Keyword[i] >= 'A') && (m_Keyword[i] <= 'Z'))
|
||||
m_Keyword[i] += 'a' - 'A';
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxSearchEngine::Scan(wxInputStream *stream)
|
||||
{
|
||||
wxASSERT_MSG(m_Keyword != NULL, _("wxSearchEngine::LookFor must be called before scanning!"));
|
||||
|
||||
int i, j;
|
||||
int lng = stream -> StreamSize();
|
||||
int wrd = strlen(m_Keyword);
|
||||
bool found = FALSE;
|
||||
char *buf = (char*) malloc(lng + 1);
|
||||
stream -> Read(buf, lng);
|
||||
buf[lng] = 0;
|
||||
|
||||
for (i = 0; i < lng; i++)
|
||||
if ((buf[i] >= 'A') && (buf[i] <= 'Z')) buf[i] += 'a' - 'A';
|
||||
|
||||
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;}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return found;
|
||||
}
|
||||
|
||||
#endif
|
50
src/html/search.h
Normal file
50
src/html/search.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: search.h
|
||||
// Purpose: wxSearchEngine - class for searching keywords
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifndef __SEARCH_H__
|
||||
#define __SEARCH_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
|
||||
#include <wx/stream.h>
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxSearchEngine
|
||||
// This class takes input streams and scans them for occurence
|
||||
// of keyword(s)
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class wxSearchEngine : public wxObject
|
||||
{
|
||||
private:
|
||||
char *m_Keyword;
|
||||
|
||||
public:
|
||||
wxSearchEngine() : wxObject() {m_Keyword = NULL;}
|
||||
~wxSearchEngine() {if (m_Keyword) free(m_Keyword);}
|
||||
|
||||
virtual void LookFor(const wxString& keyword);
|
||||
// Sets the keyword we will be searching for
|
||||
|
||||
virtual bool Scan(wxInputStream *stream);
|
||||
// Scans the stream for the keyword.
|
||||
// Returns TRUE if the stream contains keyword, fALSE otherwise
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -61,6 +61,9 @@ libwx_motif_la_SOURCES = \
|
||||
event.cpp \
|
||||
file.cpp \
|
||||
fileconf.cpp \
|
||||
filesys.cpp \
|
||||
fs_inet.cpp \
|
||||
fs_zip.cpp \
|
||||
framecmn.cpp \
|
||||
ftp.cpp \
|
||||
gdicmn.cpp \
|
||||
@@ -105,8 +108,11 @@ libwx_motif_la_SOURCES = \
|
||||
wfstream.cpp \
|
||||
wincmn.cpp \
|
||||
wxexpr.cpp \
|
||||
unzip.c \
|
||||
zipstream.cpp \
|
||||
zstream.cpp \
|
||||
\
|
||||
busyinfo.cpp \
|
||||
caret.cpp \
|
||||
choicdgg.cpp \
|
||||
colrdlgg.cpp \
|
||||
@@ -188,7 +194,25 @@ libwx_motif_la_SOURCES = \
|
||||
timer.cpp \
|
||||
toolbar.cpp \
|
||||
utils.cpp \
|
||||
window.cpp
|
||||
window.cpp \
|
||||
\
|
||||
htmlcell.cpp \
|
||||
htmlfilter.cpp \
|
||||
htmlhelp.cpp \
|
||||
htmlhelp_io.cpp \
|
||||
htmlparser.cpp \
|
||||
htmltag.cpp \
|
||||
htmlwin.cpp \
|
||||
htmlwinparser.cpp \
|
||||
mod_fonts.cpp \
|
||||
mod_hline.cpp \
|
||||
mod_image.cpp \
|
||||
mod_layout.cpp \
|
||||
mod_links.cpp \
|
||||
mod_list.cpp \
|
||||
mod_pre.cpp \
|
||||
mod_tables.cpp \
|
||||
search.cpp
|
||||
|
||||
# propform.cpp \
|
||||
# proplist.cpp \
|
||||
|
Reference in New Issue
Block a user