uidesigner/com.nokia.carbide.cpp.uiq.components/components/formLibrary.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
cawthron
parents:
diff changeset
    20
DRAW_BOUNDING_RECTS = false;
cawthron
parents:
diff changeset
    21
cawthron
parents:
diff changeset
    22
include("renderLibrary.js")
cawthron
parents:
diff changeset
    23
include("implLibrary.js")
cawthron
parents:
diff changeset
    24
include("srcgenLibrary.js")
cawthron
parents:
diff changeset
    25
cawthron
parents:
diff changeset
    26
var FORM_ID = "com.nokia.sdt.series60.CAknForm";
cawthron
parents:
diff changeset
    27
cawthron
parents:
diff changeset
    28
function isForm(formInstance) {
cawthron
parents:
diff changeset
    29
	return formInstance.componentId == FORM_ID;
cawthron
parents:
diff changeset
    30
}
cawthron
parents:
diff changeset
    31
cawthron
parents:
diff changeset
    32
function isDoubleSpaced(formInstance) {
cawthron
parents:
diff changeset
    33
	return formInstance.properties.EEikFormUseDoubleSpacedFormat;
cawthron
parents:
diff changeset
    34
}
cawthron
parents:
diff changeset
    35
cawthron
parents:
diff changeset
    36
function isShowingBitmaps(formInstance) {
cawthron
parents:
diff changeset
    37
	return formInstance.properties.EEikFormShowBitmaps;
cawthron
parents:
diff changeset
    38
}
cawthron
parents:
diff changeset
    39
		
cawthron
parents:
diff changeset
    40
function getFormSingleDividerOffset(formInstance, laf) {
cawthron
parents:
diff changeset
    41
	return laf.getInteger("form.divider.offset.single", 20);
cawthron
parents:
diff changeset
    42
}
cawthron
parents:
diff changeset
    43
cawthron
parents:
diff changeset
    44
function getFormPromptDividerOffset(formInstance, laf) {
cawthron
parents:
diff changeset
    45
	if (isDoubleSpaced(formInstance)) {
cawthron
parents:
diff changeset
    46
		if (isShowingBitmaps(formInstance))
cawthron
parents:
diff changeset
    47
			return laf.getInteger("form.inset", 20);
cawthron
parents:
diff changeset
    48
		else
cawthron
parents:
diff changeset
    49
			return laf.getInteger("form.divider.offset.double", 6);
cawthron
parents:
diff changeset
    50
	}
cawthron
parents:
diff changeset
    51
	return getFormSingleDividerOffset(formInstance, laf);
cawthron
parents:
diff changeset
    52
}
cawthron
parents:
diff changeset
    53
cawthron
parents:
diff changeset
    54
function getFormLineGap(laf) {
cawthron
parents:
diff changeset
    55
	return laf.getInteger("form.padding", 5);
cawthron
parents:
diff changeset
    56
}
cawthron
parents:
diff changeset
    57
cawthron
parents:
diff changeset
    58
function getFormPadding(laf) {
cawthron
parents:
diff changeset
    59
	return laf.getInteger("form.padding", 5);
cawthron
parents:
diff changeset
    60
}
cawthron
parents:
diff changeset
    61
cawthron
parents:
diff changeset
    62
/**
cawthron
parents:
diff changeset
    63
 *	Get all the rectangles associated with an item in a form.
cawthron
parents:
diff changeset
    64
 *
cawthron
parents:
diff changeset
    65
 *	@param rect the item's rectangle (i.e. an entire row)
cawthron
parents:
diff changeset
    66
 * @returns an array with:
cawthron
parents:
diff changeset
    67
 *
cawthron
parents:
diff changeset
    68
 *	0) Rectangle prompt bounds, as a whole
cawthron
parents:
diff changeset
    69
 *	1) Rectangle content bounds, as a whole
cawthron
parents:
diff changeset
    70
 *	2) Rectangle prompt image bounds, or null
cawthron
parents:
diff changeset
    71
 *	3) Rectangle prompt label bounds
cawthron
parents:
diff changeset
    72
 *	4) int column where divider is drawn
cawthron
parents:
diff changeset
    73
 */
