/* ===================================================================================================
 * treePictureControl
 * ===================================================================================================
 */
 
/// cell: html-div-Element
/// descr: <columnDescriptor>
treePictureControl_setup = function(cell, txt)
{
	var descr = cell.description;
	
	cell.enabled = false;
	cell.setAttribute("contenteditable", "true");
	cell.setAttribute("class", cell.getAttribute("class") + " treePicture");
	addControlEvent(cell, "focus", function(event) { treePictureControl_onFocus(cell, event); });
	addControlEvent(cell, "blur", function(event) { treePictureControl_onBlur(cell, event); });
	addControlEvent(cell, "paste", function(event) { treePictureControl_onPaste(cell, event); });
	addControlEvent(cell, "beforeinput", function(event) { treePictureControl_onBeforeInput(cell, event); });
	addControlEvent(cell, "keydown", function(event) { treePictureControl_onKeyDown(cell, event); });
	addControlEvent(cell, "contextmenu", function(event) { control_onContextMenu(cell, event); });
	cell.enabled = descr.enabled && parseInt(descr.enabled);
	treePictureControl_setText(cell, txt);
};

treePictureControl_setText = function(cell, txt)
{
	cell.innerHTML = "";

	var name = txt;
	var p = txt.indexOf(':');
	if (p >= 0)
	{
		var depth = parseIntEx(txt.substring(0, p));
		if (depth > 0)
		{
			var space = xmlCreateElement(cell, "span", null, null);
			space.style.width = depth * 8 + "px";
			space.style.minWidth = depth * 8 + "px";
			space.style.maxWidth = depth * 8 + "px";
		}
		name = txt.substring(p + 1);
	}
	var img = xmlCreateElement(cell, "img", null, null);
	if (name.substring(0,2) == "//")
		name = "https:" + name
	img.setAttribute("src", name);
	cell.title = name;
};

treePictureControl_onFocus = function(cell, event)
{
	if (getBaseClassName(cell).startsWith("grid"))
		gridControl_cellNotify(cell, "onSetFocus");
};

treePictureControl_onBlur = function(cell, event)
{
	if (getBaseClassName(cell).startsWith("grid"))
		gridControl_cellNotify(cell, "onKillFocus");
};

treePictureControl_onBeforeInput = function(cell, event)
{
	event.preventDefault();
	switch(event.inputType)
	{
		case "insertParagraph":
			editControl_selectNext(cell);
			break;

		case "insertLineBreak":
			editControl_selectPrev(cell);
			break;
	}
};

treePictureControl_onPaste = function(cell, event)
{
	event.preventDefault();
};

treePictureControl_onKeyDown = function(cell, event)
{
	if (getBaseClassName(cell).startsWith("grid"))
	{
		switch (event.key)
		{
			case " ":
			case "Enter":
				event.preventDefault();
				gridControl_cellNotify(cell, "onDblClick");
				break;
			case "ArrowLeft":
				event.preventDefault();
				editControl_selectPrev(cell);
				break;
			case "ArrowRight":
				event.preventDefault();
				editControl_selectNext(cell);
				break;
		}
	}
};
