From: Václav Slavík Date: Wed, 7 Jul 1999 22:04:58 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5526e819eca4465ed5520d49bccfebc6a28045e0 *** empty log message *** git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2963 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/acconfig.h b/acconfig.h index f0b87b500b..e0f7d38429 100644 --- a/acconfig.h +++ b/acconfig.h @@ -533,6 +533,11 @@ */ #define wxUSE_MINIFRAME 0 +/* + * wxHTML + */ +#define wxUSE_HTML 0 + /* * Disable this if your compiler can't cope * with omission of prototype parameters. diff --git a/configure.in b/configure.in index 5e6a6fa14a..3aceaf4cdf 100644 --- a/configure.in +++ b/configure.in @@ -292,6 +292,7 @@ if test $DEBUG_CONFIGURE = 1; then DEFAULT_wxUSE_STARTUP_TIPS=no DEFAULT_wxUSE_PROGRESSDLG=no DEFAULT_wxUSE_MINIFRAME=no + DEFAULT_wxUSE_HTML=no DEFAULT_wxUSE_VALIDATORS=yes DEFAULT_wxUSE_ACCEL=no @@ -391,6 +392,7 @@ else DEFAULT_wxUSE_STARTUP_TIPS=yes DEFAULT_wxUSE_PROGRESSDLG=yes DEFAULT_wxUSE_MINIFRAME=yes + DEFAULT_wxUSE_HTML=no DEFAULT_wxUSE_VALIDATORS=yes DEFAULT_wxUSE_ACCEL=yes @@ -675,6 +677,7 @@ WX_ARG_ENABLE(textdlg, [ --enable-textdlg use wxTextDialog], wxUSE_T WX_ARG_ENABLE(tipdlg, [ --enable-tipdlg use startup tips], wxUSE_STARTUP_TIPS) WX_ARG_ENABLE(progressdlg, [ --enable-progressdlg use wxProgressDialog], wxUSE_PROGRESSDLG) WX_ARG_ENABLE(miniframe, [ --enable-miniframe use wxMiniFrame class], wxUSE_MINIFRAME) +WX_ARG_ENABLE(html, [ --enable-html use wxHTML sub-library], wxUSE_HTML) WX_ARG_ENABLE(tooltips, [ --enable-tooltips use wxToolTip class], wxUSE_TOOLTIPS) WX_ARG_ENABLE(splines, [ --enable-splines use spline drawing code], wxUSE_SPLINES) WX_ARG_ENABLE(validators, [ --enable-validators use wxValidator and derived classes], wxUSE_VALIDATORS) @@ -1993,6 +1996,11 @@ if test "$wxUSE_MINIFRAME" = "yes"; then SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS minifram" fi +if test "$wxUSE_HTML" = "yes"; then + AC_DEFINE(wxUSE_HTML) + SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS html" +fi + if test "$wxUSE_VALIDATORS" = "yes"; then AC_DEFINE(wxUSE_VALIDATORS) SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS validate" @@ -2178,6 +2186,14 @@ dnl samples/Makefile samples/minimal/Makefile samples/validate/Makefile samples/wxpoem/Makefile samples/wxsocket/Makefile + samples/html/Makefile + samples/html/about/Makefile + samples/html/help/Makefile + samples/html/test/Makefile + samples/html/printing/Makefile + samples/html/widget/Makefile + samples/html/virtual/Makefile + samples/html/zip/Makefile ], [ chmod +x wx-config diff --git a/include/wx/busyinfo.h b/include/wx/busyinfo.h new file mode 100644 index 0000000000..b4266a935a --- /dev/null +++ b/include/wx/busyinfo.h @@ -0,0 +1,58 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: busyinfo.h +// Purpose: Information window (when app is busy) +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef __INFOWIN_H__ +#define __INFOWIN_H__ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + + +#include + + + + +class wxInfoFrame : public wxFrame +{ + public: + wxInfoFrame(wxWindow *parent, const wxString& message); +}; + + +//-------------------------------------------------------------------------------- +// wxBusyInfo +// Displays progress information +// Can be used in exactly same way as wxBusyCursor +//-------------------------------------------------------------------------------- + +class wxBusyInfo : public wxObject +{ + public: + wxBusyInfo(const wxString& message); + ~wxBusyInfo(); + + private: + wxInfoFrame *m_InfoFrame; +}; + + +#endif + + diff --git a/include/wx/filesys.h b/include/wx/filesys.h new file mode 100644 index 0000000000..5ff10cb25e --- /dev/null +++ b/include/wx/filesys.h @@ -0,0 +1,194 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: filesys.h +// Purpose: class for opening files - virtual file system +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef __FILESYS_H__ +#define __FILESYS_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include +#include +#include + + +class wxFSFile; +class wxFileSystemHandler; +class wxFileSystem; + +//-------------------------------------------------------------------------------- +// wxFSFile +// This class is a file opened using wxFileSystem. It consists of +// input stream, location, mime type & optional anchor +// (in 'index.htm#chapter2', 'chapter2' is anchor) +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxFSFile : public wxObject +{ + private: + wxInputStream *m_Stream; + wxString m_Location; + wxString m_MimeType; + wxString m_Anchor; + + public: + wxFSFile(wxInputStream *stream, const wxString& loc, const wxString& mimetype, const wxString& anchor) + { + m_Stream = stream; + m_Location = loc; + m_MimeType = mimetype; m_MimeType.MakeLower(); + m_Anchor = anchor; + } + virtual ~wxFSFile() + { + if (m_Stream) delete m_Stream; + } + + wxInputStream *GetStream() const {return m_Stream;} + // returns stream. This doesn't _create_ stream, it only returns + // pointer to it!! + + const wxString& GetMimeType() const {return m_MimeType;} + // returns file's mime type + + const wxString& GetLocation() const {return m_Location;} + // returns the original location (aka filename) of the file + + const wxString& GetAnchor() const {return m_Anchor;} +}; + + + + + +//-------------------------------------------------------------------------------- +// wxFileSystemHandler +// This class is FS handler for wxFileSystem. It provides +// interface to access certain +// kinds of files (HTPP, FTP, local, tar.gz etc..) +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxFileSystemHandler : public wxObject +{ + DECLARE_ABSTRACT_CLASS(wxFileSystemHandler) + + public: + wxFileSystemHandler() : wxObject() {} + + virtual bool CanOpen(const wxString& location) = 0; + // returns TRUE if this handler is able to open given location + + virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location) = 0; + // opens given file and returns pointer to input stream. + // Returns NULL if opening failed. + // The location is always absolute path. + + protected: + wxString GetProtocol(const wxString& location) const; + // returns protocol ("file", "http", "tar" etc.) The last (most right) + // protocol is used: + // {it returns "tar" for "file:subdir/archive.tar.gz#tar:/README.txt"} + + wxString GetLeftLocation(const wxString& location) const; + // returns left part of address: + // {it returns "file:subdir/archive.tar.gz" for "file:subdir/archive.tar.gz#tar:/README.txt"} + + wxString GetAnchor(const wxString& location) const; + // returns anchor part of address: + // {it returns "anchor" for "file:subdir/archive.tar.gz#tar:/README.txt#anchor"} + // NOTE: anchor is NOT a part of GetLeftLocation()'s return value + + wxString GetRightLocation(const wxString& location) const; + // returns right part of address: + // {it returns "/README.txt" for "file:subdir/archive.tar.gz#tar:/README.txt"} + + wxString GetMimeTypeFromExt(const wxString& location); + // Returns MIME type of the file - w/o need to open it + // (default behaviour is that it returns type based on extension) + + private: + static wxMimeTypesManager m_MimeMng; + // MIME manager + // (it's static and thus shared by all instances and derived classes) +}; + + + + +//-------------------------------------------------------------------------------- +// wxFileSystem +// This class provides simple interface for opening various +// kinds of files (HTPP, FTP, local, tar.gz etc..) +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxFileSystem : public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxFileSystem) + + private: + wxString m_Path; + // the path (location) we are currently in + // this is path, not file! + // (so if you opened test/demo.htm, it is + // "test/", not "test/demo.htm") + wxString m_LastName; + // name of last opened file (full path) + static wxList m_Handlers; + // list of FS handlers + + public: + wxFileSystem() : wxObject() {m_Path = m_LastName = wxEmptyString; m_Handlers.DeleteContents(TRUE);} + + void ChangePathTo(const wxString& location, bool is_dir = FALSE); + // sets the current location. Every call to OpenFile is + // relative to this location. + // NOTE !! + // unless is_dir = TRUE 'location' is *not* the directory but + // file contained in this directory + // (so ChangePathTo("dir/subdir/xh.htm") sets m_Path to "dir/subdir/") + + wxString GetPath() const {return m_Path;} + + wxFSFile* OpenFile(const wxString& location); + // opens given file and returns pointer to input stream. + // Returns NULL if opening failed. + // It first tries to open the file in relative scope + // (based on ChangePathTo()'s value) and then as an absolute + // path. + + static void AddHandler(wxFileSystemHandler *handler); + // Adds FS handler. + // In fact, this class is only front-end to the FS hanlers :-) +}; + + +/* + +'location' syntax: + +To determine FS type, we're using standard KDE notation: +file:/absolute/path/file.htm +file:relative_path/xxxxx.html +/some/path/x.file ('file:' is default) +http://www.gnome.org +file:subdir/archive.tar.gz#tar:/README.txt + +special characters : + ':' - FS identificator is before this char + '#' - separator. It can be either HTML anchor ("index.html#news") + (in case there is no ':' in the string to the right from it) + or FS separator + (example : http://www.wxhtml.org/wxhtml-0.1.tar.gz#tar:/include/wxhtml/filesys.h" + this would access tgz archive stored on web) + '/' - directory (path) separator. It is used to determine upper-level path. + HEY! Don't use \ even if you're on Windows! + +*/ + +#endif // __FILESYS_H__ diff --git a/include/wx/fs_inet.h b/include/wx/fs_inet.h new file mode 100644 index 0000000000..695bdb425f --- /dev/null +++ b/include/wx/fs_inet.h @@ -0,0 +1,55 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: fs_inet.h +// 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 + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include + + + +//-------------------------------------------------------------------------------- +// wxInternetFSHandler +//-------------------------------------------------------------------------------- + +class wxInternetFSHandler : public wxFileSystemHandler +{ + private: + wxHashTable m_Cache; + + public: + virtual bool CanOpen(const wxString& location); + virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); + ~wxInternetFSHandler(); +}; + + diff --git a/include/wx/fs_zip.h b/include/wx/fs_zip.h new file mode 100644 index 0000000000..f0b481d78f --- /dev/null +++ b/include/wx/fs_zip.h @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: fs_zip.h +// Purpose: ZIP file system +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include + + + +//-------------------------------------------------------------------------------- +// wxZipFSHandler +//-------------------------------------------------------------------------------- + +class wxZipFSHandler : public wxFileSystemHandler +{ + public: + virtual bool CanOpen(const wxString& location); + virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); + ~wxZipFSHandler(); +}; + + + diff --git a/include/wx/html/forcelink.h b/include/wx/html/forcelink.h new file mode 100644 index 0000000000..2be0bc0cf6 --- /dev/null +++ b/include/wx/html/forcelink.h @@ -0,0 +1,59 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: forcelink.h +// Purpose: see bellow +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +/* + +DESCRPITON: + +mod_*.cpp files contain handlers for tags. These files are modules - they contain +one wxTagModule class and it's OnInit() method is called from wxApp's init method. +The module is called even if you only link it into the executable, so everything +seems wonderful. + +The problem is that we have these modules in LIBRARY and mod_*.cpp files contain +no method nor class which is known out of the module. So the linker won't +link these .o/.obj files into executable because it detected that it is not used +by the program. + +To workaround this I introduced set of macros FORCE_LINK_ME and FORCE_LINK. These +macros are generic and are not limited to mod_*.cpp files. You may find them quite +useful somewhere else... + +How to use them: +let's suppose you want to always link file foo.cpp and that you have module +always.cpp that is certainly always linked (e.g. the one with main() function +or htmlwin.cpp in wxHtml library). + +Place FORCE_LINK_ME(foo) somewhere in foo.cpp and FORCE_LINK(foo) somewhere +in always.cpp +See mod_*.cpp and htmlwin.cpp for example :-) + +*/ + + +#ifndef __FORCELINK_H__ +#define __FORCELINK_H__ + + + +// This must be part of the module you want to force: +#define FORCE_LINK_ME(module_name) \ + int _link_dummy_func_##module_name () \ + { \ + return 1; \ + } + + +// And this must be somewhere where it certainly will be linked: +#define FORCE_LINK(module_name) \ + extern int _link_dummy_func_##module_name (); \ + static int _link_dummy_var_##module_name = \ + _link_dummy_func_##module_name (); + + +#endif // __FORCELINK_H__ diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h new file mode 100644 index 0000000000..23293c93b0 --- /dev/null +++ b/include/wx/html/htmlcell.h @@ -0,0 +1,292 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlcell.h +// Purpose: wxHtmlCell class is used by wxHtmlWindow/wxHtmlWinParser +// as a basic visual element of HTML page +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLCELL_H__ +#define __HTMLCELL_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + + +#include +#include +#include + +class wxHtmlCell; +class wxHtmlContainerCell; + +//-------------------------------------------------------------------------------- +// wxHtmlCell +// Internal data structure. It represents fragments of parsed HTML +// page - a word, picture, table, horizontal line and so on. +// It is used by wxHtmlWindow to represent HTML page in memory. +//-------------------------------------------------------------------------------- + + +class WXDLLEXPORT wxHtmlCell : public wxObject +{ + protected: + wxHtmlCell *m_Next; + // pointer to the next cell + wxHtmlContainerCell *m_Parent; + // pointer to parent cell + long m_Width, m_Height, m_Descent; + // dimensions of fragment + // m_Descent is used to position text&images.. + long m_PosX, m_PosY; + // position where the fragment is drawn + wxString m_Link; + // destination address if this fragment is hypertext link, "" otherwise + + public: + wxHtmlCell() : wxObject() {m_Next = NULL; m_Parent = NULL; m_Width = m_Height = m_Descent = 0;}; + virtual ~wxHtmlCell() {if (m_Next) delete m_Next;}; + + void SetParent(wxHtmlContainerCell *p) {m_Parent = p;} + wxHtmlContainerCell *GetParent() const {return m_Parent;} + + int GetPosX() const {return m_PosX;} + int GetPosY() const {return m_PosY;} + int GetWidth() const {return m_Width;} + int GetHeight() const {return m_Height;} + int GetDescent() const {return m_Descent;} + virtual wxString GetLink(int x = 0, int y = 0) const {return m_Link;} + // returns the link associated with this cell. The position is position within + // the cell so it varies from 0 to m_Width, from 0 to m_Height + wxHtmlCell *GetNext() const {return m_Next;} + // members access methods + + virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;} + void SetLink(const wxString& link) {m_Link = link;} + void SetNext(wxHtmlCell *cell) {m_Next = cell;} + // members writin methods + + virtual void Layout(int w) {SetPos(0, 0); if (m_Next) m_Next -> Layout(w);}; + // 1. adjust cell's width according to the fact that maximal possible width is w. + // (this has sense when working with horizontal lines, tables etc.) + // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height) members) + // = place items to fit window, according to the width w + + virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) {if (m_Next) m_Next -> Draw(dc, x, y, view_y1, view_y2);} + // renders the cell + + virtual void DrawInvisible(wxDC& dc, int x, int y) {if (m_Next) m_Next -> DrawInvisible(dc, x, y);}; + // proceed drawing actions in case the cell is not visible (scrolled out of screen). + // This is needed to change fonts, colors and so on + + virtual const wxHtmlCell* Find(int condition, const void* param) const {if (m_Next) return m_Next -> Find(condition, param); else return NULL;} + // This method returns pointer to the FIRST cell for that + // the condition + // is true. It first checks if the condition is true for this + // cell and then calls m_Next -> Find(). (Note: it checks + // all subcells if the cell is container) + // Condition is unique condition identifier (see htmldefs.h) + // (user-defined condition IDs should start from 10000) + // and param is optional parameter + // Example : m_Cell -> Find(HTML_COND_ISANCHOR, "news"); + // returns pointer to anchor news + + virtual void OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right); + // This function is called when mouse button is clicked over the cell. + // left, middle, right are flags indicating whether the button was or wasn't + // pressed. + // Parent is pointer to wxHtmlWindow that generated the event + // HINT: if this handling is not enough for you you should use + // wxHtmlBinderCell +}; + + + + +//-------------------------------------------------------------------------------- +// Inherited cells: +//-------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------- +// wxHtmlWordCell +// Single word in input stream. +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell +{ + protected: + wxString m_Word; + + public: + wxHtmlWordCell(const wxString& word, wxDC& dc); + void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); +}; + + + + + +//-------------------------------------------------------------------------------- +// wxHtmlContainerCell +// Container - it contains other cells. Basic of layout algorithm. +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell +{ + protected: + int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom; + // indentation of subcells. There is always m_Indent pixels + // big space between given border of the container and the subcells + // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels + int m_MinHeight, m_MinHeightAlign; + // minimal height. + int m_MaxLineWidth; + // maximal widht of line. Filled during Layout() + wxHtmlCell *m_Cells, *m_LastCell; + // internal cells, m_Cells points to the first of them, m_LastCell to the last one. + // (LastCell is needed only to speed-up InsertCell) + int m_AlignHor, m_AlignVer; + // alignment horizontal and vertical (left, center, right) + int m_WidthFloat, m_WidthFloatUnits; + // width float is used in adjustWidth + bool m_UseBkColour; + wxColour m_BkColour; + // background color of this container + bool m_UseBorder; + wxColour m_BorderColour1, m_BorderColour2; + // borders color of this container + + public: + wxHtmlContainerCell(wxHtmlContainerCell *parent); + ~wxHtmlContainerCell() {if (m_Cells) delete m_Cells;} + + virtual void Layout(int w); + virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); + virtual void DrawInvisible(wxDC& dc, int x, int y); + + void InsertCell(wxHtmlCell *cell); + // insert cell at the end of m_Cells list + void SetAlignHor(int al) {m_AlignHor = al;} + int GetAlignHor() const {return m_AlignHor;} + void SetAlignVer(int al) {m_AlignVer = al;} + // sets horizontal/vertical alignment + int GetAlignVer() const {return m_AlignVer;} + void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS); + // sets left-border indentation. units is one of HTML_UNITS_* constants + // what is combination of HTML_INDENT_* + int GetIndent(int ind) const; + // returns the indentation. ind is one of HTML_INDENT_* constants + int GetIndentUnits(int ind) const; + // returns type of value returned by GetIndent(ind) + void SetAlign(const wxHtmlTag& tag); + // sets alignment info based on given tag's params + void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units;} + void SetWidthFloat(const wxHtmlTag& tag); + // sets floating width adjustment + // (examples : 32 percent of parent container, + // -15 pixels percent (this means 100 % - 15 pixels) + void SetMinHeight(int h, int align = HTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align;} + // sets minimal height of this container. + int GetMaxLineWidth() const {return m_MaxLineWidth;} + // returns maximal line width in this container. + // Call to this method is valid only after calling + // Layout() + void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;} + void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;} + virtual wxString GetLink(int x = 0, int y = 0) const; + virtual const wxHtmlCell* Find(int condition, const void* param) const; + virtual void OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right); + + wxHtmlCell* GetFirstCell() {return m_Cells;} + // returns pointer to the first cell in container or NULL +}; + + + + + +//-------------------------------------------------------------------------------- +// wxHtmlColourCell +// Color changer. +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell +{ + public: + wxColour m_Colour; + unsigned m_Flags; + + wxHtmlColourCell(wxColour clr, int flags = HTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;} + virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); + virtual void DrawInvisible(wxDC& dc, int x, int y); +}; + + + + +//-------------------------------------------------------------------------------- +// wxHtmlFontCell +// Sets actual font used for text rendering +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell +{ + public: + wxFont *m_Font; + + wxHtmlFontCell(wxFont *font) : wxHtmlCell() {m_Font = font;}; + virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); + virtual void DrawInvisible(wxDC& dc, int x, int y); +}; + + + + + + +//-------------------------------------------------------------------------------- +// wxHtmlwidgetCell +// This cell is connected with wxWindow object +// You can use it to insert windows into HTML page +// (buttons, input boxes etc.) +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell +{ + protected: + wxWindow* m_Wnd; + int m_WidthFloat; + // width float is used in adjustWidth (it is in percents) + + public: + wxHtmlWidgetCell(wxWindow *wnd, int w = 0); + // !!! wnd must have correct parent! + // if w != 0 then the m_Wnd has 'floating' width - it adjust + // it's width according to parent container's width + // (w is percent of parent's width) + virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); + virtual void DrawInvisible(wxDC& dc, int x, int y); + virtual void Layout(int w); +}; + + + + +#endif // __HTMLCELL_H__ + +#endif + + + + + + + + diff --git a/include/wx/html/htmldefs.h b/include/wx/html/htmldefs.h new file mode 100644 index 0000000000..88d5602683 --- /dev/null +++ b/include/wx/html/htmldefs.h @@ -0,0 +1,94 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmldefs.h +// Purpose: constants for wxhtml library +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLDEFS_H__ +#define __HTMLDEFS_H__ + +#include "wx/defs.h" +#if wxUSE_HTML + + +//-------------------------------------------------------------------------------- +// ALIGNMENTS +// Describes alignment of text etc. in containers +//-------------------------------------------------------------------------------- + +#define HTML_ALIGN_LEFT 0x0000 +#define HTML_ALIGN_RIGHT 0x0002 + +#define HTML_ALIGN_TOP 0x0004 +#define HTML_ALIGN_BOTTOM 0x0008 + +#define HTML_ALIGN_CENTER 0x0001 + + + +//-------------------------------------------------------------------------------- +// COLOR MODES +// Used by wxHtmlColourCell to determine clr of what is changing +//-------------------------------------------------------------------------------- + +#define HTML_CLR_FOREGROUND 0x0001 +#define HTML_CLR_BACKGROUND 0x0002 + + + +//-------------------------------------------------------------------------------- +// UNITS +// Used to specify units +//-------------------------------------------------------------------------------- + +#define HTML_UNITS_PIXELS 0x0001 +#define HTML_UNITS_PERCENT 0x0002 + + + +//-------------------------------------------------------------------------------- +// INDENTS +// Used to specify indetation relatives +//-------------------------------------------------------------------------------- + +#define HTML_INDENT_LEFT 0x0010 +#define HTML_INDENT_RIGHT 0x0020 +#define HTML_INDENT_TOP 0x0040 +#define HTML_INDENT_BOTTOM 0x0080 + +#define HTML_INDENT_HORIZONTAL HTML_INDENT_LEFT | HTML_INDENT_RIGHT +#define HTML_INDENT_VERTICAL HTML_INDENT_TOP | HTML_INDENT_BOTTOM +#define HTML_INDENT_ALL HTML_INDENT_VERTICAL | HTML_INDENT_HORIZONTAL + + + + +//-------------------------------------------------------------------------------- +// FIND CONDITIONS +// Identifiers of wxHtmlCell's Find() conditions +//-------------------------------------------------------------------------------- + +#define HTML_COND_ISANCHOR 1 + // Finds the anchor of 'param' name (pointer to wxString). + +#define HTML_COND_USER 10000 + // User-defined conditions should start from this number + + +//-------------------------------------------------------------------------------- +// INTERNALS +// wxHTML internal constants +//-------------------------------------------------------------------------------- + +#define HTML_SCROLL_STEP 16 + /* size of one scroll step of wxHtmlWindow in pixels */ +#define HTML_BUFLEN 1024 + /* size of temporary buffer used during parsing */ +#define HTML_REALLOC_STEP 32 + /* steps of array reallocation */ + +#endif +#endif \ No newline at end of file diff --git a/include/wx/html/htmlfilter.h b/include/wx/html/htmlfilter.h new file mode 100644 index 0000000000..99b00d8de6 --- /dev/null +++ b/include/wx/html/htmlfilter.h @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlfilter.h +// Purpose: filters +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLFILTER_H__ +#define __HTMLFILTER_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + +#include + + +//-------------------------------------------------------------------------------- +// wxHtmlFilter +// This class is input filter. It can "translate" files +// in non-HTML format to HTML format +// interface to access certain +// kinds of files (HTPP, FTP, local, tar.gz etc..) +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlFilter : public wxObject +{ + DECLARE_ABSTRACT_CLASS(wxHtmlFilter) + + public: + wxHtmlFilter() : wxObject() {} + + virtual bool CanRead(const wxFSFile& file) = 0; + // returns TRUE if this filter is able to open&read given file + + virtual wxString ReadFile(const wxFSFile& file) = 0; + // reads given file and returns HTML document. + // Returns empty string if opening failed +}; + + + +//-------------------------------------------------------------------------------- +// wxHtmlFilterPlainText +// This filter is used as default filter if no other can +// be used (= uknown type of file). It is used by +// wxHtmlWindow itself. +//-------------------------------------------------------------------------------- + + +class WXDLLEXPORT wxHtmlFilterPlainText : public wxHtmlFilter +{ + DECLARE_DYNAMIC_CLASS(wxHtmlFilterPlainText) + + public: + virtual bool CanRead(const wxFSFile& file); + virtual wxString ReadFile(const wxFSFile& file); +}; + + + + +#endif // __HTMLFILTER_H__ + +#endif \ No newline at end of file diff --git a/include/wx/html/htmlhelp.h b/include/wx/html/htmlhelp.h new file mode 100644 index 0000000000..6e56bc5815 --- /dev/null +++ b/include/wx/html/htmlhelp.h @@ -0,0 +1,223 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlhelp.h +// Purpose: Help controller +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLHELP_H__ +#define __HTMLHELP_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + +#include +#include +#include +#include +#include +#include + + + +//-------------------------------------------------------------------------------- +// helper classes & structs - please ignore 'em +//-------------------------------------------------------------------------------- + + + +class WXDLLEXPORT HtmlBookRecord : public wxObject +{ + public: + wxString m_BasePath; + wxString m_Title; + wxString m_Start; + + HtmlBookRecord(const wxString& basepath, const wxString& title, const wxString& start) {m_BasePath = basepath; m_Title = title; m_Start = start;} + wxString GetTitle() const {return m_Title;} + wxString GetStart() const {return m_Start;} + wxString GetBasePath() const {return m_BasePath;} +}; + + +#undef WXDLLEXPORTLOCAL +#define WXDLLEXPORTLOCAL WXDLLEXPORT + // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL +WX_DECLARE_OBJARRAY(HtmlBookRecord, HtmlBookRecArray); + +#undef WXDLLEXPORTLOCAL +#define WXDLLEXPORTLOCAL + + +typedef struct + { + short int m_Level; + int m_ID; + char* m_Name; + char* m_Page; + HtmlBookRecord *m_Book; + } HtmlContentsItem; + + + + +//-------------------------------------------------------------------------------- +// wxHtmlHelpController +// This class ensures dislaying help. +// See documentation for details on its philosophy. +// +// WARNING!! +// This class is not derived from wxHelpController and is not +// compatible with it! +//-------------------------------------------------------------------------------- + + +class WXDLLEXPORT wxHtmlHelpController : public wxEvtHandler +{ + DECLARE_DYNAMIC_CLASS(wxHtmlHelpController) + + protected: + wxConfigBase *m_Config; + wxString m_ConfigRoot; + // configuration file/registry used to store custom settings + wxString m_TitleFormat; + // title of the help frame + wxString m_TempPath; + + wxFrame *m_Frame; + wxHtmlWindow *m_HtmlWin; + wxSplitterWindow *m_Splitter; + wxNotebook *m_NavigPan; + wxTreeCtrl *m_ContentsBox; + wxImageList *m_ContentsImageList; + wxListBox *m_IndexBox; + wxTextCtrl *m_SearchText; + wxButton *m_SearchButton; + wxListBox *m_SearchList; + // ...pointers to parts of help window + + struct { + long x, y, w, h; + long sashpos; + bool navig_on; + } m_Cfg; + // settings (window size, position, sash pos etc..) + + HtmlBookRecArray m_BookRecords; + // each book has one record in this array + HtmlContentsItem* m_Contents; + int m_ContentsCnt; + // list of all available books and pages. + HtmlContentsItem* m_Index; + int m_IndexCnt; + // list of index items + + public: + wxHtmlHelpController(); + ~wxHtmlHelpController(); + + void SetTitleFormat(const wxString& format) {m_TitleFormat = format;} + // Sets format of title of the frame. Must contain exactly one "%s" + // (for title of displayed HTML page) + + void SetTempDir(const wxString& path); + // Sets directory where temporary files are stored. + // These temp files are index & contents file in binary (much faster to read) + // form. These files are NOT deleted on program's exit. + + bool AddBook(const wxString& book, bool show_wait_msg = FALSE); + // Adds new book. 'book' is location of .htb file (stands for "html book"). + // See documentation for details on its format. + // Returns success. + // If show_wait_msg == true then message window with "loading book..." is displayed + + void Display(const wxString& x); + // Displays page x. If not found it will offect the user a choice of searching + // books. + // Looking for the page runs in these steps: + // 1. try to locate file named x (if x is for example "doc/howto.htm") + // 2. try to open starting page of book x + // 3. try to find x in contents (if x is for example "How To ...") + // 4. try to find x in index (if x is for example "How To ...") + // 5. offer searching and if the user agree, run KeywordSearch + void Display(const int id); + // Alternative version that works with numeric ID. + // (uses extension to MS format, , see docs) + + void DisplayContents(); + // Displays help window and focuses contents. + + void DisplayIndex(); + // Displays help window and focuses index. + + bool KeywordSearch(const wxString& keyword); + // Searches for keyword. Returns TRUE and display page if found, return + // FALSE otherwise + // Syntax of keyword is Altavista-like: + // * words are separated by spaces + // (but "\"hello world\"" is only one world "hello world") + // * word may be pretended by + or - + // (+ : page must contain the word ; - : page can't contain the word) + // * if there is no + or - before the word, + is default + + void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString) {m_Config = config; m_ConfigRoot = rootpath;} + // Assigns config object to the controller. This config is then + // used in subsequent calls to Read/WriteCustomization of both help + // controller and it's wxHtmlWindow + + void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString); + // saves custom settings into cfg config. it will use the path 'path' + // if given, otherwise it will save info into currently selected path. + // saved values : things set by SetFonts, SetBorders. + void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString); + // ... + + protected: + virtual void CreateHelpWindow(); + // Creates frame & html window and sets m_Frame and other variables; + // Do nothing if the window already exists + void RefreshLists(); + // Refreshes Contents and Index tabs + void CreateContents(); + // Adds items to m_Contents tree control + void CreateIndex(); + // Adds items to m_IndexList + + void LoadMSProject(HtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile, bool show_wait_msg); + // Imports .hhp files (MS HTML Help Workshop) + void LoadCachedBook(HtmlBookRecord *book, wxInputStream *f); + // Reads binary book + void SaveCachedBook(HtmlBookRecord *book, wxOutputStream *f); + // Writes binary book + + void OnToolbar(wxCommandEvent& event); + void OnContentsSel(wxTreeEvent& event); + void OnIndexSel(wxCommandEvent& event); + void OnSearchSel(wxCommandEvent& event); + void OnSearch(wxCommandEvent& event); + void OnCloseWindow(wxCloseEvent& event); + + DECLARE_EVENT_TABLE() +}; + + + +#endif // __HTMLHELP_H__ + +#endif + + + + + + + + + + diff --git a/include/wx/html/htmlparser.h b/include/wx/html/htmlparser.h new file mode 100644 index 0000000000..d1c6a65070 --- /dev/null +++ b/include/wx/html/htmlparser.h @@ -0,0 +1,176 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlparser.h +// Purpose: wxHtmlParser class (generic parser) +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLPARSER_H__ +#define __HTMLPARSER_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + +#include +#include + +class wxHtmlParser; +class wxHtmlTagHandler; + +//-------------------------------------------------------------------------------- +// wxHtmlParser +// This class handles generic parsing of HTML document : it scans +// the document and divide it into blocks of tags (where one block +// consists of starting and ending tag and of text between these +// 2 tags. +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlParser : public wxObject +{ + DECLARE_ABSTRACT_CLASS(wxHtmlParser) + + protected: + wxString m_Source; + // source being parsed + wxHtmlTagsCache *m_Cache; + // tags cache, used during parsing. + wxHashTable m_HandlersHash; + wxList m_HandlersList; + // handlers that handle particular tags. The table is accessed by + // key = tag's name. + // This attribute MUST be filled by derived class otherwise it would + // be empty and no tags would be recognized + // (see wxHtmlWinParser for details about filling it) + // m_HandlersHash is for random access based on knowledge of tag name (BR, P, etc.) + // it may (and often does) contain more references to one object + // m_HandlersList is list of all handlers and it is guaranteed to contain + // only one reference to each handler instance. + wxFileSystem *m_FS; + // class for opening files (file system) + + public: + wxHtmlParser() : wxObject(), m_HandlersHash(wxKEY_STRING) {m_FS = NULL; m_Cache = NULL;} + virtual ~wxHtmlParser(); + + void SetFS(wxFileSystem *fs) {m_FS = fs;} + // Sets the class which will be used for opening files + wxFileSystem* GetFS() const {return m_FS;} + + wxObject* Parse(const wxString& source); + // You can simply call this method when you need parsed output. + // This method does these things: + // 1. call InitParser(source); + // 2. call DoParsing(); + // 3. call GetProduct(); (it's return value is then returned) + // 4. call DoneParser(); + + virtual void InitParser(const wxString& source); + // Sets the source. This must be called before running Parse() method. + virtual void DoneParser(); + // This must be called after Parse(). + + void DoParsing(int begin_pos, int end_pos); + inline void DoParsing() {DoParsing(0, m_Source.Length());}; + // Parses the m_Source from begin_pos to end_pos-1. + // (in noparams version it parses whole m_Source) + + virtual wxObject* GetProduct() = 0; + // Returns product of parsing + // Returned value is result of parsing of the part. The type of this result + // depends on internal representation in derived parser + // (see wxHtmlWinParser for details). + + virtual void AddTagHandler(wxHtmlTagHandler *handler); + // adds handler to the list & hash table of handlers. + + wxString* GetSource() {return &m_Source;} + + virtual wxList* GetTempData() {return NULL;} + // this method returns list of wxObjects that represents + // all data allocated by the parser. These can't be freeded + // by destructor because they must be valid as long as + // GetProduct's return value is valid - the caller must + // explicitly call delete MyParser -> GetTempData() to free + // the memory + // (this method always sets the list to delete its contents) + + protected: + + virtual void AddText(const char* txt) = 0; + // Adds text to the output. + // This is called from Parse() and must be overriden in derived classes. + // txt is not guaranteed to be only one word. It is largest continuous part of text + // (= not broken by tags) + // NOTE : using char* because of speed improvements + + virtual void AddTag(const wxHtmlTag& tag); + // Adds tag and proceeds it. Parse() may (and usually is) called from this method. + // This is called from Parse() and may be overriden. + // Default behavior is that it looks for proper handler in m_Handlers. The tag is + // ignored if no hander is found. + // Derived class is *responsible* for filling in m_Handlers table. +}; + + + + + + +//-------------------------------------------------------------------------------- +// wxHtmlTagHandler +// This class (and derived classes) cooperates with wxHtmlParser. +// Each recognized tag is passed to handler which is capable +// of handling it. Each tag is handled in 3 steps: +// 1. Handler will modifies state of parser +// (using it's public methods) +// 2. Parser parses source between starting and ending tag +// 3. Handler restores original state of the parser +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlTagHandler : public wxObject +{ + DECLARE_ABSTRACT_CLASS(wxHtmlTagHandler) + + protected: + wxHtmlParser *m_Parser; + + public: + wxHtmlTagHandler() : wxObject () {m_Parser = NULL;}; + + virtual void SetParser(wxHtmlParser *parser) {m_Parser = parser;} + // Sets the parser. + // NOTE : each _instance_ of handler is guaranteed to be called + // only by one parser. This means you don't have to care about + // reentrancy. + + virtual wxString GetSupportedTags() = 0; + // Returns list of supported tags. The list is in uppercase and + // tags are delimited by ','. + // Example : "I,B,FONT,P" + // is capable of handling italic, bold, font and paragraph tags + + virtual bool HandleTag(const wxHtmlTag& tag) = 0; + // This is hadling core method. It does all the Steps 1-3. + // To process step 2, you can call ParseInner() + // returned value : TRUE if it called ParseInner(), + // FALSE etherwise + + protected: + void ParseInner(const wxHtmlTag& tag) {m_Parser -> DoParsing(tag.GetBeginPos(), tag.GetEndPos1());} + // parses input between beginning and ending tag. + // m_Parser must be set. +}; + + + + + +#endif // __HTMLPARSER_H__ + +#endif diff --git a/include/wx/html/htmltag.h b/include/wx/html/htmltag.h new file mode 100644 index 0000000000..2f6a443e58 --- /dev/null +++ b/include/wx/html/htmltag.h @@ -0,0 +1,135 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmltag.h +// Purpose: wxHtmlTag class (represents single tag) +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLTAG_H__ +#define __HTMLTAG_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + + +//-------------------------------------------------------------------------------- +// wxHtmlTagsCache +// !! INTERNAL STRUCTURE !! Do not use in your program! +// This structure contains information on positions of tags +// in the string being parsed +//-------------------------------------------------------------------------------- + +typedef struct { + int Key; + // this is "pos" value passed to wxHtmlTag's constructor. + // it is position of '<' character of the tag + int End1, End2; + // end positions for the tag: + // end1 is '<' of ending tag, + // end2 is '>' or both are + // -1 if there is no ending tag for this one... + // or -2 if this is ending tag + char *Name; + // name of this tag + } sCacheItem; + + + +class wxHtmlTagsCache : public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxHtmlTagsCache) + + private: + sCacheItem *m_Cache; + int m_CacheSize; + int m_CachePos; + + public: + wxHtmlTagsCache() : wxObject() {m_CacheSize = 0; m_Cache = NULL;} + wxHtmlTagsCache(const wxString& source); + ~wxHtmlTagsCache() {free(m_Cache);} + + void QueryTag(int at, int* end1, int* end2); + // Finds parameters for tag starting at at and fills the variables +}; + + + +//-------------------------------------------------------------------------------- +// wxHtmlTag +// This represents single tag. It is used as internal structure +// by wxHtmlParser. +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlTag : public wxObject +{ + DECLARE_CLASS(wxHtmlTag) + + private: + wxString m_Name, m_Params; + int m_Begin, m_End1, m_End2; + bool m_Ending; + + public: + wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache); + // constructs wxHtmlTag object based on HTML tag. + // The tag begins (with '<' character) at position pos in source + // end_pos is position where parsing ends (usually end of document) + + inline wxString GetName() const {return m_Name;}; + // Returns tag's name in uppercase. + + bool HasParam(const wxString& par) const; + // Returns TRUE if the tag has given parameter. Parameter + // should always be in uppercase. + // Example : HasParam("SRC") returns TRUE + + wxString GetParam(const wxString& par, bool with_commas = FALSE) const; + // Returns value of the param. Value is in uppercase unless it is + // enclosed with " + // Example :

