1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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>
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/>.
23 #include "nel/gui/view_text_formated.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/misc/i18n.h"
31 NLMISC_REGISTER_OBJECT(CViewBase
, CViewTextFormated
, std::string
, "text_formated");
36 CViewTextFormated::IViewTextFormatter
*CViewTextFormated::textFormatter
= NULL
;
38 std::string
CViewTextFormated::getProperty(const std::string
&name
) const
42 return getFormatString();
45 return CViewText::getProperty(name
);
48 void CViewTextFormated::setProperty(const std::string
&name
, const std::string
&value
)
52 setFormatString(value
);
56 CViewText::setProperty(name
, value
);
59 xmlNodePtr
CViewTextFormated::serialize( xmlNodePtr parentNode
, const char *type
) const
61 xmlNodePtr node
= CViewText::serialize( parentNode
, type
);
65 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"text_formated" );
66 xmlSetProp( node
, BAD_CAST
"format", BAD_CAST
getFormatString().c_str() );
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" ));
77 setFormatString((const char *)prop
);
79 setFormatString("$t");
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
);
101 _FormatString
= format
;
104 // ****************************************************************************
105 std::string
CViewTextFormated::formatString(const std::string
&inputString
, const std::string
¶mString
)
107 std::string formatedResult
;
109 if( textFormatter
== NULL
)
110 formatedResult
= inputString
;
112 formatedResult
= CViewTextFormated::textFormatter
->formatString( inputString
, paramString
);
114 return formatedResult
;