DH 2012-11-15 01:39:56 +02:00
parent de070bf485
commit a90b5cf37a
1998 changed files with 1034301 additions and 0 deletions

View file

@ -0,0 +1,62 @@
/////////////////////////////////////////////////////////////////////////////
// Name: forcelnk.h
// Purpose: see bellow
// Author: Vaclav Slavik
// RCS-ID: $Id: forcelnk.h 35686 2005-09-25 18:46:14Z VZ $
// Copyright: (c) 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 _WX_FORCELNK_H_
#define _WX_FORCELNK_H_
#include "wx/link.h"
// compatibility defines
#define FORCE_LINK wxFORCE_LINK_MODULE
#define FORCE_LINK_ME wxFORCE_LINK_THIS_MODULE
#define FORCE_WXHTML_MODULES() \
FORCE_LINK(m_layout) \
FORCE_LINK(m_fonts) \
FORCE_LINK(m_image) \
FORCE_LINK(m_list) \
FORCE_LINK(m_dflist) \
FORCE_LINK(m_pre) \
FORCE_LINK(m_hline) \
FORCE_LINK(m_links) \
FORCE_LINK(m_tables) \
FORCE_LINK(m_style)
#endif // _WX_FORCELNK_H_

View file

@ -0,0 +1,153 @@
/////////////////////////////////////////////////////////////////////////////
// Name: helpctrl.h
// Purpose: wxHtmlHelpController
// Notes: Based on htmlhelp.cpp, implementing a monolithic
// HTML Help controller class, by Vaclav Slavik
// Author: Harm van der Heijden and Vaclav Slavik
// RCS-ID: $Id: helpctrl.h 49563 2007-10-31 20:46:21Z VZ $
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HELPCTRL_H_
#define _WX_HELPCTRL_H_
#include "wx/defs.h"
#if wxUSE_WXHTML_HELP
#include "wx/helpbase.h"
#include "wx/html/helpfrm.h"
#define wxID_HTML_HELPFRAME (wxID_HIGHEST + 1)
// This style indicates that the window is
// embedded in the application and must not be
// destroyed by the help controller.
#define wxHF_EMBEDDED 0x00008000
// Create a dialog for the help window.
#define wxHF_DIALOG 0x00010000
// Create a frame for the help window.
#define wxHF_FRAME 0x00020000
// Make the dialog modal when displaying help.
#define wxHF_MODAL 0x00040000
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpDialog;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpWindow;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpFrame;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpDialog;
class WXDLLIMPEXP_HTML wxHtmlHelpController : public wxHelpControllerBase // wxEvtHandler
{
DECLARE_DYNAMIC_CLASS(wxHtmlHelpController)
public:
wxHtmlHelpController(int style = wxHF_DEFAULT_STYLE, wxWindow* parentWindow = NULL);
virtual ~wxHtmlHelpController();
void SetTitleFormat(const wxString& format);
void SetTempDir(const wxString& path) { m_helpData.SetTempDir(path); }
bool AddBook(const wxString& book_url, bool show_wait_msg = false);
bool AddBook(const wxFileName& book_file, bool show_wait_msg = false);
bool Display(const wxString& x);
bool Display(int id);
bool DisplayContents();
bool DisplayIndex();
bool KeywordSearch(const wxString& keyword,
wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
wxHtmlHelpWindow* GetHelpWindow() { return m_helpWindow; }
void SetHelpWindow(wxHtmlHelpWindow* helpWindow);
wxHtmlHelpFrame* GetFrame() { return m_helpFrame; }
wxHtmlHelpDialog* GetDialog() { return m_helpDialog; }
void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
// Assigns config object to the Ctrl. This config is then
// used in subsequent calls to Read/WriteCustomization of both help
// Ctrl and it's wxHtmlWindow
virtual void ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
virtual void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
//// Backward compatibility with wxHelpController API
virtual bool Initialize(const wxString& file, int WXUNUSED(server) ) { return Initialize(file); }
virtual bool Initialize(const wxString& file);
virtual void SetViewer(const wxString& WXUNUSED(viewer), long WXUNUSED(flags) = 0) {}
virtual bool LoadFile(const wxString& file = wxT(""));
virtual bool DisplaySection(int sectionNo);
virtual bool DisplaySection(const wxString& section) { return Display(section); }
virtual bool DisplayBlock(long blockNo) { return DisplaySection(blockNo); }
virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos);
virtual void SetFrameParameters(const wxString& title,
const wxSize& size,
const wxPoint& pos = wxDefaultPosition,
bool newFrameEachTime = false);
/// Obtains the latest settings used by the help frame and the help
/// frame.
virtual wxFrame *GetFrameParameters(wxSize *size = NULL,
wxPoint *pos = NULL,
bool *newFrameEachTime = NULL);
// Get direct access to help data:
wxHtmlHelpData *GetHelpData() { return &m_helpData; }
virtual bool Quit() ;
virtual void OnQuit() {}
void OnCloseFrame(wxCloseEvent& evt);
// Make the help controller's frame 'modal' if
// needed
void MakeModalIfNeeded();
// Find the top-most parent window
wxWindow* FindTopLevelWindow();
protected:
virtual wxWindow* CreateHelpWindow();
virtual wxHtmlHelpFrame* CreateHelpFrame(wxHtmlHelpData *data);
virtual wxHtmlHelpDialog* CreateHelpDialog(wxHtmlHelpData *data);
virtual void DestroyHelpWindow();
wxHtmlHelpData m_helpData;
wxHtmlHelpWindow* m_helpWindow;
wxConfigBase * m_Config;
wxString m_ConfigRoot;
wxString m_titleFormat;
int m_FrameStyle;
wxHtmlHelpFrame* m_helpFrame;
wxHtmlHelpDialog* m_helpDialog;
DECLARE_NO_COPY_CLASS(wxHtmlHelpController)
};
/*
* wxHtmlModalHelp
* A convenience class particularly for use on wxMac,
* where you can only show modal dialogs from a modal
* dialog.
*
* Use like this:
*
* wxHtmlModalHelp help(parent, filename, topic);
*
* If topic is empty, the help contents is displayed.
*/
class WXDLLIMPEXP_HTML wxHtmlModalHelp
{
public:
wxHtmlModalHelp(wxWindow* parent, const wxString& helpFile, const wxString& topic = wxEmptyString,
int style = wxHF_DEFAULT_STYLE | wxHF_DIALOG | wxHF_MODAL);
};
#endif // wxUSE_WXHTML_HELP
#endif // _WX_HELPCTRL_H_

View file

@ -0,0 +1,266 @@
/////////////////////////////////////////////////////////////////////////////
// Name: helpdata.h
// Purpose: wxHtmlHelpData
// Notes: Based on htmlhelp.cpp, implementing a monolithic
// HTML Help controller class, by Vaclav Slavik
// Author: Harm van der Heijden and Vaclav Slavik
// RCS-ID: $Id: helpdata.h 53135 2008-04-12 02:31:04Z VZ $
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HELPDATA_H_
#define _WX_HELPDATA_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/object.h"
#include "wx/string.h"
#include "wx/filesys.h"
#include "wx/dynarray.h"
#include "wx/font.h"
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpData;
//--------------------------------------------------------------------------------
// helper classes & structs
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlBookRecord
{
public:
wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
const wxString& title, const wxString& start)
{
m_BookFile = bookfile;
m_BasePath = basepath;
m_Title = title;
m_Start = start;
// for debugging, give the contents index obvious default values
m_ContentsStart = m_ContentsEnd = -1;
}
wxString GetBookFile() const { return m_BookFile; }
wxString GetTitle() const { return m_Title; }
wxString GetStart() const { return m_Start; }
wxString GetBasePath() const { return m_BasePath; }
/* SetContentsRange: store in the bookrecord where in the index/contents lists the
* book's records are stored. This to facilitate searching in a specific book.
* This code will have to be revised when loading/removing books becomes dynamic.
* (as opposed to appending only)
* Note that storing index range is pointless, because the index is alphab. sorted. */
void SetContentsRange(int start, int end) { m_ContentsStart = start; m_ContentsEnd = end; }
int GetContentsStart() const { return m_ContentsStart; }
int GetContentsEnd() const { return m_ContentsEnd; }
void SetTitle(const wxString& title) { m_Title = title; }
void SetBasePath(const wxString& path) { m_BasePath = path; }
void SetStart(const wxString& start) { m_Start = start; }
// returns full filename of page (which is part of the book),
// i.e. with book's basePath prepended. If page is already absolute
// path, basePath is _not_ prepended.
wxString GetFullPath(const wxString &page) const;
protected:
wxString m_BookFile;
wxString m_BasePath;
wxString m_Title;
wxString m_Start;
int m_ContentsStart;
int m_ContentsEnd;
};
WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray,
WXDLLIMPEXP_HTML);
struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
{
wxHtmlHelpDataItem() : level(0), parent(NULL), id(wxID_ANY), book(NULL) {}
int level;
wxHtmlHelpDataItem *parent;
int id;
wxString name;
wxString page;
wxHtmlBookRecord *book;
// returns full filename of m_Page, i.e. with book's basePath prepended
wxString GetFullPath() const { return book->GetFullPath(page); }
// returns item indented with spaces if it has level>1:
wxString GetIndentedName() const;
};
WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem, wxHtmlHelpDataItems,
WXDLLIMPEXP_HTML);
#if WXWIN_COMPATIBILITY_2_4
// old interface to contents and index:
struct wxHtmlContentsItem
{
wxHtmlContentsItem();
wxHtmlContentsItem(const wxHtmlHelpDataItem& d);
wxHtmlContentsItem& operator=(const wxHtmlContentsItem& d);
~wxHtmlContentsItem();
int m_Level;
int m_ID;
wxChar *m_Name;
wxChar *m_Page;
wxHtmlBookRecord *m_Book;
// returns full filename of m_Page, i.e. with book's basePath prepended
wxString GetFullPath() const { return m_Book->GetFullPath(m_Page); }
private:
bool m_autofree;
};
#endif
//------------------------------------------------------------------------------
// wxHtmlSearchEngine
// This class takes input streams and scans them for occurence
// of keyword(s)
//------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject
{
public:
wxHtmlSearchEngine() : wxObject() {}
virtual ~wxHtmlSearchEngine() {}
// Sets the keyword we will be searching for
virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
// Scans the stream for the keyword.
// Returns true if the stream contains keyword, fALSE otherwise
virtual bool Scan(const wxFSFile& file);
private:
wxString m_Keyword;
bool m_CaseSensitive;
bool m_WholeWords;
DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine)
};
// State information of a search action. I'd have preferred to make this a
// nested class inside wxHtmlHelpData, but that's against coding standards :-(
// Never construct this class yourself, obtain a copy from
// wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
class WXDLLIMPEXP_HTML wxHtmlSearchStatus
{
public:
// constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
// title of the book to search. By default, all books are searched.
wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
bool case_sensitive, bool whole_words_only,
const wxString& book = wxEmptyString);
bool Search(); // do the next iteration
bool IsActive() { return m_Active; }
int GetCurIndex() { return m_CurIndex; }
int GetMaxIndex() { return m_MaxIndex; }
const wxString& GetName() { return m_Name; }
const wxHtmlHelpDataItem *GetCurItem() const { return m_CurItem; }
#if WXWIN_COMPATIBILITY_2_4
wxDEPRECATED( wxHtmlContentsItem* GetContentsItem() );
#endif
private:
wxHtmlHelpData* m_Data;
wxHtmlSearchEngine m_Engine;
wxString m_Keyword, m_Name;
wxString m_LastPage;
wxHtmlHelpDataItem* m_CurItem;
bool m_Active; // search is not finished
int m_CurIndex; // where we are now
int m_MaxIndex; // number of files we search
// For progress bar: 100*curindex/maxindex = % complete
DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus)
};
class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
friend class wxHtmlSearchStatus;
public:
wxHtmlHelpData();
virtual ~wxHtmlHelpData();
// 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.
void SetTempDir(const wxString& path);
// Adds new book. 'book' is location of .htb file (stands for "html book").
// See documentation for details on its format.
// Returns success.
bool AddBook(const wxString& book);
bool AddBookParam(const wxFSFile& bookfile,
wxFontEncoding encoding,
const wxString& title, const wxString& contfile,
const wxString& indexfile = wxEmptyString,
const wxString& deftopic = wxEmptyString,
const wxString& path = wxEmptyString);
// Some accessing stuff:
// returns URL of page on basis of (file)name
wxString FindPageByName(const wxString& page);
// returns URL of page on basis of MS id
wxString FindPageById(int id);
const wxHtmlBookRecArray& GetBookRecArray() const { return m_bookRecords; }
const wxHtmlHelpDataItems& GetContentsArray() const { return m_contents; }
const wxHtmlHelpDataItems& GetIndexArray() const { return m_index; }
#if WXWIN_COMPATIBILITY_2_4
// deprecated interface, new interface is arrays-based (see above)
wxDEPRECATED( wxHtmlContentsItem* GetContents() );
wxDEPRECATED( int GetContentsCnt() );
wxDEPRECATED( wxHtmlContentsItem* GetIndex() );
wxDEPRECATED( int GetIndexCnt() );
#endif
protected:
wxString m_tempPath;
// each book has one record in this array:
wxHtmlBookRecArray m_bookRecords;
wxHtmlHelpDataItems m_contents; // list of all available books and pages
wxHtmlHelpDataItems m_index; // list of index itesm
#if WXWIN_COMPATIBILITY_2_4
// deprecated data structures, set only if GetContents(), GetIndex()
// called
wxHtmlContentsItem* m_cacheContents;
wxHtmlContentsItem* m_cacheIndex;
private:
void CleanCompatibilityData();
#endif
protected:
// Imports .hhp files (MS HTML Help Workshop)
bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
const wxString& indexfile, const wxString& contentsfile);
// Reads binary book
bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
// Writes binary book
bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
DECLARE_NO_COPY_CLASS(wxHtmlHelpData)
};
#endif
#endif

