uidesigner/com.nokia.carbide.cpp.uiq.components/components/textLinesNumberLibrary.js
changeset 0 fb279309251b
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2007 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 getTextBounds (lines, width, height, flags, font, pixelGapBetweenLines) {
       
    20 
       
    21 	var newBounds;
       
    22 	var textHeight = 0;
       
    23 	var textWidth = 0;
       
    24 
       
    25 	for (var i = 0; i < lines.length; i++ ) {
       
    26 		newBounds = font.formattedStringExtent(lines[i], 
       
    27 						new Point (width, height),
       
    28 						flags, pixelGapBetweenLines);
       
    29 		textHeight += newBounds.y;	
       
    30 		if ( newBounds.x > textWidth) {
       
    31 			textWidth = newBounds.x;
       
    32 		}
       
    33 	}
       
    34 	return new Point (textWidth, textHeight );
       
    35 }
       
    36 
       
    37 function getMaxLinesAllowedByParent(instance) {
       
    38 	var parent = instance.parent;
       
    39 	if (parent != null && isCQikContainer(parent)) {
       
    40 		return getMaxLinesAllowedInCQikContainer (instance);
       
    41 	} else if (parent != null && isItemSlot(parent)) {
       
    42 		var grandParent = parent.parent;
       
    43 		if  (grandParent != null && isSystemBuildingBlock(grandParent)) {
       
    44 			return getMaxLinesAllowedInSlot(grandParent.properties.type, parent.properties.slotId);
       
    45 		}
       
    46 	}
       
    47 	return 1;
       
    48 }
       
    49 
       
    50 function getMaxLinesAllowedInCQikContainer (instance) {
       
    51 	var maxLinesNumber = 2147483647;
       
    52 	if (instance != null && isCEikLabel(instance)) {
       
    53 		return maxLinesNumber;
       
    54 	} 
       
    55 	return 1;
       
    56 }
       
    57 
       
    58 function isCEikLabel(instance) {
       
    59 	return (instance.component.id).substring(0, 32) == "com.nokia.carbide.uiq.CEikLabel_";
       
    60 }
       
    61 
       
    62 function isCQikContainer(instance) {
       
    63 	return instance.component.id == "com.nokia.carbide.uiq.CQikContainer";
       
    64 }
       
    65 
       
    66 function isItemSlot(instance) {
       
    67 	return instance.component.id == "com.nokia.carbide.uiq.ItemSlot";
       
    68 }
       
    69 
       
    70 function isSystemBuildingBlock(instance) {
       
    71 	return instance.component.id == "com.nokia.carbide.uiq.SystemBuildingBlock";
       
    72 }
       
    73 
       
    74 function getMaxLinesAllowedInSlot(typeOfSBB, slotId) {
       
    75 	//println("***getMaxLinesAllowedInSlot");
       
    76 	var maxLinesNumber = 2147483647;
       
    77 	
       
    78 	switch (typeOfSBB) {
       
    79 		case "EQikCtOnelineBuildingBlock":
       
    80 		case "EQikCtIconOnelineBuildingBlock":
       
    81 		case "EQikCtOnelineIconBuildingBlock":
       
    82 		case "EQikCtIconOnelineIconBuildingBlock":
       
    83 		case "EQikCtMediumThumbnailDoubleOnelineBuildingBlock":
       
    84 		case "EQikCtCaptionedOnelineBuildingBlock":
       
    85 		case "EQikCtIconCaptionedOnelineBuildingBlock":
       
    86 		case "EQikCtIconIconOnelineBuildingBlock":
       
    87 		case "EQikCtHalflineHalflineBuildingBlock":
       
    88 		case "EQikCtCaptionedHalflineBuildingBlock":
       
    89 			return 1;
       
    90 		case "EQikCtTwolineBuildingBlock":
       
    91 		case "EQikCtIconTwolineBuildingBlock":
       
    92 		case "EQikCtTwolineIconBuildingBlock":
       
    93 		case "EQikCtIconTwolineIconBuildingBlock":
       
    94 			return 2;
       
    95 		case "EQikCtLargeThumbnailThreelineBuildingBlock":
       
    96 			return 3;
       
    97 		case "EQikCtManylinesBuildingBlock":
       
    98 			return maxLinesNumber;
       
    99 		case "EQikCtCaptionedTwolineBuildingBlock":
       
   100 		case "EQikCtIconCaptionedTwolineBuildingBlock":
       
   101 			return evaluateSlot(slotId, 1, 2);
       
   102 	}
       
   103 	
       
   104 	return 1;
       
   105 }
       
   106 
       
   107 function evaluateSlot(slotId, valueForItemSlot1, valueForItemSlot2) {
       
   108 //	println("***slotId: " + slotId);
       
   109 	if (slotId  == "EQikItemSlot1") {
       
   110 //		println("***valueForItemSlot1: " + valueForItemSlot1);
       
   111 		return valueForItemSlot1;
       
   112 	} else {
       
   113 		return valueForItemSlot2;
       
   114 	}
       
   115 }