uidesigner/com.nokia.sdt.series60.componentlibrary/components/cba/CBA_visual.js
changeset 0 fb279309251b
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     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 include("cbaLibrary.js")
       
    20 
       
    21 function CBAVisual() {
       
    22 }
       
    23 
       
    24 CBAVisual.prototype.draw = function(instance, laf, graphics) {
       
    25 	var properties = instance.properties;
       
    26 	var middleText = getMiddleText(instance, laf);
       
    27 	var leftText = getLeftText(instance);
       
    28 	var rightText = getRightText(instance);
       
    29 	if (middleText == leftText && middleText != ""){
       
    30 		middleText = ".";
       
    31 	}
       
    32 	drawCBA(leftText, rightText, middleText,
       
    33 		new Point(0, 0), new Point(properties.size.width, properties.size.height), laf, graphics);
       
    34 }
       
    35 
       
    36 function isRestricted(instance) {
       
    37 	return instance.component.id == "com.nokia.sdt.series60.CBARestricted";
       
    38 }
       
    39 
       
    40 function isCustom(info, instance) {
       
    41 	if (isRestricted(instance)){
       
    42 		return false;
       
    43 	}
       
    44 	
       
    45 	if (info.editableValue == "com.nokia.sdt.series60.CBA.Type.CUSTOM") {
       
    46 		return true;
       
    47 	}
       
    48 	
       
    49 	return false;
       
    50 }
       
    51 
       
    52 function getLeftText(instance) {
       
    53 	var info = instance.properties.info;
       
    54 	if (isCustom(info, instance)) {
       
    55 			return info.leftText;
       
    56 	}
       
    57 	else if (isRestricted(instance)) {
       
    58 		if ((info == "R_AVKON_SOFTKEYS_OPTIONS_BACK") || (info == "R_AVKON_SOFTKEYS_OPTIONS_EXIT"))
       
    59 			return lookupString("text_softkey_option");
       
    60 		else if (info == "R_AVKON_SOFTKEYS_OK_BACK")
       
    61 			return lookupString("text_softkey_ok");
       
    62 		else if (info == "R_AVKON_SOFTKEYS_BACK")
       
    63 			return "";
       
    64 	}
       
    65 	else {
       
    66 		return lookupString("text_" + info.leftId);
       
    67 	}
       
    68 }
       
    69 
       
    70 function getRightText(instance) {
       
    71 	var info = instance.properties.info;
       
    72 	if (isCustom(info, instance)) {
       
    73 		return info.rightText;
       
    74 	}
       
    75 	else if (isRestricted(instance)) {
       
    76 		if ((info == "R_AVKON_SOFTKEYS_OPTIONS_BACK") || (info == "R_AVKON_SOFTKEYS_OK_BACK") || (info == "R_AVKON_SOFTKEYS_BACK"))
       
    77 			return lookupString("text_softkey_back");
       
    78 		else if (info == "R_AVKON_SOFTKEYS_OPTIONS_EXIT")
       
    79 			return lookupString("text_softkey_exit");
       
    80 	}
       
    81 	else {
       
    82 		if (info.type == "R_AVKON_SOFTKEYS_EXIT") // treat this one special because it uses the "back" id
       
    83 			return lookupString("text_EAknSoftkeyExit");
       
    84 			
       
    85 		return lookupString("text_" + info.rightId);
       
    86 	}
       
    87 }
       
    88 
       
    89 function getMiddleText(instance, laf) {
       
    90 
       
    91 	if (isRestricted(instance)){
       
    92 		return "";
       
    93 	}
       
    94 	
       
    95 	if (hasMSKSupport() && laf.getBoolean("draw.msk", false)){
       
    96 		info = instance.properties.info;
       
    97 		if (info.middleId == "EAknSoftkeyContextOptions") {
       
    98 			return "_";  // sub menu of left soft key, will use icon
       
    99 		}
       
   100 		else if (isCustom(info, instance))
       
   101 			return info.middleText;
       
   102 		else
       
   103 			return lookupString("text_" + info.middleId);
       
   104 	} else {
       
   105 		return "";
       
   106 	}
       
   107 }
       
   108 
       
   109 
       
   110 CBAVisual.prototype.getPreferredSize = function(instance, laf, wHint, hHint) {
       
   111 	return null; // needs implementation	
       
   112 }
       
   113 
       
   114 CBAVisual.prototype.getPropertyPaths = function(instance) {
       
   115 	if (hasMSKSupport()){
       
   116 		return new Array("info.leftText", "info.rightText", "info.middleText");
       
   117 	} else {
       
   118 		return new Array("info.leftText", "info.rightText");
       
   119 	}
       
   120 }
       
   121 
       
   122 CBAVisual.prototype.getLabelBounds = function(instance, propertyPath, laf) {
       
   123 	var properties = instance.properties;
       
   124 	var margin = laf.getInteger("control.pane.text.margin", 5);
       
   125 	var width = properties.size.width - (2*margin);
       
   126 	var height = properties.size.height;
       
   127 	if (laf.getBoolean("is.portrait", false)) {
       
   128 		var numButtons = 2;
       
   129 		if (hasMSKSupport()){
       
   130 			numButtons = 3;
       
   131 		}
       
   132 		if (propertyPath.equals("info.leftText")) {
       
   133 			return new Rectangle(margin, 0, width / numButtons, height);
       
   134 		} 
       
   135 		else if (hasMSKSupport() && propertyPath.equals("info.middleText")) {
       
   136 			return new Rectangle(margin + (width / numButtons), 0, width / numButtons, height);
       
   137 		}
       
   138 		else {
       
   139 			return new Rectangle(margin + (width / 2), 0, width / 2, height);
       
   140 		}
       
   141 	}
       
   142 	else {
       
   143 		// landscape doesn't support MSK
       
   144 		var font = laf.getFont("control.pane.font");
       
   145 		var fontHeight = font.getHeight();
       
   146 		var sbar2Bounds = laf.getRectangle("status.bar2.bounds");
       
   147 		var rect = new Rectangle(0, 1, width-margin, fontHeight);
       
   148 		if (propertyPath.equals("info.leftText")) {
       
   149 			rect.y = height - sbar2Bounds.height + 1;
       
   150 			rect.height = sbar2Bounds.height;
       
   151 		}
       
   152 
       
   153 		return rect;
       
   154 	}
       
   155 	
       
   156 	return new Rectangle(0, 0, 0, 0);
       
   157 }
       
   158 
       
   159 CBAVisual.prototype.getLabelFont = function(instance, propertyPath, laf) {
       
   160 	return laf.getFont("control.pane.font");
       
   161 }
       
   162 
       
   163 function hasMSKSupport(){
       
   164 	var version = getComponentVersions();
       
   165 	if (version.getMajor() > 3 || (version.getMajor() == 3 && version.getMinor() >= 2)){
       
   166 		return true;
       
   167 	}
       
   168 	
       
   169 	return false;
       
   170 }