From 6198b7f4965a15e4f7f95d96f792351c537e1ba5 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Mon, 13 Apr 2015 20:53:10 +0300 Subject: [PATCH] Parse local files (ingame help) with new html parser --- code/nel/include/nel/gui/group_html.h | 6 ++ code/nel/src/gui/group_html.cpp | 83 +++++++++++++++++++++++---- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 1f3c8e4dc..34105028c 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -677,6 +677,12 @@ namespace NLGUI // read style attribute void getStyleParams(const std::string &styleString, CStyleParams &style, bool inherit = true); + // load and render local html file (from bnp for example) + void doBrowseLocalFile(const std::string &filename); + + // render html string as new browser page + bool renderHtmlString(const std::string &html); + private: // decode all HTML entities static ucstring decodeHTMLEntities(const ucstring &str); diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index f1c699a63..8619ea878 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -3824,6 +3824,10 @@ namespace NLGUI stopBrowse (); updateRefreshButton(); + // Browsing + _Browsing = true; + updateRefreshButton(); + // Home ? if (_URL == "home") _URL = home(); @@ -3843,17 +3847,24 @@ namespace NLGUI _Connecting = true; _ConnectingTimeout = ( times.thisFrameMs / 1000.0f ) + _TimeoutValue; + // Save new url + _URL = finalUrl; + + // file is probably from bnp (ingame help) + if (isLocal) + { + if (strlwr(finalUrl).find("file:/") == 0) + { + finalUrl = finalUrl.substr(6, finalUrl.size() - 6); + } + doBrowseLocalFile(finalUrl); + } + else + { CButtonFreezer freezer; this->visit(&freezer); - // Browsing - _Browsing = true; - updateRefreshButton(); - - // Save new url - _URL = finalUrl; - // display HTTP query //nlinfo("WEB: GET '%s'", finalUrl.c_str()); @@ -3869,12 +3880,7 @@ namespace NLGUI C3WSmartPtr uri = HTParse(finalUrl.c_str(), NULL, PARSE_ALL); // Create an anchor - #ifdef NL_OS_WINDOWS if ((_LibWWW->Anchor = HTAnchor_findAddress(uri)) == NULL) - #else - // temporarily disable local URL's until LibWWW can be replaced. - if (isLocal || ((_LibWWW->Anchor = HTAnchor_findAddress(uri)) == NULL)) - #endif { browseError((string("The page address is malformed : ")+(const char*)uri).c_str()); } @@ -3911,6 +3917,8 @@ namespace NLGUI } } + } // !isLocal + _BrowseNextTime = false; } @@ -4099,6 +4107,57 @@ namespace NLGUI #endif } + // *************************************************************************** + void CGroupHTML::doBrowseLocalFile(const std::string &filename) + { + CIFile in; + if (in.open(filename)) + { + std::string html; + while(!in.eof()) + { + char buf[1024]; + in.getline(buf, 1024); + html += std::string(buf) + "\n"; + } + in.close(); + + if (!renderHtmlString(html)) + { + browseError((string("Failed to parse html from file : ")+filename).c_str()); + } + } + else + { + browseError((string("The page address is malformed : ")+filename).c_str()); + } + } + + // *************************************************************************** + + bool CGroupHTML::renderHtmlString(const std::string &html) + { + bool success; + + // clear content + beginBuild(); + + success = parseHtml(html); + + // invalidate coords + endBuild(); + + // libwww would call requestTerminated() here + _Browsing = false; + if (_TitleString.empty()) + { + setTitle(_TitlePrefix); + } + updateRefreshButton(); + + return success; + } + // *************************************************************************** void CGroupHTML::draw ()