uidesigner/com.nokia.carbide.cpp.uiq.components/components/settingsListLibrary.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) 2006 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 isSettingItemList(instance) {
cawthron
parents:
diff changeset
    20
	return instance.isInstanceOf("com.nokia.sdt.series60.CAknSettingItemList");
cawthron
parents:
diff changeset
    21
}
cawthron
parents:
diff changeset
    22
cawthron
parents:
diff changeset
    23
cawthron
parents:
diff changeset
    24
cawthron
parents:
diff changeset
    25
DRAW_BOUNDING_RECTS = false;
cawthron
parents:
diff changeset
    26
cawthron
parents:
diff changeset
    27
include("renderLibrary.js")
cawthron
parents:
diff changeset
    28
include("implLibrary.js")
cawthron
parents:
diff changeset
    29
include("srcgenLibrary.js")
cawthron
parents:
diff changeset
    30
cawthron
parents:
diff changeset
    31
cawthron
parents:
diff changeset
    32
function fontForType(silProperties, laf) {
cawthron
parents:
diff changeset
    33
	return laf.getFont("NormalFont");
cawthron
parents:
diff changeset
    34
}
cawthron
parents:
diff changeset
    35
cawthron
parents:
diff changeset
    36
function getLineBounds(silProperties, laf) {
cawthron
parents:
diff changeset
    37
	var font = fontForType(silProperties, laf);
cawthron
parents:
diff changeset
    38
	// * 2 accounts for label and content
cawthron
parents:
diff changeset
    39
	var p = new Point(0, getFontHeight(font) * 2 + laf.getInteger("list.padding", 8));
cawthron
parents:
diff changeset
    40
	p.y += laf.getInteger("extra.padding", 0) * 2;
cawthron
parents:
diff changeset
    41
	//println("getLineBounds="+p);
cawthron
parents:
diff changeset
    42
	return p;
cawthron
parents:
diff changeset
    43
}
cawthron
parents:
diff changeset
    44
cawthron
parents:
diff changeset
    45
function maxDisplayableItems(silProperties, laf) {
cawthron
parents:
diff changeset
    46
	var header = 0;
cawthron
parents:
diff changeset
    47
	var bounds = getLineBounds(silProperties, laf);
cawthron
parents:
diff changeset
    48
	var max = Math.floor((silProperties.size.height - laf.getInteger("list.padding", 8) / 2) / bounds.y)
cawthron
parents:
diff changeset
    49
	//println("maxDisplayableItems="+max+" bounds="+bounds+" silProperties.size.height="+silProperties.size.height);
cawthron
parents:
diff changeset
    50
	return max;
cawthron
parents:
diff changeset
    51
}
cawthron
parents:
diff changeset
    52
cawthron
parents:
diff changeset
    53
function verticalContentMargin(silProperties, laf) {
cawthron
parents:
diff changeset
    54
	var maxItems = maxDisplayableItems(silProperties, laf);
cawthron
parents:
diff changeset
    55
	var lineBounds = getLineBounds(silProperties, laf);
cawthron
parents:
diff changeset
    56
	return maxItems * lineBounds.y + laf.getInteger("list.padding", 8) / 2;
cawthron
parents:
diff changeset
    57
}
cawthron
parents:
diff changeset
    58
cawthron
parents:
diff changeset
    59
cawthron
parents:
diff changeset
    60
function isShowingNumbers(silInstance) {
cawthron
parents:
diff changeset
    61
	return silInstance.properties.EAknSettingItemNumberedStyle;
cawthron
parents:
diff changeset
    62
}
cawthron
parents:
diff changeset
    63
		
cawthron
parents:
diff changeset
    64
