<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdInput.xml $
$Revision: 823 $

last change: $Date: 2008-11-06 17:21:34 +0300 (Чт, 06 ноя 2008) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->
<!--
====================================================================================================================
			Визуальный объект 'Ввод текста'
====================================================================================================================
-->
<composition name="rnmc_stdInput" class="rnmc_stdMediaObject">
<script><![CDATA[
	this.type = "rnmc_stdInput"
	
	//	действия при нажатии клавиши на клавиатуре
	this.onKeyDownActions = null;
	//	действия при отжатии клавиши на клавиатуре
	this.onKeyUpActions = null;				
	
//	callback'и
	this.onKeyDownCallBackObject = null;
	this.onKeyDownCallBackFunction = null;
	this.onKeyUpCallBackObject = null;
	this.onKeyUpCallBackFunction = null;
	
	
	function initFromNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

		xmlAttributeMap = srcNode.attributes;
		if (xmlAttributeMap){
			xmlAttribute = xmlAttributeMap.getNamedItem("id");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.id = xmlAttribute.value;
			xmlAttribute = xmlAttributeMap.getNamedItem("visible");
			if (xmlAttribute != null && xmlAttribute.specified){
				if(xmlAttribute.value == "true")
					this.visibility = OBJECT_VISIBILITY_TRUE;
				else if(xmlAttribute.value == "false")
					this.visibility = OBJECT_VISIBILITY_FALSE;
			}
			xmlAttribute = xmlAttributeMap.getNamedItem("enabled");
			if (xmlAttribute != null && xmlAttribute.specified && xmlAttribute.value == "false")
				this.disabled = true;
		}		

		xmlNode = srcNode.firstChild;
		while(xmlNode){
			if(xmlNode.nodeName == "param"){
				this.parseParamNode(xmlNode);
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
					xmlAttribute = xmlAttributeMap.getNamedItem("maxChars");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.maxChars = parseInt(xmlAttribute.value);
				}
			} else if(xmlNode.nodeName == "value"){
				if(xmlNode.textContent)
					this.objectValue = xmlNode.textContent;
			} else if(xmlNode.nodeName == "actions"){
				//	стандартые события
				rnmc_stdMediaObject_parseActionsNode(xmlNode);
				//	разбор действий при нажатии клавиши на клавиатуре
				this.onKeyDownActions = scene.Utils.parseActionsNode(xmlNode, "onKeyDown");
				//	разбор действий при отпускании клавиши на клавиатуре
				this.onKeyUpActions = scene.Utils.parseActionsNode(xmlNode, "onKeyUp");				
			} else if(xmlNode.nodeName == "hint"){
				this.parseHintNode(xmlNode);
			}
			xmlNode = xmlNode.nextSibling;
		}
		return true;
	};

	function loadObject(){
		if(!this.objectContent){
			this.objectContent = new Input();
			this.objectContent.parent = this;
		}
	}

	function unloadObject(){
trace("rnmc_stdInput.unloadObject");
		this.effectsTarget = null;
		if(this.objectContent){
			this.objectContent.visible = false;
			this.objectContent.parent = null;
			this.objectContent = null;
		}
	}

	function showObject(){
		this.x = 0;
		this.y = 0;
		this.loadObject();
		if(this.objectContent){
			if(this.objectStyle)
				this.objectContent.style = this.objectStyle;		
			this.setPosition(this.objectX, this.objectY, this.objectWidth, this.objectHeight, this.objectDepth);
			this.objectContent.opacity = this.objectOpacity;
			if(this.objectBgColor)
				this.objectContent.bkgColor = this.objectBgColor;
			if (this.objectValue)
				this.objectContent.value = this.objectValue;

			//if(this.onKeyDownActions){
				this.objectContent.onKeyDown = this.onKeyDownHandlerAlias;
			//}
			//if(this.onKeyUpActions){
				this.objectContent.onKeyUp = this.onKeyUpHandlerAlias;
			//}
		}
		this.objectContent.visible = true;
	//	перебор присоединённых эффектов для показа
		this.effectsTarget = this.objectContent;
		var showEffectsCount = this.startEffects(EVENT_ON_SHOW);
		if(showEffectsCount == 0){
			this.objectContent.visible = true;
		}

		rnmc_stdMediaObject_showObject();

		if (this.objectSetFocus)
			setFocus(this.objectContent);
	}

	//	Получение значений параметров объектов из user-mode
	function getObjectProperty(objectId, propertyName){
		if(objectId != this.id)
			return null;
		switch(propertyName){
		case "value":
			return this.objectContent.value;
			break;
		default:
			return null;			
		}	
	}
	
	function hideObject(){
trace("rnmc_stdInput.hideObject");
		rnmc_stdMediaObject_hideObject();
		
trace("this.visible =="+this.visible);
	};
	
	function onKeyDownHandlerAlias(){
		onKeyDownHandler();
	}

	function onKeyDownHandler(){
//trace("rnmc_stdInput(" + this.id + ").onKeyDownHandler");
		var dispatcher = parent;
		while (dispatcher) {
			if ("dispatchAction" in dispatcher)
				break;
			dispatcher = dispatcher.parent;
		}
		if (!dispatcher)
			return;
		
		if(this.onKeyDownCallBackFunction != null && this.onKeyDownCallBackObject != null)
			this.onKeyDownCallBackFunction.call(this.onKeyDownCallBackObject, Key.keyCode);
		if(this.onKeyDownActions){
			for(var i = 0; i < this.onKeyDownActions.length; i++){
				dispatcher.dispatchAction(this.onKeyDownActions[i]);
			}
		}
	}
	
	function onKeyUpHandlerAlias(){
		onKeyUpHandler();
	}

	function onKeyUpHandler(){
trace("rnmc_stdInput(" + this.id + ").onKeyUpHandler");
		var dispatcher = parent;
		while (dispatcher) {
			if ("dispatchAction" in dispatcher)
				break;
			dispatcher = dispatcher.parent;
		}
		if (!dispatcher)
			return;
			
		if(this.onKeyUpCallBackFunction != null && this.onKeyUpCallBackObject != null)
			this.onKeyUpCallBackFunction.call(this.onKeyUpCallBackObject, Key.keyCode);
		if(this.onKeyUpActions){
			for(var i = 0; i < this.onKeyUpActions.length; i++){
				dispatcher.dispatchAction(this.onKeyUpActions[i]);
			}
		}
	}
	
	function buttonDispatcher(btnId){
		switch(btnId){
		default:
			rnmc_stdMediaObject_buttonDispatcher(btnId);
		}
	}
		
	function setKeyDownCallBack(pointerToObject, callbackFunction){
		if(this.objectContent && !this.objectContent.onKeyDown)
			this.objectContent.onKeyDown = this.onKeyDownHandlerAlias;
		this.onKeyDownCallBackObject = pointerToObject;
		this.onKeyDownCallBackFunction = callbackFunction;
	};

	function clearKeyDownCallBack(){
		this.onKeyDownCallBackObject = null;
		this.onKeyDownCallBackFunction = null;
	}
	
	function setKeyUpCallBack(pointerToObject, callbackFunction){
		if(this.objectContent && !this.objectContent.onKeyUp)
			this.objectContent.onKeyUp = this.onKeyUpHandlerAlias;
		this.onKeyUpCallBackObject = pointerToObject;
		this.onKeyUpCallBackFunction = callbackFunction;
	};

	function clearKeyUpCallBack(){
		this.onKeyUpCallBackObject = null;
		this.onKeyUpCallBackFunction = null;
	}

]]></script>
</composition>
</rmml>