2
|
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 |
var indiFont = getIndiFont(laf);
|
|
124 |
var indiWidth = (indiFont.getCharWidth("5") * 3) / 2;
|
|
125 |
indiRect = new Rectangle(contentRect.x - indiWidth, contentRect.y,
|
|
126 |
indiWidth, contentRect.height);
|
|
127 |
|
|
128 |
var rects = [ rect, promptRect, titleRect, indiRect, contentRect, dividerOffset ];
|
|
129 |
//pr("Rects = " +rects);
|
|
130 |
return rects;
|
|
131 |
}
|
|
132 |
|
|
133 |
function getSettingItemRectangles(instance, laf) {
|
|
134 |
var rect = new Rectangle(0, 0,
|
|
135 |
instance.properties.size.width, instance.properties.size.height);
|
|
136 |
return getSettingItemRectanglesInRect(instance, laf, rect);
|
|
137 |
}
|
|
138 |
|
|
139 |
function getPromptFont(laf) {
|
|
140 |
return laf.getFont("AnnotationFont");
|
|
141 |
}
|
|
142 |
function getTitleFont(laf) {
|
|
143 |
return laf.getFont("NormalFont");
|
|
144 |
}
|
|
145 |
function getIndiFont(laf) {
|
|
146 |
var font = laf.getFont("Settings.list.indicator");
|
|
147 |
if (font != null)
|
|
148 |
return font;
|
|
149 |
|
|
150 |
return laf.getFont("NormalFont");
|
|
151 |
}
|
|
152 |
|
|
153 |
function getPromptFlags(instance) {
|
|
154 |
var flags = Font.OVERFLOW_ELLIPSIS;
|
|
155 |
|
|
156 |
flags |= Font.ALIGN_CENTER;
|
|
157 |
|
|
158 |
return flags;
|
|
159 |
}
|
|
160 |
|
|
161 |
function isFirstField(instance) {
|
|
162 |
var siblings = instance.parent.children;
|
|
163 |
if (siblings != null)
|
|
164 |
return instance == siblings[0];
|
|
165 |
|
|
166 |
return false;
|
|
167 |
}
|
|
168 |
|
|
169 |
function calcSettingItemNumber(silInstance, self) {
|
|
170 |
var number = silInstance.properties.initialNumber;
|
|
171 |
var numberHidden = silInstance.properties.EAknSettingItemIncludeHiddenInOrdinal;
|
|
172 |
for (var c in silInstance.children) {
|
|
173 |
var sib = silInstance.children[c];
|
|
174 |
if (sib == self)
|
|
175 |
break;
|
|
176 |
if (numberHidden || !sib.properties.itemHidden)
|
|
177 |
number++;
|
|
178 |
}
|
|
179 |
return number;
|
|
180 |
}
|
|
181 |
|
|
182 |
function setSettingsListLineStyle(laf, graphics) {
|
|
183 |
var version = getComponentVersions();
|
|
184 |
if ((version.getMajor() >= 3 || (version.getMajor() == 2 && version.getMinor() >= 8))
|
|
185 |
&& laf.getDimension("screen.size").x > 208) {
|
|
186 |
// use dashed line
|
|
187 |
graphics.setLineWidth(2);
|
|
188 |
graphics.setLineDash([ 2 ]);
|
|
189 |
} else {
|
|
190 |
// use solid line
|
|
191 |
graphics.setLineWidth(1);
|
|
192 |
}
|
|
193 |
|
|
194 |
}
|
|
195 |
|
|
196 |
function drawSettingItemPrompt(prototype, instance, laf, graphics, rects) {
|
|
197 |
var formInstance = instance.parent;
|
|
198 |
var properties = instance.properties;
|
|
199 |
|
|
200 |
var number = calcSettingItemNumber(instance.parent, instance);
|
|
201 |
|
|
202 |
var rect = rects[SIL_NUMBER_RECT_INDEX];
|
|
203 |
graphics.setBackground(laf.getColor("EEikColorControlBackground"));
|
|
204 |
//graphics.setBackground(getBackgroundColor(instance, laf));
|
|
205 |
|
|
206 |
graphics.fillRectangle(rect);
|
|
207 |
|
|
208 |
graphics.setForeground(laf.getColor("listitem.text"));
|
|
209 |
|
|
210 |
var itemRect = rects[SIL_ITEM_RECT_INDEX];
|
|
211 |
|
|
212 |
// no decorations on 3.1+
|
|
213 |
if (laf.getBoolean("decorations", true)) {
|
|
214 |
setSettingsListLineStyle(laf, graphics);
|
|
215 |
graphics.drawLine(rects[SIL_DIVIDER_OFFSET_INDEX],
|
|
216 |
itemRect.y + itemRect.height - 1,
|
|
217 |
itemRect.width, itemRect.y + itemRect.height - 1);
|
|
218 |
|
|
219 |
//graphics.drawLine(rects[SIL_DIVIDER_OFFSET_INDEX], itemRect.y, rects[SIL_DIVIDER_OFFSET_INDEX], itemRect.height);
|
|
220 |
}
|
|
221 |
|
|
222 |
// draw number
|
|
223 |
var font = getPromptFont(laf);
|
|
224 |
graphics.setFont(font);
|
|
225 |
if (isShowingNumbers(formInstance)) {
|
|
226 |
var numberRect = rects[SIL_NUMBER_RECT_INDEX];
|
|
227 |
graphics.drawFormattedString(number, numberRect,
|
|
228 |
Font.ALIGN_RIGHT,
|
|
229 |
0);
|
|
230 |
}
|
|
231 |
|
|
232 |
// draw item title
|
|
233 |
var font = getTitleFont(laf);
|
|
234 |
graphics.setFont(font);
|
|
235 |
rect = rects[SIL_TITLE_RECT_INDEX];
|
|
236 |
var height = getFontHeight(font);
|
|
237 |
var textRect = new Rectangle(rect.x, rect.y + (rect.height - height)/2,
|
|
238 |
rect.width, height);
|
|
239 |
var titleText = chooseScalableText(properties.itemTitle, font, textRect.width);
|
|
240 |
graphics.drawFormattedString(titleText, textRect, 0, 0);
|
|
241 |
|
|
242 |
// draw compulsory indicator
|
|
243 |
var font = getIndiFont(laf);
|
|
244 |
graphics.setFont(font);
|
|
245 |
rect = rects[SIL_INDICATOR_RECT_INDEX];
|
|
246 |
graphics.setForeground(laf.getColor("CAknSettingItemList.CompulsoryIndicator"));
|
|
247 |
graphics.drawFormattedString(properties.compulsoryLabel, rect, 0, 0);
|
|
248 |
|
|
249 |
// draw content rect
|
|
250 |
rect = rects[SIL_CONTENT_RECT_INDEX];
|
|
251 |
graphics.setBackground(laf.getColor("CAknSettingItemList.ContentBackground"));
|
|
252 |
graphics.fillRectangle(rect);
|
|
253 |
graphics.setForeground(laf.getColor("CAknSettingItemList.ContentForeground"));
|
|
254 |
}
|
|
255 |
|
|
256 |
function getSettingItemContentBounds(instance, laf) {
|
|
257 |
var rect = new Rectangle(0, 0,
|
|
258 |
instance.properties.size.width, instance.properties.size.height);
|
|
259 |
if (isForm(instance.parent)) {
|
|
260 |
return getSettingItemRectanglesInRect(instance, laf, rect)[SIL_CONTENT_RECT_INDEX];
|
|
261 |
}
|
|
262 |
return rect;
|
|
263 |
}
|
|
264 |
|
|
265 |
|