function getPromptDividerOffset(silInstance, laf) {
cawthron
parents:
diff changeset
    65
	var column;
cawthron
parents:
diff changeset
    66
	if (silInstance.properties.EAknSettingItemNumberedStyle)
cawthron
parents:
diff changeset
    67
		column = laf.getInteger("settingitemlist.numbered.padding", 20);
cawthron
parents:
diff changeset
    68
	else
cawthron
parents:
diff changeset
    69
		column = laf.getInteger("settingitemlist.padding", 6);
cawthron
parents:
diff changeset
    70
	return column;
cawthron
parents:
diff changeset
    71
}
cawthron
parents:
diff changeset
    72
cawthron
parents:
diff changeset
    73
function getSILPaddingY(laf) {
cawthron
parents:
diff changeset
    74
	return laf.getInteger("settingitemlist.padding.y", 6);
cawthron
parents:
diff changeset
    75
}
cawthron
parents:
diff changeset
    76
cawthron
parents:
diff changeset
    77
function getSILPaddingX(laf) {
cawthron
parents:
diff changeset
    78
	return laf.getInteger("settingitemlist.padding.x", 6);
cawthron
parents:
diff changeset
    79
}
cawthron
parents:
diff changeset
    80
cawthron
parents:
diff changeset
    81
/**
cawthron
parents:
diff changeset
    82
 *	Get all the rectangles associated with an item in a setting item list.
cawthron
parents:
diff changeset
    83
 *
cawthron
parents:
diff changeset
    84
 *	@param rect the item's rectangle (i.e. an entire row)
cawthron
parents:
diff changeset
    85
 * @returns an array with:
cawthron
parents:
diff changeset
    86
 *
cawthron
parents:
diff changeset
    87
 *	0) Rectangle numeric prompt bounds, as a whole
cawthron
parents:
diff changeset
    88
 *	1) Rectangle title bounds, as a whole
cawthron
parents:
diff changeset
    89
 *	2) Rectangle compulsory indicator bounds, as a whole
cawthron
parents:
diff changeset
    90
 *	3) Rectangle content bounds, as a whole
cawthron
parents:
diff changeset
    91
 *	4) int column where divider is drawn
cawthron
parents:
diff changeset
    92
 */
cawthron
parents:
diff changeset
    93
var SIL_ITEM_RECT_INDEX = 0;
cawthron
parents:
diff changeset
    94
var SIL_NUMBER_RECT_INDEX = 1;
cawthron
parents:
diff changeset
    95
var SIL_TITLE_RECT_INDEX = 2;
cawthron
parents:
diff changeset
    96
var SIL_INDICATOR_RECT_INDEX = 3;
cawthron
parents:
diff changeset
    97
var SIL_CONTENT_RECT_INDEX = 4;
cawthron
parents:
diff changeset
    98
var SIL_DIVIDER_OFFSET_INDEX = 5;
cawthron
parents:
diff changeset
    99
cawthron
parents:
diff changeset
   100
