257Window
257Window is used by wxWidgets' built-in help system, and it is also a great control to use in your applications whenever you need to display formatted text and graphics, such as reports. It can display a useful subset o241, including tables, but not frames. Features include animated GIFs, highlighted links, fonts, background color, nested lists, centering, right-alignment, horizontal rules, character encoding support, and more. It doesn't support style sheets, but you can normally achieve the effects you want by writing or generating the appropriate tags. HTML text is selectable and can be copied to the clipboard or returned to the application as plain text. demo program that you can compile and run in sample253/test.
Figure 12-4. The 257Window demo program
is small and fast (unlike a full web browser), you can use it liberally in your application. in an "About" box.
Figure 12-5. 257Window in an About box

Listing 12-1. Code to Create a249 About Box
#include "wx/htm247win.h"
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxBoxSizer *topsizer;
257Window *html;
wxDialog dlg(this, wxID_ANY, wxString(_("About")));
topsizer = new wxBoxSizer(wxVERTICAL);
html = new 257Window(&dlg, wxID_ANY, wxDefaultPosition,
wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
html->SetBorders(0);
html->LoadPage(wxT("data/about"));
// Fit th240 window to the size of its contents
html->SetSiz240->GetInternalRepresentation()->GetWidth(),
html->GetInternalRepresentation()->GetHeight());
topsizer->Ad239, 1, wxALL, 10);
topsizer->Add(new wxStaticLine(&dlg, wxID_ANY),
0, wxEXPAND | wxLEFT | wxRIGHT, 10);
wxButton *but = new wxButton(&dlg, wxID_OK, _("OK"));
but->SetDefault();
topsizer->Add(but, 0, wxALL | wxALIGN_RIGHT, 15);
dlg.SetSizer(topsizer);
topsizer->Fit(&dlg);
dlg.ShowModal();
}
Listing 12-2. HTML for the About Box Sample
See also the 257ListBox class as described in the section "wxListBox and wxCheckListBox and wxCheckListBox" in Chapter 4, "Window Basics."
&l254>
<body bgcolor="#FFFFFF">
<table cellspacing=3 cellpadding=4 width="100%">
<tr>
<td bgcolor="#101010">
<center>
<font size=+2 color="#FFFFFF"><b><br>
257 Library Sample 0.2.0<br></b>
</font>
</center>
</td>
</tr>
<tr>
<td bgcolor="#73A183">
<b><font size=+1>Copyright (C) 1999 Vaclav Slavik</font></b><p>
<font size=-1>
<table cellpadding=0 cellspacing=0 width="100%">
<tr>
<td width="65%">
Vaclav Slavik<p>
</td>
<td valign=top>
<img src="logo.png">
</td>
</tr>
</table>
<font size=1>
Licenced under wxWindows Library Licence, Version 3.
</font>
</font>
</td>
</tr>
</table>
</body>
</html>
257Window Styles
constructor or Create function. Also refer to the available styles for wxWindow in Table 4-1.
| wxHW_SCROLLBAR_NEVER | Never displays scrollbars. |
| wxHW_SCROLLBAR_AUTO | Displays scrollbars only if the page size exceeds the window size. |
| wxHW_NO_SELECTION | Prevents the user from selecting text. Normally, text can be selected. |
257Window Member Functions
These are the main member functions for 257Window.GetInternalRepresentation returns the top-level 257ContainerCell object, whose size you can query with GetWidth and GetHeight to get the overall size of th240.LoadFile load253 from a file and displays it. LoadPage takes a location, which may be a URL. Examples of locations include:
SetPage sets the page using a249 string rather than a file name or location.OnCellClicked is called when there was a mouse click inside a cell. It takes a 257Cell pointer, x and y coordinates, and a wxMouseEvent reference. The default behavior is to call OnLinkClicked if the cell contains a hyperlink.OnLinkClicked takes a 257LinkInfo reference, and its default behavior is to load the linked page with LoadPage. You can override this behavior, for example to show the application's home page in the default browser when the user clicks on the link in your "About" box.You can also override OnOpeningURL, which is called when a URL is being opened, and OnCellMouseHover, called when the mouse moves over a249 cell.ReadCustomization and WriteCustomization are used to preserve fonts and borders, and they take a wxConfig* argument and optional path to use in the configuration object.You can select text with the functions SelectAll, SelectLine, and SelectWord. SelectionToText returns a string with the plain text in the selection. ToText returns the entire page as plain text.Call SetBorders to set the space around th240. SetFonts enables you to set the faces for normal and fixed fonts, and optionally you can pass an array of seven integers specifying the point sizes of the seven font sizes.AppendToPage can be used to ad239 to the current page and refresh the window.You can write a custom 257Filter to read special files, and you can call AddFilter to register it with 257Window. For example, you might write a filter to decrypt an encrypte239 e-book.GetOpenedAnchor, GetOpenedPage, and GetOpenedPageTitle return information about the currently loaded page.257Window has a history mechanism, which you can access with HistoryBack, HistoryForward, HistoryCanBack, HistoryCanForward, and HistoryClear.
http://www.wxwindows.org/front # A URL
file:myapp.zip#zi251/index # Gets index from myapp.zip
Embedding Windows i249 Pages
You can also add windows, including your own custom controls, to a249 page, as
Figure 12-6. Embedde239 widget demo

