$package("js.ui.list");

js.ui.list.AbstractListItemRenderer = function (owner){
	this.owner = owner;
}

js.ui.list.AbstractListItemRenderer.prototype = new js.ui.Container();

js.ui.list.AbstractListItemRenderer.prototype.getNativeClass = function (){
	return "js.ui.list.AbstractListItemRenderer";
}

js.ui.list.AbstractListItemRenderer.prototype.state = 0;

js.ui.list.AbstractListItemRenderer.prototype.bindUI = function (){
	var __this = this;
	this.ui.onmouseover = function(){
		__this.state = 1;
		this.className = __this.baseCSS+" "+__this.baseCSS+"_over";
	}
	this.ui.onmouseout = function(){
		__this.state = 0;
		__this.paintSelect();
	}
	this.ui.onclick = function(event){
		this.oncontextmenu(event);
		return js.ui.Component.eventCancelBubble(event);
	}
	this.ui.onmousedown = function(event){
		browser.sendMessage(null, 201, event, window);//WM_ONMOUSEDOWN(WM_LBUTTONDOWN):201
		return js.ui.Component.eventCancelBubble(event);
	}
	this.ui.oncontextmenu = function(event){
		var curListBox = __this.owner;
		if (!curListBox) return;
		if(!event)event = window.event;
		if(!event.ctrlKey)
			curListBox.clearSelection();
		curListBox.setSelectedValue(__this.userObject, !curListBox.isSelectedItem(__this.userObject));
	}
	this.baseCSS = this.ui.className;
}

js.ui.list.AbstractListItemRenderer.prototype.owner = null;

js.ui.list.AbstractListItemRenderer.prototype.baseCSS = null;

js.ui.list.AbstractListItemRenderer.prototype.userObject = null;

js.ui.list.AbstractListItemRenderer.prototype.setValue = function(value){
	this.userObject = value;
	this.paint();
}
js.ui.list.AbstractListItemRenderer.prototype.isSelected = function(){
	var curListBox = this.owner;
	if (!curListBox) return false;
	return curListBox.isSelectedItem(this.userObject);
}

js.ui.list.AbstractListItemRenderer.prototype.paintSelect = function(){
	if (this.isSelected()){
		this.getUI().className = this.baseCSS+"_selected";
	}
	else{
		this.getUI().className = this.baseCSS;
	}
}
js.ui.list.AbstractListItemRenderer.prototype.paintText = function(){
	var text = this.userObject;
	if(text=='') text = "&nbsp";
	this.getUI().innerHTML = text;
}

js.ui.list.AbstractListItemRenderer.prototype.paint = function(){
	this.paintText();
	this.paintSelect();
}

