Partially support Unicode strings in GUI XML files

This was SVN commit r7594.
This commit is contained in:
Ykkrosh 2010-05-30 13:11:32 +00:00
parent 5b9d29729a
commit 4ff8d8742c
8 changed files with 48 additions and 44 deletions

View File

@ -1237,7 +1237,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
ManuallySetZ = true; ManuallySetZ = true;
// Try setting the value // Try setting the value
if (object->SetSetting(pFile->GetAttributeString(attr.Name), CStr(attr.Value), true) != PSRETURN_OK) if (object->SetSetting(pFile->GetAttributeString(attr.Name), CStrW(attr.Value), true) != PSRETURN_OK)
{ {
LOGERROR(L"GUI: (object: %hs) Can't set \"%hs\" to \"%ls\"", object->GetPresentableName().c_str(), pFile->GetAttributeString(attr.Name).c_str(), CStrW(attr.Value).c_str()); LOGERROR(L"GUI: (object: %hs) Can't set \"%hs\" to \"%ls\"", object->GetPresentableName().c_str(), pFile->GetAttributeString(attr.Name).c_str(), CStrW(attr.Value).c_str());

View File

@ -193,7 +193,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
} }
// Clear the caption // Clear the caption
usedobj->SetSetting("caption", ""); usedobj->SetSetting("caption", L"");
usedobj->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, "caption")); usedobj->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, "caption"));

View File

