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