Ejemplo n.º 1
0
// worker method to change the type of the input item
HTMLInput *jhtml_input_change_type(HTMLInput *pInput, HTMLInputType newInputType, HTMLDocument *pDocument)
{
	HTMLInputType currentInputType = pInput->GetInputType();
	HTMLElement *pParent = pInput->Parent();
	HTMLInput *pNewElement=WEBC_NULL;

	if(currentInputType == newInputType)
		return WEBC_NULL; // do nothing

	HTMLTagParse tag[1];
	HTML_InitTagParse(tag, HTML_TAG_INPUT);

	switch (newInputType)
	{
	case HTML_INPUT_TYPE_BUTTON:
		WEBC_NEW_VERBOSE(pNewElement, HTMLInputButton(tag, pDocument),"HTMLInputButton");
		break;
	case HTML_INPUT_TYPE_CHECKBOX:
		WEBC_NEW_VERBOSE(pNewElement, HTMLCheckbox(tag, pDocument),"HTMLCheckbox");
		break;
	case HTML_INPUT_TYPE_FILE:
		WEBC_NEW_VERBOSE(pNewElement, HTMLEditString(tag, pDocument),"HTMLEditString");	// TODO implement file upload
		break;
	case HTML_INPUT_TYPE_HIDDEN:
		WEBC_NEW_VERBOSE(pNewElement, HTMLInputHidden(tag, pDocument),"HTMLInputHidden");
		break;
	case HTML_INPUT_TYPE_IMAGE:
		WEBC_NEW_VERBOSE(pNewElement,  HTMLInputButton(tag, pDocument),"HTMLInputButton");	//?
		break;
	case HTML_INPUT_TYPE_PASSWORD:
		WEBC_NEW_VERBOSE(pNewElement, HTMLInputPassword(tag, pDocument),"HTMLInputPassword");
		break;
	case HTML_INPUT_TYPE_RADIO:
		WEBC_NEW_VERBOSE(pNewElement, HTMLRadioButton(tag, pDocument),"HTMLRadioButton");
		break;
	case HTML_INPUT_TYPE_RESET:
		WEBC_NEW_VERBOSE(pNewElement, HTMLInputReset(tag, pDocument),"HTMLInputReset");
		break;
	case HTML_INPUT_TYPE_SUBMIT:
		WEBC_NEW_VERBOSE(pNewElement, HTMLInputSubmit(tag, pDocument),"HTMLInputSubmit");
		break;
	case HTML_INPUT_TYPE_TEXT:
		WEBC_NEW_VERBOSE(pNewElement, HTMLEditString(tag, pDocument),"HTMLEditString");
		break;
	}

	// we may or may not be included in the DOM tree
	// if we are, then replace with the new element
	if(pParent)
	{
		pParent->InsertAfter(pNewElement, pInput);
		pParent->Remove(pInput);
	}
	WEBC_DELETE(pInput);

	return pNewElement;
}