@ -161,7 +161,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
{ {
CSize displacement; CSize displacement;
// Parse the value // Parse the value
if (!GUI<CSize>::ParseString(itTextChunk->m_Tags[0].m_TagAdditionalValue, displacement)) if (!GUI<CSize>::ParseString(CStrW(itTextChunk->m_Tags[0].m_TagAdditionalValue), displacement))
LOG(CLogger::Error, LOG_CATEGORY, L"Error parsing 'displace' value for tag [ICON]"); LOG(CLogger::Error, LOG_CATEGORY, L"Error parsing 'displace' value for tag [ICON]");
else else
SpriteCall.m_Area += displacement; SpriteCall.m_Area += displacement;
@ -207,7 +207,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
TextCall.m_UseCustomColor = true; TextCall.m_UseCustomColor = true;
// Try parsing the color std::string // Try parsing the color std::string
if (!GUI<CColor>::ParseString(it2->m_TagValue, TextCall.m_Color)) if (!GUI<CColor>::ParseString(CStrW(it2->m_TagValue), TextCall.m_Color))
{ {
if (pObject) if (pObject)
LOG(CLogger::Error, LOG_CATEGORY, L"Error parsing the value of a [color]-tag in GUI text when reading object \"%hs\".", pObject->GetPresentableName().c_str()); LOG(CLogger::Error, LOG_CATEGORY, L"Error parsing the value of a [color]-tag in GUI text when reading object \"%hs\".", pObject->GetPresentableName().c_str());

View File

@ -32,12 +32,12 @@ extern int g_yres;
template <> template <>
bool __ParseString<bool>(const CStr& Value, bool &Output) bool __ParseString<bool>(const CStrW& Value, bool &Output)
{ {
if (Value == "true") if (Value == L"true")
Output = true; Output = true;
else else
if (Value == "false") if (Value == L"false")
Output = false; Output = false;
else else
return false; return false;
@ -46,26 +46,26 @@ bool __ParseString<bool>(const CStr& Value, bool &Output)
} }
template <> template <>
bool __ParseString<int>(const CStr& Value, int &Output) bool __ParseString<int>(const CStrW& Value, int &Output)
{ {
Output = Value.ToInt(); Output = Value.ToInt();
return true; return true;
} }
template <> template <>
bool __ParseString<float>(const CStr& Value, float &Output) bool __ParseString<float>(const CStrW& Value, float &Output)
{ {
Output = Value.ToFloat(); Output = Value.ToFloat();
return true; return true;
} }
template <> template <>
bool __ParseString<CRect>(const CStr& Value, CRect &Output) bool __ParseString<CRect>(const CStrW& Value, CRect &Output)
{ {
// Use the parser to parse the values // Use the parser to parse the values
CParser& parser (CParserCache::Get("_$value_$value_$value_$value_")); CParser& parser (CParserCache::Get("_$value_$value_$value_$value_"));
std::string str = Value; std::string str = CStr(Value);
CParserLine line; CParserLine line;
line.ParseString(parser, str); line.ParseString(parser, str);
@ -90,13 +90,13 @@ bool __ParseString<CRect>(const CStr& Value, CRect &Output)
} }
template <> template <>
bool __ParseString<CClientArea>(const CStr& Value, CClientArea &Output) bool __ParseString<CClientArea>(const CStrW& Value, CClientArea &Output)
{ {
return Output.SetClientArea(Value); return Output.SetClientArea(Value);
} }
template <> template <>
bool GUI<int>::ParseColor(const CStr& Value, CColor &Output, float DefaultAlpha) bool GUI<int>::ParseColor(const CStrW& Value, CColor &Output, float DefaultAlpha)
{ {
// First, check our database in g_GUI for pre-defined colors // First, check our database in g_GUI for pre-defined colors
// If we find anything, we'll ignore DefaultAlpha // If we find anything, we'll ignore DefaultAlpha
@ -109,7 +109,7 @@ bool GUI<int>::ParseColor(const CStr& Value, CColor &Output, float DefaultAlpha)
template <> template <>
bool __ParseString<CColor>(const CStr& Value, CColor &Output) bool __ParseString<CColor>(const CStrW& Value, CColor &Output)
{ {
// First, check our database in g_GUI for pre-defined colors // First, check our database in g_GUI for pre-defined colors
// If it fails, it won't do anything with Output // If it fails, it won't do anything with Output
@ -120,12 +120,12 @@ bool __ParseString<CColor>(const CStr& Value, CColor &Output)
} }
template <> template <>
bool __ParseString<CSize>(const CStr& Value, CSize &Output) bool __ParseString<CSize>(const CStrW& Value, CSize &Output)
{ {
// Use the parser to parse the values // Use the parser to parse the values
CParser& parser (CParserCache::Get("_$value_$value_")); CParser& parser (CParserCache::Get("_$value_$value_"));
std::string str = Value; std::string str = CStr(Value);
CParserLine line; CParserLine line;
line.ParseString(parser, str); line.ParseString(parser, str);
@ -158,12 +158,12 @@ bool __ParseString<CSize>(const CStr& Value, CSize &Output)
} }
template <> template <>
bool __ParseString<CPos>(const CStr& Value, CPos &Output) bool __ParseString<CPos>(const CStrW& Value, CPos &Output)
{ {
CParser& parser (CParserCache::Get("_[-$arg(_minus)]$value_[-$arg(_minus)]$value_")); CParser& parser (CParserCache::Get("_[-$arg(_minus)]$value_[-$arg(_minus)]$value_"));
CParserLine line; CParserLine line;
line.ParseString(parser, Value); line.ParseString(parser, CStr(Value));
if (!line.m_ParseOK) if (!line.m_ParseOK)
return false; return false;
@ -180,15 +180,15 @@ bool __ParseString<CPos>(const CStr& Value, CPos &Output)
} }
template <> template <>
bool __ParseString<EAlign>(const CStr& Value, EAlign &Output) bool __ParseString<EAlign>(const CStrW& Value, EAlign &Output)
{ {
if (Value == "left") if (Value == L"left")
Output = EAlign_Left; Output = EAlign_Left;
else else
if (Value == "center") if (Value == L"center")
Output = EAlign_Center; Output = EAlign_Center;
else else
if (Value == "right") if (Value == L"right")
Output = EAlign_Right; Output = EAlign_Right;
else else
return false; return false;
@ -197,15 +197,15 @@ bool __ParseString<EAlign>(const CStr& Value, EAlign &Output)
} }
template <> template <>
bool __ParseString<EVAlign>(const CStr& Value, EVAlign &Output) bool __ParseString<EVAlign>(const CStrW& Value, EVAlign &Output)
{ {
if (Value == "top") if (Value == L"top")
Output = EVAlign_Top; Output = EVAlign_Top;
else else
if (Value == "center") if (Value == L"center")
Output = EVAlign_Center; Output = EVAlign_Center;
else else
if (Value == "bottom") if (Value == L"bottom")
Output = EVAlign_Bottom; Output = EVAlign_Bottom;
else else
return false; return false;
@ -214,17 +214,16 @@ bool __ParseString<EVAlign>(const CStr& Value, EVAlign &Output)
} }
template <> template <>
bool __ParseString<CGUIString>(const CStr& Value, CGUIString &Output) bool __ParseString<CGUIString>(const CStrW& Value, CGUIString &Output)
{ {
// Translate the Value and retrieve the localised string in // TODO: i18n: Might want to translate the Value perhaps
// Unicode.
Output.SetValue(I18n::translate((CStrW)Value)); Output.SetValue(Value);
return true; return true;
} }
template <> template <>
bool __ParseString<CStr>(const CStr& Value, CStr&Output) bool __ParseString<CStr>(const CStrW& Value, CStr& Output)
{ {
// Do very little. // Do very little.
Output = Value; Output = Value;
@ -232,24 +231,23 @@ bool __ParseString<CStr>(const CStr& Value, CStr&Output)
} }
template <> template <>
bool __ParseString<CStrW>(const CStr& Value, CStrW& Output) bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output)
{ {
// Translate the Value and retrieve the localised string in // TODO: i18n: Might want to translate the Value perhaps
// Unicode.
Output = I18n::translate((CStrW)Value); Output = Value;
return true; return true;
} }
template <> template <>
bool __ParseString<CGUISpriteInstance>(const CStr& Value, CGUISpriteInstance &Output) bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance &Output)
{ {
Output = Value; Output = Value;
return true; return true;
} }
template <> template <>
bool __ParseString<CGUIList>(const CStr& UNUSED(Value), CGUIList& UNUSED(Output)) bool __ParseString<CGUIList>(const CStrW& UNUSED(Value), CGUIList& UNUSED(Output))
{ {
return false; return false;
} }

View File

@ -52,7 +52,7 @@ class CClientArea;
class CGUIString; class CGUIString;
template <typename T> template <typename T>
bool __ParseString(const CStr& Value, T &tOutput); bool __ParseString(const CStrW& Value, T &tOutput);
// Load Identity matrix and // Load Identity matrix and
// adapt (origio) to being in top left corner and down // adapt (origio) to being in top left corner and down
@ -231,12 +231,12 @@ public:
* *
* @see __ParseString() * @see __ParseString()
*/ */
static bool ParseString(const CStr& Value, T &tOutput) static bool ParseString(const CStrW& Value, T &tOutput)
{ {
return __ParseString<T>(Value, tOutput); return __ParseString<T>(Value, tOutput);
} }
static bool ParseColor(const CStr& Value, CColor &tOutput, float DefaultAlpha); static bool ParseColor(const CStrW& Value, CColor &tOutput, float DefaultAlpha);
private: private:

View File

@ -254,7 +254,7 @@ bool IGUIObject::SettingExists(const CStr& Setting) const
GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \ GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \
} }
PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage) PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage)
{ {
if (!SettingExists(Setting)) if (!SettingExists(Setting))
{ {

View File

@ -272,7 +272,7 @@ public:
* *
* @return PSERROR (PSRETURN_OK if successful) * @return PSERROR (PSRETURN_OK if successful)
*/ */
PSRETURN SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage=false); PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage=false);
/** /**
* Retrieves the type of a named setting. * Retrieves the type of a named setting.

View File

@ -427,7 +427,10 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
{ {
if (JSVAL_IS_STRING(*vp)) if (JSVAL_IS_STRING(*vp))
{ {
if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PSRETURN_OK) std::wstring value;
StringConvert::jsstring_to_wstring(JS_ValueToString(cx, *vp), value);
if (e->SetSetting(propName, value) != PSRETURN_OK)
{ {
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
return JS_FALSE; return JS_FALSE;
@ -464,7 +467,10 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
{ {
if (JSVAL_IS_STRING(*vp)) if (JSVAL_IS_STRING(*vp))
{ {
if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PSRETURN_OK) std::wstring value;
StringConvert::jsstring_to_wstring(JS_ValueToString(cx, *vp), value);
if (e->SetSetting(propName, value) != PSRETURN_OK)
{ {
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
return JS_FALSE; return JS_FALSE;