]> git.saurik.com Git - wxWidgets.git/commitdiff
no real changes, just simplify LoadPage() to make it more readable and less redundant
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 31 May 2008 13:25:50 +0000 (13:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 31 May 2008 13:25:50 +0000 (13:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53879 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/html/htmlwin.cpp

index 11c6e1e44c924771f31c981d9ddde888c74e866f..6437b543c32b3cfc88fe1a7adb4a388fa53e5d2a 100644 (file)
@@ -472,7 +472,6 @@ bool wxHtmlWindow::LoadPage(const wxString& location)
 
     wxBusyCursor busyCursor;
 
-    wxFSFile *f;
     bool rt_val;
     bool needs_refresh = false;
 
@@ -485,31 +484,28 @@ bool wxHtmlWindow::LoadPage(const wxString& location)
         (*m_History)[m_HistoryPos].SetPos(y);
     }
 
-    if (location[0] == wxT('#'))
+    // first check if we're moving to an anchor in the same page
+    size_t posLocalAnchor = location.Find('#');
+    if ( posLocalAnchor != wxString::npos && posLocalAnchor != 0 )
     {
-        // local anchor:
-        wxString anch = location.Mid(1) /*1 to end*/;
-        m_tmpCanDrawLocks--;
-        rt_val = ScrollToAnchor(anch);
-        m_tmpCanDrawLocks++;
-    }
-    else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage)
-    {
-        wxString anch = location.AfterFirst(wxT('#'));
-        m_tmpCanDrawLocks--;
-        rt_val = ScrollToAnchor(anch);
-        m_tmpCanDrawLocks++;
+        // check if the part before the anchor is the same as the (either
+        // relative or absolute) URI of the current page
+        const wxString beforeAnchor = location.substr(0, posLocalAnchor);
+        if ( beforeAnchor != m_OpenedPage &&
+                m_FS->GetPath() + beforeAnchor != m_OpenedPage )
+        {
+            // indicate that we're not moving to a local anchor
+            posLocalAnchor = wxString::npos;
+        }
     }
-    else if (location.Find(wxT('#')) != wxNOT_FOUND &&
-             (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage)
+
+    if ( posLocalAnchor != wxString::npos )
     {
-        wxString anch = location.AfterFirst(wxT('#'));
         m_tmpCanDrawLocks--;
-        rt_val = ScrollToAnchor(anch);
+        rt_val = ScrollToAnchor(location.substr(posLocalAnchor + 1));
         m_tmpCanDrawLocks++;
     }
-
-    else
+    else // moving to another page
     {
         needs_refresh = true;
 #if wxUSE_STATUSBAR
@@ -521,7 +517,7 @@ bool wxHtmlWindow::LoadPage(const wxString& location)
         }
 #endif // wxUSE_STATUSBAR
 
-        f = m_Parser->OpenURL(wxHTML_URL_PAGE, location);
+        wxFSFile *f = m_Parser->OpenURL(wxHTML_URL_PAGE, location);
 
         // try to interpret 'location' as filename instead of URL:
         if (f == NULL)