// Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #include "stdpch.h" #include #include "nel/misc/rgba.h" #include "nel/gui/interface_parser.h" #include "nel/misc/i_xml.h" #include "nel/misc/file.h" #include "nel/misc/algo.h" #include "nel/misc/mem_stream.h" #include "nel/misc/factory.h" #include "nel/misc/big_file.h" #include "nel/misc/xml_auto_ptr.h" #include "nel/gui/interface_options.h" #include "nel/gui/interface_anim.h" #include "nel/gui/interface_expr.h" #include "nel/gui/view_pointer.h" #include "nel/gui/group_modal.h" #include "nel/gui/group_list.h" #include "nel/gui/group_container.h" #include "nel/gui/interface_link.h" #include "nel/gui/lua_helper.h" #include "nel/gui/lua_ihm.h" #include "nel/gui/lua_manager.h" #include "nel/gui/root_group.h" #ifdef LUA_NEVRAX_VERSION #include "lua_ide_dll_nevrax/include/lua_ide_dll/ide_interface.h" // external debugger #endif #ifdef DEBUG_NEW #define new DEBUG_NEW #endif const uint32 UI_CACHE_SERIAL_CHECK = NELID("IUG_"); using namespace NLMISC; using namespace std; namespace NLGUI { void saveXMLTree(COFile &f, xmlNodePtr node) { // save node name std::string name = (const char *) node->name; f.serial(name); // save properties uint32 numProp = 0; xmlAttrPtr currProp = node->properties; while (currProp) { ++ numProp; currProp = currProp->next; } f.serial(numProp); currProp = node->properties; while (currProp) { std::string name = (const char *) currProp->name; f.serial(name); CXMLAutoPtr ptr(xmlGetProp(node, currProp->name)); std::string value = (const char *) ptr; f.serial(value); currProp = currProp->next; } uint32 numChildren = 0; xmlNodePtr currChild = node->children; while (currChild) { ++ numChildren; currChild = currChild->next; } f.serial(numChildren); currChild = node->children; while (currChild) { saveXMLTree(f, currChild); currChild = currChild->next; } } xmlNodePtr buildTree(CIFile &f) { // load node name std::string name; f.serial(name); xmlNodePtr node = xmlNewNode(NULL, (const xmlChar *) name.c_str()); // slod properties uint32 numProp; f.serial(numProp); for(uint k = 0; k < numProp; ++k) { std::string name, value; f.serial(name, value); xmlSetProp(node, (const xmlChar *) name.c_str(), (const xmlChar *) value.c_str()); } uint32 numChildren; f.serial(numChildren); for(uint k = 0; k < numChildren; ++k) { xmlAddChild(node, buildTree(f)); } return node; } // ---------------------------------------------------------------------------- // CInterfaceParser // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- CInterfaceParser::CInterfaceParser() { luaInitialized = false; cacheUIParsing = false; linkId = 0; editorMode = false; setupCallback = NULL; } CInterfaceParser::~CInterfaceParser() { _ParentPositionsMap.clear(); _ParentSizesMap.clear(); _ParentSizesMaxMap.clear(); _LuaClassAssociation.clear(); _Templates.clear(); removeAllModules(); setupCallback = NULL; } /** Convert a string into a memstream */ static void interfaceScriptAsMemStream(const std::string &script, CMemStream &destStream) { NLMISC::contReset(destStream); if (destStream.isReading()) // we must be sure that we are reading the stream { destStream.invert(); } destStream.seek(0, NLMISC::IStream::begin); if (script.empty()) return; destStream.serialBuffer(const_cast((const uint8 *) &script[0]), (uint)script.size()); destStream.invert(); destStream.seek(0, NLMISC::IStream::begin); } std::string CInterfaceParser::lookup( const std::string &file ) { std::string filename; if( editorMode && !_WorkDir.empty() ) { std::string wdpath = CPath::standardizePath( _WorkDir ) + file; if( CFile::fileExists( wdpath ) ) filename = wdpath; } if( filename.empty() ) filename = CPath::lookup( file ); return filename; } // ---------------------------------------------------------------------------- bool CInterfaceParser::parseInterface (const std::vector & strings, bool reload, bool isFilename, bool checkInData) { bool ok; bool needCheck = false; #if !FINAL_VERSION needCheck = false; #endif // TestYoyo. UnHide For Parsing Profile /* NLMISC::CHTimer::startBench(); { H_AUTO(parseInterface); */ //ignore the content of tags containing only white space xmlKeepBlanksDefault(0); //parse all interface files and build a single xml document xmlNodePtr globalEnclosing; nlassert (!strings.empty()); CIXml read; string nextFileName; static const char *SCRIPT_AS_STRING = "