/////////////////////////////////////////////////////////////////////////////
-// Name: winpars.cpp
+// Name: src/html/winpars.cpp
// Purpose: wxHtmlParser class (generic parser)
// Author: Vaclav Slavik
// RCS-ID: $Id$
#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"
+ #include "wx/settings.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"
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;
m_LinkColor.Set(0, 0, 0xFF);
m_ActualColor.Set(0, 0, 0);
m_Align = wxHTML_ALIGN_LEFT;
+ m_ScriptMode = wxHTML_SCRIPT_NORMAL;
+ m_ScriptBaseline = 0;
m_tmpLastWasSpace = false;
m_lastWordCell = NULL;
+ // open the toplevel container that contains everything else and that
+ // is never closed (this makes parser's life easier):
OpenContainer();
+
+ // then open the first container into which page's content will go:
OpenContainer();
#if !wxUSE_UNICODE
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()));
}
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;
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)
wxHtmlCell *c = new wxHtmlWordCell(temp, *(GetDC()));
- if (m_UseLink)
- c->SetLink(m_Link);
+ ApplyStateToCell(c);
+
m_Container->InsertCell(c);
((wxHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell);
m_lastWordCell = (wxHtmlWordCell*)c;
m_UseLink = (link.GetHref() != wxEmptyString);
}
-
void wxHtmlWinParser::SetFontFace(const wxString& face)
{
if (GetFontFixed()) m_FontFaceFixed = face;
#endif
}
+void wxHtmlWinParser::ApplyStateToCell(wxHtmlCell *cell)
+{
+ // set the link:
+ if (m_UseLink)
+ cell->SetLink(GetLink());
+
+ // apply current script mode settings:
+ cell->SetScriptMode(GetScriptMode(), GetScriptBaseline());
+}
#if !wxUSE_UNICODE
}
#endif
-