Fix formspec label issues in win builds (MSVC)

This commit is contained in:
BlockMen 2013-08-03 17:57:51 +02:00 committed by PilzAdam
parent 2af5864534
commit be4670fecf
2 changed files with 39 additions and 61 deletions

@ -83,5 +83,12 @@ inline void changeCtype(const char *l)
else else
infostream<<"locale has been set to:"<<ret<<std::endl;*/ infostream<<"locale has been set to:"<<ret<<std::endl;*/
} }
inline std::wstring wstrgettext(std::string text) {
wchar_t* wlabel = wgettext(text.c_str());
std::wstring out = (std::wstring)wlabel;
delete[] wlabel;
return out;
}
#define GETTEXT_HEADER #define GETTEXT_HEADER
#endif #endif

@ -411,29 +411,24 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element) {
if (selected == "true") if (selected == "true")
fselected = true; fselected = true;
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(label.c_str());
if (m_use_gettext) if (m_use_gettext)
wlabel = wgettext(label.c_str()); wlabel = wstrgettext(label);
else
wlabel = (wchar_t*) narrow_to_wide(label.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
narrow_to_wide(""), L"",
wlabel, wlabel,
258+m_fields.size() 258+m_fields.size()
); );
spec.ftype = f_CheckBox; spec.ftype = f_CheckBox;
spec.flabel = wlabel; //Needed for displaying text on MSVC
gui::IGUICheckBox* e = Environment->addCheckBox(fselected, rect, this, gui::IGUICheckBox* e = Environment->addCheckBox(fselected, rect, this,
spec.fid, wlabel); spec.fid, spec.flabel.c_str());
m_checkboxes.push_back(std::pair<FieldSpec,gui::IGUICheckBox*>(spec,e)); m_checkboxes.push_back(std::pair<FieldSpec,gui::IGUICheckBox*>(spec,e));
m_fields.push_back(spec); m_fields.push_back(spec);
if (m_use_gettext)
delete[] wlabel;
return; return;
} }
errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl;
@ -547,17 +542,15 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,std::stri
label = unescape_string(label); label = unescape_string(label);
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(label.c_str());
if (m_use_gettext) if (m_use_gettext)
wlabel = wgettext(label.c_str()); wlabel = wstrgettext(label);
else
wlabel = (wchar_t*) narrow_to_wide(label.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
wlabel, wlabel,
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );
spec.ftype = f_Button; spec.ftype = f_Button;
@ -566,8 +559,6 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,std::stri
Environment->addButton(rect, this, spec.fid, spec.flabel.c_str()); Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
m_fields.push_back(spec); m_fields.push_back(spec);
if (m_use_gettext)
delete[] wlabel;
return; return;
} }
errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl;
@ -639,8 +630,8 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
fname_w, fname_w,
narrow_to_wide(""), L"",
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );
@ -720,8 +711,8 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element) {
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
fname_w, fname_w,
narrow_to_wide(""), L"",
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );
@ -782,21 +773,19 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element) {
label = unescape_string(label); label = unescape_string(label);
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(label.c_str());
if (m_use_gettext) { if (m_use_gettext) {
if (label.length() > 1) if (label.length() > 1)
wlabel = wgettext(label.c_str()); wlabel = wstrgettext(label);
else else
wlabel = (wchar_t*) narrow_to_wide("").c_str(); wlabel = L"";
} }
else
wlabel = (wchar_t*) narrow_to_wide(label.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
wlabel, wlabel,
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );
@ -819,8 +808,6 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element) {
evt.KeyInput.PressedDown = true; evt.KeyInput.PressedDown = true;
e->OnEvent(evt); e->OnEvent(evt);
m_fields.push_back(spec); m_fields.push_back(spec);
if ((m_use_gettext) && (label.length() >1))
delete[] wlabel;
return; return;
} }
errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl;
@ -862,16 +849,14 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,std::vector<std::string>
default_val = unescape_string(default_val); default_val = unescape_string(default_val);
label = unescape_string(label); label = unescape_string(label);
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(label.c_str());
if (m_use_gettext) { if (m_use_gettext) {
if (label.length() > 1) if (label.length() > 1)
wlabel = wgettext(label.c_str()); wlabel = wstrgettext(label);
else else
wlabel = (wchar_t*) narrow_to_wide("").c_str(); wlabel = L"";
} }
else
wlabel = (wchar_t*) narrow_to_wide(label.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
@ -904,8 +889,6 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,std::vector<std::string>
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0); Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
} }
} }
if (m_use_gettext && (label.length() > 1))
delete[] wlabel;
m_fields.push_back(spec); m_fields.push_back(spec);
} }
@ -953,16 +936,14 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,std::vector<std::string>& p
default_val = unescape_string(default_val); default_val = unescape_string(default_val);
label = unescape_string(label); label = unescape_string(label);
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(label.c_str());
if (m_use_gettext) { if (m_use_gettext) {
if (label.length() > 1) if (label.length() > 1)
wlabel = wgettext(label.c_str()); wlabel = wstrgettext(label);
else else
wlabel = (wchar_t*) narrow_to_wide("").c_str(); wlabel = L"";
} }
else
wlabel = (wchar_t*) narrow_to_wide(label.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
@ -1004,8 +985,6 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,std::vector<std::string>& p
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0); Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
} }
} }
if (m_use_gettext && (label.length() > 1))
delete[] wlabel;
m_fields.push_back(spec); m_fields.push_back(spec);
} }
@ -1044,23 +1023,19 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element) {
text = unescape_string(text); text = unescape_string(text);
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(text.c_str());
if (m_use_gettext) if (m_use_gettext)
wlabel = wgettext(text.c_str()); wlabel = wstrgettext(text);
else
wlabel = (wchar_t*) narrow_to_wide(text.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(""), L"",
wlabel, wlabel,
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid); Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
m_fields.push_back(spec); m_fields.push_back(spec);
if (m_use_gettext)
delete[] wlabel;
return; return;
} }
errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl;
@ -1099,9 +1074,9 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element) {
} }
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(""), L"",
narrow_to_wide(label.c_str()), narrow_to_wide(label.c_str()),
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );
gui::IGUIStaticText *t = gui::IGUIStaticText *t =
@ -1157,12 +1132,10 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std:
label = unescape_string(label); label = unescape_string(label);
wchar_t* wlabel = 0; std::wstring wlabel = narrow_to_wide(label.c_str());
if (m_use_gettext) if (m_use_gettext)
wlabel = wgettext(label.c_str()); wlabel = wstrgettext(label);
else
wlabel = (wchar_t*) narrow_to_wide(label.c_str()).c_str();
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
@ -1205,8 +1178,6 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std:
e->setDrawBorder(drawborder); e->setDrawBorder(drawborder);
m_fields.push_back(spec); m_fields.push_back(spec);
if (m_use_gettext)
delete[] wlabel;
return; return;
} }
@ -1236,8 +1207,8 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element) {
FieldSpec spec = FieldSpec( FieldSpec spec = FieldSpec(
narrow_to_wide(name.c_str()), narrow_to_wide(name.c_str()),
narrow_to_wide(""), L"",
narrow_to_wide(""), L"",
258+m_fields.size() 258+m_fields.size()
); );