More use StringUtf8ToWideChar and PlatformStringFromString

This commit is contained in:
Vladimir Perminov 2015-08-17 23:04:05 +03:00
parent a16d04fb53
commit 24d06bb1c9
4 changed files with 5 additions and 37 deletions

View File

@ -153,7 +153,7 @@ bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
bool CCFileUtilsWinRT::isDirectoryExistInternal(const std::string& dirPath) const
{
WIN32_FILE_ATTRIBUTE_DATA wfad;
std::wstring wdirPath(dirPath.begin(), dirPath.end());
std::wstring wdirPath = StringUtf8ToWideChar(dirPath);
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
{
return true;

View File

@ -84,10 +84,7 @@ void KeyboardEvent::execute()
{
case Cocos2dKeyEvent::Text:
{
std::wstring w(m_text.Get()->Data());
std::u16string s16(w.begin(),w.end());
std::string utf8String;
StringUtils::UTF16ToUTF8(s16, utf8String);
std::string utf8String = PlatformStringToString(m_text.Get());
IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), utf8String.size());
break;
}

View File

@ -354,7 +354,7 @@ void UIEditBoxImplWinrt::openKeyboard()
Windows::Foundation::EventHandler<Platform::String^>^ receiveHandler = ref new Windows::Foundation::EventHandler<Platform::String^>(
[this](Platform::Object^ sender, Platform::String^ arg)
{
setText(PlatformStringTostring(arg).c_str());
setText(PlatformStringToString(arg).c_str());
if (_delegate != NULL) {
_delegate->editBoxTextChanged(_editBox, getText());
_delegate->editBoxEditingDidEnd(_editBox);
@ -362,10 +362,10 @@ void UIEditBoxImplWinrt::openKeyboard()
}
});
m_editBoxWinrt = ref new EditBoxWinRT(stringToPlatformString(placeHolder), stringToPlatformString(getText()), m_nMaxLength, m_eEditBoxInputMode, m_eEditBoxInputFlag, receiveHandler);
m_editBoxWinrt = ref new EditBoxWinRT(PlatformStringFromString(placeHolder), PlatformStringFromString(getText()), m_nMaxLength, m_eEditBoxInputMode, m_eEditBoxInputFlag, receiveHandler);
}
m_editBoxWinrt->OpenXamlEditBox(stringToPlatformString(getText()));
m_editBoxWinrt->OpenXamlEditBox(PlatformStringFromString(getText()));
}
bool UIEditBoxImplWinrt::initWithSize( const Size& size )
@ -570,32 +570,6 @@ void UIEditBoxImplWinrt::onEnter( void )
}
Platform::String^ UIEditBoxImplWinrt::stringToPlatformString( std::string strSrc )
{
// to wide char
int nStrLen = MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, NULL, 0);
wchar_t* pWStr = new wchar_t[nStrLen + 1];
memset(pWStr, 0, nStrLen + 1);
MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, pWStr, nStrLen);
Platform::String^ strDst = ref new Platform::String(pWStr);
delete[] pWStr;
return strDst;
}
std::string UIEditBoxImplWinrt::PlatformStringTostring( Platform::String^ strSrc )
{
const wchar_t* pWStr = strSrc->Data();
int nStrLen = WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, NULL, 0, NULL, NULL);
char* pStr = new char[nStrLen + 1];
memset(pStr, 0, nStrLen + 1);
WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, pStr, nStrLen, NULL, NULL); ;
std::string strDst = std::string(pStr);
delete[] pStr;
return strDst;
}
}
NS_CC_END

View File

@ -116,9 +116,6 @@ namespace ui {
virtual void closeKeyboard();
virtual void onEnter(void);
private:
Platform::String^ stringToPlatformString(std::string strSrc);
std::string PlatformStringTostring(Platform::String^ strSrc);
private:
EditBoxWinRT^ m_editBoxWinrt;