uidesigner/com.nokia.carbide.cpp.uiq.components/components/textLinesNumberLibrary.js
author tzelaw
Tue, 14 Apr 2009 15:03:19 -0500
changeset 94 d74b720418db
parent 2 d760517a8095
permissions -rw-r--r--
Test framework support: Ask debugger to remember DebugTarget so test framework can use it to setup test framework related utility. With this we can use the DebugUI way of launching while keeping test framework functionality
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
function getTextBounds (lines, width, height, flags, font, pixelGapBetweenLines) {
cawthron
parents:
diff changeset
    20
cawthron
parents:
diff changeset
    21
	var newBounds;
cawthron
parents:
diff changeset
    22
	var textHeight = 0;
cawthron
parents:
diff changeset
    23
	var textWidth = 0;
cawthron
parents:
diff changeset
    24
cawthron
parents:
diff changeset
    25
	for (var i = 0; i < lines.length; i++ ) {
cawthron
parents:
diff changeset
    26
		newBounds = font.formattedStringExtent(lines[i], 
cawthron
parents:
diff changeset
    27
						new Point (width, height),
cawthron
parents:
diff changeset
    28
						flags, pixelGapBetweenLines);
cawthron
parents:
diff changeset
    29
		textHeight += newBounds.y;	
cawthron
parents:
diff changeset
    30
		if ( newBounds.x > textWidth) {
cawthron
parents:
diff changeset
    31
			textWidth = newBounds.x;
cawthron
parents:
diff changeset
    32
		}
cawthron
parents:
diff changeset
    33
	}
cawthron
parents:
diff changeset
    34
	return new Point (textWidth, textHeight );
cawthron
parents:
diff changeset
    35
}
cawthron
parents:
diff changeset
    36
cawthron
parents:
diff changeset
    37
function getMaxLinesAllowedByParent(instance) {
cawthron
parents:
diff changeset
    38
	var parent = instance.parent;
cawthron
parents:
diff changeset
    39
	if (parent != null && isCQikContainer(parent)) {
cawthron
parents:
diff changeset
    40
		return getMaxLinesAllowedInCQikContainer (instance);
cawthron
parents:
diff changeset
    41
	} else if (parent != null && isItemSlot(parent)) {
cawthron
parents:
diff changeset
    42
		var grandParent = parent.parent;
cawthron
parents:
diff changeset
    43
		if  (grandParent != null && isSystemBuildingBlock(grandParent)) {
cawthron
parents:
diff changeset
    44
			return getMaxLinesAllowedInSlot(grandParent.properties.type, parent.properties.slotId);
cawthron
parents:
diff changeset
    45
		}
cawthron
parents:
diff changeset
    46
	}
cawthron
parents:
diff changeset
    47
	return 1;
cawthron
parents:
diff changeset
    48
}
cawthron
parents:
diff changeset
    49
cawthron
parents:
diff changeset
    50
function getMaxLinesAllowedInCQikContainer (instance) {
cawthron
parents:
diff changeset
    51
	var maxLinesNumber = 2147483647;
cawthron
parents:
diff changeset
    52
	if (instance != null && isCEikLabel(instance)) {
cawthron
parents:
diff changeset
    53
		return maxLinesNumber;
cawthron
parents:
diff changeset
    54
	} 
cawthron
parents:
diff changeset
    55
	return 1;
cawthron
parents:
diff changeset
    56
}
cawthron
parents:
diff changeset
    57
cawthron
parents:
diff changeset
    58
function isCEikLabel(instance) {
cawthron
parents:
diff changeset
    59
	return (instance.component.id).substring(0, 32) == "com.nokia.carbide.uiq.CEikLabel_";
cawthron
parents:
diff changeset
    60
}
cawthron
parents:
diff changeset
    61
cawthron
parents:
diff changeset
    62
function isCQikContainer(instance) {
cawthron
parents:
diff changeset
    63
	return instance.component.id == "com.nokia.carbide.uiq.CQikContainer";
cawthron
parents:
diff changeset
    64
}
cawthron
parents:
diff changeset
    65
cawthron
parents:
diff changeset
    66
