added support for background bitmap specified in background attribute of the HTML body tag

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32021 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-02-13 23:17:12 +00:00
parent 1cffa15b8e
commit 97e490f8b0
4 changed files with 67 additions and 13 deletions

View File

@@ -7,8 +7,8 @@ wxWidgets 2.5 Change Log - For more verbose changes, see the manual
All: All:
- wxEvent and its derivatives have their variable members nonpublic now. - wxEvent and derived classes don't have public members any more, you must
Use the Get/Set accessors (Mart Raudsepp) use accessors methods now (Mart Raudsepp)
- new classes for reading and writing ZIP files (M.J.Wetherell) - new classes for reading and writing ZIP files (M.J.Wetherell)
- large files support for wxFFile (M.J.Wetherell) - large files support for wxFFile (M.J.Wetherell)
- classes in the manual are now cross-referenced (Zbigniew Zag<61>rski) - classes in the manual are now cross-referenced (Zbigniew Zag<61>rski)
@@ -57,6 +57,7 @@ All (GUI):
- added wxMediaCtrl - added wxMediaCtrl
- added wxDatePickerCtrl - added wxDatePickerCtrl
- wxHtmlWindow now supports background images given in <body> tag
- wxSplitterWindow now supports gravity parameter (Zbigniew Zag<61>rski) - wxSplitterWindow now supports gravity parameter (Zbigniew Zag<61>rski)
- recursive wxSizer::GetItem returns item of given window, sizer or nth index - recursive wxSizer::GetItem returns item of given window, sizer or nth index
- wxLayoutConstraints now use best size, not current size, for AsIs() condition - wxLayoutConstraints now use best size, not current size, for AsIs() condition

View File

@@ -139,6 +139,10 @@ public:
// Sets space between text and window borders. // Sets space between text and window borders.
void SetBorders(int b) {m_Borders = b;} 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' // Saves custom settings into cfg config. it will use the path 'path'
// if given, otherwise it will save info into currently selected path. // if given, otherwise it will save info into currently selected path.
// saved values : things set by SetFonts, SetBorders. // saved values : things set by SetFonts, SetBorders.
@@ -170,6 +174,7 @@ public:
// Adds HTML processor to wxHtmlWindow class as whole: // Adds HTML processor to wxHtmlWindow class as whole:
static void AddGlobalProcessor(wxHtmlProcessor *processor); static void AddGlobalProcessor(wxHtmlProcessor *processor);
// -- Callbacks -- // -- Callbacks --
// Sets the title of the window // Sets the title of the window
@@ -210,10 +215,7 @@ public:
// Converts current page to text: // Converts current page to text:
wxString ToText(); wxString ToText();
#endif #endif // wxUSE_CLIPBOARD
virtual void ApplyParentThemeBackground(const wxColour& WXUNUSED(bg))
{ /* do nothing */ }
protected: protected:
void Init(); void Init();
@@ -323,6 +325,9 @@ private:
// window content for double buffered rendering: // window content for double buffered rendering:
wxBitmap *m_backBuffer; wxBitmap *m_backBuffer;
// background image, may be invalid
wxBitmap m_bmpBg;
// variables used when user is selecting text // variables used when user is selecting text
wxPoint m_tmpSelFromPos; wxPoint m_tmpSelFromPos;
wxHtmlCell *m_tmpSelFromCell; wxHtmlCell *m_tmpSelFromCell;

View File

@@ -307,6 +307,7 @@ bool wxHtmlWindow::SetPage(const wxString& source)
wxClientDC *dc = new wxClientDC(this); wxClientDC *dc = new wxClientDC(this);
dc->SetMapMode(wxMM_TEXT); dc->SetMapMode(wxMM_TEXT);
SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF)); SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
SetBackgroundImage(wxNullBitmap);
m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
m_Parser->SetDC(dc); m_Parser->SetDC(dc);
if (m_Cell) if (m_Cell)
@@ -850,11 +851,36 @@ void wxHtmlWindow::OnCellMouseHover(wxHtmlCell * WXUNUSED(cell),
void wxHtmlWindow::OnEraseBackground(wxEraseEvent& event) void wxHtmlWindow::OnEraseBackground(wxEraseEvent& event)
{ {
// we do have to erase background now that we reuse it (instead of if ( !m_bmpBg.Ok() )
// overwriting it) in OnPaint() below, but maybe we should set some flag if {
// we get here as this would mean that user code doesn't paint background // we used to do nothing at all here but we do have to erase background
// itself and then we wouldn't have to copy old bits to dcm below... // now that we reuse it (instead of overwriting it) in OnPaint() below
event.Skip(); event.Skip();
return;
}
wxDC& dc = *event.GetDC();
// if the image is not fully opaque, we have to erase the background before
// drawing it, however avoid doing it for opaque images as this would just
// result in extra flicker without any other effect as background is
// completely covered anyhow
if ( m_bmpBg.GetMask() )
{
dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID));
dc.Clear();
}
const wxSize sizeWin(GetClientSize());
const wxSize sizeBmp(m_bmpBg.GetWidth(), m_bmpBg.GetHeight());
for ( wxCoord x = 0; x < sizeWin.x; x += sizeBmp.x )
{
for ( wxCoord y = 0; y < sizeWin.y; y += sizeBmp.y )
{
dc.DrawBitmap(m_bmpBg, x, y, true /* use mask */);
}
}
} }
void wxHtmlWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) void wxHtmlWindow::OnPaint(wxPaintEvent& WXUNUSED(event))

View File

@@ -12,9 +12,10 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/defs.h" #include "wx/defs.h"
#if wxUSE_HTML && wxUSE_STREAMS #if wxUSE_HTML && wxUSE_STREAMS
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
@@ -22,6 +23,7 @@
#ifndef WXPRECOMP #ifndef WXPRECOMP
#endif #endif
#include "wx/image.h"
#include "wx/html/forcelnk.h" #include "wx/html/forcelnk.h"
#include "wx/html/m_templ.h" #include "wx/html/m_templ.h"
@@ -330,6 +332,25 @@ TAG_HANDLER_BEGIN(BODY, "BODY")
if (tag.GetParamAsColour(wxT("LINK"), &clr)) if (tag.GetParamAsColour(wxT("LINK"), &clr))
m_WParser->SetLinkColor(clr); m_WParser->SetLinkColor(clr);
if (tag.HasParam(wxT("BACKGROUND")))
{
wxFSFile *fileBgImage = m_WParser->OpenURL
(
wxHTML_URL_IMAGE,
tag.GetParam(wxT("BACKGROUND"))
);
if ( fileBgImage )
{
wxInputStream *is = fileBgImage->GetStream();
if ( is )
{
wxImage image(*is);
if ( image.Ok() )
m_WParser->GetWindow()->SetBackgroundImage(image);
}
}
}
if (tag.GetParamAsColour(wxT("BGCOLOR"), &clr)) if (tag.GetParamAsColour(wxT("BGCOLOR"), &clr))
{ {
m_WParser->GetContainer()->InsertCell( m_WParser->GetContainer()->InsertCell(
@@ -337,6 +358,7 @@ TAG_HANDLER_BEGIN(BODY, "BODY")
if (m_WParser->GetWindow() != NULL) if (m_WParser->GetWindow() != NULL)
m_WParser->GetWindow()->SetBackgroundColour(clr); m_WParser->GetWindow()->SetBackgroundColour(clr);
} }
return false; return false;
} }