View file

@ -0,0 +1,90 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/html/helpdlg.h
// Purpose: wxHtmlHelpDialog
// Notes: Based on htmlhelp.cpp, implementing a monolithic
// HTML Help controller class, by Vaclav Slavik
// Author: Harm van der Heijden, Vaclav Slavik, Julian Smart
// RCS-ID: $Id: helpdlg.h 49804 2007-11-10 01:09:42Z VZ $
// Copyright: (c) Harm van der Heijden, Vaclav Slavik, Julian Smart
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HELPDLG_H_
#define _WX_HELPDLG_H_
#include "wx/defs.h"
#if wxUSE_WXHTML_HELP
#include "wx/html/helpdata.h"
#include "wx/window.h"
#include "wx/dialog.h"
#include "wx/frame.h"
#include "wx/config.h"
#include "wx/splitter.h"
#include "wx/notebook.h"
#include "wx/listbox.h"
#include "wx/choice.h"
#include "wx/combobox.h"
#include "wx/checkbox.h"
#include "wx/stattext.h"
#include "wx/html/htmlwin.h"
#include "wx/html/helpwnd.h"
#include "wx/html/htmprint.h"
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpController;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpWindow;
class WXDLLIMPEXP_HTML wxHtmlHelpDialog : public wxDialog
{
DECLARE_DYNAMIC_CLASS(wxHtmlHelpDialog)
public:
wxHtmlHelpDialog(wxHtmlHelpData* data = NULL) { Init(data); }
wxHtmlHelpDialog(wxWindow* parent, wxWindowID wxWindowID,
const wxString& title = wxEmptyString,
int style = wxHF_DEFAULT_STYLE, wxHtmlHelpData* data = NULL);
virtual ~wxHtmlHelpDialog();
bool Create(wxWindow* parent, wxWindowID id, const wxString& title = wxEmptyString,
int style = wxHF_DEFAULT_STYLE);
/// Returns the data associated with this dialog.
wxHtmlHelpData* GetData() { return m_Data; }
/// Returns the controller that created this dialog.
wxHtmlHelpController* GetController() const { return m_helpController; }
/// Sets the controller associated with this dialog.
void SetController(wxHtmlHelpController* controller) { m_helpController = controller; }
/// Returns the help window.
wxHtmlHelpWindow* GetHelpWindow() const { return m_HtmlHelpWin; }
// Sets format of title of the frame. Must contain exactly one "%s"
// (for title of displayed HTML page)
void SetTitleFormat(const wxString& format);
// Override to add custom buttons to the toolbar
virtual void AddToolbarButtons(wxToolBar* WXUNUSED(toolBar), int WXUNUSED(style)) {}
protected:
void Init(wxHtmlHelpData* data = NULL);
void OnCloseWindow(wxCloseEvent& event);
protected:
// Temporary pointer to pass to window
wxHtmlHelpData* m_Data;
wxString m_TitleFormat; // title of the help frame
wxHtmlHelpWindow *m_HtmlHelpWin;
wxHtmlHelpController* m_helpController;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxHtmlHelpDialog)
};
#endif
// wxUSE_WXHTML_HELP
#endif

View file

@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// Name: helpfrm.h
// Purpose: wxHtmlHelpFrame
// Notes: Based on htmlhelp.cpp, implementing a monolithic
// HTML Help controller class, by Vaclav Slavik
// Author: Harm van der Heijden and Vaclav Slavik
// RCS-ID: $Id: helpfrm.h 50202 2007-11-23 21:29:29Z VZ $
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HELPFRM_H_
#define _WX_HELPFRM_H_
#include "wx/defs.h"
#if wxUSE_WXHTML_HELP
#include "wx/helpbase.h"
#include "wx/html/helpdata.h"
#include "wx/window.h"
#include "wx/frame.h"
#include "wx/config.h"
#include "wx/splitter.h"
#include "wx/notebook.h"
#include "wx/listbox.h"
#include "wx/choice.h"
#include "wx/combobox.h"
#include "wx/checkbox.h"
#include "wx/stattext.h"
#include "wx/html/htmlwin.h"
#include "wx/html/helpwnd.h"
#include "wx/html/htmprint.h"
class WXDLLIMPEXP_FWD_CORE wxButton;
class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
class WXDLLIMPEXP_FWD_CORE wxTreeCtrl;
// style flags for the Help Frame
#define wxHF_TOOLBAR 0x0001
#define wxHF_CONTENTS 0x0002
#define wxHF_INDEX 0x0004
#define wxHF_SEARCH 0x0008
#define wxHF_BOOKMARKS 0x0010
#define wxHF_OPEN_FILES 0x0020
#define wxHF_PRINT 0x0040
#define wxHF_FLAT_TOOLBAR 0x0080
#define wxHF_MERGE_BOOKS 0x0100
#define wxHF_ICONS_BOOK 0x0200
#define wxHF_ICONS_BOOK_CHAPTER 0x0400
#define wxHF_ICONS_FOLDER 0x0000 // this is 0 since it is default
#define wxHF_DEFAULT_STYLE (wxHF_TOOLBAR | wxHF_CONTENTS | \
wxHF_INDEX | wxHF_SEARCH | \
wxHF_BOOKMARKS | wxHF_PRINT)
//compatibility:
#define wxHF_OPENFILES wxHF_OPEN_FILES
#define wxHF_FLATTOOLBAR wxHF_FLAT_TOOLBAR
#define wxHF_DEFAULTSTYLE wxHF_DEFAULT_STYLE
struct wxHtmlHelpMergedIndexItem;
class wxHtmlHelpMergedIndex;
class WXDLLIMPEXP_FWD_CORE wxHelpControllerBase;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpController;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpWindow;
class WXDLLIMPEXP_HTML wxHtmlHelpFrame : public wxFrame
{
DECLARE_DYNAMIC_CLASS(wxHtmlHelpFrame)
public:
wxHtmlHelpFrame(wxHtmlHelpData* data = NULL) { Init(data); }
wxHtmlHelpFrame(wxWindow* parent, wxWindowID wxWindowID,
const wxString& title = wxEmptyString,
int style = wxHF_DEFAULT_STYLE, wxHtmlHelpData* data = NULL,
wxConfigBase *config=NULL, const wxString& rootpath = wxEmptyString);
bool Create(wxWindow* parent, wxWindowID id, const wxString& title = wxEmptyString,
int style = wxHF_DEFAULT_STYLE,
wxConfigBase *config=NULL, const wxString& rootpath = wxEmptyString);
virtual ~wxHtmlHelpFrame();
/// Returns the data associated with the window.
wxHtmlHelpData* GetData() { return m_Data; }
/// Returns the help controller associated with the window.
wxHtmlHelpController* GetController() const { return m_helpController; }
/// Sets the help controller associated with the window.
void SetController(wxHtmlHelpController* controller) { m_helpController = controller; }
/// Returns the help window.
wxHtmlHelpWindow* GetHelpWindow() const { return m_HtmlHelpWin; }
// Sets format of title of the frame. Must contain exactly one "%s"
// (for title of displayed HTML page)
void SetTitleFormat(const wxString& format);
// For compatibility
void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
// Make the help controller's frame 'modal' if
// needed
void AddGrabIfNeeded();
// Override to add custom buttons to the toolbar
virtual void AddToolbarButtons(wxToolBar* WXUNUSED(toolBar), int WXUNUSED(style)) {}
// we don't want to prevent the app from closing just because a help window
// remains opened
virtual bool ShouldPreventAppExit() const { return false; }
protected:
void Init(wxHtmlHelpData* data = NULL);
void OnCloseWindow(wxCloseEvent& event);
void OnActivate(wxActivateEvent& event);
#ifdef __WXMAC__
void OnClose(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
#endif
// Images:
enum {
IMG_Book = 0,
IMG_Folder,
IMG_Page
};
protected:
wxHtmlHelpData* m_Data;
bool m_DataCreated; // m_Data created by frame, or supplied?
wxString m_TitleFormat; // title of the help frame
wxHtmlHelpWindow *m_HtmlHelpWin;
wxHtmlHelpController* m_helpController;
private:
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxHtmlHelpFrame)
};
#endif // wxUSE_WXHTML_HELP
#endif

View file

@ -0,0 +1,300 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/html/helpwnd.h
// Purpose: wxHtmlHelpWindow
// Notes: Based on htmlhelp.cpp, implementing a monolithic
// HTML Help controller class, by Vaclav Slavik
// Author: Harm van der Heijden and Vaclav Slavik
// RCS-ID: $Id: helpwnd.h 49563 2007-10-31 20:46:21Z VZ $
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HELPWND_H_
#define _WX_HELPWND_H_
#include "wx/defs.h"
#if wxUSE_WXHTML_HELP
#include "wx/helpbase.h"
#include "wx/html/helpdata.h"
#include "wx/window.h"
#include "wx/frame.h"
#include "wx/config.h"
#include "wx/splitter.h"
#include "wx/notebook.h"
#include "wx/listbox.h"
#include "wx/choice.h"
#include "wx/combobox.h"
#include "wx/checkbox.h"
#include "wx/stattext.h"
#include "wx/html/htmlwin.h"
#include "wx/html/htmprint.h"
class WXDLLIMPEXP_FWD_CORE wxButton;
class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
class WXDLLIMPEXP_FWD_CORE wxTreeCtrl;
// style flags for the Help Frame
#define wxHF_TOOLBAR 0x0001
#define wxHF_CONTENTS 0x0002
#define wxHF_INDEX 0x0004
#define wxHF_SEARCH 0x0008
#define wxHF_BOOKMARKS 0x0010
#define wxHF_OPEN_FILES 0x0020
#define wxHF_PRINT 0x0040
#define wxHF_FLAT_TOOLBAR 0x0080
#define wxHF_MERGE_BOOKS 0x0100
#define wxHF_ICONS_BOOK 0x0200
#define wxHF_ICONS_BOOK_CHAPTER 0x0400
#define wxHF_ICONS_FOLDER 0x0000 // this is 0 since it is default
#define wxHF_DEFAULT_STYLE (wxHF_TOOLBAR | wxHF_CONTENTS | \
wxHF_INDEX | wxHF_SEARCH | \
wxHF_BOOKMARKS | wxHF_PRINT)
//compatibility:
#define wxHF_OPENFILES wxHF_OPEN_FILES
#define wxHF_FLATTOOLBAR wxHF_FLAT_TOOLBAR
#define wxHF_DEFAULTSTYLE wxHF_DEFAULT_STYLE
struct wxHtmlHelpFrameCfg
{
int x, y, w, h;
long sashpos;
bool navig_on;
};
struct wxHtmlHelpMergedIndexItem;
class wxHtmlHelpMergedIndex;
class WXDLLIMPEXP_FWD_CORE wxHelpControllerBase;
class WXDLLIMPEXP_FWD_HTML wxHtmlHelpController;
/*!
* Help window
*/
class WXDLLIMPEXP_HTML wxHtmlHelpWindow : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxHtmlHelpWindow)
public:
wxHtmlHelpWindow(wxHtmlHelpData* data = NULL) { Init(data); }
wxHtmlHelpWindow(wxWindow* parent, wxWindowID wxWindowID,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int style = wxTAB_TRAVERSAL|wxNO_BORDER,
int helpStyle = wxHF_DEFAULT_STYLE,
wxHtmlHelpData* data = NULL);
bool Create(wxWindow* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int style = wxTAB_TRAVERSAL|wxNO_BORDER,
int helpStyle = wxHF_DEFAULT_STYLE);
virtual ~wxHtmlHelpWindow();
wxHtmlHelpData* GetData() { return m_Data; }
wxHtmlHelpController* GetController() const { return m_helpController; }
void SetController(wxHtmlHelpController* controller);
// 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 ...")
bool Display(const wxString& x);
// Alternative version that works with numeric ID.
// (uses extension to MS format, <param name="ID" value=id>, see docs)
bool Display(const int id);
// Displays help window and focuses contents.
bool DisplayContents();
// Displays help window and focuses index.
bool DisplayIndex();
// 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
bool KeywordSearch(const wxString& keyword,
wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString)
{
m_Config = config;
m_ConfigRoot = rootpath;
ReadCustomization(config, rootpath);
}
// 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 ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
// call this to let wxHtmlHelpWindow know page changed
void NotifyPageChanged();
// Refreshes Contents and Index tabs
void RefreshLists();
// Gets the HTML window
wxHtmlWindow* GetHtmlWindow() const { return m_HtmlWin; }
// Gets the splitter window
wxSplitterWindow* GetSplitterWindow() const { return m_Splitter; }
// Gets the toolbar
wxToolBar* GetToolBar() const { return m_toolBar; }
// Gets the configuration data
wxHtmlHelpFrameCfg& GetCfgData() { return m_Cfg; }
// Gets the tree control
wxTreeCtrl *GetTreeCtrl() const { return m_ContentsBox; }
protected:
void Init(wxHtmlHelpData* data = NULL);
// Adds items to m_Contents tree control
void CreateContents();
// Adds items to m_IndexList
void CreateIndex();
// Add books to search choice panel
void CreateSearch();
// Updates "merged index" structure that combines indexes of all books
// into better searchable structure
void UpdateMergedIndex();
// Add custom buttons to toolbar
virtual void AddToolbarButtons(wxToolBar *toolBar, int style);
// Displays options dialog (fonts etc.)
virtual void OptionsDialog();
void OnToolbar(wxCommandEvent& event);
void OnContentsSel(wxTreeEvent& event);
void OnIndexSel(wxCommandEvent& event);
void OnIndexFind(wxCommandEvent& event);
void OnIndexAll(wxCommandEvent& event);
void OnSearchSel(wxCommandEvent& event);
void OnSearch(wxCommandEvent& event);
void OnBookmarksSel(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
// Images:
enum {
IMG_Book = 0,
IMG_Folder,
IMG_Page
};
protected:
wxHtmlHelpData* m_Data;
bool m_DataCreated; // m_Data created by frame, or supplied?
wxString m_TitleFormat; // title of the help frame
// below are various pointers to GUI components
wxHtmlWindow *m_HtmlWin;
wxSplitterWindow *m_Splitter;
wxPanel *m_NavigPan;
wxNotebook *m_NavigNotebook;
wxTreeCtrl *m_ContentsBox;
wxTextCtrl *m_IndexText;
wxButton *m_IndexButton;
wxButton *m_IndexButtonAll;
wxListBox *m_IndexList;
wxTextCtrl *m_SearchText;
wxButton *m_SearchButton;
wxListBox *m_SearchList;
wxChoice *m_SearchChoice;
wxStaticText *m_IndexCountInfo;
wxCheckBox *m_SearchCaseSensitive;
wxCheckBox *m_SearchWholeWords;
wxToolBar* m_toolBar;
wxComboBox *m_Bookmarks;
wxArrayString m_BookmarksNames, m_BookmarksPages;
wxHtmlHelpFrameCfg m_Cfg;
wxConfigBase *m_Config;
wxString m_ConfigRoot;
// pagenumbers of controls in notebook (usually 0,1,2)
int m_ContentsPage;
int m_IndexPage;
int m_SearchPage;
// lists of available fonts (used in options dialog)
wxArrayString *m_NormalFonts, *m_FixedFonts;
int m_FontSize; // 0,1,2 = small,medium,big
wxString m_NormalFace, m_FixedFace;
bool m_UpdateContents;
#if wxUSE_PRINTING_ARCHITECTURE
wxHtmlEasyPrinting *m_Printer;
#endif
wxHashTable *m_PagesHash;
wxHtmlHelpController* m_helpController;
int m_hfStyle;
private:
void DoIndexFind();
void DoIndexAll();
void DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it);
wxHtmlHelpMergedIndex *m_mergedIndex;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxHtmlHelpWindow)
};
/*!
* Command IDs
*/
enum
{
//wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
wxID_HTML_PANEL = wxID_HIGHEST + 2,
wxID_HTML_BACK,
wxID_HTML_FORWARD,
wxID_HTML_UPNODE,
wxID_HTML_UP,
wxID_HTML_DOWN,
wxID_HTML_PRINT,
wxID_HTML_OPENFILE,
wxID_HTML_OPTIONS,
wxID_HTML_BOOKMARKSLIST,
wxID_HTML_BOOKMARKSADD,
wxID_HTML_BOOKMARKSREMOVE,
wxID_HTML_TREECTRL,
wxID_HTML_INDEXPAGE,
wxID_HTML_INDEXLIST,
wxID_HTML_INDEXTEXT,
wxID_HTML_INDEXBUTTON,
wxID_HTML_INDEXBUTTONALL,
wxID_HTML_NOTEBOOK,
wxID_HTML_SEARCHPAGE,
wxID_HTML_SEARCHTEXT,
wxID_HTML_SEARCHLIST,
wxID_HTML_SEARCHBUTTON,
wxID_HTML_SEARCHCHOICE,
wxID_HTML_COUNTINFO
};
#endif // wxUSE_WXHTML_HELP
#endif

