From e1195fe34e2d39a6cce0d1a2a42f2138c1717e74 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 28 Oct 2020 15:30:17 +0800 Subject: [PATCH] Change CDBGroupComboBox to UTF-8, ryzom/ryzomcore#335 --- nel/include/nel/gui/dbgroup_combo_box.h | 28 +++--- nel/src/gui/dbgroup_combo_box.cpp | 96 +++++++++++-------- nel/src/gui/group_html.cpp | 2 +- .../src/interface_v3/action_handler_game.cpp | 26 ++--- .../src/interface_v3/action_handler_help.cpp | 2 +- .../bot_chat_page_dynamic_mission.cpp | 8 +- .../client/src/interface_v3/macrocmd_key.cpp | 11 +-- .../client/src/interface_v3/skill_manager.cpp | 2 +- 8 files changed, 95 insertions(+), 80 deletions(-) diff --git a/nel/include/nel/gui/dbgroup_combo_box.h b/nel/include/nel/gui/dbgroup_combo_box.h index 6f42572bb..61e447f4e 100644 --- a/nel/include/nel/gui/dbgroup_combo_box.h +++ b/nel/include/nel/gui/dbgroup_combo_box.h @@ -60,13 +60,15 @@ namespace NLGUI // Combo Texts void resetTexts(); - void addText(const ucstring &text); - void setText(uint i, const ucstring &text); - void insertText(uint i, const ucstring &text); - const ucstring &getText(uint i) const; + void addText(const std::string &text); + void setText(uint i, const std::string &text); + void insertText(uint i, const std::string &text); + const std::string &getText(uint i) const; + ucstring getTextAsUtf16(uint i) const; uint getTextId(uint i) const; uint getTextPos(uint nId) const; - const ucstring &getTexture(uint i) const; + const std::string &getTexture(uint i) const; + ucstring getTextureAsUtf16(uint i) const; void setGrayed(uint i, bool g); bool getGrayed(uint i) const; void removeText(uint nPos); @@ -87,11 +89,13 @@ namespace NLGUI std::string getSelectionText() const; // view text - void setViewText(const ucstring & text); - ucstring getViewText() const; + void setViewText(const std::string & text); + std::string getViewText() const; + void setViewTextAsUtf16(const ucstring &text) { setViewText(text.toUtf8()); } + ucstring getViewTextAsUtf16() const; CViewText *getViewText(); - void setTexture(uint i, const ucstring &texture); + void setTexture(uint i, const std::string &texture); sint32 evalContentWidth() const; @@ -122,7 +126,7 @@ namespace NLGUI REFLECT_LUA_METHOD("resetTexts", luaResetTexts) REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb) REFLECT_STRING ("selection_text", getSelectionText, setSelectionText) - REFLECT_UCSTRING ("view_text", getViewText, setViewText) + REFLECT_UCSTRING ("view_text", getViewTextAsUtf16, setViewTextAsUtf16) // FIXME: Better to have UTF-8 REFLECT_EXPORT_END @@ -137,8 +141,8 @@ namespace NLGUI // sint32 CInterfaceProperty _Selection; sint32 _NotLinkedToDBSelection; - std::vector > _Texts; - std::vector _Textures; + std::vector > _Texts; + std::vector _Textures; std::vector _Grayed; // Action Handler called on combo click @@ -155,7 +159,7 @@ namespace NLGUI CCtrlBaseButton *_SelectButton; bool _IsExternViewText; - ucstring _ExternViewText; + std::string _ExternViewText; private: diff --git a/nel/src/gui/dbgroup_combo_box.cpp b/nel/src/gui/dbgroup_combo_box.cpp index f7c49fee8..dd7f2154d 100644 --- a/nel/src/gui/dbgroup_combo_box.cpp +++ b/nel/src/gui/dbgroup_combo_box.cpp @@ -43,9 +43,9 @@ namespace NLGUI void force_link_dbgroup_combo_box_cpp() { } // Compare strings - static inline bool lt_text(const std::pair &s1, const std::pair &s2) + static inline bool lt_text(const std::pair &s1, const std::pair &s2) { - return toLower(s1.second) < toLower(s2.second); + return toLowerAsUtf8(s1.second) < toLowerAsUtf8(s2.second); } std::string CDBGroupComboBox::measureMenu; @@ -183,10 +183,10 @@ namespace NLGUI if (name) { const char *propPtr = name; - ucstring Text = ucstring::makeFromUtf8(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - Text = CI18N::get (propPtr); - addText(Text); + if (NLMISC::startsWith(propPtr, "ui")) + addText(CI18N::get(propPtr).toUtf8()); + else + addText(propPtr); } } child = child->next; @@ -240,11 +240,11 @@ namespace NLGUI } else if(_IsExternViewText) { - _ViewText->setText(_ExternViewText.toUtf8()); + _ViewText->setText(_ExternViewText); } else { - _ViewText->setText(_Texts[_CacheSelection].second.toUtf8()); + _ViewText->setText(_Texts[_CacheSelection].second); } } } @@ -274,7 +274,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::addText(const ucstring &text) + void CDBGroupComboBox::addText(const std::string &text) { dirt(); _Texts.push_back(make_pair((uint)_Texts.size(), text)); @@ -283,7 +283,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::setText(uint i, const ucstring &text) + void CDBGroupComboBox::setText(uint i, const std::string &text) { dirt(); if(i<_Texts.size()) @@ -291,7 +291,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::insertText(uint i, const ucstring &text) + void CDBGroupComboBox::insertText(uint i, const std::string &text) { dirt(); if(i<_Texts.size()) @@ -313,7 +313,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::setTexture(uint i, const ucstring &texture) + void CDBGroupComboBox::setTexture(uint i, const std::string &texture) { dirt(); if(i<_Textures.size()) @@ -351,13 +351,19 @@ namespace NLGUI } // *************************************************************************** - const ucstring &CDBGroupComboBox::getText(uint i) const + const std::string &CDBGroupComboBox::getText(uint i) const { - static ucstring null; - if(i<_Texts.size()) + static const std::string empty; + if (i < _Texts.size()) return _Texts[i].second; else - return null; + return empty; + } + + // *************************************************************************** + ucstring CDBGroupComboBox::getTextAsUtf16(uint i) const + { + return ucstring::makeFromUtf8(getText(i)); } // *************************************************************************** @@ -385,15 +391,21 @@ namespace NLGUI { sort(_Texts.begin(), _Texts.end(), lt_text); } - + // *************************************************************************** - const ucstring &CDBGroupComboBox::getTexture(uint i) const + const std::string &CDBGroupComboBox::getTexture(uint i) const { - static ucstring null; - if(i<_Textures.size()) + static const std::string empty; + if (i < _Textures.size()) return _Textures[i]; else - return null; + return empty; + } + + // *************************************************************************** + ucstring CDBGroupComboBox::getTextureAsUtf16(uint i) const + { + return ucstring::makeFromUtf8(getTexture(i)); } // *************************************************************************** @@ -452,8 +464,7 @@ namespace NLGUI sint32 value; for(uint i=0; isetText(_ExternViewText.toUtf8()); + _ViewText->setText(_ExternViewText); } // *************************************************************************** - ucstring CDBGroupComboBox::getViewText() const + std::string CDBGroupComboBox::getViewText() const + { + return _ViewText->getText(); + } + + // *************************************************************************** + ucstring CDBGroupComboBox::getViewTextAsUtf16() const { return CUtfStringView(_ViewText->getText()).toUtf16(); } @@ -486,18 +503,14 @@ namespace NLGUI // *************************************************************************** std::string CDBGroupComboBox::getSelectionText() const { - ucstring text; if (_LinkedToDB) { - text = getText(_Selection.getSInt32()); + return getText(_Selection.getSInt32()); } else { - text = getText(_NotLinkedToDBSelection); + return getText(_NotLinkedToDBSelection); } - std::string texteS; - text.toString(texteS); - return texteS; } // *************************************************************************** @@ -538,8 +551,7 @@ namespace NLGUI sint32 value; for(uint i=0; iaddLine(getText(i), "combo_box_select_end", toString(i), - "", std::string(), getTexture(i).toString(), checkable); + groupMenu->addLine(ucstring::makeFromUtf8(getText(i)), "combo_box_select_end", toString(i), + "", std::string(), getTexture(i), checkable); groupMenu->setGrayedLine(i, getGrayed(i)); } diff --git a/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index 7d9e48baf..e6b1ba473 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -6437,7 +6437,7 @@ namespace NLGUI if (cb) { uint lineIndex = cb->getNumTexts(); - cb->addText(_SelectOptionStr); + cb->addText(_SelectOptionStr.toUtf8()); if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex) { cb->setGrayed(lineIndex, true); diff --git a/ryzom/client/src/interface_v3/action_handler_game.cpp b/ryzom/client/src/interface_v3/action_handler_game.cpp index 19820be99..44c6e64fb 100644 --- a/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -3013,7 +3013,7 @@ void updateVRDevicesComboUI(bool enable) { std::stringstream displayname; displayname << std::string("[") << VRDeviceCache[i].first << "] [" << VRDeviceCache[i].second << "]"; - pCB->addText(ucstring(displayname.str())); + pCB->addText(displayname.str()); if (ClientCfg.VRDisplayDevice == VRDeviceCache[i].first) { if (selectedDevice == -1 || ClientCfg.VRDisplayDeviceId == VRDeviceCache[i].second) @@ -3027,7 +3027,7 @@ void updateVRDevicesComboUI(bool enable) // configured device not found, add a dummy std::stringstream displayname; displayname << std::string("[") << ClientCfg.VRDisplayDevice << "] [" << ClientCfg.VRDisplayDeviceId<< "] [DEVICE NOT FOUND]"; - pCB->addText(ucstring(displayname.str())); + pCB->addText(displayname.str()); selectedDevice = VRDeviceCache.size(); } NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->setValue32(-1); @@ -3062,7 +3062,7 @@ public: { pCB->resetTexts(); for (sint j = 0; j < (sint)stringModeList.size(); j++) - pCB->addText(ucstring(stringModeList[j])); + pCB->addText(stringModeList[j]); } // frequencies @@ -3071,7 +3071,7 @@ public: { pCB->resetTexts(); for (sint j = 0; j < (sint)stringFreqList.size(); j++) - pCB->addText(ucstring(stringFreqList[j])); + pCB->addText(stringFreqList[j]); } // -1 is important to indicate we set this value in edit mode @@ -3094,10 +3094,10 @@ public: if( pCB ) { pCB->resetTexts(); - pCB->addText(CI18N::get("uigcLowTextureMode")); - pCB->addText(CI18N::get("uigcNormalTextureMode")); + pCB->addText(CI18N::get("uigcLowTextureMode").toUtf8()); + pCB->addText(CI18N::get("uigcNormalTextureMode").toUtf8()); if(ClientCfg.HDTextureInstalled) - pCB->addText(CI18N::get("uigcHighTextureMode")); + pCB->addText(CI18N::get("uigcHighTextureMode").toUtf8()); } // Anisotropic Filtering @@ -3110,14 +3110,14 @@ public: sint maxAnisotropic = (sint)Driver->getAnisotropicFilterMaximum(); pCB->resetTexts(); - pCB->addText(CI18N::get("uigcFxAnisotropicFilterNone")); + pCB->addText(CI18N::get("uigcFxAnisotropicFilterNone").toUtf8()); sint anisotropic = 2; uint i = 1; while (anisotropic <= maxAnisotropic) { - pCB->addText(ucstring(NLMISC::toString("%dx", anisotropic))); + pCB->addText(NLMISC::toString("%dx", anisotropic)); if (ClientCfg.AnisotropicFilter == anisotropic) nAnisotropic = i; @@ -3222,7 +3222,7 @@ class CHandlerGameConfigMode : public IActionHandler // Get W, H sint w,h; { - string vidModeStr = pCB->getText(nVideModeNb).toString(); + string vidModeStr = pCB->getText(nVideModeNb); string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1); fromString(tmp, w); tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size()); @@ -3262,7 +3262,7 @@ class CHandlerGameConfigMode : public IActionHandler { pCB->resetTexts(); for (j = 0; j < (sint)stringFreqList.size(); j++) - pCB->addText(ucstring(stringFreqList[j]) + " Hz"); + pCB->addText(stringFreqList[j] + " Hz"); } NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(nFoundFreq); @@ -3464,7 +3464,7 @@ class CHandlerGameConfigApply : public IActionHandler CDBGroupComboBox *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO )); if( pCB != NULL ) { - string vidModeStr = pCB->getText(nVideModeNb).toString(); + string vidModeStr = pCB->getText(nVideModeNb); string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1); fromString(tmp, w); tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size()); @@ -3478,7 +3478,7 @@ class CHandlerGameConfigApply : public IActionHandler CDBGroupComboBox *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO )); if( pCB != NULL ) { - string vidFreqStr = pCB->getText(nVideoFreqNb).toString(); + string vidFreqStr = pCB->getText(nVideoFreqNb); fromString(vidFreqStr, freq); } } diff --git a/ryzom/client/src/interface_v3/action_handler_help.cpp b/ryzom/client/src/interface_v3/action_handler_help.cpp index 030d34bfe..6b699f8ee 100644 --- a/ryzom/client/src/interface_v3/action_handler_help.cpp +++ b/ryzom/client/src/interface_v3/action_handler_help.cpp @@ -2200,7 +2200,7 @@ static void setupRawMaterialStats(CSheetHelpSetup &setup) if(pIS->canBuildItemPart(faberType)) { - pCB->addText(RM_FABER_TYPE::toLocalString(faberType)); + pCB->addText(RM_FABER_TYPE::toLocalString(faberType).toUtf8()); } } diff --git a/ryzom/client/src/interface_v3/bot_chat_page_dynamic_mission.cpp b/ryzom/client/src/interface_v3/bot_chat_page_dynamic_mission.cpp index 1e9d56dc3..0fc03124a 100644 --- a/ryzom/client/src/interface_v3/bot_chat_page_dynamic_mission.cpp +++ b/ryzom/client/src/interface_v3/bot_chat_page_dynamic_mission.cpp @@ -156,7 +156,7 @@ void CBotChatPageDynamicMission::update() { if (ClientCfg.Local) { - _ChoiceCB[k]->setText(l, ucstring(toString("Dynamic mission %d:%d", (int) k, (int) l))); + _ChoiceCB[k]->setText(l, toString("Dynamic mission %d:%d", (int) k, (int) l)); _TextReceived[k][l] = true; } else @@ -167,7 +167,7 @@ void CBotChatPageDynamicMission::update() bool received = CStringManagerClient::instance()->getDynString(textID, result); if (received) { - _ChoiceCB[k]->setText(l, result); + _ChoiceCB[k]->setText(l, result.toUtf8()); _TextReceived[k][l] = true; } } @@ -183,13 +183,13 @@ void CBotChatPageDynamicMission::update() bool received = CStringManagerClient::instance()->getDynString(textID, result); if (received) { - _ChoiceCB[k]->addText(result); + _ChoiceCB[k]->addText(result.toUtf8()); _TextReceived[k][l] = true; } else { // add a text to show the player that the text is being received - _ChoiceCB[k]->addText(NLMISC::CI18N::get("uiWaitingChoiceFromServer")); + _ChoiceCB[k]->addText(NLMISC::CI18N::get("uiWaitingChoiceFromServer").toUtf8()); } } } diff --git a/ryzom/client/src/interface_v3/macrocmd_key.cpp b/ryzom/client/src/interface_v3/macrocmd_key.cpp index d9dfce119..9fce02ef8 100644 --- a/ryzom/client/src/interface_v3/macrocmd_key.cpp +++ b/ryzom/client/src/interface_v3/macrocmd_key.cpp @@ -492,7 +492,7 @@ void CModalContainerEditCmd::activate() } if (found) { - pCB->addText( CI18N::get(rVCat[i].LocalizedName) ); + pCB->addText(CI18N::get(rVCat[i].LocalizedName).toUtf8()); CurrentEditCmdCategories.push_back(rVCat[i].Name); } } @@ -1033,7 +1033,7 @@ void CModalContainerEditCmd::onChangeCategory() { if (rBA.isUsableInCurrentContext()) { - pCB->addText( CI18N::get(rBA.LocalizedName) ); + pCB->addText(CI18N::get(rBA.LocalizedName).toUtf8()); } } } @@ -1130,11 +1130,10 @@ void CModalContainerEditCmd::onChangeAction() if (ActionsContext.matchContext(rVal.Contexts)) { - if ((rVal.LocalizedValue.size() >= 2) && - (rVal.LocalizedValue[0] == 'u') && (rVal.LocalizedValue[1] == 'i')) - pCB->addText(CI18N::get(rVal.LocalizedValue)); + if (NLMISC::startsWith(rVal.LocalizedValue, "ui")) + pCB->addText(CI18N::get(rVal.LocalizedValue).toUtf8()); else - pCB->addText(ucstring(rVal.LocalizedValue)); + pCB->addText(rVal.LocalizedValue); } } } diff --git a/ryzom/client/src/interface_v3/skill_manager.cpp b/ryzom/client/src/interface_v3/skill_manager.cpp index c2f242921..5e91f6f6e 100644 --- a/ryzom/client/src/interface_v3/skill_manager.cpp +++ b/ryzom/client/src/interface_v3/skill_manager.cpp @@ -1097,7 +1097,7 @@ public: string titleStr = CHARACTER_TITLE::toString((CHARACTER_TITLE::ECharacterTitle)i); bool womenTitle = (UserEntity && UserEntity->getGender() == GSGENDER::female); const ucstring s(CStringManagerClient::getTitleLocalizedName(titleStr,womenTitle)); - pCB->addText(s); + pCB->addText(s.toUtf8()); pSM->_UIUnblockedTitles.push_back((CHARACTER_TITLE::ECharacterTitle)i); } }