function getSettingItemRectanglesInRect(instance, laf, rect) {
cawthron
parents:
diff changeset
   101
	var silInstance = instance.parent;
cawthron
parents:
diff changeset
   102
	var dividerOffset = getPromptDividerOffset(instance.parent, laf);
cawthron
parents:
diff changeset
   103
cawthron
parents:
diff changeset
   104
	var promptRect, contentRect, titleRect, indiRect;
cawthron
parents:
diff changeset
   105
	
cawthron
parents:
diff changeset
   106
	var contentHeight = laf.getInteger("settingitemlist.content.height", 16);
cawthron
parents:
diff changeset
   107
	var vertPadding = getSILPaddingY(laf);	
cawthron
parents:
diff changeset
   108
	var horizPadding = getSILPaddingX(laf);
cawthron
parents:
diff changeset
   109
	
cawthron
parents:
diff changeset
   110
	promptRect = new Rectangle(rect.x, rect.y + vertPadding, 
cawthron
parents:
diff changeset
   111
					dividerOffset - horizPadding, rect.height - vertPadding);
cawthron
parents:
diff changeset
   112
	
cawthron
parents:
diff changeset
   113
	var leftMargin = dividerOffset + horizPadding;
cawthron
parents:
diff changeset
   114
	titleRect = new Rectangle(leftMargin, rect.y + vertPadding, 
cawthron
parents:
diff changeset
   115
		rect.width - leftMargin, contentHeight);
cawthron
parents:
diff changeset
   116
cawthron
parents:
diff changeset
   117
	var contentX = laf.getInteger("settingitemlist.content.x", 32);
cawthron
parents:
diff changeset
   118
	contentRect = new Rectangle(rect.x + contentX,
cawthron
parents:
diff changeset
   119
			rect.y + rect.height / 2 + vertPadding, 
cawthron
parents:
diff changeset
   120
			rect.width - contentX - horizPadding/2,
cawthron
parents:
diff changeset
   121
			contentHeight);
cawthron
parents:
diff changeset
   122
cawthron
parents:
diff changeset
   123
	indiRect = new Rectangle(leftMargin, contentRect.y,
cawthron
parents:
diff changeset
   124
			contentRect.x - leftMargin, contentRect.height);
cawthron
parents:
diff changeset
   125
			
cawthron
parents:
diff changeset
   126
	var rects = [ rect, promptRect, titleRect, indiRect, contentRect, dividerOffset ];
cawthron
parents:
diff changeset
   127
	//pr("Rects = " +rects);
cawthron
parents:
diff changeset
   128
	return rects;
cawthron
parents:
diff changeset
   129
}
cawthron
parents:
diff changeset
   130
cawthron
parents:
diff changeset
   131
function getSettingItemRectangles(instance, laf) {
cawthron
parents:
diff changeset
   132
	var rect = new Rectangle(0, 0, 
cawthron
parents:
diff changeset
   133
		instance.properties.size.width, instance.properties.size.height);
cawthron
parents:
diff changeset
   134
	return getSettingItemRectanglesInRect(instance, laf, rect);
cawthron
parents:
diff changeset
   135
}
cawthron
parents:
diff changeset
   136
cawthron
parents:
diff changeset
   137
function getPromptFont(laf) {
cawthron
parents:
diff changeset
   138
	return laf.getFont("AnnotationFont");
cawthron
parents:
diff changeset
   139
}
cawthron
parents:
diff changeset
   140
function getTitleFont(laf) {
cawthron
parents:
diff changeset
   141
	return laf.getFont("NormalFont");
cawthron
parents:
diff changeset
   142
}
cawthron
parents:
diff changeset
   143
function getIndiFont(laf) {
cawthron
parents:
diff changeset
   144
	return laf.getFont("NormalFont");
cawthron
parents:
diff changeset
   145
}
cawthron
parents:
diff changeset
   146
cawthron
parents:
diff changeset
   147
function getPromptFlags(instance) {
cawthron
parents:
diff changeset
   148
	var flags = Font.OVERFLOW_ELLIPSIS;
cawthron
parents:
diff changeset
   149
	
cawthron
parents:
diff changeset
   150
	flags |= Font.ALIGN_CENTER;
cawthron
parents:
diff changeset
   151
	
cawthron
parents:
diff changeset
   152
	return flags;
cawthron
parents:
diff changeset
   153
}
cawthron
parents:
diff changeset
   154
cawthron
parents:
diff changeset
   155
function isFirstField(instance) {
cawthron
parents:
diff changeset
   156
	var siblings = instance.parent.children;
cawthron
parents:
diff changeset
   157
	if (siblings != null)
cawthron
parents:
diff changeset
   158
		return instance == siblings[0];
cawthron
parents:
diff changeset
   159
		
cawthron
parents:
diff changeset
   160
	return false;
cawthron
parents:
diff changeset
   161
}
cawthron
parents:
diff changeset
   162
cawthron
parents:
diff changeset
   163