GetParam("ALIGN") returns (RIGHT) + //

GetParam("SRC") returns (WhaT.jpg) + // (or ("WhaT.jpg") if with_commas == TRUE) + + void ScanParam(const wxString& par, char *format, ...) const; + // Scans param like scanf() functions family do. + // Example : ScanParam("COLOR", "\"#%X\"", &clr); + // This is always with with_commas=FALSE + + inline const wxString& GetAllParams() const {return m_Params;}; + // Returns string containing all params. + + inline bool IsEnding() const {return m_Ending;}; + // return TRUE if this is ending tag () or FALSE + // if it isn't () + + inline bool HasEnding() const {return m_End1 >= 0;}; + // return TRUE if this is ending tag () or FALSE + // if it isn't () + + inline int GetBeginPos() const {return m_Begin;}; + // returns beginning position of _internal_ block of text + // See explanation (returned value is marked with *): + // bla bla bla * bla bla intenal text bla bla + inline int GetEndPos1() const {return m_End1;}; + // returns ending position of _internal_ block of text. + // bla bla bla bla bla intenal text* bla bla + inline int GetEndPos2() const {return m_End2;}; + // returns end position 2 : + // bla bla bla bla bla internal text* bla bla +}; + + + + + + +#endif // __HTMLTAG_H__ + +#endif diff --git a/include/wx/html/htmlwin.h b/include/wx/html/htmlwin.h new file mode 100644 index 0000000000..351e000d0c --- /dev/null +++ b/include/wx/html/htmlwin.h @@ -0,0 +1,220 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlwin.h +// Purpose: wxHtmlWindow class for parsing & displaying HTML +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLWIN_H__ +#define __HTMLWIN_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + +#include +#include +#include +#include +#include +#include +#include + + +//-------------------------------------------------------------------------------- +// wxHtmlWindow +// (This is probably the only class you will directly use.) +// Purpose of this class is to display HTML page (either local +// file or downloaded via HTTP protocol) in a window. Width +// of window is constant - given in constructor - virtual height +// is changed dynamicly depending on page size. +// Once the window is created you can set it's content by calling +// SetPage(text) or LoadPage(filename). +//-------------------------------------------------------------------------------- + + +// item of history list +class WXDLLEXPORT HtmlHistoryItem : public wxObject +{ + private: + wxString m_Page; + wxString m_Anchor; + int m_Pos; + + public: + HtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;} + int GetPos() const {return m_Pos;} + void SetPos(int p) {m_Pos = p;} + const wxString& GetPage() const {return m_Page;} + const wxString& GetAnchor() const {return m_Anchor;} +}; + +#undef WXDLLEXPORTLOCAL +#define WXDLLEXPORTLOCAL WXDLLEXPORT + // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL + +WX_DECLARE_OBJARRAY(HtmlHistoryItem, HtmlHistoryArray); + +#undef WXDLLEXPORTLOCAL +#define WXDLLEXPORTLOCAL + + +class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow +{ + DECLARE_DYNAMIC_CLASS(wxHtmlWindow) + + protected: + wxHtmlContainerCell *m_Cell; + // This is pointer to the first cell in parsed data. + // (Note: the first cell is usually top one = all other cells are sub-cells of this one) + wxHtmlWinParser *m_Parser; + // parser which is used to parse HTML input. + // Each wxHtmlWindow has it's own parser because sharing one global + // parser would be problematic (because of reentrancy) + wxString m_OpenedPage; + // contains name of actualy opened page or empty string if no page opened + wxString m_OpenedAnchor; + // contains name of current anchor within m_OpenedPage + wxFileSystem* m_FS; + // class for opening files (file system) + + wxFrame *m_RelatedFrame; + wxString m_TitleFormat; + int m_RelatedStatusBar; + // frame in which page title should be displayed & number of it's statusbar + // reserved for usage with this html window + + int m_Borders; + // borders (free space between text and window borders) + // defaults to 10 pixels. + + bool m_Scrollable; + // TRUE if you can scroll the window. + // If it is FALSE you can't scroll the window even if it's contents is larger + // than window. + + + private: + bool m_tmpMouseMoved; + // a flag indicated if mouse moved + // (if TRUE we will try to change cursor in last call to OnIdle) + bool m_tmpCanDraw; + // if FALSE contents of the window is not redrawn + // (in order to avoid ugly bliking) + + static wxList m_Filters; + // list of HTML filters + static wxHtmlFilterPlainText m_DefaultFilter; + // this filter is used when no filter is able to read some file + + HtmlHistoryArray m_History; + int m_HistoryPos; + // browser history + bool m_HistoryOn; + // if this FLAG is false, items are not added to history + + public: + wxHtmlWindow() : wxScrolledWindow() {}; + wxHtmlWindow(wxWindow *parent, wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + const wxString& name = "htmlWindow", bool scrollable = TRUE); + ~wxHtmlWindow(); + + bool SetPage(const wxString& source); + // Set HTML page and display it. !! source is HTML document itself, + // it is NOT address/filename of HTML document. If you want to + // specify document location, use LoadPage() istead + // Return value : FALSE if an error occured, TRUE otherwise + + bool LoadPage(const wxString& location); + // Load HTML page from given location. Location can be either + // a) /usr/wxGTK2/docs/html/wx.htm + // b) http://www.somewhere.uk/document.htm + // c) ftp://ftp.somesite.cz/pub/something.htm + // In case there is no prefix (http:,ftp:), the method + // will try to find it itself (1. local file, then http or ftp) + // After the page is loaded, the method calls SetPage() to display it. + // Note : you can also use path relative to previously loaded page + // Return value : same as SetPage + + wxString GetOpenedPage() const {return m_OpenedPage;} + // Returns full location of opened page + + void SetRelatedFrame(wxFrame* frame, const wxString& format); + // sets frame in which page title will be displayed. Format is format of + // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s + wxFrame* GetRelatedFrame() const {return m_RelatedFrame;} + + void SetRelatedStatusBar(int bar); + // after(!) calling SetRelatedFrame, this sets statusbar slot where messages + // will be displayed. Default is -1 = no messages. + + void SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes); + // sets fonts to be used when displaying HTML page. + // *_italic_mode can be either wxSLANT or wxITALIC + + void SetTitle(const wxString& title); + // Sets the title of the window + // (depending on the information passed to SetRelatedFrame() method) + + void SetBorders(int b) {m_Borders = b;} + // Sets space between text and window borders. + + virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString); + // saves custom settings into cfg config. it will use the path 'path' + // if given, otherwise it will save info into currently selected path. + // saved values : things set by SetFonts, SetBorders. + virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString); + // ... + + bool HistoryBack(); + bool HistoryForward(); + // Goes to previous/next page (in browsing history) + // Returns TRUE if successful, FALSE otherwise + void HistoryClear(); + // Resets history + + wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;} + // Returns pointer to conteiners/cells structure. + // It should be used ONLY when printing + + static void AddFilter(wxHtmlFilter *filter); + // Adds input filter + + virtual void OnLinkClicked(const wxString& link); + // called when users clicked on hypertext link. Default behavior is to + // call LoadPage(loc) + + protected: + bool ScrollToAnchor(const wxString& anchor); + // Scrolls to anchor of this name. (Anchor is #news + // or #features etc. it is part of address sometimes: + // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news) + // Return value : TRUE if anchor exists, FALSE otherwise + + void CreateLayout(); + // prepare layout (= fill m_PosX, m_PosY for fragments) based on actual size of + // window. This method also setup scrollbars + + void OnDraw(wxDC& dc); + void OnSize(wxSizeEvent& event); + void OnMouseEvent(wxMouseEvent& event); + void OnIdle(wxIdleEvent& event); + void OnKeyDown(wxKeyEvent& event); + + DECLARE_EVENT_TABLE() +}; + + + +#endif // __HTMLWIN_H__ + +#endif + + + diff --git a/include/wx/html/htmlwinparser.h b/include/wx/html/htmlwinparser.h new file mode 100644 index 0000000000..fa1769c5ba --- /dev/null +++ b/include/wx/html/htmlwinparser.h @@ -0,0 +1,219 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlwinparser.h +// Purpose: wxHtmlWinParser class (parser to be used with wxHtmlWindow) +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __HTMLWINPARSER_H__ +#define __HTMLWINPARSER_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#if wxUSE_HTML + +#include +#include +#include + +class wxHtmlWinParser; +class wxHtmlWinTagHandler; +class wxHtmlTagsModule; + +//-------------------------------------------------------------------------------- +// wxHtmlWinParser +// This class is derived from wxHtmlParser and its mail goal +// is to parse HTML input so that it can be displayed in +// wxHtmlWindow. It uses special wxHtmlWinTagHandler. +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser +{ + DECLARE_DYNAMIC_CLASS(wxHtmlWinParser) + + friend class wxHtmlWindow; + + private: + wxWindow *m_Window; + // window we're parsing for + wxDC *m_DC; + // Device Context we're parsing for + static wxList m_Modules; + // list of tags modules (see wxHtmlTagsModule for details) + // This list is used to initialize m_Handlers member. + + wxHtmlContainerCell *m_Container; + // actual container. See Open/CloseContainer for details. + + int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not TRUE,FALSE but 1,0, we need it for indexing + int m_FontSize; /* -2 to +4, 0 is default */ + wxColour m_LinkColor; + wxColour m_ActualColor; + // basic font parameters. + wxString m_Link; + // actual hypertext link or empty string + bool m_UseLink; + // TRUE if m_Link is not empty + long m_CharHeight, m_CharWidth; + // average height of normal-sized text + int m_Align; + // actual alignment + + wxFont *m_FontsTable[2][2][2][2][7]; + // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off + // state of these flags (from left to right): + // [bold][italic][underlined][fixed_size] + // last index is font size : from 0 to 7 (remapped from html sizes -2 to +4) + // Note : this table covers all possible combinations of fonts, but not + // all of them are used, so many items in table are usually NULL. + int m_FontsSizes[7]; + wxString m_FontFaceFixed, m_FontFaceNormal; + int m_ItalicModeFixed, m_ItalicModeNormal; + // html font sizes and faces of fixed and proportional fonts + + public: + wxHtmlWinParser() : wxHtmlParser() {wxHtmlWinParser(NULL);} + wxHtmlWinParser(wxWindow *wnd); + + virtual void InitParser(const wxString& source); + virtual void DoneParser(); + virtual wxObject* GetProduct(); + + virtual void SetDC(wxDC *dc) {m_DC = dc;} + // Set's the DC used for parsing. If SetDC() is not called, + // parsing won't proceed + wxDC *GetDC() {return m_DC;} + int GetCharHeight() const {return m_CharHeight;} + int GetCharWidth() const {return m_CharWidth;} + // NOTE : these functions do _not_ return _actual_ + // height/width. They return h/w of default font + // for this DC. If you want actual values, call + // GetDC() -> GetChar...() + wxWindow *GetWindow() {return m_Window;} + // returns associated wxWindow + + void SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes); + // sets fonts to be used when displaying HTML page. + // *_italic_mode can be either wxSLANT or wxITALIC + + virtual wxList* GetTempData(); + + static void AddModule(wxHtmlTagsModule *module); + // Adds tags module. see wxHtmlTagsModule for details. + + // parsing-related methods. These methods are called by tag handlers: + wxHtmlContainerCell *GetContainer() const {return m_Container;} + // Returns pointer to actual container. Common use in tag handler is : + // m_WParser -> GetContainer() -> InsertCell(new ...); + wxHtmlContainerCell *OpenContainer(); + // opens new container. This container is sub-container of opened + // container. Sets GetContainer to newly created container + // and returns it. + wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); + // works like OpenContainer except that new container is not created + // but c is used. You can use this to directly set actual container + wxHtmlContainerCell *CloseContainer(); + // closes the container and sets actual Container to upper-level + // container + + int GetFontSize() const {return m_FontSize;} + void SetFontSize(int s) {m_FontSize = s;} + int GetFontBold() const {return m_FontBold;} + void SetFontBold(int x) {m_FontBold = x;} + int GetFontItalic() const {return m_FontItalic;} + void SetFontItalic(int x) {m_FontItalic = x;} + int GetFontUnderlined() const {return m_FontUnderlined;} + void SetFontUnderlined(int x) {m_FontUnderlined = x;} + int GetFontFixed() const {return m_FontFixed;} + void SetFontFixed(int x) {m_FontFixed = x;} + + int GetAlign() const {return m_Align;} + void SetAlign(int a) {m_Align = a;} + const wxColour& GetLinkColor() const {return m_LinkColor;} + void SetLinkColor(const wxColour& clr) {m_LinkColor = clr;} + const wxColour& GetActualColor() const {return m_ActualColor;} + void SetActualColor(const wxColour& clr) {m_ActualColor = clr;} + const wxString& GetLink() const {return m_Link;} + void SetLink(const wxString& link) {m_Link = link; m_UseLink = link.Length() > 0;} + + virtual wxFont* CreateCurrentFont(); + // creates font depending on m_Font* members. + // (note : it calls wxHtmlWindow's CreateCurrentFont...) + + protected: + virtual void AddText(const char *txt); + + private: + bool m_tmpLastWasSpace; + // temporary variable used by AddText +}; + + + + + + +//-------------------------------------------------------------------------------- +// wxHtmlWinTagHandler +// This is basicly wxHtmlTagHandler except +// it is extended with protected member m_Parser pointing to +// the wxHtmlWinParser object +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlWinTagHandler : public wxHtmlTagHandler +{ + DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler) + + protected: + wxHtmlWinParser *m_WParser; + // same as m_Parser, but overcasted + + public: + wxHtmlWinTagHandler() : wxHtmlTagHandler() {}; + + virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;}; +}; + + + + + + +//-------------------------------------------------------------------------------- +// wxHtmlTagsModule +// This is basic of dynamic tag handlers binding. +// The class provides methods for filling parser's handlers +// hash table. +// (See documentation for details) +//-------------------------------------------------------------------------------- + +class WXDLLEXPORT wxHtmlTagsModule : public wxModule +{ + DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule) + + public: + wxHtmlTagsModule() : wxModule() {}; + + virtual bool OnInit(); + virtual void OnExit(); + + virtual void FillHandlersTable(wxHtmlWinParser *parser) {} + // This is called by wxHtmlWinParser. + // The method must simply call parser->AddTagHandler(new ); + // for each handler + +}; + + + +#endif // __HTMLWINPARSER_H__ + +#endif + + + diff --git a/include/wx/html/mod_templ.h b/include/wx/html/mod_templ.h new file mode 100644 index 0000000000..cb9f3fadb6 --- /dev/null +++ b/include/wx/html/mod_templ.h @@ -0,0 +1,102 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: mod_templ.h +// Purpose: wxHtml tags module generic "template" +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +/* + +DESCRIPTION: +This is set of macros for easier writing of tag handlers. How to use it? +See mod_fonts.cpp for example... + +Attention! This is quite strange C++ bastard. Before using it, +I STRONGLY recommend reading and understanding these macros!! + +*/ + + +#ifndef __MOD_TEMPL_H__ +#define __MOD_TEMPL_H__ + +#include "wx/defs.h" +#if wxUSE_HTML + + +#ifdef __GNUG__ +#pragma interface +#pragma implementation +#endif + +#include + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + + + + +#include + + +#define TAG_HANDLER_BEGIN(name,tags) \ + class HTML_Handler_##name : public wxHtmlWinTagHandler \ + { \ + public: \ + wxString GetSupportedTags() {return tags;} + + + +#define TAG_HANDLER_VARS \ + private: + +#define TAG_HANDLER_CONSTR(name) \ + public: \ + HTML_Handler_##name () : wxHtmlWinTagHandler() + + +#define TAG_HANDLER_PROC(varib) \ + public: \ + bool HandleTag(const wxHtmlTag& varib) + + + +#define TAG_HANDLER_END(name) \ + }; + + + + +#define TAGS_MODULE_BEGIN(name) \ + class HTML_Module##name : public wxHtmlTagsModule \ + { \ + DECLARE_DYNAMIC_CLASS(HTML_Module##name ) \ + public: \ + void FillHandlersTable(wxHtmlWinParser *parser) \ + { + + + + +#define TAGS_MODULE_ADD(handler) \ + parser -> AddTagHandler(new HTML_Handler_##handler); + + + + +#define TAGS_MODULE_END(name) \ + } \ + }; \ + IMPLEMENT_DYNAMIC_CLASS(HTML_Module##name , wxHtmlTagsModule) + + + +#endif +#endif \ No newline at end of file diff --git a/include/wx/html/msw/back.bmp b/include/wx/html/msw/back.bmp new file mode 100644 index 0000000000..a81d37879a Binary files /dev/null and b/include/wx/html/msw/back.bmp differ diff --git a/include/wx/html/msw/book.ico b/include/wx/html/msw/book.ico new file mode 100644 index 0000000000..2b32793135 Binary files /dev/null and b/include/wx/html/msw/book.ico differ diff --git a/include/wx/html/msw/folder.ico b/include/wx/html/msw/folder.ico new file mode 100644 index 0000000000..ead2829ada Binary files /dev/null and b/include/wx/html/msw/folder.ico differ diff --git a/include/wx/html/msw/forward.bmp b/include/wx/html/msw/forward.bmp new file mode 100644 index 0000000000..ec26993fd2 Binary files /dev/null and b/include/wx/html/msw/forward.bmp differ diff --git a/include/wx/html/msw/page.ico b/include/wx/html/msw/page.ico new file mode 100644 index 0000000000..46114c9e2a Binary files /dev/null and b/include/wx/html/msw/page.ico differ diff --git a/include/wx/html/msw/panel.bmp b/include/wx/html/msw/panel.bmp new file mode 100644 index 0000000000..e735d3584b Binary files /dev/null and b/include/wx/html/msw/panel.bmp differ diff --git a/include/wx/html/msw/wxhtml.rc b/include/wx/html/msw/wxhtml.rc new file mode 100644 index 0000000000..99c310f430 --- /dev/null +++ b/include/wx/html/msw/wxhtml.rc @@ -0,0 +1,16 @@ + +// +// This file contains bitmaps used +// by wxHtmlHelpController +// Include it in your .rc file if you're using wxHTML help system +// (#include "wx/html/msw/wxhtml.rc") +// + +back BITMAP "wx/html/msw/back.bmp" +forward BITMAP "wx/html/msw/forward.bmp" +panel BITMAP "wx/html/msw/panel.bmp" + +book ICON "wx/html/msw/book.ico" +folder ICON "wx/html/msw/folder.ico" +page ICON "wx/html/msw/page.ico" + diff --git a/include/wx/html/version.h b/include/wx/html/version.h new file mode 100644 index 0000000000..49ff8aeae8 --- /dev/null +++ b/include/wx/html/version.h @@ -0,0 +1,7 @@ + +#define wxHTML_VERSION_MAJOR 0 +#define wxHTML_VERSION_MINOR 2 +#define wxHTML_VERSION_REL 3 + +#define wxHTML_VERSION (wxHTML_VERSION_MAJOR * 1000 + wxHTML_VERSION_MINOR * 100 + wxHTML_VERSION_REL) + diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index d7a89dba0a..b67a81cd27 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -198,6 +198,8 @@ // wxWindow::SetToolTip() method #define wxUSE_SOCKETS 0 // Set to 1 to use socket classes +#define wxUSE_HTML 0 + // Set to 1 to use wxHTML sub-library /* * Finer detail diff --git a/include/wx/wxhtml.h b/include/wx/wxhtml.h new file mode 100644 index 0000000000..f8082a7aaa --- /dev/null +++ b/include/wx/wxhtml.h @@ -0,0 +1,27 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxhtml.h +// Purpose: wxHTML library for wxWindows +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef __WXHTML_H__ +#define __WXHTML_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // __WXHTML_H__ diff --git a/include/wx/zipstream.h b/include/wx/zipstream.h new file mode 100644 index 0000000000..6da057c473 --- /dev/null +++ b/include/wx/zipstream.h @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: zipstream.h +// Purpose: wxZipInputStream for reading files from ZIP archive +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef __ZIPSTREAM_H__ +#define __ZIPSTREAM_H__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#if wxUSE_ZLIB && wxUSE_STREAMS + +#include + +//-------------------------------------------------------------------------------- +// wxZipInputStream +// This class is input stream from ZIP archive. The archive +// must be local file (accessible via FILE*) +//-------------------------------------------------------------------------------- + + +class WXDLLEXPORT wxZipInputStream : public wxInputStream +{ + private: + size_t m_Size; + off_t m_Pos; + void *m_Archive; + // this void* is handle of archive . + // I'm sorry it is void and not proper type but I don't want + // to make unzip.h header public. + + public: + wxZipInputStream(const wxString& archive, const wxString& file); + // archive is name of .zip archive, file is name of file to be extracted. + // Remember that archive must be local file accesible via fopen, fread functions! + ~wxZipInputStream(); + + protected: + virtual size_t StreamSize() const {return m_Size;} + virtual size_t OnSysRead(void *buffer, size_t bufsize); + virtual off_t OnSysSeek(off_t seek, wxSeekMode mode); + virtual off_t OnSysTell() const {return m_Pos;} +}; + + +#endif // if use_zlib && use_streams + +#endif // __ZIPSTREAM_H__ + + + + + + + + + + + + + + + + + diff --git a/samples/html/Makefile.am b/samples/html/Makefile.am new file mode 100644 index 0000000000..6eee574d1b --- /dev/null +++ b/samples/html/Makefile.am @@ -0,0 +1,8 @@ +## Purpose: The automake makefile for wxHTML samples +## Author: VS +## Version: $Id$ +## +## Process this file with automake to produce Makefile.in + +SUBDIRS = about help printing test virtual widget zip + diff --git a/samples/html/about/Makefile.am b/samples/html/about/Makefile.am new file mode 100644 index 0000000000..56e4183fdc --- /dev/null +++ b/samples/html/about/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = about + +about_SOURCES = about.cpp diff --git a/samples/html/about/about.cpp b/samples/html/about/about.cpp new file mode 100644 index 0000000000..7bfb813b2e --- /dev/null +++ b/samples/html/about/about.cpp @@ -0,0 +1,174 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: test.cpp +// Purpose: wxHtml testing example +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "test.cpp" + #pragma interface "test.cpp" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include +#endif + +#include +#include + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + + +// Define a new application type, each program should derive a class from wxApp + class MyApp : public wxApp + { + public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + virtual bool OnInit(); + }; + +// Define a new frame type: this is going to be our main frame + class MyFrame : public wxFrame + { + public: + // ctor(s) + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + + // event handlers (these functions should _not_ be virtual) + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + + private: + // any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + }; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// IDs for the controls and the menu commands + enum + { + // menu items + Minimal_Quit = 1, + Minimal_About, + Minimal_Back, + Minimal_Forward, + + // controls start here (the numbers are, of course, arbitrary) + Minimal_Text = 1000, + }; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +// the event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. + BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(Minimal_Quit, MyFrame::OnQuit) + EVT_MENU(Minimal_About, MyFrame::OnAbout) + END_EVENT_TABLE() + + // Create a new application object: this macro will allow wxWindows to create + // the application object during program execution (it's better than using a + // static object for many reasons) and also declares the accessor function + // wxGetApp() which will return the reference of the right type (i.e. MyApp and + // not wxApp) + IMPLEMENT_APP(MyApp) + + // ============================================================================ + // implementation + // ============================================================================ + + // ---------------------------------------------------------------------------- + // the application class + // ---------------------------------------------------------------------------- + // `Main program' equivalent: the program execution "starts" here + bool MyApp::OnInit() + { + wxImage::AddHandler(new wxPNGHandler); + // Create the main application window + MyFrame *frame = new MyFrame("wxHtmlWindow testing application", + wxPoint(50, 50), wxSize(150, 50)); + + // Show it and tell the application that it's our main window + // @@@ what does it do exactly, in fact? is it necessary here? + frame->Show(TRUE); + SetTopWindow(frame); + + + // success: wxApp::OnRun() will be called which will enter the main message + // loop and the application will run. If we returned FALSE here, the + // application would exit immediately. + return TRUE; + } + +// ---------------------------------------------------------------------------- +// main frame +// ---------------------------------------------------------------------------- + + +// frame constructor + MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame((wxFrame *)NULL, -1, title, pos, size) + { + // create a menu bar + wxMenu *menuFile = new wxMenu; + + menuFile->Append(Minimal_About, "&About"); + menuFile->Append(Minimal_Quit, "E&xit"); + + // now append the freshly created menu to the menu bar... + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(menuFile, "&File"); + + // ... and attach this menu bar to the frame + SetMenuBar(menuBar); + } + + +// event handlers + + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) + { + // TRUE is to force the frame to close + Close(TRUE); + } + + void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) + { + wxHtmlWindow *html; + wxDialog dlg(this, -1, "About", wxDefaultPosition, wxSize(400, 230), wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE); + + html = new wxHtmlWindow(&dlg, -1, wxPoint(10, 10), wxSize(380, 160), "htmlWindow", FALSE); + html -> SetBorders(0); + html -> LoadPage("data/about.htm"); + wxButton *bu1 = new wxButton(&dlg, wxID_OK, "OK", wxPoint(250, 185), wxSize(100, 30)); + bu1 -> SetDefault(); + dlg.ShowModal(); + } + + + + + + + diff --git a/samples/html/about/about.rc b/samples/html/about/about.rc new file mode 100644 index 0000000000..82bdf07561 --- /dev/null +++ b/samples/html/about/about.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" + diff --git a/samples/html/about/data/about.htm b/samples/html/about/data/about.htm new file mode 100644 index 0000000000..b3bfa67dfc --- /dev/null +++ b/samples/html/about/data/about.htm @@ -0,0 +1,17 @@ + +
+
+
wxHTML Library Sample 0.2.0
+
+
+Copyright (C) 1999 Vaclav Slavik

