Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / nel / src / gui / view_text_formated.cpp
blob5377737886d88f34e3ed0948f1ef81e157f3265e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdpch.h"
23 #include "nel/gui/view_text_formated.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/misc/i18n.h"
27 #ifdef DEBUG_NEW
28 #define new DEBUG_NEW
29 #endif
31 NLMISC_REGISTER_OBJECT(CViewBase, CViewTextFormated, std::string, "text_formated");
33 namespace NLGUI
36 CViewTextFormated::IViewTextFormatter *CViewTextFormated::textFormatter = NULL;
38 std::string CViewTextFormated::getProperty(const std::string &name) const
40 if (name == "format")
42 return getFormatString();
44 else
45 return CViewText::getProperty(name);
48 void CViewTextFormated::setProperty(const std::string &name, const std::string &value)
50 if (name == "format")
52 setFormatString(value);
53 return;
55 else
56 CViewText::setProperty(name, value);
59 xmlNodePtr CViewTextFormated::serialize( xmlNodePtr parentNode, const char *type ) const
61 xmlNodePtr node = CViewText::serialize( parentNode, type );
62 if( node == NULL )
63 return NULL;
65 xmlSetProp( node, BAD_CAST "type", BAD_CAST "text_formated" );
66 xmlSetProp( node, BAD_CAST "format", BAD_CAST getFormatString().c_str() );
68 return NULL;
71 // ****************************************************************************
72 bool CViewTextFormated::parse(xmlNodePtr cur,CInterfaceGroup * parentGroup)
74 if (!CViewText::parse(cur, parentGroup)) return false;
75 CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"format" ));
76 if (prop)
77 setFormatString((const char *)prop);
78 else
79 setFormatString("$t");
80 return true;
83 // ****************************************************************************
84 void CViewTextFormated::checkCoords()
86 if (!getActive()) return;
87 std::string formatedResult;
88 formatedResult = formatString(_FormatString, std::string());
91 setText (formatedResult);
92 CViewText::checkCoords();
95 // ****************************************************************************
96 void CViewTextFormated::setFormatString(const std::string &format)
98 if (NLMISC::startsWith(format, "ui"))
99 _FormatString = NLMISC::CI18N::get(format);
100 else
101 _FormatString = format;
104 // ****************************************************************************
105 std::string CViewTextFormated::formatString(const std::string &inputString, const std::string &paramString)
107 std::string formatedResult;
109 if( textFormatter == NULL )
110 formatedResult = inputString;
111 else
112 formatedResult = CViewTextFormated::textFormatter->formatString( inputString, paramString );
114 return formatedResult;