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