+ + +
+Vaclav Slavik (slavik2@czn.cz)
Someone Else (selse@hell.org)

+

+
+ +The wxHTML library is available at http://www.ms.mff.cuni.cz/~vsla8348/wxhtml
+The library is licenced under wxWindows Library Licence, Version 3. +

diff --git a/samples/html/about/data/logo.png b/samples/html/about/data/logo.png new file mode 100644 index 0000000000..6c5e312049 Binary files /dev/null and b/samples/html/about/data/logo.png differ diff --git a/samples/html/help/Makefile.am b/samples/html/help/Makefile.am new file mode 100644 index 0000000000..99eba9fb57 --- /dev/null +++ b/samples/html/help/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = help + +help_SOURCES = help.cpp diff --git a/samples/html/help/help.cpp b/samples/html/help/help.cpp new file mode 100644 index 0000000000..22677fee69 --- /dev/null +++ b/samples/html/help/help.cpp @@ -0,0 +1,85 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: test.cpp +// Purpose: wxHtml testing example +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation + #pragma interface +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include +#endif + +#include +#include +#if (( wxVERSION_NUMBER < 2100 ) || (( wxVERSION_NUMBER == 2100 ) && (wxBETA_NUMBER <= 4))) +#include +#endif +#include + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp + class MyApp : public wxApp + { + private: + wxHtmlHelpController help; + wxConfig* config; + + public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + bool OnInit(); + int OnExit(); + }; + + IMPLEMENT_APP(MyApp) + + + bool MyApp::OnInit() + { + config = new wxConfig("wxHTMLhelp"); + #if wxUSE_LIBPNG + wxImage::AddHandler(new wxPNGHandler); + #endif + #if wxUSE_LIBJPEG + wxImage::AddHandler(new wxJPEGHandler); + #endif + + help.UseConfig(config); + help.SetTempDir("tmp"); + help.AddBook("helpfiles/testing.hhp"); + help.Display("Main page"); + return TRUE; + } + + int MyApp::OnExit() + { + delete config; + return 0; + } + + + + + + + + diff --git a/samples/html/help/help.rc b/samples/html/help/help.rc new file mode 100644 index 0000000000..7fa90c817b --- /dev/null +++ b/samples/html/help/help.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" +#include "wx/html/msw/wxhtml.rc" diff --git a/samples/html/help/helpfiles/Index.hhk b/samples/html/help/helpfiles/Index.hhk new file mode 100644 index 0000000000..a9ab87b4a0 --- /dev/null +++ b/samples/html/help/helpfiles/Index.hhk @@ -0,0 +1,24 @@ + + + + + + +

    +
  • + + + + +
  • + + + + +
  • + + + + +
+ diff --git a/samples/html/help/helpfiles/book1.htm b/samples/html/help/helpfiles/book1.htm new file mode 100644 index 0000000000..fa470e3ec5 --- /dev/null +++ b/samples/html/help/helpfiles/book1.htm @@ -0,0 +1,4 @@ +Book 1 +

Book 1.

+How do you enjoy book one?? + diff --git a/samples/html/help/helpfiles/book2.htm b/samples/html/help/helpfiles/book2.htm new file mode 100644 index 0000000000..828723fc65 --- /dev/null +++ b/samples/html/help/helpfiles/book2.htm @@ -0,0 +1,5 @@ +Book 1 +

Book 2.

+How do you enjoy book two?? +

Please click HERE + diff --git a/samples/html/help/helpfiles/contents.hhc b/samples/html/help/helpfiles/contents.hhc new file mode 100644 index 0000000000..3eb7c2c974 --- /dev/null +++ b/samples/html/help/helpfiles/contents.hhc @@ -0,0 +1,33 @@ + + + + + + + + + +

    +
  • + + + +
      +
    • + + + +
    • + + + + +
        +
      • + + + +
      +
    +
+ diff --git a/samples/html/help/helpfiles/main.htm b/samples/html/help/helpfiles/main.htm new file mode 100644 index 0000000000..ca5275bfd7 --- /dev/null +++ b/samples/html/help/helpfiles/main.htm @@ -0,0 +1,5 @@ + +

This is main page.