View file

@ -0,0 +1,673 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmlcell.h
// Purpose: wxHtmlCell class is used by wxHtmlWindow/wxHtmlWinParser
// as a basic visual element of HTML page
// Author: Vaclav Slavik
// RCS-ID: $Id: htmlcell.h 53135 2008-04-12 02:31:04Z VZ $
// Copyright: (c) 1999-2003 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLCELL_H_
#define _WX_HTMLCELL_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/html/htmltag.h"
#include "wx/html/htmldefs.h"
#include "wx/window.h"
class WXDLLIMPEXP_FWD_HTML wxHtmlWindowInterface;
class WXDLLIMPEXP_FWD_HTML wxHtmlLinkInfo;
class WXDLLIMPEXP_FWD_HTML wxHtmlCell;
class WXDLLIMPEXP_FWD_HTML wxHtmlContainerCell;
// wxHtmlSelection is data holder with information about text selection.
// Selection is defined by two positions (beginning and end of the selection)
// and two leaf(!) cells at these positions.
class WXDLLIMPEXP_HTML wxHtmlSelection
{
public:
wxHtmlSelection()
: m_fromPos(wxDefaultPosition), m_toPos(wxDefaultPosition),
m_fromPrivPos(wxDefaultPosition), m_toPrivPos(wxDefaultPosition),
m_fromCell(NULL), m_toCell(NULL) {}
void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
const wxPoint& toPos, const wxHtmlCell *toCell);
void Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell);
const wxHtmlCell *GetFromCell() const { return m_fromCell; }
const wxHtmlCell *GetToCell() const { return m_toCell; }
// these values are in absolute coordinates:
const wxPoint& GetFromPos() const { return m_fromPos; }
const wxPoint& GetToPos() const { return m_toPos; }
// these are From/ToCell's private data
const wxPoint& GetFromPrivPos() const { return m_fromPrivPos; }
const wxPoint& GetToPrivPos() const { return m_toPrivPos; }
void SetFromPrivPos(const wxPoint& pos) { m_fromPrivPos = pos; }
void SetToPrivPos(const wxPoint& pos) { m_toPrivPos = pos; }
void ClearPrivPos() { m_toPrivPos = m_fromPrivPos = wxDefaultPosition; }
bool IsEmpty() const
{ return m_fromPos == wxDefaultPosition &&
m_toPos == wxDefaultPosition; }
private:
wxPoint m_fromPos, m_toPos;
wxPoint m_fromPrivPos, m_toPrivPos;
const wxHtmlCell *m_fromCell, *m_toCell;
};
enum wxHtmlSelectionState
{
wxHTML_SEL_OUT, // currently rendered cell is outside the selection
wxHTML_SEL_IN, // ... is inside selection
wxHTML_SEL_CHANGING // ... is the cell on which selection state changes
};
// Selection state is passed to wxHtmlCell::Draw so that it can render itself
// differently e.g. when inside text selection or outside it.
class WXDLLIMPEXP_HTML wxHtmlRenderingState
{
public:
wxHtmlRenderingState() : m_selState(wxHTML_SEL_OUT) {}
void SetSelectionState(wxHtmlSelectionState s) { m_selState = s; }
wxHtmlSelectionState GetSelectionState() const { return m_selState; }
void SetFgColour(const wxColour& c) { m_fgColour = c; }
const wxColour& GetFgColour() const { return m_fgColour; }
void SetBgColour(const wxColour& c) { m_bgColour = c; }
const wxColour& GetBgColour() const { return m_bgColour; }
private:
wxHtmlSelectionState m_selState;
wxColour m_fgColour, m_bgColour;
};
// HTML rendering customization. This class is used when rendering wxHtmlCells
// as a callback:
class WXDLLIMPEXP_HTML wxHtmlRenderingStyle
{
public:
virtual ~wxHtmlRenderingStyle() {}
virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
};
// Standard style:
class WXDLLIMPEXP_HTML wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle
{
public:
virtual wxColour GetSelectedTextColour(const wxColour& clr);
virtual wxColour GetSelectedTextBgColour(const wxColour& clr);
};
// Information given to cells when drawing them. Contains rendering state,
// selection information and rendering style object that can be used to
// customize the output.
class WXDLLIMPEXP_HTML wxHtmlRenderingInfo
{
public:
wxHtmlRenderingInfo() : m_selection(NULL), m_style(NULL) {}
void SetSelection(wxHtmlSelection *s) { m_selection = s; }
wxHtmlSelection *GetSelection() const { return m_selection; }
void SetStyle(wxHtmlRenderingStyle *style) { m_style = style; }
wxHtmlRenderingStyle& GetStyle() { return *m_style; }
wxHtmlRenderingState& GetState() { return m_state; }
protected:
wxHtmlSelection *m_selection;
wxHtmlRenderingStyle *m_style;
wxHtmlRenderingState m_state;
};
// Flags for wxHtmlCell::FindCellByPos
enum
{
wxHTML_FIND_EXACT = 1,
wxHTML_FIND_NEAREST_BEFORE = 2,
wxHTML_FIND_NEAREST_AFTER = 4
};
// Superscript/subscript/normal script mode of a cell
enum wxHtmlScriptMode
{
wxHTML_SCRIPT_NORMAL,
wxHTML_SCRIPT_SUB,
wxHTML_SCRIPT_SUP
};
// ---------------------------------------------------------------------------
// 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 WXDLLIMPEXP_HTML wxHtmlCell : public wxObject
{
public:
wxHtmlCell();
virtual ~wxHtmlCell();
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;}
// Returns the maximum possible length of the cell.
// Call Layout at least once before using GetMaxTotalWidth()
virtual int GetMaxTotalWidth() const { return m_Width; }
int GetHeight() const {return m_Height;}
int GetDescent() const {return m_Descent;}
void SetScriptMode(wxHtmlScriptMode mode, long previousBase);
wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
long GetScriptBaseline() { return m_ScriptBaseline; }
// Formatting cells are not visible on the screen, they only alter
// renderer's state.
bool IsFormattingCell() const { return m_Width == 0 && m_Height == 0; }
const wxString& GetId() const { return m_id; }
void SetId(const wxString& id) { m_id = id; }
// 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
virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0,
int WXUNUSED(y) = 0) const
{ return m_Link; }
// Returns cursor to be used when mouse is over the cell:
virtual wxCursor GetMouseCursor(wxHtmlWindowInterface *window) const;
#if WXWIN_COMPATIBILITY_2_6
// this was replaced by GetMouseCursor, don't use in new code!
virtual wxCursor GetCursor() const;
#endif
// return next cell among parent's cells
wxHtmlCell *GetNext() const {return m_Next;}
// returns first child cell (if there are any, i.e. if this is container):
virtual wxHtmlCell* GetFirstChild() const { return NULL; }
// members writing methods
virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;}
void SetLink(const wxHtmlLinkInfo& link);
void SetNext(wxHtmlCell *cell) {m_Next = cell;}
// 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 Layout(int w);
// renders the cell
virtual void Draw(wxDC& WXUNUSED(dc),
int WXUNUSED(x), int WXUNUSED(y),
int WXUNUSED(view_y1), int WXUNUSED(view_y2),
wxHtmlRenderingInfo& WXUNUSED(info)) {}
// 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 void DrawInvisible(wxDC& WXUNUSED(dc),
int WXUNUSED(x), int WXUNUSED(y),
wxHtmlRenderingInfo& WXUNUSED(info)) {}
// 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(wxHTML_COND_ISANCHOR, "news");
// returns pointer to anchor news
virtual const wxHtmlCell* Find(int condition, const void* param) const;
// This function is called when mouse button is clicked over the cell.
// Returns true if a link is clicked, false otherwise.
//
// 'window' is pointer to wxHtmlWindowInterface of the window which
// generated the event.
// HINT: if this handling is not enough for you you should use
// wxHtmlWidgetCell
virtual bool ProcessMouseClick(wxHtmlWindowInterface *window,
const wxPoint& pos,
const wxMouseEvent& event);
#if WXWIN_COMPATIBILITY_2_6
// this was replaced by ProcessMouseClick, don't use in new code!
virtual void OnMouseClick(wxWindow *window,
int x, int y, const wxMouseEvent& event);
#endif
// This method used to adjust pagebreak position. The parameter is variable
// that contains y-coordinate of page break (= horizontal line that should
// not be crossed by words, images etc.). If this cell cannot be divided
// into two pieces (each one on another page) then it moves the pagebreak
// few pixels up.
//
// Returned value : true if pagebreak was modified, false otherwise
// Usage : while (container->AdjustPagebreak(&p)) {}
virtual bool AdjustPagebreak(int *pagebreak,
wxArrayInt& known_pagebreaks) const;
// Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default
// is true - the cell can be split on two pages
void SetCanLiveOnPagebreak(bool can) { m_CanLiveOnPagebreak = can; }
// Can the line be broken before this cell?
virtual bool IsLinebreakAllowed() const
{ return !IsFormattingCell(); }
// Returns true for simple == terminal cells, i.e. not composite ones.
// This if for internal usage only and may disappear in future versions!
virtual bool IsTerminalCell() const { return true; }
// Find a cell inside this cell positioned at the given coordinates
// (relative to this's positions). Returns NULL if no such cell exists.
// The flag can be used to specify whether to look for terminal or
// nonterminal cells or both. In either case, returned cell is deepest
// cell in cells tree that contains [x,y].
virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
unsigned flags = wxHTML_FIND_EXACT) const;
// Returns absolute position of the cell on HTML canvas.
// If rootCell is provided, then it's considered to be the root of the
// hierarchy and the returned value is relative to it.
wxPoint GetAbsPos(wxHtmlCell *rootCell = NULL) const;
// Returns root cell of the hierarchy (i.e. grand-grand-...-parent that
// doesn't have a parent itself)
wxHtmlCell *GetRootCell() const;
// Returns first (last) terminal cell inside this cell. It may return NULL,
// but it is rare -- only if there are no terminals in the tree.
virtual wxHtmlCell *GetFirstTerminal() const
{ return wxConstCast(this, wxHtmlCell); }
virtual wxHtmlCell *GetLastTerminal() const
{ return wxConstCast(this, wxHtmlCell); }
// Returns cell's depth, i.e. how far under the root cell it is
// (if it is the root, depth is 0)
unsigned GetDepth() const;
// Returns true if the cell appears before 'cell' in natural order of
// cells (= as they are read). If cell A is (grand)parent of cell B,
// then both A.IsBefore(B) and B.IsBefore(A) always return true.
bool IsBefore(wxHtmlCell *cell) const;
// Converts the cell into text representation. If sel != NULL then
// only part of the cell inside the selection is converted.
virtual wxString ConvertToText(wxHtmlSelection *WXUNUSED(sel)) const
{ return wxEmptyString; }
protected:
// pointer to the next cell
wxHtmlCell *m_Next;
// pointer to parent cell
wxHtmlContainerCell *m_Parent;
// dimensions of fragment (m_Descent is used to position text & images)
long m_Width, m_Height, m_Descent;
// position where the fragment is drawn:
long m_PosX, m_PosY;
// superscript/subscript/normal:
wxHtmlScriptMode m_ScriptMode;
long m_ScriptBaseline;
// destination address if this fragment is hypertext link, NULL otherwise
wxHtmlLinkInfo *m_Link;
// true if this cell can be placed on pagebreak, false otherwise
bool m_CanLiveOnPagebreak;
// unique identifier of the cell, generated from "id" property of tags
wxString m_id;
DECLARE_ABSTRACT_CLASS(wxHtmlCell)
DECLARE_NO_COPY_CLASS(wxHtmlCell)
};
// ----------------------------------------------------------------------------
// Inherited cells:
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxHtmlWordCell
// Single word in input stream.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlWordCell : public wxHtmlCell
{
public:
wxHtmlWordCell(const wxString& word, const wxDC& dc);
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingInfo& info);
virtual wxCursor GetMouseCursor(wxHtmlWindowInterface *window) const;
wxString ConvertToText(wxHtmlSelection *sel) const;
bool IsLinebreakAllowed() const { return m_allowLinebreak; }
void SetPreviousWord(wxHtmlWordCell *cell);
protected:
void SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const;
void Split(const wxDC& dc,
const wxPoint& selFrom, const wxPoint& selTo,
unsigned& pos1, unsigned& pos2) const;
wxString m_Word;
bool m_allowLinebreak;
DECLARE_ABSTRACT_CLASS(wxHtmlWordCell)
DECLARE_NO_COPY_CLASS(wxHtmlWordCell)
};
// Container contains other cells, thus forming tree structure of rendering
// elements. Basic code of layout algorithm is contained in this class.
class WXDLLIMPEXP_HTML wxHtmlContainerCell : public wxHtmlCell
{
public:
wxHtmlContainerCell(wxHtmlContainerCell *parent);
virtual ~wxHtmlContainerCell();
virtual void Layout(int w);
virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingInfo& info);
virtual void DrawInvisible(wxDC& dc, int x, int y,
wxHtmlRenderingInfo& info);
/* virtual bool AdjustPagebreak(int *pagebreak, int *known_pagebreaks = NULL, int number_of_pages = 0) const;*/
virtual bool AdjustPagebreak(int *pagebreak, wxArrayInt& known_pagebreaks) const;
// insert cell at the end of m_Cells list
void InsertCell(wxHtmlCell *cell);
// sets horizontal/vertical alignment
void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;}
int GetAlignHor() const {return m_AlignHor;}
void SetAlignVer(int al) {m_AlignVer = al; m_LastLayout = -1;}
int GetAlignVer() const {return m_AlignVer;}
// sets left-border indentation. units is one of wxHTML_UNITS_* constants
// what is combination of wxHTML_INDENT_*
void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
// returns the indentation. ind is one of wxHTML_INDENT_* constants
int GetIndent(int ind) const;
// returns type of value returned by GetIndent(ind)
int GetIndentUnits(int ind) const;
// sets alignment info based on given tag's params
void SetAlign(const wxHtmlTag& tag);
// sets floating width adjustment
// (examples : 32 percent of parent container,
// -15 pixels percent (this means 100 % - 15 pixels)
void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units; m_LastLayout = -1;}
void SetWidthFloat(const wxHtmlTag& tag, double pixel_scale = 1.0);
// sets minimal height of this container.
void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;}
void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = true; m_BkColour = clr;}
// returns background colour (of wxNullColour if none set), so that widgets can
// adapt to it:
wxColour GetBackgroundColour();
void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = true; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
virtual const wxHtmlCell* Find(int condition, const void* param) const;
#if WXWIN_COMPATIBILITY_2_6
// this was replaced by ProcessMouseClick, don't use in new code!
virtual void OnMouseClick(wxWindow *window,
int x, int y, const wxMouseEvent& event);
#endif
virtual bool ProcessMouseClick(wxHtmlWindowInterface *window,
const wxPoint& pos,
const wxMouseEvent& event);
virtual wxHtmlCell* GetFirstChild() const { return m_Cells; }
#if WXWIN_COMPATIBILITY_2_4
wxDEPRECATED( wxHtmlCell* GetFirstCell() const );
#endif
// returns last child cell:
wxHtmlCell* GetLastChild() const { return m_LastCell; }
// see comment in wxHtmlCell about this method
virtual bool IsTerminalCell() const { return false; }
virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
unsigned flags = wxHTML_FIND_EXACT) const;
virtual wxHtmlCell *GetFirstTerminal() const;
virtual wxHtmlCell *GetLastTerminal() const;
// Removes indentation on top or bottom of the container (i.e. above or
// below first/last terminal cell). For internal use only.
virtual void RemoveExtraSpacing(bool top, bool bottom);
// Returns the maximum possible length of the container.
// Call Layout at least once before using GetMaxTotalWidth()
virtual int GetMaxTotalWidth() const { return m_MaxTotalWidth; }
protected:
void UpdateRenderingStatePre(wxHtmlRenderingInfo& info,
wxHtmlCell *cell) const;
void UpdateRenderingStatePost(wxHtmlRenderingInfo& info,
wxHtmlCell *cell) const;
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.
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
int m_LastLayout;
// if != -1 then call to Layout may be no-op
// if previous call to Layout has same argument
int m_MaxTotalWidth;
// Maximum possible length if ignoring line wrap
DECLARE_ABSTRACT_CLASS(wxHtmlContainerCell)
DECLARE_NO_COPY_CLASS(wxHtmlContainerCell)
};
#if WXWIN_COMPATIBILITY_2_4
inline wxHtmlCell* wxHtmlContainerCell::GetFirstCell() const
{ return GetFirstChild(); }
#endif
// ---------------------------------------------------------------------------
// wxHtmlColourCell
// Color changer.
// ---------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlColourCell : public wxHtmlCell
{
public:
wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingInfo& info);
virtual void DrawInvisible(wxDC& dc, int x, int y,
wxHtmlRenderingInfo& info);
protected:
wxColour m_Colour;
unsigned m_Flags;
DECLARE_ABSTRACT_CLASS(wxHtmlColourCell)
DECLARE_NO_COPY_CLASS(wxHtmlColourCell)
};
//--------------------------------------------------------------------------------
// wxHtmlFontCell
// Sets actual font used for text rendering
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlFontCell : public wxHtmlCell
{
public:
wxHtmlFontCell(wxFont *font) : wxHtmlCell() { m_Font = (*font); }
virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingInfo& info);
virtual void DrawInvisible(wxDC& dc, int x, int y,
wxHtmlRenderingInfo& info);
protected:
wxFont m_Font;
DECLARE_ABSTRACT_CLASS(wxHtmlFontCell)
DECLARE_NO_COPY_CLASS(wxHtmlFontCell)
};
//--------------------------------------------------------------------------------
// wxHtmlwidgetCell
// This cell is connected with wxWindow object
// You can use it to insert windows into HTML page
// (buttons, input boxes etc.)
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlWidgetCell : public wxHtmlCell
{
public:
// !!! 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)
wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
virtual ~wxHtmlWidgetCell() { m_Wnd->Destroy(); }
virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingInfo& info);
virtual void DrawInvisible(wxDC& dc, int x, int y,
wxHtmlRenderingInfo& info);
virtual void Layout(int w);
protected:
wxWindow* m_Wnd;
int m_WidthFloat;
// width float is used in adjustWidth (it is in percents)
DECLARE_ABSTRACT_CLASS(wxHtmlWidgetCell)
DECLARE_NO_COPY_CLASS(wxHtmlWidgetCell)
};
//--------------------------------------------------------------------------------
// wxHtmlLinkInfo
// Internal data structure. It represents hypertext link
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlLinkInfo : public wxObject
{
public:
wxHtmlLinkInfo() : wxObject()
{ m_Href = m_Target = wxEmptyString; m_Event = NULL, m_Cell = NULL; }
wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString) : wxObject()
{ m_Href = href; m_Target = target; m_Event = NULL, m_Cell = NULL; }
wxHtmlLinkInfo(const wxHtmlLinkInfo& l) : wxObject()
{ m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
m_Cell = l.m_Cell; }
wxHtmlLinkInfo& operator=(const wxHtmlLinkInfo& l)
{ m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
m_Cell = l.m_Cell; return *this; }
void SetEvent(const wxMouseEvent *e) { m_Event = e; }
void SetHtmlCell(const wxHtmlCell *e) { m_Cell = e; }
wxString GetHref() const { return m_Href; }
wxString GetTarget() const { return m_Target; }
const wxMouseEvent* GetEvent() const { return m_Event; }
const wxHtmlCell* GetHtmlCell() const { return m_Cell; }
private:
wxString m_Href, m_Target;
const wxMouseEvent *m_Event;
const wxHtmlCell *m_Cell;
};
// ----------------------------------------------------------------------------
// wxHtmlTerminalCellsInterator
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlTerminalCellsInterator
{
public:
wxHtmlTerminalCellsInterator(const wxHtmlCell *from, const wxHtmlCell *to)
: m_to(to), m_pos(from) {}
operator bool() const { return m_pos != NULL; }
const wxHtmlCell* operator++();
const wxHtmlCell* operator->() const { return m_pos; }
const wxHtmlCell* operator*() const { return m_pos; }
private:
const wxHtmlCell *m_to, *m_pos;
};
#endif // wxUSE_HTML
#endif // _WX_HTMLCELL_H_

