From 28811105be4433f75e9d4aad7fd2bd6d7227c34a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 Aug 2012 02:43:01 +0200 Subject: [PATCH] CHANGED: #1471 CCtrlBase fields can now be serialized. --- code/nel/include/nel/gui/ctrl_base.h | 4 ++ code/nel/include/nel/gui/interface_element.h | 2 +- code/nel/src/gui/ctrl_base.cpp | 45 +++++++++++++++++++ code/nel/src/gui/interface_element.cpp | 6 +-- .../plugins/gui_editor/widget_serializer.cpp | 10 +++-- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h index f450a9042..a29e28fbe 100644 --- a/code/nel/include/nel/gui/ctrl_base.h +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -63,6 +63,8 @@ namespace NLGUI void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + // special parse virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); @@ -171,6 +173,8 @@ namespace NLGUI THotSpot _ToolTipPosRefAlt : 6; protected: void convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS); + static std::string TooltipHotSpotToString( THotSpot parent, THotSpot child ); + bool resizer; }; diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 7610ccff8..54d2a1ada 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -127,7 +127,7 @@ namespace NLGUI virtual void setProperty( const std::string &name, const std::string &value ); - virtual bool serialize( xmlNodePtr parentNode, const char *type ) const; + virtual xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; /// Parse the element and initalize it virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); diff --git a/code/nel/src/gui/ctrl_base.cpp b/code/nel/src/gui/ctrl_base.cpp index 17e6a067a..fab44dd5a 100644 --- a/code/nel/src/gui/ctrl_base.cpp +++ b/code/nel/src/gui/ctrl_base.cpp @@ -313,6 +313,33 @@ namespace NLGUI CInterfaceElement::setProperty( name, value ); } + + xmlNodePtr CCtrlBase::serialize( xmlNodePtr parentNode, const char *type ) const + { + xmlNodePtr node = + CInterfaceElement::serialize( parentNode, type ); + + if( node == NULL ) + return NULL; + + xmlNewProp( node, BAD_CAST "tooltip", BAD_CAST _ContextHelp.toString().c_str() ); + xmlNewProp( node, BAD_CAST "tooltip_i18n", BAD_CAST _ContextHelp.toString().c_str() ); + xmlNewProp( node, BAD_CAST "on_tooltip", BAD_CAST _OnContextHelp.toString().c_str() ); + xmlNewProp( node, BAD_CAST "on_tooltip_params", BAD_CAST _OnContextHelpParams.toString().c_str() ); + xmlNewProp( node, BAD_CAST "tooltip_parent", BAD_CAST tooltipParentToString( _ToolTipParent ).c_str() ); + xmlNewProp( node, BAD_CAST "tooltip_special_parent", BAD_CAST _ToolTipSpecialParent.toString().c_str() ); + + xmlNewProp( node, BAD_CAST "tooltip_posref", + BAD_CAST TooltipHotSpotToString( _ToolTipParentPosRef, _ToolTipPosRef ).c_str() ); + + xmlNewProp( node, BAD_CAST "tooltip_posref_alt", + BAD_CAST TooltipHotSpotToString( _ToolTipParentPosRefAlt, _ToolTipPosRefAlt ).c_str() ); + + xmlNewProp( node, BAD_CAST "instant_help", BAD_CAST toString( _ToolTipInstant ).c_str() ); + + return node; + } + // *************************************************************************** void CCtrlBase::convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS) { @@ -339,6 +366,24 @@ namespace NLGUI } + std::string CCtrlBase::TooltipHotSpotToString( THotSpot parent, THotSpot child ) + { + std::string s; + + if( ( parent == Hotspot_TTAuto ) && ( child == Hotspot_TTAuto ) ) + { + s = "auto"; + } + else + { + s = CInterfaceElement::HotSpotToString( parent ); + s += " "; + s += CInterfaceElement::HotSpotToString( child ); + } + + return s; + } + // *************************************************************************** bool CCtrlBase::emptyContextHelp() const { diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index da466d529..f2e0e55b2 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -259,11 +259,11 @@ namespace NLGUI nlwarning( "Tried to set invalid property '%s' for widget '%s'", name.c_str(), _Id.c_str() ); } - bool CInterfaceElement::serialize( xmlNodePtr parentNode, const char *type ) const + xmlNodePtr CInterfaceElement::serialize( xmlNodePtr parentNode, const char *type ) const { xmlNodePtr node = xmlNewNode( NULL, BAD_CAST type ); if( node == NULL ) - return false; + return NULL; xmlAddChild( parentNode, node ); @@ -284,7 +284,7 @@ namespace NLGUI xmlNewProp( node, BAD_CAST "render_layer", BAD_CAST toString( _RenderLayer ).c_str() ); xmlNewProp( node, BAD_CAST "avoid_resize_parent", BAD_CAST toString( _AvoidResizeParent ).c_str() ); - return true; + return node; } // ------------------------------------------------------------------------------------------------ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp index 55dffa7d7..bf6a9f83e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp @@ -43,7 +43,7 @@ namespace GUIEditor return false; } - if( !mg->serialize( root, "root" ) ) + if( mg->serialize( root, "root" ) == NULL ) { xmlFreeNode( root ); out.close(); @@ -66,8 +66,12 @@ namespace GUIEditor xmlAttrPtr prop = node->properties; while( prop != NULL ) { - std::string name = std::string( (const char*)prop->name ); - std::string value = std::string( (const char*)xmlGetProp( node, BAD_CAST name.c_str() ) ); + std::string name = + std::string( reinterpret_cast< const char* >( prop->name ) ); + + std::string value = + std::string( reinterpret_cast< const char* >( xmlGetProp( node, BAD_CAST name.c_str() ) ) ); + out << " " << name << "=\"" << value << "\"" << std::endl; prop = prop->next;