+Book 1
+Book 2
+ diff --git a/samples/html/help/helpfiles/page2-b.htm b/samples/html/help/helpfiles/page2-b.htm new file mode 100644 index 0000000000..f51dd6d6d6 --- /dev/null +++ b/samples/html/help/helpfiles/page2-b.htm @@ -0,0 +1,5 @@ + + +Hello, you're on sub page of page 2 !!! + + diff --git a/samples/html/help/helpfiles/testing.hhp b/samples/html/help/helpfiles/testing.hhp new file mode 100644 index 0000000000..5cd4d4e87f --- /dev/null +++ b/samples/html/help/helpfiles/testing.hhp @@ -0,0 +1,15 @@ +[OPTIONS] +Compatibility=1.1 +Compiled file=testing.chm +Contents file=contents.hhc +Display compile progress=No +Index file=Index.hhk +Language=0x405 Èesky +Title=Testing HELPFILE :-) +Default topic=main.htm + +[FILES] +main.htm +book1.htm +book2.htm +page2-b.htm diff --git a/samples/html/printing/Makefile.am b/samples/html/printing/Makefile.am new file mode 100644 index 0000000000..73aa8ade60 --- /dev/null +++ b/samples/html/printing/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = printing + +printing_SOURCES = printing.cpp diff --git a/samples/html/printing/mondrian.ico b/samples/html/printing/mondrian.ico new file mode 100644 index 0000000000..2310c5d275 Binary files /dev/null and b/samples/html/printing/mondrian.ico differ diff --git a/samples/html/printing/mondrian.xpm b/samples/html/printing/mondrian.xpm new file mode 100644 index 0000000000..409f27a843 --- /dev/null +++ b/samples/html/printing/mondrian.xpm @@ -0,0 +1,44 @@ +/* XPM */ +static char *mondrian_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 6 1", +" c Black", +". c Blue", +"X c #00bf00", +"o c Red", +"O c Yellow", +"+ c Gray100", +/* pixels */ +" ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" " +}; diff --git a/samples/html/printing/pic.png b/samples/html/printing/pic.png new file mode 100644 index 0000000000..fcc18c1296 Binary files /dev/null and b/samples/html/printing/pic.png differ diff --git a/samples/html/printing/printing.cpp b/samples/html/printing/printing.cpp new file mode 100644 index 0000000000..2febc3bd6c --- /dev/null +++ b/samples/html/printing/printing.cpp @@ -0,0 +1,312 @@ +/* + * File: printing.cc + * Purpose: Printing demo for wxWindows class library + * Author: Julian Smart + * modified by Vaclav Slavik (wxHTML stuffs) + * Created: 1995 + * Updated: + * Copyright: (c) 1995, AIAI, University of Edinburgh + */ + +/* static const char sccsid[] = "%W% %G%"; */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#if !wxUSE_PRINTING_ARCHITECTURE +#error You must set wxUSE_PRINTING_ARCHITECTURE to 1 in setup.h to compile this demo. +#endif + +// Set this to 1 if you want to test PostScript printing under MSW. +// However, you'll also need to edit src/msw/makefile.nt. + +//!!! DON'T DO THAT! This is wxHTML sample now +#define wxTEST_POSTSCRIPT_IN_MSW 0 + +#include +#include "wx/metafile.h" +#include "wx/print.h" +#include "wx/printdlg.h" + +#include "wx/accel.h" + +#if wxTEST_POSTSCRIPT_IN_MSW +#include "wx/generic/printps.h" +#include "wx/generic/prntdlgg.h" +#endif + +#include +#include +#include "printing.h" + +#ifndef __WXMSW__ +#include "mondrian.xpm" +#endif + +// Global print data, to remember settings during the session +wxPrintData *g_printData = (wxPrintData*) NULL ; + +// Global page setup data +wxPageSetupData* g_pageSetupData = (wxPageSetupData*) NULL; + + +// Declare a frame +MyFrame *frame = (MyFrame *) NULL; +wxHtmlWindow *html = NULL; +int orientation = wxPORTRAIT; + +// Main proc +IMPLEMENT_APP(MyApp) + + +MyApp::MyApp() +{ +} + +// The `main program' equivalent, creating the windows and returning the +// main frame +bool MyApp::OnInit(void) +{ + g_printData = new wxPrintData; + g_pageSetupData = new wxPageSetupDialogData; + + // Create the main frame window + frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows Printing Demo", wxPoint(0, 0), wxSize(600, 400)); + + // Give it a status line + frame->CreateStatusBar(2); + + // Load icon and bitmap + frame->SetIcon( wxICON( mondrian) ); + + // Make a menubar + wxMenu *file_menu = new wxMenu; + + file_menu->Append(WXPRINT_PRINT, "&Print...", "Print"); + file_menu->Append(WXPRINT_PRINT_SETUP, "Print &Setup...", "Setup printer properties"); + file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup"); + file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view", "Preview"); + + // Accelerators + wxAcceleratorEntry entries[1]; + entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW); + wxAcceleratorTable accel(1, entries); + frame->SetAcceleratorTable(accel); + + file_menu->AppendSeparator(); + file_menu->Append(WXPRINT_QUIT, "E&xit", "Exit program"); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(WXPRINT_ABOUT, "&About", "About this demo"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(help_menu, "&Help"); + + // Associate the menu bar with the frame + frame->SetMenuBar(menu_bar); + + frame->Centre(wxBOTH); + frame->Show(TRUE); + + frame->SetStatusText("Printing demo"); + + SetTopWindow(frame); + + return TRUE; +} + +int MyApp::OnExit() +{ + delete g_printData; + delete g_pageSetupData; + return 1; +} + +BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(WXPRINT_QUIT, MyFrame::OnExit) + EVT_MENU(WXPRINT_PRINT, MyFrame::OnPrint) + EVT_MENU(WXPRINT_PREVIEW, MyFrame::OnPrintPreview) + EVT_MENU(WXPRINT_PRINT_SETUP, MyFrame::OnPrintSetup) + EVT_MENU(WXPRINT_PAGE_SETUP, MyFrame::OnPageSetup) + EVT_MENU(WXPRINT_ABOUT, MyFrame::OnPrintAbout) +END_EVENT_TABLE() + +// Define my frame constructor +MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size): + wxFrame(frame, -1, title, pos, size) +{ + html = new wxHtmlWindow(this); + html -> LoadPage("test.htm"); +} + +void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) +{ + Close(TRUE); +} + +void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) +{ + wxPrinter printer; + MyPrintout printout("My printout"); + if (!printer.Print(this, &printout, TRUE)) + wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK); +} + +void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) +{ + wxPrintData printData; + printData.SetOrientation(orientation); + + // Pass two printout objects: for preview, and possible printing. + wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printData); + if (!preview->Ok()) + { + delete preview; + wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK); + return; + } + + wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); + frame->Centre(wxBOTH); + frame->Initialize(); + frame->Show(TRUE); +} + +void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) +{ + wxPrintDialogData printDialogData(* g_printData); + wxPrintDialog printerDialog(this, & printDialogData); + + printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); + printerDialog.ShowModal(); + + (*g_printData) = printerDialog.GetPrintDialogData().GetPrintData(); +} + +void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event)) +{ + (*g_pageSetupData) = * g_printData; + + wxPageSetupDialog pageSetupDialog(this, g_pageSetupData); + pageSetupDialog.ShowModal(); + + (*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData(); + (*g_pageSetupData) = pageSetupDialog.GetPageSetupData(); +} + + + +void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event)) +{ + (void)wxMessageBox("wxWindows printing demo\nAuthor: Julian Smart julian.smart@ukonline.co.uk\n\nModified by Vaclav Slavik to show wxHtml features", + "About wxWindows printing demo", wxOK|wxCENTRE); +} + + +bool MyPrintout::OnPrintPage(int page) +{ + wxDC *dc = GetDC(); + if (dc) + { + if (page == 1) + DrawPageOne(dc); + + return TRUE; + } + else + return FALSE; +} + +bool MyPrintout::OnBeginDocument(int startPage, int endPage) +{ + if (!wxPrintout::OnBeginDocument(startPage, endPage)) + return FALSE; + + return TRUE; +} + +void MyPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) +{ + *minPage = 1; + *maxPage = 1; + *selPageFrom = 1; + *selPageTo = 1; +} + +bool MyPrintout::HasPage(int pageNum) +{ + return (pageNum == 1); +} + + +void MyPrintout::DrawPageOne(wxDC *dc) +{ + int leftMargin = 20; + int topMargin = 40; + +/* You might use THIS code to set the printer DC to ROUGHLY reflect + * the screen text size. This page also draws lines of actual length 5cm + * on the page. + */ + // Get the logical pixels per inch of screen and printer + int ppiScreenX, ppiScreenY; + GetPPIScreen(&ppiScreenX, &ppiScreenY); + int ppiPrinterX, ppiPrinterY; + GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); + + // Here we obtain internal cell representation of HTML document: + wxHtmlContainerCell *cell = html -> GetInternalRepresentation(); + + // Now we have to check in case our real page size is reduced + // (e.g. because we're drawing to a print preview memory DC) + int pageWidth, pageHeight; + int w, h; + dc->GetSize(&w, &h); + GetPageSizePixels(&pageWidth, &pageHeight); + + // Now we must scale it somehow. The best would be to suppose that html window + // width is equal to page width: + + float scale = (float)((float)(pageWidth - 0 * leftMargin)/((float)cell -> GetMaxLineWidth() + 2 * leftMargin)); + + // If printer pageWidth == current DC width, then this doesn't + // change. But w might be the preview bitmap width, so scale down. + float overallScale = scale * (float)(w/(float)pageWidth); + dc->SetUserScale(overallScale, overallScale); + + // Calculate conversion factor for converting millimetres into + // logical units. + // There are approx. 25.1 mm to the inch. There are ppi + // device units to the inch. Therefore 1 mm corresponds to + // ppi/25.1 device units. We also divide by the + // screen-to-printer scaling factor, because we need to + // unscale to pass logical units to DrawLine. + + dc->SetBackgroundMode(wxTRANSPARENT); + + // TESTING + + int pageWidthMM, pageHeightMM; + GetPageSizeMM(&pageWidthMM, &pageHeightMM); + + + // This is all the printing : + cell -> Draw(*dc, leftMargin, topMargin, 0, cell -> GetHeight()); +} + + + diff --git a/samples/html/printing/printing.h b/samples/html/printing/printing.h new file mode 100644 index 0000000000..ba50b4e216 --- /dev/null +++ b/samples/html/printing/printing.h @@ -0,0 +1,76 @@ +/* + * File: printing.h + * Purpose: Printing demo for wxWindows class library + * Author: Julian Smart + * Created: 1995 + * Updated: + * Copyright: (c) 1995, AIAI, University of Edinburgh + */ + +/* sccsid[] = "%W% %G%" */ + +#ifdef __GNUG__ +#pragma interface +#endif + +// Define a new application +class MyApp: public wxApp +{ + public: + MyApp() ; + bool OnInit(); + int OnExit(); +}; + +DECLARE_APP(MyApp) + +class MyCanvas; + +// Define a new canvas and frame +class MyFrame: public wxFrame +{ + public: + MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size); + + void OnPrint(wxCommandEvent& event); + void OnPrintPreview(wxCommandEvent& event); + void OnPrintSetup(wxCommandEvent& event); + void OnPageSetup(wxCommandEvent& event); +#if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW + void OnPrintPS(wxCommandEvent& event); + void OnPrintPreviewPS(wxCommandEvent& event); + void OnPrintSetupPS(wxCommandEvent& event); + void OnPageSetupPS(wxCommandEvent& event); +#endif + + void OnExit(wxCommandEvent& event); + void OnPrintAbout(wxCommandEvent& event); +DECLARE_EVENT_TABLE() +}; + + +class MyPrintout: public wxPrintout +{ + public: + MyPrintout(char *title = "My printout"):wxPrintout(title) {} + bool OnPrintPage(int page); + bool HasPage(int page); + bool OnBeginDocument(int startPage, int endPage); + void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo); + + void DrawPageOne(wxDC *dc); +}; + +#define WXPRINT_QUIT 100 +#define WXPRINT_PRINT 101 +#define WXPRINT_PRINT_SETUP 102 +#define WXPRINT_PAGE_SETUP 103 +#define WXPRINT_PREVIEW 104 + +#define WXPRINT_PRINT_PS 105 +#define WXPRINT_PRINT_SETUP_PS 106 +#define WXPRINT_PAGE_SETUP_PS 107 +#define WXPRINT_PREVIEW_PS 108 + +#define WXPRINT_ABOUT 109 + diff --git a/samples/html/printing/printing.rc b/samples/html/printing/printing.rc new file mode 100644 index 0000000000..7655c62a4c --- /dev/null +++ b/samples/html/printing/printing.rc @@ -0,0 +1,3 @@ +mondrian ICON "mondrian.ico" +#include "wx/msw/wx.rc" + diff --git a/samples/html/printing/test.htm b/samples/html/printing/test.htm new file mode 100644 index 0000000000..ca2d7dfba1 --- /dev/null +++ b/samples/html/printing/test.htm @@ -0,0 +1,126 @@ + + + + + + + +This is - - default text, now switching to +
+

center, now still ctr, now exiting

+ +

exited!.[link to down] +

Hello, this *is* default charset (helvetica, probably) and it is displayed +with one  COLOR CHANGE. Of course we +can have as many color changes as we can, what about this MADNESS? +

There was a space above. +
+


This was a line. (BTW we are in fixed font +/ typewriter font right now :-) +
This is in BOLD face. This is ITALIC. This is E +V E R Y T H I N G. +
  +
  +
+
+
+
+

Right now, centered REALLY Big Text, +how do you like (space) it?

+ +
RIGHT: text-2, text-1, +text+0, +text+1, +text+2, +text+3, +text+4 +
we are right now
+ +
we are center now
+we are left now. +

Blue italic text is displayed there.... +

+ +
This is heading one.

+this is normal +
+

+This is CENTERED heading one

+Testing image imageand this is text...... +
  +
    +
  • +item 1
  • + +
  • +item 2
  • + +
      +
    • +nested item
    • + +
    • +nested item 2
    • +
    + +
  • +item 3
  • +
+ +
    +
  1. +item one
  2. + +
  3. +item two
  4. + +
      +
    1. +nsted item
    2. +
    + +
  5. +last numbered item
  6. +
+ +

+Heading 1

+Italic text now... +

+Heading 2

+and now? +

+Heading 3

+ +

+Heading 4

+ +
+Heading 5
+ +
+Heading 6
+And this is normal text, once again :-) +

And yes, we're in HTML DOCUMENT, so +what about some nice hypertext link?? +

hello? +

+

This is centered paragraph

+ +

Now, you will see some PRE text: +

// This is sample C++ code:
+
+void main(int argc, char *argv[])
+{
+    printf("Go away, man!\n");
+    i = 666;
+    printf("\n\n\nCRASH\n  DOWN NOW. . .  \n");
+}
+ +

+WWW

+This is WWW link to KDE site! +
(one +folder up) + + diff --git a/samples/html/test/Makefile.am b/samples/html/test/Makefile.am new file mode 100644 index 0000000000..3631656b63 --- /dev/null +++ b/samples/html/test/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = test + +test_SOURCES = test.cpp diff --git a/samples/html/test/f.html b/samples/html/test/f.html new file mode 100644 index 0000000000..625ec44f81 --- /dev/null +++ b/samples/html/test/f.html @@ -0,0 +1,2474 @@ + +wxWindow + +
+Contents Up << >>

+ +

wxWindow

+

+wxWindow is the base class for all windows. Any +children of the window will be deleted automatically by the destructor +before the window itself is deleted.

+Derived from

+wxEvtHandler
+ +wxObject

+Include files

+<wx/window.h>

+Window styles

+The following styles can apply to all windows, although they will not always make sense for a particular +window class.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+wxSIMPLE_BORDER + +Displays a thin border around the window. wxBORDER is the old name +for this style. +
+wxDOUBLE_BORDER + +Displays a double border. Windows only. +
+wxSUNKEN_BORDER + +Displays a sunken border. +
+wxRAISED_BORDER + +Displays a raised border. +
+wxSTATIC_BORDER + +Displays a border suitable for a static control. +
+wxTRANSPARENT_WINDOW + +The window is transparent, that is, it will not receive paint +events. Windows only. +
+wxNO_3D + +Prevents the children of this window taking on 3D styles, even though +the application-wide policy is for 3D controls. Windows only. +
+wxTAB_TRAVERSAL + +Use this to enable tab traversal for non-dialog windows. +
+wxVSCROLL + +Use this style to enable a vertical scrollbar. +
+wxHSCROLL + +Use this style to enable a horizontal scrollbar. +
+wxCLIP_CHILDREN + +Use this style to eliminate flicker caused by the background being +repainted, then children being painted over them. Windows-only. +
+

+See also window styles overview.

+See also

+Event handling overview

+Members

+wxWindow::wxWindow
+wxWindow::~wxWindow
+wxWindow::AddChild
+wxWindow::CaptureMouse
+wxWindow::Center
+wxWindow::Centre
+wxWindow::Clear
+wxWindow::ClientToScreen
+wxWindow::Close
+wxWindow::ConvertDialogToPixels
+wxWindow::ConvertPixelsToDialog
+wxWindow::Destroy
+wxWindow::DestroyChildren
+wxWindow::DragAcceptFiles
+wxWindow::Enable
+wxWindow::FindFocus
+wxWindow::FindWindow
+wxWindow::Fit
+wxWindow::GetBackgroundColour
+wxWindow::GetCharHeight
+wxWindow::GetCharWidth
+wxWindow::GetChildren
+wxWindow::GetClientSize
+wxWindow::GetConstraints
+wxWindow::GetDefaultItem
+wxWindow::GetDropTarget
+wxWindow::GetEventHandler
+wxWindow::GetFont
+wxWindow::GetForegroundColour
+wxWindow::GetGrandParent
+wxWindow::GetHandle
+wxWindow::GetId
+wxWindow::GetPosition
+wxWindow::GetLabel
+wxWindow::GetName
+wxWindow::GetParent
+wxWindow::GetRect
+wxWindow::GetReturnCode
+wxWindow::GetScrollThumb
+wxWindow::GetScrollPos
+wxWindow::GetScrollRange
+wxWindow::GetSize
+wxWindow::GetTextExtent
+wxWindow::GetTitle
+wxWindow::GetUpdateRegion
+wxWindow::GetWindowStyleFlag
+wxWindow::InitDialog
+wxWindow::IsEnabled
+wxWindow::IsRetained
+wxWindow::IsShown
+wxWindow::Layout
+wxWindow::LoadFromResource
+wxWindow::Lower
+wxWindow::MakeModal
+wxWindow::Move
+wxWindow::OnActivate
+wxWindow::OnChar
+wxWindow::OnCharHook
+wxWindow::OnCommand
+wxWindow::OnClose
+wxWindow::OnCloseWindow
+wxWindow::OnDropFiles
+wxWindow::OnEraseBackground
+wxWindow::OnKeyDown
+wxWindow::OnKeyUp
+wxWindow::OnKillFocus
+wxWindow::OnIdle
+wxWindow::OnInitDialog
+wxWindow::OnMenuCommand
+wxWindow::OnMenuHighlight
+wxWindow::OnMouseEvent
+wxWindow::OnMove
+wxWindow::OnPaint
+wxWindow::OnScroll
+wxWindow::OnSetFocus
+wxWindow::OnSize
+wxWindow::OnSysColourChanged
+wxWindow::PopEventHandler
+wxWindow::PopupMenu
+wxWindow::PushEventHandler
+wxWindow::Raise
+wxWindow::Refresh
+wxWindow::ReleaseMouse
+wxWindow::RemoveChild
+wxWindow::ScreenToClient
+wxWindow::ScrollWindow
+wxWindow::SetAcceleratorTable
+wxWindow::SetAutoLayout
+wxWindow::SetBackgroundColour
+wxWindow::SetClientSize
+wxWindow::SetCursor
+wxWindow::SetEventHandler
+wxWindow::SetConstraints
+wxWindow::SetDropTarget
+wxWindow::SetFocus
+wxWindow::SetFont
+wxWindow::SetForegroundColour
+wxWindow::SetId
+wxWindow::SetName
+wxWindow::SetPalette
+wxWindow::SetReturnCode
+wxWindow::SetScrollbar
+wxWindow::SetScrollPos
+wxWindow::SetSize
+wxWindow::SetSizeHints
+wxWindow::SetTitle
+wxWindow::Show
+wxWindow::TransferDataFromWindow
+wxWindow::TransferDataToWindow
+wxWindow::Validate
+wxWindow::WarpPointer
+

+ +


+ +

wxWindow::wxWindow

+

+ wxWindow()

+Default constructor.

+ wxWindow(wxWindow* parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxPanelNameStr)

+Constructs a window, which can be a child of a frame, dialog or any other non-control window.

+Parameters

+parent

      +Pointer to a parent window.
+

+id

      +Window identifier. If -1, will automatically create an identifier.
+

+pos

      +Window position. wxDefaultPosition is (-1, -1) which indicates that wxWindows +should generate a default position for the window. If using the wxWindow class directly, supply +an actual position.
+

+size

      +Window size. wxDefaultSize is (-1, -1) which indicates that wxWindows +should generate a default size for the window.
+

+style

      +Window style. For generic window styles, please see wxWindow.
+

+name

      +Window name.
+

+ +


+ +

wxWindow::~wxWindow

+

+ ~wxWindow()

+Destructor. Deletes all subwindows, then deletes itself. Instead of using +the delete operator explicitly, you should normally +use wxWindow::Destroy so that wxWindows +can delete a window only when it is safe to do so, in idle time.

+See also

+Window deletion overview, +wxWindow::OnCloseWindow, +wxWindow::Destroy, +wxCloseEvent

+ +


+ +

wxWindow::AddChild

+

+virtual void AddChild(wxWindow* child)

+Adds a child window. This is called automatically by window creation +functions so should not be required by the application programmer.

+Parameters

+child

      +Child window to add.
+

+ +


+ +

wxWindow::CaptureMouse

+

+virtual void CaptureMouse()

+Directs all mouse input to this window. Call wxWindow::ReleaseMouse to +release the capture.

+See also

+wxWindow::ReleaseMouse

+ +


+ +

wxWindow::Center

+

+void Center(int direction)

+A synonym for Centre.

+ +


+ +

wxWindow::Centre

+

+virtual void Centre(int direction = wxHORIZONTAL)

+Centres the window.

+Parameters

+direction

      +Specifies the direction for the centering. May be wxHORIZONTAL, wxVERTICAL +or wxBOTH.
+

+Remarks

+The actual behaviour depends on the derived window. For a frame or dialog box, +centring is relative to the whole display. For a panel item, centring is +relative to the panel.

+See also

+wxWindow::Center

+ +


+ +

wxWindow::Clear

+

+void Clear()

+Clears the window by filling it with the current background colour. Does not +cause an erase background event to be generated.

+ +


+ +

wxWindow::ClientToScreen

+

+virtual void ClientToScreen(int* x, int* y) const

+virtual wxPoint ClientToScreen(const wxPoint& pt) const

+Converts to screen coordinates from coordinates relative to this window.

+x

      +A pointer to a integer value for the x coordinate. Pass the client coordinate in, and +a screen coordinate will be passed out.
+

+y

      +A pointer to a integer value for the y coordinate. Pass the client coordinate in, and +a screen coordinate will be passed out.
+

+pt

      +The client position for the second form of the function.
+

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +ClientToScreen(point) + +Accepts and returns a wxPoint +
      +ClientToScreenXY(x, y) + +Returns a 2-tuple, (x, y) +
      +
+ +

+ + +


+ +

wxWindow::Close

+

+virtual bool Close(const bool force = FALSE)

+The purpose of this call is to provide a safer way of destroying a window than using +the delete operator.

+Parameters

+force

      +FALSE if the window's close handler should be able to veto the destruction +of this window, TRUE if it cannot.
