|
1 /* |
|
2 * Copyright (c) 2007 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 |
|
21 function StylusPopupItem() { |
|
22 this.lafInfo = null; |
|
23 } |
|
24 |
|
25 ///////////////////////// |
|
26 // IVisualAppearance |
|
27 ///////////////////////// |
|
28 StylusPopupItem.prototype.draw = function(instance, laf, graphics) { |
|
29 var props = instance.properties; |
|
30 |
|
31 if (props.textItem == ""){ |
|
32 // default text |
|
33 props.textItem = "new item"; |
|
34 } |
|
35 graphics.setBackground(getBackgroundColor(instance, laf)); |
|
36 drawTextItem(props.textItem, new Point(0, 0), new Point(props.size.width , props.size.height), laf, graphics); |
|
37 } |
|
38 |
|
39 StylusPopupItem.prototype.getPreferredSize = function(instance, laf, wHint, hHint) { |
|
40 return null; |
|
41 } |
|
42 |
|
43 function drawTextItem(text, location, size, laf, graphics) { |
|
44 |
|
45 var x = location.x; |
|
46 var y = location.y; |
|
47 var width = size.x; |
|
48 var height = size.y; |
|
49 |
|
50 var font = laf.getFont("menuitem.font"); |
|
51 graphics.setFont(font); |
|
52 |
|
53 var margin = laf.getInteger("control.pane.text.margin", 5); |
|
54 var extent = font.stringExtent(text) |
|
55 |
|
56 if (laf.getBoolean("is.portrait", true)) { |
|
57 var fontOffset = (height - extent.y) / 2 |
|
58 |
|
59 var rect = new Rectangle(x + margin, y + fontOffset, |
|
60 width - (2*margin), height ); |
|
61 |
|
62 graphics.fillRectangle(x, y, width, height); |
|
63 |
|
64 text = chooseScalableText(text, font, rect.width); |
|
65 graphics.drawFormattedString(text, rect, Font.ALIGN_LEFT | Font.OVERFLOW_ELLIPSIS, 0); |
|
66 } |
|
67 else { |
|
68 var fontHeight = font.getHeight(); |
|
69 var sbar1Bounds = laf.getRectangle("status.bar1.bounds"); |
|
70 var sbar2Bounds = laf.getRectangle("status.bar2.bounds"); |
|
71 |
|
72 var fontOffset = (sbar2Bounds.height - extent.y) / 2 |
|
73 |
|
74 var rect = new Rectangle(x, y + fontOffset, width-margin, height-fontOffset); |
|
75 graphics.fillRectangle(x, y + sbar1Bounds.y, width, sbar1Bounds.height); |
|
76 |
|
77 rect.y = y + height - sbar2Bounds.height + fontOffset -5; |
|
78 rect.height = sbar2Bounds.height - fontOffset; |
|
79 |
|
80 graphics.fillRectangle(x, y + sbar2Bounds.y, width, sbar2Bounds.height); |
|
81 text = chooseScalableText(text, font, rect.width); |
|
82 graphics.drawFormattedString(text, rect, Font.ALIGN_LEFT | Font.OVERFLOW_ELLIPSIS, 0); |
|
83 } |
|
84 } |
|
85 |
|
86 ////////////////////////// |
|
87 // IDirectLableEdit |
|
88 ////////////////////////// |
|
89 StylusPopupItem.prototype.getLabelFont = function(instance, propertyPath, laf) { |
|
90 return laf.getFont("menuitem.font"); |
|
91 } |
|
92 |
|
93 |
|
94 StylusPopupItem.prototype.getPropertyPaths = function(instance) { |
|
95 return new Array("textItem"); |
|
96 } |
|
97 |
|
98 StylusPopupItem.prototype.getLabelBounds = function(instance, propertyPath, laf) { |
|
99 var props = instance.properties; |
|
100 return new Rectangle(0, 0, props.size.width, props.size.height); |
|
101 } |