X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c115835b39194fd6c6852c96f5a9cccd2cc9aaa..d64ad2c7e18f23ae0d6458a009bf832c04dde2aa:/src/html/winpars.cpp diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index 265572a844..97c4c92d40 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: winpars.cpp +// Name: src/html/winpars.cpp // Purpose: wxHtmlParser class (generic parser) // Author: Vaclav Slavik // RCS-ID: $Id$ @@ -9,23 +9,22 @@ #include "wx/wxprec.h" -#include "wx/defs.h" -#if wxUSE_HTML && wxUSE_STREAMS - #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif +#if wxUSE_HTML && wxUSE_STREAMS + #ifndef WXPRECOMP #include "wx/intl.h" #include "wx/dc.h" + #include "wx/log.h" #endif #include "wx/html/htmldefs.h" #include "wx/html/winpars.h" #include "wx/html/htmlwin.h" #include "wx/fontmap.h" -#include "wx/log.h" #include "wx/settings.h" #include "wx/uri.h" @@ -38,11 +37,11 @@ IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinParser, wxHtmlParser) wxList wxHtmlWinParser::m_Modules; -wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindow *wnd) : wxHtmlParser() +wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindowInterface *wndIface) { m_tmpStrBuf = NULL; m_tmpStrBufSize = 0; - m_Window = wnd; + m_windowInterface = wndIface; m_Container = NULL; m_DC = NULL; m_CharHeight = m_CharWidth = 0; @@ -212,11 +211,18 @@ void wxHtmlWinParser::InitParser(const wxString& source) m_Container->InsertCell(new wxHtmlColourCell(m_ActualColor)); wxColour windowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ; - m_Container->InsertCell( - new wxHtmlColourCell(GetWindow() ? - GetWindow()->GetBackgroundColour() : - windowColour, - wxHTML_CLR_BACKGROUND)); + + m_Container->InsertCell + ( + new wxHtmlColourCell + ( + m_windowInterface + ? m_windowInterface->GetHTMLBackgroundColour() + : windowColour, + wxHTML_CLR_BACKGROUND + ) + ); + m_Container->InsertCell(new wxHtmlFontCell(CreateCurrentFont())); } @@ -229,6 +235,15 @@ void wxHtmlWinParser::DoneParser() wxHtmlParser::DoneParser(); } +#if WXWIN_COMPATIBILITY_2_6 +wxHtmlWindow *wxHtmlWinParser::GetWindow() +{ + if (!m_windowInterface) + return NULL; + return wxDynamicCast(m_windowInterface->GetHTMLWindow(), wxHtmlWindow); +} +#endif + wxObject* wxHtmlWinParser::GetProduct() { wxHtmlContainerCell *top; @@ -246,58 +261,56 @@ wxObject* wxHtmlWinParser::GetProduct() wxFSFile *wxHtmlWinParser::OpenURL(wxHtmlURLType type, const wxString& url) const { - if ( m_Window ) + if ( !m_windowInterface ) + return wxHtmlParser::OpenURL(type, url); + + wxString myurl(url); + wxHtmlOpeningStatus status; + for (;;) { - wxString myurl(url); - wxHtmlOpeningStatus status; - for (;;) - { - wxString myfullurl(myurl); + wxString myfullurl(myurl); - // consider url as absolute path first - wxURI current(myurl); - myfullurl = current.BuildUnescapedURI(); + // consider url as absolute path first + wxURI current(myurl); + myfullurl = current.BuildUnescapedURI(); - // if not absolute then ... - if( current.IsReference() ) - { - wxString basepath = GetFS()->GetPath(); - wxURI base(basepath); + // if not absolute then ... + if( current.IsReference() ) + { + wxString basepath = GetFS()->GetPath(); + wxURI base(basepath); - // ... try to apply base path if valid ... - if( !base.IsReference() ) - { - wxURI path(myfullurl); - path.Resolve( base ); - myfullurl = path.BuildUnescapedURI(); - } - else + // ... try to apply base path if valid ... + if( !base.IsReference() ) + { + wxURI path(myfullurl); + path.Resolve( base ); + myfullurl = path.BuildUnescapedURI(); + } + else + { + // ... or force such addition if not included already + if( !current.GetPath().Contains(base.GetPath()) ) { - // ... or force such addition if not included already - if( !current.GetPath().Contains(base.GetPath()) ) - { - basepath += myurl; - wxURI connected( basepath ); - myfullurl = connected.BuildUnescapedURI(); - } + basepath += myurl; + wxURI connected( basepath ); + myfullurl = connected.BuildUnescapedURI(); } } - - wxString redirect; - status = m_Window->OnOpeningURL(type, myfullurl, &redirect); - if ( status != wxHTML_REDIRECT ) - break; - - myurl = redirect; } - if ( status == wxHTML_BLOCK ) - return NULL; + wxString redirect; + status = m_windowInterface->OnHTMLOpeningURL(type, myfullurl, &redirect); + if ( status != wxHTML_REDIRECT ) + break; - return GetFS()->OpenFile(myurl); + myurl = redirect; } - return wxHtmlParser::OpenURL(type, url); + if ( status == wxHTML_BLOCK ) + return NULL; + + return GetFS()->OpenFile(myurl); } void wxHtmlWinParser::AddText(const wxChar* txt) @@ -588,4 +601,3 @@ void wxHtmlTagsModule::OnExit() } #endif -