cawthron
parents:
diff changeset
    74
var FORM_PROMPT_RECT_INDEX = 0;
cawthron
parents:
diff changeset
    75
var FORM_CONTENT_RECT_INDEX = 1;
cawthron
parents:
diff changeset
    76
var FORM_PROMPT_IMAGE_RECT_INDEX = 2;
cawthron
parents:
diff changeset
    77
var FORM_PROMPT_LABEL_RECT_INDEX = 3;
cawthron
parents:
diff changeset
    78
var FORM_DIVIDER_OFFSET_INDEX = 4;
cawthron
parents:
diff changeset
    79
cawthron
parents:
diff changeset
    80
function getFormItemRectanglesInRect(instance, laf, rect) {
cawthron
parents:
diff changeset
    81
	var formInstance = instance.parent;
cawthron
parents:
diff changeset
    82
	var dividerOffset = getFormPromptDividerOffset(instance.parent, laf);
cawthron
parents:
diff changeset
    83
cawthron
parents:
diff changeset
    84
	var bmsize = laf.getDimension("form.image.size").x;
cawthron
parents:
diff changeset
    85
	
cawthron
parents:
diff changeset
    86
	var promptRect, contentRect, promptImageRect = null, promptLabelRect;
cawthron
parents:
diff changeset
    87
	
cawthron
parents:
diff changeset
    88
	// NOTE: S60 seems to NOT add padding for prompts, but we do it anyway
cawthron
parents:
diff changeset
    89
	if (isDoubleSpaced(formInstance)) {
cawthron
parents:
diff changeset
    90
		var promptExtent = getFontHeight(getFormPromptFont(laf));
cawthron
parents:
diff changeset
    91
	
cawthron
parents:
diff changeset
    92
		//		println("rect="+rect+", dividerOffset="+dividerOffset+", promptExtent="+promptExtent);
cawthron
parents:
diff changeset
    93
		promptRect = new Rectangle(rect.x + dividerOffset + getFormPadding(laf), rect.y + getFormPadding(laf), 
cawthron
parents:
diff changeset
    94
			rect.width - dividerOffset - getFormPadding(laf), promptExtent);
cawthron
parents:
diff changeset
    95
		promptLabelRect = new Rectangle(promptRect.x, promptRect.y,
cawthron
parents:
diff changeset
    96
			promptRect.width, promptRect.height);
cawthron
parents:
diff changeset
    97
			
cawthron
parents:
diff changeset
    98
		if (isShowingBitmaps(formInstance)) {
cawthron
parents:
diff changeset
    99
			// image is on left side of divider, flush right
cawthron
parents:
diff changeset
   100
			promptImageRect = new Rectangle(
cawthron
parents:
diff changeset
   101
				rect.x + dividerOffset - bmsize - getFormPadding(laf)/3, 
cawthron
parents:
diff changeset
   102
				rect.y,
cawthron
parents:
diff changeset
   103
				bmsize,
cawthron
parents:
diff changeset
   104
				bmsize);
cawthron
parents:
diff changeset
   105
				
cawthron
parents:
diff changeset
   106
		}
cawthron
parents:
diff changeset
   107
		
cawthron
parents:
diff changeset
   108
		var leftMargin = dividerOffset + getFormPadding(laf) * 2;
cawthron
parents:
diff changeset
   109
		contentRect = new Rectangle(rect.x + leftMargin, 
cawthron
parents:
diff changeset
   110
				rect.y + promptExtent + getFormLineGap(laf),
cawthron
parents:
diff changeset
   111
				rect.width - leftMargin, 
cawthron
parents:
diff changeset
   112
				rect.height - promptExtent);
cawthron
parents:
diff changeset
   113
		
cawthron
parents:
diff changeset
   114
	} else {
cawthron
parents:
diff changeset
   115
		promptRect = new Rectangle(rect.x, rect.y, 
cawthron
parents:
diff changeset
   116
						dividerOffset - getFormPadding(laf), rect.height);
cawthron
parents:
diff changeset
   117
cawthron
parents:
diff changeset
   118
		if (isShowingBitmaps(formInstance)) {
cawthron
parents:
diff changeset
   119
			// image is on left side of label, flush left
cawthron
parents:
diff changeset
   120
			promptImageRect = new Rectangle(
cawthron
parents:
diff changeset
   121
				promptRect.x, 
cawthron
parents:
diff changeset
   122
				promptRect.y + (promptRect.height - bmsize) / 2,
cawthron
parents:
diff changeset
   123
				bmsize,
cawthron
parents:
diff changeset
   124
				bmsize);
cawthron
parents:
diff changeset
   125
cawthron
parents:
diff changeset
   126
			promptLabelRect = new Rectangle(
cawthron
parents:
diff changeset
   127
				promptRect.x + bmsize + 2, promptRect.y, 
cawthron
parents:
diff changeset
   128
				promptRect.width - bmsize, promptRect.height);
cawthron
parents:
diff changeset
   129
		} else {
cawthron
parents:
diff changeset
   130
			promptLabelRect = new Rectangle(
cawthron
parents:
diff changeset
   131
				promptRect.x, promptRect.y, 
cawthron
parents:
diff changeset
   132
				promptRect.width, promptRect.height);
cawthron
parents:
diff changeset
   133
		}
cawthron
parents:
diff changeset
   134
		
cawthron
parents:
diff changeset
   135
		var leftMargin = dividerOffset + getFormPadding(laf);
cawthron
parents:
diff changeset
   136
		contentRect = new Rectangle(rect.x + leftMargin, rect.y, 
cawthron
parents:
diff changeset
   137
				rect.width - leftMargin, rect.height);
cawthron
parents:
diff changeset
   138
		
cawthron
parents:
diff changeset
   139
	}
cawthron
parents:
diff changeset
   140
		
cawthron
parents:
diff changeset
   141
	var rects = [ promptRect, contentRect, promptImageRect, promptLabelRect, dividerOffset ];
cawthron
parents:
diff changeset
   142
	//println( "rects = " + rects);
cawthron
parents:
diff changeset
   143
	return rects;
cawthron
parents:
diff changeset
   144
}
cawthron
parents:
diff changeset
   145