+

+Remarks

+Close calls the close handler for the window, providing an opportunity for the window to +choose whether to destroy the window.

+The close handler should check whether the window is being deleted forcibly, +using wxCloseEvent::GetForce, in which case it should +destroy the window using wxWindow::Destroy.

+Applies to managed windows (wxFrame and wxDialog classes) only.

+Note that calling Close does not guarantee that the window will be destroyed; but it +provides a way to simulate a manual close of a window, which may or may not be implemented by +destroying the window. The default implementation of wxDialog::OnCloseWindow does not +necessarily delete the dialog, since it will simply simulate an wxID_CANCEL event which +itself only hides the dialog.

+To guarantee that the window will be destroyed, call wxWindow::Destroy instead.

+See also

+Window deletion overview, +wxWindow::OnCloseWindow, +wxWindow::Destroy, +wxCloseEvent

+ +


+ +

wxWindow::ConvertDialogToPixels

+

+wxPoint ConvertDialogToPixels(const wxPoint& pt)

+wxSize ConvertDialogToPixels(const wxSize& sz)

+Converts a point or size from dialog units to pixels.

+For the x dimension, the dialog units are multiplied by the average character width +and then divided by 4.

+For the y dimension, the dialog units are multiplied by the average character height +and then divided by 8.

+Remarks

+Dialog units are used for maintaining a dialog's proportions even if the font changes. +Dialogs created using Dialog Editor optionally use dialog units.

+You can also use these functions programmatically. A convenience macro is defined:

+ +

+#define wxDLG_UNIT(parent, pt) parent->ConvertDialogToPixels(pt)
+
+

+See also

+wxWindow::ConvertPixelsToDialog

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +ConvertDialogPointToPixels(point) + +Accepts and returns a wxPoint +
      +ConvertDialogSizeToPixels(size) + +Accepts and returns a wxSize +
      +
+

+Additionally, the following helper functions are defined:

+ +

      + + + + + + + + + + + + + + +
      +wxDLG_PNT(win, point) + +Converts a wxPoint from dialog +units to pixels +
      +wxDLG_SZE(win, size) + +Converts a wxSize from dialog +units to pixels +
      +
+ +

+ + +


+ +

wxWindow::ConvertPixelsToDialog

+

+wxPoint ConvertPixelsToDialog(const wxPoint& pt)

+wxSize ConvertPixelsToDialog(const wxSize& sz)

+Converts a point or size from pixels to dialog units.

+For the x dimension, the pixels are multiplied by 4 and then divided by the average +character width.

+For the y dimension, the pixels are multipled by 8 and then divided by the average +character height.

+Remarks

+Dialog units are used for maintaining a dialog's proportions even if the font changes. +Dialogs created using Dialog Editor optionally use dialog units.

+See also

+wxWindow::ConvertDialogToPixels

+ +wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +ConvertDialogPointToPixels(point) + +Accepts and returns a wxPoint +
      +ConvertDialogSizeToPixels(size) + +Accepts and returns a wxSize +
      +
+ +

+ +


+ +

wxWindow::Destroy

+

+virtual bool Destroy()

+Destroys the window safely. Use this function instead of the delete operator, since +different window classes can be destroyed differently. Frames and dialogs +are not destroyed immediately when this function is called - they are added +to a list of windows to be deleted on idle time, when all the window's events +have been processed. This prevents problems with events being sent to non-existant +windows.

+Return value

+TRUE if the window has either been successfully deleted, or it has been added +to the list of windows pending real deletion.

+ +


+ +

wxWindow::DestroyChildren

+

+virtual void DestroyChildren()

+Destroys all children of a window. Called automatically by the destructor.

+ +


+ +

wxWindow::DragAcceptFiles

+

+virtual void DragAcceptFiles(const bool accept)

+Enables or disables elibility for drop file events (OnDropFiles).

+Parameters

+accept

      +If TRUE, the window is eligible for drop file events. If FALSE, the window +will not accept drop file events.
+

+Remarks

+Windows only.

+See also

+wxWindow::OnDropFiles

+ +


+ +

wxWindow::Enable

+

+virtual void Enable(const bool enable)

+Enable or disable the window for user input.

+Parameters

+enable

      +If TRUE, enables the window for input. If FALSE, disables the window.
+

+See also

+wxWindow::IsEnabled

+ +


+ +

wxWindow::FindFocus

+

+static wxWindow* FindFocus()

+Finds the window or control which currently has the keyboard focus.

+Remarks

+Note that this is a static function, so it can be called without needing a wxWindow pointer.

+See also

+wxWindow::SetFocus

+ +


+ +

wxWindow::FindWindow

+

+wxWindow* FindWindow(long id)

+Find a child of this window, by identifier.

+wxWindow* FindWindow(const wxString& name)

+Find a child of this window, by name.

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +FindWindowById(id) + +Accepts an integer +
      +FindWindowByName(name) + +Accepts a string +
      +
+ +

+ +


+ +

wxWindow::Fit

+

+virtual void Fit()

+Sizes the window so that it fits around its subwindows.

+ +


+ +

wxWindow::GetBackgroundColour

+

+virtual wxColour GetBackgroundColour() const

+Returns the background colour of the window.

+See also

+wxWindow::SetBackgroundColour, +wxWindow::SetForegroundColour, +wxWindow::GetForegroundColour, +wxWindow::OnEraseBackground

+ +


+ +

wxWindow::GetCharHeight

+

+virtual int GetCharHeight() const

+Returns the character height for this window.

+ +


+ +

wxWindow::GetCharWidth

+

+virtual int GetCharWidth() const

+Returns the average character width for this window.

+ +


+ +

wxWindow::GetChildren

+

+wxList& GetChildren()

+Returns a reference to the list of the window's children.

+ +


+ +

wxWindow::GetClientSize

+

+virtual void GetClientSize(int* width, int* height) const

+virtual wxSize GetClientSize() const

+This gets the size of the window 'client area' in pixels. The client area is the +area which may be drawn on by the programmer, excluding title bar, border etc.

+Parameters

+width

      +Receives the client width in pixels.
+

+height

      +Receives the client height in pixels.
+

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +wxGetClientSizeTuple() + +Returns a 2-tuple of (width, height) +
      +wxGetClientSize() + +Returns a wxSize object +
      +
+ +

+ +


+ +

wxWindow::GetConstraints

+

+wxLayoutConstraints* GetConstraints() const

+Returns a pointer to the window's layout constraints, or NULL if there are none.

+ +


+ +

wxWindow::GetDefaultItem

+

+wxButton* GetDefaultItem() const

+Returns a pointer to the button which is the default for this window, or NULL.

+ +


+ +

wxWindow::GetDropTarget

+

+wxDropTarget* GetDropTarget() const

+Returns the associated drop target, which may be NULL.

+See also

+wxWindow::SetDropTarget, +Drag and drop overview

+ +


+ +

wxWindow::GetEventHandler

+

+wxEvtHandler* GetEventHandler() const

+Returns the event handler for this window. By default, the window is its +own event handler.

+See also

+wxWindow::SetEventHandler, +wxWindow::PushEventHandler, +wxWindow::PopEventHandler, +wxEvtHandler::ProcessEvent, +wxEvtHandler

+ +


+ +

wxWindow::GetFont

+

+wxFont& GetFont() const

+Returns a reference to the font for this window.

+See also

+wxWindow::SetFont

+ +


+ +

wxWindow::GetForegroundColour

+

+virtual wxColour GetForegroundColour()

+Returns the foreground colour of the window.

+Remarks

+The interpretation of foreground colour is open to interpretation according +to the window class; it may be the text colour or other colour, or it may not +be used at all.

+See also

+wxWindow::SetForegroundColour, +wxWindow::SetBackgroundColour, +wxWindow::GetBackgroundColour

+ +


+ +

wxWindow::GetGrandParent

+

+wxWindow* GetGrandParent() const

+Returns the grandparent of a window, or NULL if there isn't one.

+ +


+ +

wxWindow::GetHandle

+

+void* GetHandle() const

+Returns the platform-specific handle of the physical window. Cast it to an appropriate +handle, such as HWND for Windows or Widget for Motif.

+ +


+ +

wxWindow::GetId

+

+int GetId() const

+Returns the identifier of the window.

+Remarks

+Each window has an integer identifier. If the application has not provided one, +an identifier will be generated.

+See also

+wxWindow::SetId +Window identifiers

+ +


+ +

wxWindow::GetPosition

+

+virtual void GetPosition(int* x, int* y) const

+This gets the position of the window in pixels, relative to the parent window or +if no parent, relative to the whole display.

+Parameters

+x

      +Receives the x position of the window.
+

+y

      +Receives the y position of the window.
+

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +GetPosition() + +Returns a wxPoint +
      +GetPositionTuple() + +Returns a tuple (x, y) +
      +
+ +

+ +


+ +

wxWindow::GetLabel

+

+virtual wxString& GetLabel() const

+Generic way of getting a label from any window, for +identification purposes.

+Remarks

+The interpretation of this function differs from class to class. +For frames and dialogs, the value returned is the title. For buttons or static text controls, it is +the button text. This function can be useful for meta-programs (such as testing +tools or special-needs access programs) which need to identify windows +by name.

+ +


+ +

wxWindow::GetName

+

+virtual wxString& GetName() const

+Returns the window's name.

+Remarks

+This name is not guaranteed to be unique; it is up to the programmer to supply an appropriate +name in the window constructor or via wxWindow::SetName.

+See also

+wxWindow::SetName

+ +


+ +

wxWindow::GetParent

+

+virtual wxWindow* GetParent() const

+Returns the parent of the window, or NULL if there is no parent.

+ +


+ +

wxWindow::GetRect

+

+virtual wxRect GetRect() const

+Returns the size and position of the window as a wxRect object.

+ +


+ +

wxWindow::GetReturnCode

+

+int GetReturnCode()

+Gets the return code for this window.

+Remarks

+A return code is normally associated with a modal dialog, where wxDialog::ShowModal returns +a code to the application.

+See also

+wxWindow::SetReturnCode, wxDialog::ShowModal, +wxDialog::EndModal

+ +


+ +

wxWindow::GetScrollThumb

+

+virtual int GetScrollThumb(int orientation)

+Returns the built-in scrollbar thumb size.

+See also

+wxWindow::SetScrollbar

+ +


+ +

wxWindow::GetScrollPos

+

+virtual int GetScrollPos(int orientation)

+Returns the built-in scrollbar position.

+See also

+See wxWindow::SetScrollbar

+ +


+ +

wxWindow::GetScrollRange

+

+virtual int GetScrollRange(int orientation)

+Returns the built-in scrollbar range.

+See also

+wxWindow::SetScrollbar

+ +


+ +

wxWindow::GetSize

+

+virtual void GetSize(int* width, int* height) const

+virtual wxSize GetSize() const

+This gets the size of the entire window in pixels.

+Parameters

+width

      +Receives the window width.
+

+height

      +Receives the window height.
+

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +GetSize() + +Returns a wxSize +
      +GetSizeTuple() + +Returns a 2-tuple (width, height) +
      +
+ +

+ +


+ +

wxWindow::GetTextExtent

+

+virtual void GetTextExtent(const wxString& string, int* x, int* y, + int* descent = NULL, int* externalLeading = NULL, + const wxFont* font = NULL, const bool use16 = FALSE) const

+Gets the dimensions of the string as it would be drawn on the +window with the currently selected font.

+Parameters

+string

      +String whose extent is to be measured.
+

+x

      +Return value for width.
+

+y

      +Return value for height.
+

+descent

      +Return value for descent (optional).
+

+externalLeading

      +Return value for external leading (optional).
+

+font

      +Font to use instead of the current window font (optional).
+

+use16

      +If TRUE, string contains 16-bit characters. The default is FALSE.
+

+ +wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +GetTextExtent(string) + +Returns a 2-tuple, (width, height) +
      +GetFullTextExtent(string, font=NULL) + +Returns a +4-tuple, (width, height, descent, externalLeading) +
      +
+ +

+ + +


+ +

wxWindow::GetTitle

+

+virtual wxString GetTitle()

+Gets the window's title. Applicable only to frames and dialogs.

+See also

+wxWindow::SetTitle

+ +


+ +

wxWindow::GetUpdateRegion

+

+virtual wxRegion GetUpdateRegion() const

+Returns the region specifying which parts of the window have been damaged. Should +only be called within an OnPaint event handler.

+See also

+wxRegion, wxRegionIterator, wxWindow::OnPaint

+ +


+ +

wxWindow::GetWindowStyleFlag

+

+long GetWindowStyleFlag() const

+Gets the window style that was passed to the consructor or Create member.

+ +


+ +

wxWindow::InitDialog

+

+void InitDialog()

+Sends an wxWindow::OnInitDialog event, which +in turn transfers data to the dialog via validators.

+See also

+wxWindow::OnInitDialog

+ +


+ +

wxWindow::IsEnabled

+

+virtual bool IsEnabled() const

+Returns TRUE if the window is enabled for input, FALSE otherwise.

+See also

+wxWindow::Enable

+ +


+ +

wxWindow::IsRetained

+

+virtual bool IsRetained() const

+Returns TRUE if the window is retained, FALSE otherwise.

+Remarks

+Retained windows are only available on X platforms.

+ +


+ +

wxWindow::IsShown

+

+virtual bool IsShown() const

+Returns TRUE if the window is shown, FALSE if it has been hidden.

+ +


+ +

wxWindow::Layout

+

+void Layout()

+Invokes the constraint-based layout algorithm for this window. It is called +automatically by the default wxWindow::OnSize member.

+ +


+ +

wxWindow::LoadFromResource

+

+virtual bool LoadFromResource(wxWindow* parent, +const wxString& resourceName, const wxResourceTable* resourceTable = NULL)

+Loads a panel or dialog from a resource file.

+Parameters

+parent

      +Parent window.
+

+resourceName

      +The name of the resource to load.
+

+resourceTable

      +The resource table to load it from. If this is NULL, the +default resource table will be used.
+

+Return value

+TRUE if the operation succeeded, otherwise FALSE.

+ +


+ +

wxWindow::Lower

+

+void Lower()

+Lowers the window to the bottom of the window hierarchy if it is a managed window (dialog +or frame).

+ +


+ +

wxWindow::MakeModal

+

+virtual void MakeModal(const bool flag)

+Disables all other windows in the application so that +the user can only interact with this window.

+Parameters

+flag

      +If TRUE, this call disables all other windows in the application so that +the user can only interact with this window. If FALSE, the effect is reversed.
+

+ +


+ +

wxWindow::Move

+

+void Move(int x, int y)

+void Move(const wxPoint& pt)

+Moves the window to the given position.

+Parameters

+x

      +Required x position.
+

+y

      +Required y position.
+

+pt

      +wxPoint object representing the position.
+

+Remarks

+Implementations of SetSize can also implicitly implement the +wxWindow::Move function, which is defined in the base wxWindow class +as the call:

+

+  SetSize(x, y, -1, -1, wxSIZE_USE_EXISTING);
+
+See also

+wxWindow::SetSize

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +Move(point) + +Accepts a wxPoint +
      +MoveXY(x, y) + +Accepts a pair of integers +
      +
+ +

+ +


+ +

wxWindow::OnActivate

+

+void OnActivate(wxActivateEvent& event)

+Called when a window is activated or deactivated.

+Parameters

+event

      +Object containing activation information.
+

+Remarks

+If the window is being activated, wxActivateEvent::GetActive returns TRUE, +otherwise it returns FALSE (it is being deactivated).

+See also

+wxActivateEvent, +Event handling overview

+ +


+ +

wxWindow::OnChar

+

+void OnChar(wxKeyEvent& event)

+Called when the user has pressed a key that is not a modifier (SHIFT, CONTROL or ALT).

+Parameters

+event

      +Object containing keypress information. See wxKeyEvent for +details about this class.
+

+Remarks

+This member function is called in response to a keypress. To intercept this event, +use the EVT_CHAR macro in an event table definition. Your OnChar handler may call this +default function to achieve default keypress functionality.

+Note that the ASCII values do not have explicit key codes: they are passed as ASCII +values.

+Note that not all keypresses can be intercepted this way. If you wish to intercept modifier +keypresses, then you will need to use wxWindow::OnKeyDown or +wxWindow::OnKeyUp.

+Most, but not all, windows allow keypresses to be intercepted.

+See also

+wxWindow::OnKeyDown, wxWindow::OnKeyUp, +wxKeyEvent, wxWindow::OnCharHook, +Event handling overview

+ +


+ +

wxWindow::OnCharHook

+

+void OnCharHook(wxKeyEvent& event)

+This member is called to allow the window to intercept keyboard events +before they are processed by child windows.

+Parameters

+event

      +Object containing keypress information. See wxKeyEvent for +details about this class.
+

+Remarks

+This member function is called in response to a keypress, if the window is active. To intercept this event, +use the EVT_CHAR_HOOK macro in an event table definition. If you do not process a particular +keypress, call wxEvent::Skip to allow default processing.

+An example of using this function is in the implementation of escape-character processing for wxDialog, +where pressing ESC dismisses the dialog by OnCharHook 'forging' a cancel button press event.

+Note that the ASCII values do not have explicit key codes: they are passed as ASCII +values.

+This function is only relevant to top-level windows (frames and dialogs), and under +Windows only.

+See also

+wxKeyEvent, wxWindow::OnCharHook, +wxApp::OnCharHook, +Event handling overview

+ +


+ +

wxWindow::OnCommand

+

+virtual void OnCommand(wxEvtHandler& object, wxCommandEvent& event)

+This virtual member function is called if the control does not handle the command event.

+Parameters

+object

      +Object receiving the command event.
+

+event

      +Command event
+

+Remarks

+This virtual function is provided mainly for backward compatibility. You can also intercept commands +from child controls by using an event table, with identifiers or identifier ranges to identify +the control(s) in question.

+See also

+wxCommandEvent, +Event handling overview

+ +


+ +

wxWindow::OnClose

+

+virtual bool OnClose()

+Called when the user has tried to close a a frame +or dialog box using the window manager (X) or system menu (Windows).

+Note: This is an obsolete function. +It is superceded by the wxWindow::OnCloseWindow event +handler.

+Return value

+If TRUE is returned by OnClose, the window will be deleted by the system, otherwise the +attempt will be ignored. Do not delete the window from within this handler, although +you may delete other windows.

+See also

+Window deletion overview, +wxWindow::Close, +wxWindow::OnCloseWindow, +wxCloseEvent

+ +


+ +

wxWindow::OnCloseWindow

+

+void OnCloseWindow(wxCloseEvent& event)

+This is an event handler function called when the user has tried to close a a frame +or dialog box using the window manager (X) or system menu (Windows). It is +called via the wxWindow::Close function, so +that the application can also invoke the handler programmatically.

+Use the EVT_CLOSE event table macro to handle close events.

+You should check whether the application is forcing the deletion of the window +using wxCloseEvent::GetForce. If this is TRUE, +destroy the window using wxWindow::Destroy. +If not, it is up to you whether you respond by destroying the window.

+(Note: GetForce is now superceded by CanVeto. So to test whether forced destruction of +the window is required, test for the negative of CanVeto. If CanVeto returns FALSE, +it is not possible to skip window deletion.)

+If you don't destroy the window, you should call wxCloseEvent::Veto to +let the calling code know that you did not destroy the window. This allows the wxWindow::Close function +to return TRUE or FALSE depending on whether the close instruction was honoured or not.

+Remarks

+The wxWindow::OnClose virtual function remains +for backward compatibility with earlier versions of wxWindows. The +default OnCloseWindow handler for wxFrame and wxDialog will call OnClose, +destroying the window if it returns TRUE or if the close is being forced.

+See also

+Window deletion overview, +wxWindow::Close, +wxWindow::OnClose, +wxWindow::Destroy, +wxCloseEvent, +wxApp::OnQueryEndSession, +wxApp::OnEndSession

+ +


+ +

wxWindow::OnDropFiles

+

+void OnDropFiles(wxDropFilesEvent& event)

+Called when files have been dragged from the file manager to the window.

+Parameters

+event

+

+Remarks

+The window must have previously been enabled for dropping by calling +wxWindow::DragAcceptFiles.

+This event is only generated under Windows.

+To intercept this event, use the EVT_DROP_FILES macro in an event table definition.

+See also

+wxDropFilesEvent, wxWindow::DragAcceptFiles, +Event handling overview

+ +


+ +

wxWindow::OnEraseBackground

+

+void OnEraseBackground(wxEraseEvent& event)

+Called when the background of the window needs to be erased.

+Parameters

+event

      +Erase background event. For more information, see wxEraseEvent.
+

+Remarks

+This event is only generated under Windows.

+To intercept this event, use the EVT_ERASE_BACKGROUND macro in an event table definition.

+See also

+wxEraseEvent, Event handling overview

+ +


+ +

wxWindow::OnKeyDown

+

+void OnKeyDown(wxKeyEvent& event)

+Called when the user has pressed a key, before it is translated into an ASCII value using other +modifier keys that might be pressed at the same time.

+Parameters

+event

      +Object containing keypress information. See wxKeyEvent for +details about this class.
+

+Remarks

+This member function is called in response to a key down event. To intercept this event, +use the EVT_KEY_DOWN macro in an event table definition. Your OnKeyDown handler may call this +default function to achieve default keypress functionality.

+Note that not all keypresses can be intercepted this way. If you wish to intercept special +keys, such as shift, control, and function keys, then you will need to use wxWindow::OnKeyDown or +wxWindow::OnKeyUp.

+Most, but not all, windows allow keypresses to be intercepted.

+See also

+wxWindow::OnChar, wxWindow::OnKeyUp, +wxKeyEvent, wxWindow::OnCharHook, +Event handling overview

+ +


+ +

wxWindow::OnKeyUp

+

+void OnKeyUp(wxKeyEvent& event)

+Called when the user has released a key.

+Parameters

+event

      +Object containing keypress information. See wxKeyEvent for +details about this class.
+

+Remarks

+This member function is called in response to a key up event. To intercept this event, +use the EVT_KEY_UP macro in an event table definition. Your OnKeyUp handler may call this +default function to achieve default keypress functionality.

+Note that not all keypresses can be intercepted this way. If you wish to intercept special +keys, such as shift, control, and function keys, then you will need to use wxWindow::OnKeyDown or +wxWindow::OnKeyUp.

+Most, but not all, windows allow key up events to be intercepted.

+See also

+wxWindow::OnChar, wxWindow::OnKeyDown, +wxKeyEvent, wxWindow::OnCharHook, +Event handling overview

+ +


+ +

wxWindow::OnKillFocus

+

+void OnKillFocus(wxFocusEvent& event)

+Called when a window's focus is being killed.

+Parameters

+event

+

+Remarks

+To intercept this event, use the macro EVT_KILL_FOCUS in an event table definition.

+Most, but not all, windows respond to this event.

+See also

+wxFocusEvent, wxWindow::OnSetFocus, +Event handling overview

+ +


+ +

wxWindow::OnIdle

+

+void OnIdle(wxIdleEvent& event)

+Provide this member function for any processing which needs to be done +when the application is idle.

+See also

+wxApp::OnIdle, wxIdleEvent

+ +


+ +

wxWindow::OnInitDialog

+

+void OnInitDialog(wxInitDialogEvent& event)

