Alex Fenton wrote:> Attached is a patch to add HtmlWindow and some of its friends,
> including HtmlEasyPrinting. Also a sample.
Wow! Great stuff. I''ll try this out later.
Roy>
> I haven''t tried exposing the parsing and rendering API yet to
allow
> custom tags etc - I just wanted to get basic HTML and the 0.6.0
> compatibility classes first. There may well be some quite easy classes
> left.
>
> There''s one ugly kludge to get OnOpeningURL to compile - it just
means
> that this method can''t for now be overridden in ruby subclasses.
Apart
> from that, all seems to work well.
>
> I''d like to check in some stuff from last week: client_data and
> DestroyEvent. If someone has a few minutes in the next few days
> perhaps they could confirm that these at least compile on their platform.
>
> cheers
> alex
>
>
> ------------------------------------------------------------------------
>
> Index: wxruby2/swig/classes/HtmlCell.i
> ==================================================================> ---
wxruby2/swig/classes/HtmlCell.i (revision 0)
> +++ wxruby2/swig/classes/HtmlCell.i (revision 0)
> @@ -0,0 +1,14 @@
> +# Copyright 2004-2006 by Kevin Smith
> +# released under the MIT-style wxruby2 license
> +
> +%include "../common.i"
> +
> +%module(directors="1") wxHtmlCell
> +
> +%{
> +#include <wx/html/htmlcell.h>
> +%}
> +
> +%import "include/wxObject.h"
> +
> +%include "include/wxHtmlCell.h"
> Index: wxruby2/swig/classes/HtmlContainerCell.i
> ==================================================================> ---
wxruby2/swig/classes/HtmlContainerCell.i (revision 0)
> +++ wxruby2/swig/classes/HtmlContainerCell.i (revision 0)
> @@ -0,0 +1,15 @@
> +# Copyright 2004-2006 by Kevin Smith
> +# released under the MIT-style wxruby2 license
> +
> +%include "../common.i"
> +
> +%module(directors="1") wxHtmlContainerCell
> +
> +%{
> +#include <wx/html/htmlcell.h>
> +%}
> +
> +%import "include/wxObject.h"
> +%import "include/wxHtmlCell.h"
> +
> +%include "include/wxHtmlContainerCell.h"
> Index: wxruby2/swig/classes/HtmlEasyPrinting.i
> ==================================================================> ---
wxruby2/swig/classes/HtmlEasyPrinting.i (revision 0)
> +++ wxruby2/swig/classes/HtmlEasyPrinting.i (revision 0)
> @@ -0,0 +1,15 @@
> +# Copyright 2004-2006 by Kevin Smith
> +# released under the MIT-style wxruby2 license
> +
> +%include "../common.i"
> +
> +%module(directors="1") wxHtmlEasyPrinting
> +
> +%{
> +#include <wx/html/htmprint.h>
> +%}
> +
> +
> +%import "include/wxObject.h"
> +
> +%include "include/wxHtmlEasyPrinting.h"
> Index: wxruby2/swig/classes/HtmlLinkInfo.i
> ==================================================================> ---
wxruby2/swig/classes/HtmlLinkInfo.i (revision 0)
> +++ wxruby2/swig/classes/HtmlLinkInfo.i (revision 0)
> @@ -0,0 +1,18 @@
> +# Copyright 2004-2006 by Kevin Smith
> +# released under the MIT-style wxruby2 license
> +
> +%include "../common.i"
> +
> +%module(directors="1") wxHtmlLinkInfo
> +
> +%{
> +#include <wx/html/htmlcell.h>
> +%}
> +
> +// for some reason this ignore doesn''t actually ignore
> +// so then there is a problem b/c the ''redirect'' string
isn''t
> +// mapped as output
> +
> +%import "include/wxObject.h"
> +
> +%include "include/wxHtmlLinkInfo.h"
> Index: wxruby2/swig/classes/HtmlWidgetCell.i
> ==================================================================> ---
wxruby2/swig/classes/HtmlWidgetCell.i (revision 0)
> +++ wxruby2/swig/classes/HtmlWidgetCell.i (revision 0)
> @@ -0,0 +1,15 @@
> +# Copyright 2004-2006 by Kevin Smith
> +# released under the MIT-style wxruby2 license
> +
> +%include "../common.i"
> +
> +%module(directors="1") wxHtmlWidgetCell
> +
> +%{
> +#include <wx/html/htmlcell.h>
> +%}
> +
> +%import "include/wxObject.h"
> +%import "include/wxHtmlCell.h"
> +
> +%include "include/wxHtmlWidgetCell.h"
> Index: wxruby2/swig/classes/HtmlWindow.i
> ==================================================================> ---
wxruby2/swig/classes/HtmlWindow.i (revision 0)
> +++ wxruby2/swig/classes/HtmlWindow.i (revision 0)
> @@ -0,0 +1,41 @@
> +# Copyright 2004-2006 by Kevin Smith
> +# released under the MIT-style wxruby2 license
> +
> +%include "../common.i"
> +
> +%module(directors="1") wxHtmlWindow
> +
> +%{
> +#include <wx/html/htmlwin.h>
> +%}
> +
> +// enums for wxHtmlWindow::OnOpeningURL
> +enum wxHtmlOpeningStatus
> +{
> + wxHTML_OPEN,
> + wxHTML_BLOCK,
> + wxHTML_REDIRECT
> +};
> +
> +// implement in ruby
> +%ignore wxHtmlWindow::LoadFile;
> +
> +// OnOpeningURL: for some reason this ignore doesn''t actually
ignore
> +// %ignore wxHtmlWindow::OnOpeningURL(wxHtmlURLType type , const
wxString& url , wxString * redirect ) const;
> +
> +// TODO: fix typemaps so that on_opening_url will be called in subclass
method.
> +// The default typemap for WxString. * is not correct for this method, but
ignore doesn''t seem to be working (SWIG 1.3.29). The typemaps below
just stop a compile error
> +%typemap(in, numinputs=0) wxString * redirect "//*$1 = *$1;";
> +%typemap(directorargin) wxString * redirect "$1 = obj2;";
> +%typemap(directorargout, fragment="output_helper") wxString *
redirect {
> + //VALUE o = rb_str_new2((const char*)$1->mb_str());
> + //$result = output_helper($result, o);
> +}
> +
> +%import "include/wxObject.h"
> +%import "include/wxEvtHandler.h"
> +%import "include/wxWindow.h"
> +%import "include/wxPanel.h"
> +%import "include/wxScrolledWindow.h"
> +
> +%include "include/wxHtmlWindow.h"
> Index: wxruby2/swig/classes/include/wxHtmlCell.h
> ==================================================================> ---
wxruby2/swig/classes/include/wxHtmlCell.h (revision 718)
> +++ wxruby2/swig/classes/include/wxHtmlCell.h (working copy)
> @@ -13,182 +13,25 @@
> */
>
> wxHtmlCell() ;
> - /**
> - * \brief This method is 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.
> -
> -Returns true if pagebreak was modified, false otherwise
> -
> -Usage:
> - * \param int *
> - */
> -
> virtual bool AdjustPagebreak(int * pagebreak ) ;
> - /**
> - * \brief Renders the cell.
> - * \param wxDC&
> - * \param int
> - * \param int
> - * \param int
> - * \param int
> - */
> -
> - virtual void Draw(wxDC& dc , int x , int y , int view_y1 , int
view_y2 ) ;
> - /**
> - * \brief This method is called instead of when the
> -cell is certainly out of the screen (and thus invisible). This is not
> -nonsense - some tags (like
> -or font setter) must be drawn even if they are invisible!
> - * \param wxDC&
> - * \param int
> - * \param int
> - */
> -
> - virtual void DrawInvisible(wxDC& dc , int x , int y ) ;
> - /**
> - * \brief Returns pointer to itself if this cell matches condition (or if
any of the cells
> -following in the list matches), NULL otherwise.
> -(In other words if you call top-level container''s Find it will
> -return pointer to the first cell that matches the condition)
> -
> -It is recommended way how to obtain pointer to particular cell or
> -to cell of some type (e.g. wxHtmlAnchorCell reacts on
> -wxHTML_COND_ISANCHOR condition)
> -
> -
> -
> -
> -
> -
> -
> -\wxheading{Defined conditions}
> - * \param int
> - * \param const void*
> - */
> -
> + 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 const wxHtmlCell* Find(int condition , const void* param ) ;
> - /**
> - * \brief Returns descent value of the cell (m_Descent member).
> -\helponly{See explanation:
> -
> -\image{}{descent.bmp}
> -}
> - */
> -
> int GetDescent() const;
> - /**
> - * \brief Returns height of the cell (m_Height member).
> - */
> -
> int GetHeight() const;
> - /**
> - * \brief Returns unique cell identifier if there is any, empty string
otherwise.
> - */
> -
> virtual wxString GetId() const;
> - /**
> - * \brief Returns hypertext link if associated with this cell or NULL
otherwise.
> -See .
> -(Note: this makes sense only for visible tags).
> - * \param int
> - * \param int
> - */
> -
> virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
> - /**
> - * \brief Returns pointer to the next cell in list (see htmlcell.h if
you''re
> -interested in details).
> - */
> -
> wxHtmlCell* GetNext() const;
> - /**
> - * \brief Returns pointer to parent container.
> - */
> -
> wxHtmlContainerCell* GetParent() const;
> - /**
> - * \brief Returns X position within parent (the value is relative to
parent''s
> -upper left corner). The returned value is meaningful only if
> -parent''s was called before!
> - */
> -
> int GetPosX() const;
> - /**
> - * \brief Returns Y position within parent (the value is relative to
parent''s
> -upper left corner). The returned value is meaningful only if
> -parent''s was called before!
> - */
> -
> int GetPosY() const;
> - /**
> - * \brief Returns width of the cell (m_Width member).
> - */
> -
> int GetWidth() const;
> - /**
> - * \brief This method performs two actions:
> -
> -\begin{enumerate}\itemsep=0pt
> -\item adjusts the cell''s width according to the fact that maximal
possible width is .
> -(this has sense when working with horizontal lines, tables etc.)
> -\item prepares layout (=fill-in m_PosX, m_PosY (and sometimes m_Height)
members)
> -based on actual width
> -\end{enumerate}
> -
> -It must be called before displaying cells structure because
> -m_PosX and m_PosY are undefined (or invalid)
> -before calling Layout.
> - * \param int
> - */
> -
> virtual void Layout(int w ) ;
> - /**
> - * \brief This function is simple event handler. Each time the user
clicks mouse button over a cell
> -within this method of that cell is called. Default behavior is
> -that it calls .
> - * \param wxWindow*
> - * \param int
> - * \param int
> - * \param const wxMouseEvent&
> - */
> -
> virtual void OnMouseClick(wxWindow* parent , int x , int y , const
wxMouseEvent& event ) ;
> - /**
> - * \brief Sets unique cell identifier. Default value is no identifier,
i.e. empty string.
> - * \param const wxString&
> - */
> -
> void SetId(const wxString& id ) ;
> - /**
> - * \brief Sets the hypertext link associated with this cell. (Default
value
> -is ("", "") (no link))
> - * \param const wxHtmlLinkInfo&
> - */
> -
> void SetLink(const wxHtmlLinkInfo& link ) ;
> - /**
> - * \brief Sets the next cell in the list. This shouldn''t be
called by user - it is
> -to be used only by .
> - * \param wxHtmlCell
> - */
> -
> void SetNext(wxHtmlCell *cell ) ;
> - /**
> - * \brief Sets parent container of this cell. This is called from
> - .
> - * \param wxHtmlContainerCell
> - */
> -
> void SetParent(wxHtmlContainerCell *p ) ;
> - /**
> - * \brief Sets the cell''s position within parent container.
> - * \param int
> - * \param int
> - */
> -
> void SetPos(int x , int y ) ;
> };
>
> Index: wxruby2/swig/classes/include/wxHtmlContainerCell.h
> ==================================================================> ---
wxruby2/swig/classes/include/wxHtmlContainerCell.h (revision 718)
> +++ wxruby2/swig/classes/include/wxHtmlContainerCell.h (working copy)
> @@ -8,148 +8,22 @@
> class wxHtmlContainerCell : public wxHtmlCell
> {
> public:
> - /**
> - * \brief Constructor. is pointer to parent container or NULL.
> - * \param wxHtmlContainerCell
> - */
> -
> wxHtmlContainerCell(wxHtmlContainerCell *parent ) ;
> - /**
> - * \brief Returns container''s horizontal alignment.
> - */
> -
> int GetAlignHor() const;
> - /**
> - * \brief Returns container''s vertical alignment.
> - */
> -
> int GetAlignVer() const;
> - /**
> - * \brief Returns the background colour of the container or if no
background
> -colour is set.
> - */
> -
> wxColour GetBackgroundColour() ;
> - /**
> - * \brief Returns pointer to the first cell in the list.
> -You can then use wxHtmlCell''s GetNext method to obtain pointer to
the next
> -cell in list.
> -
> - This shouldn''t be used by the end user. If you need some way of
> -finding particular cell in the list, try method
> -instead.
> - */
> -
> wxHtmlCell* GetFirstCell() ;
> - /**
> - * \brief Returns the indentation. is one of the constants.
> -
> - You must call
> -with same parameter in order to correctly interpret the returned integer
value.
> -It is NOT always in pixels!
> - * \param int
> - */
> -
> int GetIndent(int ind ) const;
> - /**
> - * \brief Returns the units of indentation for where is one
> -of the constants.
> - * \param int
> - */
> -
> int GetIndentUnits(int ind ) const;
> - /**
> - * \brief Inserts new cell into the container.
> - * \param wxHtmlCell
> - */
> -
> void InsertCell(wxHtmlCell *cell ) ;
> - /**
> - * \brief Sets the container''s alignment (both horizontal and
vertical) according to
> -the values stored in . (Tags parameter is extracted.) In fact
> -it is only a front-end to
> -and .
> - * \param const wxHtmlTag&
> - */
> -
> void SetAlign(const wxHtmlTag& tag ) ;
> - /**
> - * \brief Sets the container''s . During
> -each line is aligned according to value.
> - * \param int
> - */
> -
> void SetAlignHor(int al ) ;
> - /**
> - * \brief Sets the container''s . This is per-line alignment!
> - * \param int
> - */
> -
> void SetAlignVer(int al ) ;
> - /**
> - * \brief Sets the background colour for this container.
> - * \param const wxColour&
> - */
> -
> void SetBackgroundColour(const wxColour& clr ) ;
> - /**
> - * \brief Sets the border (frame) colours. A border is a rectangle around
the container.
> - * \param const wxColour&
> - * \param const wxColour&
> - */
> -
> void SetBorder(const wxColour& clr1 , const wxColour& clr2 ) ;
> - /**
> - * \brief Sets the indentation (free space between borders of container
and subcells).
> - * \param int
> - * \param int
> - * \param int
> - */
> -
> void SetIndent(int i , int what , int units = wxHTML_UNITS_PIXELS) ;
> - /**
> - * \brief Sets minimal height of the container.
> -
> -When container''s is called, m_Height
> -is set depending on layout of subcells to the height of area covered
> -by layed-out subcells. Calling this method guarantees you that the height
> -of container is never smaller than - even if the subcells cover
> -much smaller area.
> - * \param int
> - * \param int
> - */
> -
> void SetMinHeight(int h , int align = wxHTML_ALIGN_TOP) ;
> - /**
> - * \brief
> - * \param int
> - * \param int
> - */
> -
> void SetWidthFloat(int w , int units ) ;
> - /**
> - * \brief Sets floating width adjustment.
> -
> -The normal behaviour of container is that its width is the same as the
width of
> -parent container (and thus you can have only one sub-container per line).
> -You can change this by setting FWA.
> -
> - is number of real pixels that equals to 1 HTML pixel.
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -\pythonnote{The second form of this method is named
> -SetWidthFloatFromTag in wxPython.}
> - * \param const wxHtmlTag&
> - * \param double
> - */
> -
> void SetWidthFloat(const wxHtmlTag& tag , double pixel_scale =
1.0) ;
> };
>
> Index: wxruby2/swig/classes/include/wxHtmlEasyPrinting.h
> ==================================================================> ---
wxruby2/swig/classes/include/wxHtmlEasyPrinting.h (revision 718)
> +++ wxruby2/swig/classes/include/wxHtmlEasyPrinting.h (working copy)
> @@ -8,99 +8,19 @@
> class wxHtmlEasyPrinting : public wxObject
> {
> public:
> - /**
> - * \brief Constructor.
> - * \param const wxString&
> - * \param wxWindow*
> - */
>
> wxHtmlEasyPrinting(const wxString& name =
wxT("Printing"), wxWindow* parentWindow = NULL) ;
> - /**
> - * \brief Preview HTML file.
> -
> -Returns false in case of error -- call
> - to get detailed
> -information about the kind of the error.
> - * \param const wxString&
> - */
> -
> bool PreviewFile(const wxString& htmlfile ) ;
> - /**
> - * \brief Preview HTML text (not file!).
> -
> -Returns false in case of error -- call
> - to get detailed
> -information about the kind of the error.
> - * \param const wxString&
> - * \param const wxString&
> - */
> -
> bool PreviewText(const wxString& htmltext , const wxString&
basepath = wxEmptyString) ;
> - /**
> - * \brief Print HTML file.
> -
> -Returns false in case of error -- call
> - to get detailed
> -information about the kind of the error.
> - * \param const wxString&
> - */
> -
> bool PrintFile(const wxString& htmlfile ) ;
> - /**
> - * \brief Print HTML text (not file!).
> -
> -Returns false in case of error -- call
> - to get detailed
> -information about the kind of the error.
> - * \param const wxString&
> - * \param const wxString&
> - */
> -
> bool PrintText(const wxString& htmltext , const wxString&
basepath = wxEmptyString) ;
> - /**
> - * \brief Display printer setup dialog and allows the user to modify
settings.
> - */
> -
> - void PrinterSetup() ;
> - /**
> - * \brief Display page setup dialog and allows the user to modify
settings.
> - */
> -
> + // Not defined in 2.6.3 headers
> + // void PrinterSetup() ;
> void PageSetup() ;
> - /**
> - * \brief Sets fonts. See for
> -detailed description.
> - * \param wxString
> - * \param wxString
> - * \param const int
> - */
> -
> void SetFonts(wxString normal_face , wxString fixed_face , const int
*sizes = NULL) ;
> - /**
> - * \brief Set page header.
> - * \param const wxString&
> - * \param int
> - */
> -
> void SetHeader(const wxString& header , int pg = wxPAGE_ALL) ;
> - /**
> - * \brief Set page footer.
> - * \param const wxString&
> - * \param int
> - */
> -
> void SetFooter(const wxString& footer , int pg = wxPAGE_ALL) ;
> - /**
> - * \brief Returns pointer to instance used by this class. You can
> -set its parameters (via SetXXXX methods).
> - */
> -
> wxPrintData* GetPrintData() ;
> - /**
> - * \brief Returns a pointer to instance used by
> -this class. You can set its parameters (via SetXXXX methods).
> - */
> -
> wxPageSetupDialogData* GetPageSetupData() ;
> };
>
> Index: wxruby2/swig/classes/include/wxHtmlWindow.h
> ==================================================================> ---
wxruby2/swig/classes/include/wxHtmlWindow.h (revision 718)
> +++ wxruby2/swig/classes/include/wxHtmlWindow.h (working copy)
> @@ -8,236 +8,33 @@
> class wxHtmlWindow : public wxScrolledWindow
> {
> public:
> - /**
> - * \brief Default constructor.
> - */
> -
> wxHtmlWindow() ;
> - /**
> - * \brief Constructor. The parameters are the same as for the
constructor.
> - * \param wxWindow
> - * \param wxWindowID
> - * \param const wxPoint&
> - * \param const wxSize&
> - * \param long
> - * \param const wxString&
> - */
> -
> wxHtmlWindow(wxWindow *parent , wxWindowID id = -1, const
wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxHW_SCROLLBAR_AUTO, const wxString& name =
wxT("htmlWindow")) ;
> - /**
> - * \brief Adds to the static list of available
> -filters. These filters are present by default:
> - * \param wxHtmlFilter
> - */
> -
> static void AddFilter(wxHtmlFilter *filter ) ;
> - /**
> - * \brief Appends HTML fragment to currently displayed text and refreshes
the window.
> - * \param const wxString&
> - */
> -
> bool AppendToPage(const wxString& source ) ;
> - /**
> - * \brief Returns pointer to the top-level container.
> -
> -See also: ,
> - */
> -
> wxHtmlContainerCell* GetInternalRepresentation() const;
> - /**
> - * \brief Returns anchor within currently opened page
> -(see ).
> -If no page is opened or if the displayed page wasn''t
> -produced by call to LoadPage, empty string is returned.
> - */
> -
> wxString GetOpenedAnchor() ;
> - /**
> - * \brief Returns full location of the opened page. If no page is opened
or if the displayed page wasn''t
> -produced by call to LoadPage, empty string is returned.
> - */
> -
> wxString GetOpenedPage() ;
> - /**
> - * \brief Returns title of the opened page or wxEmptyString if current
page does not contain tag.
> - */
> -
> wxString GetOpenedPageTitle() ;
> - /**
> - * \brief Returns the related frame.
> - */
> -
> wxFrame* GetRelatedFrame() const;
> - /**
> - * \brief Moves back to the previous page. (each page displayed using
> - is stored in history list.)
> - */
> -
> bool HistoryBack() ;
> - /**
> - * \brief Returns true if it is possible to go back in the history (i.e.
HistoryBack()
> -won''t fail).
> - */
> -
> bool HistoryCanBack() ;
> - /**
> - * \brief Returns true if it is possible to go forward in the history
(i.e. HistoryBack()
> -won''t fail).
> - */
> -
> bool HistoryCanForward() ;
> - /**
> - * \brief Clears history.
> - */
> -
> void HistoryClear() ;
> - /**
> - * \brief Moves to next page in history.
> - */
> -
> bool HistoryForward() ;
> - /**
> - * \brief Loads HTML page from file and displays it.
> - * \param const wxFileName&
> - */
> -
> virtual bool LoadFile(const wxFileName& filename ) ;
> - /**
> - * \brief Unlike SetPage this function first loads HTML page from
> -and then displays it. See example:
> - * \param const wxString&
> - */
> -
> virtual bool LoadPage(const wxString& location ) ;
> - /**
> - * \brief This method is called when a mouse button is clicked inside
wxHtmlWindow.
> -The default behaviour is to call
> - if the cell contains a
> -hypertext link.
> - * \param wxHtmlCell
> - * \param wxCoord
> - * \param wxCoord
> - * \param const wxMouseEvent&
> - */
> -
> virtual void OnCellClicked(wxHtmlCell *cell , wxCoord x , wxCoord y ,
const wxMouseEvent& event ) ;
> - /**
> - * \brief This method is called when a mouse moves over an HTML cell.
> - * \param wxHtmlCell
> - * \param wxCoord
> - * \param wxCoord
> - */
> -
> virtual void OnCellMouseHover(wxHtmlCell *cell , wxCoord x , wxCoord
y ) ;
> - /**
> - * \brief Called when user clicks on hypertext link. Default behaviour is
to call
> - and do nothing else.
> -
> -Also see .
> - * \param const wxHtmlLinkInfo&
> - */
> -
> virtual void OnLinkClicked(const wxHtmlLinkInfo& link ) ;
> - /**
> - * \brief Called when an URL is being opened (either when the user clicks
on a link or
> -an image is loaded). The URL will be opened only if OnOpeningURL returns
> - . This method is called by
> - .
> -You can override OnOpeningURL to selectively block some
> -URLs (e.g. for security reasons) or to redirect them elsewhere. Default
> -behaviour is to always return .
> - * \param wxHtmlURLType
> - * \param const wxString&
> - * \param wxString *
> - */
> -
> - virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type , const
wxString& url , wxString * redirect ) ;
> - /**
> - * \brief Called on parsing tag.
> - * \param const wxString&
> - */
> -
> + virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type , const
wxString& url , wxString * redirect ) const;
> virtual void OnSetTitle(const wxString& title ) ;
> - /**
> - * \brief This reads custom settings from wxConfig. It uses the path
''path''
> -if given, otherwise it saves info into currently selected path.
> -The values are stored in sub-path
> -
> -Read values: all things set by SetFonts, SetBorders.
> - * \param wxConfigBase
> - * \param wxString
> - */
> -
> virtual void ReadCustomization(wxConfigBase *cfg , wxString path =
wxEmptyString) ;
> - /**
> - * \brief This function sets the space between border of window and HTML
contents. See image:
> -
> -\helponly{\image{}{border.bmp}}
> - * \param int
> - */
> -
> void SetBorders(int b ) ;
> - /**
> - * \brief This function sets font sizes and faces.
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -\wxheading{Defaults}
> -
> -Default font sizes are defined by constants wxHTML_FONT_SIZE_1,
> -wxHTML_FONT_SIZE_2, ..., wxHTML_FONT_SIZE_7. Note that they differ among
> -platforms. Default face names are empty strings.
> - * \param wxString
> - * \param wxString
> - * \param const int
> - */
> -
> void SetFonts(wxString normal_face , wxString fixed_face , const int
*sizes = NULL) ;
> - /**
> - * \brief Sets HTML page and display it. This won''t the page!!
> -It will display the . See example:
> -
> -
> -
> -If you want to load a document from some location use
> - instead.
> - * \param const wxString&
> - */
> -
> bool SetPage(const wxString& source ) ;
> - /**
> - * \brief Sets the frame in which page title will be displayed. is
format of
> -frame title, e.g. "HtmlHelp :
> - * \param wxFrame*
> - * \param const wxString&
> - */
> -
> void SetRelatedFrame(wxFrame* frame , const wxString& format ) ;
> - /**
> - * \brief calling ,
> -this sets statusbar slot where messages will be displayed.
> -(Default is -1 = no messages.)
> - * \param int
> - */
> -
> void SetRelatedStatusBar(int bar ) ;
> - /**
> - * \brief Saves custom settings into wxConfig. It uses the path
''path''
> -if given, otherwise it saves info into currently selected path.
> -Regardless of whether the path is given or not, the function creates
sub-path
> - .
> -
> -Saved values: all things set by SetFonts, SetBorders.
> - * \param wxConfigBase
> - * \param wxString
> - */
> -
> virtual void WriteCustomization(wxConfigBase *cfg , wxString path =
wxEmptyString) ;
> };
>
> Index: wxruby2/lib/wx/classes/htmlwindow.rb
> ==================================================================> ---
wxruby2/lib/wx/classes/htmlwindow.rb (revision 0)
> +++ wxruby2/lib/wx/classes/htmlwindow.rb (revision 0)
> @@ -0,0 +1,6 @@
> +class Wx::HtmlWindow
> + # imitate the in-built LoadFile method
> + def load_file(file)
> + set_page( File.read(file) )
> + end
> +end
> Index: wxruby2/samples/html/html.rb
> ==================================================================> ---
wxruby2/samples/html/html.rb (revision 0)
> +++ wxruby2/samples/html/html.rb (revision 0)
> @@ -0,0 +1,238 @@
> +#!/usr/bin/env ruby
> +# wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
> +# Freely reusable code: see SAMPLES-LICENSE.TXT for details
> +
> +begin
> + require ''wx''
> +rescue LoadError => no_wx_err
> + begin
> + require ''rubygems''
> + require ''wx''
> + rescue LoadError
> + raise no_wx_err
> + end
> +end
> +
> +require ''net/http''
> +require ''uri''
> +
> +class MyHtmlWindow < Wx::HtmlWindow
> + attr_reader :html_src
> + def load_page_from_uri(uri)
> + case uri
> + when URI::HTTP
> + Wx::BusyCursor.busy do
> + res = Net::HTTP.start(uri.host, uri.port) do | http |
> + http.get(uri.path)
> + end
> + @loaded_uri = uri
> + set_page(res.body)
> + end
> + return @loaded_uri
> + when URI::Generic
> + if @loaded_uri and @loaded_uri.kind_of?(URI::HTTP)
> + return load_page_from_uri( @loaded_uri.merge(uri) )
> + elsif @loaded_uri # current viewing a file
> + if uri.to_s =~ /^\//
> + return load_file(uri.path)
> + elsif not uri.path.empty?
> + local_file = File.join( File.dirname(@loaded_uri.path),
uri.path)
> + return load_file( local_file )
> + end
> + end
> + end
> +
> + dlg = Wx::MessageDialog.new(nil, "Can''t load link",
> + "Unable to load the link
#{uri}",
> + Wx::ICON_ERROR)
> + dlg.show_modal
> + end
> +
> + def load_file(file)
> + @loaded_uri = URI.parse("file:////" + file)
> + super file
> + @loaded_uri
> + end
> +
> + def set_page(html)
> + super html
> + @html_src = html
> + get_related_frame.addr_bar.set_value(@loaded_uri.to_s)
> + end
> +
> + def on_link_clicked(link)
> + link_uri = URI.parse(link.get_href)
> + @loaded_uri = load_page_from_uri(link_uri)
> + end
> +
> + def on_cell_mouse_hover(cell, x, y)
> + if link = cell.get_link
> + get_related_frame.set_status_text(link.get_href)
> + else
> + get_related_frame.set_status_text('''')
> + end
> + end
> +end
> +
> +# The frame or self-contained window for this application
> +class HtmlFrame < Wx::Frame
> + attr_reader :html_win, :addr_bar
> +
> + def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
> + # A main application frame has no parent (nil)
> + # -1 means this frame will be supplied a default id
> + super(nil, -1, title, pos, size, style)
> + setup_menus
> + setup_panel
> + create_status_bar(2)
> + set_status_text("Welcome to wxRuby!")
> + end
> +
> + def setup_panel
> + sizer = Wx::BoxSizer.new(Wx::VERTICAL)
> + top_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
> +
> + @go_butt = Wx::StaticText.new(self, -1,
''Location:'')
> + top_sizer.add(@go_butt, 0, Wx::ALL, 4)
> + @addr_bar = Wx::TextCtrl.new(self, -1, ''HOME'',
Wx::DEFAULT_POSITION,
> + Wx::DEFAULT_SIZE, Wx::TE_READONLY)
> + top_sizer.add(@addr_bar, 1, Wx::ALL, 4)
> + sizer.add(top_sizer, 0, Wx::EXPAND|Wx::TOP|Wx::BOTTOM, 4)
> +
> + @html_win = MyHtmlWindow.new(self, -1)
> + @html_win.set_related_frame(self, ''HTML Window: %s'')
> + @html_win.set_related_status_bar(2)
> + @html_win.set_page(DATA.read)
> + sizer.add(@html_win, 1, Wx::ALL|Wx::GROW, 4)
> + self.set_sizer(sizer)
> + end
> +
> + def setup_menus
> + menu_file = Wx::Menu.new()
> + menu_help = Wx::Menu.new()
> + # Using Wx::ID_ABOUT default id means the menu item will be placed
> + # in the correct platform-specific place
> + menu_help.append(Wx::ID_ABOUT, "&About...\tF1",
"Show about dialog")
> + menu_file.append(Wx::ID_OPEN, "&Open File...\tCtrl-O",
"Open File")
> + menu_file.append(Wx::ID_PRINT, "&Print...\tCtrl-P",
"Print")
> +
> + menu_file.append(Wx::ID_PREVIEW,
"&Preview...\tCtrl-Shift-P",
> + "Print Preview")
> + menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit
this program")
> +
> + menu_bar = Wx::MenuBar.new()
> + menu_bar.append(menu_file, "&File")
> + menu_bar.append(menu_help, "&Help")
> + # Assign the menus to this frame
> + set_menu_bar(menu_bar)
> + # handle menu events
> + evt_menu(Wx::ID_OPEN) { on_open_file }
> + evt_menu(Wx::ID_PRINT) { on_print }
> + evt_menu(Wx::ID_PREVIEW) { on_preview }
> + evt_menu(Wx::ID_EXIT) { on_quit }
> + evt_menu(Wx::ID_ABOUT) { on_about }
> + end
> +
> + # end the application
> + def on_quit
> + close
> + end
> +
> + def on_open_file
> + f_dlg = Wx::FileDialog.new(self, "Open an HTML file",
"", "",
> + "HTML files
(*.html;*.htm)|.html;.htm)",
> + Wx::OPEN)
> + if not f_dlg.show_modal == Wx::ID_OK
> + return
> + end
> + html_file = f_dlg.get_path
> +
> + @html_win.load_file(html_file)
> + end
> +
> + # show an ''About'' dialog
> + def on_about
> + msg = sprintf("This is the About dialog of the HTML
sample.\n" \
> + "Welcome to wxRuby, version %s",
Wx::WXRUBY_VERSION)
> +
> + # create a simple message dialog with OK button
> + about_dlg = Wx::MessageDialog.new( self, msg, ''About WxRuby
HTML'',
> + Wx::OK|Wx::ICON_INFORMATION )
> + about_dlg.show_modal()
> + about_dlg.destroy()
> + end
> +
> + def on_preview
> + print = Wx::HtmlEasyPrinting.new(''Print HTML'', self)
> + print.preview_text(@html_win.html_src)
> + end
> +
> + def on_print
> + print = Wx::HtmlEasyPrinting.new(''Print HTML'', self)
> + print.print_text(@html_win.html_src)
> + end
> +
> + # utility function to find an icon relative to this ruby script
> + def local_icon_file(icon_name)
> + File.join( File.dirname(__FILE__), icon_name)
> + end
> +end
> +
> +# Wx::App is the container class for any wxruby app - only a single
> +# instance is required
> +class HtmlApp < Wx::App
> + def on_init
> + frame = HtmlFrame.new("Minimal wxRuby App",
> + Wx::Point.new(50, 50),
> + Wx::Size.new(450, 340))
> + set_app_name(''HtmlDemo'')
> + # required
> + frame.show()
> + end
> +end
> +
> +# Create an instance ...
> +app = HtmlApp.new
> +# ... and run the application
> +app.main_loop()
> +
> +__END__
> +<html>
> +<head>
> +<title>WxRuby HTML Demo</title>
> +</head>
> +
> +<body bgcolor="#ffffff">
> +<h1>The HtmlWindow widget</h1>
> +<p>This is a very simple demonstration of
> +<strong>Wx::HtmlWindow</strong>, a control for displaying
hypertext. The
> + control understands most HTML tags, including links, tables, images,
> + lists and the venerable FONT tag. It does not know about CSS or
> + Javascript; it is not really intended for building a general-purpose
> + web browser.</p>
> +<h2>This demo</h2>
> +<p>In this demo you can open local files for viewing (by choosing
the
> +File / Open). If you have an internet connection http:// links will be
> +downloaded as well. Its features are otherwise limited - for example,
> +this example doesn''t know about HTML anchor targets, because it
has
> +over-ridden default link handling to show how to subclass and
> +specialise HtmlWindow in Ruby.</a>
> +<h2>Html Easy Printing</h2>
> +<p>A useful feature included with WxRuby is a simple interface for
> +printing HTML. You can see this in action by choosing
''Print'' or
> +''Preview'' from the File menu.</p>
> +<h3>Further information</h3>
> +<p>Here''s a table with some links</p>
> +<table border="1">
> +<tr>
> +<td>WxRuby online documentation</td>
> +<td><a
href="http://wxruby.rubyforge.org/doc/">http://wxruby.rubyforge.org/doc/</a></td>
> +</tr>
> +<tr>
> +<td>WxRuby Wiki</td>
> +<td><a
href="http://wxruby.rubyforge.org/wiki/wiki.pl">http://wxruby.rubyforge.org/wiki/wiki.pl</a></td>
> +</tr>
> +</table>
> +
> +</body>
> +</html>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Wxruby-development mailing list
> Wxruby-development at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-development
>