Symbian.org/preview/script/lib/menuItem.js
changeset 0 54498df70f5d
child 10 07ac2f6a36a9
equal deleted inserted replaced
-1:000000000000 0:54498df70f5d
       
     1 /*
       
     2 	Function 	:	MenuItem()
       
     3 	Argument	:	Void
       
     4 	Returns		:	Void
       
     5 	Description	:	Constructor Function creates a Menu object to the WINDOW
       
     6 */
       
     7 
       
     8 function MenuItem(name, id)
       
     9 {
       
    10 	this.id = id;
       
    11 	this.name = name;
       
    12 	this.isDimmed = false;
       
    13 	
       
    14 	this.items = Array();
       
    15 	this.index = null;
       
    16 	this.parent = null;
       
    17 	this.type = 'MenuItem';
       
    18 	
       
    19 	
       
    20 	//	Event triggers
       
    21 	this.onSelect = null;
       
    22 }
       
    23 
       
    24 
       
    25 /*
       
    26 	Function 	:	MenuItem.append(MenuItem)
       
    27 	Argument	:	Menu Object
       
    28 	Returns		:	Void
       
    29 	Description	:	Function appends childMenuItem to a MenuItem
       
    30 */
       
    31 MenuItem.prototype.append = function(childMenuItem)
       
    32 {
       
    33 	if( (childMenuItem != null) && (childMenuItem.type == 'MenuItem'))
       
    34 	{
       
    35 		childMenuItem.parent = this;
       
    36 		this.items.push(childMenuItem);
       
    37 	}
       
    38 }
       
    39 
       
    40 
       
    41 /*
       
    42 	Function 	:	MenuItem.remove()
       
    43 	Argument	:	Menu Object
       
    44 	Returns		:	Void
       
    45 	Description	:	Function Removes childMenuItem and its children from the parent menu item.
       
    46 */
       
    47 MenuItem.prototype.remove = function(childMenuItem)
       
    48 {
       
    49 	if((childMenuItem != null) && (childMenuItem.type == 'MenuItem'))
       
    50 	{
       
    51 		var i = this.search(childMenuItem);
       
    52 		if(i > -1)
       
    53 			this.items.splice(i, 1);
       
    54 	}
       
    55 }
       
    56 
       
    57 /*
       
    58 	Function 	:	MenuItem.remove()
       
    59 	Argument	:	Menu Object
       
    60 	Returns		:	Void
       
    61 	Description	:	If flag is true the MenuItem is hidden and if flag is false the item is shown.
       
    62 */
       
    63 MenuItem.prototype.setDimmed = function(flag)
       
    64 {
       
    65 	this.isDimmed = flag;
       
    66 }
       
    67 
       
    68 
       
    69 /*
       
    70 	Function 	:	MenuItem.search()
       
    71 	Argument	:	MenuItem Object
       
    72 	Returns		:	Integer
       
    73 	Description	:	Function Replace oldMenuItem with newMenuItem
       
    74 */
       
    75 MenuItem.prototype.search = function(MenuItem)
       
    76 {
       
    77 		var i;
       
    78 		var flag = false;
       
    79 		for(i=0; i<this.items.length; i++)
       
    80 		{
       
    81 			if(this.items[i].id == MenuItem.id)
       
    82 			{	
       
    83 				flag = true; 
       
    84 				break; 
       
    85 			}
       
    86 		}
       
    87 		if(flag)
       
    88 			return i;
       
    89 		else
       
    90 			return -1;		
       
    91 }