View file

@ -0,0 +1,104 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmldefs.h
// Purpose: constants for wxhtml library
// Author: Vaclav Slavik
// RCS-ID: $Id: htmldefs.h 40823 2006-08-25 16:52:58Z VZ $
// Copyright: (c) 1999 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLDEFS_H_
#define _WX_HTMLDEFS_H_
#include "wx/defs.h"
#if wxUSE_HTML
//--------------------------------------------------------------------------------
// ALIGNMENTS
// Describes alignment of text etc. in containers
//--------------------------------------------------------------------------------
#define wxHTML_ALIGN_LEFT 0x0000
#define wxHTML_ALIGN_RIGHT 0x0002
#define wxHTML_ALIGN_JUSTIFY 0x0010
#define wxHTML_ALIGN_TOP 0x0004
#define wxHTML_ALIGN_BOTTOM 0x0008
#define wxHTML_ALIGN_CENTER 0x0001
//--------------------------------------------------------------------------------
// COLOR MODES
// Used by wxHtmlColourCell to determine clr of what is changing
//--------------------------------------------------------------------------------
#define wxHTML_CLR_FOREGROUND 0x0001
#define wxHTML_CLR_BACKGROUND 0x0002
//--------------------------------------------------------------------------------
// UNITS
// Used to specify units
//--------------------------------------------------------------------------------
#define wxHTML_UNITS_PIXELS 0x0001
#define wxHTML_UNITS_PERCENT 0x0002
//--------------------------------------------------------------------------------
// INDENTS
// Used to specify indetation relatives
//--------------------------------------------------------------------------------
#define wxHTML_INDENT_LEFT 0x0010
#define wxHTML_INDENT_RIGHT 0x0020
#define wxHTML_INDENT_TOP 0x0040
#define wxHTML_INDENT_BOTTOM 0x0080
#define wxHTML_INDENT_HORIZONTAL (wxHTML_INDENT_LEFT | wxHTML_INDENT_RIGHT)
#define wxHTML_INDENT_VERTICAL (wxHTML_INDENT_TOP | wxHTML_INDENT_BOTTOM)
#define wxHTML_INDENT_ALL (wxHTML_INDENT_VERTICAL | wxHTML_INDENT_HORIZONTAL)
//--------------------------------------------------------------------------------
// FIND CONDITIONS
// Identifiers of wxHtmlCell's Find() conditions
//--------------------------------------------------------------------------------
#define wxHTML_COND_ISANCHOR 1
// Finds the anchor of 'param' name (pointer to wxString).
#define wxHTML_COND_ISIMAGEMAP 2
// Finds imagemap of 'param' name (pointer to wxString).
// (used exclusively by m_image.cpp)
#define wxHTML_COND_USER 10000
// User-defined conditions should start from this number
//--------------------------------------------------------------------------------
// INTERNALS
// wxHTML internal constants
//--------------------------------------------------------------------------------
/* size of one scroll step of wxHtmlWindow in pixels */
#define wxHTML_SCROLL_STEP 16
/* size of temporary buffer used during parsing */
#define wxHTML_BUFLEN 1024
/* maximum number of pages printable via html printing */
#define wxHTML_PRINT_MAX_PAGES 999
#endif // wxUSE_HTML
#endif // _WX_HTMLDEFS_H_

View file

