2014-08-19 10:28:24 +08:00
|
|
|
/****************************************************************************
|
2017-05-17 16:20:21 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013 Jozef Pridavok
|
|
|
|
Copyright (c) 2013-2017 zilongshanren
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2017-05-17 16:20:21 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "ui/UIEditBox/UIEditBoxImpl-win32.h"
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformConfig.h"
|
2014-08-19 10:28:24 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "ui/UIEditBox/UIEditBox.h"
|
2014-09-24 17:47:38 +08:00
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "2d/CCLabel.h"
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/ccUTF8.h"
|
2017-05-17 16:20:21 +08:00
|
|
|
#include <Commctrl.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include "ui/UIHelper.h"
|
2014-09-24 17:47:38 +08:00
|
|
|
|
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
NS_CC_BEGIN
|
2014-09-24 17:47:38 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
namespace ui {
|
2014-09-24 17:47:38 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
bool EditBoxImplWin::s_isInitialized = false;
|
|
|
|
int EditBoxImplWin::s_editboxChildID = 100;
|
|
|
|
HWND EditBoxImplWin::s_previousFocusWnd = 0;
|
|
|
|
WNDPROC EditBoxImplWin::s_prevCocosWndProc = 0;
|
|
|
|
HINSTANCE EditBoxImplWin::s_hInstance = 0;
|
|
|
|
HWND EditBoxImplWin::s_hwndCocos = 0;
|
2014-09-24 17:47:38 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::lazyInit()
|
|
|
|
{
|
|
|
|
s_hwndCocos = cocos2d::Director::getInstance()->getOpenGLView()->getWin32Window();
|
2017-12-22 09:14:27 +08:00
|
|
|
LONG style = ::GetWindowLongW(s_hwndCocos, GWL_STYLE);
|
|
|
|
::SetWindowLongW(s_hwndCocos, GWL_STYLE, style | WS_CLIPCHILDREN);
|
2017-05-17 16:20:21 +08:00
|
|
|
s_isInitialized = true;
|
|
|
|
s_previousFocusWnd = s_hwndCocos;
|
2015-08-05 07:54:50 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
s_hInstance = ::GetModuleHandleW(nullptr);
|
2014-09-24 17:47:38 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
s_prevCocosWndProc = (WNDPROC)SetWindowLongPtrW(s_hwndCocos, GWL_WNDPROC, (LONG_PTR)hookGLFWWindowProc);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
EditBoxImpl* __createSystemEditBox(EditBox* pEditBox)
|
|
|
|
{
|
|
|
|
return new (std::nothrow) EditBoxImplWin(pEditBox);
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
EditBoxImplWin::EditBoxImplWin(EditBox* pEditText)
|
|
|
|
: EditBoxImplCommon(pEditText),
|
2018-09-10 11:23:14 +08:00
|
|
|
_hwndEdit(NULL),
|
2017-05-17 16:20:21 +08:00
|
|
|
_changedTextManually(false),
|
2017-12-22 09:14:27 +08:00
|
|
|
_hasFocus(false),
|
|
|
|
_endAction(EditBoxDelegate::EditBoxEndAction::UNKNOWN)
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
|
|
|
if (!s_isInitialized)
|
|
|
|
{
|
|
|
|
lazyInit();
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
s_editboxChildID++;
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
EditBoxImplWin::~EditBoxImplWin()
|
|
|
|
{
|
|
|
|
this->cleanupEditCtrl();
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
bool EditBoxImplWin::isEditing()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::cleanupEditCtrl()
|
2015-11-06 02:14:34 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
if (_hwndEdit)
|
2015-11-06 02:14:34 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
SetWindowLongPtrW(_hwndEdit, GWL_WNDPROC, (LONG_PTR)_prevWndProc);
|
|
|
|
::DestroyWindow(_hwndEdit);
|
2017-05-17 16:20:21 +08:00
|
|
|
_hasFocus = false;
|
|
|
|
_changedTextManually = false;
|
|
|
|
_editingMode = false;
|
2017-12-22 09:14:27 +08:00
|
|
|
_hwndEdit = NULL;
|
2015-11-06 02:14:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
void EditBoxImplWin::createEditCtrl(bool singleLine)
|
2015-11-06 02:14:34 +08:00
|
|
|
{
|
2017-05-17 16:20:21 +08:00
|
|
|
this->cleanupEditCtrl();
|
2017-12-22 09:14:27 +08:00
|
|
|
if (!_hwndEdit)
|
2015-11-06 02:14:34 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
_hwndEdit = ::CreateWindowExW(
|
2017-05-17 16:20:21 +08:00
|
|
|
WS_EX_CLIENTEDGE, L"EDIT", // predefined class
|
|
|
|
NULL, // no window title
|
2017-12-22 09:14:27 +08:00
|
|
|
WS_CHILD | ES_LEFT | WS_BORDER | WS_EX_TRANSPARENT | WS_TABSTOP | ES_AUTOHSCROLL | (singleLine ? 0 : ES_MULTILINE),
|
2017-05-17 16:20:21 +08:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, // set size in WM_SIZE message
|
|
|
|
s_hwndCocos, // parent window
|
|
|
|
(HMENU)s_editboxChildID, // edit control ID
|
|
|
|
s_hInstance,
|
|
|
|
this); // pointer not needed
|
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
SetWindowLongPtrW(_hwndEdit, GWL_USERDATA, (LONG_PTR)this);
|
|
|
|
_prevWndProc = (WNDPROC)SetWindowLongPtrW(_hwndEdit, GWL_WNDPROC, (LONG_PTR)WindowProc);
|
2017-05-17 16:20:21 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
::SendMessageW(_hwndEdit, EM_LIMITTEXT, this->_maxLength, 0);
|
2017-05-17 16:20:21 +08:00
|
|
|
s_previousFocusWnd = s_hwndCocos;
|
|
|
|
this->setNativeFont(this->getNativeDefaultFontName(), this->_fontSize);
|
|
|
|
this->setNativeText(this->_text.c_str());
|
2015-11-06 02:14:34 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
void EditBoxImplWin::createNativeControl(const Rect& frame)
|
2015-11-06 02:14:34 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->createEditCtrl(false);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
void EditBoxImplWin::setNativeFont(const char* pFontName, int fontSize)
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
2017-12-08 18:18:04 +08:00
|
|
|
auto glView = Director::getInstance()->getOpenGLView();
|
2017-12-22 09:14:27 +08:00
|
|
|
HFONT hFont = ::CreateFontW(static_cast<int>(fontSize * glView->getScaleX()), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
|
|
|
|
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, L"Arial");
|
2017-05-17 16:20:21 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
::SendMessageW(_hwndEdit, // Handle of edit control
|
2017-05-17 16:20:21 +08:00
|
|
|
WM_SETFONT, // Message to change the font
|
|
|
|
(WPARAM)hFont, // handle of the font
|
|
|
|
MAKELPARAM(TRUE, 0) // Redraw text
|
|
|
|
);
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
void EditBoxImplWin::setNativeFontColor(const Color4B& color)
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
|
|
|
//not implemented yet
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
void EditBoxImplWin::setNativePlaceholderFont(const char* pFontName, int fontSize)
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
|
|
|
//not implemented yet
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativePlaceholderFontColor(const Color4B& color)
|
|
|
|
{
|
|
|
|
//not implemented yet
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativeInputMode(EditBox::InputMode inputMode)
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-05-17 16:20:21 +08:00
|
|
|
if (_editBoxInputMode == cocos2d::ui::EditBox::InputMode::ANY)
|
2015-08-05 07:54:50 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->createEditCtrl(false);
|
2015-08-05 07:54:50 +08:00
|
|
|
}
|
2017-05-17 16:20:21 +08:00
|
|
|
else if (_editBoxInputMode == cocos2d::ui::EditBox::InputMode::NUMERIC
|
|
|
|
|| _editBoxInputMode == cocos2d::ui::EditBox::InputMode::DECIMAL
|
|
|
|
|| _editBoxInputMode == cocos2d::ui::EditBox::InputMode::PHONE_NUMBER)
|
2015-08-05 07:54:50 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->createEditCtrl(true);
|
|
|
|
::SetWindowLongW(_hwndEdit, GWL_STYLE, ::GetWindowLongW(_hwndEdit, GWL_STYLE) | ES_NUMBER);
|
2015-08-05 07:54:50 +08:00
|
|
|
}
|
2017-05-17 16:20:21 +08:00
|
|
|
else
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->createEditCtrl(true);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
2015-11-06 02:14:34 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
if (this->_editBoxInputFlag != cocos2d::ui::EditBox::InputFlag::PASSWORD)
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::PostMessageW(_hwndEdit, EM_SETPASSWORDCHAR, (WPARAM)0, (LPARAM)0);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void EditBoxImplWin::setNativeInputFlag(EditBox::InputFlag inputFlag)
|
|
|
|
{
|
|
|
|
if (inputFlag == EditBox::InputFlag::PASSWORD)
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->createEditCtrl(true);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_editBoxInputMode != cocos2d::ui::EditBox::InputMode::ANY)
|
2015-01-23 14:13:36 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->createEditCtrl(true);
|
2017-05-17 16:20:21 +08:00
|
|
|
|
|
|
|
if (inputFlag == EditBox::InputFlag::INITIAL_CAPS_ALL_CHARACTERS)
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::SetWindowLongW(_hwndEdit, GWL_STYLE, ::GetWindowLongW(_hwndEdit, GWL_STYLE) | ES_UPPERCASE);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
// Clear the password style
|
2017-12-22 09:14:27 +08:00
|
|
|
::PostMessageW(_hwndEdit, EM_SETPASSWORDCHAR, (WPARAM)0, (LPARAM)0);
|
2015-01-23 14:13:36 +08:00
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
}
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativeReturnType(EditBox::KeyboardReturnType returnType)
|
|
|
|
{
|
|
|
|
//not implemented yet
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
|
|
|
void EditBoxImplWin::setNativeTextHorizontalAlignment(TextHAlignment alignment)
|
|
|
|
{
|
|
|
|
LONG style = ::GetWindowLongW(_hwndEdit, GWL_STYLE);
|
|
|
|
switch (alignment)
|
|
|
|
{
|
|
|
|
case TextHAlignment::LEFT:
|
|
|
|
style = (style & ~ES_CENTER & ~ES_RIGHT) | ES_LEFT;
|
|
|
|
break;
|
|
|
|
case TextHAlignment::CENTER:
|
|
|
|
style = (style & ~ES_LEFT & ~ES_RIGHT) | ES_CENTER;
|
|
|
|
break;
|
|
|
|
case TextHAlignment::RIGHT:
|
|
|
|
style = (style & ~ES_LEFT & ~ES_CENTER) | ES_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
::SetWindowLongW(_hwndEdit, GWL_STYLE, style);
|
|
|
|
}
|
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativeText(const char* pText)
|
|
|
|
{
|
|
|
|
std::u16string utf16Result;
|
|
|
|
std::string text(pText);
|
|
|
|
cocos2d::StringUtils::UTF8ToUTF16(text, utf16Result);
|
|
|
|
this->_changedTextManually = true;
|
2017-12-22 09:14:27 +08:00
|
|
|
::SetWindowTextW(_hwndEdit, (LPCWSTR)utf16Result.c_str());
|
2017-05-17 16:20:21 +08:00
|
|
|
int textLen = text.size();
|
2017-12-22 09:14:27 +08:00
|
|
|
::SendMessageW(_hwndEdit, EM_SETSEL, textLen, textLen);
|
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
if (_editBoxInputMode == cocos2d::ui::EditBox::InputMode::ANY)
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::SendMessageW(_hwndEdit, EM_SCROLLCARET, 0, 0);
|
2014-08-19 10:28:24 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativePlaceHolder(const char* pText)
|
|
|
|
{
|
|
|
|
//not implemented yet
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativeVisible(bool visible)
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-05-17 16:20:21 +08:00
|
|
|
if (visible)
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::ShowWindow(_hwndEdit, SW_SHOW);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::ShowWindow(_hwndEdit, SW_HIDE);
|
2014-08-19 10:28:24 +08:00
|
|
|
}
|
|
|
|
}
|
2017-02-17 15:45:19 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
void EditBoxImplWin::updateNativeFrame(const Rect& rect)
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
|
|
|
::SetWindowPos(
|
2017-12-22 09:14:27 +08:00
|
|
|
_hwndEdit,
|
2017-05-17 16:20:21 +08:00
|
|
|
HWND_NOTOPMOST,
|
|
|
|
rect.origin.x,
|
|
|
|
rect.origin.y,
|
|
|
|
rect.size.width,
|
|
|
|
rect.size.height,
|
|
|
|
SWP_NOZORDER);
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
const char* EditBoxImplWin::getNativeDefaultFontName()
|
|
|
|
{
|
|
|
|
return "Arial";
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::nativeOpenKeyboard()
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::PostMessageW(_hwndEdit, WM_SETFOCUS, (WPARAM)s_previousFocusWnd, 0);
|
2017-05-17 16:20:21 +08:00
|
|
|
// s_previousFocusWnd = hwndEdit;
|
|
|
|
this->editBoxEditingDidBegin();
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
auto rect = ui::Helper::convertBoundingBoxToScreen(_editBox);
|
|
|
|
this->updateNativeFrame(rect);
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::nativeCloseKeyboard()
|
|
|
|
{
|
|
|
|
//don't need to implement
|
|
|
|
}
|
2017-12-22 09:14:27 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::setNativeMaxLength(int maxLength)
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::SendMessageW(_hwndEdit, EM_LIMITTEXT, maxLength, 0);
|
2015-11-06 02:14:34 +08:00
|
|
|
}
|
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
void EditBoxImplWin::_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-05-17 16:20:21 +08:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_CHAR:
|
|
|
|
if (wParam == VK_RETURN)
|
|
|
|
{
|
|
|
|
if (_editBoxInputMode != cocos2d::ui::EditBox::InputMode::ANY) {
|
|
|
|
if (s_previousFocusWnd != s_hwndCocos) {
|
2017-12-22 09:14:27 +08:00
|
|
|
switch (_keyboardReturnType)
|
|
|
|
{
|
|
|
|
case EditBox::KeyboardReturnType::DEFAULT:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::UNKNOWN;
|
|
|
|
break;
|
|
|
|
case EditBox::KeyboardReturnType::DONE:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::RETURN;
|
|
|
|
break;
|
|
|
|
case EditBox::KeyboardReturnType::SEND:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::RETURN;
|
|
|
|
break;
|
|
|
|
case EditBox::KeyboardReturnType::SEARCH:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::RETURN;
|
|
|
|
break;
|
|
|
|
case EditBox::KeyboardReturnType::GO:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::RETURN;
|
|
|
|
break;
|
|
|
|
case EditBox::KeyboardReturnType::NEXT:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::TAB_TO_NEXT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_endAction = EditBoxDelegate::EditBoxEndAction::UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
2017-05-17 16:20:21 +08:00
|
|
|
::ShowWindow(s_previousFocusWnd, SW_HIDE);
|
2017-12-22 09:14:27 +08:00
|
|
|
::SendMessageW(s_hwndCocos, WM_SETFOCUS, (WPARAM)s_previousFocusWnd, 0);
|
2017-05-17 16:20:21 +08:00
|
|
|
s_previousFocusWnd = s_hwndCocos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
if (hwnd != s_previousFocusWnd)
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::PostMessageW(hwnd, WM_ACTIVATE, (WPARAM)s_previousFocusWnd, 0);
|
|
|
|
::PostMessageW(hwnd, WM_SETCURSOR, (WPARAM)s_previousFocusWnd, 0);
|
|
|
|
s_previousFocusWnd = _hwndEdit;
|
2017-05-17 16:20:21 +08:00
|
|
|
_hasFocus = true;
|
|
|
|
this->_changedTextManually = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_KILLFOCUS:
|
|
|
|
_hasFocus = false;
|
|
|
|
//when app enter background, this message also be called.
|
2017-12-22 09:14:27 +08:00
|
|
|
if (this->_editingMode && !::IsWindowVisible(hwnd))
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
this->editBoxEditingDidEnd(this->getText(), _endAction);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
}
|
2014-11-14 15:04:32 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
std::string EditBoxImplWin::getText() const
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-05-17 16:20:21 +08:00
|
|
|
std::u16string wstrResult;
|
|
|
|
std::string utf8Result;
|
2015-11-06 02:14:34 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
int inputLength = ::GetWindowTextLengthW(_hwndEdit);
|
2017-05-17 16:20:21 +08:00
|
|
|
wstrResult.resize(inputLength);
|
2015-11-06 02:14:34 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
::GetWindowTextW(_hwndEdit, (LPWSTR)&wstrResult[0], inputLength + 1);
|
2017-05-17 16:20:21 +08:00
|
|
|
bool conversionResult = cocos2d::StringUtils::UTF16ToUTF8(wstrResult, utf8Result);
|
|
|
|
if (!conversionResult)
|
|
|
|
{
|
2017-09-20 09:05:00 +08:00
|
|
|
CCLOG("warning, editbox input text conversion error.");
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
return std::move(utf8Result);
|
2015-11-06 02:14:34 +08:00
|
|
|
}
|
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
LRESULT EditBoxImplWin::hookGLFWWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2017-05-17 16:20:21 +08:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (HIWORD(wParam) == EN_CHANGE) {
|
2017-12-22 09:14:27 +08:00
|
|
|
EditBoxImplWin* pThis = (EditBoxImplWin*)GetWindowLongPtrW((HWND)lParam, GWLP_USERDATA);
|
2017-05-17 16:20:21 +08:00
|
|
|
if (pThis && !pThis->_changedTextManually)
|
|
|
|
{
|
|
|
|
pThis->editBoxEditingChanged(pThis->getText());
|
|
|
|
pThis->_changedTextManually = false;
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
if (s_previousFocusWnd != s_hwndCocos) {
|
|
|
|
::ShowWindow(s_previousFocusWnd, SW_HIDE);
|
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
EditBoxImplWin* pThis = (EditBoxImplWin*)GetWindowLongPtrW(s_previousFocusWnd, GWLP_USERDATA);
|
2018-05-11 15:09:09 +08:00
|
|
|
if (pThis!=nullptr && !pThis->_hasFocus)
|
2017-05-17 16:20:21 +08:00
|
|
|
{
|
|
|
|
if (pThis->_editingMode && !IsWindowVisible(s_previousFocusWnd))
|
|
|
|
{
|
|
|
|
pThis->editBoxEditingDidEnd(pThis->getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
::PostMessageW(s_hwndCocos, WM_SETFOCUS, (WPARAM)s_previousFocusWnd, 0);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
|
|
|
s_previousFocusWnd = s_hwndCocos;
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-08-05 07:54:50 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
return ::CallWindowProcW(s_prevCocosWndProc, hwnd, uMsg, wParam, lParam);
|
2015-08-05 07:54:50 +08:00
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
LRESULT EditBoxImplWin::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2015-08-05 07:54:50 +08:00
|
|
|
{
|
2017-12-22 09:14:27 +08:00
|
|
|
EditBoxImplWin* pThis = (EditBoxImplWin*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
2017-05-17 16:20:21 +08:00
|
|
|
if (pThis)
|
|
|
|
{
|
|
|
|
pThis->_WindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2017-12-22 09:14:27 +08:00
|
|
|
return ::CallWindowProcW(pThis->_prevWndProc, hwnd, uMsg, wParam, lParam);
|
2017-05-17 16:20:21 +08:00
|
|
|
}
|
2014-08-19 10:28:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2017-12-08 18:18:04 +08:00
|
|
|
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
|