function calcSettingItemNumber(silInstance, self) {
cawthron
parents:
diff changeset
   164
	var number = silInstance.properties.initialNumber;
cawthron
parents:
diff changeset
   165
	var numberHidden = silInstance.properties.EAknSettingItemIncludeHiddenInOrdinal;
cawthron
parents:
diff changeset
   166
	for (var c in silInstance.children) {
cawthron
parents:
diff changeset
   167
		var sib = silInstance.children[c];
cawthron
parents:
diff changeset
   168
		if (sib == self)
cawthron
parents:
diff changeset
   169
			break;
cawthron
parents:
diff changeset
   170
		if (numberHidden || !sib.properties.itemHidden)
cawthron
parents:
diff changeset
   171
			number++;
cawthron
parents:
diff changeset
   172
	}
cawthron
parents:
diff changeset
   173
	return number;
cawthron
parents:
diff changeset
   174
}
cawthron
parents:
diff changeset
   175
cawthron
parents:
diff changeset
   176
function setSettingsListLineStyle(laf, graphics) {
cawthron
parents:
diff changeset
   177
	var version = getComponentVersions();
cawthron
parents:
diff changeset
   178
	if ((version.getMajor() >= 3 || (version.getMajor() == 2 && version.getMinor() >= 8))
cawthron
parents:
diff changeset
   179
			&& laf.getDimension("screen.size").x > 208) {
cawthron
parents:
diff changeset
   180
		// use dashed line
cawthron
parents:
diff changeset
   181
		graphics.setLineWidth(2);
cawthron
parents:
diff changeset
   182
		graphics.setLineDash([ 2 ]);
cawthron
parents:
diff changeset
   183
	} else {
cawthron
parents:
diff changeset
   184
		// use solid line
cawthron
parents:
diff changeset
   185
		graphics.setLineWidth(1);
cawthron
parents:
diff changeset
   186
	}
cawthron
parents:
diff changeset
   187
cawthron
parents:
diff changeset
   188
}
cawthron
parents:
diff changeset
   189
cawthron
parents:
diff changeset
   190