@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmlfilt.h
// Purpose: filters
// Author: Vaclav Slavik
// RCS-ID: $Id: htmlfilt.h 35650 2005-09-23 12:56:45Z MR $
// Copyright: (c) 1999 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLFILT_H_
#define _WX_HTMLFILT_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/filesys.h"
//--------------------------------------------------------------------------------
// 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 WXDLLIMPEXP_HTML wxHtmlFilter : public wxObject
{
DECLARE_ABSTRACT_CLASS(wxHtmlFilter)
public:
wxHtmlFilter() : wxObject() {}
virtual ~wxHtmlFilter() {}
// returns true if this filter is able to open&read given file
virtual bool CanRead(const wxFSFile& file) const = 0;
// Reads given file and returns HTML document.
// Returns empty string if opening failed
virtual wxString ReadFile(const wxFSFile& file) const = 0;
};
//--------------------------------------------------------------------------------
// 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 WXDLLIMPEXP_HTML wxHtmlFilterPlainText : public wxHtmlFilter
{
DECLARE_DYNAMIC_CLASS(wxHtmlFilterPlainText)
public:
virtual bool CanRead(const wxFSFile& file) const;
virtual wxString ReadFile(const wxFSFile& file) const;
};
//--------------------------------------------------------------------------------
// wxHtmlFilterHTML
// filter for text/html
//--------------------------------------------------------------------------------
class wxHtmlFilterHTML : public wxHtmlFilter
{
DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML)
public:
virtual bool CanRead(const wxFSFile& file) const;
virtual wxString ReadFile(const wxFSFile& file) const;
};
#endif // wxUSE_HTML
#endif // _WX_HTMLFILT_H_

View file

@ -0,0 +1,283 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmlpars.h
// Purpose: wxHtmlParser class (generic parser)
// Author: Vaclav Slavik
// RCS-ID: $Id: htmlpars.h 49563 2007-10-31 20:46:21Z VZ $
// Copyright: (c) 1999 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLPARS_H_
#define _WX_HTMLPARS_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/html/htmltag.h"
#include "wx/filesys.h"
#include "wx/hash.h"
#include "wx/fontenc.h"
class WXDLLIMPEXP_FWD_BASE wxMBConv;
class WXDLLIMPEXP_FWD_HTML wxHtmlParser;
class WXDLLIMPEXP_FWD_HTML wxHtmlTagHandler;
class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser;
class wxHtmlTextPieces;
class wxHtmlParserState;
enum wxHtmlURLType
{
wxHTML_URL_PAGE,
wxHTML_URL_IMAGE,
wxHTML_URL_OTHER
};
// This class handles generic parsing of HTML document : it scans
// the document and divides it into blocks of tags (where one block
// consists of starting and ending tag and of text between these
// 2 tags.
class WXDLLIMPEXP_HTML wxHtmlParser : public wxObject
{
DECLARE_ABSTRACT_CLASS(wxHtmlParser)
public:
wxHtmlParser();
virtual ~wxHtmlParser();
// Sets the class which will be used for opening files
void SetFS(wxFileSystem *fs) { m_FS = fs; }
wxFileSystem* GetFS() const { return m_FS; }
// Opens file if the parser is allowed to open given URL (may be forbidden
// for security reasons)
virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
// 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(); (its return value is then returned)
// 4. call DoneParser();
wxObject* Parse(const wxString& source);
// Sets the source. This must be called before running Parse() method.
virtual void InitParser(const wxString& source);
// This must be called after Parse().
virtual void DoneParser();
// May be called during parsing to immediately return from Parse().
virtual void StopParsing() { m_stopParsing = true; }
// Parses the m_Source from begin_pos to end_pos-1.
// (in noparams version it parses whole m_Source)
void DoParsing(int begin_pos, int end_pos);
void DoParsing();
// Returns pointer to the tag at parser's current position
wxHtmlTag *GetCurrentTag() const { return m_CurTag; }
// 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 wxObject* GetProduct() = 0;
// adds handler to the list & hash table of handlers.
virtual void AddTagHandler(wxHtmlTagHandler *handler);
// Forces the handler to handle additional tags (not returned by GetSupportedTags).
// The handler should already be in use by this parser.
// Example: you want to parse following pseudo-html structure:
// <myitems>
// <it name="one" value="1">
// <it name="two" value="2">
// </myitems>
// <it> This last it has different meaning, we don't want it to be parsed by myitems handler!
// handler can handle only 'myitems' (e.g. its GetSupportedTags returns "MYITEMS")
// you can call PushTagHandler(handler, "IT") when you find <myitems>
// and call PopTagHandler() when you find </myitems>
void PushTagHandler(wxHtmlTagHandler *handler, const wxString& tags);
// Restores state before last call to PushTagHandler
void PopTagHandler();
wxString* GetSource() {return &m_Source;}
void SetSource(const wxString& src);
// Sets HTML source and remembers current parser's state so that it can
// later be restored. This is useful for on-line modifications of
// HTML source (for example, <pre> handler replaces spaces with &nbsp;
// and newlines with <br>)
virtual void SetSourceAndSaveState(const wxString& src);
// Restores parser's state from stack or returns false if the stack is
// empty
virtual bool RestoreState();
// Returns HTML source inside the element (i.e. between the starting
// and ending tag)
wxString GetInnerSource(const wxHtmlTag& tag);
// Parses HTML string 'markup' and extracts charset info from <meta> tag
// if present. Returns empty string if the tag is missing.
// For wxHTML's internal use.
static wxString ExtractCharsetInformation(const wxString& markup);
// Returns entity parser object, used to substitute HTML &entities;
wxHtmlEntitiesParser *GetEntitiesParser() const { return m_entitiesParser; }
protected:
// DOM structure
void CreateDOMTree();
void DestroyDOMTree();
void CreateDOMSubTree(wxHtmlTag *cur,
int begin_pos, int end_pos,
wxHtmlTagsCache *cache);
// 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 AddText(const wxChar* txt) = 0;
// 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.
virtual void AddTag(const wxHtmlTag& tag);
protected:
// DOM tree:
wxHtmlTag *m_CurTag;
wxHtmlTag *m_Tags;
wxHtmlTextPieces *m_TextPieces;
size_t m_CurTextPiece;
wxString m_Source;
wxHtmlParserState *m_SavedStates;
// 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.
wxList m_HandlersList;
wxHashTable m_HandlersHash;
DECLARE_NO_COPY_CLASS(wxHtmlParser)
// class for opening files (file system)
wxFileSystem *m_FS;
// handlers stack used by PushTagHandler and PopTagHandler
wxList *m_HandlersStack;
// entity parse
wxHtmlEntitiesParser *m_entitiesParser;
// flag indicating that the parser should stop
bool m_stopParsing;
};
// 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 its public methods)
// 2. Parser parses source between starting and ending tag
// 3. Handler restores original state of the parser
class WXDLLIMPEXP_HTML wxHtmlTagHandler : public wxObject
{
DECLARE_ABSTRACT_CLASS(wxHtmlTagHandler)
public:
wxHtmlTagHandler() : wxObject () { m_Parser = NULL; }
// 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 void SetParser(wxHtmlParser *parser)
{ m_Parser = parser; }
// 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 wxString GetSupportedTags() = 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
virtual bool HandleTag(const wxHtmlTag& tag) = 0;
protected:
// parses input between beginning and ending tag.
// m_Parser must be set.
void ParseInner(const wxHtmlTag& tag)
{ m_Parser->DoParsing(tag.GetBeginPos(), tag.GetEndPos1()); }
// Parses given source as if it was tag's inner code (see
// wxHtmlParser::GetInnerSource). Unlike ParseInner(), this method lets
// you specify the source code to parse. This is useful when you need to
// modify the inner text before parsing.
void ParseInnerSource(const wxString& source);
wxHtmlParser *m_Parser;
DECLARE_NO_COPY_CLASS(wxHtmlTagHandler)
};
// This class is used to parse HTML entities in strings. It can handle
// both named entities and &#xxxx entries where xxxx is Unicode code.
class WXDLLIMPEXP_HTML wxHtmlEntitiesParser : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxHtmlEntitiesParser)
public:
wxHtmlEntitiesParser();
virtual ~wxHtmlEntitiesParser();
// Sets encoding of output string.
// Has no effect if wxUSE_WCHAR_T==0 or wxUSE_UNICODE==1
void SetEncoding(wxFontEncoding encoding);
// Parses entities in input and replaces them with respective characters
// (with respect to output encoding)
wxString Parse(const wxString& input);
// Returns character for given entity or 0 if the enity is unknown
wxChar GetEntityChar(const wxString& entity);
// Returns character that represents given Unicode code
#if wxUSE_UNICODE
wxChar GetCharForCode(unsigned code) { return (wxChar)code; }
#else
wxChar GetCharForCode(unsigned code);
#endif
protected:
#if wxUSE_WCHAR_T && !wxUSE_UNICODE
wxMBConv *m_conv;
wxFontEncoding m_encoding;
#endif
DECLARE_NO_COPY_CLASS(wxHtmlEntitiesParser)
};
#endif
#endif // _WX_HTMLPARS_H_

View file

@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmlprep.h
// Purpose: HTML processor
// Author: Vaclav Slavik
// RCS-ID: $Id: htmlproc.h 35650 2005-09-23 12:56:45Z MR $
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLPREP_H_
#define _WX_HTMLPREP_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/string.h"
// Priority of preprocessor in the chain. The higher, the earlier it is used
enum
{
wxHTML_PRIORITY_DONTCARE = 128, // if the order doesn't matter, use this
// priority
wxHTML_PRIORITY_SYSTEM = 256 // >=256 is only for wxHTML's internals
};
// Classes derived from this class serve as simple text processors for
// wxHtmlWindow. wxHtmlWindow runs HTML markup through all registered
// processors before displaying it, thus allowing for on-the-fly
// modifications of the markup.
class WXDLLIMPEXP_HTML wxHtmlProcessor : public wxObject
{
DECLARE_ABSTRACT_CLASS(wxHtmlProcessor)
public:
wxHtmlProcessor() : wxObject(), m_enabled(true) {}
virtual ~wxHtmlProcessor() {}
// Process input text and return processed result
virtual wxString Process(const wxString& text) const = 0;
// Return priority value of this processor. The higher, the sooner
// is the processor applied to the text.
virtual int GetPriority() const { return wxHTML_PRIORITY_DONTCARE; }
// Enable/disable the processor. wxHtmlWindow won't use a disabled
// processor even if it is in its processors queue.
virtual void Enable(bool enable = true) { m_enabled = enable; }
bool IsEnabled() const { return m_enabled; }
protected:
bool m_enabled;
};
#endif // wxUSE_HTML
#endif // _WX_HTMLPROC_H_

View file

@ -0,0 +1,148 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmltag.h
// Purpose: wxHtmlTag class (represents single tag)
// Author: Vaclav Slavik
// RCS-ID: $Id: htmltag.h 49563 2007-10-31 20:46:21Z VZ $
// Copyright: (c) 1999 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLTAG_H_
#define _WX_HTMLTAG_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/object.h"
#include "wx/arrstr.h"
class WXDLLIMPEXP_FWD_CORE wxColour;
class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser;
//-----------------------------------------------------------------------------
// wxHtmlTagsCache
// - internal wxHTML class, do not use!
//-----------------------------------------------------------------------------
struct wxHtmlCacheItem;
class WXDLLIMPEXP_HTML wxHtmlTagsCache : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxHtmlTagsCache)
private:
wxHtmlCacheItem *m_Cache;
int m_CacheSize;
int m_CachePos;
public:
wxHtmlTagsCache() : wxObject() {m_CacheSize = 0; m_Cache = NULL;}
wxHtmlTagsCache(const wxString& source);
virtual ~wxHtmlTagsCache() {free(m_Cache);}
// Finds parameters for tag starting at at and fills the variables
void QueryTag(int at, int* end1, int* end2);
DECLARE_NO_COPY_CLASS(wxHtmlTagsCache)
};
//--------------------------------------------------------------------------------
// wxHtmlTag
// This represents single tag. It is used as internal structure
// by wxHtmlParser.
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlTag : public wxObject
{
DECLARE_CLASS(wxHtmlTag)
protected:
// 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)
wxHtmlTag(wxHtmlTag *parent,
const wxString& source, int pos, int end_pos,
wxHtmlTagsCache *cache,
wxHtmlEntitiesParser *entParser);
friend class wxHtmlParser;
public:
virtual ~wxHtmlTag();
wxHtmlTag *GetParent() const {return m_Parent;}
wxHtmlTag *GetFirstSibling() const;
wxHtmlTag *GetLastSibling() const;
wxHtmlTag *GetChildren() const { return m_FirstChild; }
wxHtmlTag *GetPreviousSibling() const { return m_Prev; }
wxHtmlTag *GetNextSibling() const {return m_Next; }
// Return next tag, as if tree had been flattened
wxHtmlTag *GetNextTag() const;
// Returns tag's name in uppercase.
inline wxString GetName() const {return m_Name;}
// Returns true if the tag has given parameter. Parameter
// should always be in uppercase.
// Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
bool HasParam(const wxString& par) const;
// Returns value of the param. Value is in uppercase unless it is
// enclosed with "
// Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
// <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
// (or ("WhaT.jpg") if with_commas == true)
wxString GetParam(const wxString& par, bool with_commas = false) const;
// Convenience functions:
bool GetParamAsColour(const wxString& par, wxColour *clr) const;
bool GetParamAsInt(const wxString& par, int *clr) const;
// Scans param like scanf() functions family does.
// Example : ScanParam("COLOR", "\"#%X\"", &clr);
// This is always with with_commas=false
// Returns number of scanned values
// (like sscanf() does)
// NOTE: unlike scanf family, this function only accepts
// *one* parameter !
int ScanParam(const wxString& par, const wxChar *format, void *param) const;
// Returns string containing all params.
wxString GetAllParams() const;
// return true if this there is matching ending tag
inline bool HasEnding() const {return m_End1 >= 0;}
// returns beginning position of _internal_ block of text
// See explanation (returned value is marked with *):
// bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
inline int GetBeginPos() const {return m_Begin;}
// returns ending position of _internal_ block of text.
// bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
inline int GetEndPos1() const {return m_End1;}
// returns end position 2 :
// bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
inline int GetEndPos2() const {return m_End2;}
private:
wxString m_Name;
int m_Begin, m_End1, m_End2;
wxArrayString m_ParamNames, m_ParamValues;
// DOM tree relations:
wxHtmlTag *m_Next;
wxHtmlTag *m_Prev;
wxHtmlTag *m_FirstChild, *m_LastChild;
wxHtmlTag *m_Parent;
DECLARE_NO_COPY_CLASS(wxHtmlTag)
};
#endif
#endif // _WX_HTMLTAG_H_

