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