function drawSettingItemPrompt(prototype, instance, laf, graphics, rects) {
cawthron
parents:
diff changeset
   191
	var formInstance = instance.parent;
cawthron
parents:
diff changeset
   192
	var properties = instance.properties;
cawthron
parents:
diff changeset
   193
cawthron
parents:
diff changeset
   194
	var number = calcSettingItemNumber(instance.parent, instance);
cawthron
parents:
diff changeset
   195
cawthron
parents:
diff changeset
   196
	var rect = rects[SIL_NUMBER_RECT_INDEX];	
cawthron
parents:
diff changeset
   197
	graphics.setBackground(laf.getColor("EEikColorControlBackground"));
cawthron
parents:
diff changeset
   198
	//graphics.setBackground(getBackgroundColor(instance, laf));
cawthron
parents:
diff changeset
   199
	
cawthron
parents:
diff changeset
   200
	graphics.fillRectangle(rect);
cawthron
parents:
diff changeset
   201
cawthron
parents:
diff changeset
   202
	graphics.setForeground(laf.getColor("EEikColorControlText"));
cawthron
parents:
diff changeset
   203
cawthron
parents:
diff changeset
   204
	var itemRect = rects[SIL_ITEM_RECT_INDEX];
cawthron
parents:
diff changeset
   205
	
cawthron
parents:
diff changeset
   206
	// no decorations on 3.1+
cawthron
parents:
diff changeset
   207
	if (laf.getBoolean("decorations", true)) {
cawthron
parents:
diff changeset
   208
		setSettingsListLineStyle(laf, graphics);
cawthron
parents:
diff changeset
   209
		graphics.drawLine(rects[SIL_DIVIDER_OFFSET_INDEX], 
cawthron
parents:
diff changeset
   210
			itemRect.y + itemRect.height - 1,  
cawthron
parents:
diff changeset
   211
			itemRect.width, itemRect.y + itemRect.height - 1);
cawthron
parents:
diff changeset
   212
	
cawthron
parents:
diff changeset
   213
		//graphics.drawLine(rects[SIL_DIVIDER_OFFSET_INDEX], itemRect.y, rects[SIL_DIVIDER_OFFSET_INDEX], itemRect.height);
cawthron
parents:
diff changeset
   214
	}
cawthron
parents:
diff changeset
   215
	
cawthron
parents:
diff changeset
   216
	// draw number
cawthron
parents:
diff changeset
   217
	var font = getPromptFont(laf);
cawthron
parents:
diff changeset
   218
	graphics.setFont(font);
cawthron
parents:
diff changeset
   219
	if (isShowingNumbers(formInstance)) {
cawthron
parents:
diff changeset
   220
		var numberRect = rects[SIL_NUMBER_RECT_INDEX];
cawthron
parents:
diff changeset
   221
		graphics.drawFormattedString(number, numberRect, 
cawthron
parents:
diff changeset
   222
			Font.ALIGN_RIGHT,
cawthron
parents:
diff changeset
   223
			0);	
cawthron
parents:
diff changeset
   224
	}
cawthron
parents:
diff changeset
   225
	
cawthron
parents:
diff changeset
   226
	// draw item title
cawthron
parents:
diff changeset
   227
	var font = getTitleFont(laf);
cawthron
parents:
diff changeset
   228
	graphics.setFont(font);
cawthron
parents:
diff changeset
   229
	rect = rects[SIL_TITLE_RECT_INDEX];
cawthron
parents:
diff changeset
   230
	var height = getFontHeight(font);
cawthron
parents:
diff changeset
   231
	var textRect = new Rectangle(rect.x, rect.y + (rect.height - height)/2,
cawthron
parents:
diff changeset
   232
			rect.width, height);
cawthron
parents:
diff changeset
   233
	var titleText = chooseScalableText(properties.itemTitle, font, textRect.width);
cawthron
parents:
diff changeset
   234
	graphics.drawFormattedString(titleText, textRect, 0, 0);	
cawthron
parents:
diff changeset
   235
	
cawthron
parents:
diff changeset
   236
	// draw compulsory indicator
cawthron
parents:
diff changeset
   237
	var font = getIndiFont(laf);
cawthron
parents:
diff changeset
   238
	graphics.setFont(font);	
cawthron
parents:
diff changeset
   239
	rect = rects[SIL_INDICATOR_RECT_INDEX];
cawthron
parents:
diff changeset
   240
	graphics.setForeground(laf.getColor("CAknSettingItemList.CompulsoryIndicator"));
cawthron
parents:
diff changeset
   241
	graphics.drawFormattedString(properties.compulsoryLabel, rect, 0, 0);
cawthron
parents:
diff changeset
   242
	
cawthron
parents:
diff changeset
   243
	// draw content rect
cawthron
parents:
diff changeset
   244
	rect = rects[SIL_CONTENT_RECT_INDEX];
cawthron
parents:
diff changeset
   245
	graphics.setBackground(laf.getColor("CAknSettingItemList.ContentBackground"));
cawthron
parents:
diff changeset
   246
	graphics.fillRectangle(rect);
cawthron
parents:
diff changeset
   247
	graphics.setForeground(laf.getColor("CAknSettingItemList.ContentForeground"));
cawthron
parents:
diff changeset
   248
}
cawthron
parents:
diff changeset
   249
cawthron
parents:
diff changeset
   250
function getSettingItemContentBounds(instance, laf) {
cawthron
parents:
diff changeset
   251
	var rect = new Rectangle(0, 0, 
cawthron
parents:
diff changeset
   252
		instance.properties.size.width, instance.properties.size.height);
cawthron
parents:
diff changeset
   253
	if (isForm(instance.parent)) {
cawthron
parents:
diff changeset
   254
		return getSettingItemRectanglesInRect(instance, laf, rect)[SIL_CONTENT_RECT_INDEX];
cawthron
parents:
diff changeset
   255
	}
cawthron
parents:
diff changeset
   256
	return rect;		
cawthron
parents:
diff changeset
   257
}
cawthron
parents:
diff changeset
   258
cawthron
parents:
diff changeset
   259