View file

@ -0,0 +1,651 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmlwin.h
// Purpose: wxHtmlWindow class for parsing & displaying HTML
// Author: Vaclav Slavik
// RCS-ID: $Id: htmlwin.h 53135 2008-04-12 02:31:04Z VZ $
// Copyright: (c) 1999 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMLWIN_H_
#define _WX_HTMLWIN_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/window.h"
#include "wx/scrolwin.h"
#include "wx/config.h"
#include "wx/stopwatch.h"
#include "wx/html/winpars.h"
#include "wx/html/htmlcell.h"
#include "wx/filesys.h"
#include "wx/html/htmlfilt.h"
#include "wx/filename.h"
#include "wx/bitmap.h"
class wxHtmlProcessor;
class wxHtmlWinModule;
class wxHtmlHistoryArray;
class wxHtmlProcessorList;
class WXDLLIMPEXP_FWD_HTML wxHtmlWinAutoScrollTimer;
class WXDLLIMPEXP_FWD_HTML wxHtmlCellEvent;
class WXDLLIMPEXP_FWD_HTML wxHtmlLinkEvent;
// wxHtmlWindow flags:
#define wxHW_SCROLLBAR_NEVER 0x0002
#define wxHW_SCROLLBAR_AUTO 0x0004
#define wxHW_NO_SELECTION 0x0008
#define wxHW_DEFAULT_STYLE wxHW_SCROLLBAR_AUTO
/// Enum for wxHtmlWindow::OnOpeningURL and wxHtmlWindowInterface::OnOpeningURL
enum wxHtmlOpeningStatus
{
/// Open the requested URL
wxHTML_OPEN,
/// Do not open the URL
wxHTML_BLOCK,
/// Redirect to another URL (returned from OnOpeningURL)
wxHTML_REDIRECT
};
/**
Abstract interface to a HTML rendering window (such as wxHtmlWindow or
wxHtmlListBox) that is passed to wxHtmlWinParser. It encapsulates all
communication from the parser to the window.
*/
class WXDLLIMPEXP_HTML wxHtmlWindowInterface
{
public:
/// Ctor
wxHtmlWindowInterface() {}
virtual ~wxHtmlWindowInterface() {}
/**
Called by the parser to set window's title to given text.
*/
virtual void SetHTMLWindowTitle(const wxString& title) = 0;
/**
Called when a link is clicked.
@param link information about the clicked link
*/
virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link) = 0;
/**
Called when the parser needs to open another URL (e.g. an image).
@param type Type of the URL request (e.g. image)
@param url URL the parser wants to open
@param redirect If the return value is wxHTML_REDIRECT, then the
URL to redirect to will be stored in this variable
(the pointer must never be NULL)
@return indicator of how to treat the request
*/
virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
const wxString& url,
wxString *redirect) const = 0;
/**
Converts coordinates @a pos relative to given @a cell to
physical coordinates in the window.
*/
virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
const wxPoint& pos) const = 0;
/// Returns the window used for rendering (may be NULL).
virtual wxWindow* GetHTMLWindow() = 0;
/// Returns background colour to use by default.
virtual wxColour GetHTMLBackgroundColour() const = 0;
/// Sets window's background to colour @a clr.
virtual void SetHTMLBackgroundColour(const wxColour& clr) = 0;
/// Sets window's background to given bitmap.
virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg) = 0;
/// Sets status bar text.
virtual void SetHTMLStatusText(const wxString& text) = 0;
/// Type of mouse cursor
enum HTMLCursor
{
/// Standard mouse cursor (typically an arrow)
HTMLCursor_Default,
/// Cursor shown over links
HTMLCursor_Link,
/// Cursor shown over selectable text
HTMLCursor_Text
};
/**
Returns mouse cursor of given @a type.
*/
virtual wxCursor GetHTMLCursor(HTMLCursor type) const = 0;
};
/**
Helper class that implements part of mouse handling for wxHtmlWindow and
wxHtmlListBox. Cursor changes and clicking on links are handled, text
selection is not.
*/
class WXDLLIMPEXP_HTML wxHtmlWindowMouseHelper
{
protected:
/**
Ctor.
@param iface Interface to the owner window.
*/
wxHtmlWindowMouseHelper(wxHtmlWindowInterface *iface);
/**
Virtual dtor.
It is not really needed in this case but at leats it prevents gcc from
complaining about its absence.
*/
virtual ~wxHtmlWindowMouseHelper() { }
/// Returns true if the mouse moved since the last call to HandleIdle
bool DidMouseMove() const { return m_tmpMouseMoved; }
/// Call this from EVT_MOTION event handler
void HandleMouseMoved();
/**
Call this from EVT_LEFT_UP handler (or, alternatively, EVT_LEFT_DOWN).
@param rootCell HTML cell inside which the click occured. This doesn't
have to be the leaf cell, it can be e.g. toplevel
container, but the mouse must be inside the container's
area, otherwise the event would be ignored.
@param pos Mouse position in coordinates relative to @a cell
@param event The event that triggered the call
*/
bool HandleMouseClick(wxHtmlCell *rootCell,
const wxPoint& pos, const wxMouseEvent& event);
/**
Call this from OnInternalIdle of the HTML displaying window. Handles
mouse movements and must be used together with HandleMouseMoved.
@param rootCell HTML cell inside which the click occured. This doesn't
have to be the leaf cell, it can be e.g. toplevel
container, but the mouse must be inside the container's
area, otherwise the event would be ignored.
@param pos Current mouse position in coordinates relative to
@a cell
*/
void HandleIdle(wxHtmlCell *rootCell, const wxPoint& pos);
/**
Called by HandleIdle when the mouse hovers over a cell. Default
behaviour is to do nothing.
@param cell the cell the mouse is over
@param x, y coordinates of mouse relative to the cell
*/
virtual void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
/**
Called by HandleMouseClick when the user clicks on a cell.
Default behavior is to call wxHtmlWindowInterface::OnLinkClicked()
if this cell corresponds to a hypertext link.
@param cell the cell the mouse is over
@param x, y coordinates of mouse relative to the cell
@param event The event that triggered the call
@return true if a link was clicked, false otherwise.
*/
virtual bool OnCellClicked(wxHtmlCell *cell,
wxCoord x, wxCoord y,
const wxMouseEvent& event);
protected:
// this flag indicates if the mouse moved (used by HandleIdle)
bool m_tmpMouseMoved;
// contains last link name
wxHtmlLinkInfo *m_tmpLastLink;
// contains the last (terminal) cell which contained the mouse
wxHtmlCell *m_tmpLastCell;
private:
wxHtmlWindowInterface *m_interface;
};
// ----------------------------------------------------------------------------
// 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).
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlWindow : public wxScrolledWindow,
public wxHtmlWindowInterface,
public wxHtmlWindowMouseHelper
{
DECLARE_DYNAMIC_CLASS(wxHtmlWindow)
friend class wxHtmlWinModule;
public:
wxHtmlWindow() : wxHtmlWindowMouseHelper(this) { Init(); }
wxHtmlWindow(wxWindow *parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHW_DEFAULT_STYLE,
const wxString& name = wxT("htmlWindow"))
: wxHtmlWindowMouseHelper(this)
{
Init();
Create(parent, id, pos, size, style, name);
}
virtual ~wxHtmlWindow();
bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHW_SCROLLBAR_AUTO,
const wxString& name = wxT("htmlWindow"));
// 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 occurred, true otherwise
virtual bool SetPage(const wxString& source);
// Append to current page
bool AppendToPage(const wxString& source);
// 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
virtual bool LoadPage(const wxString& location);
// Loads HTML page from file
bool LoadFile(const wxFileName& filename);
// Returns full location of opened page
wxString GetOpenedPage() const {return m_OpenedPage;}
// Returns anchor within opened page
wxString GetOpenedAnchor() const {return m_OpenedAnchor;}
// Returns <TITLE> of opened page or empty string otherwise
wxString GetOpenedPageTitle() const {return m_OpenedPageTitle;}
// 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
void SetRelatedFrame(wxFrame* frame, const wxString& format);
wxFrame* GetRelatedFrame() const {return m_RelatedFrame;}
#if wxUSE_STATUSBAR
// After(!) calling SetRelatedFrame, this sets statusbar slot where messages
// will be displayed. Default is -1 = no messages.
void SetRelatedStatusBar(int bar);
#endif // wxUSE_STATUSBAR
// Sets fonts to be used when displaying HTML page.
void SetFonts(const wxString& normal_face, const wxString& fixed_face,
const int *sizes = NULL);
// Sets font sizes to be relative to the given size or the system
// default size; use either specified or default font
void SetStandardFonts(int size = -1,
const wxString& normal_face = wxEmptyString,
const wxString& fixed_face = wxEmptyString);
// Sets space between text and window borders.
void SetBorders(int b) {m_Borders = b;}
// Sets the bitmap to use for background (currnetly it will be tiled,
// when/if we have CSS support we could add other possibilities...)
void SetBackgroundImage(const wxBitmap& bmpBg) { m_bmpBg = bmpBg; }
// 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 ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
// ...
virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
// Goes to previous/next page (in browsing history)
// Returns true if successful, false otherwise
bool HistoryBack();
bool HistoryForward();
bool HistoryCanBack();
bool HistoryCanForward();
// Resets history
void HistoryClear();
// Returns pointer to conteiners/cells structure.
// It should be used ONLY when printing
wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;}
// Adds input filter
static void AddFilter(wxHtmlFilter *filter);
// Returns a pointer to the parser.
wxHtmlWinParser *GetParser() const { return m_Parser; }
// Adds HTML processor to this instance of wxHtmlWindow:
void AddProcessor(wxHtmlProcessor *processor);
// Adds HTML processor to wxHtmlWindow class as whole:
static void AddGlobalProcessor(wxHtmlProcessor *processor);
// -- Callbacks --
// Sets the title of the window
// (depending on the information passed to SetRelatedFrame() method)
virtual void OnSetTitle(const wxString& title);
// Called when user clicked on hypertext link. Default behavior is to
// call LoadPage(loc)
virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
// Called when wxHtmlWindow wants to fetch data from an URL (e.g. when
// loading a page or loading an image). The data are downloaded if and only if
// OnOpeningURL returns true. If OnOpeningURL returns wxHTML_REDIRECT,
// it must set *redirect to the new URL
virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType WXUNUSED(type),
const wxString& WXUNUSED(url),
wxString *WXUNUSED(redirect)) const
{ return wxHTML_OPEN; }
#if wxUSE_CLIPBOARD
// Helper functions to select parts of page:
void SelectWord(const wxPoint& pos);
void SelectLine(const wxPoint& pos);
void SelectAll();
// Convert selection to text:
wxString SelectionToText() { return DoSelectionToText(m_selection); }
// Converts current page to text:
wxString ToText();
#endif // wxUSE_CLIPBOARD
virtual void OnInternalIdle();
/// Returns standard HTML cursor as used by wxHtmlWindow
static wxCursor GetDefaultHTMLCursor(HTMLCursor type);
protected:
void Init();
// 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
bool ScrollToAnchor(const wxString& anchor);
// Prepares layout (= fill m_PosX, m_PosY for fragments) based on
// actual size of window. This method also setup scrollbars
void CreateLayout();
void OnEraseBackground(wxEraseEvent& event);
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnMouseMove(wxMouseEvent& event);
void OnMouseDown(wxMouseEvent& event);
void OnMouseUp(wxMouseEvent& event);
#if wxUSE_CLIPBOARD
void OnKeyUp(wxKeyEvent& event);
void OnDoubleClick(wxMouseEvent& event);
void OnCopy(wxCommandEvent& event);
void OnClipboardEvent(wxClipboardTextEvent& event);
void OnMouseEnter(wxMouseEvent& event);
void OnMouseLeave(wxMouseEvent& event);
void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
#endif // wxUSE_CLIPBOARD
// Returns new filter (will be stored into m_DefaultFilter variable)
virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
// cleans static variables
static void CleanUpStatics();
// Returns true if text selection is enabled (wxClipboard must be available
// and wxHW_NO_SELECTION not used)
bool IsSelectionEnabled() const;
enum ClipboardType
{
Primary,
Secondary
};
// Copies selection to clipboard if the clipboard support is available
//
// returns true if anything was copied to clipboard, false otherwise
bool CopySelection(ClipboardType t = Secondary);
#if wxUSE_CLIPBOARD
// Automatic scrolling during selection:
void StopAutoScrolling();
#endif // wxUSE_CLIPBOARD
wxString DoSelectionToText(wxHtmlSelection *sel);
public:
// wxHtmlWindowInterface methods:
virtual void SetHTMLWindowTitle(const wxString& title);
virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
const wxString& url,
wxString *redirect) const;
virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
const wxPoint& pos) const;
virtual wxWindow* GetHTMLWindow();
virtual wxColour GetHTMLBackgroundColour() const;
virtual void SetHTMLBackgroundColour(const wxColour& clr);
virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
virtual void SetHTMLStatusText(const wxString& text);
virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
// implementation of SetPage()
bool DoSetPage(const wxString& source);
protected:
// 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)
wxHtmlContainerCell *m_Cell;
// 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)
wxHtmlWinParser *m_Parser;
// contains name of actualy opened page or empty string if no page opened
wxString m_OpenedPage;
// contains name of current anchor within m_OpenedPage
wxString m_OpenedAnchor;
// contains title of actualy opened page or empty string if no <TITLE> tag
wxString m_OpenedPageTitle;
// class for opening files (file system)
wxFileSystem* m_FS;
wxFrame *m_RelatedFrame;
wxString m_TitleFormat;
#if wxUSE_STATUSBAR
// frame in which page title should be displayed & number of it's statusbar
// reserved for usage with this html window
int m_RelatedStatusBar;
#endif // wxUSE_STATUSBAR
// borders (free space between text and window borders)
// defaults to 10 pixels.
int m_Borders;
// current text selection or NULL
wxHtmlSelection *m_selection;
// true if the user is dragging mouse to select text
bool m_makingSelection;
#if wxUSE_CLIPBOARD
// time of the last doubleclick event, used to detect tripleclicks
// (tripleclicks are used to select whole line):
wxMilliClock_t m_lastDoubleClick;
// helper class to automatically scroll the window if the user is selecting
// text and the mouse leaves wxHtmlWindow:
wxHtmlWinAutoScrollTimer *m_timerAutoScroll;
#endif // wxUSE_CLIPBOARD
private:
// window content for double buffered rendering:
wxBitmap *m_backBuffer;
// background image, may be invalid
wxBitmap m_bmpBg;
// variables used when user is selecting text
wxPoint m_tmpSelFromPos;
wxHtmlCell *m_tmpSelFromCell;
// if >0 contents of the window is not redrawn
// (in order to avoid ugly blinking)
int m_tmpCanDrawLocks;
// list of HTML filters
static wxList m_Filters;
// this filter is used when no filter is able to read some file
static wxHtmlFilter *m_DefaultFilter;
// html processors array:
wxHtmlProcessorList *m_Processors;
static wxHtmlProcessorList *m_GlobalProcessors;
// browser history
wxHtmlHistoryArray *m_History;
int m_HistoryPos;
// if this FLAG is false, items are not added to history
bool m_HistoryOn;
// a flag set if we need to erase background in OnPaint() (otherwise this
// is supposed to have been done in OnEraseBackground())
bool m_eraseBgInOnPaint;
// standard mouse cursors
static wxCursor *ms_cursorLink;
static wxCursor *ms_cursorText;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxHtmlWindow)
};
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTML,
wxEVT_COMMAND_HTML_CELL_CLICKED, 1000)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTML,
wxEVT_COMMAND_HTML_CELL_HOVER, 1001)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTML,
wxEVT_COMMAND_HTML_LINK_CLICKED, 1002)
END_DECLARE_EVENT_TYPES()
/*!
* Html cell window event
*/
class WXDLLIMPEXP_HTML wxHtmlCellEvent : public wxCommandEvent
{
public:
wxHtmlCellEvent() {}
wxHtmlCellEvent(wxEventType commandType, int id,
wxHtmlCell *cell, const wxPoint &pt,
const wxMouseEvent &ev)
: wxCommandEvent(commandType, id)
{
m_cell = cell;
m_pt = pt;
m_mouseEvent = ev;
m_bLinkWasClicked = false;
}
wxHtmlCell* GetCell() const { return m_cell; }
wxPoint GetPoint() const { return m_pt; }
wxMouseEvent GetMouseEvent() const { return m_mouseEvent; }
void SetLinkClicked(bool linkclicked) { m_bLinkWasClicked=linkclicked; }
bool GetLinkClicked() const { return m_bLinkWasClicked; }
// default copy ctor, assignment operator and dtor are ok
virtual wxEvent *Clone() const { return new wxHtmlCellEvent(*this); }
private:
wxHtmlCell *m_cell;
wxMouseEvent m_mouseEvent;
wxPoint m_pt;
bool m_bLinkWasClicked;
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHtmlCellEvent)
};
/*!
* Html link event
*/
class WXDLLIMPEXP_HTML wxHtmlLinkEvent : public wxCommandEvent
{
public:
wxHtmlLinkEvent() {}
wxHtmlLinkEvent(int id, const wxHtmlLinkInfo &linkinfo)
: wxCommandEvent(wxEVT_COMMAND_HTML_LINK_CLICKED, id)
{
m_linkInfo = linkinfo;
}
const wxHtmlLinkInfo &GetLinkInfo() const { return m_linkInfo; }
// default copy ctor, assignment operator and dtor are ok
virtual wxEvent *Clone() const { return new wxHtmlLinkEvent(*this); }
private:
wxHtmlLinkInfo m_linkInfo;
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHtmlLinkEvent)
};
typedef void (wxEvtHandler::*wxHtmlCellEventFunction)(wxHtmlCellEvent&);
typedef void (wxEvtHandler::*wxHtmlLinkEventFunction)(wxHtmlLinkEvent&);
#define wxHtmlCellEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHtmlCellEventFunction, &func)
#define wxHtmlLinkEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHtmlLinkEventFunction, &func)
#define EVT_HTML_CELL_CLICKED(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_HTML_CELL_CLICKED, id, wxHtmlCellEventHandler(fn))
#define EVT_HTML_CELL_HOVER(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_HTML_CELL_HOVER, id, wxHtmlCellEventHandler(fn))
#define EVT_HTML_LINK_CLICKED(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_HTML_LINK_CLICKED, id, wxHtmlLinkEventHandler(fn))
#endif // wxUSE_HTML
#endif // _WX_HTMLWIN_H_