cawthron
parents:
diff changeset
   146
function getFormItemRectangles(instance, laf) {
cawthron
parents:
diff changeset
   147
	var rect = new Rectangle(0, 0, 
cawthron
parents:
diff changeset
   148
		instance.properties.size.width, instance.properties.size.height);
cawthron
parents:
diff changeset
   149
	return getFormItemRectanglesInRect(instance, laf, rect);
cawthron
parents:
diff changeset
   150
}
cawthron
parents:
diff changeset
   151
cawthron
parents:
diff changeset
   152
function getFormPromptFont(laf) {
cawthron
parents:
diff changeset
   153
	return laf.getFont("DenseFont");
cawthron
parents:
diff changeset
   154
}
cawthron
parents:
diff changeset
   155
cawthron
parents:
diff changeset
   156
function getFormPromptFlags(instance) {
cawthron
parents:
diff changeset
   157
	var flags = Font.OVERFLOW_ELLIPSIS;
cawthron
parents:
diff changeset
   158
	
cawthron
parents:
diff changeset
   159
	if (isDoubleSpaced(instance.parent) || isShowingBitmaps(instance.parent))
cawthron
parents:
diff changeset
   160
		flags |= Font.ALIGN_LEFT;
cawthron
parents:
diff changeset
   161
	else
cawthron
parents:
diff changeset
   162
		flags |= Font.ALIGN_RIGHT;
cawthron
parents:
diff changeset
   163
	
cawthron
parents:
diff changeset
   164
	return flags;
cawthron
parents:
diff changeset
   165
}
cawthron
parents:
diff changeset
   166
cawthron
parents:
diff changeset
   167
function isFirstField(instance) {
cawthron
parents:
diff changeset
   168
	var siblings = instance.parent.children;
cawthron
parents:
diff changeset
   169
	if (siblings != null)
cawthron
parents:
diff changeset
   170
		return instance == siblings[0];
cawthron
parents:
diff changeset
   171
		
cawthron
parents:
diff changeset
   172
	return false;
cawthron
parents:
diff changeset
   173
}
cawthron
parents:
diff changeset
   174