+Default handler for the wxEVT_INIT_DIALOG event. Calls wxWindow::TransferDataToWindow.

+Parameters

+event

      +Dialog initialisation event.
+

+Remarks

+Gives the window the default behaviour of transferring data to child controls via +the validator that each control has.

+See also

+wxValidator, wxWindow::TransferDataToWindow

+ +


+ +

wxWindow::OnMenuCommand

+

+void OnMenuCommand(wxCommandEvent& event)

+Called when a menu command is received from a menu bar.

+Parameters

+event

+

+Remarks

+A function with this name doesn't actually exist; you can choose any member function to receive +menu command events, using the EVT_COMMAND macro for individual commands or EVT_COMMAND_RANGE for +a range of commands.

+See also

+wxCommandEvent, +wxWindow::OnMenuHighlight, +Event handling overview

+ +


+ +

wxWindow::OnMenuHighlight

+

+void OnMenuHighlight(wxMenuEvent& event)

+Called when a menu select is received from a menu bar: that is, the +mouse cursor is over a menu item, but the left mouse button has not been +pressed.

+Parameters

+event

      +The menu highlight event. For more information, see wxMenuEvent.
+

+Remarks

+You can choose any member function to receive +menu select events, using the EVT_MENU_HIGHLIGHT macro for individual menu items or EVT_MENU_HIGHLIGHT_ALL macro +for all menu items.

+The default implementation for wxFrame::OnMenuHighlight displays help +text in the first field of the status bar.

+This function was known as OnMenuSelect in earlier versions of wxWindows, but this was confusing +since a selection is normally a left-click action.

+See also

+wxMenuEvent, +wxWindow::OnMenuCommand, +Event handling overview

+ + +


+ +

wxWindow::OnMouseEvent

+

+void OnMouseEvent(wxMouseEvent& event)

+Called when the user has initiated an event with the +mouse.

+Parameters

+event

+

+Remarks

+Most, but not all, windows respond to this event.

+To intercept this event, use the EVT_MOUSE_EVENTS macro in an event table definition, or individual +mouse event macros such as EVT_LEFT_DOWN.

+See also

+wxMouseEvent, +Event handling overview

+ +


+ +

wxWindow::OnMove

+

+void OnMove(wxMoveEvent& event)

+Called when a window is moved.

+Parameters

+event

      +The move event. For more information, see wxMoveEvent.
+

+Remarks

+Use the EVT_MOVE macro to intercept move events.

+Remarks

+Not currently implemented.

+See also

+wxMoveEvent, +wxFrame::OnSize, +Event handling overview

+ +


+ +

wxWindow::OnPaint

+

+void OnPaint(wxPaintEvent& event)

+Sent to the event handler when the window must be refreshed.

+Parameters

+event

+

+Remarks

+Use the EVT_PAINT macro in an event table definition to intercept paint events.

+In a paint event handler, the application should always create a wxPaintDC object.

+For example:

+

+  void MyWindow::OnPaint(wxPaintEvent& event)
+  {
+      wxPaintDC dc(this);
+
+      DrawMyDocument(dc);
+  }
+
+You can optimize painting by retrieving the rectangles +that have been damaged and only repainting these. The rectangles are in +terms of the client area, and are unscrolled, so you will need to do +some calculations using the current view position to obtain logical, +scrolled units.

+Here is an example of using the wxRegionIterator class:

+

+// Called when window needs to be repainted.
+void MyWindow::OnPaint(wxPaintEvent& event)
+{
+  wxPaintDC dc(this);
+
+  // Find Out where the window is scrolled to
+  int vbX,vbY;                     // Top left corner of client
+  ViewStart(&vbX,&vbY);
+
+  int vX,vY,vW,vH;                 // Dimensions of client area in pixels
+  wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
+
+  while (upd)
+  {
+    vX = upd.GetX();
+    vY = upd.GetY();
+    vW = upd.GetW();
+    vH = upd.GetH();
+
+    // Alternatively we can do this:
+    // wxRect rect;
+    // upd.GetRect(&rect);
+
+    // Repaint this rectangle
+    ...some code...
+
+    upd ++ ;
+  }
+}
+
+See also

+wxPaintEvent, +wxPaintDC, +Event handling overview

+ +


+ +

wxWindow::OnScroll

+

+void OnScroll(wxScrollEvent& event)

+Called when a scroll event is received from one of the window's built-in scrollbars.

+Parameters

+event

+

+Remarks

+Note that it is not possible to distinguish between horizontal and vertical scrollbars +until the function is executing (you can't have one function for vertical, another +for horizontal events).

+See also

+wxScrollEvent, +Event handling overview

+ +


+ +

wxWindow::OnSetFocus

+

+void OnSetFocus(wxFocusEvent& event)

+Called when a window's focus is being set.

+Parameters

+event

+

+Remarks

+To intercept this event, use the macro EVT_SET_FOCUS in an event table definition.

+Most, but not all, windows respond to this event.

+See also

+wxFocusEvent, wxWindow::OnKillFocus, +Event handling overview

+ +


+ +

wxWindow::OnSize

+

+void OnSize(wxSizeEvent& event)

+Called when the window has been resized.

+Parameters

+event

+

+Remarks

+You may wish to use this for frames to resize their child windows as appropriate.

+Note that the size passed is of +the whole window: call wxWindow::GetClientSize for the area which may be +used by the application.

+See also

+wxSizeEvent, +Event handling overview

+ +


+ +

wxWindow::OnSysColourChanged

+

+void OnSysColourChanged(wxOnSysColourChangedEvent& event)

+Called when the user has changed the system colours.

+Parameters

+event

+

+See also

+wxSysColourChangedEvent, +Event handling overview

+ +


+ +

wxWindow::PopEventHandler

+

+wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE) const

+Removes and returns the top-most event handler on the event handler stack.

+Parameters

+deleteHandler

      +If this is TRUE, the handler will be deleted after it is removed. The +default value is FALSE.
+

+See also

+wxWindow::SetEventHandler, +wxWindow::GetEventHandler, +wxWindow::PushEventHandler, +wxEvtHandler::ProcessEvent, +wxEvtHandler

+ +


+ +

wxWindow::PopupMenu

+

+virtual bool PopupMenu(wxMenu* menu, int x, int y)

+Pops up the given menu at the specified coordinates, relative to this +window, and returns control when the user has dismissed the menu. If a +menu item is selected, the callback defined for the menu is called with +wxMenu and wxCommandEvent reference arguments. The callback should access +the commandInt member of the event to check the selected menu identifier.

+Parameters

+menu

      +Menu to pop up.
+

+x

      +Required x position for the menu to appear.
+

+y

      +Required y position for the menu to appear.
+

+See also

+wxMenu

+Remarks

+Just before the menu is popped up, wxMenu::UpdateUI is called +to ensure that the menu items are in the correct state.

+ +


+ +

wxWindow::PushEventHandler

+

+void PushEventHandler(wxEvtHandler* handler)

+Pushes this event handler onto the event stack for the window.

+Parameters

+handler

      +Specifies the handler to be pushed.
+

+Remarks

+An event handler is an object that is capable of processing the events +sent to a window. By default, the window is its own event handler, but +an application may wish to substitute another, for example to allow +central implementation of event-handling for a variety of different +window classes.

+wxWindow::PushEventHandler allows +an application to set up a chain of event handlers, where an event not handled by one event handler is +handed to the next one in the chain. Use wxWindow::PopEventHandler to +remove the event handler.

+See also

+wxWindow::SetEventHandler, +wxWindow::GetEventHandler, +wxWindow::PopEventHandler, +wxEvtHandler::ProcessEvent, +wxEvtHandler

+ +


+ +

wxWindow::Raise

+

+void Raise()

+Raises the window to the top of the window hierarchy if it is a managed window (dialog +or frame).

+ +


+ +

wxWindow::Refresh

+

+virtual void Refresh(const bool eraseBackground = TRUE, const wxRect* rect += NULL)

+Causes a message or event to be generated to repaint the +window.

+Parameters

+eraseBackground

      +If TRUE, the background will be +erased.
+

+rect

      +If non-NULL, only the given rectangle will +be treated as damaged.
+

+ +


+ +

wxWindow::ReleaseMouse

+

+virtual void ReleaseMouse()

+Releases mouse input captured with wxWindow::CaptureMouse.

+See also

+wxWindow::CaptureMouse

+ +


+ +

wxWindow::RemoveChild

+

+virtual void RemoveChild(wxWindow* child)

+Removes a child window. This is called automatically by window deletion +functions so should not be required by the application programmer.

+Parameters

+child

      +Child window to remove.
+

+ +


+ +

wxWindow::ScreenToClient

+

+virtual void ScreenToClient(int* x, int* y) const

+virtual wxPoint ScreenToClient(const wxPoint& pt) const

+Converts from screen to client window coordinates.

+Parameters

+x

      +Stores the screen x coordinate and receives the client x coordinate.
+

+y

      +Stores the screen x coordinate and receives the client x coordinate.
+

+pt

      +The screen position for the second form of the function.
+

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +ScreenToClient(point) + +Accepts and returns a wxPoint +
      +ScreenToClientXY(x, y) + +Returns a 2-tuple, (x, y) +
      +
+ +

+ + +


+ +

wxWindow::ScrollWindow

+

+virtual void ScrollWindow(int dx, int dy, const wxRect* rect = NULL)

+Physically scrolls the pixels in the window.

+Parameters

+dx

      +Amount to scroll horizontally.
+

+dy

      +Amount to scroll vertically.
+

+rect

      +Rectangle to invalidate. If this is NULL, the whole window is invalidated. If you +pass a rectangle corresponding to the area of the window exposed by the scroll, your painting handler +can optimise painting by checking for the invalidated region.
+

+Remarks

+Available only under Windows.

+Use this function to optimise your scrolling implementations, to minimise the area that must be +redrawn.

+ +


+ +

wxWindow::SetAcceleratorTable

+

+virtual void SetAcceleratorTable(const wxAcceleratorTable& accel)

+Sets the accelerator table for this window. See wxAcceleratorTable.

+ +


+ +

wxWindow::SetAutoLayout

+

+void SetAutoLayout(const bool autoLayout)

+Determines whether the wxWindow::Layout function will +be called automatically when the window is resized.

+Parameters

+autoLayout

      +Set this to TRUE if you wish the Layout function to be called +from within wxWindow::OnSize functions.
+

+See also

+wxWindow::SetConstraints

+ +


+ +

wxWindow::SetBackgroundColour

+

+virtual void SetBackgroundColour(const wxColour& colour)

+Sets the background colour of the window.

+Parameters

+colour

      +The colour to be used as the background colour.
+

+Remarks

+The background colour is usually painted by the default +wxWindow::OnEraseBackground event handler function.

+Note that setting the background colour does not cause an immediate refresh, so you +may wish to call wxWindow::Clear or wxWindow::Refresh after +calling this function.

+See also

+wxWindow::GetBackgroundColour, +wxWindow::SetForegroundColour, +wxWindow::GetForegroundColour, +wxWindow::Clear, +wxWindow::Refresh, +wxWindow::OnEraseBackground

+ +


+ +

wxWindow::SetClientSize

+

+virtual void SetClientSize(int width, int height)

+virtual void SetClientSize(const wxSize& size)

+This sets the size of the window client area in pixels. Using this function to size a window +tends to be more device-independent than wxWindow::SetSize, since the application need not +worry about what dimensions the border or title bar have when trying to fit the window +around panel items, for example.

+Parameters

+width

      +The required client area width.
+

+height

      +The required client area height.
+

+size

      +The required client size.
+

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + +
      +SetClientSize(size) + +Accepts a wxSize +
      +SetClientSizeWH(width, height) + + +
      +
+ +

+ +


+ +

wxWindow::SetCursor

+

+virtual void SetCursor(const wxCursor&cursor)

+Sets the window's cursor. Notice that setting the cursor for this window does +not set it for its children so you'll need to explicitly call SetCursor() for +them too if you need it.

+Parameters

+cursor

      +Specifies the cursor that the window should normally display.
+

+See also

+::wxSetCursor, wxCursor

+ +


+ +

wxWindow::SetEventHandler

+

+void SetEventHandler(wxEvtHandler* handler)

+Sets the event handler for this window.

+Parameters

+handler

      +Specifies the handler to be set.
+

+Remarks

+An event handler is an object that is capable of processing the events +sent to a window. By default, the window is its own event handler, but +an application may wish to substitute another, for example to allow +central implementation of event-handling for a variety of different +window classes.

+It is usually better to use wxWindow::PushEventHandler since +this sets up a chain of event handlers, where an event not handled by one event handler is +handed to the next one in the chain.

+See also

+wxWindow::GetEventHandler, +wxWindow::PushEventHandler, +wxWindow::PopEventHandler, +wxEvtHandler::ProcessEvent, +wxEvtHandler

+ +


+ +

wxWindow::SetConstraints

+

+void SetConstraints(wxLayoutConstraints* constraints)

+Sets the window to have the given layout constraints. The window +will then own the object, and will take care of its deletion. +If an existing layout constraints object is already owned by the +window, it will be deleted.

+Parameters

+constraints

      +The constraints to set. Pass NULL to disassociate and delete the window's +constraints.
+

+Remarks

+You must call wxWindow::SetAutoLayout to tell a window to use +the constraints automatically in OnSize; otherwise, you must +override OnSize and call Layout explicitly.

+ +


+ +

wxWindow::SetDropTarget

+

+void SetDropTarget(wxDropTarget* target)

+Associates a drop target with this window.

+If the window already has a drop target, it is deleted.

+See also

+wxWindow::GetDropTarget, +Drag and drop overview

+ +


+ +

wxWindow::SetFocus

+

+virtual void SetFocus()

+This sets the window to receive keyboard input.

+ +


+ +

wxWindow::SetFont

+

+void SetFont(const wxFont& font)

+Sets the font for this window.

+Parameters

+font

      +Font to associate with this window.
+

+See also

+wxWindow::GetFont

+ +


+ +

wxWindow::SetForegroundColour

+

+virtual void SetForegroundColour(const wxColour& colour)

+Sets the foreground colour of the window.

+Parameters

+colour

      +The colour to be used as the foreground colour.
+

+Remarks

+The interpretation of foreground colour is open to interpretation according +to the window class; it may be the text colour or other colour, or it may not +be used at all.

+See also

+wxWindow::GetForegroundColour, +wxWindow::SetBackgroundColour, +wxWindow::GetBackgroundColour

+ +


+ +

wxWindow::SetId

+

+void SetId(int id)

+Sets the identifier of the window.

+Remarks

+Each window has an integer identifier. If the application has not provided one, +an identifier will be generated. Normally, the identifier should be provided +on creation and should not be modified subsequently.

+See also

+wxWindow::GetId, +Window identifiers

+ +


+ +

wxWindow::SetName

+

+virtual void SetName(const wxString& name)

+Sets the window's name.

+Parameters

+name

      +A name to set for the window.
+

+See also

+wxWindow::GetName

+ +


+ +

wxWindow::SetPalette

+

+virtual void SetPalette(wxPalette* palette)

+Obsolete - use wxDC::SetPalette instead.

+ +


+ +

wxWindow::SetReturnCode

+

+void SetReturnCode(int retCode)

+Sets the return code for this window.

+Parameters

+retCode

      +The integer return code, usually a control identifier.
+

+Remarks

+A return code is normally associated with a modal dialog, where wxDialog::ShowModal returns +a code to the application. The function wxDialog::EndModal calls SetReturnCode.

+See also

+wxWindow::GetReturnCode, wxDialog::ShowModal, +wxDialog::EndModal

+ +


+ +

wxWindow::SetScrollbar

+

+virtual void SetScrollbar(int orientation, int position, +int thumbSize, int range, +const bool refresh = TRUE)

+Sets the scrollbar properties of a built-in scrollbar.

+Parameters

+orientation

      +Determines the scrollbar whose page size is to be set. May be wxHORIZONTAL or wxVERTICAL.
+

+position

      +The position of the scrollbar in scroll units.
+

+thumbSize

      +The size of the thumb, or visible portion of the scrollbar, in scroll units.
+

+range

      +The maximum position of the scrollbar.
+

+refresh

      +TRUE to redraw the scrollbar, FALSE otherwise.
+

+Remarks

+Let's say you wish to display 50 lines of text, using the same font. +The window is sized so that you can only see 16 lines at a time.

+You would use:

+

+  SetScrollbar(wxVERTICAL, 0, 16, 50);
+
+

+Note that with the window at this size, the thumb position can never go +above 50 minus 16, or 34.

+You can determine how many lines are currently visible by dividing the current view +size by the character height in pixels.

+When defining your own scrollbar behaviour, you will always need to recalculate +the scrollbar settings when the window size changes. You could therefore put your +scrollbar calculations and SetScrollbar +call into a function named AdjustScrollbars, which can be called initially and also +from your wxWindow::OnSize event handler function.

+See also

+Scrolling overview, +wxScrollBar, wxScrolledWindow

+ +


+ +

wxWindow::SetScrollPos

+

+virtual void SetScrollPos(int orientation, int pos, const bool refresh = TRUE)

+Sets the position of one of the built-in scrollbars.

+Parameters

+orientation

      +Determines the scrollbar whose position is to be set. May be wxHORIZONTAL or wxVERTICAL.
+

+pos

      +Position in scroll units.
+

+refresh

      +TRUE to redraw the scrollbar, FALSE otherwise.
+

+Remarks

+This function does not directly affect the contents of the window: it is up to the +application to take note of scrollbar attributes and redraw contents accordingly.

+See also

+wxWindow::SetScrollbar, +wxWindow::GetScrollPos, +wxWindow::GetScrollThumb, +wxScrollBar, wxScrolledWindow

+ +


+ +

wxWindow::SetSize

+

+virtual void SetSize(int x, int y, int width, int height, + int sizeFlags = wxSIZE_AUTO)

+virtual void SetSize(const wxRect& rect)

+Sets the size and position of the window in pixels.

+virtual void SetSize(int width, int height)

+virtual void SetSize(const wxSize& size)

+Sets the size of the window in pixels.

+Parameters

+x

      +Required x position in pixels, or -1 to indicate that the existing +value should be used.
+

+y

      +Required y position in pixels, or -1 to indicate that the existing +value should be used.
+

+width

      +Required width in pixels, or -1 to indicate that the existing +value should be used.
+

+height

      +Required height position in pixels, or -1 to indicate that the existing +value should be used.
+

+size

      +wxSize object for setting the size.
+

+rect

      +wxRect object for setting the position and size.
+

+sizeFlags

      +Indicates the interpretation of other parameters. It is a bit list of the following:

      +wxSIZE_AUTO_WIDTH: a -1 width value is taken to indicate +a wxWindows-supplied default width.
      + +wxSIZE_AUTO_HEIGHT: a -1 height value is taken to indicate +a wxWindows-supplied default width.
      + +wxSIZE_AUTO: -1 size values are taken to indicate +a wxWindows-supplied default size.
      + +wxSIZE_USE_EXISTING: existing dimensions should be used +if -1 values are supplied.
      + +wxSIZE_ALLOW_MINUS_ONE: allow dimensions of -1 and less to be interpreted +as real dimensions, not default values. +

+

+Remarks

+The second form is a convenience for calling the first form with default +x and y parameters, and must be used with non-default width and height values.

+The first form sets the position and optionally size, of the window. +Parameters may be -1 to indicate either that a default should be supplied +by wxWindows, or that the current value of the dimension should be used.

+See also

+wxWindow::Move

+wxPython note:
+ In place of a single overloaded method name, wxPython +implements the following methods:

+ +

      + + + + + + + + + + + + + + + + + + + +
      +SetDimensions(x, y, width, height, sizeFlags=wxSIZE_AUTO) + + +
      +SetSize(size) + + +
      +SetPosition(point) + + +
      +
+ +

+ +


+ +

wxWindow::SetSizeHints

+

+virtual void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, + int incW=-1, int incH=-1)

+Allows specification of minimum and maximum window sizes, and window size increments. +If a pair of values is not set (or set to -1), the default values will be used.

+Parameters

+minW

      +Specifies the minimum width allowable.
+

+minH

      +Specifies the minimum height allowable.
+

+maxW

      +Specifies the maximum width allowable.
+

+maxH

      +Specifies the maximum height allowable.
+

+incW

      +Specifies the increment for sizing the width (Motif/Xt only).
+

+incH

      +Specifies the increment for sizing the height (Motif/Xt only).
+

+Remarks

+If this function is called, the user will not be able to size the window outside the +given bounds.

+The resizing increments are only significant under Motif or Xt.

+ +


+ +

wxWindow::SetTitle

+

+virtual void SetTitle(const wxString& title)

+Sets the window's title. Applicable only to frames and dialogs.

+Parameters

+title

      +The window's title.
+

+See also

+wxWindow::GetTitle

+ +


+ +

wxWindow::Show

+

+virtual bool Show(const bool show)

+Shows or hides the window.

+Parameters

+show

      +If TRUE, displays the window and brings it to the front. Otherwise, +hides the window.
+

+See also

+wxWindow::IsShown

+ +


+ +

wxWindow::TransferDataFromWindow

+

+virtual bool TransferDataFromWindow()

+Transfers values from child controls to data areas specified by their validators. Returns +FALSE if a transfer failed.

+See also

+wxWindow::TransferDataToWindow, +wxValidator, wxWindow::Validate

+ +


+ +

wxWindow::TransferDataToWindow

+

+virtual bool TransferDataToWindow()

+Transfers values to child controls from data areas specified by their validators.

+Return value

+Returns FALSE if a transfer failed.

+See also

+wxWindow::TransferDataFromWindow, +wxValidator, wxWindow::Validate

+ +


+ +

wxWindow::Validate

+

+virtual bool Validate()

+Validates the current values of the child controls using their validators.

+Return value

+Returns FALSE if any of the validations failed.

+See also

+wxWindow::TransferDataFromWindow, +wxWindow::TransferDataFromWindow, +wxValidator

+ +


+ +

wxWindow::WarpPointer

+

+void WarpPointer(int x, int y)

+Moves the pointer to the given position on the window.

+Parameters

+x

      +The new x position for the cursor.
+

+y

      +The new y position for the cursor.
+

+ + diff --git a/samples/html/test/fft.html b/samples/html/test/fft.html new file mode 100644 index 0000000000..3cef164b9e --- /dev/null +++ b/samples/html/test/fft.html @@ -0,0 +1,144 @@ + + + + + wxHTML : wxWindows HTML library + + + + + + +

+ +

+[ Intro & News ] +[ Features ] +[ Download ] +[ Licence ] +[ Screenshots ] +[ Links & Apps ] +

+ + + + + + + +

+ +

+
+
+ +Latest release 0.2.3 + +
+
+
+ +

+ +
+
+ +2811 visitors since January 99 + + +
Last updated on : June 13, 1999 + + +
+

+ +
+ + + + +

News

+ +
    +
  • 13/06/1999 - CVS available!
    +Thanks to Russell Smith, development version of wxHTML is available through CVS. +See Download page for details! +
+ +
    +
  • 13/06/1999 - 0.2.3 release
    +Only minor changes and bugfixes. +
+ +
    +
  • 16/05/1999 - New release
    +Well, 0.2.1 is out. It contains some bug fixes (mainly related to Visual C++) +and new help controller that works with MS HTML Help Workshop projects as +it's native format. Patch from previous version is only 30kB so don't hesitate +to download it! +
