Symbian.org/preview/script/lib/menuItem.js
author ivanl
Fri, 05 Jun 2009 16:18:05 +0100
changeset 0 54498df70f5d
child 10 07ac2f6a36a9
permissions -rw-r--r--
Adding Symbian.org Widget 1.0rc3 source

/*
	Function 	:	MenuItem()
	Argument	:	Void
	Returns		:	Void
	Description	:	Constructor Function creates a Menu object to the WINDOW
*/

function MenuItem(name, id)
{
	this.id = id;
	this.name = name;
	this.isDimmed = false;
	
	this.items = Array();
	this.index = null;
	this.parent = null;
	this.type = 'MenuItem';
	
	
	//	Event triggers
	this.onSelect = null;
}


/*
	Function 	:	MenuItem.append(MenuItem)
	Argument	:	Menu Object
	Returns		:	Void
	Description	:	Function appends childMenuItem to a MenuItem
*/
MenuItem.prototype.append = function(childMenuItem)
{
	if( (childMenuItem != null) && (childMenuItem.type == 'MenuItem'))
	{
		childMenuItem.parent = this;
		this.items.push(childMenuItem);
	}
}


/*
	Function 	:	MenuItem.remove()
	Argument	:	Menu Object
	Returns		:	Void
	Description	:	Function Removes childMenuItem and its children from the parent menu item.
*/
MenuItem.prototype.remove = function(childMenuItem)
{
	if((childMenuItem != null) && (childMenuItem.type == 'MenuItem'))
	{
		var i = this.search(childMenuItem);
		if(i > -1)
			this.items.splice(i, 1);
	}
}

/*
	Function 	:	MenuItem.remove()
	Argument	:	Menu Object
	Returns		:	Void
	Description	:	If flag is true the MenuItem is hidden and if flag is false the item is shown.
*/
MenuItem.prototype.setDimmed = function(flag)
{
	this.isDimmed = flag;
}


/*
	Function 	:	MenuItem.search()
	Argument	:	MenuItem Object
	Returns		:	Integer
	Description	:	Function Replace oldMenuItem with newMenuItem
*/
MenuItem.prototype.search = function(MenuItem)
{
		var i;
		var flag = false;
		for(i=0; i<this.items.length; i++)
		{
			if(this.items[i].id == MenuItem.id)
			{	
				flag = true; 
				break; 
			}
		}
		if(flag)
			return i;
		else
			return -1;		
}