cawthron
parents:
diff changeset
   175
function drawFormPrompt(prototype, instance, laf, graphics, rects) {
cawthron
parents:
diff changeset
   176
	var formInstance = instance.parent;
cawthron
parents:
diff changeset
   177
	var properties = instance.properties;
cawthron
parents:
diff changeset
   178
	var prompt = properties.prompt;
cawthron
parents:
diff changeset
   179
	
cawthron
parents:
diff changeset
   180
	var font = getFormPromptFont(laf);
cawthron
parents:
diff changeset
   181
	graphics.setFont(font);
cawthron
parents:
diff changeset
   182
cawthron
parents:
diff changeset
   183
	var rect = rects[FORM_PROMPT_RECT_INDEX];	
cawthron
parents:
diff changeset
   184
	graphics.setBackground(laf.getColor("EEikColorWindowBackground"));
cawthron
parents:
diff changeset
   185
	graphics.fillRectangle(rect);
cawthron
parents:
diff changeset
   186
cawthron
parents:
diff changeset
   187
	graphics.setForeground(laf.getColor("EEikColorControlText"));
cawthron
parents:
diff changeset
   188
cawthron
parents:
diff changeset
   189
	// in single spaced only, draw line before prompt if separator before or after is specified
cawthron
parents:
diff changeset
   190
	// and this is not the first form field (2.x only)
cawthron
parents:
diff changeset
   191
	var version = getComponentVersions();
cawthron
parents:
diff changeset
   192
	if (!isDoubleSpaced(formInstance) && !isFirstField(instance) && properties.EEikDlgItemSeparatorBefore
cawthron
parents:
diff changeset
   193
		&& version.getMajor() < 3) {
cawthron
parents:
diff changeset
   194
		graphics.drawLine(rect.x, rect.y, rect.width + getFormPadding(laf) - 1, rect.y);
cawthron
parents:
diff changeset
   195
	}
cawthron
parents:
diff changeset
   196
cawthron
parents:
diff changeset
   197
	// draw bitmap on the left side of the divider
cawthron
parents:
diff changeset
   198
	if (isShowingBitmaps(formInstance)) {
cawthron
parents:
diff changeset
   199
		var imageRect = rects[FORM_PROMPT_IMAGE_RECT_INDEX];
cawthron
parents:
diff changeset
   200
		renderImage(prototype, instance, laf, graphics, 
cawthron
parents:
diff changeset
   201
			0, 0, "promptImage", false);
cawthron
parents:
diff changeset
   202
	}
cawthron
parents:
diff changeset
   203
	
cawthron
parents:
diff changeset
   204
	rect = rects[FORM_PROMPT_LABEL_RECT_INDEX];
cawthron
parents:
diff changeset
   205
	var height = getFontHeight(font);
cawthron
parents:
diff changeset
   206
	var textRect = new Rectangle(rect.x, rect.y + (rect.height - height)/2,
cawthron
parents:
diff changeset
   207
			rect.width, height);
cawthron
parents:
diff changeset
   208
	var promptText = chooseScalableText(prompt, font, textRect.width);
cawthron
parents:
diff changeset
   209
	graphics.drawFormattedString(promptText, textRect, getFormPromptFlags(instance), 0);	
cawthron
parents:
diff changeset
   210
}
cawthron
parents:
diff changeset
   211
cawthron
parents:
diff changeset
   212
function getFormContentBounds(instance, laf) {
cawthron
parents:
diff changeset
   213
	var rect = new Rectangle(0, 0, 
cawthron
parents:
diff changeset
   214
		instance.properties.size.width, instance.properties.size.height);
cawthron
parents:
diff changeset
   215
	if (isForm(instance.parent)) {
cawthron
parents:
diff changeset
   216
		return getFormItemRectanglesInRect(instance, laf, rect)[FORM_CONTENT_RECT_INDEX];
cawthron
parents:
diff changeset
   217
	}
cawthron
parents:
diff changeset
   218
	return rect;		
cawthron
parents:
diff changeset
   219
}
cawthron
parents:
diff changeset
   220
cawthron
parents:
diff changeset
   221
cawthron
parents:
diff changeset
   222