|
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("../messageLibrary.js") |
|
20 |
|
21 var STATUS_PANE_ID = "com.nokia.sdt.series60.StatusPane"; |
|
22 |
|
23 function setBounds(container, rect) { |
|
24 if (container.properties.location.x != rect.x |
|
25 || container.properties.location.y != rect.y) { |
|
26 //println("Setting location for " + container.instanceName + " to " + rect.x + "," + rect.y); |
|
27 container.properties.location.x = rect.x; |
|
28 container.properties.location.y = rect.y; |
|
29 } |
|
30 if (container.properties.size.width != rect.width |
|
31 || container.properties.size.height != rect.height) { |
|
32 //println("Setting size for " + container.instanceName + " to " + rect.width + "," + rect.height); |
|
33 container.properties.size.width = rect.width; |
|
34 container.properties.size.height = rect.height; |
|
35 } |
|
36 } |
|
37 |
|
38 function doScreenLayout(container, laf) { |
|
39 var screenWidth = container.properties.size.width; |
|
40 var screenHeight = container.properties.size.height; |
|
41 var children = container.children; |
|
42 |
|
43 var statusArea = getStatusPane(children); |
|
44 if (statusArea != null) { |
|
45 setBounds(statusArea, laf.getRectangle("status.pane.bounds")); |
|
46 } |
|
47 |
|
48 var cba = getControlPane(children); |
|
49 if (cba != null) { |
|
50 setBounds(cba, laf.getRectangle("control.pane.bounds")); |
|
51 } |
|
52 |
|
53 var contents = getContents(children); |
|
54 if (contents != null) { |
|
55 setBounds(contents, laf.getRectangle("content.pane.bounds")); |
|
56 } |
|
57 } |
|
58 |
|
59 function getControlPane(children) { |
|
60 return findImmediateChildByComponentID(children, "com.nokia.sdt.series60.CBABase"); |
|
61 } |
|
62 |
|
63 function getToolbar(children) { |
|
64 return findImmediateChildByComponentID(children, "com.nokia.sdt.series60.Toolbar"); |
|
65 } |
|
66 |
|
67 function getStatusPane(children) { |
|
68 return findImmediateChildByComponentID(children, "com.nokia.sdt.series60.StatusPane"); |
|
69 } |
|
70 |
|
71 function getNaviPaneContent(children) { |
|
72 return findImmediateChildByAttributeValue(children, "is-navipane-content", "true"); |
|
73 } |
|
74 |
|
75 function getStatusPaneContent(children, componentIdArg) { |
|
76 return findImmediateChildByComponentID(children, componentIdArg); |
|
77 } |
|
78 |
|
79 |
|
80 function getContents(children) { |
|
81 return findImmediateChildByAttributeValue(children, "is-top-level-content-container", "true"); |
|
82 } |
|
83 |
|
84 function findImmediateChildByAttributeValue(children, attrName, attrValue) { |
|
85 var result = null; |
|
86 if (children != null) { |
|
87 for (var i in children) { |
|
88 var child = children[i]; |
|
89 if (child.component != null && child.component.attributes != null && |
|
90 child.component.attributes[attrName] == attrValue) { |
|
91 result = child; |
|
92 break; |
|
93 } |
|
94 } |
|
95 } |
|
96 return result; |
|
97 } |
|
98 |
|
99 function findImmediateChildByComponentID(children, componentID) { |
|
100 var result = null; |
|
101 for (var i in children) { |
|
102 var child = children[i]; |
|
103 if (child.component != null && child.component.isOfType(componentID)) { |
|
104 result = child; |
|
105 break; |
|
106 } |
|
107 } |
|
108 return result; |
|
109 } |
|
110 |
|
111 function hasAttributeValue(attributesArg, attrName, attrValue) { |
|
112 return attributesArg[attrName] == attrValue; |
|
113 } |
|
114 |
|
115 function hasTopLevelContentContainerAttribute(attributesArg) { |
|
116 return hasAttributeValue(attributesArg, "is-top-level-content-container", "true"); |
|
117 } |
|
118 |
|
119 function hasStatusPaneContentAttribute(attributesArg) { |
|
120 return hasAttributeValue(attributesArg, "is-status-pane-content", "true"); |
|
121 } |
|
122 |
|
123 function buildSimpleContainmentErrorStatus(errorString, params) { |
|
124 return buildSimpleErrorStatus(errorString, params); |
|
125 } |
|
126 |
|
127 function buildMultipleContainmentErrorStatus(header, errorString, params, status) { |
|
128 return buildMultipleErrorStatus(header, errorString, params, status); |
|
129 } |
|
130 |
|
131 function isControlPane(component) { |
|
132 return component.isOfType("com.nokia.sdt.series60.CBABase"); |
|
133 } |
|
134 |
|
135 function isToolbar(component) { |
|
136 return component.isOfType("com.nokia.sdt.series60.Toolbar"); |
|
137 } |
|
138 |
|
139 function isStatusPaneId(componentIdArg) { |
|
140 return componentIdArg == STATUS_PANE_ID; |
|
141 } |
|
142 |
|
143 function isDesignRef(component) { |
|
144 return component.isOfType("com.nokia.sdt.series60.DesignReference"); |
|
145 } |
|
146 |
|
147 function getLayoutChildren(children) { |
|
148 var result = []; |
|
149 var idx = 0; |
|
150 if (children != null) { |
|
151 for (var i in children) { |
|
152 var child = children[i]; |
|
153 if (child.component != null && child.component.attributes != null |
|
154 && child.component.attributes["is-non-layout-object"] != "true" |
|
155 && child.component.attributes["is-non-transient-object"] != "true") { |
|
156 result[idx++] = child; |
|
157 } |
|
158 } |
|
159 } |
|
160 return result; |
|
161 } |
|
162 |
|
163 function allowsCBAInParent(instance) { |
|
164 return instance.attributes["allow-cba-in-parent"] == "true"; |
|
165 } |
|
166 |
|
167 function getInstanceFromChildName(children, name) { |
|
168 if (children != null) { |
|
169 for (i in children) { |
|
170 if (children[i].name == name) { |
|
171 return children[i]; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 return null; |
|
177 } |
|
178 |
|
179 |
|
180 /** |
|
181 * Find a child of type CAknForm |
|
182 */ |
|
183 function findAknFormChild(children) { |
|
184 return findImmediateChildByComponentID(children, "com.nokia.sdt.series60.CAknForm"); |
|
185 } |
|
186 |
|
187 /** |
|
188 * Iterate children to find the one with exitsApp property and return property value |
|
189 */ |
|
190 function childWantsExitBehavior(children) { |
|
191 for (var i in children) { |
|
192 if (children[i].isInstanceOf("com.nokia.sdt.series60.ContainerBase")) { |
|
193 return children[i].properties.exitsApp; |
|
194 } |
|
195 } |
|
196 |
|
197 return false; |
|
198 } |
|
199 |
|
200 |
|
201 function findNaviTabs(appUiInstance) { |
|
202 var statusPane = findImmediateChildByComponentID(appUiInstance.children, "com.nokia.sdt.series60.StatusPane"); |
|
203 if (statusPane != null) { |
|
204 var naviTabs = findImmediateChildByComponentID(statusPane.children, "com.nokia.sdt.series60.NaviTabs"); |
|
205 return naviTabs; |
|
206 } |
|
207 |
|
208 return null; |
|
209 } |
|
210 |
|
211 function hasNaviTabs(appUiInstance) { |
|
212 return findNaviTabs(appUiInstance) != null; |
|
213 } |
|
214 |
|
215 /** |
|
216 * Get the view UID enumerator, adding the generating #include if necessary (for use from views) |
|
217 */ |
|
218 function getViewUidConstant(instance) { |
|
219 // the algorithm can deal with either CAknView or AvkonViewReference |
|
220 var name = Engine.queryEnumeratorForAlgorithm(instance, ".", |
|
221 "com.nokia.sdt.component.symbian.NAME_ALG_VIEW_UID"); |
|
222 return name; |
|
223 } |
|
224 |
|
225 /** |
|
226 * Find or create the view UID enumerator (for use from appui) |
|
227 */ |
|
228 function findOrCreateViewUidConstant(instance) { |
|
229 // the algorithm can deal with either CAknView or AvkonViewReference |
|
230 return Engine.findOrCreateEnumeratorForAlgorithm(instance, ".", |
|
231 "com.nokia.sdt.component.symbian.NAME_ALG_VIEW_UID"); |
|
232 } |
|
233 |
|
234 /** |
|
235 * Get the name of the project's HRH file (which contains view UID enums) |
|
236 */ |
|
237 function getProjectHrhFile() { |
|
238 return getProjectName() + ".hrh"; |
|
239 } |
|
240 |
|
241 /** |
|
242 * Get the name of the project's HRH file (which contains view UID enums) |
|
243 */ |
|
244 function includeProjectHrhFile(contribs) { |
|
245 var mycontrib = Engine.createContributionForPhase("MainUserIncludes") |
|
246 mycontrib.setText("#include \"" + getProjectHrhFile() + "\"\n"); |
|
247 contribs.add(mycontrib); |
|
248 } |
|
249 |
|
250 /** |
|
251 * Set up query containment based on an attribute in potential children. |
|
252 * |
|
253 * @param prototype the prototype to add IQueryContainment to. |
|
254 * The prototype must implement this functions: |
|
255 * <p> |
|
256 * <li> |
|
257 * getAllowedAttribute(): return the attribute string for allowed children |
|
258 * |
|
259 * The component must define a string with ID "generalContainmentError" |
|
260 * that takes a single argument for the type of component: e.g., |
|
261 * "A <container_type_name> can''t contain objects of type ''{0}''." |
|
262 */ |
|
263 function setupAttributeBasedQueryContainment(prototype) { |
|
264 var origCanContainComponent = null; |
|
265 if ("canContainComponent" in prototype) |
|
266 origCanContainComponent = prototype.canContainComponent; |
|
267 prototype.canContainComponent = function(instance, otherComponent) { |
|
268 var status = null; |
|
269 if (origCanContainComponent != null) { |
|
270 status = origCanContainComponent(instance, otherComponent); |
|
271 } |
|
272 var attrName = prototype.getAllowedAttribute(); |
|
273 if (!hasAttributeValue(otherComponent.attributes, attrName, "true")) |
|
274 if (status != null) |
|
275 return buildMultipleContainmentErrorStatus( |
|
276 lookupString("containmentErrorHeader"), |
|
277 lookupString("generalContainmentError"), |
|
278 new Array( otherComponent.friendlyName ), status); |
|
279 else |
|
280 return buildSimpleContainmentErrorStatus( |
|
281 lookupString("generalContainmentError"), |
|
282 new Array( otherComponent.friendlyName )); |
|
283 |
|
284 return status; |
|
285 } |
|
286 |
|
287 var origCanContainChild = null; |
|
288 if ("canContainChild" in prototype) |
|
289 origCanContainChild = prototype.canContainChild; |
|
290 prototype.canContainChild = function(instance, child) { |
|
291 var status = null; |
|
292 if (origCanContainChild != null) { |
|
293 status = origCanContainChild(instance, child); |
|
294 } |
|
295 var attrName = prototype.getAllowedAttribute(); |
|
296 if (!hasAttributeValue(child.component.attributes, attrName, "true")) |
|
297 if (status != null) |
|
298 return buildMultipleContainmentErrorStatus( |
|
299 lookupString("containmentErrorHeader"), |
|
300 lookupString("generalContainmentError"), |
|
301 new Array( otherComponent.friendlyName ), status); |
|
302 else |
|
303 return buildSimpleContainmentErrorStatus( |
|
304 lookupString("generalContainmentError"), |
|
305 new Array( child.component.friendlyName )); |
|
306 |
|
307 return status; |
|
308 } |
|
309 |
|
310 var origCanRemoveChild = null; |
|
311 if ("canRemoveChild" in prototype) |
|
312 origCanRemoveChild = prototype.canRemoveChild; |
|
313 prototype.canRemoveChild = function(instance, child) { |
|
314 if (origCanRemoveChild != null) { |
|
315 return origCanRemoveChild(instance, child); |
|
316 } |
|
317 return true; // everything can be removed |
|
318 } |
|
319 |
|
320 var origIsValidComponentInPalette = null; |
|
321 if ("isValidComponentInPalette" in prototype) |
|
322 origIsValidComponentInPalette = prototype.isValidComponentInPalette; |
|
323 prototype.isValidComponentInPalette = function(instance, otherComponent) { |
|
324 if (origIsValidComponentInPalette != null) { |
|
325 var result = origIsValidComponentInPalette(instance, otherComponent); |
|
326 if (!result) |
|
327 return result; |
|
328 } |
|
329 var attrName = prototype.getAllowedAttribute(); |
|
330 return hasAttributeValue(otherComponent.attributes, attrName, "true"); |
|
331 } |
|
332 } |
|
333 |
|
334 function countImmediateChildrenWithAttributeValue(children, attrName, attrValue) { |
|
335 var result = 0; |
|
336 if (children != null) { |
|
337 for (var i in children) { |
|
338 var child = children[i]; |
|
339 if (child.component != null && child.component.attributes != null && |
|
340 child.component.attributes[attrName] == attrValue) { |
|
341 result++; |
|
342 } |
|
343 } |
|
344 } |
|
345 return result; |
|
346 } |
|
347 |
|
348 function isAvkonView(instance) { |
|
349 return (instance != null && instance.componentId == "com.nokia.sdt.series60.CAknView"); |
|
350 } |
|
351 |
|
352 function isPreviewPopUp(instance) { |
|
353 return (instance != null && instance.componentId == "com.nokia.sdt.series60.CAknPreviewPopUp"); |
|
354 } |
|
355 |