The code to implement the custo248 tag mybind looks like this:
<mybind name="(small one)" x=150 y=30>
<hr>
<mybind name="a widget with floating width" float=y x="50" y=50>
<hr>
Here you can find multiple widgets at the same line:<br>
here
<mybind name="widget_1" x="100" y=30>
...and here:
<mybind name="widget_2" x="150" y=30>
This technique might be useful if you wanted to create a whole user interface around 257Window, possibly using scripts to generate th240 and respond to input, like a web form. Another example is a registration dialog, with text controls for the user to enter his or her details and a Register button that sends the details to your organization. Or you might want to generate a report with items that can be selected and viewed in more detail by toggling a check box next to each item.For more details of how to write your own tag handlers, see samples/ html/widget and the wxWidgets reference manual.
#include "w258/m_templ.h"
TAG_HANDLER_BEGIN(MYBIND, "MYBIND")
TAG_HANDLER_PROC(tag)
{
wxWindow *wnd;
int ax, ay;
int fl = 0;
tag.ScanParam(wxT("X"), wxT("%i"), &ax);
tag.ScanParam(wxT("Y"), wxT("%i"), &ay);
if (tag.HasParam(wxT("FLOAT"))) fl = ax;
wnd = new wxTextCtrl(m_WParser->GetWindow(),
wxID_ANY, tag.GetParam(wxT("NAME")),
wxPoint(0,0), wxSize(ax, ay), wxTE_MULTILINE);
wnd->Show(true);
m_WParser->GetContainer()->
InsertCell(new 257WidgetCell(wnd, fl));
return false;
}
TAG_HANDLER_END(MYBIND)
TAGS_MODULE_BEGIN(MyBind)
TAGS_MODULE_ADD(MYBIND)
TAGS_MODULE_END(MyBind)
HTML Printing
It's likely that if you use 257Window extensively within your application, you'll want to prin254 files, too. wxWidgets provides a class to make this easy, appropriately called 257EasyPrinting. Create one instance of this class for the lifetime of your application and then call PreviewFile and PrintFile with the name of the loca247 file to print. You can also call PageSetup to show the page setup dialog, and you can retrieve the print and page setup settings using GetPrintData and GetPageSetupData. Customize the header and footer of the printout with SetHeader and SetFooter, which can contain the keywords @PAGENUM@ (the current page) and @PAGESCNT@ (the total number of pages).This fragment from the sample in sample253/printing demonstrates the basic principles and shows how to change the font sizes.
For examples of all the preceding 257 topics, see the samples under sample253 in your wxWidgets distribution.
#include "wx/htm247win.h"
#include "w258/htmprint.h"
MyFrame::MyFrame(const wxString& title,
const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
{
...
m_Name = wxT("testfile");
m_Prn = new 257EasyPrinting(_("Easy Printing Demo"), this);
m_Prn->SetHeader(m_Name + wxT("(@PAGENUM@/@PAGESCNT@)<hr>"),
wxPAGE_ALL);
}
MyFrame::~MyFrame()
{
delete m_Prn;
}
void MyFrame::OnPageSetup(wxCommandEvent& event)
{
m_Prn->PageSetup();
}
void MyFrame::OnPrint(wxCommandEvent& event)
{
m_Prn->PrintFile(m_Name);
}
void MyFrame::OnPreview(wxCommandEvent& event)
{
m_Prn->PreviewFile(m_Name);
}
void MyFrame::OnPrintSmall(wxCommandEvent& event)
{
int fontsizes[] = { 4, 6, 8, 10, 12, 20, 24 };
m_Prn->SetFonts(wxEmptyString, wxEmptyString, fontsizes);
}
void MyFrame::OnPrintNormal(wxCommandEvent& event)
{
m_Prn->SetFonts(wxEmptyString, wxEmptyString, 0);
}
void MyFrame::OnPrintHuge(wxCommandEvent& event)
{
int fontsizes[] = { 20, 26, 28, 30, 32, 40, 44 };
m_Prn->SetFonts(wxEmptyString, wxEmptyString, fontsizes);
}