void EditBoxImplWin::openKeyboard()
{
    if (_delegate != nullptr)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }

#if CC_ENABLE_SCRIPT_BINDING
    auto editBox = this->getEditBox();
    if (editBox && editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(editBox->getScriptEditBoxHandler(), "began",editBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif
    
	std::string placeHolder = _labelPlaceHolder->getString();
	if (placeHolder.length() == 0)
		placeHolder = "Enter value";

	char pText[100]= {0};
	std::string text = getText();
	if (text.length())
		strncpy(pText, text.c_str(), 100);
	auto glView = Director::getInstance()->getOpenGLView();
	HWND hwnd = glView->getWin32Window();
	bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK;
	
	if (didChange) 	
		setText(pText);

	if (_delegate != nullptr) {
		if (didChange)
			_delegate->editBoxTextChanged(_editBox, getText());
		_delegate->editBoxEditingDidEnd(_editBox);
		_delegate->editBoxReturn(_editBox);
	}
    
#if CC_ENABLE_SCRIPT_BINDING
    if (nullptr != _editBox && 0 != _editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed",_editBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        if (didChange)
        {
            ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        }
        memset(data.eventName,0,sizeof(data.eventName));
        strncpy(data.eventName,"ended",sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName,0,sizeof(data.eventName));
        strncpy(data.eventName,"return",sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif // #if CC_ENABLE_SCRIPT_BINDING
}
Ejemplo n.º 2
0
void EditBoxImplWin::openKeyboard()
{
    if (_delegate != nullptr)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }

    _isEditing = true;
#if CC_ENABLE_SCRIPT_BINDING
    auto editBox = this->getEditBox();
    if (nullptr != editBox && 0 != editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(editBox->getScriptEditBoxHandler(), "began",editBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif
    
	std::string placeHolder = _labelPlaceHolder->getString();
	if (placeHolder.length() == 0)
		placeHolder = "Enter value";

	std::string text = getText();
    std::string originalText = text;
	auto glView = Director::getInstance()->getOpenGLView();
	HWND hwnd = glView->getWin32Window();
	bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), &text, _maxLength, false, hwnd,
        _keyboardReturnType, _editBoxInputMode, _editBoxInputFlag,
        &EditBoxImplWin::onWin32InputBoxTextChange, this) == IDOK;
    _isEditing = false;
	
	setText(didChange ? text.c_str() : originalText.c_str());

	if (_delegate != nullptr)
	{
		_delegate->editBoxTextChanged(_editBox, getText());
		_delegate->editBoxEditingDidEnd(_editBox);
		_delegate->editBoxReturn(_editBox);
	}
    
#if CC_ENABLE_SCRIPT_BINDING
    if (nullptr != _editBox && 0 != _editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed",_editBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName,0,sizeof(data.eventName));
        strncpy(data.eventName,"ended",sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName,0,sizeof(data.eventName));
        strncpy(data.eventName,"return",sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif // #if CC_ENABLE_SCRIPT_BINDING
}
Ejemplo n.º 3
0
void EditBoxImplWin::onWin32InputBoxTextChange(const char *pText, EditBoxImplWin* thiz)
{
    thiz->_isEditing = false;  // Prevent recursive calls
    thiz->setText(pText);
    thiz->_isEditing = true;

    auto delegate = thiz->getDelegate();
    if (delegate != nullptr)
    {
        delegate->editBoxTextChanged(thiz->_editBox, thiz->_text);
    }

#if CC_ENABLE_SCRIPT_BINDING
    auto editBox = thiz->getEditBox();
    if (nullptr != editBox && 0 != editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(editBox->getScriptEditBoxHandler(), "changed", editBox);
        ScriptEvent event(kCommonEvent, (void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif // #if CC_ENABLE_SCRIPT_BINDING
}
Ejemplo n.º 4
0
void EditBoxImplWin::openKeyboard()
{
    if (s_win32InputBox != nullptr)
    {
        return;
    }

    if (_delegate != nullptr)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }

    _isEditing = true;
#if CC_ENABLE_SCRIPT_BINDING
    auto editBox = this->getEditBox();
    if (nullptr != editBox && 0 != editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(editBox->getScriptEditBoxHandler(), "began", editBox);
        ScriptEvent event(kCommonEvent, (void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif

    std::string placeHolder = _labelPlaceHolder->getString();
    if (placeHolder.length() == 0)
        placeHolder = "Enter value";

    _editingText = getText();
    _originalText = _editingText;
    auto glView = Director::getInstance()->getOpenGLView();
    HWND hwnd = glView->getWin32Window();
    CWin32InputBox::InputBox("Input", placeHolder.c_str(), &_editingText, _maxLength, false, hwnd,
        _keyboardReturnType, _editBoxInputMode, _editBoxInputFlag,
        std::bind(&EditBoxImplWin::onWin32InputBoxTextChange, this, std::placeholders::_1),
        std::bind(&EditBoxImplWin::onWin32InputBoxClose, this, std::placeholders::_1));
}