|
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("containerLibrary.js") |
|
21 |
|
22 function CCoeControlLayout() { |
|
23 } |
|
24 |
|
25 CCoeControlLayout.prototype.layout = function(instance, laf) { |
|
26 var thisWidth = instance.properties.size.width; |
|
27 var thisHeight = instance.properties.size.height; |
|
28 |
|
29 var exclusiveChild = getExclusiveChild(instance.children); |
|
30 if (exclusiveChild != null) { |
|
31 setBounds(exclusiveChild, new Rectangle(0, 0, thisWidth, thisHeight)); |
|
32 } |
|
33 } |
|
34 |
|
35 CCoeControlLayout.prototype.getPreferredSize = function(instance, laf, wHint, hHint) { |
|
36 return null; |
|
37 } |
|
38 |
|
39 function getExclusiveChild(children) { |
|
40 var result = null; |
|
41 for (var i = 0; i < children.length; i++) { |
|
42 var child = children[i]; |
|
43 if (child.component != null && child.component.attributes["is-exclusive-child-layout-object"] == "true") { |
|
44 return children[i]; |
|
45 } |
|
46 } |
|
47 return null; |
|
48 } |
|
49 |
|
50 /////////////////// |
|
51 |
|
52 |
|
53 |
|
54 function CCoeControlVisual() { |
|
55 } |
|
56 |
|
57 CCoeControlVisual.prototype.draw = function(instance, laf, graphics) { |
|
58 var properties = instance.properties; |
|
59 var color = colorFromString(laf, properties.backColor); |
|
60 if (color != null) { |
|
61 graphics.setBackground(color); |
|
62 graphics.fillRectangle(0, 0, properties.size.width, properties.size.height); |
|
63 } |
|
64 else { |
|
65 var properties = instance.properties; |
|
66 var width = properties.size.width; |
|
67 var height = properties.size.height; |
|
68 graphics.setBackground(getBackgroundColor(instance, laf)); |
|
69 graphics.fillRectangle(new Rectangle(0, 0, width, height)); |
|
70 } |
|
71 } |
|
72 |
|
73 CCoeControlVisual.prototype.getPreferredSize = function(instance, laf, wHint, hHint) { |
|
74 return null; // not needed |
|
75 } |
|
76 |
|
77 ///////////////////// |
|
78 |
|
79 function CCoeControlPropertyExtenders() { |
|
80 } |
|
81 |
|
82 // Return instances that may provide extension properties |
|
83 // The target instance parameter is the instance to receive the |
|
84 // additional properties |
|
85 CCoeControlPropertyExtenders.prototype.getPropertyExtenders = function(instance, targetInstance) { |
|
86 if (isAvkonView(targetInstance.parent) && !isPreviewPopUp(instance)) { |
|
87 return [instance]; |
|
88 } |
|
89 |
|
90 return null; |
|
91 } |
|
92 |
|
93 CCoeControlPropertyExtenders.prototype.getExtensionSetNames = function(instance, targetInstance) { |
|
94 if (instance == targetInstance) |
|
95 return [ "default" ]; |
|
96 |
|
97 return null; |
|
98 } |
|
99 |
|
100 ///////////////////// |
|
101 |
|
102 |
|
103 function CCoeControlQueryContainment() { |
|
104 } |
|
105 |
|
106 CCoeControlQueryContainment.prototype.getAllowedAttribute = function() { |
|
107 return "is-ccoecontrol-content"; |
|
108 } |
|
109 |
|
110 setupAttributeBasedQueryContainment(CCoeControlQueryContainment.prototype); |
|
111 |
|
112 ///////////////////////// |
|
113 |
|
114 function CCoeControlPropertyListener() { |
|
115 } |
|
116 |
|
117 CCoeControlPropertyListener.prototype.propertyChanged = function(instance, propertyId) { |
|
118 if (propertyId == "backColor") { |
|
119 // anything hosted on top may depend on the color |
|
120 for (var c in instance.children) { |
|
121 instance.children[c].forceRedraw(); |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 ///////////////////////// |
|
127 |
|
128 function CCoeControlChildListener() { |
|
129 } |
|
130 |
|
131 CCoeControlChildListener.prototype.childAdded = function(instance, child, laf) { |
|
132 var properties = instance.properties; |
|
133 var childWantsFocus = hasAttributeValue(child.attributes, "wants-initial-focus", "true"); |
|
134 var numFocusableChildren = |
|
135 countImmediateChildrenWithAttributeValue(instance.children, "wants-initial-focus", "true"); |
|
136 |
|
137 // if has no initial focus, but the child just added is the only one that wants it |
|
138 if ((properties.initialFocus == "") && childWantsFocus && (numFocusableChildren == 1)) |
|
139 properties.initialFocus = child.name; |
|
140 } |
|
141 |
|
142 CCoeControlChildListener.prototype.childRemoved = function(instance, child, laf) { |
|
143 // nothing to do |
|
144 } |
|
145 |
|
146 CCoeControlChildListener.prototype.childrenReordered = function(instance, laf) { |
|
147 // nothing to do |
|
148 } |
|
149 |
|
150 ////////////////////////////////////////// |
|
151 // IComponentEventInfo |
|
152 ////////////////////////////////////////// |
|
153 function CCoeControlEventInfo(){} |
|
154 |
|
155 CCoeControlEventInfo.prototype.getEventGroups = function(instance) { |
|
156 // Get the proper events depending on the SDK. |
|
157 version = getComponentVersions(); |
|
158 if (version.major >= 5) { |
|
159 // Add touch events |
|
160 return ["TouchUIEvent", "CustomCCoeControl", "CCoeControl"]; |
|
161 } |
|
162 else { |
|
163 // sdks prior to touch |
|
164 return ["CustomCCoeControl", "CCoeControl"]; |
|
165 } |
|
166 } |