]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/winpars.cpp
silence gcc warnings about values not handled in switch
[wxWidgets.git] / src / html / winpars.cpp
index 52578cc0eee46e34625d9d9995d973157fa89056..6c7d8dab0fca30297258d71cc6dd89ab126b688c 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        winpars.cpp
+// Name:        src/html/winpars.cpp
 // Purpose:     wxHtmlParser class (generic parser)
 // Author:      Vaclav Slavik
 // RCS-ID:      $Id$
@@ -9,24 +9,23 @@
 
 #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"
 
 
@@ -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;
@@ -192,10 +191,16 @@ void wxHtmlWinParser::InitParser(const wxString& source)
     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
@@ -210,11 +215,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()));
 }
 
@@ -227,6 +239,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;
@@ -244,58 +265,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)
@@ -366,8 +385,8 @@ void wxHtmlWinParser::DoAddText(wxChar *temp, int& templen, wxChar nbsp)
 
     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;
@@ -464,7 +483,6 @@ void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo& link)
     m_UseLink = (link.GetHref() != wxEmptyString);
 }
 
-
 void wxHtmlWinParser::SetFontFace(const wxString& face)
 {
     if (GetFontFixed()) m_FontFaceFixed = face;
@@ -476,6 +494,15 @@ void wxHtmlWinParser::SetFontFace(const wxString& 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
@@ -578,4 +605,3 @@ void wxHtmlTagsModule::OnExit()
 }
 
 #endif
-