+ +
    +
  • 02/05/1999 - Beta release 0.2 is out!
    +Ok, it's here, download it! Help controller is included (and broken under +MSW/Mingw32 - I'll fix it asap. If anyone can help with it, please do so...) +
+ + + + + + + +
+

Intro

+ +I started work on this library in January, 1999. +
The main goal was to provide light-weight HTML viewer for +wxWindows 2 toolkit. +This viewer was expected to be used as help/documentation browser rather than full-featured web browser. + +

This library is released under +wxWindows Library Licence, Version 3. It is basically +GNU Library General Public Licence except that it makes using +wxHTML in commercial products much easier. + +

The library should work on all platforms supported by wxWindows - it +is written as poor wxWindows-only code, without line of platform-specific +code (as I hope :-). It is known to compile under these enviromnets: + +

    +
  • EGCS under Linux +
  • Cygwin b20 or Mingw32 under Windows 95 +
+ + + + + + + + +

Author(s)

+wxHTML (and this page) is copyrighted by Vaclav Slavik. Parts of wxHTML are copyrighted by other +autors - all of them are listed in contributors section. + +

+Feel free to send your suggestions, comments, bug reports to me. My +e-mail address is + +
slavik2@czn.cz +
or +
vsla8348@ss1000.ms.mff.cuni.cz +

Vaclav Slavik + + +

Contributors

+
    +
  • Guillermo Rodriguez Garcia (guille@iies.es) +
    contributed GIF reading routines +
+ +
+ + diff --git a/samples/html/test/pic.png b/samples/html/test/pic.png new file mode 100644 index 0000000000..fcc18c1296 Binary files /dev/null and b/samples/html/test/pic.png differ diff --git a/samples/html/test/pic2.bmp b/samples/html/test/pic2.bmp new file mode 100644 index 0000000000..e79b526fc3 Binary files /dev/null and b/samples/html/test/pic2.bmp differ diff --git a/samples/html/test/tables.htm b/samples/html/test/tables.htm new file mode 100644 index 0000000000..b27eb5e3f5 --- /dev/null +++ b/samples/html/test/tables.htm @@ -0,0 +1,116 @@ + + + + + + + + +

+This is TABLES +tests page...

+ + +(yes, really, see bellow:) +
Click here to go to original testing page... +
Click here to go to manuals... +
  +
+ + + + + + + + + + + +
Top left +
(two lines expression) +

paragraph done

Top right
Bottom leftBottom right
+ +

Subsampling is shown there: +
  + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
ab
cd
+
2
3 dflkj lkjfl dkjldkfjl flk jflkf lkjflkj ljlf ajlfj alff h khg hgj +gjg jg gjhfg fg gjh gjf jgf jgj f gjfgj kfajg 4 +
gh +
gfh +
gh +
hg +
5
+ +

This is "default" table - with no sizes givev: +
  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Hellolkfdsjlk fj dlfj lkfj lkjflk jlfk lk fjlk elwkf lkejflek f jlekjflkj +ljlk lk jlkf lefjl j flkj ljl lf lfj lfjl lj lwe lekf;eh kfejh lkh kjh +kjhkj hkj hkj lkh kjh kjlh kjshortebn formo lr lkdjsf lkjlf poer oi pjr po kpk 
abcd
123
AB
+ + + + + + + diff --git a/samples/html/test/test.cpp b/samples/html/test/test.cpp new file mode 100644 index 0000000000..fa61e56489 --- /dev/null +++ b/samples/html/test/test.cpp @@ -0,0 +1,203 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: test.cpp +// Purpose: wxHtml testing example +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "test.cpp" + #pragma interface "test.cpp" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include +#endif + +#include +#include + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp + class MyApp : public wxApp + { + public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + virtual bool OnInit(); + }; + +// Define a new frame type: this is going to be our main frame + class MyFrame : public wxFrame + { + public: + // ctor(s) + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + + // event handlers (these functions should _not_ be virtual) + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + void OnBack(wxCommandEvent& event); + void OnForward(wxCommandEvent& event); + + private: + // any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + }; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// IDs for the controls and the menu commands + enum + { + // menu items + Minimal_Quit = 1, + Minimal_About, + Minimal_Back, + Minimal_Forward, + + // controls start here (the numbers are, of course, arbitrary) + Minimal_Text = 1000, + }; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +// the event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. + BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(Minimal_Quit, MyFrame::OnQuit) + EVT_MENU(Minimal_About, MyFrame::OnAbout) + EVT_MENU(Minimal_Back, MyFrame::OnBack) + EVT_MENU(Minimal_Forward, MyFrame::OnForward) + END_EVENT_TABLE() + + // Create a new application object: this macro will allow wxWindows to create + // the application object during program execution (it's better than using a + // static object for many reasons) and also declares the accessor function + // wxGetApp() which will return the reference of the right type (i.e. MyApp and + // not wxApp) + IMPLEMENT_APP(MyApp) + + // ============================================================================ + // implementation + // ============================================================================ + + // ---------------------------------------------------------------------------- + // the application class + // ---------------------------------------------------------------------------- + // `Main program' equivalent: the program execution "starts" here + bool MyApp::OnInit() + { + wxLogDebug("[starting testing app]"); + #if wxUSE_LIBPNG + wxImage::AddHandler(new wxPNGHandler); + #endif + #if wxUSE_LIBJPEG + wxImage::AddHandler(new wxJPEGHandler); + #endif + // Create the main application window + MyFrame *frame = new MyFrame("wxHtmlWindow testing application", + wxPoint(50, 50), wxSize(640, 480)); + + // Show it and tell the application that it's our main window + // @@@ what does it do exactly, in fact? is it necessary here? + frame->Show(TRUE); + SetTopWindow(frame); + + + // success: wxApp::OnRun() will be called which will enter the main message + // loop and the application will run. If we returned FALSE here, the + // application would exit immediately. + return TRUE; + } + +// ---------------------------------------------------------------------------- +// main frame +// ---------------------------------------------------------------------------- + +wxHtmlWindow *html; + +// frame constructor + MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame((wxFrame *)NULL, -1, title, pos, size) + { + // create a menu bar + wxMenu *menuFile = new wxMenu; + wxMenu *menuNav = new wxMenu; + + menuFile->Append(Minimal_About, "&Load wxWindows manual page"); + menuFile->AppendSeparator(); + menuFile->Append(Minimal_Quit, "E&xit"); + menuNav->Append(Minimal_Back, "Go &BACK"); + menuNav->Append(Minimal_Forward, "Go &FORWARD"); + + // now append the freshly created menu to the menu bar... + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(menuFile, "&File"); + menuBar->Append(menuNav, "&Navigate"); + + // ... and attach this menu bar to the frame + SetMenuBar(menuBar); + + CreateStatusBar(1); + + { + wxConfig *cfg = new wxConfig("wxHtmlTest"); + html = new wxHtmlWindow(this); + html -> SetRelatedFrame(this, "HTML : %s"); + html -> SetRelatedStatusBar(0); + html -> ReadCustomization(cfg); + delete cfg; + html -> LoadPage("test.htm"); + } + } + + +// event handlers + + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) + { + // TRUE is to force the frame to close + wxLogDebug("about to save config..."); + wxConfig *cfg = new wxConfig("wxHtmlTest"); + html -> WriteCustomization(cfg); + delete cfg; + Close(TRUE); + } + + void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) + { + html -> LoadPage("fft.html"); + } + + + + void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryBack()) wxMessageBox("You reached prehistory era!"); + } + + + void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryForward()) wxMessageBox("No more items in history!"); + } diff --git a/samples/html/test/test.htm b/samples/html/test/test.htm new file mode 100644 index 0000000000..dc7ead5694 --- /dev/null +++ b/samples/html/test/test.htm @@ -0,0 +1,266 @@ + + + + + + + + +click here to go to tables test page! + +

+This is - - default text, now switching to +

+

center, now still ctr, now exiting

+exited!.[link to down] +

Hello, this *is* default charset (helvetica, probably) and it is displayed +with one  COLOR CHANGE. Of course we +can have as many color changes as we can, what about this MADNESS? +

There was a space above. +
+


This was a line. (BTW we are in fixed font +/ typewriter font right now :-) +
This is in BOLD face. This is ITALIC. This is E +V E R Y T H I N G. +
  +


+

+

Right now, centered REALLY Big Text, +how do you like (space) it?

+ +
RIGHT: text-2, text-1, +text+0, +text+1, +text+2, +text+3, +text+4 +
we are right now
+ +
we are center now
+we are left now. +

Blue italic text is displayed there.... +

+ +
This is heading one.

+this is normal +
+

+This is CENTERED heading one

+Yes, hmmmmmmmmm........, right now, we should +display some tiny nice image, he? +
Testing image imageand this is text...... +

Testing image imageand +this is text...... +
Testing image image (try clicking on the image :-) and +this is text...... +
  +
  +

    +
  • +item 1
  • + +
  • +item 2
  • + +
      +
    • +nested item
    • + +
    • +nested item 2
    • +
    + +
  • +item 3
  • +
+ +
    +
  1. +item one
  2. + +
  3. +item two
  4. + +
      +
    1. +nsted item
    2. +
    + +
  5. +last numbered item
  6. +
+ +

+Heading 1

+Italic text now... +

+Heading 2

+and now? +

+Heading 3

+ +

+Heading 4

+ +
+Heading 5
+ +
+Heading 6
+And this is normal text, once again :-) +
  +
  +
  +
  +
  +
  +

And yes, we're in HTML DOCUMENT, so +what about some nice hypertext link?? +

hello? +
  +


+

+

This is centered paragraph

+ +

This is new par? +

We switched to BOLD +

This is new paragraph Bold is off now. +

new par +

  ----------- +

Hello +

    this is standalone :-) +
  1. +This is item number one. iti lkdjfdl kjd lk jlkjdl kjlk jlf +jflkj d lfkjlkf jl jflkj flkwe lkhelf ;fk;fl kw;lfke ;ffj lkjflk wj lfjl +fkw ;k;ekf;lkfe ;kf;lk; ;j ;lrj;wfj;f ;eljfw; lfj;ewlfj dagdja gdj chga +kjegiquw iuqdb qiud iquwd hurray googoo.
  2. + +
  3. +two two two two two two twotwo TWO two two two two two two +twotwo TWO two two two two two two twotwo TWO two two two two two two twotwo +TWO two two two two two two twotwo TWO two two two two two two twotwo TWO +two two two two two two twotwo TWO
  4. + +
    (blockquote)two two two two two two twotwo +TWO two two two two two two twotwo TWO two two two two two two twotwo TWO +
    two two two two two two twotwo TWO two two two
    +two two two twotwo TWO two two two two two two twotwo TWO +two two two two two two twotwo TWO
    +two two two two two two twotwo TWO two two two two two two +twotwo TWO +
  5. +This is item nyumber 3.
  6. + +
  7. +This is item number one. iti lkdjfdl kjd lk jlkjdl kjlk jlf +jflkj d lfkjlkf jl jflkj flkwe lkhelf ;fk;fl kw;lfke ;ffj lkjflk wj lfjl +fkw ;k;ekf;lkfe ;kf;lk; ;j ;lrj;wfj;f ;eljfw; lfj;ewlfj dagdja gdj chga +kjegiquw iuqdb qiud iquwd hurray googoo.
  8. + +
  9. +two two two two two two twotwo TWO two two two two two two +twotwo TWO two two two two two two twotwo TWO two two two two two two twotwo +TWO two two two two two two twotwo TWO two two two two two two twotwo TWO +two two two two two two twotwo TWO two two two two two two twotwo TWO two +two two two two two twotwo TWO two two two two two two twotwo TWO two two +two two two two twotwo TWO two two two two two two twotwo TWO two two two +two two two twotwo TWO two two two two two two twotwo TWO two two two two +two two twotwo TWO two two two two two two twotwo TWO
  10. + +
  11. +This is item nyumber 3.
  12. + +
  13. +This is item number one. iti lkdjfdl kjd lk jlkjdl kjlk jlf +jflkj d lfkjlkf jl jflkj flkwe lkhelf ;fk;fl kw;lfke ;ffj lkjflk wj lfjl +fkw ;k;ekf;lkfe ;kf;lk; ;j ;lrj;wfj;f ;eljfw; lfj;ewlfj dagdja gdj chga +kjegiquw iuqdb qiud iquwd hurray googoo.
  14. + +
  15. +two two two two two two twotwo TWO two two two two two two +twotwo TWO two two two two two two twotwo TWO two two two two two two twotwo +TWO two two two two two two twotwo TWO two two two two two two twotwo TWO +two two two two two two twotwo TWO two two two two two two twotwo TWO two +two two two two two twotwo TWO two two two two two two twotwo TWO two two +two two two two twotwo TWO two two two two two two twotwo TWO two two two +two two two twotwo TWO two two two two two two twotwo TWO two two two two +two two twotwo TWO two two two two two two twotwo TWO
  16. + +
  17. +This is item nyumber 3.
  18. + +
  19. +This is item number one. iti lkdjfdl kjd lk jlkjdl kjlk jlf +jflkj d lfkjlkf jl jflkj flkwe lkhelf ;fk;fl kw;lfke ;ffj lkjflk wj lfjl +fkw ;k;ekf;lkfe ;kf;lk; ;j ;lrj;wfj;f ;eljfw; lfj;ewlfj dagdja gdj chga +kjegiquw iuqdb qiud iquwd hurray googoo.
  20. + +
  21. +two two two two two two twotwo TWO two two two two two two +twotwo TWO two two two two two two twotwo TWO two two two two two two twotwo +TWO two two two two two two twotwo TWO two two two two two two twotwo TWO +two two two two two two twotwo TWO two two two two two two twotwo TWO two +two two two two two twotwo TWO two two two two two two twotwo TWO two two +two two two two twotwo TWO two two two two two two twotwo TWO two two two +two two two twotwo TWO two two two two two two twotwo TWO two two two two +two two twotwo TWO two two two two two two twotwo TWO
  22. + +
  23. +This is item nyumber 3.
  24. + +
  25. +This is item number one. iti lkdjfdl kjd lk jlkjdl kjlk jlf +jflkj d lfkjlkf jl jflkj flkwe lkhelf ;fk;fl kw;lfke ;ffj lkjflk wj lfjl +fkw ;k;ekf;lkfe ;kf;lk; ;j ;lrj;wfj;f ;eljfw; lfj;ewlfj dagdja gdj chga +kjegiquw iuqdb qiud iquwd hurray googoo.
  26. + +
  27. +two two two two two two twotwo TWO two two two two two two +twotwo TWO two two two two two two twotwo TWO two two two two two two twotwo +TWO two two two two two two twotwo TWO two two two two two two twotwo TWO +two two two two two two twotwo TWO two two two two two two twotwo TWO
  28. + +


    two two two two two two twotwo TWO two two two two +two two twotwo TWO two two two two two two twotwo TWO two two two two two +two twotwo TWO +

    two two two two two two twotwo TWO two two two two two +two twotwo TWO two two two two two two twotwo TWO two two two two two two +twotwo TWO +

  29. +This is item nyumber 3.
  30. +
+Now, you will see some PRE text:

+

// This is sample C++ code:
+
+void main(int argc, char *argv[])
+{
+    printf("Go away, man!\n");
+    i = 666;
+    printf("\n\n\nCRASH\n  DOWN NOW. . .  \n");
+}
+ +

WWW

+This is WWW link to KDE site! +
+ + + + + + +(one folder up) +
+ +... +
+... +
+Link to normal text file : test.cpp +
+And link to BINARY : Unix or Windows +
+ANOTHER LINK(www.tue.nl) + + + + diff --git a/samples/html/test/test.rc b/samples/html/test/test.rc new file mode 100644 index 0000000000..82bdf07561 --- /dev/null +++ b/samples/html/test/test.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" + diff --git a/samples/html/virtual/Makefile.am b/samples/html/virtual/Makefile.am new file mode 100644 index 0000000000..e5fe674b3e --- /dev/null +++ b/samples/html/virtual/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = virtual + +virtual_SOURCES = virtual.cpp diff --git a/samples/html/virtual/start.htm b/samples/html/virtual/start.htm new file mode 100644 index 0000000000..1dc3cdd353 --- /dev/null +++ b/samples/html/virtual/start.htm @@ -0,0 +1,12 @@ + +VFS Demo + +

Virtual File Systems demonstration

+ +Hello. This sample demonstrates VFS. Try the link (and have a look +at status bar before clicking on them) +

+Enter top level Node... + + + diff --git a/samples/html/virtual/virtual.cpp b/samples/html/virtual/virtual.cpp new file mode 100644 index 0000000000..99e848ee55 --- /dev/null +++ b/samples/html/virtual/virtual.cpp @@ -0,0 +1,231 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: virtua;.cpp +// Purpose: wxHtml testing example +// demonstrates virtual file systems feature +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "test.cpp" + #pragma interface "test.cpp" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include +#endif + + +#include + + +// new handler class: + +#include +#include + + + +class MyVFS : public wxFileSystemHandler +{ +public: + MyVFS() : wxFileSystemHandler() {} + + wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); + bool CanOpen(const wxString& location); +}; + + +bool MyVFS::CanOpen(const wxString& location) +{ + return (GetProtocol(location) == "myVFS"); +} + + + +wxFSFile* MyVFS::OpenFile(wxFileSystem& fs, const wxString& location) +{ + wxFSFile *f; + wxInputStream *str; + char *buf = (char*)malloc(1024); + + sprintf(buf, "

You're in Node %s

" + "Where do you want to go?

" + "sub-1
" + "sub-2
" + "sub-3
" + "
", + location.GetData(), location.GetData(), location.GetData(), location.GetData()); + str = new wxMemoryInputStream(buf, strlen(buf)); + f = new wxFSFile(str, location, "text/html", wxEmptyString); + return f; +} + + + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp + class MyApp : public wxApp + { + public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + virtual bool OnInit(); + }; + +// Define a new frame type: this is going to be our main frame + class MyFrame : public wxFrame + { + public: + // ctor(s) + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + + // event handlers (these functions should _not_ be virtual) + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + void OnBack(wxCommandEvent& event); + void OnForward(wxCommandEvent& event); + + private: + // any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + }; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// IDs for the controls and the menu commands + enum + { + // menu items + Minimal_Quit = 1, + Minimal_About, + Minimal_Back, + Minimal_Forward, + + // controls start here (the numbers are, of course, arbitrary) + Minimal_Text = 1000, + }; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +// the event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. + BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(Minimal_Quit, MyFrame::OnQuit) + EVT_MENU(Minimal_About, MyFrame::OnAbout) + EVT_MENU(Minimal_Back, MyFrame::OnBack) + EVT_MENU(Minimal_Forward, MyFrame::OnForward) + END_EVENT_TABLE() + + // Create a new application object: this macro will allow wxWindows to create + // the application object during program execution (it's better than using a + // static object for many reasons) and also declares the accessor function + // wxGetApp() which will return the reference of the right type (i.e. MyApp and + // not wxApp) + IMPLEMENT_APP(MyApp) + + // ============================================================================ + // implementation + // ============================================================================ + + // ---------------------------------------------------------------------------- + // the application class + // ---------------------------------------------------------------------------- + + // `Main program' equivalent: the program execution "starts" here + bool MyApp::OnInit() + { + // Create the main application window + MyFrame *frame = new MyFrame("wxHtmlWindow testing application", + wxPoint(50, 50), wxSize(640, 480)); + + // Show it and tell the application that it's our main window + // @@@ what does it do exactly, in fact? is it necessary here? + frame->Show(TRUE); + SetTopWindow(frame); + wxFileSystem::AddHandler(new MyVFS); + + // success: wxApp::OnRun() will be called which will enter the main message + // loop and the application will run. If we returned FALSE here, the + // application would exit immediately. + return TRUE; + } + +// ---------------------------------------------------------------------------- +// main frame +// ---------------------------------------------------------------------------- + +wxHtmlWindow *html; + +// frame constructor + MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame((wxFrame *)NULL, -1, title, pos, size) + { + // create a menu bar + wxMenu *menuFile = new wxMenu; + wxMenu *menuNav = new wxMenu; + + menuFile->Append(Minimal_Quit, "E&xit"); + menuNav->Append(Minimal_Back, "Go &BACK"); + menuNav->Append(Minimal_Forward, "Go &FORWARD"); + + // now append the freshly created menu to the menu bar... + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(menuFile, "&File"); + menuBar->Append(menuNav, "&Navigate"); + + // ... and attach this menu bar to the frame + SetMenuBar(menuBar); + + CreateStatusBar(1); + + html = new wxHtmlWindow(this); + html -> SetRelatedFrame(this, "VFS Demo: '%s'"); + html -> SetRelatedStatusBar(1); + html -> LoadPage("start.htm"); + } + + +// event handlers + + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) + { + // TRUE is to force the frame to close + Close(TRUE); + } + + void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) + { + } + + + + void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryBack()) wxMessageBox("You reached prehistory era!"); + } + + + void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryForward()) wxMessageBox("No more items in history!"); + } diff --git a/samples/html/virtual/virtual.rc b/samples/html/virtual/virtual.rc new file mode 100644 index 0000000000..82bdf07561 --- /dev/null +++ b/samples/html/virtual/virtual.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" + diff --git a/samples/html/widget/Makefile.am b/samples/html/widget/Makefile.am new file mode 100644 index 0000000000..5e03a4a779 --- /dev/null +++ b/samples/html/widget/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = widget + +widget_SOURCES = widget.cpp diff --git a/samples/html/widget/start.htm b/samples/html/widget/start.htm new file mode 100644 index 0000000000..23c528d04e --- /dev/null +++ b/samples/html/widget/start.htm @@ -0,0 +1,20 @@ + +Binder demo + +

wxHtmlBinderCell demonstration