View file

@ -0,0 +1,305 @@
/////////////////////////////////////////////////////////////////////////////
// Name: htmprint.h
// Purpose: html printing classes
// Author: Vaclav Slavik
// Created: 25/09/99
// RCS-ID: $Id: htmprint.h 62758 2009-12-01 20:21:46Z BP $
// Copyright: (c) Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_HTMPRINT_H_
#define _WX_HTMPRINT_H_
#include "wx/defs.h"
#if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
#include "wx/html/htmlcell.h"
#include "wx/html/winpars.h"
#include "wx/html/htmlfilt.h"
#include "wx/print.h"
#include "wx/printdlg.h"
#include <limits.h> // INT_MAX
//--------------------------------------------------------------------------------
// wxHtmlDCRenderer
// This class is capable of rendering HTML into specified
// portion of DC
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlDCRenderer : public wxObject
{
public:
wxHtmlDCRenderer();
virtual ~wxHtmlDCRenderer();
// Following 3 methods *must* be called before any call to Render:
// Assign DC to this render
void SetDC(wxDC *dc, double pixel_scale = 1.0);
// Sets size of output rectangle, in pixels. Note that you *can't* change
// width of the rectangle between calls to Render! (You can freely change height.)
void SetSize(int width, int height);
// Sets the text to be displayed.
// Basepath is base directory (html string would be stored there if it was in
// file). It is used to determine path for loading images, for example.
// isdir is false if basepath is filename, true if it is directory name
// (see wxFileSystem for detailed explanation)
void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = true);
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
// Sets font sizes to be relative to the given size or the system
// default size; use either specified or default font
void SetStandardFonts(int size = -1,
const wxString& normal_face = wxEmptyString,
const wxString& fixed_face = wxEmptyString);
// [x,y] is position of upper-left corner of printing rectangle (see SetSize)
// from is y-coordinate of the very first visible cell
// to is y-coordinate of the next following page break, if any
// Returned value is y coordinate of first cell than didn't fit onto page.
// Use this value as 'from' in next call to Render in order to print multiple pages
// document
// If dont_render is TRUE then nothing is rendered into DC and it only counts
// pixels and return y coord of the next page
//
// known_pagebreaks and number_of_pages are used only when counting pages;
// otherwise, their default values should be used. Their purpose is to
// support pagebreaks using a subset of CSS2's <DIV>. The <DIV> handler
// needs to know what pagebreaks have already been set so that it doesn't
// set the same pagebreak twice.
//
// CAUTION! Render() changes DC's user scale and does NOT restore it!
int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0,
int dont_render = FALSE, int to = INT_MAX);
// returns total height of the html document
// (compare Render's return value with this)
int GetTotalHeight();
private:
wxDC *m_DC;
wxHtmlWinParser *m_Parser;
wxFileSystem *m_FS;
wxHtmlContainerCell *m_Cells;
int m_MaxWidth, m_Width, m_Height;
DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer)
};
enum {
wxPAGE_ODD,
wxPAGE_EVEN,
wxPAGE_ALL
};
//--------------------------------------------------------------------------------
// wxHtmlPrintout
// This class is derived from standard wxWidgets printout class
// and is used to print HTML documents.
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlPrintout : public wxPrintout
{
public:
wxHtmlPrintout(const wxString& title = wxT("Printout"));
virtual ~wxHtmlPrintout();
void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = true);
// prepares the class for printing this html document.
// Must be called before using the class, in fact just after constructor
//
// basepath is base directory (html string would be stored there if it was in
// file). It is used to determine path for loading images, for example.
// isdir is false if basepath is filename, true if it is directory name
// (see wxFileSystem for detailed explanation)
void SetHtmlFile(const wxString &htmlfile);
// same as SetHtmlText except that it takes regular file as the parameter
void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
// sets header/footer for the document. The argument is interpreted as HTML document.
// You can use macros in it:
// @PAGENUM@ is replaced by page number
// @PAGESCNT@ is replaced by total number of pages
//
// pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
// You can set different header/footer for odd and even pages
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
// Sets font sizes to be relative to the given size or the system
// default size; use either specified or default font
void SetStandardFonts(int size = -1,
const wxString& normal_face = wxEmptyString,
const wxString& fixed_face = wxEmptyString);
void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2,
float spaces = 5);
// sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
// between text and header and/or footer
// wxPrintout stuff:
bool OnPrintPage(int page);
bool HasPage(int page);
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
bool OnBeginDocument(int startPage, int endPage);
void OnPreparePrinting();
// Adds input filter
static void AddFilter(wxHtmlFilter *filter);
// Cleanup
static void CleanUpStatics();
private:
void RenderPage(wxDC *dc, int page);
// renders one page into dc
wxString TranslateHeader(const wxString& instr, int page);
// substitute @PAGENUM@ and @PAGESCNT@ by real values
void CountPages();
// counts pages and fills m_NumPages and m_PageBreaks
private:
int m_NumPages;
//int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
wxArrayInt m_PageBreaks;
wxString m_Document, m_BasePath;
bool m_BasePathIsDir;
wxString m_Headers[2], m_Footers[2];
int m_HeaderHeight, m_FooterHeight;
wxHtmlDCRenderer *m_Renderer, *m_RendererHdr;
float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace;
// list of HTML filters
static wxList m_Filters;
DECLARE_NO_COPY_CLASS(wxHtmlPrintout)
};
//--------------------------------------------------------------------------------
// wxHtmlEasyPrinting
// This class provides very simple interface to printing
// architecture. It allows you to print HTML documents only
// with very few commands.
//
// Note : do not create this class on stack only.
// You should create an instance on app startup and
// use this instance for all printing. Why? The class
// stores page&printer settings in it.
//--------------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlEasyPrinting : public wxObject
{
public:
wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL);
virtual ~wxHtmlEasyPrinting();
bool PreviewFile(const wxString &htmlfile);
bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
// Preview file / html-text for printing
// (and offers printing)
// basepath is base directory for opening subsequent files (e.g. from <img> tag)
bool PrintFile(const wxString &htmlfile);
bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
// Print file / html-text w/o preview
void PageSetup();
// pop up printer or page setup dialog
void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
// sets header/footer for the document. The argument is interpreted as HTML document.
// You can use macros in it:
// @PAGENUM@ is replaced by page number
// @PAGESCNT@ is replaced by total number of pages
//
// pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
// You can set different header/footer for odd and even pages
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = 0);
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used)
// Sets font sizes to be relative to the given size or the system
// default size; use either specified or default font
void SetStandardFonts(int size = -1,
const wxString& normal_face = wxEmptyString,
const wxString& fixed_face = wxEmptyString);
wxPrintData *GetPrintData();
wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
// return page setting data objects.
// (You can set their parameters.)
#if wxABI_VERSION >= 20805
wxWindow* GetParentWindow() const { return m_ParentWindow; }
// get the parent window
void SetParentWindow(wxWindow* window) { m_ParentWindow = window; }
// set the parent window
#endif
#if wxABI_VERSION >= 20811
const wxString& GetName() const { return m_Name; }
// get the printout name
void SetName(const wxString& name) { m_Name = name; }
// set the printout name
#endif
protected:
virtual wxHtmlPrintout *CreatePrintout();
virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
virtual bool DoPrint(wxHtmlPrintout *printout);
private:
wxPrintData *m_PrintData;
wxPageSetupDialogData *m_PageSetupData;
wxString m_Name;
int m_FontsSizesArr[7];
int *m_FontsSizes;
wxString m_FontFaceFixed, m_FontFaceNormal;
enum FontMode
{
FontMode_Explicit,
FontMode_Standard
};
FontMode m_fontMode;
wxString m_Headers[2], m_Footers[2];
wxWindow *m_ParentWindow;
DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting)
};
#endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
#endif // _WX_HTMPRINT_H_

View file

