Ejemplo n.º 1
0
void EditBoxImplWin::openKeyboard()
{
    if (_delegate != nullptr)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    
    CEditBox* pEditBox = this->getEditBox();
    if (nullptr != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
    
	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);
	GLView *glView = Director::getInstance()->getOpenGLView();
	GLFWwindow *glfwWindow = glView->getWindow();
	HWND hwnd = glfwGetWin32Window(glfwWindow);
	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 != NULL)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    
    EditBox* pEditBox = this->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
    
	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);
	GLView *glView = Director::getInstance()->getOpenGLView();
	GLFWwindow *glfwWindow = glView->getWindow();
	HWND hwnd = glfwGetWin32Window(glfwWindow);
	bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK;
	
	if (didChange) 	
		setText(pText);

	if (_delegate != NULL) {
		if (didChange)
			_delegate->editBoxTextChanged(_editBox, getText());
		_delegate->editBoxEditingDidEnd(_editBox);
		_delegate->editBoxReturn(_editBox);
	}
}