+ +There is binded window somewhere around. Enjoy it. + +
+
+ +
+
+ + +
+ + + + + diff --git a/samples/html/widget/widget.cpp b/samples/html/widget/widget.cpp new file mode 100644 index 0000000000..74fa22ff81 --- /dev/null +++ b/samples/html/widget/widget.cpp @@ -0,0 +1,244 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: virtua;.cpp +// Purpose: wxHtml testing example +// demonstrates virtual file systems feature +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "test.cpp" + #pragma interface "test.cpp" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include +#endif + + +#include + + + + +/* + + +TAG HANDER FOR 'MYBIND' TAG + + +*/ + +#include + + +TAG_HANDLER_BEGIN(MYBIND, "MYBIND") + + TAG_HANDLER_PROC(tag) + { + wxWindow *wnd; + int ax, ay; + int fl = 0; + + tag.ScanParam("X", "%i", &ax); + tag.ScanParam("Y", "%i", &ay); + if (tag.HasParam("FLOAT")) fl = ax; + + wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1, tag.GetParam("NAME"), + wxPoint(0,0), wxSize(ax, ay), wxTE_MULTILINE ); + wnd -> Show(TRUE); + + m_WParser -> OpenContainer() -> InsertCell(new wxHtmlWidgetCell(wnd, fl)); + + return FALSE; + } + +TAG_HANDLER_END(MYBIND) + + + +TAGS_MODULE_BEGIN(MyBind) + + TAGS_MODULE_ADD(MYBIND) + +TAGS_MODULE_END(MyBind) + + + + + + + + + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp + class MyApp : public wxApp + { + public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + virtual bool OnInit(); + }; + +// Define a new frame type: this is going to be our main frame + class MyFrame : public wxFrame + { + public: + // ctor(s) + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + + // event handlers (these functions should _not_ be virtual) + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + void OnBack(wxCommandEvent& event); + void OnForward(wxCommandEvent& event); + + private: + // any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + }; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// IDs for the controls and the menu commands + enum + { + // menu items + Minimal_Quit = 1, + Minimal_About, + Minimal_Back, + Minimal_Forward, + + // controls start here (the numbers are, of course, arbitrary) + Minimal_Text = 1000, + }; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +// the event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. + BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(Minimal_Quit, MyFrame::OnQuit) + EVT_MENU(Minimal_About, MyFrame::OnAbout) + EVT_MENU(Minimal_Back, MyFrame::OnBack) + EVT_MENU(Minimal_Forward, MyFrame::OnForward) + END_EVENT_TABLE() + + // Create a new application object: this macro will allow wxWindows to create + // the application object during program execution (it's better than using a + // static object for many reasons) and also declares the accessor function + // wxGetApp() which will return the reference of the right type (i.e. MyApp and + // not wxApp) + IMPLEMENT_APP(MyApp) + + // ============================================================================ + // implementation + // ============================================================================ + + // ---------------------------------------------------------------------------- + // the application class + // ---------------------------------------------------------------------------- + + // `Main program' equivalent: the program execution "starts" here + bool MyApp::OnInit() + { + // Create the main application window + MyFrame *frame = new MyFrame("wxHtmlWindow testing application", + wxPoint(50, 50), wxSize(640, 480)); + + // Show it and tell the application that it's our main window + // @@@ what does it do exactly, in fact? is it necessary here? + frame->Show(TRUE); + SetTopWindow(frame); + + // success: wxApp::OnRun() will be called which will enter the main message + // loop and the application will run. If we returned FALSE here, the + // application would exit immediately. + return TRUE; + } + +// ---------------------------------------------------------------------------- +// main frame +// ---------------------------------------------------------------------------- + +wxHtmlWindow *html; + +// frame constructor + MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame((wxFrame *)NULL, -1, title, pos, size) + { + // create a menu bar + wxMenu *menuFile = new wxMenu; + wxMenu *menuNav = new wxMenu; + + menuFile->Append(Minimal_Quit, "E&xit"); + menuNav->Append(Minimal_Back, "Go &BACK"); + menuNav->Append(Minimal_Forward, "Go &FORWARD"); + + // now append the freshly created menu to the menu bar... + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(menuFile, "&File"); + menuBar->Append(menuNav, "&Navigate"); + + // ... and attach this menu bar to the frame + SetMenuBar(menuBar); + + CreateStatusBar(1); + + html = new wxHtmlWindow(this); + html -> SetRelatedFrame(this, "VFS Demo: '%s'"); + html -> SetRelatedStatusBar(1); + html -> LoadPage("start.htm"); + } + + +// event handlers + + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) + { + // TRUE is to force the frame to close + Close(TRUE); + } + + void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) + { + } + + + + void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryBack()) wxMessageBox("You reached prehistory era!"); + } + + + void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryForward()) wxMessageBox("No more items in history!"); + } + + + + + + diff --git a/samples/html/widget/widget.rc b/samples/html/widget/widget.rc new file mode 100644 index 0000000000..82bdf07561 --- /dev/null +++ b/samples/html/widget/widget.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" + diff --git a/samples/html/zip/Makefile.am b/samples/html/zip/Makefile.am new file mode 100644 index 0000000000..814476c5da --- /dev/null +++ b/samples/html/zip/Makefile.am @@ -0,0 +1,9 @@ +AUTOMAKE_OPTIONS = 1.3 no-dependencies + +SUFFIXES = .cpp + +DEFS = @DEFS@ $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) + +noinst_PROGRAMS = zip + +zip_SOURCES = zip.cpp diff --git a/samples/html/zip/pages.zip b/samples/html/zip/pages.zip new file mode 100644 index 0000000000..f70ded12b5 Binary files /dev/null and b/samples/html/zip/pages.zip differ diff --git a/samples/html/zip/start.htm b/samples/html/zip/start.htm new file mode 100644 index 0000000000..cca461e6b0 --- /dev/null +++ b/samples/html/zip/start.htm @@ -0,0 +1,9 @@ + +

ZIP archive

+

feature demo

+

+Click on this link to load page stored in ZIP +archive (pages.zip). Enjoy it! + + + diff --git a/samples/html/zip/zip.cpp b/samples/html/zip/zip.cpp new file mode 100644 index 0000000000..3f518da664 --- /dev/null +++ b/samples/html/zip/zip.cpp @@ -0,0 +1,195 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: test.cpp +// Purpose: wxHtml testing example +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "test.cpp" + #pragma interface "test.cpp" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include +#endif + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp + class MyApp : public wxApp + { + public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + virtual bool OnInit(); + }; + +// Define a new frame type: this is going to be our main frame + class MyFrame : public wxFrame + { + public: + // ctor(s) + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + + // event handlers (these functions should _not_ be virtual) + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + void OnBack(wxCommandEvent& event); + void OnForward(wxCommandEvent& event); + + private: + // any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + }; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// IDs for the controls and the menu commands + enum + { + // menu items + Minimal_Quit = 1, + Minimal_About, + Minimal_Back, + Minimal_Forward, + + // controls start here (the numbers are, of course, arbitrary) + Minimal_Text = 1000, + }; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +// the event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. + BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(Minimal_Quit, MyFrame::OnQuit) + EVT_MENU(Minimal_About, MyFrame::OnAbout) + EVT_MENU(Minimal_Back, MyFrame::OnBack) + EVT_MENU(Minimal_Forward, MyFrame::OnForward) + END_EVENT_TABLE() + + // Create a new application object: this macro will allow wxWindows to create + // the application object during program execution (it's better than using a + // static object for many reasons) and also declares the accessor function + // wxGetApp() which will return the reference of the right type (i.e. MyApp and + // not wxApp) + IMPLEMENT_APP(MyApp) + + // ============================================================================ + // implementation + // ============================================================================ + + // ---------------------------------------------------------------------------- + // the application class + // ---------------------------------------------------------------------------- + // `Main program' equivalent: the program execution "starts" here + bool MyApp::OnInit() + { + #if wxUSE_LIBPNG + wxImage::AddHandler(new wxPNGHandler); + #endif + #if wxUSE_LIBJPEG + wxImage::AddHandler(new wxJPEGHandler); + #endif + + wxFileSystem::AddHandler(new wxZipFSHandler); + + // Create the main application window + MyFrame *frame = new MyFrame("wxHtmlWindow testing application", + wxPoint(50, 50), wxSize(640, 480)); + + // Show it and tell the application that it's our main window + // @@@ what does it do exactly, in fact? is it necessary here? + frame->Show(TRUE); + SetTopWindow(frame); + + // success: wxApp::OnRun() will be called which will enter the main message + // loop and the application will run. If we returned FALSE here, the + // application would exit immediately. + return TRUE; + } + +// ---------------------------------------------------------------------------- +// main frame +// ---------------------------------------------------------------------------- + +wxHtmlWindow *html; + +// frame constructor + MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame((wxFrame *)NULL, -1, title, pos, size) + { + // create a menu bar + wxMenu *menuFile = new wxMenu; + wxMenu *menuNav = new wxMenu; + + menuFile->Append(Minimal_Quit, "E&xit"); + menuNav->Append(Minimal_Back, "Go &BACK"); + menuNav->Append(Minimal_Forward, "Go &FORWARD"); + + // now append the freshly created menu to the menu bar... + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(menuFile, "&File"); + menuBar->Append(menuNav, "&Navigate"); + + // ... and attach this menu bar to the frame + SetMenuBar(menuBar); + + CreateStatusBar(1); + + { + html = new wxHtmlWindow(this); + html -> SetRelatedFrame(this, "HTML : %s"); + html -> SetRelatedStatusBar(0); + html -> LoadPage("start.htm"); + } + } + + +// event handlers + + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) + { + // TRUE is to force the frame to close + Close(TRUE); + } + + void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) + { + } + + + + void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryBack()) wxMessageBox("You reached prehistory era!"); + } + + + void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) + { + if (!html -> HistoryForward()) wxMessageBox("No more items in history!"); + } diff --git a/samples/html/zip/zip.rc b/samples/html/zip/zip.rc new file mode 100644 index 0000000000..82bdf07561 --- /dev/null +++ b/samples/html/zip/zip.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" + diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp new file mode 100644 index 0000000000..5712bf60ba --- /dev/null +++ b/src/common/filesys.cpp @@ -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 + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include +#include +#include + + + +//-------------------------------------------------------------------------------- +// 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) + + + + diff --git a/src/common/fs_inet.cpp b/src/common/fs_inet.cpp new file mode 100644 index 0000000000..acb0c25831 --- /dev/null +++ b/src/common/fs_inet.cpp @@ -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 + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#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; + } +} + + + + diff --git a/src/common/fs_zip.cpp b/src/common/fs_zip.cpp new file mode 100644 index 0000000000..2bd3b224ed --- /dev/null +++ b/src/common/fs_zip.cpp @@ -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 + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#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() +{ +} + + + + + + + diff --git a/src/common/unzip.c b/src/common/unzip.c new file mode 100644 index 0000000000..ff71a474da --- /dev/null +++ b/src/common/unzip.c @@ -0,0 +1,1294 @@ +/* unzip.c -- IO on .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Read unzip.h for more info +*/ + + +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + + +#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ + !defined(CASESENSITIVITYDEFAULT_NO) +#define CASESENSITIVITYDEFAULT_NO +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +const char unz_copyright[] = + " unzip 0.15 Copyright 1998 Gilles Vollant "; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile;/* relative offset of local header 4 bytes */ +} unz_file_info_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + uLong offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read*/ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + FILE* file; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + FILE* file; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + uLong num_file; /* number of the current file in the zipfile*/ + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ + uLong current_file_ok; /* flag about the usability of the current file*/ + uLong central_pos; /* position of the beginning of the central dir*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ +} unz_s; + + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unzlocal_getByte(fin,pi) + FILE *fin; + int *pi; +{ + unsigned char c; + int err = fread(&c, 1, 1, fin); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ferror(fin)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unzlocal_getShort (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (fileName1,fileName2) + const char* fileName1; + const char* fileName2; +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + 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 int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) + const char* fileName1; + const char* fileName2; + int iCaseSensitivity; +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#define BUFREADCOMMENT (0x400) + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong unzlocal_SearchCentralDir(fin) + FILE *fin; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if (fseek(fin,0,SEEK_END) != 0) + return 0; + + + uSizeFile = ftell( fin ); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if (fseek(fin,uReadPos,SEEK_SET)!=0) + break; + + if (fread(buf,(uInt)uReadSize,1,fin)!=1) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer + "zlib/zlib109.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 unzFile ZEXPORT unzOpen (path) + const char *path; +{ + unz_s us; + unz_s *s; + uLong central_pos,uL; + FILE * fin ; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + fin=fopen(path,"rb"); + if (fin==NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(fin); + if (central_pos==0) + err=UNZ_ERRNO; + + if (fseek(fin,central_pos,SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unzlocal_getLong(fin,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir */ + if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* zipfile comment length */ + if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + fclose(s->file); + TRYFREE(s); + return UNZ_OK; +} + + +/* + 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 unzGetGlobalInfo (file,pglobal_info) + unzFile file; + unz_global_info *pglobal_info; +{ + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + + +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) + uLong ulDosDate; + tm_unz* ptm; +{ + uLong uDate; + uDate = (uLong)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unzlocal_GetCurrentFileInfoInternal (file, + pfile_info, + pfile_info_internal, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + unz_file_info_internal *pfile_info_internal; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + unz_s* s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + + if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + + if ((err==UNZ_OK) && (extraField!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek+=file_info.size_file_extra; + + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + 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 unzGetCurrentFileInfo (file, + pfile_info, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (file) + unzFile file; +{ + int err=UNZ_OK; + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + 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 unzGoToNextFile (file) + unzFile file; +{ + unz_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + 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 unzLocateFile (file, szFileName, iCaseSensitivity) + unzFile file; + const char *szFileName; + int iCaseSensitivity; +{ + unz_s* s; + int err; + + + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + unzGetCurrentFileInfo(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + return err; +} + + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, + poffset_local_extrafield, + psize_local_extrafield) + unz_s* s; + uInt* piSizeVar; + uLong *poffset_local_extrafield; + uInt *psize_local_extrafield; +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (fseek(s->file,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + + if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + int Store; + uInt iSizeVar; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s*) + ALLOC(sizeof(file_in_zip_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if ((s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + Store = s->cur_file_info.compression_method==0; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->file=s->file; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if (!Store) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=1; + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + + s->pfile_in_zip_read = pfile_in_zip_read_info; + return UNZ_OK; +} + + +/* + Read bytes from the current file. + 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 int ZEXPORT unzReadCurrentFile (file, buf, len) + unzFile file; + voidp buf; + unsigned len; +{ + int err=UNZ_OK; + uInt iRead = 0; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if (len>pfile_in_zip_read_info->rest_read_uncompressed) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, + pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if (pfile_in_zip_read_info->compression_method==0) + { + uInt uDoCopy,i ; + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* + 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 that can be read + + 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 +*/ +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) + unzFile file; + voidp buf; + unsigned len; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + 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 +*/ +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) + unzFile file; + char *szComment; + uLong uSizeBuf; +{ + int err=UNZ_OK; + unz_s* s; + uLong uReadThis ; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} diff --git a/src/common/unzip.h b/src/common/unzip.h new file mode 100644 index 0000000000..76692cb703 --- /dev/null +++ b/src/common/unzip.h @@ -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 */ diff --git a/src/common/zipstream.cpp b/src/common/zipstream.cpp new file mode 100644 index 0000000000..39f4888df6 --- /dev/null +++ b/src/common/zipstream.cpp @@ -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 + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include +#include +#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; +} + diff --git a/src/generic/busyinfo.cpp b/src/generic/busyinfo.cpp new file mode 100644 index 0000000000..c443c1daa3 --- /dev/null +++ b/src/generic/busyinfo.cpp @@ -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 + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#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(); +} + + + + + + + + + + + diff --git a/src/gtk/Makefile.am b/src/gtk/Makefile.am index 5bff538335..596102f8d1 100644 --- a/src/gtk/Makefile.am +++ b/src/gtk/Makefile.am @@ -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 # diff --git a/src/gtk1/Makefile.am b/src/gtk1/Makefile.am index 5bff538335..596102f8d1 100644 --- a/src/gtk1/Makefile.am +++ b/src/gtk1/Makefile.am @@ -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 # diff --git a/src/html/bitmaps/back.xpm b/src/html/bitmaps/back.xpm new file mode 100644 index 0000000000..fbb4378bf6 --- /dev/null +++ b/src/html/bitmaps/back.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * back_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #C0E4CB", +"@ c #77C490", +"# c #808080", +" ", +" ", +" . ", +" .. ", +" .+. ", +" .++........ ", +" .++@+++++++. ", +" .++@@@@@@@@@. ", +" .+@@@@@@@@@. ", +" #.+@........ ", +" #.+.####### ", +" #..# ", +" #.# ", +" ## ", +" # ", +" "}; diff --git a/src/html/bitmaps/book.xpm b/src/html/bitmaps/book.xpm new file mode 100644 index 0000000000..3146053f85 --- /dev/null +++ b/src/html/bitmaps/book.xpm @@ -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", +" ", +" ......... ", +" +@#$$$$$%&+ ", +" +##$$$$$$$* ", +" +##$$$$$$$=- ", +" +##$$$$$$$=;> ", +" +##$$$$$$$=;,. ", +" +##$$$$$$$=;,. ", +" +##$$$$$$$=''. ", +" +##$$$$$$$=,;. ", +" +##$$$$$$%+,;. ", +" +&++++++++),;. ", +" ++!~~~~~~~~~,. ", +" ++!~~~~~~~~~{. ", +" ]^^^^^^^^^^^ ", +" "}; diff --git a/src/html/bitmaps/folder.xpm b/src/html/bitmaps/folder.xpm new file mode 100644 index 0000000000..a7fbf85369 --- /dev/null +++ b/src/html/bitmaps/folder.xpm @@ -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. "}; diff --git a/src/html/bitmaps/forward.xpm b/src/html/bitmaps/forward.xpm new file mode 100644 index 0000000000..6e3de64511 --- /dev/null +++ b/src/html/bitmaps/forward.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * forward_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #C0E4CB", +"@ c #77C490", +"# c #808080", +" ", +" ", +" . ", +" .. ", +" .+. ", +" ........++. ", +" .+++++++@++. ", +" .@@@@@@@@@++. ", +" .@@@@@@@@@+. ", +" ........@+.# ", +" #######.+.# ", +" #..# ", +" #.# ", +" ## ", +" # ", +" "}; diff --git a/src/html/bitmaps/page.xpm b/src/html/bitmaps/page.xpm new file mode 100644 index 0000000000..f8bf0c0057 --- /dev/null +++ b/src/html/bitmaps/page.xpm @@ -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 */ +" ", +" ........ ", +" .++++++.. ", +" .+.+.++.+. ", +" .++++++.... ", +" .+.+.+++++. ", +" .+++++++++. ", +" .+.+.+.+.+. ", +" .+++++++++. ", +" .+.+.+.+.+. ", +" .+++++++++. ", +" .+.+.+.+.+. ", +" .+++++++++. ", +" ........... ", +" ", +" "}; diff --git a/src/html/bitmaps/panel.xpm b/src/html/bitmaps/panel.xpm new file mode 100644 index 0000000000..42798ebbe3 --- /dev/null +++ b/src/html/bitmaps/panel.xpm @@ -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 ", +"=.-.-.-.-.-.-.-.-.-.-.-.-.-.-.;."}; diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp new file mode 100644 index 0000000000..c70e0a281c --- /dev/null +++ b/src/html/htmlcell.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include +#include + + + + +//----------------------------------------------------------------------------- +// 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 diff --git a/src/html/htmlfilter.cpp b/src/html/htmlfilter.cpp new file mode 100644 index 0000000000..792240be7e --- /dev/null +++ b/src/html/htmlfilter.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include + + +/* + +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 = "

\n" + doc + "\n
"; + 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 (""); +} + + + + +//-------------------------------------------------------------------------------- +// 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 \ No newline at end of file diff --git a/src/html/htmlhelp.cpp b/src/html/htmlhelp.cpp new file mode 100644 index 0000000000..22d69b06cd --- /dev/null +++ b/src/html/htmlhelp.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + + +#include +#include +#include +#include +#include +#include +#include +#include + +#if !((wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))) +#include +#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_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 + diff --git a/src/html/htmlhelp_io.cpp b/src/html/htmlhelp_io.cpp new file mode 100644 index 0000000000..b4d82e7ec9 --- /dev/null +++ b/src/html/htmlhelp_io.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + + +#include +#include + + + + +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 \ No newline at end of file diff --git a/src/html/htmlparser.cpp b/src/html/htmlparser.cpp new file mode 100644 index 0000000000..ff72c7d6cb --- /dev/null +++ b/src/html/htmlparser.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include +#include +#include +#include + + + +//----------------------------------------------------------------------------- +// 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 \ No newline at end of file diff --git a/src/html/htmltag.cpp b/src/html/htmltag.cpp new file mode 100644 index 0000000000..16e780335f --- /dev/null +++ b/src/html/htmltag.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include + + + + +//----------------------------------------------------------------------------- +// 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 \ No newline at end of file diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp new file mode 100644 index 0000000000..b0077c8b1a --- /dev/null +++ b/src/html/htmlwin.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include + +#include + +///// 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_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(""); +} + + + +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 \ No newline at end of file diff --git a/src/html/htmlwinparser.cpp b/src/html/htmlwinparser.cpp new file mode 100644 index 0000000000..efc1d0d198 --- /dev/null +++ b/src/html/htmlwinparser.cpp @@ -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 + +#include "wx/defs.h" +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#endif + +#include +#include +#include + + +//----------------------------------------------------------------------------- +// 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 \ No newline at end of file diff --git a/src/html/mod_fonts.cpp b/src/html/mod_fonts.cpp new file mode 100644 index 0000000000..45c723c1fb --- /dev/null +++ b/src/html/mod_fonts.cpp @@ -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 +#include + +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 \ No newline at end of file diff --git a/src/html/mod_hline.cpp b/src/html/mod_hline.cpp new file mode 100644 index 0000000000..c79c3ad13e --- /dev/null +++ b/src/html/mod_hline.cpp @@ -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 +#include + +#include + +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 diff --git a/src/html/mod_image.cpp b/src/html/mod_image.cpp new file mode 100644 index 0000000000..908e4b6241 --- /dev/null +++ b/src/html/mod_image.cpp @@ -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 +#include + +#include +#include + +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 \ No newline at end of file diff --git a/src/html/mod_layout.cpp b/src/html/mod_layout.cpp new file mode 100644 index 0000000000..42b1de108c --- /dev/null +++ b/src/html/mod_layout.cpp @@ -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 +#include + +#include + +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 diff --git a/src/html/mod_links.cpp b/src/html/mod_links.cpp new file mode 100644 index 0000000000..9b92982866 --- /dev/null +++ b/src/html/mod_links.cpp @@ -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 +#include +#include + +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 diff --git a/src/html/mod_list.cpp b/src/html/mod_list.cpp new file mode 100644 index 0000000000..4222d6bc02 --- /dev/null +++ b/src/html/mod_list.cpp @@ -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 +#include + +#include + +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 diff --git a/src/html/mod_pre.cpp b/src/html/mod_pre.cpp new file mode 100644 index 0000000000..e2fa697bda --- /dev/null +++ b/src/html/mod_pre.cpp @@ -0,0 +1,157 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: mod_pre.cpp +// Purpose: wxHtml module for
 ... 
tag (code citation) +// Author: Vaclav Slavik +// Copyright: (c) 1999 Vaclav Slavik +// Licence: wxWindows Licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/defs.h" +#if wxUSE_HTML + +#include +#include + +#include +#include + +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 diff --git a/src/html/mod_tables.cpp b/src/html/mod_tables.cpp new file mode 100644 index 0000000000..7f9e31c08e --- /dev/null +++ b/src/html/mod_tables.cpp @@ -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 +#include + +#include + +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 diff --git a/src/html/search.cpp b/src/html/search.cpp new file mode 100644 index 0000000000..aab3906fd5 --- /dev/null +++ b/src/html/search.cpp @@ -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 + +#include +#if wxUSE_HTML + +#ifdef __BORDLANDC__ +#pragma hdrstop +#endif + +#ifndef WXPRECOMP +#include +#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 diff --git a/src/html/search.h b/src/html/search.h new file mode 100644 index 0000000000..ff9db742e0 --- /dev/null +++ b/src/html/search.h @@ -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 + +//-------------------------------------------------------------------------------- +// 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 \ No newline at end of file diff --git a/src/motif/Makefile.am b/src/motif/Makefile.am index 7a692f9537..5822878182 100644 --- a/src/motif/Makefile.am +++ b/src/motif/Makefile.am @@ -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 \