@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////
// Name: m_templ.h
// Purpose: Modules template file
// Author: Vaclav Slavik
// RCS-ID: $Id: m_templ.h 30098 2004-10-26 10:32:38Z VS $
// Copyright: (c) 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 _WX_M_TEMPL_H_
#define _WX_M_TEMPL_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/html/winpars.h"
#define TAG_HANDLER_BEGIN(name,tags) \
class wxHTML_Handler_##name : public wxHtmlWinTagHandler \
{ \
public: \
wxString GetSupportedTags() {return wxT(tags);}
#define TAG_HANDLER_VARS \
private:
#define TAG_HANDLER_CONSTR(name) \
public: \
wxHTML_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 wxHTML_Module##name : public wxHtmlTagsModule \
{ \
DECLARE_DYNAMIC_CLASS(wxHTML_Module##name ) \
public: \
void FillHandlersTable(wxHtmlWinParser *parser) \
{
#define TAGS_MODULE_ADD(handler) \
parser->AddTagHandler(new wxHTML_Handler_##handler);
#define TAGS_MODULE_END(name) \
} \
}; \
IMPLEMENT_DYNAMIC_CLASS(wxHTML_Module##name , wxHtmlTagsModule)
#endif
#endif

View file

@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/html/webkit.h
// Purpose: wxWebKitCtrl - embeddable web kit control
// Author: Jethro Grassie / Kevin Ollivier
// Modified by:
// Created: 2004-4-16
// RCS-ID: $Id: webkit.h 53798 2008-05-28 06:12:34Z RD $
// Copyright: (c) Jethro Grassie / Kevin Ollivier
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WEBKIT_H
#define _WX_WEBKIT_H
#if wxUSE_WEBKIT
#if !defined(__WXMAC__) && !defined(__WXCOCOA__)
#error "wxWebKitCtrl not implemented for this platform"
#endif
#include "wx/control.h"
// ----------------------------------------------------------------------------
// Web Kit Control
// ----------------------------------------------------------------------------
class wxWebKitCtrl : public wxControl
{
public:
DECLARE_DYNAMIC_CLASS(wxWebKitCtrl)
wxWebKitCtrl() {};
wxWebKitCtrl(wxWindow *parent,
wxWindowID winID,
const wxString& strURL,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxT("webkitctrl"))
{
Create(parent, winID, strURL, pos, size, style, validator, name);
};
bool Create(wxWindow *parent,
wxWindowID winID,
const wxString& strURL,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxT("webkitctrl"));
virtual ~wxWebKitCtrl();
void LoadURL(const wxString &url);
bool CanGoBack();
bool CanGoForward();
bool GoBack();
bool GoForward();
void Reload();
void Stop();
bool CanGetPageSource();
wxString GetPageSource();
void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
wxString GetPageURL(){ return m_currentURL; }
void SetPageTitle(const wxString& title) { m_pageTitle = title; }
wxString GetPageTitle(){ return m_pageTitle; }
// since these worked in 2.6, add wrappers
void SetTitle(const wxString& title) { SetPageTitle(title); }
wxString GetTitle() { return GetPageTitle(); }
wxString GetSelection();
bool CanIncreaseTextSize();
void IncreaseTextSize();
bool CanDecreaseTextSize();
void DecreaseTextSize();
void Print(bool showPrompt=FALSE);
void MakeEditable(bool enable=TRUE);
bool IsEditable();
wxString RunScript(const wxString& javascript);
void SetScrollPos(int pos);
int GetScrollPos();
//we need to resize the webview when the control size changes
void OnSize(wxSizeEvent &event);
void OnMove(wxMoveEvent &event);
void OnMouseEvents(wxMouseEvent &event);
protected:
DECLARE_EVENT_TABLE()
void MacVisibilityChanged();
private:
wxWindow *m_parent;
wxWindowID m_windowID;
wxString m_currentURL;
wxString m_pageTitle;
struct objc_object *m_webView;
// we may use this later to setup our own mouse events,
// so leave it in for now.
void* m_webKitCtrlEventHandler;
//It should be WebView*, but WebView is an Objective-C class
//TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
};
// ----------------------------------------------------------------------------
// Web Kit Events
// ----------------------------------------------------------------------------
enum {
wxWEBKIT_STATE_START = 1,
wxWEBKIT_STATE_NEGOTIATING = 2,
wxWEBKIT_STATE_REDIRECTING = 4,
wxWEBKIT_STATE_TRANSFERRING = 8,
wxWEBKIT_STATE_STOP = 16,
wxWEBKIT_STATE_FAILED = 32
};
enum {
wxWEBKIT_NAV_LINK_CLICKED = 1,
wxWEBKIT_NAV_BACK_NEXT = 2,
wxWEBKIT_NAV_FORM_SUBMITTED = 4,
wxWEBKIT_NAV_RELOAD = 8,
wxWEBKIT_NAV_FORM_RESUBMITTED = 16,
wxWEBKIT_NAV_OTHER = 32
};
class wxWebKitBeforeLoadEvent : public wxCommandEvent
{
DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent )
public:
bool IsCancelled() { return m_cancelled; }
void Cancel(bool cancel = true) { m_cancelled = cancel; }
wxString GetURL() { return m_url; }
void SetURL(const wxString& url) { m_url = url; }
void SetNavigationType(int navType) { m_navType = navType; }
int GetNavigationType() { return m_navType; }
wxWebKitBeforeLoadEvent( wxWindow* win = (wxWindow*) NULL );
wxEvent *Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); }
protected:
bool m_cancelled;
wxString m_url;
int m_navType;
};
class wxWebKitStateChangedEvent : public wxCommandEvent
{
DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent )
public:
int GetState() { return m_state; }
void SetState(const int state) { m_state = state; }
wxString GetURL() { return m_url; }
void SetURL(const wxString& url) { m_url = url; }
wxWebKitStateChangedEvent( wxWindow* win = (wxWindow*) NULL );
wxEvent *Clone(void) const { return new wxWebKitStateChangedEvent(*this); }
protected:
int m_state;
wxString m_url;
};
#if wxABI_VERSION >= 20808
class wxWebKitNewWindowEvent : public wxCommandEvent
{
DECLARE_DYNAMIC_CLASS( wxWebViewNewWindowEvent )
public:
wxString GetURL() const { return m_url; }
void SetURL(const wxString& url) { m_url = url; }
wxString GetTargetName() const { return m_targetName; }
void SetTargetName(const wxString& name) { m_targetName = name; }
wxWebKitNewWindowEvent( wxWindow* win = (wxWindow*)(NULL));
wxEvent *Clone(void) const { return new wxWebKitNewWindowEvent(*this); }
private:
wxString m_url;
wxString m_targetName;
};
#endif
typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction)(wxWebKitStateChangedEvent&);
typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction)(wxWebKitBeforeLoadEvent&);
typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction)(wxWebKitNewWindowEvent&);
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_BEFORE_LOAD, wxID_ANY)
DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_STATE_CHANGED, wxID_ANY)
DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_NEW_WINDOW, wxID_ANY)
END_DECLARE_EVENT_TYPES()
#define EVT_WEBKIT_STATE_CHANGED(func) \
DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \
wxID_ANY, \
wxID_ANY, \
(wxObjectEventFunction) \
(wxWebKitStateChangedEventFunction) & func, \
(wxObject *) NULL ),
#define EVT_WEBKIT_BEFORE_LOAD(func) \
DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \
wxID_ANY, \
wxID_ANY, \
(wxObjectEventFunction) \
(wxWebKitBeforeLoadEventFunction) & func, \
(wxObject *) NULL ),
#define EVT_WEBKIT_NEW_WINDOW(func) \
DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \
wxID_ANY, \
wxID_ANY, \
(wxObjectEventFunction) \
(wxWebKitNewWindowEventFunction) & func, \
(wxObject *) NULL ),
#endif // wxUSE_WEBKIT
#endif
// _WX_WEBKIT_H_

View file

@ -0,0 +1,292 @@
/////////////////////////////////////////////////////////////////////////////
// Name: winpars.h
// Purpose: wxHtmlWinParser class (parser to be used with wxHtmlWindow)
// Author: Vaclav Slavik
// RCS-ID: $Id: winpars.h 59260 2009-03-02 10:43:00Z VS $
// Copyright: (c) 1999 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WINPARS_H_
#define _WX_WINPARS_H_
#include "wx/defs.h"
#if wxUSE_HTML
#include "wx/module.h"
#include "wx/font.h"
#include "wx/html/htmlpars.h"
#include "wx/html/htmlcell.h"
#include "wx/encconv.h"
class WXDLLIMPEXP_FWD_HTML wxHtmlWindow;
class WXDLLIMPEXP_FWD_HTML wxHtmlWindowInterface;
class WXDLLIMPEXP_FWD_HTML wxHtmlWinParser;
class WXDLLIMPEXP_FWD_HTML wxHtmlWinTagHandler;
class WXDLLIMPEXP_FWD_HTML wxHtmlTagsModule;
struct wxHtmlWinParser_TextParsingState;
//--------------------------------------------------------------------------------
// 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 WXDLLIMPEXP_HTML wxHtmlWinParser : public wxHtmlParser
{
DECLARE_ABSTRACT_CLASS(wxHtmlWinParser)
friend class wxHtmlWindow;
public:
wxHtmlWinParser(wxHtmlWindowInterface *wndIface = NULL);
virtual ~wxHtmlWinParser();
virtual void InitParser(const wxString& source);
virtual void DoneParser();
virtual wxObject* GetProduct();
virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
// Set's the DC used for parsing. If SetDC() is not called,
// parsing won't proceed
virtual void SetDC(wxDC *dc, double pixel_scale = 1.0)
{ m_DC = dc; m_PixelScale = pixel_scale; }
wxDC *GetDC() {return m_DC;}
double GetPixelScale() {return m_PixelScale;}
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...()
// returns interface to the rendering window
wxHtmlWindowInterface *GetWindowInterface() {return m_windowInterface;}
#if WXWIN_COMPATIBILITY_2_6
// deprecated, use GetWindowInterface()->GetHTMLWindow() instead
wxDEPRECATED( wxHtmlWindow *GetWindow() );
#endif
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
// Sets font sizes to be relative to the given size or the system
// default size; use either specified or default font
void SetStandardFonts(int size = -1,
const wxString& normal_face = wxEmptyString,
const wxString& fixed_face = wxEmptyString);
// Adds tags module. see wxHtmlTagsModule for details.
static void AddModule(wxHtmlTagsModule *module);
static void RemoveModule(wxHtmlTagsModule *module);
// parsing-related methods. These methods are called by tag handlers:
// Returns pointer to actual container. Common use in tag handler is :
// m_WParser->GetContainer()->InsertCell(new ...);
wxHtmlContainerCell *GetContainer() const {return m_Container;}
// opens new container. This container is sub-container of opened
// container. Sets GetContainer to newly created container
// and returns it.
wxHtmlContainerCell *OpenContainer();
// works like OpenContainer except that new container is not created
// but c is used. You can use this to directly set actual container
wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
// closes the container and sets actual Container to upper-level
// container
wxHtmlContainerCell *CloseContainer();
int GetFontSize() const {return m_FontSize;}
void SetFontSize(int 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;}
wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;}
void SetFontFace(const wxString& face);
int GetAlign() const {return m_Align;}
void SetAlign(int a) {m_Align = a;}
wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
void SetScriptMode(wxHtmlScriptMode mode) { m_ScriptMode = mode; }
long GetScriptBaseline() const { return m_ScriptBaseline; }
void SetScriptBaseline(long base) { m_ScriptBaseline = base; }
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 wxHtmlLinkInfo& GetLink() const { return m_Link; }
void SetLink(const wxHtmlLinkInfo& link);
// applies current parser state (link, sub/supscript, ...) to given cell
void ApplyStateToCell(wxHtmlCell *cell);
#if !wxUSE_UNICODE
void SetInputEncoding(wxFontEncoding enc);
wxFontEncoding GetInputEncoding() const { return m_InputEnc; }
wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; }
wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; }
#endif
// creates font depending on m_Font* members.
virtual wxFont* CreateCurrentFont();
#if wxABI_VERSION >= 20808
enum WhitespaceMode
{
Whitespace_Normal, // normal mode, collapse whitespace
Whitespace_Pre // inside <pre>, keep whitespace as-is
};
// change the current whitespace handling mode
void SetWhitespaceMode(WhitespaceMode mode);
WhitespaceMode GetWhitespaceMode() const;
#endif // wxABI_VERSION >= 20808
protected:
virtual void AddText(const wxChar* txt);
private:
void FlushWordBuf(wxChar *temp, int& templen, wxChar nbsp);
void AddWord(wxHtmlWordCell *c);
void AddWord(const wxString& word);
void AddPreBlock(const wxString& text);
bool m_tmpLastWasSpace;
wxChar *m_tmpStrBuf;
size_t m_tmpStrBufSize;
// temporary variables used by AddText
wxHtmlWindowInterface *m_windowInterface;
// window we're parsing for
double m_PixelScale;
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;
// current 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.
wxHtmlLinkInfo 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
wxHtmlScriptMode m_ScriptMode;
// current script mode (sub/sup/normal)
long m_ScriptBaseline;
// current sub/supscript base
wxFont* m_FontsTable[2][2][2][2][7];
wxString m_FontsFacesTable[2][2][2][2][7];
#if !wxUSE_UNICODE
wxFontEncoding m_FontsEncTable[2][2][2][2][7];
#endif
// 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 6 (remapped from html sizes 1 to 7)
// 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;
// html font sizes and faces of fixed and proportional fonts
#if !wxUSE_UNICODE
wxFontEncoding m_InputEnc, m_OutputEnc;
// I/O font encodings
wxEncodingConverter *m_EncConv;
#endif
// NB: this pointer replaces m_lastWordCell pointer in wx<=2.8.7; this
// way, wxHtmlWinParser remains ABI compatible with older versions
// despite addition of two fields in wxHtmlWinParser_TextParsingState
wxHtmlWinParser_TextParsingState *m_textParsingState;
DECLARE_NO_COPY_CLASS(wxHtmlWinParser)
};
//-----------------------------------------------------------------------------
// wxHtmlWinTagHandler
// This is basicly wxHtmlTagHandler except
// it is extended with protected member m_Parser pointing to
// the wxHtmlWinParser object
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler
{
DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler)
public:
wxHtmlWinTagHandler() : wxHtmlTagHandler() {}
virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;}
protected:
wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted
DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler)
};
//----------------------------------------------------------------------------
// 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 WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule
{
DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule)
public:
wxHtmlTagsModule() : wxModule() {}
virtual bool OnInit();
virtual void OnExit();
// This is called by wxHtmlWinParser.
// The method must simply call parser->AddTagHandler(new
// <handler_class_name>); for each handler
virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { }
};
#endif
#endif // _WX_WINPARS_H_