|
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 include("../renderLibrary.js") |
|
20 include("../implLibrary.js") |
|
21 |
|
22 function CEikLabelVisual() { |
|
23 } |
|
24 |
|
25 function isDialog(inst) { |
|
26 return inst.componentId == "com.nokia.sdt.series60.CAknDialog"; |
|
27 } |
|
28 |
|
29 CEikLabelVisual.prototype.draw = function(instance, laf, graphics) { |
|
30 draw(instance, laf, graphics, false); |
|
31 } |
|
32 |
|
33 CEikLabelVisual.prototype.getPreferredSize = function(instance, laf, wHint, hHint) { |
|
34 return getPreferredSize(instance, laf, wHint, hHint, !isDialog(instance.parent)); |
|
35 } |
|
36 |
|
37 |
|
38 setupCommonDirectLabelEditing(CEikLabelVisual.prototype, |
|
39 "text", |
|
40 null, |
|
41 function(instance, laf) { return laf.getFont(instance.properties.font); } |
|
42 ) |
|
43 |
|
44 function draw(instance, laf, graphics, wrap) { |
|
45 var properties = instance.properties |
|
46 var flags = 0; |
|
47 |
|
48 if (wrap) |
|
49 flags |= Font.WRAPPING_ENABLED; |
|
50 else |
|
51 flags |= Font.WRAPPING_NONE; |
|
52 |
|
53 switch (properties.alignment) { |
|
54 case "EEikLabelAlignHCenter": |
|
55 flags |= Font.ALIGN_CENTER; break; |
|
56 case "EEikLabelAlignHLeft": |
|
57 flags |= Font.ALIGN_LEFT; break; |
|
58 case "EEikLabelAlignHRight": |
|
59 flags |= Font.ALIGN_RIGHT; break; |
|
60 } |
|
61 if (properties.strikethrough != false) |
|
62 flags |= Font.OPTIONS_STRIKETHROUGH; |
|
63 if (properties.underline != false) |
|
64 flags |= Font.OPTIONS_UNDERLINE; |
|
65 |
|
66 /* |
|
67 switch (properties.emphasis) { |
|
68 case "EPartialEmphasis": |
|
69 flags |= Font.OPTIONS_BOLD; |
|
70 break; |
|
71 case "EFullEmphasis": |
|
72 flags |= Font.OPTIONS_EXTRABOLD; |
|
73 } |
|
74 */ |
|
75 |
|
76 var font = laf.getFont(properties.font); |
|
77 graphics.setFont(font); |
|
78 |
|
79 var pattern = null; |
|
80 var drawBg = false; |
|
81 graphics.setBackground(getBackgroundColor(instance, laf)) |
|
82 |
|
83 switch (properties.emphasis) { |
|
84 case "EPartialEmphasis": |
|
85 drawBg = true; |
|
86 graphics.setBackground(laf.getColor("EEikColorLabelBackgroundPartialEmphasis")); |
|
87 break; |
|
88 case "EFullEmphasis": |
|
89 drawBg = true; |
|
90 graphics.setBackground(laf.getColor("EEikColorLabelBackgroundFullEmphasis")); |
|
91 } |
|
92 |
|
93 // get bounding rect |
|
94 var rect = instance.getRenderingBounds(); |
|
95 var text = chooseScalableText(properties.text, font, rect.width); |
|
96 |
|
97 if (drawBg) { |
|
98 graphics.fillRectangle(rect); |
|
99 } |
|
100 |
|
101 if (properties.brushStyle != "ENullBrush") { |
|
102 pattern = getPattern(graphics, properties.brushStyle); |
|
103 graphics.setBackgroundPattern(pattern); |
|
104 graphics.fillRectangle(rect); |
|
105 } |
|
106 |
|
107 |
|
108 // Series 60 draws left justified if the extent is at least the bounds |
|
109 oversize = new Point(rect.width * 2, rect.height); |
|
110 size = graphics.formattedStringExtent(text, oversize, flags | Font.WRAPPING_NONE); |
|
111 if (size.x >= rect.width) { |
|
112 flags &= ~Font.ALIGN_MASK; |
|
113 flags |= Font.ALIGN_LEFT; |
|
114 } |
|
115 |
|
116 text = text.replace(/\u2028|\u2029/,"\u7fff"); |
|
117 graphics.drawFormattedString(text, |
|
118 rect, |
|
119 flags, |
|
120 properties.pixelGapBetweenLines); |
|
121 |
|
122 if (pattern != null) |
|
123 pattern.dispose(); |
|
124 } |
|
125 |
|
126 // N.B.: we must define this function outside the prototype |
|
127 // in order for strings to persist as such. Otherwise they |
|
128 // are converted to Object and switch() no longer works! |
|
129 |
|
130 function getPattern(graphics, patt) { |
|
131 |
|
132 if (this.image3 == null) { |
|
133 this.image3 = Images.newImage(graphics.getDevice(), 3, 3) |
|
134 } |
|
135 if (this.image4 == null) { |
|
136 this.image4 = Images.newImage(graphics.getDevice(), 4, 4) |
|
137 } |
|
138 |
|
139 //println("brush type: " +typeof(patt)); |
|
140 |
|
141 var img; |
|
142 if (patt != "EDiamondCrossHatchBrush" |
|
143 && patt != "EVerticalHatchBrush" |
|
144 && patt != "EHorizontalHatchBrush") |
|
145 img = this.image3 |
|
146 else |
|
147 img = this.image4 |
|
148 |
|
149 var gc = new GC(graphics.getDevice(), img) |
|
150 |
|
151 //gc.setBackground(Colors.getColor(255, 255, 255)) |
|
152 gc.setBackground(graphics.getBackground()) |
|
153 gc.fillRectangle(0, 0, 4, 4); |
|
154 gc.setBackground(Colors.getColor(255, 255,255)) |
|
155 gc.setForeground(Colors.getColor(0, 0, 0)) |
|
156 |
|
157 switch (patt) { |
|
158 case "EVerticalHatchBrush": |
|
159 gc.drawLine(1, 0, 1, 3); |
|
160 gc.drawLine(3, 0, 3, 3); |
|
161 break; |
|
162 case "EForwardDiagonalHatchBrush": |
|
163 gc.drawLine(0, 2, 2, 0); |
|
164 break; |
|
165 case "EHorizontalHatchBrush": |
|
166 gc.drawLine(0, 1, 3, 1); |
|
167 gc.drawLine(0, 3, 3, 3); |
|
168 break; |
|
169 case "ERearwardDiagonalHatchBrush": |
|
170 gc.drawLine(0, 0, 2, 2); |
|
171 break; |
|
172 case "ESquareCrossHatchBrush": |
|
173 gc.drawLine(1, 0, 1, 3); |
|
174 gc.drawLine(0, 1, 3, 1); |
|
175 break; |
|
176 case "EDiamondCrossHatchBrush": |
|
177 gc.drawLine(0, 0, 3, 3); |
|
178 gc.drawLine(2, 0, 0, 2); |
|
179 break; |
|
180 case "ESolidBrush": |
|
181 default: |
|
182 // note: if all cases come here, it's because switch(string) |
|
183 // only makes sense with actual string types. |
|
184 // If this function is part of a prototype that's wrapped |
|
185 // into JS by UI Designer, then Rhino tends to coerce the arguments |
|
186 // to Object. |
|
187 |
|
188 //println("default brush type: " +patt); |
|
189 gc.setBackground(Colors.getColor(0, 0, 0)) |
|
190 gc.fillRectangle(0, 0, 5, 5); |
|
191 break; |
|
192 } |
|
193 |
|
194 gc.dispose() |
|
195 |
|
196 try { |
|
197 return new Pattern(graphics.getDevice(), img) |
|
198 } catch (e) { |
|
199 // not GDI+ |
|
200 return null; |
|
201 } |
|
202 } |
|
203 |
|
204 function getPreferredSize(instance, laf, wHint, hHint, wrap) { |
|
205 var properties = instance.properties; |
|
206 var flags = 0; |
|
207 |
|
208 if (wrap) |
|
209 flags |= Font.WRAPPING_ENABLED; |
|
210 else |
|
211 flags |= Font.WRAPPING_NONE; |
|
212 |
|
213 font = laf.getFont(properties.font); |
|
214 switch (properties.alignment) { |
|
215 case "EEikLabelAlignHCenter": |
|
216 flags |= Font.ALIGN_CENTER; break; |
|
217 case "EEikLabelAlignHLeft": |
|
218 flags |= Font.ALIGN_LEFT; break; |
|
219 case "EEikLabelAlignHRight": |
|
220 flags |= Font.ALIGN_RIGHT; break; |
|
221 } |
|
222 |
|
223 // get bounding rect |
|
224 var layoutBounds = instance.getLayoutBounds(); |
|
225 width = layoutBounds.width; |
|
226 height = layoutBounds.height; |
|
227 // if either of these are empty, use the parent's bounds as starting point |
|
228 if ((width == 0) || (height == 0)) { |
|
229 layoutBounds = instance.parent.getLayoutBounds(); |
|
230 width = layoutBounds.width; |
|
231 height = layoutBounds.height; |
|
232 } |
|
233 |
|
234 if (wHint >= 0) |
|
235 width = wHint; |
|
236 if (hHint >= 0) |
|
237 height = hHint; |
|
238 var bounds = new Point(width, height); |
|
239 |
|
240 var text = chooseScalableText(properties.text.toString(), font, width); |
|
241 if (text.length == 0) |
|
242 text = " "; |
|
243 return font.formattedStringExtent(text, bounds, flags, properties.pixelGapBetweenLines); |
|
244 } |
|
245 |