uidesigner/com.nokia.sdt.series60.componentlibrary/components/cba/cbaLibrary.js
changeset 2 d760517a8095
equal deleted inserted replaced
-1:000000000000 2:d760517a8095
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 function findImmediateChildByComponentId(children, componentID) {
       
    20     var result = null;
       
    21 	for (var i in children) {
       
    22 		var child = children[i];
       
    23 		if (child.component != null && child.component.isOfType(componentID)) {
       
    24 			result = child;
       
    25 			break;
       
    26 		}
       
    27 	}
       
    28 	return result;
       
    29 }
       
    30 
       
    31 function isRestricted(instance) {
       
    32 	return instance.component.id == "com.nokia.sdt.series60.CBARestricted";
       
    33 }
       
    34 
       
    35 function findCbaLeftId(children) {
       
    36 	var cba = findImmediateChildByComponentId(children, "com.nokia.sdt.series60.CBABase");
       
    37 	if (cba == null) return null;
       
    38 	return getCbaLeftId(cba);
       
    39 }
       
    40 
       
    41 function findCbaMiddleId(children) {
       
    42 	var cba = findImmediateChildByComponentId(children, "com.nokia.sdt.series60.CBABase");
       
    43 	if (cba == null) return null;
       
    44 	return getCbaMiddleId(cba);
       
    45 }
       
    46 
       
    47 
       
    48 function getCbaLeftId(cba) {
       
    49 	var info = cba.properties.info;
       
    50 	if (isRestricted(cba)) {
       
    51 		if ((info == "R_AVKON_SOFTKEYS_OPTIONS_BACK") || (info == "R_AVKON_SOFTKEYS_OPTIONS_EXIT"))
       
    52 			return "EAknSoftkeyOptions";
       
    53 		else if (info == "R_AVKON_SOFTKEYS_OK_BACK")
       
    54 			return "EAknSoftkeyOk";
       
    55 	}
       
    56 	else {
       
    57 		// need to check, since CBA may not be emitted if not custom (thus no enumerator registered)
       
    58 		//println("cba:"+cba.properties.info.editableValue);
       
    59 		if (cba.properties.info.editableValue != "com.nokia.sdt.series60.CBA.Type.CUSTOM")
       
    60 			return cba.properties.info.leftId;
       
    61 		else
       
    62 			return Engine.findBuiltinOrGeneratedEnumeratorForAlgorithm(cba, "leftId", "com.nokia.sdt.component.symbian.NAME_ALG_COMMANDS");
       
    63 	}
       
    64 }		
       
    65 
       
    66 function getCbaMiddleId(cba) {
       
    67 	var info = cba.properties.info;
       
    68 	// TODO: Need to revisit this code for MSK
       
    69 	if (isRestricted(cba)) {
       
    70 		if ((info == "R_AVKON_SOFTKEYS_OPTIONS_BACK") || (info == "R_AVKON_SOFTKEYS_OPTIONS_EXIT"))
       
    71 			return "EAknSoftkeyOptions";
       
    72 		else if (info == "R_AVKON_SOFTKEYS_OK_BACK")
       
    73 			return "EAknSoftkeyOk";
       
    74 	}
       
    75 	else {
       
    76 		// need to check, since CBA may not be emitted if not custom (thus no enumerator registered)
       
    77 		//println("cba:"+cba.properties.info.editableValue);
       
    78 		if (cba.properties.info.editableValue != "com.nokia.sdt.series60.CBA.Type.CUSTOM")
       
    79 			return cba.properties.info.middleId;
       
    80 		else
       
    81 			return Engine.findBuiltinOrGeneratedEnumeratorForAlgorithm(cba, "middleId", "com.nokia.sdt.component.symbian.NAME_ALG_COMMANDS");
       
    82 	}
       
    83 }		
       
    84 
       
    85 function findCbaRightId(children) {
       
    86 	var cba = findImmediateChildByComponentId(children, "com.nokia.sdt.series60.CBABase");
       
    87 	if (cba == null) return null;
       
    88 	return getCbaRightId(cba);
       
    89 }	
       
    90 
       
    91 function getCbaRightId(cba) {
       
    92 	var info = cba.properties.info;
       
    93 	if (isRestricted(cba)) {
       
    94 		if ((info == "R_AVKON_SOFTKEYS_OPTIONS_BACK") || (info == "R_AVKON_SOFTKEYS_OK_BACK") || (info == "R_AVKON_SOFTKEYS_BACK"))
       
    95 			return "EAknSoftkeyBack";
       
    96 		else if (info == "R_AVKON_SOFTKEYS_OPTIONS_EXIT")
       
    97 			return "EAknSoftkeyExit";
       
    98 	}
       
    99 	else {
       
   100 		// need to check, since CBA may not be emitted if not custom (thus no enumerator registered)
       
   101 		if (cba.properties.info.editableValue != "com.nokia.sdt.series60.CBA.Type.CUSTOM")
       
   102 			return cba.properties.info.rightId;
       
   103 		else
       
   104 			return Engine.findBuiltinOrGeneratedEnumeratorForAlgorithm(cba, "rightId", "com.nokia.sdt.component.symbian.NAME_ALG_COMMANDS");
       
   105 	}
       
   106 }
       
   107 
       
   108 function drawCBA(leftText, rightText, middleText, location, size, laf, graphics) {
       
   109 	var x = location.x;
       
   110 	var y = location.y;
       
   111 	var width = size.x;
       
   112 	var height = size.y;
       
   113 
       
   114 	var backColor = laf.getColor("control.pane.background");
       
   115 	graphics.setBackground(backColor);
       
   116 
       
   117 	var font = laf.getFont("control.pane.font");
       
   118 		
       
   119 	graphics.setFont(font);
       
   120 	graphics.setForeground(laf.getColor("control.pane.text"));
       
   121 	
       
   122 	var margin = laf.getInteger("control.pane.text.margin", 5);
       
   123 	var extent = font.stringExtent(leftText + "/" + rightText)
       
   124 
       
   125 	if (laf.getBoolean("is.portrait", true)) {
       
   126 		var fontOffset = (height - extent.y) / 2
       
   127 
       
   128 		var rect = new Rectangle(x + margin, y + fontOffset, 
       
   129 				width - (2*margin), height - fontOffset);
       
   130 
       
   131 		graphics.fillRectangle(x, y, width, height);
       
   132 
       
   133 		leftText = chooseScalableText(leftText, font, rect.width);
       
   134 		graphics.drawFormattedString(leftText, rect, Font.ALIGN_LEFT, 0);
       
   135 		rightText = chooseScalableText(rightText, font, rect.width);
       
   136 		graphics.drawFormattedString(rightText, rect, Font.ALIGN_RIGHT, 0);
       
   137 		middleText = chooseScalableText(middleText, font, rect.width);
       
   138 		if (middleText == "_" || middleText == "."){
       
   139 			var imageMSK;
       
   140 			if (middleText == "_") {
       
   141 				imageMSK = laf.getImage("msk.context.options.icon");
       
   142 			} else {
       
   143 				imageMSK = laf.getImage("msk.left.key.icon");
       
   144 			}
       
   145 			
       
   146 			if (imageMSK != null) {
       
   147 				var imageData = imageMSK.getImageData();
       
   148 				graphics.drawImage(imageMSK, 0, 0, imageData.width, imageData.height,
       
   149 				width/2-imageData.width/2, height/2-imageData.height/2, imageData.width, imageData.height);
       
   150 
       
   151 			} else {
       
   152 				graphics.drawFormattedString("NO IMAGE", rect, Font.ALIGN_CENTER, 0);
       
   153 			}
       
   154 		}  else {
       
   155 			graphics.drawFormattedString(middleText, rect, Font.ALIGN_CENTER, 0);
       
   156 		}
       
   157 	}
       
   158 	else {
       
   159 		// middle soft key text is not displayed in landscape
       
   160 		var fontHeight = font.getHeight();
       
   161 		var sbar1Bounds = laf.getRectangle("status.bar1.bounds");
       
   162 		var sbar2Bounds = laf.getRectangle("status.bar2.bounds");
       
   163 		var gradientStart = laf.getColor("control.pane.gradient.start");
       
   164 		var gradientEnd = laf.getColor("control.pane.gradient.end");
       
   165 		graphics.setBackground(gradientEnd);
       
   166 
       
   167 		var alignCenter = laf.getBoolean("cba.align.center", false);
       
   168 		var flags = alignCenter ? Font.ALIGN_CENTER : Font.ALIGN_RIGHT;
       
   169 		
       
   170 		var fontOffset = (sbar1Bounds.height - extent.y) / 2
       
   171 
       
   172 		var rect = new Rectangle(x, y + fontOffset, width-margin, height-fontOffset);
       
   173 		graphics.setForeground(gradientStart);
       
   174 		graphics.fillGradientRectangle(x, y + sbar1Bounds.y, width, sbar1Bounds.height, false);
       
   175 		rightText = chooseScalableText(rightText, font, rect.width);
       
   176 		graphics.setForeground(laf.getColor("control.pane.text"));
       
   177 		graphics.drawFormattedString(rightText, rect, flags, 0);
       
   178 		
       
   179 		rect.y = y + height - sbar1Bounds.height + fontOffset;
       
   180 		rect.height = sbar1Bounds.height - fontOffset;
       
   181 
       
   182 		graphics.setForeground(gradientStart);
       
   183 		graphics.fillGradientRectangle(x, y + sbar2Bounds.y, width, sbar2Bounds.height, false);
       
   184 		leftText = chooseScalableText(leftText, font, rect.width);
       
   185 		graphics.setForeground(laf.getColor("control.pane.text"));
       
   186 		graphics.drawFormattedString(leftText, rect, flags, 0);
       
   187 	}
       
   188 }
       
   189