function isItemSlot(instance) {
cawthron
parents:
diff changeset
    67
	return instance.component.id == "com.nokia.carbide.uiq.ItemSlot";
cawthron
parents:
diff changeset
    68
}
cawthron
parents:
diff changeset
    69
cawthron
parents:
diff changeset
    70
function isSystemBuildingBlock(instance) {
cawthron
parents:
diff changeset
    71
	return instance.component.id == "com.nokia.carbide.uiq.SystemBuildingBlock";
cawthron
parents:
diff changeset
    72
}
cawthron
parents:
diff changeset
    73
cawthron
parents:
diff changeset
    74
function getMaxLinesAllowedInSlot(typeOfSBB, slotId) {
cawthron
parents:
diff changeset
    75
	//println("***getMaxLinesAllowedInSlot");
cawthron
parents:
diff changeset
    76
	var maxLinesNumber = 2147483647;
cawthron
parents:
diff changeset
    77
	
cawthron
parents:
diff changeset
    78
	switch (typeOfSBB) {
cawthron
parents:
diff changeset
    79
		case "EQikCtOnelineBuildingBlock":
cawthron
parents:
diff changeset
    80
		case "EQikCtIconOnelineBuildingBlock":
cawthron
parents:
diff changeset
    81
		case "EQikCtOnelineIconBuildingBlock":
cawthron
parents:
diff changeset
    82
		case "EQikCtIconOnelineIconBuildingBlock":
cawthron
parents:
diff changeset
    83
		case "EQikCtMediumThumbnailDoubleOnelineBuildingBlock":
cawthron
parents:
diff changeset
    84
		case "EQikCtCaptionedOnelineBuildingBlock":
cawthron
parents:
diff changeset
    85
		case "EQikCtIconCaptionedOnelineBuildingBlock":
cawthron
parents:
diff changeset
    86
		case "EQikCtIconIconOnelineBuildingBlock":
cawthron
parents:
diff changeset
    87
		case "EQikCtHalflineHalflineBuildingBlock":
cawthron
parents:
diff changeset
    88
		case "EQikCtCaptionedHalflineBuildingBlock":
cawthron
parents:
diff changeset
    89
			return 1;
cawthron
parents:
diff changeset
    90
		case "EQikCtTwolineBuildingBlock":
cawthron
parents:
diff changeset
    91
		case "EQikCtIconTwolineBuildingBlock":
cawthron
parents:
diff changeset
    92
		case "EQikCtTwolineIconBuildingBlock":
cawthron
parents:
diff changeset
    93
		case "EQikCtIconTwolineIconBuildingBlock":
cawthron
parents:
diff changeset
    94
			return 2;
cawthron
parents:
diff changeset
    95
		case "EQikCtLargeThumbnailThreelineBuildingBlock":
cawthron
parents:
diff changeset
    96
			return 3;
cawthron
parents:
diff changeset
    97
		case "EQikCtManylinesBuildingBlock":
cawthron
parents:
diff changeset
    98
			return maxLinesNumber;
cawthron
parents:
diff changeset
    99
		case "EQikCtCaptionedTwolineBuildingBlock":
cawthron
parents:
diff changeset
   100
		case "EQikCtIconCaptionedTwolineBuildingBlock":
cawthron
parents:
diff changeset
   101
			return evaluateSlot(slotId, 1, 2);
cawthron
parents:
diff changeset
   102
	}
cawthron
parents:
diff changeset
   103
	
cawthron
parents:
diff changeset
   104
	return 1;
cawthron
parents:
diff changeset
   105
}
cawthron
parents:
diff changeset
   106
cawthron
parents:
diff changeset
   107
function evaluateSlot(slotId, valueForItemSlot1, valueForItemSlot2) {
cawthron
parents:
diff changeset
   108
//	println("***slotId: " + slotId);
cawthron
parents:
diff changeset
   109
	if (slotId  == "EQikItemSlot1") {
cawthron
parents:
diff changeset
   110
//		println("***valueForItemSlot1: " + valueForItemSlot1);
cawthron
parents:
diff changeset
   111
		return valueForItemSlot1;
cawthron
parents:
diff changeset
   112
	} else {
cawthron
parents:
diff changeset
   113
		return valueForItemSlot2;
cawthron
parents:
diff changeset
   114
	}
cawthron
parents:
diff changeset
   115
}